Exemplo n.º 1
0
        public void Should_invoke_listener_after_call_has_been_intercepted_when_application_of_rule_throws()
        {
            // Arrange
            var interceptedCall = A.Fake <IWritableFakeObjectCall>(x => x.Implements(typeof(ICompletedFakeObjectCall)));

            A.CallTo(() => interceptedCall.AsReadOnly()).Returns((ICompletedFakeObjectCall)interceptedCall);

            var listener = A.Fake <IInterceptionListener>();
            var manager  = new RaisableFakeManager();

            var selectedRule = A.Fake <IFakeObjectCallRule>();

            A.CallTo(() => selectedRule.IsApplicableTo(interceptedCall)).Returns(true);
            A.CallTo(() => selectedRule.Apply(A <IInterceptedFakeObjectCall> ._)).Throws(new Exception());

            manager.AddRuleFirst(selectedRule);
            manager.AddInterceptionListener(listener);

            // Act
            try
            {
                manager.RaiseCallIntercepted(new CallInterceptedEventArgs(interceptedCall));
            }
            catch
            {
            }

            // Assert
            A.CallTo(() => listener.OnAfterCallIntercepted((ICompletedFakeObjectCall)interceptedCall, selectedRule)).MustHaveHappened();
        }
Exemplo n.º 2
0
        public void Should_invoke_listeners_in_correct_order()
        {
            // Arrange
            var manager   = new RaisableFakeManager();
            var listener1 = A.Fake <IInterceptionListener>();
            var listener2 = A.Fake <IInterceptionListener>();

            // Act
            manager.AddInterceptionListener(listener1);
            manager.AddInterceptionListener(listener2);

            // Assert
            using (var scope = Fake.CreateScope())
            {
                manager.RaiseCallIntercepted(new CallInterceptedEventArgs(A.Dummy <IWritableFakeObjectCall>()));

                using (scope.OrderedAssertions())
                {
                    A.CallTo(() => listener2.OnBeforeCallIntercepted(A <IFakeObjectCall> ._)).MustHaveHappened();
                    A.CallTo(() => listener1.OnBeforeCallIntercepted(A <IFakeObjectCall> ._)).MustHaveHappened();
                    A.CallTo(() => listener1.OnAfterCallIntercepted(A <ICompletedFakeObjectCall> ._, A <IFakeObjectCallRule> ._)).MustHaveHappened();
                    A.CallTo(() => listener2.OnAfterCallIntercepted(A <ICompletedFakeObjectCall> ._, A <IFakeObjectCallRule> ._)).MustHaveHappened();
                }
            }
        }
Exemplo n.º 3
0
        public void Should_invoke_listener_when_call_is_intercepted()
        {
            // Arrange
            var interceptedCall = A.Dummy <IWritableFakeObjectCall>();

            var listener = A.Fake <IInterceptionListener>();
            var manager  = new RaisableFakeManager();

            manager.AddInterceptionListener(listener);

            // Act
            manager.RaiseCallIntercepted(new CallInterceptedEventArgs(interceptedCall));

            // Assert
            A.CallTo(() => listener.OnBeforeCallIntercepted(interceptedCall)).MustHaveHappened();
        }