diff --git a/samples/src/Cache/CacheAspect.cs b/samples/src/Cache/CacheAspect.cs index 8267681a..da11f9c1 100644 --- a/samples/src/Cache/CacheAspect.cs +++ b/samples/src/Cache/CacheAspect.cs @@ -52,7 +52,7 @@ public object Handle( cacheTrigger.Set(key, result, retType, instance); } } - + if (result == NullMarker) return null; return result; } diff --git a/samples/tests/Aspests.Tests/CacheTests.cs b/samples/tests/Aspests.Tests/CacheTests.cs index c65e340b..32439ed5 100644 --- a/samples/tests/Aspests.Tests/CacheTests.cs +++ b/samples/tests/Aspests.Tests/CacheTests.cs @@ -11,6 +11,20 @@ public class CacheTests { class TestClass { + [MemoryCache(3, PerInstanceCache = false)] + public int? Nullable(bool ok) + { + if (ok) return 1; + return null; + } + + [MemoryCache(3, PerInstanceCache = true)] + public int? NullablePerInstance(bool ok) + { + if (ok) return 1; + return null; + } + [MemoryCache(3, PerInstanceCache = false)] public void Do(ref int a) { @@ -164,6 +178,24 @@ public async Task Cache_Aspect_Caches_AsyncTaskMethod_Result() Assert.NotEqual(result4, result); } + [Fact] + public void Cache_Nullable_Method() + { + var target = new TestClass(); + + var i = target.Nullable(true); + Assert.Equal(1, i); + + i = target.Nullable(false); + Assert.Null(i); + + i = target.NullablePerInstance(true); + Assert.Equal(1, i); + + i = target.NullablePerInstance(false); + Assert.Null(i); + } + [Fact] public void Cache_Void_Method() {