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


C# MockRepository.Ordered方法代码示例

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


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

示例1: ShouldIgnoreArgumentsOnGenericCallWhenTypeIsStruct

        public void ShouldIgnoreArgumentsOnGenericCallWhenTypeIsStruct()
        {
            // setup
            MockRepository mocks = new MockRepository();
            ISomeService m_SomeServiceMock = mocks.StrictMock<ISomeService>();
            SomeClient sut = new SomeClient(m_SomeServiceMock);

            using (mocks.Ordered())
            {
                Expect.Call(delegate
                {
                    m_SomeServiceMock.DoSomething<string>(null, null);
                });
                LastCall.IgnoreArguments();

                Expect.Call(delegate
                {
                    m_SomeServiceMock.DoSomething<DateTime>(null, default(DateTime));  // can't use null here, because it's a value type!
                });
                LastCall.IgnoreArguments();

            }
            mocks.ReplayAll();

            // test
            sut.DoSomething();

            // verification
            mocks.VerifyAll();

            // cleanup
            m_SomeServiceMock = null;
            sut = null;
        }
开发者ID:bjornbouetsmith,项目名称:mammock,代码行数:34,代码来源:FieldProblem_Stephan.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: CanUseExpectSyntax_OnMockWithOrderedExpectations

        public void CanUseExpectSyntax_OnMockWithOrderedExpectations(bool shouldSwitchToReplyImmediately)
        {
            MockRepository mocks = new MockRepository();

            var foo54 = mocks.StrictMock<IFoo54>();
            if (shouldSwitchToReplyImmediately)
                mocks.ReplayAll();

            using (mocks.Ordered())
            {
                foo54
                    .Expect(x => x.DoSomething())
                    .Return(0);

                foo54
                    .Expect(x => x.DoSomethingElse());
            }

            if (!shouldSwitchToReplyImmediately)
                mocks.Replay(foo54);

            foo54.DoSomething();
            foo54.DoSomethingElse();

            foo54.VerifyAllExpectations();
        }
开发者ID:ChuangYang,项目名称:RhinoMocks,代码行数:26,代码来源:FieldProblem_Jodran.cs

示例4: WillRememberExceptionInsideOrderRecorderEvenIfInsideCatchBlock

        public void WillRememberExceptionInsideOrderRecorderEvenIfInsideCatchBlock()
        {
            MockRepository mockRepository = new MockRepository();
            IInterfaceWithThreeMethods interfaceWithThreeMethods = mockRepository.StrictMock<IInterfaceWithThreeMethods>();

            using (mockRepository.Ordered())
            {
                interfaceWithThreeMethods.A();
                interfaceWithThreeMethods.C();
            }

            mockRepository.ReplayAll();

            interfaceWithThreeMethods.A();
            try
            {
                interfaceWithThreeMethods.B();
            }
            catch { /* valid for code under test to catch all */ }
            interfaceWithThreeMethods.C();

            string expectedMessage="Unordered method call! The expected call is: 'Ordered: { IInterfaceWithThreeMethods.C(); }' but was: 'IInterfaceWithThreeMethods.B();'";
            ExpectationViolationException ex = Assert.Throws<ExpectationViolationException>(
                () => mockRepository.VerifyAll());
            Assert.Equal(expectedMessage, ex.Message);
        }
开发者ID:bjornbouetsmith,项目名称:mammock,代码行数:26,代码来源:FieldProblem_Sam.cs

示例5: CanUseSetupResultAndIgnoreArguments_WhenUsingOrderedBlock

        public void CanUseSetupResultAndIgnoreArguments_WhenUsingOrderedBlock()
        {
            MockRepository mocks = new MockRepository();
            IFetcher fetcher = mocks.DynamicMock<IFetcher>();

            using (mocks.Ordered())
            {
                SetupResult.For(fetcher.GetUsersWithCriteriaLike(null)).IgnoreArguments().Return(
                    new Student[] { new Student(), new Student() });
            }

            mocks.ReplayAll();

            Assert.Equal(2, fetcher.GetUsersWithCriteriaLike("foo").Length);
        }
开发者ID:ChuangYang,项目名称:RhinoMocks,代码行数:15,代码来源:SetupResultAndIgnoreArguments.cs

示例6: 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;
            }

            using (mocks.Playback())
            {
                mapper.MarkCustomerAsPreferred(customer);
            }
        }
开发者ID:bcraytor,项目名称:rhino-mocks,代码行数:20,代码来源:FieldProblem_Shane.cs

示例7: NestedInorderedAndAtLeastOnce

        public void NestedInorderedAndAtLeastOnce()
        {
            MockRepository mocks = new MockRepository();
            IMyObject myObject = mocks.StrictMock(typeof(IMyObject)) as IMyObject;

            using (mocks.Ordered())
            {
                using (mocks.Unordered()) // <-- Works only if ordered
                {
                    Expect.Call(myObject.SomeProperty).Return(null).Repeat.AtLeastOnce();
                }
                myObject.DoSomething();
            }

            mocks.ReplayAll();

            Assert.IsNull(myObject.SomeProperty);
            Assert.IsNull(myObject.SomeProperty);
            Assert.IsNull(myObject.SomeProperty);
            myObject.DoSomething();
            mocks.VerifyAll();
        }
开发者ID:bcraytor,项目名称:rhino-mocks,代码行数:22,代码来源:FieldProblem_Entropy.cs

示例8: WillRememberExceptionInsideOrderRecorderEvenIfInsideCatchBlock

        public void WillRememberExceptionInsideOrderRecorderEvenIfInsideCatchBlock()
        {
            MockRepository mockRepository = new MockRepository();
            IInterfaceWithThreeMethods interfaceWithThreeMethods = mockRepository.StrictMock<IInterfaceWithThreeMethods>();

            using (mockRepository.Ordered())
            {
                interfaceWithThreeMethods.A();
                interfaceWithThreeMethods.C();
            }

            mockRepository.ReplayAll();

            interfaceWithThreeMethods.A();
            try
            {
                interfaceWithThreeMethods.B();
            }
            catch { /* valid for code under test to catch all */ }
            interfaceWithThreeMethods.C();

            mockRepository.VerifyAll();
        }
开发者ID:nkmajeti,项目名称:rhino-tools,代码行数:23,代码来源:FieldProblem_Sam.cs

示例9: ShouldFailInNestedOrderringIfMethodWasNotCalled

        public void ShouldFailInNestedOrderringIfMethodWasNotCalled()
        {
            MockRepository mocks = new MockRepository();
            IMyObject myObject = mocks.StrictMock(typeof(IMyObject)) as IMyObject;

            using (mocks.Ordered())
            {
                using (mocks.Ordered())
                {
                    myObject.DoSomethingElse();
                    LastCall.Repeat.AtLeastOnce();
                }
                myObject.DoSomething();
            }

            mocks.ReplayAll();
            myObject.DoSomethingElse();
            mocks.VerifyAll();
        }
开发者ID:bcraytor,项目名称:rhino-mocks,代码行数:19,代码来源:FieldProblem_Entropy.cs

示例10: OrderedAndAtLeastOnce_CallingAnExtraMethod

        public void OrderedAndAtLeastOnce_CallingAnExtraMethod()
        {
            MockRepository mocks = new MockRepository();
            IMyObject myObject = mocks.StrictMock(typeof(IMyObject)) as IMyObject;

            using (mocks.Ordered())
            {
                Expect.Call(myObject.SomeProperty).Return(null).Repeat.AtLeastOnce();
            }
            myObject.DoSomethingElse();

            mocks.ReplayAll();

            Assert.IsNull(myObject.SomeProperty);
            Assert.IsNull(myObject.SomeProperty);
            Assert.IsNull(myObject.SomeProperty);
            myObject.DoSomething();

            mocks.VerifyAll();
        }
开发者ID:bcraytor,项目名称:rhino-mocks,代码行数:20,代码来源:FieldProblem_Entropy.cs

示例11: RecordOrdered

 private static void RecordOrdered(MockRepository mocks, IDemo demo)
 {
     using (mocks.Ordered())
     {
         demo.ReturnStringNoArgs();
         LastCall.On(demo).Return(null);
         demo.VoidNoArgs();
         LastCall.On(demo).Repeat.Twice();
         demo.VoidStringArg("Hello");
         demo.VoidStringArg("World");
     }
 }
开发者ID:bjornbouetsmith,项目名称:mammock,代码行数:12,代码来源:RhinoMockTests.cs

示例12: ShouldFailInNestedOrderringIfMethodWasNotCalled

        public void ShouldFailInNestedOrderringIfMethodWasNotCalled()
        {
            MockRepository mocks = new MockRepository();
            IMyObject myObject = mocks.StrictMock(typeof(IMyObject)) as IMyObject;

            using (mocks.Ordered())
            {
                using (mocks.Ordered())
                {
                    myObject.DoSomethingElse();
                    LastCall.Repeat.AtLeastOnce();
                }
                myObject.DoSomething();
            }

            mocks.ReplayAll();
            myObject.DoSomethingElse();
            Assert.Throws<ExpectationViolationException>(
                "IMyObject.DoSomething(); Expected #1, Actual #0.",
                () => mocks.VerifyAll());
        }
开发者ID:medmondson,项目名称:RhinoMocks,代码行数:21,代码来源:FieldProblem_Entropy.cs

示例13: OrderedAndAtLeastOnce_CallingAnExtraMethod

        public void OrderedAndAtLeastOnce_CallingAnExtraMethod()
        {
            MockRepository mocks = new MockRepository();
            IMyObject myObject = mocks.StrictMock(typeof(IMyObject)) as IMyObject;

            using (mocks.Ordered())
            {
                Expect.Call(myObject.SomeProperty).Return(null).Repeat.AtLeastOnce();
            }
            myObject.DoSomethingElse();

            mocks.ReplayAll();

            Assert.Null(myObject.SomeProperty);
            Assert.Null(myObject.SomeProperty);
            Assert.Null(myObject.SomeProperty);

            Assert.Throws<ExpectationViolationException>(
                @"IMyObject.DoSomething(); Expected #0, Actual #1.",
                () => myObject.DoSomething());
        }
开发者ID:medmondson,项目名称:RhinoMocks,代码行数:21,代码来源:FieldProblem_Entropy.cs

示例14: ConfigureOrderedAtLeastOnce

 private static void ConfigureOrderedAtLeastOnce(MockRepository mocks, I1 mockObject)
 {
     using (mocks.Ordered())
     {
         mockObject.A();
         mockObject.B();
         LastCall.Repeat.AtLeastOnce();
         mockObject.C();
     }
 }
开发者ID:medmondson,项目名称:RhinoMocks,代码行数:10,代码来源:OrderTest.cs

示例15: ExampleUsingCallbacks

        public void ExampleUsingCallbacks()
        {
            MockRepository mocks = new MockRepository();

            ISongBird maleBird = (ISongBird)mocks.StrictMock(typeof(ISongBird)),
                femaleBird = (ISongBird)mocks.StrictMock(typeof(ISongBird));

            using (mocks.Ordered())
            {
                using (mocks.Unordered())
                {
                    maleBird.MoveToCage(null);
                    LastCall.On(maleBird).Callback(new CageDelegate(IsSameCage));
                    femaleBird.MoveToCage(null);
                    LastCall.On(femaleBird).Callback(new CageDelegate(IsSameCage));
                }
                maleBird.Eat("seeds", 250);
                femaleBird.Eat("seeds", 250);
                using (mocks.Unordered())
                {
                    maleBird.Mate(femaleBird);
                    femaleBird.Mate(maleBird);
                }
            }
            mocks.ReplayAll();

            BirdVeterinary vet = new BirdVeterinary();
            vet.Mate(maleBird, femaleBird);
            mocks.VerifyAll();
        }
开发者ID:nkmajeti,项目名称:rhino-tools,代码行数:30,代码来源:IntegrationTests.cs


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