本文整理汇总了C#中MockRepository.CreateMock方法的典型用法代码示例。如果您正苦于以下问题:C# MockRepository.CreateMock方法的具体用法?C# MockRepository.CreateMock怎么用?C# MockRepository.CreateMock使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MockRepository
的用法示例。
在下文中一共展示了MockRepository.CreateMock方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TestInitialize
public void TestInitialize()
{
mocks = new MockRepository();
smsSender = mocks.CreateMock<ISmsSender>();
user = new User("sally", "1234");
userRepository = mocks.Stub<IUserRepository>();
SetupResult.For(userRepository.GetByUserName("sally"))
.Return(user);
}
示例2: Main
internal static void Main(string[] args)
{
// Setup the expectatons of the mock GST rate provider
MockRepository repository = new MockRepository();
IGstRateProvider provider = repository.CreateMock<IGstRateProvider>();
provider.GetGstRate("Bread").WillReturn(0.00M);
provider.GetGstRate("Milk").WillReturn(0.00M);
provider.DefaultGstRate.WillReturn(0.10M);
repository.ReplayAll();
// Test the GST Calculator using the mock provider (instead of, say, the database
// GST rate provider it would use in production).
GstCalculator calculator = new GstCalculator(provider);
Assert.AreEqual(2.57M, calculator.ApplyGst("Bread", 2.57M), "Bread should be exempt from GST");
Assert.AreEqual(4.00M, calculator.ApplyGst("Milk", 4.00M), "Milk should be exempt from GST");
Assert.AreEqual(2200M, calculator.ApplyGst("Laptop", 2000M), "Laptops should not be exempt from GST");
Assert.AreEqual(26400M, calculator.ApplyGst("Car", 24000M), "Cars should not be exempt from GST");
repository.VerifyAll();
Console.ReadKey();
}