public void ReadLine() { var logSystem = new LogSystem(); logSystem.OpenRead(new StubReader()); var result = logSystem.ReadLine(); Assert.AreEqual("运行正常", result); }
public void ReadLine() { var logSystem = new LogSystem(); //todo //logSystem.OpenRead(ILogReader实例); var result = logSystem.ReadLine(); Assert.AreEqual("运行正常", result); }
public void ReadLine2() { var logSystem = new LogSystem(); //todo //logSystem.OpenRead(ILogReader实例); logSystem.ReadLine(); Assert.AreEqual(4, logSystem.Reader.CurrentLine); }
public void ReadLine() { var logSystem = new LogSystem(); // 新建一个ILogReader的Mock对象,其Object属性即为我们需要的伪对象 var fakeReader = new Mock <ILogReader>(); // 当调用ILogReader接口的ReadLine()方法时,将返回运行正常字符串 fakeReader.Setup(fake => fake.ReadLine()).Returns("运行正常"); //将伪对象注入到被测试类 logSystem.OpenRead(fakeReader.Object); var result = logSystem.ReadLine(); Assert.AreEqual("运行正常", result); }
public void ReadLine2() { var logSystem = new LogSystem(); // 新建一个ILogReader的Mock对象,其Object属性即为我们需要的伪对象 var fakeReader = new Mock <ILogReader>(); // 伪造ILogReader接口的CurrentLine属性时,并且赋初值为3 fakeReader.SetupProperty(fake => fake.CurrentLine, 3); // 当调用ILogReader接口的ReadLine()方法时,触发回调函数,将伪对象的CurrentLine属性值+1 fakeReader.Setup(fake => fake.ReadLine()).Callback(() => fakeReader.Object.CurrentLine++); //将伪对象注入到被测试类 logSystem.OpenRead(fakeReader.Object); logSystem.ReadLine(); Assert.AreEqual(4, logSystem.Reader.CurrentLine); }