예제 #1
0
        public void OverrideTest()
        {
            FakeExtensionManager stub = new FakeExtensionManager();

            stub.WillBeValid = true;
            // 创建被测试类的派生类的实例
            TestableLogAnalyzer logan = new TestableLogAnalyzer(stub);
            bool result = logan.IsValidLogFileName("stubfile.ext");

            Assert.AreEqual(true, result);
        }
예제 #2
0
        public void IsValidFileName_ExtManagerThrowsException_ReturnsFalse()
        {
            FakeExtensionManager myFakeManager = new FakeExtensionManager();

            myFakeManager.WillThrow = new Exception("this is fake");

            LogAnalyzerCh3 log    = new LogAnalyzerCh3(myFakeManager);
            bool           result = log.IsValidLogFileName("anything.anyextension");

            Assert.IsFalse(result);
        }
예제 #3
0
        public void OverrideTests()
        {
            FakeExtensionManager stub = new FakeExtensionManager();

            stub.WillBeValid = true;

            TestableLogAnalyzer logan = new TestableLogAnalyzer(stub);
            bool result = logan.IsValidLogFileName("file.ext");

            Assert.True(result);
        }
예제 #4
0
        public void IsValidLogFileNameShouldThrowExceptionWhenFilenameIsNullOrEmpty(string filename)
        {
            const string ExpectedResult = "No filename provided";
            var          stub           = new FakeExtensionManager {
                WillThrow = new ArgumentException("No filename provided")
            };
            var analyzer = new FakeLogAnalyzerExtensionManager(stub);
            var result   = Assert.Throws <ArgumentException>(() => analyzer.IsValidLogFileName(filename));

            Assert.That(result.Message, Does.Contain(ExpectedResult));
        }
예제 #5
0
        public void IsValidLogFileNameShouldReturnFalseWhenExtensionManagerRejectsExtension()
        {
            const bool ExpectedResult = false;
            var        stub           = new FakeExtensionManager {
                WillBeValid = false
            };
            var analyzer = new FakeLogAnalyzerExtensionManager(stub);
            var result   = analyzer.IsValidLogFileName("file.ext");

            Assert.That(result, Is.EqualTo(ExpectedResult));
        }
예제 #6
0
        public void IsValidFileName_SupportedExtensionUsingFactoryClass_ReturnsTrue()
        {
            FakeExtensionManager myFakeManager = new FakeExtensionManager();

            myFakeManager.WillBeValid = true;

            ExtensionManagerFactory.SetManager(myFakeManager); //create Analyzer, di the stub
            LogAnalyzerCh3WithFactoryClass log = new LogAnalyzerCh3WithFactoryClass();
            bool result = log.IsValidLogFileName("short.ext");

            Assert.IsTrue(result);
        }
예제 #7
0
        public void IsValidFileName_NameSupportedExtension_ReturnsTrue()
        {
            FakeExtensionManager myFakeManager = new FakeExtensionManager(); //prepare a stub

            myFakeManager.WillBeValid = true;

            LogAnalyzerCh3 log = new LogAnalyzerCh3(myFakeManager);

            bool result = log.IsValidLogFileName("short.ext");

            Assert.IsTrue(result);
        }
예제 #8
0
        public void IsValidFileName_NameSupportExtension_ReturnsTrue()
        {
            //准备一个存根
            FakeExtensionManager myFakeManager = new FakeExtensionManager();

            myFakeManager.WillBeValid = true;
            //通过构造器注入传入存根

            LogAnalyzer2 analyzer = new LogAnalyzer2(myFakeManager);
            bool         result   = analyzer.IsValidLogFileName("short.ext");

            Assert.AreEqual(true, result);
        }
예제 #9
0
        public void IsValidFileName_SupportedExtension_ReturnsTrue()
        {
            FakeExtensionManager myFakeManager = new FakeExtensionManager();

            myFakeManager.WillBeValid = true;

            LogAnalyzerCh3re log = new LogAnalyzerCh3re();

            log.ExtensionManager = myFakeManager;

            bool result = log.IsValidLogFileName("short.ext");

            Assert.IsTrue(result);
        }
예제 #10
0
        public void IsValidFileName_NameSupportedExtension_ReturnsTrue()
        {
            //set up the stub to use, make sure it returns true

            FakeExtensionManager myFakeManager =
                new FakeExtensionManager();

            myFakeManager.WillBeValid = false;

            //create analyzer and inject stub

            LogAnalyzer log = new LogAnalyzer();

            log.ExtensionManager = myFakeManager;

            //Assert logic assuming extension is supported

            bool result = log.IsValidLogFileName("short.ext");

            Assert.False(result);
        }