Example #1
0
        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>());
        }
Example #2
0
        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);
        }
Example #3
0
        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);
        }