Skip to content

Commit 808b869

Browse files
author
dahall
committed
Unit test fixes to comply with move to .NET 8
1 parent ba40434 commit 808b869

File tree

9 files changed

+22
-23
lines changed

9 files changed

+22
-23
lines changed

UnitTests/Core/InteropServices/MatrixTests.cs

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
#if NET7_0_OR_GREATER
2-
using NUnit.Framework;
3-
using GMatrix4x4 = System.Numerics.Matrix<System.Single>;
1+
using NUnit.Framework;
2+
using Vanara;
3+
using GMatrix4x4 = Vanara.Matrix<float>;
44
using GScalar = System.Single;
55

66
namespace System.Numerics.Tests;
@@ -25,7 +25,7 @@ public void AdditionTest()
2525
GMatrix4x4 vr = GMatrix4x4.CreateIdentity(4);
2626

2727
GMatrix4x4 bad = GMatrix4x4.CreateIdentity(3);
28-
Assert.Throws<ArgumentException>(() => vl + bad);
28+
Assert.That(() => vl + bad, Throws.ArgumentException);
2929

3030
var val = vl + vr;
3131
Assert.Equals(val.Columns, vl.Columns);
@@ -102,7 +102,7 @@ public void HashCodeTest()
102102
Assert.Equals(val.GetHashCode(), val.GetHashCode());
103103

104104
GMatrix4x4 val2 = GenerateIncrementalMatrixNumber(4f);
105-
Assert.AreNotEqual(val.GetHashCode(), val2.GetHashCode());
105+
Assert.That(val.GetHashCode(), Is.Not.EqualTo(val2.GetHashCode()));
106106
}
107107

108108
[Test]
@@ -161,7 +161,7 @@ public void MultiplicationTest()
161161
GMatrix4x4 vl = new float[,] { { 1, 2, 3 }, { 4, 5, 6 } };
162162
GMatrix4x4 vr = new float[,] { { 10, 11 }, { 20, 21 }, { 30, 31 } };
163163

164-
Assert.Throws<ArgumentException>(() => vl * GenerateIncrementalMatrixNumber());
164+
Assert.That(() => vl * GenerateIncrementalMatrixNumber(), Throws.ArgumentException);
165165

166166
var val = vl * vr;
167167
Assert.Equals(val.Columns, vr.Columns);
@@ -197,14 +197,14 @@ public void PropCheck()
197197
Assert.That(val[0, 0] == 1f);
198198
Assert.That(val[0, 1] == 0f);
199199

200-
Assert.Throws<ArgumentOutOfRangeException>(() => val[0, 4] == 0f);
201-
Assert.Throws<ArgumentOutOfRangeException>(() => val[4, 0] == 0f);
200+
Assert.That(() => val[0, 4] == 0f, Throws.TypeOf<ArgumentOutOfRangeException>());
201+
Assert.That(() => val[4, 0] == 0f, Throws.TypeOf<ArgumentOutOfRangeException>());
202202

203203
val[0, 0] = 2f;
204204
Assert.That(val[0, 0] == 2f);
205205

206-
Assert.Throws<ArgumentOutOfRangeException>(() => val[0, 4] = 0f);
207-
Assert.Throws<ArgumentOutOfRangeException>(() => val[4, 0] = 0f);
206+
Assert.That(() => val[0, 4] = 0f, Throws.TypeOf<ArgumentOutOfRangeException>());
207+
Assert.That(() => val[4, 0] = 0f, Throws.TypeOf<ArgumentOutOfRangeException>());
208208
}
209209

210210
[Test]
@@ -237,7 +237,7 @@ public void SubtractTest()
237237
GMatrix4x4 vr = GenerateIncrementalMatrixNumber(-5f);
238238

239239
GMatrix4x4 bad = GMatrix4x4.CreateIdentity(3);
240-
Assert.Throws<ArgumentException>(() => vl - bad);
240+
Assert.That(() => vl - bad, Throws.ArgumentException);
241241

242242
Assert.That(vl != vr);
243243
var val = vl - vr;
@@ -283,5 +283,4 @@ public void VectorTest()
283283
Assert.Equals(rvec2, val.RowVector(2));
284284
Assert.Equals(cvec2, val.ColumnVector(2));
285285
}
286-
}
287-
#endif
286+
}

UnitTests/Directory.Build.props

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<Project>
22
<PropertyGroup>
33
<TargetFrameworks/>
4-
<TargetFramework>net6.0</TargetFramework>
4+
<TargetFramework>net8.0</TargetFramework>
55
<Configurations>Debug;Release;DebugNoTests</Configurations>
66
<Platforms>AnyCPU;x64;x86</Platforms>
77
<LangVersion>latest</LangVersion>

UnitTests/PInvoke/CldApi/CldApi.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22
<PropertyGroup>
33
<AssemblyName>UnitTest.PInvoke.CldApi</AssemblyName>
4-
<TargetFramework>net6.0-windows10.0.19041.0</TargetFramework>
4+
<TargetFramework>$(TargetFramework)-windows10.0.19041.0</TargetFramework>
55
</PropertyGroup>
66
<ItemGroup>
77
<ProjectReference Include="..\..\..\PInvoke\CldApi\Vanara.PInvoke.CldApi.csproj" />

UnitTests/PInvoke/ComCtl32/ComCtl32.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22
<PropertyGroup>
33
<AssemblyName>UnitTest.PInvoke.ComCtl32</AssemblyName>
4-
<TargetFramework>net6.0-windows</TargetFramework>
4+
<TargetFramework>$(TargetFramework)-windows</TargetFramework>
55
<UseWindowsForms>true</UseWindowsForms>
66
</PropertyGroup>
77
<ItemGroup>

UnitTests/PInvoke/NdfApi/NdfApi.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<PropertyGroup>
33
<AssemblyName>UnitTest.PInvoke.NdfApi</AssemblyName>
44
<RegisterForComInterop>false</RegisterForComInterop>
5-
<TargetFramework>net6.0-windows</TargetFramework>
5+
<TargetFramework>$(TargetFramework)-windows</TargetFramework>
66
<EnableComHosting>true</EnableComHosting>
77
</PropertyGroup>
88
<ItemGroup>

UnitTests/PInvoke/Printing/PrintingTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -424,7 +424,7 @@ public void PortTest()
424424

425425
Assert.That(SetPort(null, port, PORT_STATUS.PORT_STATUS_OFFLINE, PORT_STATUS_TYPE.PORT_STATUS_TYPE_ERROR), ResultIs.Successful);
426426
Assert.That(SetPort(null, port, "Off-line", PORT_STATUS_TYPE.PORT_STATUS_TYPE_ERROR), ResultIs.Successful);
427-
Assert.That(SetPort(null, port, 0, 0), ResultIs.Successful);
427+
Assert.That(SetPort(null, port, 0, default(IntPtr)), ResultIs.Successful);
428428
}
429429

430430
[Test]

UnitTests/PInvoke/Security/AdvApi32/PSIDTests.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public void AllocateAndInitializeSidTest()
3737
Assert.That(() => s = ConvertSidToStringSid(pSid), Throws.Nothing);
3838
Assert.That(s, Is.EqualTo("S-1-1-0"));
3939
Assert.That(GetSidSubAuthority(pSid, 0), Is.EqualTo(0));
40-
var len = GetLengthSid(pSid);
40+
SizeT len = GetLengthSid(pSid);
4141
var p2 = new SafePSID(len);
4242
b = CopySid(len, (IntPtr)p2, pSid);
4343
Assert.That(EqualSid(p2, pSid));
@@ -132,7 +132,7 @@ public void GetWindowsAccountDomainSidTest()
132132
[Test]
133133
public void InitializeSidTest()
134134
{
135-
using var pSid = new SafePSID(32);
135+
using var pSid = new SafePSID((SizeT)32);
136136
Assert.That(InitializeSid(pSid, KnownSIDAuthority.SECURITY_LOCAL_SID_AUTHORITY, 2), ResultIs.Successful);
137137
}
138138

@@ -173,7 +173,7 @@ public void PSIDTest()
173173
var id2 = new SecurityIdentifier((IntPtr)sid3);
174174
Assert.That(id2.IsWellKnown(WellKnownSidType.WorldSid));
175175

176-
using var sid4 = new SafePSID(100);
176+
using var sid4 = new SafePSID((SizeT)100);
177177
Assert.That(!sid4.IsClosed);
178178
Assert.That(!sid4.IsValidSid);
179179
Assert.That((int)sid4.Size, Is.EqualTo(100));

UnitTests/PInvoke/Security/AdvApi32/WinSaferTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public void SaferGetSetLevelInformationTest()
2828
//Assert.That(SaferSetLevelInformation(hLvl, SAFER_OBJECT_INFO_CLASS.SaferObjectDescription, str, str.Size), ResultIs.Successful);
2929
Assert.That(SaferGetLevelInformation(hLvl, SAFER_OBJECT_INFO_CLASS.SaferObjectDescription, retstr, retstr.Size, out _), ResultIs.Successful);
3030
//Assert.That(retstr.ToString(), Is.EqualTo(str.ToString()));
31-
TestContext.WriteLine(retstr);
31+
TestContext.WriteLine((string?)retstr);
3232
}
3333
}
3434

UnitTests/Windows.Shell/Windows.Shell.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22
<PropertyGroup>
33
<AssemblyName>UnitTest.Windows.Shell</AssemblyName>
4-
<TargetFramework>net7.0-windows</TargetFramework>
4+
<TargetFramework>$(TargetFramework)-windows</TargetFramework>
55
<UseWindowsForms>true</UseWindowsForms>
66
</PropertyGroup>
77
<ItemGroup>

0 commit comments

Comments
 (0)