Skip to content

Commit b115680

Browse files
hughbelonitradipeshmsft
authored
Add WindowsBase tests (#8215)
* Add WindowsBase tests * Fix build post rebase * Fix build errors * Fix tests * Fix tests crash * Disabled few tests and modified WeakEventManager tests * Disabling Create_EmptyApplicationManifest_ThrowsRightsManagementException test * Disabling Create_InvokeInvalidApplicationManifest_ThrowsRightsManagementException test * Updated DispatcherTests test attribute to WpfFact and WpfTheory --------- Co-authored-by: Loni Tra <lonitra@microsoft.com> Co-authored-by: Dipesh Kumar <dipeshkumar@microsoft.com>
1 parent 99d6c0c commit b115680

File tree

96 files changed

+48679
-28
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

96 files changed

+48679
-28
lines changed

eng/Versions.props

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@
9393
</PropertyGroup>
9494
<!-- Test related -->
9595
<PropertyGroup>
96-
<MoqPackageVersion>4.18.4</MoqPackageVersion>
96+
<MoqPackageVersion>4.20.70</MoqPackageVersion>
9797
<FluentAssertionsVersion>6.11.0</FluentAssertionsVersion>
9898
<SystemComponentModelTypeConverterTestDataVersion>8.0.0-beta.23107.1</SystemComponentModelTypeConverterTestDataVersion>
9999
<SystemDrawingCommonTestDataVersion>8.0.0-beta.23107.1</SystemDrawingCommonTestDataVersion>

src/Microsoft.DotNet.Wpf/src/WindowsBase/System/Windows/Data/DataSourceProvider.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -338,8 +338,6 @@ protected virtual void EndInit()
338338

339339
private void EndDefer()
340340
{
341-
Debug.Assert(_deferLevel > 0);
342-
343341
--_deferLevel;
344342

345343
if (_deferLevel == 0)
Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
4+
using System.IO;
5+
using System.Runtime.ExceptionServices;
6+
using System.Threading;
7+
using System.Windows.Media;
8+
9+
namespace System.Windows.Tests;
10+
11+
public static class Helpers
12+
{
13+
#pragma warning disable xUnit1013
14+
public static string GetResourcePath(string name) => Path.GetFullPath(Path.Combine("Resources", name));
15+
16+
public static void ExecuteOnDifferentThread(Action action, ApartmentState? state = null)
17+
{
18+
ExceptionDispatchInfo? edi = null;
19+
var t = new Thread(() =>
20+
{
21+
try
22+
{
23+
action();
24+
}
25+
catch (Exception e)
26+
{
27+
edi = ExceptionDispatchInfo.Capture(e);
28+
}
29+
});
30+
if (state is not null)
31+
{
32+
t.SetApartmentState(state.Value);
33+
}
34+
t.Start();
35+
t.Join();
36+
37+
edi?.Throw();
38+
}
39+
40+
public static T ExecuteOnDifferentThread<T>(Func<T> action, ApartmentState? state = null)
41+
{
42+
T? result = default;
43+
ExceptionDispatchInfo? edi = null;
44+
var t = new Thread(() =>
45+
{
46+
try
47+
{
48+
result = action();
49+
}
50+
catch (Exception e)
51+
{
52+
edi = ExceptionDispatchInfo.Capture(e);
53+
}
54+
});
55+
if (state is not null)
56+
{
57+
t.SetApartmentState(state.Value);
58+
}
59+
t.Start();
60+
t.Join();
61+
62+
if (edi is not null)
63+
{
64+
edi.Throw();
65+
#pragma warning disable CA2201 // Do not raise reserved exception types
66+
throw new Exception("Not reachable.");
67+
#pragma warning restore CA2201 // Do not raise reserved exception types
68+
}
69+
else
70+
{
71+
return result!;
72+
}
73+
}
74+
75+
public static void AssertEqualRounded(Matrix expected, Matrix actual, int precision = 5)
76+
{
77+
if (expected.Equals(actual))
78+
{
79+
return;
80+
}
81+
82+
try
83+
{
84+
Assert.Equal(expected.M11, actual.M11, precision);
85+
Assert.Equal(expected.M12, actual.M12, precision);
86+
Assert.Equal(expected.M21, actual.M21, precision);
87+
Assert.Equal(expected.M22, actual.M22, precision);
88+
Assert.Equal(expected.OffsetX, actual.OffsetX, precision);
89+
Assert.Equal(expected.OffsetY, actual.OffsetY, precision);
90+
}
91+
catch (Exception)
92+
{
93+
// Throw main AssertException with formatting.
94+
//Assert.Equal(expected, actual);
95+
}
96+
}
97+
98+
public static void AssertEqualRounded(Rect expected, Rect actual, int precision)
99+
{
100+
if (expected.Equals(actual))
101+
{
102+
return;
103+
}
104+
105+
try
106+
{
107+
Assert.Equal(expected.X, actual.X, precision);
108+
Assert.Equal(expected.Y, actual.Y, precision);
109+
Assert.Equal(expected.Width, actual.Width, precision);
110+
Assert.Equal(expected.Height, actual.Height, precision);
111+
}
112+
catch (Exception)
113+
{
114+
// Throw main AssertException with formatting.
115+
Assert.Equal(expected, actual);
116+
}
117+
}
118+
#pragma warning restore xUnit1013
119+
}
Binary file not shown.
Binary file not shown.

0 commit comments

Comments
 (0)