Skip to content

Commit 9ed576f

Browse files
committed
tests
1 parent 39dd644 commit 9ed576f

3 files changed

Lines changed: 225 additions & 29 deletions

File tree

RoyalCode.SmartValidations.Tests/BuildInPredicatesTests.EqualsNotEquals.cs

Lines changed: 56 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
namespace RoyalCode.SmartValidations.Tests;
1+
using System.Numerics;
2+
3+
namespace RoyalCode.SmartValidations.Tests;
24

35
public partial class BuildInPredicatesTests
46
{
@@ -21,4 +23,57 @@ public void String_Equals(string? value, string compare, StringComparison? compa
2123
// Assert
2224
Assert.Equal(expected, areEquals);
2325
}
26+
27+
[Theory]
28+
[MemberData(nameof(Equitable_Data))]
29+
public void Equitable_Equals<T>(T value, T compare, bool expected)
30+
where T : IEquatable<T>
31+
{
32+
// Arrange
33+
// Act
34+
var areEquals = BuildInPredicates.Equal(value, compare);
35+
36+
// Assert
37+
Assert.Equal(expected, areEquals);
38+
}
39+
40+
[Theory]
41+
[InlineData("", "", null, false)]
42+
[InlineData("abc", "abc", null, false)]
43+
[InlineData("abc", "abcdfg", null, true)]
44+
[InlineData("abc", "ABC", null, true)]
45+
[InlineData("abc", "ABC", StringComparison.OrdinalIgnoreCase, false)]
46+
[InlineData("abc", "ABCdfg", StringComparison.OrdinalIgnoreCase, true)]
47+
[InlineData(null, "", null, true)]
48+
public void String_NotEquals(string? value, string compare, StringComparison? comparison, bool expected)
49+
{
50+
// Arrange
51+
comparison ??= StringComparison.Ordinal;
52+
53+
// Act
54+
var areEquals = BuildInPredicates.NotEqual(value, compare, comparison.Value);
55+
56+
// Assert
57+
Assert.Equal(expected, areEquals);
58+
}
59+
60+
public static IEnumerable<object[]> Equitable_Data()
61+
{
62+
yield return [(byte)1, (byte)1, true];
63+
yield return [(byte)1, (byte)2, false];
64+
yield return [(short)1, (short)1, true];
65+
yield return [(short)1, (short)2, false];
66+
yield return [1, 1, true];
67+
yield return [1, 2, false];
68+
yield return [1L, 1L, true];
69+
yield return [1L, 2L, false];
70+
yield return [1f, 1f, true];
71+
yield return [1f, 2f, false];
72+
yield return [1d, 1d, true];
73+
yield return [1d, 2d, false];
74+
yield return [1M, 1M, true];
75+
yield return [1M, 2M, false];
76+
yield return [BigInteger.One, BigInteger.One, true];
77+
yield return [BigInteger.One, BigInteger.Zero, false];
78+
}
2479
}

RoyalCode.SmartValidations.Tests/BuildInPredicatesTests.NotEmpty.cs

Lines changed: 61 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ public void Number_NotEmpty<T>(T value, bool expected) where T : INumber<T>
1717
}
1818

1919
[Theory]
20-
[MemberData(nameof(Numbers_Data))]
20+
[MemberData(nameof(Numbers_AndNulls_Data))]
2121
public void NullableNumber_NotEmpty<T>(T? value, bool expected) where T : struct, INumber<T>
2222
{
2323
// Arrange
@@ -40,6 +40,66 @@ public void NullableInt_NotEmpty(int? value, bool expected)
4040

4141
// Assert
4242
Assert.Equal(expected, result);
43+
44+
// Act
45+
var result2 = BuildInPredicates.NotEmpty((byte?)null);
46+
// Assert
47+
Assert.False(result2);
48+
49+
// Act
50+
var result3 = BuildInPredicates.NotEmpty((short?)null);
51+
// Assert
52+
Assert.False(result3);
53+
54+
// Act
55+
var result4 = BuildInPredicates.NotEmpty((long?)null);
56+
// Assert
57+
Assert.False(result4);
58+
59+
// Act
60+
var result5 = BuildInPredicates.NotEmpty((float?)null);
61+
// Assert
62+
Assert.False(result5);
63+
64+
// Act
65+
var result6 = BuildInPredicates.NotEmpty((double?)null);
66+
// Assert
67+
Assert.False(result6);
68+
69+
// Act
70+
var result7 = BuildInPredicates.NotEmpty((decimal?)null);
71+
// Assert
72+
Assert.False(result7);
73+
74+
// Act
75+
var result8 = BuildInPredicates.NotEmpty((BigInteger?)null);
76+
// Assert
77+
Assert.False(result8);
78+
}
79+
80+
public static IEnumerable<object[]> Numbers_AndNulls_Data()
81+
{
82+
foreach (var value in Numbers_Data())
83+
{
84+
yield return value;
85+
}
86+
87+
yield return [(byte?)1, true];
88+
yield return [(byte?)0, false];
89+
yield return [(short?)1, true];
90+
yield return [(short?)0, false];
91+
yield return [(int?)1, true];
92+
yield return [(int?)0, false];
93+
yield return [(long?)1L, true];
94+
yield return [(long?)0L, false];
95+
yield return [(float?)1f, true];
96+
yield return [(float?)0f, false];
97+
yield return [(double?)1d, true];
98+
yield return [(double?)0d, false];
99+
yield return [(decimal?)1M, true];
100+
yield return [(decimal?)0M, false];
101+
yield return [(BigInteger?)BigInteger.One, true];
102+
yield return [(BigInteger?)BigInteger.Zero, false];
43103
}
44104

45105
public static IEnumerable<object[]> Numbers_Data()
@@ -288,31 +348,4 @@ public void String_NotEmpty(string? value, bool expected)
288348
// Assert
289349
Assert.Equal(expected, result);
290350
}
291-
292-
[Theory]
293-
[InlineData(null, null, true)]
294-
[InlineData(null, "", false)]
295-
[InlineData("", null, false)]
296-
[InlineData("", "", false)]
297-
[InlineData(null, " ", false)]
298-
[InlineData(" ", null, false)]
299-
[InlineData(" ", "", false)]
300-
[InlineData("", " ", false)]
301-
[InlineData(" ", " ", false)]
302-
[InlineData("a", null, false)]
303-
[InlineData("a", "", false)]
304-
[InlineData("a", " ", false)]
305-
[InlineData(null, "a", false)]
306-
[InlineData("", "a", false)]
307-
[InlineData(" ", "a", false)]
308-
[InlineData("a", "b", true)]
309-
public void BothNullOrNotEmpty(string? v1, string? v2, bool expected)
310-
{
311-
// Arrange
312-
// Act
313-
var result = BuildInPredicates.BothNullOrNotEmpty(v1, v2);
314-
315-
// Assert
316-
Assert.Equal(expected, result);
317-
}
318351
}
Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
using System.Numerics;
2+
3+
namespace RoyalCode.SmartValidations.Tests;
4+
5+
public partial class BuildInPredicatesTests
6+
{
7+
[Theory]
8+
[MemberData(nameof(Numbers_Data))]
9+
public void Number_NullOrNotEmpty<T>(T value, bool expected)
10+
where T : INumber<T>
11+
{
12+
// Arrange
13+
// Act
14+
var result = BuildInPredicates.NullOrNotEmpty(value);
15+
16+
// Assert
17+
Assert.Equal(expected, result);
18+
}
19+
20+
[Theory]
21+
[MemberData(nameof(Numbers_AndNulls_Data))]
22+
public void NullableNumber_NullOrNotEmpty<T>(T? value, bool expected)
23+
where T : struct, INumber<T>
24+
{
25+
// Arrange
26+
// Act
27+
var result = BuildInPredicates.NullOrNotEmpty(value);
28+
29+
// Assert
30+
Assert.Equal(expected, result);
31+
32+
// Act
33+
var result2 = BuildInPredicates.NullOrNotEmpty((byte?)null);
34+
// Assert
35+
Assert.True(result2);
36+
37+
// Act
38+
var result3 = BuildInPredicates.NullOrNotEmpty((short?)null);
39+
// Assert
40+
Assert.True(result3);
41+
42+
// Act
43+
var result4 = BuildInPredicates.NullOrNotEmpty((long?)null);
44+
// Assert
45+
46+
Assert.True(result4);
47+
// Act
48+
var result5 = BuildInPredicates.NullOrNotEmpty((float?)null);
49+
50+
// Assert
51+
Assert.True(result5);
52+
// Act
53+
var result6 = BuildInPredicates.NullOrNotEmpty((double?)null);
54+
55+
// Assert
56+
Assert.True(result6);
57+
// Act
58+
var result7 = BuildInPredicates.NullOrNotEmpty((decimal?)null);
59+
60+
// Assert
61+
Assert.True(result7);
62+
// Act
63+
var result8 = BuildInPredicates.NullOrNotEmpty((BigInteger?)null);
64+
}
65+
66+
[Theory]
67+
[InlineData("", false)]
68+
[InlineData(" ", false)]
69+
[InlineData("a", true)]
70+
[InlineData("abc", true)]
71+
[InlineData(null, true)]
72+
public void String_NullOrNotEmpty(string? value, bool expected)
73+
{
74+
// Arrange
75+
// Act
76+
var result = BuildInPredicates.NullOrNotEmpty(value);
77+
78+
// Assert
79+
Assert.Equal(expected, result);
80+
}
81+
82+
[Theory]
83+
[InlineData(null, null, true)]
84+
[InlineData(null, "", false)]
85+
[InlineData("", null, false)]
86+
[InlineData("", "", false)]
87+
[InlineData(null, " ", false)]
88+
[InlineData(" ", null, false)]
89+
[InlineData(" ", "", false)]
90+
[InlineData("", " ", false)]
91+
[InlineData(" ", " ", false)]
92+
[InlineData("a", null, false)]
93+
[InlineData("a", "", false)]
94+
[InlineData("a", " ", false)]
95+
[InlineData(null, "a", false)]
96+
[InlineData("", "a", false)]
97+
[InlineData(" ", "a", false)]
98+
[InlineData("a", "b", true)]
99+
public void BothNullOrNotEmpty(string? v1, string? v2, bool expected)
100+
{
101+
// Arrange
102+
// Act
103+
var result = BuildInPredicates.BothNullOrNotEmpty(v1, v2);
104+
105+
// Assert
106+
Assert.Equal(expected, result);
107+
}
108+
}

0 commit comments

Comments
 (0)