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


C# Mock.When方法代码示例

本文整理汇总了C#中Mock.When方法的典型用法代码示例。如果您正苦于以下问题:C# Mock.When方法的具体用法?C# Mock.When怎么用?C# Mock.When使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Mock的用法示例。


在下文中一共展示了Mock.When方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: ChooseAffirmativeExpetationOnVoidMethod

		public void ChooseAffirmativeExpetationOnVoidMethod()
		{
			var mock = new Mock<IFoo>();

			var when = true;
			var positive = false;
			var negative = false;

			mock.When(() => when).Setup(x => x.Bar()).Callback(() => positive = true);
			mock.When(() => !when).Setup(x => x.Bar()).Callback(() => negative = true);

			mock.Object.Bar();

			Assert.True(positive);
			Assert.False(negative);

			when = false;
			positive = false;
			mock.Object.Bar();

			Assert.False(positive);
			Assert.True(negative);

			when = true;
			negative = false;
			mock.Object.Bar();

			Assert.True(positive);
			Assert.False(negative);
		}
开发者ID:mbrit,项目名称:MoqForWinRT,代码行数:30,代码来源:ConditionalSetupFixture.cs

示例2: ChooseAffirmativeExpetationOnPropertySetter

		public void ChooseAffirmativeExpetationOnPropertySetter()
		{
			var mock = new Mock<IFoo>();

			var when = true;
			var positive = false;
			var negative = false;

			mock.When(() => when).SetupSet(x => x.Value = "foo").Callback(() => positive = true);
			mock.When(() => !when).SetupSet(x => x.Value = "foo").Callback(() => negative = true);

			mock.Object.Value = "foo";

			Assert.True(positive);
			Assert.False(negative);

			when = false;
			positive = false;
			mock.Object.Value = "foo";

			Assert.False(positive);
			Assert.True(negative);

			when = true;
			negative = false;
			mock.Object.Value = "foo";

			Assert.True(positive);
			Assert.False(negative);
		}
开发者ID:20John22,项目名称:moq4,代码行数:30,代码来源:ConditionalSetupFixture.cs

示例3: ChooseAffirmativeExpectationOnPropertyIndexer

        public void ChooseAffirmativeExpectationOnPropertyIndexer()
        {
            var mock = new Mock<IFoo>();

            var first = true;

            mock.When(() => first).Setup(x => x[0]).Returns("bar");
            mock.When(() => !first).Setup(x => x[0]).Returns("no bar");

            Assert.Equal("bar", mock.Object[0]);
            first = false;
            Assert.Equal("no bar", mock.Object[0]);
            first = true;
            Assert.Equal("bar", mock.Object[0]);
        }
开发者ID:RajOpteamix,项目名称:moq,代码行数:15,代码来源:ConditionalSetupFixture.cs

示例4: MethodCallReturnsValue

 public void MethodCallReturnsValue()
 {
     var mock = new Mock<IBlah>();
     mock.When(o => o.GetThing()).Return(10);
     var blah = mock.Object;
     Assert.AreEqual(10, blah.GetThing());
 }
开发者ID:dezfowler,项目名称:LiteMock,代码行数:7,代码来源:MockTest.cs

示例5: MethodCallInvalid

 public void MethodCallInvalid()
 {
     var mock = new Mock<IBlah>();
     mock.When(o => o.DoThing(5)).CheckArguments();
     var blah = mock.Object;
     blah.DoThing(4);
 }
开发者ID:dezfowler,项目名称:LiteMock,代码行数:7,代码来源:MockTest.cs

示例6: IgnoreSpecificCalls

 public void IgnoreSpecificCalls()
 {
     var mock = new Mock<IBlah>();
     mock.When(o => o.GetThing()).Ignore();
     var blah = mock.Object;
     Assert.AreEqual(default(int), blah.GetThing());
     int i = blah.Thing;
 }
开发者ID:dezfowler,项目名称:LiteMock,代码行数:8,代码来源:MockTest.cs

示例7: ChooseAffirmativeExpectationOnMethod

        public void ChooseAffirmativeExpectationOnMethod()
        {
            var mock = new Mock<IFoo>();

            var when = true;

            mock.When(() => when).Setup(x => x.Foo()).Returns("bar");
            mock.When(() => !when).Setup(x => x.Foo()).Returns("no bar");

            Assert.Equal("bar", mock.Object.Foo());

            when = false;
            Assert.Equal("no bar", mock.Object.Foo());

            when = true;
            Assert.Equal("bar", mock.Object.Foo());
        }
开发者ID:RajOpteamix,项目名称:moq,代码行数:17,代码来源:ConditionalSetupFixture.cs

示例8: ExpectedExceptionWhenToIsSpecificMail

        public void ExpectedExceptionWhenToIsSpecificMail()
        {
            Mock<IServicioCorreo> mMockMailSvc = new Mock<IServicioCorreo>();
            //Se prepara el mock
            mMockMailSvc.When(() => this.iMailDTO.CuentaDestino.Equals("[email protected]")).Setup(x => x.EnviarCorreo(this.iMailDTO, this.iAccountDTO)).Throws<Exception>();

            IServicioCorreo mMailSvc = mMockMailSvc.Object;
            mMailSvc.EnviarCorreo(this.iMailDTO, this.iAccountDTO);
        }
开发者ID:matiadr,项目名称:tpfinalTallerProgramacion,代码行数:9,代码来源:CorreoServicioTest.cs

示例9: MethodCallThrows

 public void MethodCallThrows()
 {
     var mock = new Mock<IBlah>();
     mock.When(o => o.GetThing()).Throw();
     var blah = mock.Object;
     int i = blah.GetThing();
 }
开发者ID:dezfowler,项目名称:LiteMock,代码行数:7,代码来源:MockTest.cs

示例10: ReadOnlyPropertyReturnsCorrectValue

 public void ReadOnlyPropertyReturnsCorrectValue()
 {
     var mock = new Mock<IBlah>();
     mock.When(o => o.ReadOnly).Return("thing");
     var blah = mock.Object;
     Assert.AreEqual("thing", blah.ReadOnly);
 }
开发者ID:dezfowler,项目名称:LiteMock,代码行数:7,代码来源:MockTest.cs

示例11: PropertyGetThrows

 public void PropertyGetThrows()
 {
     var mock = new Mock<IBlah>();
     mock.When(o => o.Thing).Throw();
     var blah = mock.Object;
     int i = blah.Thing;
 }
开发者ID:dezfowler,项目名称:LiteMock,代码行数:7,代码来源:MockTest.cs

示例12: MethodCallWithArgsThrows

 public void MethodCallWithArgsThrows()
 {
     var mock = new Mock<IBlah>();
     mock.When(o => o.DoThing(5)).WithExactArguments().Throw();
     var blah = mock.Object;
     blah.DoThing(5);
 }
开发者ID:dezfowler,项目名称:LiteMock,代码行数:7,代码来源:MockTest.cs


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