本文整理汇总了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;
}
示例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);
}
示例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();
}
示例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);
}
示例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);
}
示例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);
}
}
示例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();
}
示例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();
}
示例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();
}
示例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();
}
示例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");
}
}
示例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());
}
示例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());
}
示例14: ConfigureOrderedAtLeastOnce
private static void ConfigureOrderedAtLeastOnce(MockRepository mocks, I1 mockObject)
{
using (mocks.Ordered())
{
mockObject.A();
mockObject.B();
LastCall.Repeat.AtLeastOnce();
mockObject.C();
}
}
示例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();
}