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


C# Mock.___方法代码示例

本文整理汇总了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());
        }
开发者ID:npinchot,项目名称:MoqKoans,代码行数:10,代码来源:4_Virtual.cs

示例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.
            }
        }
开发者ID:npinchot,项目名称:MoqKoans,代码行数:20,代码来源:6_VerifyMethods.cs

示例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));
        }
开发者ID:npinchot,项目名称:MoqKoans,代码行数:10,代码来源:2_Methods.cs

示例4: WriteASetupMethodToMakeCurrentVolumeReturnTheExpectedValue

        public void WriteASetupMethodToMakeCurrentVolumeReturnTheExpectedValue()
        {
            var mock = new Mock<IVolume>();
            mock.___();

            Assert.AreEqual("yay!", mock.Object.CurrentVolume());
        }
开发者ID:npinchot,项目名称:MoqKoans,代码行数:7,代码来源:2_Methods.cs

示例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));
        }
开发者ID:npinchot,项目名称:MoqKoans,代码行数:11,代码来源:2_Methods.cs


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