|
| 1 | +using Xunit; |
| 2 | + |
| 3 | +namespace AltaSoft.DomainPrimitives.UnitTests.TransformableTests; |
| 4 | + |
| 5 | +public class NestedDomainPrimitivesTests |
| 6 | +{ |
| 7 | + [Fact] |
| 8 | + public void CanCreateNestedString_FromToUpperString() |
| 9 | + { |
| 10 | + var toUpper = new ToUpperString("HELLO"); |
| 11 | + var nested = new NestedString(toUpper); |
| 12 | + Assert.NotNull(nested); |
| 13 | + Assert.Equal("HELLO", nested); |
| 14 | + |
| 15 | + var nested2 = new NestedString("HELLO"); |
| 16 | + Assert.Equal(nested, nested2); |
| 17 | + } |
| 18 | + |
| 19 | + [Fact] |
| 20 | + public void CanCreateNestedString_FromString_ImplicitCast() |
| 21 | + { |
| 22 | + NestedString nested = "HELLO"; |
| 23 | + Assert.NotNull(nested); |
| 24 | + |
| 25 | + NestedString? nestedNull = (string?)null; |
| 26 | + Assert.Null(nestedNull); |
| 27 | + } |
| 28 | + |
| 29 | + [Fact] |
| 30 | + public void CanCreateNestedString_FromToUpperString_ImplicitCast() |
| 31 | + { |
| 32 | + ToUpperString toUpper = "HELLO"; |
| 33 | + NestedString nested = toUpper; |
| 34 | + Assert.NotNull(nested); |
| 35 | + |
| 36 | + NestedString? nestedNull = (ToUpperString?)null; |
| 37 | + Assert.Null(nestedNull); |
| 38 | + } |
| 39 | + |
| 40 | + [Fact] |
| 41 | + public void CreatingNestedString_WithError_Throws() |
| 42 | + { |
| 43 | + ToUpperString toUpper = "ErrorValue"; |
| 44 | + Assert.Throws<InvalidDomainValueException>(() => new NestedString(toUpper)); |
| 45 | + } |
| 46 | + |
| 47 | + [Fact] |
| 48 | + public void CreatingNestedString_FromStringWithError_Throws() |
| 49 | + { |
| 50 | + Assert.Throws<InvalidDomainValueException>(() => { NestedString _ = "ErrorValue"; }); |
| 51 | + } |
| 52 | + |
| 53 | + [Fact] |
| 54 | + public void CanCreateNestedInt_FromAbsoluteInt() |
| 55 | + { |
| 56 | + var abs = new AbsoluteInt(5); |
| 57 | + var nested = new NestedInt(abs); |
| 58 | + Assert.Equal(5, (int)nested); |
| 59 | + |
| 60 | + var nested2 = new NestedInt(5); |
| 61 | + Assert.Equal(nested, nested2); |
| 62 | + } |
| 63 | + |
| 64 | + [Fact] |
| 65 | + public void CanCreateNestedInt_FromInt_ImplicitCast() |
| 66 | + { |
| 67 | + NestedInt nested = 5; |
| 68 | + Assert.Equal(5, (int)nested); |
| 69 | + |
| 70 | + NestedInt? nestedNull = (int?)null; |
| 71 | + Assert.Null(nestedNull); |
| 72 | + } |
| 73 | + |
| 74 | + [Fact] |
| 75 | + public void CanCreateNestedInt_FromAbsoluteInt_ImplicitCast() |
| 76 | + { |
| 77 | + AbsoluteInt abs = 5; |
| 78 | + NestedInt nested = abs; |
| 79 | + Assert.Equal(5, (int)nested); |
| 80 | + |
| 81 | + NestedInt? nestedNull = (AbsoluteInt?)null; |
| 82 | + Assert.Null(nestedNull); |
| 83 | + } |
| 84 | + |
| 85 | + [Fact] |
| 86 | + public void CreatingNestedInt_WithError_Throws() |
| 87 | + { |
| 88 | + AbsoluteInt abs = 11; |
| 89 | + Assert.Throws<InvalidDomainValueException>(() => new NestedInt(abs)); |
| 90 | + } |
| 91 | + |
| 92 | + [Fact] |
| 93 | + public void CreatingNestedInt_FromIntWithError_Throws() |
| 94 | + { |
| 95 | + Assert.Throws<InvalidDomainValueException>(() => { NestedInt n = 11; }); |
| 96 | + } |
| 97 | +} |
0 commit comments