Exemplo n.º 1
0
        public void Analyze_LoggerThrows_CallsWebService()
        {
            FakeWebService mockWebService = new FakeWebService();
            FakeLogger2    stubLogger     = new FakeLogger2();

            stubLogger.WillThrow = new Exception("fake exception");
            var analyzer2 =
                new LogAnalyzer2(stubLogger, mockWebService);

            analyzer2.MinNameLength = 8;
            string tooShortFileName = "abc.ext";

            analyzer2.Analyze(tooShortFileName);
            Assert.That(mockWebService.MessageToWebService, Is.StringContaining("fake exception"));
        }
Exemplo n.º 2
0
        public void Analyze_LoggerThrows_CallsWebService_NSub()
        {
            //Arrange
            IWebService fakeWebService = Substitute.For <IWebService>();
            ILogger     fakeLogger     = Substitute.For <ILogger>();

            fakeLogger.When(x => x.LogError(Arg.Any <string>())).Do(info => { throw new Exception("some fake exception"); });
            LogAnalyzer2 logAnalyzer = new LogAnalyzer2(fakeLogger, fakeWebService);

            logAnalyzer.MinNameLength = 20;

            //Act
            logAnalyzer.Analyze("short.txt");

            //Assert
            fakeWebService.Received().Write(Arg.Is <string>(s => s.Contains("some fake exception")));
        }