Skip to content

Commit 92c5f8d

Browse files
committed
add tests
1 parent 2d31633 commit 92c5f8d

File tree

11 files changed

+673
-2
lines changed

11 files changed

+673
-2
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ Prevent including Equatable.Generator as a dependence
3333
### Requirements
3434

3535
This library requires:
36+
3637
- Target framework .NET Standard 2.0 or greater
3738
- Project C# `LangVersion` 9.0 or higher
3839

src/Equatable.Generator/Attributes/SequenceEqualityAttribute.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using System.Diagnostics;
1+
using System.Diagnostics;
22

33
namespace Equatable.Attributes;
44

test/Equatable.Entities/Nested.cs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
using Equatable.Attributes;
2+
3+
namespace Equatable.Entities;
4+
5+
public class Nested
6+
{
7+
//[Equatable]
8+
public partial class Animal
9+
{
10+
public int Id { get; set; }
11+
public string Name { get; set; }
12+
public string Type { get; set; }
13+
}
14+
}

test/Equatable.Entities/StatusRecordList.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,5 @@ public partial record StatusRecordList(
1212
string? Description,
1313
int DisplayOrder,
1414
bool IsActive,
15-
List<string> Versions
15+
[property: SequenceEquality] List<string> Versions
1616
);
Lines changed: 246 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,246 @@
1+
using Equatable.Entities;
2+
3+
namespace Equatable.Generator.Tests.Entities;
4+
5+
public class DataTypeTest
6+
{
7+
[Fact]
8+
public void EqualNotNull()
9+
{
10+
var left = new DataType
11+
{
12+
Id = 1,
13+
Name = "Test1",
14+
Boolean = false,
15+
Short = 2,
16+
Long = 200,
17+
Float = 200.20F,
18+
Double = 300.35,
19+
Decimal = 456.12M,
20+
DateTime = new DateTime(2024, 5, 1, 8, 0, 0),
21+
DateTimeOffset = new DateTimeOffset(2024, 5, 1, 8, 0, 0, TimeSpan.FromHours(-6)),
22+
Guid = Guid.Empty,
23+
TimeSpan = TimeSpan.FromHours(1),
24+
DateOnly = new DateOnly(2022, 12, 1),
25+
TimeOnly = new TimeOnly(1, 30, 0),
26+
BooleanNull = false,
27+
ShortNull = 2,
28+
LongNull = 200,
29+
FloatNull = 200.20F,
30+
DoubleNull = 300.35,
31+
DecimalNull = 456.12M,
32+
DateTimeNull = new DateTime(2024, 4, 1, 8, 0, 0),
33+
DateTimeOffsetNull = new DateTimeOffset(2024, 4, 1, 8, 0, 0, TimeSpan.FromHours(-6)),
34+
GuidNull = Guid.Empty,
35+
TimeSpanNull = TimeSpan.FromHours(1),
36+
DateOnlyNull = new DateOnly(2022, 12, 1),
37+
TimeOnlyNull = new TimeOnly(1, 30, 0),
38+
};
39+
40+
var right = new DataType
41+
{
42+
Id = 1,
43+
Name = "Test1",
44+
Boolean = false,
45+
Short = 2,
46+
Long = 200,
47+
Float = 200.20F,
48+
Double = 300.35,
49+
Decimal = 456.12M,
50+
DateTime = new DateTime(2024, 5, 1, 8, 0, 0),
51+
DateTimeOffset = new DateTimeOffset(2024, 5, 1, 8, 0, 0, TimeSpan.FromHours(-6)),
52+
Guid = Guid.Empty,
53+
TimeSpan = TimeSpan.FromHours(1),
54+
DateOnly = new DateOnly(2022, 12, 1),
55+
TimeOnly = new TimeOnly(1, 30, 0),
56+
BooleanNull = false,
57+
ShortNull = 2,
58+
LongNull = 200,
59+
FloatNull = 200.20F,
60+
DoubleNull = 300.35,
61+
DecimalNull = 456.12M,
62+
DateTimeNull = new DateTime(2024, 4, 1, 8, 0, 0),
63+
DateTimeOffsetNull = new DateTimeOffset(2024, 4, 1, 8, 0, 0, TimeSpan.FromHours(-6)),
64+
GuidNull = Guid.Empty,
65+
TimeSpanNull = TimeSpan.FromHours(1),
66+
DateOnlyNull = new DateOnly(2022, 12, 1),
67+
TimeOnlyNull = new TimeOnly(1, 30, 0),
68+
};
69+
70+
var isEqual = left.Equals(right);
71+
isEqual.Should().BeTrue();
72+
73+
// check operator ==
74+
isEqual = left == right;
75+
isEqual.Should().BeTrue();
76+
77+
}
78+
79+
[Fact]
80+
public void EqualNulls()
81+
{
82+
var left = new DataType
83+
{
84+
Id = 1,
85+
Name = "Test1",
86+
Boolean = false,
87+
Short = 2,
88+
Long = 200,
89+
Float = 200.20F,
90+
Double = 300.35,
91+
Decimal = 456.12M,
92+
DateTime = new DateTime(2024, 5, 1, 8, 0, 0),
93+
DateTimeOffset = new DateTimeOffset(2024, 5, 1, 8, 0, 0, TimeSpan.FromHours(-6)),
94+
Guid = Guid.Empty,
95+
TimeSpan = TimeSpan.FromHours(1),
96+
DateOnly = new DateOnly(2022, 12, 1),
97+
TimeOnly = new TimeOnly(1, 30, 0)
98+
};
99+
100+
var right = new DataType
101+
{
102+
Id = 1,
103+
Name = "Test1",
104+
Boolean = false,
105+
Short = 2,
106+
Long = 200,
107+
Float = 200.20F,
108+
Double = 300.35,
109+
Decimal = 456.12M,
110+
DateTime = new DateTime(2024, 5, 1, 8, 0, 0),
111+
DateTimeOffset = new DateTimeOffset(2024, 5, 1, 8, 0, 0, TimeSpan.FromHours(-6)),
112+
Guid = Guid.Empty,
113+
TimeSpan = TimeSpan.FromHours(1),
114+
DateOnly = new DateOnly(2022, 12, 1),
115+
TimeOnly = new TimeOnly(1, 30, 0)
116+
};
117+
118+
var isEqual = left.Equals(right);
119+
isEqual.Should().BeTrue();
120+
121+
// check operator ==
122+
isEqual = left == right;
123+
isEqual.Should().BeTrue();
124+
125+
}
126+
127+
[Fact]
128+
public void NotEqualNotNull()
129+
{
130+
var left = new DataType
131+
{
132+
Id = 1,
133+
Name = "Test1",
134+
Boolean = false,
135+
Short = 2,
136+
Long = 200,
137+
Float = 200.20F,
138+
Double = 300.35,
139+
Decimal = 456.12M,
140+
DateTime = new DateTime(2024, 5, 1, 8, 0, 0),
141+
DateTimeOffset = new DateTimeOffset(2024, 5, 1, 8, 0, 0, TimeSpan.FromHours(-6)),
142+
Guid = Guid.Empty,
143+
TimeSpan = TimeSpan.FromHours(1),
144+
DateOnly = new DateOnly(2022, 12, 1),
145+
TimeOnly = new TimeOnly(1, 30, 0),
146+
BooleanNull = false,
147+
ShortNull = 2,
148+
LongNull = 200,
149+
FloatNull = 200.20F,
150+
DoubleNull = 300.35,
151+
DecimalNull = 456.12M,
152+
DateTimeNull = new DateTime(2024, 4, 1, 8, 0, 0),
153+
DateTimeOffsetNull = new DateTimeOffset(2024, 4, 1, 8, 0, 0, TimeSpan.FromHours(-6)),
154+
GuidNull = Guid.Empty,
155+
TimeSpanNull = TimeSpan.FromHours(1),
156+
DateOnlyNull = new DateOnly(2022, 12, 1),
157+
TimeOnlyNull = new TimeOnly(1, 30, 0),
158+
};
159+
160+
var right = new DataType
161+
{
162+
Id = 2,
163+
Name = "Test2",
164+
Boolean = true,
165+
Short = 2,
166+
Long = 200,
167+
Float = 200.20F,
168+
Double = 300.35,
169+
Decimal = 456.12M,
170+
DateTime = new DateTime(2024, 5, 1, 8, 0, 0),
171+
DateTimeOffset = new DateTimeOffset(2024, 5, 1, 8, 0, 0, TimeSpan.FromHours(-6)),
172+
Guid = Guid.Empty,
173+
TimeSpan = TimeSpan.FromHours(1),
174+
DateOnly = new DateOnly(2022, 12, 1),
175+
TimeOnly = new TimeOnly(1, 30, 0),
176+
BooleanNull = false,
177+
ShortNull = 2,
178+
LongNull = 200,
179+
FloatNull = 200.20F,
180+
DoubleNull = 300.35,
181+
DecimalNull = 456.12M,
182+
DateTimeNull = new DateTime(2024, 4, 1, 8, 0, 0),
183+
DateTimeOffsetNull = new DateTimeOffset(2024, 4, 1, 8, 0, 0, TimeSpan.FromHours(-6)),
184+
GuidNull = Guid.Empty,
185+
TimeSpanNull = TimeSpan.FromHours(1),
186+
DateOnlyNull = new DateOnly(2022, 12, 1),
187+
TimeOnlyNull = new TimeOnly(1, 30, 0),
188+
};
189+
190+
var isEqual = left.Equals(right);
191+
isEqual.Should().BeFalse();
192+
193+
// check operator !=
194+
isEqual = left != right;
195+
isEqual.Should().BeTrue();
196+
197+
}
198+
199+
[Fact]
200+
public void NotEqualNulls()
201+
{
202+
var left = new DataType
203+
{
204+
Id = 1,
205+
Name = "Test1",
206+
Boolean = false,
207+
Short = 2,
208+
Long = 200,
209+
Float = 200.20F,
210+
Double = 300.35,
211+
Decimal = 456.12M,
212+
DateTime = new DateTime(2024, 5, 1, 8, 0, 0),
213+
DateTimeOffset = new DateTimeOffset(2024, 5, 1, 8, 0, 0, TimeSpan.FromHours(-6)),
214+
Guid = Guid.Empty,
215+
TimeSpan = TimeSpan.FromHours(1),
216+
DateOnly = new DateOnly(2022, 12, 1),
217+
TimeOnly = new TimeOnly(1, 30, 0)
218+
};
219+
220+
var right = new DataType
221+
{
222+
Id = 2,
223+
Name = "Test2",
224+
Boolean = true,
225+
Short = 2,
226+
Long = 200,
227+
Float = 200.20F,
228+
Double = 300.35,
229+
Decimal = 456.12M,
230+
DateTime = new DateTime(2024, 5, 1, 8, 0, 0),
231+
DateTimeOffset = new DateTimeOffset(2024, 5, 1, 8, 0, 0, TimeSpan.FromHours(-6)),
232+
Guid = Guid.Empty,
233+
TimeSpan = TimeSpan.FromHours(1),
234+
DateOnly = new DateOnly(2022, 12, 1),
235+
TimeOnly = new TimeOnly(1, 30, 0)
236+
};
237+
238+
var isEqual = left.Equals(right);
239+
isEqual.Should().BeFalse();
240+
241+
// check operator !=
242+
isEqual = left != right;
243+
isEqual.Should().BeTrue();
244+
245+
}
246+
}

0 commit comments

Comments
 (0)