本文整理汇总了C#中Mock.___方法的典型用法代码示例。如果您正苦于以下问题:C# Mock.___方法的具体用法?C# Mock.___怎么用?C# Mock.___使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Mock
的用法示例。
在下文中一共展示了Mock.___方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: SetupAMockPersonWithTheNameJohnDoe
public void SetupAMockPersonWithTheNameJohnDoe()
{
var mock = new Mock<Person>(MockBehavior.Strict);
mock.___();
mock.___();
var person = mock.Object;
Assert.AreEqual("John", person.GetFirstName());
Assert.AreEqual("Doe", person.GetLastName());
}
示例2: IfAMethodIsSetupVerifiableButVerifyIsNotCalledLaterThenNoExceptionIsThrown
public void IfAMethodIsSetupVerifiableButVerifyIsNotCalledLaterThenNoExceptionIsThrown()
{
var mock = new Mock<IVolume>();
mock.Setup(x => x.Louder(It.IsAny<int>()))
.Returns(0)
.Verifiable("Louder was not called.");
//mock.Object.Louder(0); <-- intentionally NOT calling .Louder. Don't uncomment this to solve the test.
try
{
mock.___();
Assert.Fail(".Louder() was not called on the Mock, but no exception was thrown.");
}
catch (MockException)
{
// we expect an exception to be thrown, sicne we are not calling .Louder(), but it is setup to be verifiable.
}
}
示例3: WriteASingleSetupMethodForQuieterSoThatItAlwaysReturnsOneLessThanThePassedInValue
public void WriteASingleSetupMethodForQuieterSoThatItAlwaysReturnsOneLessThanThePassedInValue()
{
var mock = new Mock<IVolume>();
var volume = mock.Object;
mock.___();
Assert.AreEqual(0, volume.Quieter(1));
Assert.AreEqual(1, volume.Quieter(2));
Assert.AreEqual(2, volume.Quieter(3));
}
示例4: WriteASetupMethodToMakeCurrentVolumeReturnTheExpectedValue
public void WriteASetupMethodToMakeCurrentVolumeReturnTheExpectedValue()
{
var mock = new Mock<IVolume>();
mock.___();
Assert.AreEqual("yay!", mock.Object.CurrentVolume());
}
示例5: SetupTheMockQuieterMethodToReturnTheDesiredResultsToMakeTheTestPass
public void SetupTheMockQuieterMethodToReturnTheDesiredResultsToMakeTheTestPass()
{
var mock = new Mock<IVolume>();
mock.___();
mock.___();
Assert.AreEqual(0, mock.Object.Quieter(-2));
Assert.AreEqual(0, mock.Object.Quieter(-1));
Assert.AreEqual(100, mock.Object.Quieter(1));
Assert.AreEqual(100, mock.Object.Quieter(2));
}