Ejemplo n.º 1
0
        public void IsValidFileName_ExtManagerThrowsException_ReturnFalse()
        {
            FakeExtensionManager myFakeManager = new FakeExtensionManager();

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

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

            //需要在被测方法外添加一个try-catch,并且在catch中返回false(根据需要可以对应修改catch和这个assert)
            Assert.False(result);
        }
Ejemplo n.º 2
0
        public void IsValidFileName_NameSupportedExtension_ReturnsTrue()
        {
            //准备一个返回true的桩
            FakeExtensionManager myFakeManager =
                new FakeExtensionManager();

            myFakeManager.WillBeValid = true;

            //传入桩
            LogAnalyzerConstructorInject log =
                new LogAnalyzerConstructorInject(myFakeManager);
            bool result = log.IsValidLogFileName("short.ext");

            Assert.True(result);
        }