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


C# MockRepository.Record方法代码示例

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


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

示例1: Ayende_View_On_Mocking

        public void Ayende_View_On_Mocking()
        {
            MockRepository mocks = new MockRepository();
            ISomeSystem mockSomeSystem = mocks.StrictMock<ISomeSystem>();

            using (mocks.Record())
            {
                Expect.Call(mockSomeSystem.GetFooFor<ExpectedBar>("foo"))
                    .Return(new List<ExpectedBar>());
            }

            ExpectationViolationException ex = Assert.Throws<ExpectationViolationException>(
                () =>
                {
                    using (mocks.Playback())
                    {
                        ExpectedBarPerformer cut = new ExpectedBarPerformer(mockSomeSystem);
                        cut.DoStuffWithExpectedBar("foo");
                    }
                }
                );

            Assert.Equal(@"ISomeSystem.GetFooFor<Rhino.Mocks.Tests.FieldsProblem.UnexpectedBar>(""foo""); Expected #1, Actual #1.
            ISomeSystem.GetFooFor<Rhino.Mocks.Tests.FieldsProblem.ExpectedBar>(""foo""); Expected #1, Actual #0.", ex.Message);
        }
开发者ID:bjornbouetsmith,项目名称:mammock,代码行数:25,代码来源:FieldProblem_Rob.cs

示例2: WillMerge_UnorderedRecorder_WhenRecorderHasSingleRecorderInside

        public void WillMerge_UnorderedRecorder_WhenRecorderHasSingleRecorderInside()
        {
            MockRepository mocks = new MockRepository();
            ICustomer customer = mocks.StrictMock<ICustomer>();

            CustomerMapper mapper = new CustomerMapper();

            using (mocks.Record())
            using (mocks.Ordered())
            {
                Expect.Call(customer.Id).Return(0);

                customer.IsPreferred = true;
            }

            ExpectationViolationException ex = Assert.Throws<ExpectationViolationException>(() =>
            {
                using (mocks.Playback())
                {
                    mapper.MarkCustomerAsPreferred(customer);
                }
            });

            Assert.Equal("Unordered method call! The expected call is: 'Ordered: { ICustomer.get_Id(); }' but was: 'ICustomer.set_IsPreferred(True);'", ex.Message);
        }
开发者ID:bjornbouetsmith,项目名称:mammock,代码行数:25,代码来源:FieldProblem_Shane.cs

示例3: MultiThreadedReplay

        public void MultiThreadedReplay()
        {
            var mocks = new MockRepository();
            var service = mocks.StrictMock<IService>();
            using (mocks.Record())
            {
                for (int i = 0; i < 100; i++)
                {
                    int i1 = i;

                    Expect.Call(() => service.Do("message" + i1));
                }
            }
            using (mocks.Playback())
            {
                int counter = 0;
                for (int i = 0; i < 100; i++)
                {
                    var i1 = i;
                    ThreadPool.QueueUserWorkItem(delegate
                    {
                        service.Do("message" + i1);
                        Interlocked.Increment(ref counter);
                    });
                }
                while (counter != 100)
                    Thread.Sleep(100);
            }
        }
开发者ID:guesshoo,项目名称:rhino-mocks,代码行数:29,代码来源:FieldProblem_Naraga.cs

示例4: The_value_of_a_variable_used_as_an_out_parameter_should_not_be_used_as_a_constraint_on_an_expectation

        public void The_value_of_a_variable_used_as_an_out_parameter_should_not_be_used_as_a_constraint_on_an_expectation()
        {
            MockRepository mockRepository = new MockRepository();
            ServiceBeingCalled service = mockRepository.StrictMock<ServiceBeingCalled>();
            const int theNumberToReturnFromTheServiceOutParameter = 20;

            using(mockRepository.Record())
            {
                int uninitialized;

                // Uncommenting the following line will make the test pass, because the expectation constraints will match up with the actual call.
                // However, the value of an out parameter cannot be used within a method value before it is set within the method value,
                // so the value going in really is irrelevant, and should therefore be ignored when evaluating constraints.
                // Even ReSharper will tell you "Value assigned is not used in any execution path" for the following line.

                //uninitialized = 42;

                // I understand I can do an IgnoreArguments() or Contraints(Is.Equal("key"), Is.Anything()), but I think the framework should take care of that for me

                Expect.Call(service.PopulateOutParameter("key", out uninitialized)).Return(null).OutRef(theNumberToReturnFromTheServiceOutParameter);
            }
            ObjectBeingTested testObject = new ObjectBeingTested(service);
            int returnedValue = testObject.MethodUnderTest();
            Assert.Equal(theNumberToReturnFromTheServiceOutParameter, returnedValue);
        }
开发者ID:ChuangYang,项目名称:RhinoMocks,代码行数:25,代码来源:FieldProblem_Joshua.cs

示例5: CannotCallLastCallConstraintsMoreThanOnce

 public void CannotCallLastCallConstraintsMoreThanOnce()
 {
     MockRepository repository = new MockRepository();
     IGetResults resultGetter = repository.Stub<IGetResults>();
     using (repository.Record())
     {
         resultGetter.GetSomeNumber("a");
         LastCall.Constraints(Text.Contains("b"));
         LastCall.Constraints(Text.Contains("a"));
     }
 }
开发者ID:nkmajeti,项目名称:rhino-tools,代码行数:11,代码来源:FieldProblem_Roy.cs

示例6: OutByRefTest

            public void OutByRefTest()
            {
                MockRepository mockery = new MockRepository();
                IFoo mockFoo = mockery.StrictMock<IFoo>();
                int three = 3;
                int six = 6;
                using (mockery.Record())
                {
                    SetupResult.For(mockFoo.foo(ref three)).OutRef(six).Return(true);
                }

                Assert.Throws<Rhino.Mocks.Exceptions.ExpectationViolationException>(() => mockFoo.foo(ref six));
            }
开发者ID:andriniaina,项目名称:rhino-mocks,代码行数:13,代码来源:FieldProblem_Andri.cs

示例7: CanGetSetupResultFromStub

        public void CanGetSetupResultFromStub()
        {
            MockRepository repository = new MockRepository();
            IGetResults resultGetter = repository.Stub<IGetResults>();
            using (repository.Record())
            {
                resultGetter.GetSomeNumber("a");
                LastCall.Return(1);
            }

            int result = resultGetter.GetSomeNumber("a");
            Assert.Equal(1, result);
            repository.VerifyAll();
        }
开发者ID:bjornbouetsmith,项目名称:mammock,代码行数:14,代码来源:FieldProblem_Roy.cs

示例8: PlaybackThrowsOtherExceptionDoesntReport

 public void PlaybackThrowsOtherExceptionDoesntReport()
 {
     MockRepository mockRepository;
     mockRepository = new MockRepository();
     IFoo mockedFoo = mockRepository.StrictMock<IFoo>();
     using (mockRepository.Record())
     {
         Expect.Call(mockedFoo.Bar()).Return(42);
     }
     using (mockRepository.Playback())
     {
         throw new ArgumentException();
     }
 }
开发者ID:nkmajeti,项目名称:rhino-tools,代码行数:14,代码来源:RecordPlaybackTests.cs

示例9: StubNeverFailsTheTest

        public void StubNeverFailsTheTest()
        {
            MockRepository repository = new MockRepository();
            IGetResults resultGetter = repository.Stub<IGetResults>();
            using (repository.Record())
            {
                resultGetter.GetSomeNumber("a");
                LastCall.Return(1);
            }

            int result = resultGetter.GetSomeNumber("b");
            Assert.Equal(0, result);
            repository.VerifyAll(); //<- should not fail the test methinks
        }
开发者ID:bjornbouetsmith,项目名称:mammock,代码行数:14,代码来源:FieldProblem_Roy.cs

示例10: NaturalSyntaxForCallingMethods_WithArguments

        public void NaturalSyntaxForCallingMethods_WithArguments()
        {
            MockRepository mocks = new MockRepository();
            IDemo demo = mocks.StrictMock<IDemo>();
            using (mocks.Record())
            {
                Expect.Call( () => demo.VoidStringArg("blah") );
            }

            using (mocks.Playback())
            {
                demo.VoidStringArg("blah");
            }
        }
开发者ID:medmondson,项目名称:RhinoMocks,代码行数:14,代码来源:DotNet35Tests.cs

示例11: NaturalSyntaxForCallingMethods

        public void NaturalSyntaxForCallingMethods()
        {
            MockRepository mocks = new MockRepository();
            IDemo demo = mocks.StrictMock<IDemo>();
            using (mocks.Record())
            {
                Expect.Call(demo.VoidNoArgs);
            }

            using (mocks.Playback())
            {
                demo.VoidNoArgs();
            }
        }
开发者ID:medmondson,项目名称:RhinoMocks,代码行数:14,代码来源:DotNet35Tests.cs

示例12: NaturalSyntaxForCallingMethods_WithArguments_WhenNotCalled_WouldFailVerification

        public void NaturalSyntaxForCallingMethods_WithArguments_WhenNotCalled_WouldFailVerification()
        {
            MockRepository mocks = new MockRepository();
            IDemo demo = mocks.StrictMock<IDemo>();
            using (mocks.Record())
            {
                Expect.Call(() => demo.VoidStringArg("blah"));
            }

            Throws.Exception<ExpectationViolationException>("IDemo.VoidStringArg(\"blah\"); Expected #1, Actual #0.",delegate
            {
                mocks.VerifyAll();
            });
        }
开发者ID:medmondson,项目名称:RhinoMocks,代码行数:14,代码来源:DotNet35Tests.cs

示例13: CanCallMethodWithParameters_WithoutSpecifyingParameters_WillAcceptAnyParameter

        public void CanCallMethodWithParameters_WithoutSpecifyingParameters_WillAcceptAnyParameter()
        {
            MockRepository mocks = new MockRepository();
            IDemo demo = mocks.StrictMock<IDemo>();
            using (mocks.Record())
            {
                Expect.Call(() => demo.VoidStringArg("blah")).IgnoreArguments();
            }

            using (mocks.Playback())
            {
                demo.VoidStringArg("asd");
            }
        }
开发者ID:medmondson,项目名称:RhinoMocks,代码行数:14,代码来源:DotNet35Tests.cs

示例14: CanSetExpectationOnReadWritePropertyUsingRecordPlaybackSyntax

        public void CanSetExpectationOnReadWritePropertyUsingRecordPlaybackSyntax()
        {
            var mocks = new MockRepository();
            var demo = mocks.DynamicMock<IDemo>();

            using (mocks.Record())
            {
                demo.Expect(x => x.Prop).SetPropertyWithArgument("Eduardo");
            }

            using (mocks.Playback())
            {
                demo.Prop = "Eduardo";
            }
        }
开发者ID:guesshoo,项目名称:rhino-mocks,代码行数:15,代码来源:FieldProblem_Eduardo.cs

示例15: CannotCallLastCallConstraintsMoreThanOnce

 public void CannotCallLastCallConstraintsMoreThanOnce()
 {
     MockRepository repository = new MockRepository();
     IGetResults resultGetter = repository.Stub<IGetResults>();
     var ex = Assert.Throws<InvalidOperationException>(() =>
                                                       	{
                                                       		using (repository.Record())
                                                       		{
                                                       			resultGetter.GetSomeNumber("a");
                                                       			LastCall.Constraints(Text.Contains("b"));
                                                       			LastCall.Constraints(Text.Contains("a"));
                                                       		}
                                                       	});
     Assert.Equal("You have already specified constraints for this method. (IGetResults.GetSomeNumber(contains \"b\");)", ex.Message);
 }
开发者ID:guesshoo,项目名称:rhino-mocks,代码行数:15,代码来源:FieldProblem_Roy.cs


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