-
Notifications
You must be signed in to change notification settings - Fork 3
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
074b766
commit 605f827
Showing
8 changed files
with
237 additions
and
76 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
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
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,77 @@ | ||
using Xunit; | ||
|
||
namespace WrapperValueObject.Tests | ||
{ | ||
[WrapperValueObject(typeof(int))] | ||
public readonly partial struct MeterLength | ||
{ | ||
public static implicit operator CentimeterLength(MeterLength meter) => meter.Value * 100; | ||
} | ||
|
||
[WrapperValueObject(typeof(int))] | ||
public readonly partial struct CentimeterLength | ||
{ | ||
public static implicit operator MeterLength(CentimeterLength centiMeter) => centiMeter.Value / 100; | ||
} | ||
|
||
public class MetricTypesTests | ||
{ | ||
[Fact] | ||
public void Test_Conversion() | ||
{ | ||
MeterLength meters = 2; | ||
|
||
CentimeterLength centiMeters = meters; | ||
|
||
Assert.Equal(200, (int)centiMeters); | ||
} | ||
|
||
[Fact] | ||
public void Test_Add() | ||
{ | ||
MeterLength meters = 2; | ||
|
||
var result = meters + 2; | ||
|
||
Assert.Equal(((int)meters) + 2, (int)result); | ||
Assert.True(meters != result); | ||
Assert.True(meters == 2); | ||
} | ||
|
||
[Fact] | ||
public void Test_Subtract() | ||
{ | ||
MeterLength meters = 5; | ||
|
||
var result = meters - 2; | ||
|
||
Assert.Equal(((int)meters) - 2, (int)result); | ||
Assert.True(meters != result); | ||
Assert.True(meters == 5); | ||
} | ||
|
||
[Fact] | ||
public void Test_Multiply() | ||
{ | ||
MeterLength meters = 5; | ||
|
||
var result = meters * 2; | ||
|
||
Assert.Equal(((int)meters) * 2, (int)result); | ||
Assert.True(meters != result); | ||
Assert.True(meters == 5); | ||
} | ||
|
||
[Fact] | ||
public void Test_Divide() | ||
{ | ||
MeterLength meters = 2; | ||
|
||
var result = meters / 2; | ||
|
||
Assert.Equal(((int)meters) / 2, (int)result); | ||
Assert.True(meters != result); | ||
Assert.True(meters == 2); | ||
} | ||
} | ||
} |
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,62 @@ | ||
using Xunit; | ||
|
||
namespace WrapperValueObject.Tests | ||
{ | ||
[WrapperValueObject(typeof(decimal))] | ||
public readonly partial struct Money | ||
{ | ||
} | ||
|
||
public class MoneyTypeTests | ||
{ | ||
[Fact] | ||
public void Test_Add() | ||
{ | ||
Money money = 2m; | ||
|
||
var result = money + 2m; | ||
var result2 = money + new Money(2m); | ||
|
||
Assert.True(result == result2); | ||
Assert.Equal(((decimal)money) + 2m, (decimal)result); | ||
Assert.True(money != result); | ||
Assert.True(money == 2m); | ||
} | ||
|
||
[Fact] | ||
public void Test_Subtract() | ||
{ | ||
Money money = 5m; | ||
|
||
var result = money - 2m; | ||
|
||
Assert.Equal(((decimal)money) - 2m, (decimal)result); | ||
Assert.True(money != result); | ||
Assert.True(money == 5m); | ||
} | ||
|
||
[Fact] | ||
public void Test_Multiply() | ||
{ | ||
Money money = 5m; | ||
|
||
var result = money * 2m; | ||
|
||
Assert.Equal(((decimal)money) * 2m, (decimal)result); | ||
Assert.True(money != result); | ||
Assert.True(money == 5m); | ||
} | ||
|
||
[Fact] | ||
public void Test_Divide() | ||
{ | ||
Money money = 2m; | ||
|
||
var result = money / 2m; | ||
|
||
Assert.Equal(((decimal)money) / 2m, (decimal)result); | ||
Assert.True(money != result); | ||
Assert.True(money == 2m); | ||
} | ||
} | ||
} |
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 @@ | ||
using System; | ||
using Xunit; | ||
|
||
namespace WrapperValueObject.Tests | ||
{ | ||
[WrapperValueObject] readonly partial struct ProductId { } | ||
|
||
public class ProductIdTypeTests | ||
{ | ||
[Fact] | ||
public void Test_New() | ||
{ | ||
var id = ProductId.New(); | ||
|
||
Assert.NotEqual(Guid.Empty, (Guid)id); | ||
|
||
var id2 = id; | ||
|
||
Assert.Equal(id2, id); | ||
Assert.True(id2 == id); | ||
Assert.NotEqual(ProductId.New(), id); | ||
Assert.True(ProductId.New() != id); | ||
} | ||
} | ||
} |
Oops, something went wrong.