当前位置: 首页>>代码示例>>C#>>正文


C# MockRepository.CreateMock方法代码示例

本文整理汇总了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);
		}
开发者ID:JackWangCUMT,项目名称:rhino-tools,代码行数:11,代码来源:RhinoMocks101.cs

示例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();
        }
开发者ID:PaulStovell,项目名称:stovell-mocks,代码行数:20,代码来源:Program.cs


注:本文中的MockRepository.CreateMock方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。