本文整理汇总了C#中MockRepository.Create方法的典型用法代码示例。如果您正苦于以下问题:C# MockRepository.Create方法的具体用法?C# MockRepository.Create怎么用?C# MockRepository.Create使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MockRepository
的用法示例。
在下文中一共展示了MockRepository.Create方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ShouldCreateMockWithConstructorArgs
public void ShouldCreateMockWithConstructorArgs()
{
var repository = new MockRepository(MockBehavior.Loose);
var mock = repository.Create<BaseClass>("foo");
Assert.Equal("foo", mock.Object.Value);
}
示例2: ShouldCreateMocksWithFactoryBehavior
public void ShouldCreateMocksWithFactoryBehavior()
{
var repository = new MockRepository(MockBehavior.Loose);
var mock = repository.Create<IFormatProvider>();
Assert.Equal(MockBehavior.Loose, mock.Behavior);
}
示例3: ShouldAggregateFailures
public void ShouldAggregateFailures()
{
try
{
var repository = new MockRepository(MockBehavior.Loose);
var foo = repository.Create<IFoo>();
var bar = repository.Create<IBar>();
foo.Setup(f => f.Do());
bar.Setup(b => b.Redo());
repository.VerifyAll();
}
catch (MockException mex)
{
Expression<Action<IFoo>> fooExpect = f => f.Do();
Assert.True(mex.Message.Contains(fooExpect.ToString()));
Expression<Action<IBar>> barExpect = b => b.Redo();
Assert.True(mex.Message.Contains(barExpect.ToString()));
}
}
示例4: ShouldAssignNullCallSequenceToCreatedMocksByDefault
public void ShouldAssignNullCallSequenceToCreatedMocksByDefault()
{
var repository = new MockRepository(MockBehavior.Default);
var mock = repository.Create<IFoo>();
Assert.Throws<NoSequenceAssignedException>(
() => mock.CallSequence.Verify(
mock.CallTo(m => m.Do()),
mock.CallTo(m => m.Undo())
)
);
}
示例5: ShouldVerifyAll
public void ShouldVerifyAll()
{
try
{
var repository = new MockRepository(MockBehavior.Default);
var mock = repository.Create<IFoo>();
mock.Setup(foo => foo.Do());
repository.VerifyAll();
}
catch (MockException mex)
{
Assert.Equal(MockException.ExceptionReason.VerificationFailed, mex.Reason);
}
}
示例6: ShouldCreateMocksWithFactoryCallBase
public void ShouldCreateMocksWithFactoryCallBase()
{
var repository = new MockRepository(MockBehavior.Loose);
var mock = repository.Create<BaseClass>();
mock.Object.BaseMethod();
Assert.False(mock.Object.BaseCalled);
repository.CallBase = true;
mock = repository.Create<BaseClass>();
mock.Object.BaseMethod();
Assert.True(mock.Object.BaseCalled);
}
示例7: ShouldVerifyVerifiables
public void ShouldVerifyVerifiables()
{
try
{
var repository = new MockRepository(MockBehavior.Default);
var mock = repository.Create<IFoo>();
mock.Setup(foo => foo.Do());
mock.Setup(foo => foo.Undo()).Verifiable();
repository.Verify();
}
catch (MockException mex)
{
Assert.Equal(MockException.ExceptionReason.VerificationFailed, mex.Reason);
Expression<Action<IFoo>> doExpr = foo => foo.Do();
Assert.False(mex.Message.Contains(doExpr.ToString()));
}
}
示例8: ShouldCreateMocksWithFactoryDefaultValue
public void ShouldCreateMocksWithFactoryDefaultValue()
{
var repository = new MockRepository(MockBehavior.Loose) { DefaultValue = DefaultValue.Mock };
var mock = repository.Create<IFoo>();
Assert.NotNull(mock.Object.Bar());
}
示例9: ShouldOverrideDefaultBehaviorWithCtorArgs
public void ShouldOverrideDefaultBehaviorWithCtorArgs()
{
var repository = new MockRepository(MockBehavior.Loose);
var mock = repository.Create<BaseClass>(MockBehavior.Strict, "Foo");
Assert.Equal(MockBehavior.Strict, mock.Behavior);
Assert.Equal("Foo", mock.Object.Value);
}
示例10: ShouldOverrideDefaultBehavior
public void ShouldOverrideDefaultBehavior()
{
var repository = new MockRepository(MockBehavior.Loose);
var mock = repository.Create<IFoo>(MockBehavior.Strict);
Assert.Equal(MockBehavior.Strict, mock.Behavior);
}
示例11: ShouldAssignTheSameCallSequenceToCreatedMocksThatWasAssignedToIt
public void ShouldAssignTheSameCallSequenceToCreatedMocksThatWasAssignedToIt()
{
var callSequence = new CallSequence(MockBehavior.Strict);
var repository = new MockRepository(MockBehavior.Default)
{
CallSequence = callSequence
};
var mock = repository.Create<IFoo>();
Assert.Equal(callSequence, mock.CallSequence);
}