本文整理汇总了C#中MockRepository.Stub方法的典型用法代码示例。如果您正苦于以下问题:C# MockRepository.Stub方法的具体用法?C# MockRepository.Stub怎么用?C# MockRepository.Stub使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MockRepository
的用法示例。
在下文中一共展示了MockRepository.Stub方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: StubDemoTestFixture
public StubDemoTestFixture()
{
_mocks = new MockRepository();
_mockBase = _mocks.Stub<IBase>();
_mockChild = _mocks.Stub<IChild>();
_mocks.ReplayAll();
}
示例2: SetUp
public void SetUp()
{
_mocks = new MockRepository();
_mockBase = _mocks.Stub<IBase>();
_mockChild = _mocks.Stub<IChild>();
_mocks.ReplayAll();
}
示例3: CanUseStubSyntaxOnMocksInRecordMode
public void CanUseStubSyntaxOnMocksInRecordMode()
{
MockRepository mocks = new MockRepository();
var service = mocks.Stub<IService>();
var view = mocks.Stub<IView>();
service.Stub(x => x.GetString()).Return("Test");
var presenter = new Presenter(view, service);
mocks.ReplayAll();
presenter.OnViewLoaded();
view.AssertWasCalled(x => x.Message = "Test");
}
示例4: SetupResult_For_writeable_property_on_stub_should_be_ignored
public void SetupResult_For_writeable_property_on_stub_should_be_ignored()
{
MockRepository mocks = new MockRepository();
TestClass test = mocks.Stub<TestClass>();
SetupResult.For(test.ReadOnly).Return("foo");
SetupResult.For(test.ReadWrite).PropertyBehavior();
}
示例5: MultiStubShouldGenerateStubWithOnlyBaseClass
public void MultiStubShouldGenerateStubWithOnlyBaseClass()
{
var mockRepository = new MockRepository();
var animal = (IAnimal)mockRepository.Stub(typeof(IAnimal), null, null);
Assert.NotNull(animal);
Assert.Null(animal as ICat);
}
示例6: Stub
public static PageTypeUpdater Stub(MockRepository fakesRepository)
{
return fakesRepository.Stub<PageTypeUpdater>(
PageTypeDefinitionLocatorFactory.Stub(),
new PageTypeFactory(),
new PageTypeValueExtractor(),
new PageTypeLocator(new PageTypeFactory()));
}
示例7: MultiStubShouldGenerateStubWithMultiInterfaces
public void MultiStubShouldGenerateStubWithMultiInterfaces()
{
var mockRepository = new MockRepository();
var animal = (IAnimal)mockRepository.Stub(typeof(IAnimal), new[] { typeof(ICat) });
var cat = (ICat)animal;
Assert.NotNull(cat);
Assert.NotNull(animal);
}
示例8: SetupPageTypeUpdaterWithFakePageTypeFactory
private void SetupPageTypeUpdaterWithFakePageTypeFactory(PageTypeUpdater pageTypeUpdater)
{
MockRepository mocks = new MockRepository();
PageTypeFactory fakePageTypeFactory = mocks.Stub<PageTypeFactory>();
fakePageTypeFactory.Stub(factory => factory.Save(Arg<IPageType>.Is.NotNull));
fakePageTypeFactory.Stub(factory => factory.CreateNew()).Return(new NativePageType());
fakePageTypeFactory.Replay();
pageTypeUpdater.PageTypeFactory = fakePageTypeFactory;
}
示例9: PropertiesWillBehaveLikeProperties
public void PropertiesWillBehaveLikeProperties()
{
MockRepository mocks = new MockRepository();
TestObject testObject = mocks.Stub<TestObject>();
mocks.ReplayAll();
Assert.Equal(0, testObject.IntProperty);
}
示例10: TestInitialize
public void TestInitialize()
{
mocks = new MockRepository();
smsSender = mocks.CreateMock<ISmsSender>();
user = new User("sally", "1234");
userRepository = mocks.Stub<IUserRepository>();
SetupResult.For(userRepository.GetByUserName("sally"))
.Return(user);
}
示例11: CannotCallLastCallConstraintsMoreThanOnce
public void CannotCallLastCallConstraintsMoreThanOnce()
{
MockRepository repository = new MockRepository();
IGetResults resultGetter = repository.Stub<IGetResults>();
using (repository.Record())
{
resultGetter.GetSomeNumber("a");
LastCall.Constraints(Text.Contains("b"));
LastCall.Constraints(Text.Contains("a"));
}
}
示例12: SetupResult_For_writeable_property_on_stub_should_be_ignored
public void SetupResult_For_writeable_property_on_stub_should_be_ignored()
{
MockRepository mocks = new MockRepository();
TestClass test = mocks.Stub<TestClass>();
SetupResult.For(test.ReadOnly).Return("foo");
const string expected =
@"You are trying to set an expectation on a property that was defined to use PropertyBehavior.
Instead of writing code such as this: mockObject.Stub(x => x.SomeProperty).Return(42);
You can use the property directly to achieve the same result: mockObject.SomeProperty = 42;";
Assert.Throws<InvalidOperationException>(expected, () => SetupResult.For(test.ReadWrite).PropertyBehavior());
}
示例13: StubNeverFailsTheTest
public void StubNeverFailsTheTest()
{
MockRepository repository = new MockRepository();
IGetResults resultGetter = repository.Stub<IGetResults>();
using (repository.Record())
{
resultGetter.GetSomeNumber("a");
LastCall.Return(1);
}
int result = resultGetter.GetSomeNumber("b");
Assert.Equal(0, result);
repository.VerifyAll(); //<- should not fail the test methinks
}
示例14: CanGetSetupResultFromStub
public void CanGetSetupResultFromStub()
{
MockRepository repository = new MockRepository();
IGetResults resultGetter = repository.Stub<IGetResults>();
using (repository.Record())
{
resultGetter.GetSomeNumber("a");
LastCall.Return(1);
}
int result = resultGetter.GetSomeNumber("a");
Assert.Equal(1, result);
repository.VerifyAll();
}
示例15: CannotCallLastCallConstraintsMoreThanOnce
public void CannotCallLastCallConstraintsMoreThanOnce()
{
MockRepository repository = new MockRepository();
IGetResults resultGetter = repository.Stub<IGetResults>();
var ex = Assert.Throws<InvalidOperationException>(() =>
{
using (repository.Record())
{
resultGetter.GetSomeNumber("a");
LastCall.Constraints(Text.Contains("b"));
LastCall.Constraints(Text.Contains("a"));
}
});
Assert.Equal("You have already specified constraints for this method. (IGetResults.GetSomeNumber(contains \"b\");)", ex.Message);
}