public void CreateCorrectInstance_WhenParametersAreValid() { // Arrange var shouldCacheInvocationReturnValueStrategy = new Mock <IShouldCacheInvocationReturnValueStrategy>(); var decoratedCachingInterceptor = new Mock <ICachingInterceptor>(); // Act var actualInstance = new ManagedCachingInterceptor(shouldCacheInvocationReturnValueStrategy.Object, decoratedCachingInterceptor.Object); // Assert Assert.That(actualInstance, Is.Not.Null); Assert.That(actualInstance, Is.InstanceOf <IInterceptor>()); Assert.That(actualInstance, Is.InstanceOf <ICachingInterceptor>()); }
public void InvokeIShouldCacheInvocationReturnValueStrategyShouldCacheReturnValueMethodOnceWithCorrectParameter() { // Arrange var shouldCacheInvocationReturnValueStrategy = new Mock <IShouldCacheInvocationReturnValueStrategy>(); var decoratedCachingInterceptor = new Mock <ICachingInterceptor>(); var managedCachingInterceptor = new ManagedCachingInterceptor(shouldCacheInvocationReturnValueStrategy.Object, decoratedCachingInterceptor.Object); var invocation = new Mock <IInvocation>(); // Act managedCachingInterceptor.Intercept(invocation.Object); // Assert shouldCacheInvocationReturnValueStrategy.Verify(s => s.ShouldCacheReturnValue(invocation.Object), Times.Once); }
public void InvokeIInvocationProceedMethodWithCorrectParameter_WhenIShouldCacheInvocationReturnValueStrategyReturnsFalse() { // Arrange var shouldCacheInvocationReturnValueStrategy = new Mock <IShouldCacheInvocationReturnValueStrategy>(); var decoratedCachingInterceptor = new Mock <ICachingInterceptor>(); var managedCachingInterceptor = new ManagedCachingInterceptor(shouldCacheInvocationReturnValueStrategy.Object, decoratedCachingInterceptor.Object); shouldCacheInvocationReturnValueStrategy.Setup(s => s.ShouldCacheReturnValue(It.IsAny <IInvocation>())).Returns(false); var invocation = new Mock <IInvocation>(); // Act managedCachingInterceptor.Intercept(invocation.Object); // Assert invocation.Verify(i => i.Proceed(), Times.Once); }