本文整理汇总了C#中MockRepository.Playback方法的典型用法代码示例。如果您正苦于以下问题:C# MockRepository.Playback方法的具体用法?C# MockRepository.Playback怎么用?C# MockRepository.Playback使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MockRepository
的用法示例。
在下文中一共展示了MockRepository.Playback方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: 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);
}
}
示例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: 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);
}
示例4: 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();
}
}
示例5: 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();
}
}
示例6: 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");
}
}
示例7: 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");
}
}
示例8: CanRecordPlayback
public void CanRecordPlayback()
{
MockRepository mockRepository;
mockRepository = new MockRepository();
IFoo mockedFoo = mockRepository.StrictMock<IFoo>();
using (mockRepository.Record())
{
Expect.Call(mockedFoo.Bar()).Return(42);
}
using (mockRepository.Playback())
{
Fooz fooz = new Fooz(mockedFoo);
fooz.Barz();
}
}
示例9: 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";
}
}
示例10: 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>());
}
using (mocks.Playback())
{
ExpectedBarPerformer cut = new ExpectedBarPerformer(mockSomeSystem);
cut.DoStuffWithExpectedBar("foo");
}
}
示例11: Setter_Expectation_Not_Fullfilled
public void Setter_Expectation_Not_Fullfilled()
{
MockRepository mocks = new MockRepository();
IBar bar = mocks.StrictMock<IBar>();
using (mocks.Record())
{
Expect.Call(bar.Foo).SetPropertyAndIgnoreArgument();
}
using (mocks.Playback())
{
}
mocks.VerifyAll();
}
示例12: CorrectResultForExpectedWhenUsingTimesWithRange
public void CorrectResultForExpectedWhenUsingTimesWithRange()
{
MockRepository mocks = new MockRepository();
IView view = mocks.StrictMock<IView>();
using (mocks.Record())
{
view.RedrawDisplay(null);
LastCall.Repeat.Times(3,4).IgnoreArguments();
}
using(mocks.Playback())
{
for (int i = 0; i < 5; i++)
{
view.RedrawDisplay("blah");
}
}
}
示例13: IsMatching
public void IsMatching()
{
MockRepository mocks = new MockRepository();
IView view = mocks.StrictMock<IView>();
using (mocks.Record())
{
view.Foo = null;
Predicate<int> alwaysReturnsTrue = delegate(int input)
{
return true;
};
LastCall.Constraints(Is.Matching(alwaysReturnsTrue));
}
using (mocks.Playback())
{
view.Foo = 1;
}
}
示例14: Setter_Expectation_Not_Fullfilled
public void Setter_Expectation_Not_Fullfilled()
{
MockRepository mocks = new MockRepository();
IBar bar = mocks.StrictMock<IBar>();
using (mocks.Record())
{
Expect.Call(bar.Foo).SetPropertyAndIgnoreArgument();
}
Assert.Throws<ExpectationViolationException>("IBar.set_Foo(any); Expected #1, Actual #0.", () =>
{
using (mocks.Playback())
{
}
});
}
示例15: TestOutMethod
public void TestOutMethod()
{
MockRepository mocks = new MockRepository();
ITest mockProxy = mocks.StrictMock<ITest>();
int intTest = 0;
using (mocks.Record())
{
Expect.Call(delegate { mockProxy.Addnumber(out intTest); }).OutRef(4);
}
using(mocks.Playback())
{
mockProxy.Addnumber(out intTest);
Assert.Equal(4, intTest);
}
}