Пример #1
0
        public void Returns_ByDefault_WorkForIgnoreArgument()
        {
            IFileNameRules fakeRules = Substitute.For <IFileNameRules>();

            fakeRules.IsValidLogFileName(Arg.Any <string>()).Returns(true);
            Assert.IsTrue(fakeRules.IsValidLogFileName("a.txt"));
        }
Пример #2
0
        public void SubstituteFor_ForInterfaces_ReturnsAFakeInterface()
        {
            IFileNameRules fakeRules = Substitute.For <IFileNameRules>();
            var            result    = fakeRules.IsValidLogFileName("something.bla");

            Assert.IsFalse(fakeRules.IsValidLogFileName("something.bla"));
        }
Пример #3
0
        public void Returns_ByDefault_WorkForHardCodeArgument()
        {
            IFileNameRules fakeRules = Substitute.For <IFileNameRules>();

            fakeRules.IsValidLogFileName("a.txt").Returns(true);
            Assert.IsTrue(fakeRules.IsValidLogFileName("a.txt"));
        }
Пример #4
0
        public void Returns_ByDefault_WorksForHardCodedArgument()
        {
            IFileNameRules fakeRules = Substitute.For <IFileNameRules>();

            fakeRules.IsValidLogFileName(Arg.Any <String>()).Returns(true);
            Assert.IsTrue(fakeRules.IsValidLogFileName("strict.txt"));
        }
Пример #5
0
        public void Returns_ArgAny_IgnoresArgument()
        {
            IFileNameRules fakeRules = Substitute.For <IFileNameRules>();

            fakeRules.IsValidLogFileName(Arg.Any <string>()).Returns(true);

            Assert.IsTrue(fakeRules.IsValidLogFileName("anything, really"));
        }
        public void Returns_ByDefault_WorksForHardCodedArgument()
        {
            IFileNameRules fakeRules = Substitute.For <IFileNameRules>();

            //when this is called that is returned
            fakeRules.IsValidLogFileName("strict.txt").Returns(true);

            Assert.IsTrue(fakeRules.IsValidLogFileName("strict.txt"));
        }
Пример #7
0
        public void Returns_ByDefault_WorksForHardCodedArgument2()
        {
            IFileNameRules fakeRules = Substitute.For <IFileNameRules>();

            //这个Arg.Any<string>()就是参数匹配器,只要是string都会返回一个假值(例子里是true)
            fakeRules.IsValidLogFileName(Arg.Any <string>()).Returns(true);

            Assert.IsTrue(fakeRules.IsValidLogFileName("anything.txt"));
        }
        public void Returns_ByDefault_WorksForAnyArgument()
        {
            IFileNameRules fakeRules = Substitute.For <IFileNameRules>();

            //return this when input is _any_ string
            fakeRules.IsValidLogFileName(Arg.Any <String>())
            .Returns(true);

            Assert.IsTrue(fakeRules.IsValidLogFileName("anything.txt"));
        }
Пример #9
0
        public void Returns_ByDefault_WorksForHardCodedArgument()
        {
            IFileNameRules fakeRules = Substitute.For <IFileNameRules>();

            //强制方法调用时返回一个假值
            fakeRules.IsValidLogFileName("strict.txt").Returns(true);

            //因为调用了“fakeRules.IsValidLogFileName("strict.txt")”所以根据框架设置,返回了true
            Assert.IsTrue(fakeRules.IsValidLogFileName("strict.txt"));
        }
Пример #10
0
        public void Returns_ArgAny_Throws()
        {
            IFileNameRules fakeRules = Substitute.For <IFileNameRules>();

            fakeRules.When(x => x.IsValidLogFileName(Arg.Any <string>())).Do(context => { throw new Exception("sztuczny wyjątek"); });

            Assert.Throws <Exception>(() => fakeRules.IsValidLogFileName("cokolwiek"));
        }
Пример #11
0
        public void Analyze_FileNameTooShort_CallLogger_ArgMatch()
        {
            IFileNameRules rule = Substitute.For <IFileNameRules>();

            rule.IsValidLogFileName(Arg.Any <string>()).Returns(true);
            var analyzer = new LogAnalyzer(rule);

            Assert.IsTrue(analyzer.IsValidFileName("a1.txt"));
        }
Пример #12
0
        public void Returns_ArgAny_Throws()
        {
            IFileNameRules fakeRules = Substitute.For <IFileNameRules>();

            fakeRules.When(x => x.IsValidLogFileName(Arg.Any <string>()))
            .Do(a => { throw new Exception("fake exception"); });
            Assert.Throws <Exception>(() =>
                                      fakeRules.IsValidLogFileName("anything"));
        }
Пример #13
0
        public void Returns_ArgAny_Throws()
        {
            IFileNameRules fakeRules = Substitute.For <IFileNameRules>();

            //When方法必须使用Lambda表达式,其中x代表要改变行为的伪对象,context包含调用的参数值
            fakeRules.When(x => x.IsValidLogFileName(Arg.Any <string>()))
            .Do(context => { throw new Exception("fake exception"); });

            Assert.Throws <Exception>(() => fakeRules.IsValidLogFileName("anything"));
        }
        public void Returns_ArgAny_Throws()
        {
            IFileNameRules fakeRules = Substitute.For <IFileNameRules>();

            fakeRules.When(x => x.IsValidLogFileName(Arg.Any <string>())) // x signifies fake object behaviour is changed on
            .Do(context =>                                                // context is callinfo property from NSub holding argument values at runtime.
                // allows cool things to be done in more advanced scenarios
                { throw new Exception("fake exception"); });

            Assert.Throws <Exception>(() =>
                                      fakeRules.IsValidLogFileName("anything"));
        }
Пример #15
0
 public bool IsValidFileName(string fileName)
 {
     return(fileNameRules.IsValidLogFileName(fileName));
 }