public void IsLoginOK_LoggerError_CallsWs()
        {
            IWebService svc = Substitute.For<IWebService>();
            ILogger fake = Substitute.For<ILogger>();
            fake.When(logger => logger.Write(Arg.Any<string>()))
                .Do(info =>
                        {
                            throw new Exception("fake exception");
                        });

            var lm = new LoginManagerWithMockAndStub(fake,svc);
            lm.IsLoginOK("", "");

            svc.Received().Write(Arg.Any<string>());
        }
        public void IsLoginOK_LoggerThrowsException_WritesToWebService()
        {
            DynamicMock stubLog     = new DynamicMock(typeof(ILogger));
            DynamicMock mockService = new DynamicMock(typeof(IWebService));

            stubLog.ExpectAndThrow("Write", new LoggerException("fake exception"), "yo");
            mockService.Expect("Write", "got exception");

            var loginManager =
                new LoginManagerWithMockAndStub((ILogger)stubLog.MockInstance,
                                                (IWebService)mockService.MockInstance);

            loginManager.IsLoginOK("", "");

            mockService.Verify();
        }
        public void IsLoginOK_LoggerThrowsException_CallsToWebService()
        {
            FakeLogger2 stubLog = new FakeLogger2();

            stubLog.WillThrow = new LoggerException("fake exception");

            FakeWebService mockService = new FakeWebService();


            LoginManagerWithMockAndStub loginManager =
                new LoginManagerWithMockAndStub(stubLog, mockService);

            loginManager.IsLoginOK("", "");

            StringAssert.Contains("got exception", mockService.Message);
        }
示例#4
0
        public void IsLoginOK_LogError_WritesToWebService()
        {
            var stublog = MockRepository.GenerateStub <ILogger>();

            stublog.Expect(logger => logger.Write("yo"))
            .Throw(new LoggerException("fake exception"));

            var mockService = MockRepository.GenerateMock <IWebService>();

            LoginManagerWithMockAndStub lm =
                new LoginManagerWithMockAndStub(stublog, mockService);

            lm.IsLoginOK("a", "b");

            mockService.AssertWasCalled(service => service.Write("got exception"));
        }
        public void IsLoginOK_LoggerError_CallsWs()
        {
            IWebService svc  = Substitute.For <IWebService>();
            ILogger     fake = Substitute.For <ILogger>();

            fake.When(logger => logger.Write(Arg.Any <string>()))
            .Do(info =>
            {
                throw new LoggerException("fake exception");
            });

            var lm = new LoginManagerWithMockAndStub(fake, svc);

            lm.IsLoginOK("", "");

            svc.Received().Write(Arg.Any <string>());
        }
示例#6
0
        public void IsLoginOK_LogError_WritesToWebService()
        {
            Mock <ILogger> stubLog = new Mock <ILogger>();

            stubLog.Setup(x => x.Write(It.IsAny <string>()))
            .Throws(new LoggerException("fake exception"));


            Mock <IWebService> mockService = new Mock <IWebService>();

            LoginManagerWithMockAndStub lm =
                new LoginManagerWithMockAndStub(stubLog.Object, mockService.Object);

            lm.IsLoginOK("", "");

            mockService.Verify(svc => svc.Write("got exception"));
        }
示例#7
0
        public void IsLoginOK_LoggerThrowsException_CallsWebService()
        {
            ILogger fakeLogger = Isolate.Fake.Instance <ILogger>();

            Isolate
            .WhenCalled(() => fakeLogger.Write(""))
            .WillThrow(new LoggerException());

            IWebService fakeWebService = Isolate.Fake.Instance <IWebService>();

            LoginManagerWithMockAndStub lm =
                new LoginManagerWithMockAndStub(fakeLogger, fakeWebService);

            lm.IsLoginOK("", "");

            Isolate.Verify
            .WasCalledWithAnyArguments(() => fakeWebService.Write(""));
        }
        public void IsLoginOK_WhenLoggerThrows_CallsWebService()
        {
            ILogger     fakeLog = A.Fake <ILogger>();
            IWebService fakeWs  = A.Fake <IWebService>();

            A.CallTo(() => fakeLog.Write(A <string> .Ignored))
            .Throws(new LoggerException());


            LoginManagerWithMockAndStub lm =
                new LoginManagerWithMockAndStub(fakeLog, fakeWs);

            lm.IsLoginOK("", "");

            A.CallTo(() => fakeWs.Write(
                         A <string> .That.Contains("got exception")))
            .MustHaveHappened();
        }
        public void IsLoginOK_WhenLoggerThrows_CallsWebService()
        {
            var fac        = new MockFactory();
            var webservice = fac.CreateMock <IWebService>();

            webservice.Expects.AtLeastOne.Method(_ => _.Write(null)).With(NMock.Is.StringContaining("s"));

            var logger = fac.CreateMock <ILogger>();

            logger.Stub.Out.Method(_ => _.Write(null))
            .WithAnyArguments()
            .Will(Throw.Exception(new Exception("dude this is fake")));

            var lm =
                new LoginManagerWithMockAndStub(logger.MockObject, webservice.MockObject);

            lm.IsLoginOK("a", "b");


            webservice.VerifyAllExpectations();
        }