Skip to content

Commit 5a4a4c0

Browse files
committed
fix(tests): fix assertion and parameter compatibility issues
- Convert Assert.ThrowsException<Exception> to Action.Should().Throw<Exception>() MSTest's ThrowsException requires exact type match, while AwesomeAssertions' Throw<T> accepts derived exception types (35 occurrences in 9 files) - Remove CancellationToken parameter from ExtractShape_FromArray test TUnit injected cancellation tokens for timeout support; MSTest uses [Timeout] attribute Test results: 5596 passed, 0 failed, 11 skipped
1 parent 469b5c6 commit 5a4a4c0

10 files changed

Lines changed: 36 additions & 36 deletions

test/NumSharp.UnitTest/APIs/np.can_cast.BattleTest.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ public async Task CanCast_UnsafeMode_AllowsAnything()
106106
[TestMethod]
107107
public async Task CanCast_InvalidMode_Throws()
108108
{
109-
Microsoft.VisualStudio.TestTools.UnitTesting.Assert.ThrowsException<Exception>(() => np.can_cast(NPTypeCode.Int32, NPTypeCode.Int64, "invalid"));
109+
new Action(() => np.can_cast(NPTypeCode.Int32, NPTypeCode.Int64, "invalid")).Should().Throw<Exception>();
110110
}
111111

112112
#endregion

test/NumSharp.UnitTest/APIs/np.common_type.BattleTest.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -113,19 +113,19 @@ public async Task CommonType_Type_Float32_ReturnsSingle()
113113
[TestMethod]
114114
public async Task CommonType_Empty_Throws()
115115
{
116-
Microsoft.VisualStudio.TestTools.UnitTesting.Assert.ThrowsException<Exception>(() => np.common_type_code(Array.Empty<NDArray>()));
116+
new Action(() => np.common_type_code(Array.Empty<NDArray>())).Should().Throw<Exception>();
117117
}
118118

119119
[TestMethod]
120120
public async Task CommonType_Null_Throws()
121121
{
122-
Microsoft.VisualStudio.TestTools.UnitTesting.Assert.ThrowsException<Exception>(() => np.common_type_code((NDArray[])null!));
122+
new Action(() => np.common_type_code((NDArray[])null!)).Should().Throw<Exception>();
123123
}
124124

125125
[TestMethod]
126126
public async Task CommonTypeCode_Empty_Throws()
127127
{
128-
Microsoft.VisualStudio.TestTools.UnitTesting.Assert.ThrowsException<Exception>(() => np.common_type_code(Array.Empty<NPTypeCode>()));
128+
new Action(() => np.common_type_code(Array.Empty<NPTypeCode>())).Should().Throw<Exception>();
129129
}
130130

131131
#endregion

test/NumSharp.UnitTest/APIs/np.finfo.BattleTest.cs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -64,49 +64,49 @@ public async Task FInfo_Decimal_AllProperties()
6464
[TestMethod]
6565
public async Task FInfo_Int32_Throws()
6666
{
67-
Microsoft.VisualStudio.TestTools.UnitTesting.Assert.ThrowsException<Exception>(() => np.finfo(NPTypeCode.Int32));
67+
new Action(() => np.finfo(NPTypeCode.Int32)).Should().Throw<Exception>();
6868
}
6969

7070
[TestMethod]
7171
public async Task FInfo_Boolean_Throws()
7272
{
73-
Microsoft.VisualStudio.TestTools.UnitTesting.Assert.ThrowsException<Exception>(() => np.finfo(NPTypeCode.Boolean));
73+
new Action(() => np.finfo(NPTypeCode.Boolean)).Should().Throw<Exception>();
7474
}
7575

7676
[TestMethod]
7777
public async Task FInfo_Byte_Throws()
7878
{
79-
Microsoft.VisualStudio.TestTools.UnitTesting.Assert.ThrowsException<Exception>(() => np.finfo(NPTypeCode.Byte));
79+
new Action(() => np.finfo(NPTypeCode.Byte)).Should().Throw<Exception>();
8080
}
8181

8282
[TestMethod]
8383
public async Task FInfo_Empty_Throws()
8484
{
85-
Microsoft.VisualStudio.TestTools.UnitTesting.Assert.ThrowsException<Exception>(() => np.finfo(NPTypeCode.Empty));
85+
new Action(() => np.finfo(NPTypeCode.Empty)).Should().Throw<Exception>();
8686
}
8787

8888
[TestMethod]
8989
public async Task FInfo_NullType_Throws()
9090
{
91-
Microsoft.VisualStudio.TestTools.UnitTesting.Assert.ThrowsException<Exception>(() => np.finfo((Type)null!));
91+
new Action(() => np.finfo((Type)null!)).Should().Throw<Exception>();
9292
}
9393

9494
[TestMethod]
9595
public async Task FInfo_NullArray_Throws()
9696
{
97-
Microsoft.VisualStudio.TestTools.UnitTesting.Assert.ThrowsException<Exception>(() => np.finfo((NDArray)null!));
97+
new Action(() => np.finfo((NDArray)null!)).Should().Throw<Exception>();
9898
}
9999

100100
[TestMethod]
101101
public async Task FInfo_EmptyDtypeString_Throws()
102102
{
103-
Microsoft.VisualStudio.TestTools.UnitTesting.Assert.ThrowsException<Exception>(() => np.finfo(""));
103+
new Action(() => np.finfo("")).Should().Throw<Exception>();
104104
}
105105

106106
[TestMethod]
107107
public async Task FInfo_InvalidDtypeString_Throws()
108108
{
109-
Microsoft.VisualStudio.TestTools.UnitTesting.Assert.ThrowsException<Exception>(() => np.finfo("int32"));
109+
new Action(() => np.finfo("int32")).Should().Throw<Exception>();
110110
}
111111

112112
#endregion
@@ -139,7 +139,7 @@ public async Task FInfo_Generic_Decimal()
139139
[TestMethod]
140140
public async Task FInfo_Generic_Int_Throws()
141141
{
142-
Microsoft.VisualStudio.TestTools.UnitTesting.Assert.ThrowsException<Exception>(() => np.finfo<int>());
142+
new Action(() => np.finfo<int>()).Should().Throw<Exception>();
143143
}
144144

145145
#endregion
@@ -166,7 +166,7 @@ public async Task FInfo_NDArray_Float64()
166166
public async Task FInfo_NDArray_Int_Throws()
167167
{
168168
var arr = np.array(new int[] { 1, 2, 3 });
169-
Microsoft.VisualStudio.TestTools.UnitTesting.Assert.ThrowsException<Exception>(() => np.finfo(arr));
169+
new Action(() => np.finfo(arr)).Should().Throw<Exception>();
170170
}
171171

172172
#endregion

test/NumSharp.UnitTest/APIs/np.iinfo.BattleTest.cs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -112,49 +112,49 @@ public async Task IInfo_Char_AllProperties()
112112
[TestMethod]
113113
public async Task IInfo_Single_Throws()
114114
{
115-
Microsoft.VisualStudio.TestTools.UnitTesting.Assert.ThrowsException<Exception>(() => np.iinfo(NPTypeCode.Single));
115+
new Action(() => np.iinfo(NPTypeCode.Single)).Should().Throw<Exception>();
116116
}
117117

118118
[TestMethod]
119119
public async Task IInfo_Double_Throws()
120120
{
121-
Microsoft.VisualStudio.TestTools.UnitTesting.Assert.ThrowsException<Exception>(() => np.iinfo(NPTypeCode.Double));
121+
new Action(() => np.iinfo(NPTypeCode.Double)).Should().Throw<Exception>();
122122
}
123123

124124
[TestMethod]
125125
public async Task IInfo_Decimal_Throws()
126126
{
127-
Microsoft.VisualStudio.TestTools.UnitTesting.Assert.ThrowsException<Exception>(() => np.iinfo(NPTypeCode.Decimal));
127+
new Action(() => np.iinfo(NPTypeCode.Decimal)).Should().Throw<Exception>();
128128
}
129129

130130
[TestMethod]
131131
public async Task IInfo_Empty_Throws()
132132
{
133-
Microsoft.VisualStudio.TestTools.UnitTesting.Assert.ThrowsException<Exception>(() => np.iinfo(NPTypeCode.Empty));
133+
new Action(() => np.iinfo(NPTypeCode.Empty)).Should().Throw<Exception>();
134134
}
135135

136136
[TestMethod]
137137
public async Task IInfo_NullType_Throws()
138138
{
139-
Microsoft.VisualStudio.TestTools.UnitTesting.Assert.ThrowsException<Exception>(() => np.iinfo((Type)null!));
139+
new Action(() => np.iinfo((Type)null!)).Should().Throw<Exception>();
140140
}
141141

142142
[TestMethod]
143143
public async Task IInfo_NullArray_Throws()
144144
{
145-
Microsoft.VisualStudio.TestTools.UnitTesting.Assert.ThrowsException<Exception>(() => np.iinfo((NDArray)null!));
145+
new Action(() => np.iinfo((NDArray)null!)).Should().Throw<Exception>();
146146
}
147147

148148
[TestMethod]
149149
public async Task IInfo_EmptyDtypeString_Throws()
150150
{
151-
Microsoft.VisualStudio.TestTools.UnitTesting.Assert.ThrowsException<Exception>(() => np.iinfo(""));
151+
new Action(() => np.iinfo("")).Should().Throw<Exception>();
152152
}
153153

154154
[TestMethod]
155155
public async Task IInfo_InvalidDtypeString_Throws()
156156
{
157-
Microsoft.VisualStudio.TestTools.UnitTesting.Assert.ThrowsException<Exception>(() => np.iinfo("float32"));
157+
new Action(() => np.iinfo("float32")).Should().Throw<Exception>();
158158
}
159159

160160
#endregion
@@ -196,7 +196,7 @@ public async Task IInfo_Generic_Bool()
196196
[TestMethod]
197197
public async Task IInfo_Generic_Float_Throws()
198198
{
199-
Microsoft.VisualStudio.TestTools.UnitTesting.Assert.ThrowsException<Exception>(() => np.iinfo<float>());
199+
new Action(() => np.iinfo<float>()).Should().Throw<Exception>();
200200
}
201201

202202
#endregion
@@ -224,7 +224,7 @@ public async Task IInfo_NDArray_Byte()
224224
public async Task IInfo_NDArray_Float_Throws()
225225
{
226226
var arr = np.array(new float[] { 1.0f, 2.0f });
227-
Microsoft.VisualStudio.TestTools.UnitTesting.Assert.ThrowsException<Exception>(() => np.iinfo(arr));
227+
new Action(() => np.iinfo(arr)).Should().Throw<Exception>();
228228
}
229229

230230
#endregion

test/NumSharp.UnitTest/APIs/np.isreal_iscomplex.BattleTest.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ public async Task IsReal_ShapeMatches()
4848
[TestMethod]
4949
public async Task IsReal_Null_Throws()
5050
{
51-
Microsoft.VisualStudio.TestTools.UnitTesting.Assert.ThrowsException<Exception>(() => np.isreal(null!));
51+
new Action(() => np.isreal(null!)).Should().Throw<Exception>();
5252
}
5353

5454
#endregion
@@ -84,7 +84,7 @@ public async Task IsComplex_ShapeMatches()
8484
[TestMethod]
8585
public async Task IsComplex_Null_Throws()
8686
{
87-
Microsoft.VisualStudio.TestTools.UnitTesting.Assert.ThrowsException<Exception>(() => np.iscomplex(null!));
87+
new Action(() => np.iscomplex(null!)).Should().Throw<Exception>();
8888
}
8989

9090
#endregion
@@ -125,7 +125,7 @@ public async Task IsRealObj_AllTypes_True()
125125
[TestMethod]
126126
public async Task IsRealObj_Null_Throws()
127127
{
128-
Microsoft.VisualStudio.TestTools.UnitTesting.Assert.ThrowsException<Exception>(() => np.isrealobj(null!));
128+
new Action(() => np.isrealobj(null!)).Should().Throw<Exception>();
129129
}
130130

131131
#endregion
@@ -158,7 +158,7 @@ public async Task IsComplexObj_AllRealTypes_False()
158158
[TestMethod]
159159
public async Task IsComplexObj_Null_Throws()
160160
{
161-
Microsoft.VisualStudio.TestTools.UnitTesting.Assert.ThrowsException<Exception>(() => np.iscomplexobj(null!));
161+
new Action(() => np.iscomplexobj(null!)).Should().Throw<Exception>();
162162
}
163163

164164
#endregion

test/NumSharp.UnitTest/APIs/np.issubdtype.BattleTest.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ public async Task IsSubdtype_NDArray_String()
123123
[TestMethod]
124124
public async Task IsSubdtype_NDArray_Null_Throws()
125125
{
126-
Microsoft.VisualStudio.TestTools.UnitTesting.Assert.ThrowsException<Exception>(() => np.issubdtype((NDArray)null!, "integer"));
126+
new Action(() => np.issubdtype((NDArray)null!, "integer")).Should().Throw<Exception>();
127127
}
128128

129129
#endregion

test/NumSharp.UnitTest/APIs/np.min_scalar_type.BattleTest.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ public async Task MinScalarType_Decimal()
136136
[TestMethod]
137137
public async Task MinScalarType_Null_Throws()
138138
{
139-
Microsoft.VisualStudio.TestTools.UnitTesting.Assert.ThrowsException<Exception>(() => np.min_scalar_type(null!));
139+
new Action(() => np.min_scalar_type(null!)).Should().Throw<Exception>();
140140
}
141141

142142
#endregion

test/NumSharp.UnitTest/APIs/np.result_type.BattleTest.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,13 +58,13 @@ public async Task ResultType_Float32Float64_ReturnsFloat64()
5858
[TestMethod]
5959
public async Task ResultType_Empty_Throws()
6060
{
61-
Microsoft.VisualStudio.TestTools.UnitTesting.Assert.ThrowsException<Exception>(() => np.result_type(Array.Empty<NPTypeCode>()));
61+
new Action(() => np.result_type(Array.Empty<NPTypeCode>())).Should().Throw<Exception>();
6262
}
6363

6464
[TestMethod]
6565
public async Task ResultType_NullArray_Throws()
6666
{
67-
Microsoft.VisualStudio.TestTools.UnitTesting.Assert.ThrowsException<Exception>(() => np.result_type((NPTypeCode[])null!));
67+
new Action(() => np.result_type((NPTypeCode[])null!)).Should().Throw<Exception>();
6868
}
6969

7070
#endregion
@@ -95,14 +95,14 @@ public async Task ResultType_TwoArg_NDArray()
9595
public async Task ResultType_TwoArg_NDArray_NullFirst_Throws()
9696
{
9797
var b = np.array(new int[] { 1, 2 });
98-
Microsoft.VisualStudio.TestTools.UnitTesting.Assert.ThrowsException<Exception>(() => np.result_type((NDArray)null!, b));
98+
new Action(() => np.result_type((NDArray)null!, b)).Should().Throw<Exception>();
9999
}
100100

101101
[TestMethod]
102102
public async Task ResultType_TwoArg_NDArray_NullSecond_Throws()
103103
{
104104
var a = np.array(new int[] { 1, 2 });
105-
Microsoft.VisualStudio.TestTools.UnitTesting.Assert.ThrowsException<Exception>(() => np.result_type(a, (NDArray)null!));
105+
new Action(() => np.result_type(a, (NDArray)null!)).Should().Throw<Exception>();
106106
}
107107

108108
#endregion

test/NumSharp.UnitTest/APIs/np.type_checks.BattleTest.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ public async Task IsDtype_NDArray_Integral()
113113
[TestMethod]
114114
public async Task IsDtype_NDArray_Null_Throws()
115115
{
116-
Microsoft.VisualStudio.TestTools.UnitTesting.Assert.ThrowsException<Exception>(() => np.isdtype((NDArray)null!, "integral"));
116+
new Action(() => np.isdtype((NDArray)null!, "integral")).Should().Throw<Exception>();
117117
}
118118

119119
#endregion

test/NumSharp.UnitTest/View/Shape.Test.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ public void EqualityComparer()
9494

9595

9696
[TestMethod, Timeout(10000)]
97-
public void ExtractShape_FromArray(CancellationToken cancellationToken)
97+
public void ExtractShape_FromArray()
9898
{
9999
// @formatter:off — disable formatter after this line
100100
var v = Shape.ExtractShape((Array)new int[][][]

0 commit comments

Comments
 (0)