-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d4190e1
commit 99eb9ff
Showing
7 changed files
with
157 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
mode: ContinuousDelivery | ||
next-version: 1.0.0 | ||
next-version: 1.0.1 | ||
branches: {} | ||
ignore: | ||
sha: [] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
namespace Xer.DomainDriven.Tests.Entities | ||
{ | ||
public class TestValueObject : ValueObject<TestValueObject> | ||
{ | ||
public string Data { get; } | ||
public int Number { get; } | ||
|
||
public TestValueObject(string data, int number) | ||
{ | ||
Data = data; | ||
Number = number; | ||
} | ||
|
||
protected override bool ValueEquals(TestValueObject other) | ||
{ | ||
return Data == other.Data && | ||
Number == other.Number; | ||
} | ||
|
||
protected override HashCode GenerateHashCode() | ||
{ | ||
return HashCode.From(Number, Data); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
using Xer.DomainDriven.Tests.Entities; | ||
using Xunit; | ||
|
||
namespace Xer.DomainDriven.Tests | ||
{ | ||
public class ValueObjectTests | ||
{ | ||
public class EqualsMethod | ||
{ | ||
[Fact] | ||
public void ShouldBeTrueIfValueObjectsMatchByValue() | ||
{ | ||
TestValueObject valueObject1 = new TestValueObject("Test", 123); | ||
TestValueObject valueObject2 = new TestValueObject("Test", 123); | ||
|
||
Assert.True(valueObject1 == valueObject2); | ||
} | ||
|
||
[Fact] | ||
public void ShouldNotBeTrueIfValueObjectsDoNotMatchByValue() | ||
{ | ||
TestValueObject valueObject1 = new TestValueObject("Test", 123); | ||
TestValueObject valueObject2 = new TestValueObject("Test2", 1234); | ||
|
||
Assert.True(valueObject1 != valueObject2); | ||
} | ||
|
||
[Fact] | ||
public void ShouldNotBeTrueIfComparedWithNull() | ||
{ | ||
TestValueObject valueObject1 = new TestValueObject("Test", 123); | ||
TestValueObject valueObject2 = null; | ||
|
||
Assert.True(valueObject1 != valueObject2); | ||
} | ||
} | ||
|
||
public class GetHashCodeMethod | ||
{ | ||
[Fact] | ||
public void ShouldBeSameForTheSameInstance() | ||
{ | ||
TestValueObject valueObject1 = new TestValueObject("Test", 123); | ||
|
||
Assert.True(valueObject1.GetHashCode() == valueObject1.GetHashCode()); | ||
} | ||
|
||
[Fact] | ||
public void ShouldBeSameForTheDifferentInstancesWithSameValues() | ||
{ | ||
TestValueObject valueObject1 = new TestValueObject("Test", 123); | ||
TestValueObject valueObject2 = new TestValueObject("Test", 123); | ||
|
||
Assert.True(valueObject1.GetHashCode() == valueObject2.GetHashCode()); | ||
} | ||
|
||
[Fact] | ||
public void ShouldNotBeSameForTheDifferentInstancesWithDifferentValues() | ||
{ | ||
TestValueObject valueObject1 = new TestValueObject("Test", 123); | ||
TestValueObject valueObject2 = new TestValueObject("Test2", 1234); | ||
|
||
Assert.True(valueObject1.GetHashCode() != valueObject2.GetHashCode()); | ||
} | ||
} | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
Tests/Xer.DomainDriven.Tests/Xer.DomainDriven.Tests.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>netcoreapp2.0</TargetFramework> | ||
|
||
<IsPackable>false</IsPackable> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.5.0" /> | ||
<PackageReference Include="xunit" Version="2.3.1" /> | ||
<PackageReference Include="xunit.runner.visualstudio" Version="2.3.1" /> | ||
<DotNetCliToolReference Include="dotnet-xunit" Version="2.3.1" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\..\Src\Xer.DomainDriven\Xer.DomainDriven.csproj" /> | ||
</ItemGroup> | ||
|
||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters