diff --git a/src/AutoLazy.Tests/GenericTypeTests.cs b/src/AutoLazy.Tests/GenericTypeTests.cs index ebf0b77..e8b465f 100644 --- a/src/AutoLazy.Tests/GenericTypeTests.cs +++ b/src/AutoLazy.Tests/GenericTypeTests.cs @@ -11,11 +11,16 @@ public class GenericTypeTests public void MockGeneric_with_int_should_be_lazy() { var target = new MockGeneric(() => 123); + Assert.AreEqual(0, target.GetValueCount); + var first = target.GetValue(); + Assert.AreEqual(123, first); Assert.AreEqual(1, target.GetValueCount); + var second = target.GetValue(); + Assert.AreEqual(first, second); Assert.AreEqual(1, target.GetValueCount); } @@ -24,13 +29,81 @@ public void MockGeneric_with_int_should_be_lazy() public void MockGeneric_with_string_should_be_lazy() { var target = new MockGeneric(() => Guid.NewGuid().ToString("n")); + Assert.AreEqual(0, target.GetValueCount); + var first = target.GetValue(); + Assert.AreNotEqual(null, first); Assert.AreEqual(1, target.GetValueCount); + var second = target.GetValue(); + Assert.AreEqual(first, second); Assert.AreEqual(1, target.GetValueCount); } + + [Test] + public void MockGeneric_with_null_string_should_be_lazy() + { + var target = new MockGeneric(() => null); + + Assert.AreEqual(0, target.GetValueCount); + + var first = target.GetValue(); + + Assert.AreEqual(1, target.GetValueCount); + + var second = target.GetValue(); + + Assert.AreEqual(first, second); + Assert.AreEqual(1, target.GetValueCount); + } + + [Test] + public void MockGeneric_with_exception_string_should_be_lazy() + { + var target = new MockGeneric(() => throw new ExpectedException()); + + Assert.AreEqual(0, target.GetValueCount); + + object first = null; + ExpectedException firstException = null; + try + { + first = target.GetValue(); + } + catch (ExpectedException e ) + { + firstException = e; + } + + Assert.IsNotNull(firstException); + Assert.AreEqual(1, target.GetValueCount); + + object second = null; + ExpectedException secondException = null; + try + { + second = target.GetValue(); + } + catch (ExpectedException e) + { + secondException = e; + } + + Assert.IsNotNull(secondException); + Assert.AreSame(firstException, secondException ); + Assert.AreEqual(1, target.GetValueCount); + Assert.AreEqual(first, second); + + } + } + + public class ExpectedException:Exception + { + + } + }