本文整理汇总了C#中MockRepository.DynamicMock方法的典型用法代码示例。如果您正苦于以下问题:C# MockRepository.DynamicMock方法的具体用法?C# MockRepository.DynamicMock怎么用?C# MockRepository.DynamicMock使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MockRepository
的用法示例。
在下文中一共展示了MockRepository.DynamicMock方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CannotUseRepeatAny
public void CannotUseRepeatAny()
{
MockRepository mocks = new MockRepository();
IFoo54 demo = mocks.DynamicMock<IFoo54>();
mocks.ReplayAll();
demo.AssertWasCalled(x => x.Bar("a"), o => o.Repeat.Any());
}
示例2: DslFactoryFixture
public DslFactoryFixture()
{
factory = new DslFactory();
mocks = new MockRepository();
mockedDslEngine = mocks.DynamicMock<DslEngine>();
mockCache = mocks.DynamicMock<IDslEngineCache>();
mockCache.WriteLock(null);
LastCall.Repeat.Any()
.IgnoreArguments()
.Do((Action<CacheAction>) ExecuteCachedAction);
mockCache.ReadLock(null);
LastCall.Repeat.Any()
.IgnoreArguments()
.Do((Action<CacheAction>)ExecuteCachedAction);
IDslEngineStorage mockStorage = mocks.DynamicMock<IDslEngineStorage>();
Assembly assembly = Assembly.GetCallingAssembly();
context = new CompilerContext();
context.GeneratedAssembly = assembly;
mockedDslEngine.Storage = mockStorage;
mockedDslEngine.Cache = mockCache;
SetupResult.For(mockStorage.GetMatchingUrlsIn("", ref testUrl)).Return(new string[] { testUrl });
SetupResult.For(mockStorage.IsUrlIncludeIn(null, null, null))
.IgnoreArguments()
.Return(true);
}
示例3: setup
public void setup()
{
mocks = new MockRepository();
builder = new TestControllerBuilder();
session = mocks.DynamicMock<ISession>();
todoRepository = mocks.StrictMock<TodoRepository>(session);
todoController = new TodoController(todoRepository);
builder.InitializeController(todoController);
}
示例4: FieldProblem_leftend
public FieldProblem_leftend()
{
mocks = new MockRepository();
viewMock =
(IAddAlbumPresenter) mocks.DynamicMock(typeof (IAddAlbumPresenter));
albumMock = mocks.StrictMock<IAlbum>();
viewMock.Save += null;
LastCall.IgnoreArguments().Constraints(Is.NotNull());
saveRaiser = LastCall.GetEventRaiser();
}
示例5: TestSampleMatrixChanged
public void TestSampleMatrixChanged()
{
var repository = new MockRepository();
var mockTestClass = repository.DynamicMock<ClassToMock>();
mockTestClass.ChangeTestProperty += null;
var fireChangeTestProperty = LastCall.IgnoreArguments().GetEventRaiser();
new ClassRaisingException(mockTestClass);
repository.ReplayAll();
fireChangeTestProperty.Raise(true);
repository.VerifyAll();
}
示例6: GoodExplanationForUsingReturnAndRepeatNever
public void GoodExplanationForUsingReturnAndRepeatNever()
{
MockRepository mocks = new MockRepository();
ILogWriter eventLogMock = (ILogWriter)mocks.DynamicMock(typeof(ILogWriter));
Log log = new Log(null, eventLogMock, "MOCK", true, false);
Expect.Call(eventLogMock.WriteLog(EventLogEntryType.SuccessAudit, "MOCK", null, null, 0)).Return(true);
Assert.Throws<InvalidOperationException>(
"After specifying Repeat.Never(), you cannot specify a return value, exception to throw or an action to execute",
() => Expect.Call(eventLogMock.WriteLog(EventLogEntryType.FailureAudit, "MOCK", null, null, 0))
.Return(true).Repeat.Never());
}
示例7: 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?
}
示例8: 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";
}
}
示例9: CanUseSetupResultAndIgnoreArguments_WhenUsingUnorderedBlock
public void CanUseSetupResultAndIgnoreArguments_WhenUsingUnorderedBlock()
{
MockRepository mocks = new MockRepository();
IFetcher fetcher = mocks.DynamicMock<IFetcher>();
using (mocks.Unordered())
{
SetupResult.For(fetcher.GetUsersWithCriteriaLike(null)).IgnoreArguments().Return(
new Student[] {new Student(), new Student()});
}
mocks.ReplayAll();
Assert.Equal(2, fetcher.GetUsersWithCriteriaLike("foo").Length);
}
示例10: GoodExplanationForUsingReturnAndRepeatNever
public void GoodExplanationForUsingReturnAndRepeatNever()
{
MockRepository mocks = new MockRepository();
ILogWriter eventLogMock = (ILogWriter)mocks.DynamicMock(typeof(ILogWriter));
Log log = new Log(null, eventLogMock, "MOCK", true, false);
Expect.Call(eventLogMock.WriteLog(EventLogEntryType.SuccessAudit, "MOCK", null, null, 0)).Return(true);
//Actually I don't expect this one. But Repeat.Never() doesn't work.
Expect.Call(eventLogMock.WriteLog(EventLogEntryType.FailureAudit, "MOCK", null, null, 0))
.Return(true).Repeat.Never();
mocks.ReplayAll();
log.Audit(AuditOptions.Succes, null, null, null, 0);
mocks.VerifyAll();
}
示例11: IgnoreArgumentsAfterDo
public void IgnoreArgumentsAfterDo()
{
MockRepository mocks = new MockRepository();
IDemo demo = mocks.DynamicMock<IDemo>();
bool didDo = false;
demo.VoidNoArgs();
LastCall
.Do(SetToTrue(out didDo))
.IgnoreArguments();
mocks.ReplayAll();
demo.VoidNoArgs();
Assert.True(didDo, "Do has not been executed!");
mocks.VerifyAll();
}
示例12: WillDisposeInternalEnumeratorAndEnumerableWhenDisposed
public void WillDisposeInternalEnumeratorAndEnumerableWhenDisposed()
{
MockRepository mocks = new MockRepository();
IEnumerable<Row> enumerable = mocks.DynamicMultiMock<IEnumerable<Row>>(typeof(IDisposable));
IEnumerator<Row> enumerator = mocks.DynamicMock<IEnumerator<Row>>();
using(mocks.Record())
{
SetupResult.For(enumerable.GetEnumerator()).Return(enumerator);
enumerator.Dispose();
((IDisposable)enumerable).Dispose();
}
using (mocks.Playback())
{
DictionaryEnumeratorDataReader reader =
new DictionaryEnumeratorDataReader(new Dictionary<string, Type>(), enumerable);
reader.Dispose();
}
}
示例13: BackToRecordOnADynamicMock
public void BackToRecordOnADynamicMock()
{
MockRepository repository = new MockRepository();
ITest test = (ITest)repository.DynamicMock(typeof(ITest));
test.DoSomething(1);
repository.BackToRecord(test);
test.DoSomething(2);
repository.ReplayAll();
test.DoSomething(2);
test.DoSomething(3);
repository.VerifyAll();
}
示例14: WillFailVerificationsOfMethod_IfWereNotCalled_OnVoidMethod
public void WillFailVerificationsOfMethod_IfWereNotCalled_OnVoidMethod()
{
MockRepository mocks = new MockRepository();
IFoo54 demo = mocks.DynamicMock<IFoo54>();
mocks.ReplayAll();
demo.AssertWasCalled(x => x.DoSomethingElse());
}
示例15: WhenNoExpectationIsSetup_WillReturnDefaultValues
public void WhenNoExpectationIsSetup_WillReturnDefaultValues()
{
MockRepository mocks = new MockRepository();
IFoo54 demo = mocks.DynamicMock<IFoo54>();
Assert.AreEqual(0, demo.DoSomething());
}