本文整理汇总了C#中MockRepository.ReplayAll方法的典型用法代码示例。如果您正苦于以下问题:C# MockRepository.ReplayAll方法的具体用法?C# MockRepository.ReplayAll怎么用?C# MockRepository.ReplayAll使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MockRepository
的用法示例。
在下文中一共展示了MockRepository.ReplayAll方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Can_mix_assert_was_call_with_verify_all
public void Can_mix_assert_was_call_with_verify_all()
{
MockRepository mocks = new MockRepository();
var errorHandler = mocks.DynamicMock<IErrorHandler>();
mocks.ReplayAll();
var ex = new Exception("Take this");
errorHandler.HandleError(ex);
errorHandler.AssertWasCalled(eh => eh.HandleError(ex));
mocks.ReplayAll();
mocks.VerifyAll(); // Can I still keep this somehow?
}
示例2: 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();
}
示例3: 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);
}
示例4: 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;
}
示例5: Test_View_Events_WiredUp
public void Test_View_Events_WiredUp()
{
MockRepository mocks = new MockRepository();
IView view = mocks.StrictMock<IView>();
// expect that the model is set on the view
// NOTE: if I move this Expect.Call above
// the above Expect.Call, Rhino mocks blows up on with an
// "This method has already been set to ArgsEqualExpectation."
// not sure why. Its a side issue.
Expect.Call(view.Model = Arg<Model>.Is.NotNull);
// expect the event ClickButton to be wired up
IEventRaiser clickButtonEvent =
Expect.Call(delegate
{
view.ClickButton += null;
}).IgnoreArguments().GetEventRaiser();
// Q: How do i set an expectation that checks that the controller
// correctly updates the model in the event handler.
// i.e. above we know that the controller executes
// _model.UserName = "Keith here :)"
// but how can I verify it?
// The following wont work, because Model is null:
// Expect.Call(view.Model.UserName = Arg<String>.Is.Anything);
mocks.ReplayAll();
Controller controller = new Controller(view);
clickButtonEvent.Raise(null, null);
mocks.VerifyAll();
}
示例6: TestChar
public void TestChar()
{
MockRepository mocks = new MockRepository();
IProvider mockProvider = (IProvider)mocks.StrictMock(typeof(IProvider));
SetupResult.For(mockProvider.GetChar()).Return('X');
mocks.ReplayAll();
Assert.Equal('X', mockProvider.GetChar()); // actual is a random char
}
示例7: TestInt32
public void TestInt32()
{
MockRepository mocks = new MockRepository();
IProvider mockProvider = (IProvider)mocks.StrictMock(typeof(IProvider));
SetupResult.For(mockProvider.GetInt32()).Return(100);
mocks.ReplayAll();
Assert.Equal(100, mockProvider.GetInt32()); // actual is 100
}
示例8: Can_do_nested_virtual_calls_when_not_called
public void Can_do_nested_virtual_calls_when_not_called()
{
var mocks = new MockRepository();
var subject = mocks.PartialMock<SUT>();
mocks.ReplayAll();
subject.AssertWasCalled(it => it.NestedVirtualMethod());
}
示例9: MockAClassWithFinalizer
public void MockAClassWithFinalizer()
{
MockRepository mocks = new MockRepository();
ClassWithFinalizer withFinalizer = (ClassWithFinalizer) mocks.StrictMock(typeof (ClassWithFinalizer));
mocks.ReplayAll();
mocks.VerifyAll(); //move it to verify state
withFinalizer = null; // abandon the variable, will make it avialable for GC.
GC.WaitForPendingFinalizers();
}
示例10: MockClass
public void MockClass()
{
MockRepository mocks = new MockRepository();
RemotableDemoClass demo = (RemotableDemoClass)mocks.StrictMock(typeof(RemotableDemoClass));
Expect.Call(demo.Two()).Return(44);
mocks.ReplayAll();
Assert.Equal(44, contextSwitcher.DoStuff(demo));
mocks.VerifyAll();
}
示例11: Test
public void Test()
{
MockRepository mocks = new MockRepository();
SimpleOperations myMock = mocks.StrictMock<SimpleOperations>();
Expect.Call(myMock.AddTwoValues(1, 2)).Return(3);
mocks.ReplayAll();
Assert.Equal(3, myMock.AddTwoValues(1, 2));
mocks.VerifyAll();
}
示例12: Can_do_nested_virtual_calls_when_not_called
public void Can_do_nested_virtual_calls_when_not_called()
{
var mocks = new MockRepository();
var subject = mocks.PartialMock<SUT>();
mocks.ReplayAll();
var ex = Assert.Throws<ExpectationViolationException>(() => subject.AssertWasCalled(it => it.NestedVirtualMethod()));
Assert.Equal("SUT.NestedVirtualMethod(); Expected #1, Actual #0.", ex.Message);
}
示例13: PropertiesWillBehaveLikeProperties
public void PropertiesWillBehaveLikeProperties()
{
MockRepository mocks = new MockRepository();
TestObject testObject = mocks.Stub<TestObject>();
mocks.ReplayAll();
Assert.Equal(0, testObject.IntProperty);
}
示例14: SetUp
public void SetUp()
{
_mocks = new MockRepository();
_mockBase = _mocks.Stub<IBase>();
_mockChild = _mocks.Stub<IChild>();
_mocks.ReplayAll();
}
示例15: CanMockInternalInterface
public void CanMockInternalInterface()
{
MockRepository mocks = new MockRepository();
IInternal mock = mocks.StrictMock<IInternal>();
mock.Foo();
mocks.ReplayAll();
mock.Foo();
mocks.VerifyAll();
}