-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathValueObjectTests.cs
More file actions
70 lines (57 loc) · 1.73 KB
/
Copy pathValueObjectTests.cs
File metadata and controls
70 lines (57 loc) · 1.73 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
using SmartMovieCatalog.Domain.Common;
namespace SmartMovieCatalog.Domain.Tests.Common;
public sealed class ValueObjectTests
{
[Fact]
public void Equals_WithSameTypeAndSameComponents_ReturnsTrue()
{
SampleValueObject left = new("same", 7);
SampleValueObject right = new("same", 7);
Assert.True(left.Equals(right));
Assert.Equal(left.GetHashCode(), right.GetHashCode());
}
[Fact]
public void Equals_WithDifferentComponents_ReturnsFalse()
{
SampleValueObject left = new("left", 7);
SampleValueObject right = new("right", 8);
Assert.False(left.Equals(right));
}
[Fact]
public void Equals_WithDifferentRuntimeType_ReturnsFalse()
{
SampleValueObject sample = new("same", 7);
OtherValueObject other = new("same", 7);
Assert.False(sample.Equals(other));
}
private sealed class SampleValueObject : ValueObject
{
private readonly string _name;
private readonly int _version;
public SampleValueObject(string name, int version)
{
_name = name;
_version = version;
}
protected override IEnumerable<object?> GetEqualityComponents()
{
yield return _name;
yield return _version;
}
}
private sealed class OtherValueObject : ValueObject
{
private readonly string _name;
private readonly int _version;
public OtherValueObject(string name, int version)
{
_name = name;
_version = version;
}
protected override IEnumerable<object?> GetEqualityComponents()
{
yield return _name;
yield return _version;
}
}
}