public void Analyze_LoggerThrows_CallsWebServiceWithNSubObject()
        {
            var mockWebService = Substitute.For <IWebService>();

            var stubLogger = Substitute.For <ILogger>();

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

            var analyzer = new LogAnalyzer(stubLogger, mockWebService);

            analyzer.MinNameLength = 10;
            analyzer.UseInfoObject = true;
            string tooShortFileName = "abc.ext";

            analyzer.Analyze(tooShortFileName);

            // Compare contents of an object
            // Default: Readability may suffer ...
            //mockWebService.Received().Write(Arg.Is<ErrorInfo>(info => info.Severity == 1000
            //                                                  && info.Message.Contains("fake exception")));

            // Simpler:
            // Create object that you expect to receive
            var expected = new ErrorInfo(1000, "fake exception");

            // Assert that you got exactly the same object (essentially assert.equals())
            mockWebService.Received().Write(expected);

            // Note that since you can't use argument matchers to see if a string contains some value, tests are a little less robust for future changes.
            // For example, any change to the string, including white space, will fail the test unless the test is updated.
        }
        public void Analyze_WhenExceptionThrown_EmailIsSent()
        {
            var mocks = new MockRepository();
            var stubWebService = mocks.Stub<IWebService>();
            var mockEmailSender = mocks.DynamicMock<IEmailSender>();

            using (mocks.Record())
            {
                stubWebService.LogError("Anything");
                LastCall.Constraints(Is.Anything());
                LastCall.Throw(new Exception("Fake Exception"));

                mockEmailSender.SendEmail("to", "subject", "Fake Exception");
            }

            var logAnalyzer = new LogAnalyzer
            {
                EmailSender = mockEmailSender,
                WebService = stubWebService
            };

            logAnalyzer.Analyze("abc.txt");

            mocks.Verify(mockEmailSender);
        }
        public void Analyze_EmptyFile_ThrowException()
        {
            LogAnalyzer la = new LogAnalyzer();

            la.Analyze("myemptyfile.txt");
            //测试的其余部分
        }
Beispiel #4
0
        public void Analyze_EmptyFile_ThrowsException()
        {
            LogAnalyzer la = new LogAnalyzer();

            la.Analyze("myemptyfile.txt");
            // rest of test
        }
Beispiel #5
0
        public void Analyze_EmptyFile_ThrowsException()
        {
           FakeTheLogger();

           LogAnalyzer la = new LogAnalyzer();
           la.Analyze("myemptyfile.txt");
            //rest of test
        }
Beispiel #6
0
        public void Analyze_EmptyFile_ThrowsException()
        {
            LoggingFacility.Logger = Substitute.For<ILogger>();

            LogAnalyzer la = new LogAnalyzer();
            la.Analyze("myemptyfile.txt");
            //rest of test
        }
Beispiel #7
0
        //[Test]
        public void Analyze_TooShortFileName_CallsWebService()
        {
            var    mockService      = new ManualMockService();
            var    log              = new LogAnalyzer(mockService);
            string tooShortFileName = "abc.ext";

            log.Analyze(tooShortFileName);
            Assert.AreEqual("Filename too short:abc.ext", mockService.LastError);
        }
Beispiel #8
0
    public static void EditorLogAnalyze()
    {
        LogAnalyzer a = new LogAnalyzer();
        LogReporter r = a.Analyze();

        ShowReportEditorWindow window = (ShowReportEditorWindow)EditorWindow.GetWindow(typeof(ShowReportEditorWindow));

        window.reportText = r.ToString();
    }
Beispiel #9
0
        //[Test]
        public void Analyse_NameLength()
        {
            var    mockService = new MockService();
            var    log         = new LogAnalyzer(mockService);
            string short_name  = "abc.ext";

            log.Analyze(short_name);
            Assert.AreEqual("Filename too short:abc.ext", mockService.LastError);
        }
        public void Analyze_FileNameTooShort_CallLogger()
        {
            ILogger logger   = Substitute.For <ILogger>();
            var     analyzer = new LogAnalyzer(logger);

            analyzer.MinNameLength = 6;
            analyzer.Analyze("a.txt");
            logger.Received().LogError("Filename too short:a.txt");
        }
Beispiel #11
0
        public void Analyze_TooShortFileName_CallsWebService()
        {
            FakeWebService mockService      = new FakeWebService();
            LogAnalyzer    log              = new LogAnalyzer(mockService);
            string         tooShortFileName = "abc.ext";

            log.Analyze(tooShortFileName);
            StringAssert.Contains("Filename too short: " + tooShortFileName, mockService.LastError);
        }
        public void Analyze_EmptyFile_ThrowsException()
        {
            LoggingFacility.Logger = Substitute.For <ILogger>();

            LogAnalyzer la = new LogAnalyzer();

            la.Analyze("myemptyfile.txt");
            //rest of test
        }
Beispiel #13
0
        public void Analyze_TooShortFileName_CallLogger()
        {
            ILogger     logger   = MockRepository.GenerateMock <ILogger>();
            LogAnalyzer analyzer = new LogAnalyzer(logger);

            analyzer.MinNameLength = 6;
            analyzer.Analyze("a.txt");

            logger.AssertWasCalled(x => x.LogError("Too short name: a.txt"));
        }
        public void Analyze_TooShortFileName_CallsWebServices()
        {
            FakeWebServices fake      = new FakeWebServices();
            LogAnalyzer     analyzer  = new LogAnalyzer(fake);
            string          shortName = "asdas";

            analyzer.Analyze(shortName);

            StringAssert.Contains("file name too short: asdas", fake.lastError);
        }
Beispiel #15
0
        public void WhenAnalyze_ShouldReturnTooShortFileName()
        {
            var mockService = new MockService();
            var log = new LogAnalyzer(mockService);
            string tooShortFileName = "abc.ext";

            log.Analyze(tooShortFileName);

            Assert.That(mockService.LastError, Is.EqualTo("Filename too short:abc.ext"));
        }
Beispiel #16
0
        public void WhenAnalyze_ShouldReturnTooShortFileName()
        {
            var    mockService      = new MockService();
            var    log              = new LogAnalyzer(mockService);
            string tooShortFileName = "abc.ext";

            log.Analyze(tooShortFileName);

            Assert.That(mockService.LastError, Is.EqualTo("Filename too short:abc.ext"));
        }
Beispiel #17
0
        public void Analyze_TooShortFileName_CallLogger()
        {
            IWebService logger   = Substitute.For <IWebService>();
            LogAnalyzer analyzer = new LogAnalyzer(logger);

            analyzer.MinNameLength = 6;
            analyzer.Analyze("a.txt");

            logger.Received().LogError("Filename too short:a.txt");
        }
        public void Analyze_EmptyFile_ThrowsException()
        {
            // Call base class helper method.
            FakeTheLogger();

            LogAnalyzer la = new LogAnalyzer();

            la.Analyze("myemptyfile.txt");
            // rest of test
        }
        public void Analyze_LongEnoughFileName_CallsWebService()
        {
            FakeWebService mockService      = new FakeWebService();
            LogAnalyzer    logAn            = new LogAnalyzer(mockService);
            string         tooShortFileName = "abcdefgh.ext";

            logAn.Analyze(tooShortFileName);

            Assert.IsNull(mockService.LastError);
        }
Beispiel #20
0
        public void Analyze_TooShortFileName_CallLogger()
        {
            ILoger      logger   = Substitute.For <ILoger>();
            LogAnalyzer analyzer = new LogAnalyzer(logger);

            analyzer.MinNameLength = 6;
            analyzer.Analyze("a.txt");
            logger.Received().LogError("Filename too short:a.txt");
            StringAssert.Contains("too short", logger.LastError);
        }
Beispiel #21
0
        public void Analyze_ToShortFileName_CallLogger()
        {
            ILogger     logger   = Substitute.For <ILogger>();
            LogAnalyzer analyzer = new LogAnalyzer(logger);

            analyzer.MinNameLength = 6;
            analyzer.Analyze("a.txt");

            logger.Received().LogError("Nazwa pliku jest za krótka: a.txt");
        }
Beispiel #22
0
        public void Analyze_NameToShort_CallsLogger()
        {
            ILogger fakeLogger = Substitute.For <ILogger>();

            LogAnalyzer analyzer = new LogAnalyzer(fakeLogger);

            analyzer.Analyze("a.txt");

            fakeLogger.Received().LogError("Filename too short:a.txt");
        }
Beispiel #23
0
        public void Analyze_TooShortFileName_CallLogger()
        {
            FakeLogger  logger   = new FakeLogger();
            LogAnalyzer analyzer = new LogAnalyzer(logger);

            analyzer.MinNameLength = 6;
            analyzer.Analyze("a.txt");

            StringAssert.Contains("Too short name", logger.LastError);
        }
        public void CreateMock_WithReplayAll_AAA()
        {
            MockRepository mockEngine       = new MockRepository();
            IWebService    simualtedService = mockEngine.DynamicMock <IWebService>();
            LogAnalyzer    log = new LogAnalyzer(simualtedService);

            mockEngine.ReplayAll();
            log.Analyze("abc.ext");

            simualtedService.AssertWasCalled(svc => svc.LogError("파일명이 너무 짧음:abc.ext"));
        }
Beispiel #25
0
        public void Analyze_SimpleStringLine_UsesDefaulTabDelimiterToParseFields2()
        {
            LogAnalyzer log = new LogAnalyzer();
            AnalyzedOutput expected = new AnalyzedOutput();
            expected.AddLine("10:05", "Open", "Roy");

            AnalyzedOutput output =
                log.Analyze("10:05\tOpen\tRoy");

            Assert.AreEqual(expected,output);
        }
Beispiel #26
0
        public void Analyze_SimpleStringLine_UsesDefaulTabDelimiterToParseFields()
        {
            LogAnalyzer log = new LogAnalyzer();
            AnalyzedOutput output =
                log.Analyze("10:05\tOpen\tRoy");

            Assert.AreEqual(1,output.LineCount);
            Assert.AreEqual("10:05",output.GetLine(1)[0]);
            Assert.AreEqual("Open",output.GetLine(1)[1]);
            Assert.AreEqual("Roy",output.GetLine(1)[2]);
        }
Beispiel #27
0
        public void Analyze_TooShortFileName_CallLoggerArgMatchers()
        {
            ILogger logger = Substitute.For <ILogger>();

            LogAnalyzer analyzer = new LogAnalyzer(logger);

            analyzer.MinNameLength = 6;
            analyzer.Analyze("a.txt");

            logger.Received().LogError(Arg.Is <string>(s => s.Contains("too short")));
        }
Beispiel #28
0
        public void Analyze_SimpleStringLine_UsesDefaulTabDelimiterToParseFields()
        {
            LogAnalyzer    log    = new LogAnalyzer();
            AnalyzedOutput output =
                log.Analyze("10:05\tOpen\tRoy");

            Assert.AreEqual(1, output.LineCount);
            Assert.AreEqual("10:05", output.GetLine(1)[0]);
            Assert.AreEqual("Open", output.GetLine(1)[1]);
            Assert.AreEqual("Roy", output.GetLine(1)[2]);
        }
Beispiel #29
0
        public void AnalyzeTest()
        {
            var mockWebService = new Mock <IWebService>();

            mockWebService.Setup(p => p.LogError(It.Is <string>(str => str.Length > 8))).Throws(new Exception());
            var         mockEmailService = new Mock <IEmailService>();
            var         a   = mockEmailService.Setup(e => e.SendEmail("*****@*****.**", "*****@*****.**", "IWebServiceFailed", It.Is <string>(x => x != null)));
            LogAnalyzer log = new LogAnalyzer(mockWebService.Object, mockEmailService.Object);

            log.Analyze("xxx");
            mockEmailService.Verify(p => p.SendEmail("*****@*****.**", "*****@*****.**", "IWebServiceFailed", It.Is <string>(x => x != null)));
        }
        public void Analyze_FileNameTooShort_CallLogger()
        {
            ILogger logger = Substitute.For <ILogger>();

            logger.When(x => x.LogError(Arg.Any <string>())).Do(c => { throw new Exception("fake exception"); });

            IWebService webber   = Substitute.For <IWebService>();
            var         analyzer = new LogAnalyzer(logger, webber);

            analyzer.Analyze("a");
            webber.Received().SendMsg(Arg.Any <string>());
        }
Beispiel #31
0
        public void Analyze_TooShortFileName_CallLogger()
        {
            // 创建模拟对象,用于测试结尾的断言
            ILogger     logger   = Substitute.For <ILogger>();
            LogAnalyzer analyzer = new LogAnalyzer(logger);

            analyzer.MinNameLength = 6;
            analyzer.Analyze("a.txt");

            // 使用NSub API设置预期字符串
            logger.Received().LogError("Filename too short : a.txt");
        }
Beispiel #32
0
        public void Analyze_SimpleStringLine_UsesDefaulTabDelimiterToParseFields2()
        {
            LogAnalyzer    log      = new LogAnalyzer();
            AnalyzedOutput expected = new AnalyzedOutput();

            expected.AddLine("10:05", "Open", "Roy");

            AnalyzedOutput output =
                log.Analyze("10:05\tOpen\tRoy");

            Assert.AreEqual(expected, output);
        }
        public void Analyze_ShortFileName_LogsError()
        {
            var mockWebService = new MockWebService();

            var logAnalyzer = new LogAnalyzer
            {
                WebService = mockWebService
            };

            logAnalyzer.Analyze("abc.txt");

            Assert.AreEqual(mockWebService.LogText, "Short FileName:abc.txt");
        }
        public void StubThatThrowsException_RhinoMocks()
        {
            IWebService simulatedService = MockRepository.GenerateStub <IWebService>();

            simulatedService
            .Expect(t => t.LogError(""))
            .Throw(new Exception("fake exception"))
            .Constraints(Is.Anything());

            LogAnalyzer log = new LogAnalyzer(simulatedService);

            log.Analyze("abc.ext");
        }
        public void Analyze_TooShortFileName_LogFileNameTooShort()
        {
            var mockLogger  = FakeTheLogger();
            var logAnalyzer = new LogAnalyzer();

            const string fileName = "abc.txt";

            logAnalyzer.Analyze(fileName);

            mockLogger.Verify(l =>
                              l.Log(It.Is <string>(s =>
                                                   s.Contains("Filename too short:"))));
        }
        public void Analyze_TooShortFileName_CallLogger()
        {
            FakeLogger logger = new FakeLogger();

            LogAnalyzer analyzer = new LogAnalyzer(logger);

            analyzer.MinNameLength = 6;

            string tooShortFileName = "a.ext";

            analyzer.Analyze(tooShortFileName);

            StringAssert.Contains("too short", logger.LastError);
        }
Beispiel #37
0
        public void Analyze_TooShortFileName_CallLogger()
        {
            //Arrange
            ILogger     logger   = Substitute.For <ILogger>();
            LogAnalyzer analyzer = new LogAnalyzer(logger);

            analyzer.MinNameLength = 6;

            //Act
            analyzer.Analyze("a.txt");

            //Assert
            logger.Received().LogError("Filename too short: a.txt");
        }
Beispiel #38
0
        public void WhenAnalyze_ShouldReturnTooShortFileName_WithMock()
        {
            var mockService = new Mock<IWebService>(MockBehavior.Strict);

            string tooShortFileName = "abc.ext";
            mockService.Setup(x => x.LogError("Filename too short:abc.ext")).Verifiable();

            var log = new LogAnalyzer(mockService.Object);

            log.Analyze(tooShortFileName);

            //Assert.That(strLastError, Is.EqualTo("Filename too short:abc.ext"));
            mockService.Verify(x => x.LogError("Filename too short:abc.ext"));
            //mockService.Verify(x => x.LogError(It.IsAny<string>()));
        }
        public void Analyze_ShortFileName_LogsError()
        {
            var mocks = new MockRepository();
            var mockWebService = mocks.DynamicMock<IWebService>();

            using (mocks.Record())
            {
                mockWebService.LogError("Short FileName:abc.txt");
            }

            var logAnalyzer = new LogAnalyzer
            {
                WebService = mockWebService
            };

            logAnalyzer.Analyze("abc.txt");

            mocks.Verify(mockWebService);
        }
Beispiel #40
0
        //[ExpectedException]
        public void WhenAnalyze_ShouldReturnTooShortFileName_WithCallback()
        {
            //Arrange
            var mockService = new Mock<IWebService>(MockBehavior.Strict);
            string strLastError = "";
            string tooShortFileName = "abc.ext";

            mockService.Setup(x => x.LogError(It.IsAny<string>(
                )))
                .Callback(
                    (string error) =>
                    {
                        strLastError = error;
                    }
                );
            //mockService.Setup(x => x.LogError("Tsest")).Throws(new ArgumentException());
            var log = new LogAnalyzer(mockService.Object);

            //Act
            log.Analyze(tooShortFileName);

            //Assert
            Assert.That(strLastError, Is.EqualTo("Filename too short:abc.ext"));
        }