public void AcceptsEnumerableOnlyReturn() { MethodInfo method = new EnumerableResultMethod(cacheResultTarget.ReturnsEnumerableOnlyAndItems).Method; object[] args = new object[] { "one", "two", "three" }; EnumerableOnlyResult expectedReturnValue = new EnumerableOnlyResult(args); ExpectAttributeRetrieval(method); ExpectCacheKeyGeneration(method, 5, expectedReturnValue.InnerArray); ExpectCacheInstanceRetrieval("results", resultCache); ExpectCallToProceed(expectedReturnValue); ExpectCacheInstanceRetrieval("items", itemCache); // return value should be added to result cache and each item to item cache object returnValue = advice.Invoke(mockInvocation); Assert.AreEqual(1, resultCache.Count); Assert.AreEqual(3, itemCache.Count); Assert.AreSame(expectedReturnValue, returnValue); Assert.AreSame(expectedReturnValue, resultCache.Get(5)); // and again, but without Proceed() and item cache access... ExpectAttributeRetrieval(method); ExpectCacheKeyGeneration(method, 5, IGNORED_ARGS); // cached value should be returned, cache remains unchanged object cachedValue = advice.Invoke(mockInvocation); Assert.AreSame(expectedReturnValue, cachedValue); Assert.AreSame(returnValue, cachedValue); Assert.AreSame(expectedReturnValue, resultCache.Get(5)); Assert.AreEqual(1, resultCache.Count); Assert.AreEqual(3, itemCache.Count); }
public void AcceptsEnumerableOnlyReturn() { MethodInfo method = new EnumerableResultMethod( cacheResultTarget.ReturnsEnumerableOnlyAndItems ).Method; object[] args = new object[] { "one", "two", "three" }; EnumerableOnlyResult expectedReturnValue = new EnumerableOnlyResult(args); ExpectAttributeRetrieval(method); ExpectCacheKeyGeneration(method, 5, expectedReturnValue.InnerArray); ExpectCacheInstanceRetrieval("results", resultCache); ExpectCallToProceed(expectedReturnValue); ExpectCacheInstanceRetrieval("items", itemCache); // return value should be added to result cache and each item to item cache object returnValue = advice.Invoke((IMethodInvocation)mockInvocation.Object); Assert.AreEqual(1, resultCache.Count); Assert.AreEqual(3, itemCache.Count); Assert.AreSame(expectedReturnValue, returnValue); Assert.AreSame(expectedReturnValue, resultCache.Get(5)); // and again, but without Proceed() and item cache access... ExpectAttributeRetrieval(method); ExpectCacheKeyGeneration(method, 5, IGNORED_ARGS); ExpectCacheInstanceRetrieval("results", resultCache); // cached value should be returned, cache remains unchanged object cachedValue = advice.Invoke((IMethodInvocation)mockInvocation.Object); Assert.AreSame(expectedReturnValue, cachedValue); Assert.AreSame(returnValue, cachedValue ); Assert.AreSame(expectedReturnValue, resultCache.Get(5)); Assert.AreEqual( 1, resultCache.Count ); Assert.AreEqual( 3, itemCache.Count ); mockInvocation.Verify(); mockContext.Verify(); }