Ejemplo n.º 1
0
        public void AnalyzeFile_FileWith3Line_CallLogProvider3TimesEvenLessBrittle()
        {
            Mock <ILogProvider> logProviderStub = new Mock <ILogProvider>();

            logProviderStub.Setup(l => l.GetLineCount()).Returns(3);
            logProviderStub.Setup(l => l.GetText(It.IsAny <string>(), It.IsAny <int>(), It.IsAny <int>()))
            .Returns <string, int, int>((s, i1, i2) => new string('A', i2 - i1 + 1));

            LogAnalyzer target = new LogAnalyzer(logProviderStub.Object);

            var result = target.AnalyzeFile("any file name");

            Assert.AreEqual("AAA", result.AllLines);
        }
        public void AnalyzeFile_FileWith3Line_CallLogProvider3Times()
        {
            Mock <ILogProvider> logProviderMock = new Mock <ILogProvider>();

            logProviderMock.Setup(l => l.GetLineCount()).Returns(3);

            LogAnalyzer target = new LogAnalyzer(logProviderMock.Object);

            target.AnalyzeFile("any file name");

            logProviderMock.Verify(l => l.GetText("any file name", 1, 1), Times.Once());
            logProviderMock.Verify(l => l.GetText("any file name", 2, 2), Times.Once());
            logProviderMock.Verify(l => l.GetText("any file name", 3, 3), Times.Once());
        }