public void Returns_ByDefault_WorkForIgnoreArgument() { IFileNameRules fakeRules = Substitute.For <IFileNameRules>(); fakeRules.IsValidLogFileName(Arg.Any <string>()).Returns(true); Assert.IsTrue(fakeRules.IsValidLogFileName("a.txt")); }
public void Returns_ByDefault_WorksForHardCodedArgument() { IFileNameRules fakeRules = Substitute.For <IFileNameRules>(); fakeRules.IsValidLogFileName(Arg.Any <String>()).Returns(true); Assert.IsTrue(fakeRules.IsValidLogFileName("strict.txt")); }
public void Returns_ByDefault_WorkForHardCodeArgument() { IFileNameRules fakeRules = Substitute.For <IFileNameRules>(); fakeRules.IsValidLogFileName("a.txt").Returns(true); Assert.IsTrue(fakeRules.IsValidLogFileName("a.txt")); }
public void Returns_ByDefault_WorksForHardCodedArgument_Refactored() { IFileNameRules fakeRules = Substitute.For <IFileNameRules>(); fakeRules.IsValideLogFileName(Arg.Any <string>()).Returns(true); Assert.IsTrue(fakeRules.IsValideLogFileName("anything.SLF")); }
public void SubstituteFor_ForInterfaces_ReturnsAFakeInterface() { IFileNameRules fakeRules = Substitute.For <IFileNameRules>(); var result = fakeRules.IsValidLogFileName("something.bla"); Assert.IsFalse(fakeRules.IsValidLogFileName("something.bla")); }
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_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")); }
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")); }
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")); }
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")); }
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")); }
public void Analyze_FileNameTooShort_CallLogger_Exception() { IFileNameRules rule = Substitute.For <IFileNameRules>(); rule.When(x => x.IsValidLogFileName(Arg.Any <string>())) .Do(t => { throw new Exception("fake exception"); }); var analyzer = new LogAnalyzer(rule); Assert.Throws <Exception>(() => { analyzer.IsValidFileName("a"); }); }
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_ByDefault_WorksForHardCodedArgument() { IFileNameRules fakeRules = Substitute.For <IFileNameRules>(); //强制方法调用时返回一个假值 fakeRules.IsValidLogFileName("strict.txt").Returns(true); //因为调用了“fakeRules.IsValidLogFileName("strict.txt")”所以根据框架设置,返回了true Assert.IsTrue(fakeRules.IsValidLogFileName("strict.txt")); }
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")); }
public LogAnalyzer(IFileNameRules fileNameRules) { this.fileNameRules = fileNameRules; }