public void CallingAnInterceptedMethod_InterceptorThatChangesTheInputParameters_GetsForwardedToTheInterceptee()
        {
            // Arrange
            string expectedValue = "XYZ";

            var container = new Container();

            var interceptee = new WithOutAndRef();

            var interceptor = new DelegateInterceptor();

            interceptor.Intercepting += invocation =>
            {
                invocation.Arguments[0] = expectedValue;
            };

            container.RegisterInstance <IWithOutAndRef>(interceptee);
            container.InterceptWith(interceptor, IsInterface);

            var intercepted = container.GetInstance <IWithOutAndRef>();

            // Act
            string refValue = "Something different";
            string unused;

            intercepted.Operate(ref refValue, out unused);

            // Assert
            Assert.AreEqual(expectedValue, interceptee.SuppliedRefValue);
        }
        public void CallingAnInterceptedMethod_InterceptorThatChangesAnOutputParameter_OutputParameterFlowsBackToTheCaller()
        {
            // Arrange
            string expectedOutValue = "KLM";

            var container = new Container();

            var interceptee = new WithOutAndRef();

            var interceptor = new DelegateInterceptor();

            interceptor.Intercepted += invocation =>
            {
                invocation.Arguments[1] = expectedOutValue;
            };

            container.RegisterInstance <IWithOutAndRef>(interceptee);
            container.InterceptWith(interceptor, IsInterface);

            var intercepted = container.GetInstance <IWithOutAndRef>();

            // Act
            string unused = null;
            string actualOutValue;

            intercepted.Operate(ref unused, out actualOutValue);

            // Assert
            Assert.AreEqual(expectedOutValue, actualOutValue);
        }
        public void CallingInterceptedMethodWithRefArgument_InterceptedWithPassThroughInterceptor_ChangesTheRefValue()
        {
            // Arrange
            string expectedRefValue = "ABC";

            var container = new Container();

            var interceptee = new WithOutAndRef {
                OutputRefValue = expectedRefValue
            };

            container.RegisterInstance <IWithOutAndRef>(interceptee);

            container.InterceptWith <FakeInterceptor>(IsInterface);

            var intercepted = container.GetInstance <IWithOutAndRef>();

            // Act
            string unused;
            string actualRefValue = null;

            intercepted.Operate(ref actualRefValue, out unused);

            // Assert
            Assert.AreEqual(expectedRefValue, actualRefValue);
        }
        public void CallingInterceptedMethodWithOutArgument_InterceptedWithPassThroughInterceptor_ReturnsTheExpectedOutValue()
        {
            // Arrange
            string expectedOutValue = "DEF";

            var container = new Container();

            var interceptee = new WithOutAndRef {
                OutValue = expectedOutValue
            };

            container.RegisterInstance <IWithOutAndRef>(interceptee);

            container.InterceptWith <FakeInterceptor>(IsInterface);

            var intercepted = container.GetInstance <IWithOutAndRef>();

            // Act
            string actualOutValue;
            string unused = null;

            intercepted.Operate(ref unused, out actualOutValue);

            // Assert
            Assert.AreEqual(expectedOutValue, actualOutValue);
        }
        public void CallingInterceptedMethodWithReturnValue_InterceptedWithPassThroughInterceptor_ReturnsTheExpectedValue()
        {
            // Arrange
            int expectedReturnValue = 3;

            var container = new Container();

            var interceptee = new WithOutAndRef {
                ReturnValue = expectedReturnValue
            };

            container.RegisterInstance <IWithOutAndRef>(interceptee);

            container.InterceptWith <FakeInterceptor>(IsInterface);

            var intercepted = container.GetInstance <IWithOutAndRef>();

            // Act
            string unused1 = null;
            string unused2;
            int    actualReturnValue = intercepted.Operate(ref unused1, out unused2);

            // Assert
            Assert.AreEqual(expectedReturnValue, actualReturnValue);
        }
        public void CallingInterceptedMethodWithRefArgument_InterceptedWithPassThroughInterceptor_PassesTheRefArgumentToTheInterceptee()
        {
            // Arrange
            string expectedRefValue = "ABC";

            var container = new Container();

            var interceptee = new WithOutAndRef();

            container.RegisterSingleton <IWithOutAndRef>(interceptee);

            container.InterceptWith <FakeInterceptor>(IsInterface);

            var intercepted = container.GetInstance <IWithOutAndRef>();

            // Act
            string refValue = expectedRefValue;
            string unused;

            intercepted.Operate(ref refValue, out unused);

            // Assert
            Assert.AreEqual(expectedRefValue, interceptee.SuppliedRefValue);
        }
        public void CallingAnInterceptedMethod_InterceptorThatChangesAnOutputParameter_OutputParameterFlowsBackToTheCaller()
        {
            // Arrange  
            string expectedOutValue = "KLM";

            var container = new Container();

            var interceptee = new WithOutAndRef();

            var interceptor = new DelegateInterceptor();

            interceptor.Intercepted += invocation =>
            {
                invocation.Arguments[1] = expectedOutValue;
            };

            container.RegisterSingleton<IWithOutAndRef>(interceptee);
            container.InterceptWith(interceptor, IsInterface);

            var intercepted = container.GetInstance<IWithOutAndRef>();

            // Act
            string unused = null;
            string actualOutValue;
            intercepted.Operate(ref unused, out actualOutValue);

            // Assert
            Assert.AreEqual(expectedOutValue, actualOutValue);
        }
        public void CallingAnInterceptedMethod_InterceptorThatChangesTheInputParameters_GetsForwardedToTheInterceptee()
        {
            // Arrange  
            string expectedValue = "XYZ";

            var container = new Container();

            var interceptee = new WithOutAndRef();

            var interceptor = new DelegateInterceptor();

            interceptor.Intercepting += invocation =>
            {
                invocation.Arguments[0] = expectedValue;
            };

            container.RegisterSingleton<IWithOutAndRef>(interceptee);
            container.InterceptWith(interceptor, IsInterface);

            var intercepted = container.GetInstance<IWithOutAndRef>();

            // Act
            string refValue = "Something different";
            string unused;
            intercepted.Operate(ref refValue, out unused);

            // Assert
            Assert.AreEqual(expectedValue, interceptee.SuppliedRefValue);
        }
        public void CallingInterceptedMethodWithOutArgument_InterceptedWithPassThroughInterceptor_ReturnsTheExpectedOutValue()
        {
            // Arrange
            string expectedOutValue = "DEF";

            var container = new Container();

            var interceptee = new WithOutAndRef { OutValue = expectedOutValue };

            container.RegisterSingleton<IWithOutAndRef>(interceptee);

            container.InterceptWith<FakeInterceptor>(IsInterface);

            var intercepted = container.GetInstance<IWithOutAndRef>();

            // Act
            string actualOutValue;
            string unused = null;
            intercepted.Operate(ref unused, out actualOutValue);

            // Assert
            Assert.AreEqual(expectedOutValue, actualOutValue);
        }
        public void CallingInterceptedMethodWithRefArgument_InterceptedWithPassThroughInterceptor_PassesTheRefArgumentToTheInterceptee()
        {
            // Arrange
            string expectedRefValue = "ABC";

            var container = new Container();

            var interceptee = new WithOutAndRef();

            container.RegisterSingleton<IWithOutAndRef>(interceptee);

            container.InterceptWith<FakeInterceptor>(IsInterface);

            var intercepted = container.GetInstance<IWithOutAndRef>();

            // Act
            string refValue = expectedRefValue;
            string unused;
            intercepted.Operate(ref refValue, out unused);

            // Assert
            Assert.AreEqual(expectedRefValue, interceptee.SuppliedRefValue);
        }
        public void CallingInterceptedMethodWithReturnValue_InterceptedWithPassThroughInterceptor_ReturnsTheExpectedValue()
        {
            // Arrange
            int expectedReturnValue = 3;

            var container = new Container();

            var interceptee = new WithOutAndRef { ReturnValue = expectedReturnValue };

            container.RegisterSingleton<IWithOutAndRef>(interceptee);

            container.InterceptWith<FakeInterceptor>(IsInterface);

            var intercepted = container.GetInstance<IWithOutAndRef>();

            // Act
            string unused1 = null;
            string unused2;
            int actualReturnValue = intercepted.Operate(ref unused1, out unused2);

            // Assert
            Assert.AreEqual(expectedReturnValue, actualReturnValue);
        }