本文整理汇总了C#中MockRepository.StrictMock方法的典型用法代码示例。如果您正苦于以下问题:C# MockRepository.StrictMock方法的具体用法?C# MockRepository.StrictMock怎么用?C# MockRepository.StrictMock使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MockRepository
的用法示例。
在下文中一共展示了MockRepository.StrictMock方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: SameNameInterface
public void SameNameInterface()
{
MockRepository mocks = new MockRepository();
IDemo demo1 = (IDemo)mocks.StrictMock(typeof(IDemo));
Other.IDemo demo2 = (Other.IDemo)mocks.StrictMock(typeof(Other.IDemo));
Assert.NotEqual(demo1.GetType(), demo2.GetType());
}
示例2: GenericMethodWithConstrait
public void GenericMethodWithConstrait()
{
MockRepository mocks = new MockRepository();
IClass1 class1 = mocks.StrictMock<IClass1>();
IClass2 class2 = mocks.StrictMock<IClass2>();
class1.Method1<int>(1);
class2.Method2(mocks);
}
示例3: CanMockIE
public void CanMockIE()
{
//TODO: Figure out why this does not work.
MockRepository mockRepository = new MockRepository();
IHTMLEventObj2 mock = mockRepository.StrictMock<IHTMLEventObj2>();
Assert.NotNull(mock);
}
示例4: CallbackTests
public CallbackTests()
{
System.Threading.Thread.CurrentThread.CurrentCulture = System.Globalization.CultureInfo.InvariantCulture;
mocks = new MockRepository();
demo = (IDemo) mocks.StrictMock(typeof (IDemo));
callbackCalled = false;
}
示例5: 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);
}
示例6: 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);
}
示例7: CantCallOriginalMethodOnAbstractMethod
public void CantCallOriginalMethodOnAbstractMethod()
{
MockRepository mocks = new MockRepository();
MockingClassesTests.AbstractDemo demo = (MockingClassesTests.AbstractDemo)mocks.StrictMock(typeof(MockingClassesTests.AbstractDemo));
var ex = Assert.Throws<InvalidOperationException>(() => SetupResult.For(demo.Six()).CallOriginalMethod(OriginalCallOptions.CreateExpectation));
Assert.Equal("Can't use CallOriginalMethod on method Six because the method is abstract.", ex.Message);
}
示例8: MockInternalClass
public void MockInternalClass()
{
MockRepository mocker = new MockRepository();
InternalClass mockInternalClass = mocker.StrictMock<InternalClass>();
Assert.IsNotNull(mockInternalClass);
}
示例9: CallbackExpectationTests
public CallbackExpectationTests()
{
mocks = new MockRepository();
demo = (IDemo) mocks.StrictMock(typeof (IDemo));
method = typeof (IDemo).GetMethod("VoidThreeArgs");
callbackCalled = false;
}
示例10: 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();
}
示例11: 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);
}
}
示例12: 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();
}
示例13: 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;
}
示例14: 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);
}
示例15: 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);
}