public void WhenNoExpectationIsSetup_WillReturnDefaultValues() { MockRepository mocks = new MockRepository(); IFoo54 demo = mocks.DynamicMock <IFoo54>(); Assert.Equal(0, demo.DoSomething()); }
public void WillFailVerificationsOfMethod_IfWereNotCalled_OnVoidMethod() { MockRepository mocks = new MockRepository(); IFoo54 demo = mocks.DynamicMock <IFoo54>(); mocks.ReplayAll(); Assert.Throws <ExpectationViolationException>( "IFoo54.DoSomethingElse(); Expected #1, Actual #0.", () => demo.AssertWasCalled(x => x.DoSomethingElse())); }
public void CanUseNonRecordReplayModel_Expect_OnVoidMethod() { MockRepository mocks = new MockRepository(); IFoo54 demo = mocks.DynamicMock <IFoo54>(); demo.Expect(x => x.DoSomethingElse()); mocks.Replay(demo); demo.DoSomethingElse(); mocks.VerifyAll(); }
public void CanUseNonRecordReplayModel_Stub_WillNotThrowIfExpectationIsNotMet() { MockRepository mocks = new MockRepository(); IFoo54 demo = mocks.DynamicMock <IFoo54>(); demo.Stub(x => x.DoSomething()).Return(1); mocks.Replay(demo); mocks.VerifyAll(); }
public void CanUseNonRecordReplayModel_Stub() { MockRepository mocks = new MockRepository(); IFoo54 demo = mocks.DynamicMock <IFoo54>(); demo.Stub(x => x.DoSomething()).Return(1); mocks.Replay(demo); Assert.Equal(1, demo.DoSomething()); }
public void CannotUseRepeatAny() { MockRepository mocks = new MockRepository(); IFoo54 demo = mocks.DynamicMock <IFoo54>(); mocks.ReplayAll(); Assert.Throws <InvalidOperationException>( "The expectation was removed from the waiting expectations list, did you call Repeat.Any() ? This is not supported in AssertWasCalled()", () => demo.AssertWasCalled(x => x.Bar("a"), o => o.Repeat.Any())); }
public void CanAssertNotCalledOnPropertyAccess() { MockRepository mocks = new MockRepository(); IFoo54 demo = mocks.DynamicMock <IFoo54>(); mocks.Replay(demo); demo.DoSomething(); demo.AssertWasNotCalled(x => x.FooBar); }
public void CanAssertOnPropertyAccess() { MockRepository mocks = new MockRepository(); IFoo54 demo = mocks.DynamicMock <IFoo54>(); mocks.Replay(demo); var result = demo.FooBar; demo.AssertWasCalled(x => x.FooBar); }
public void CanAssertOnMethodCall() { MockRepository mocks = new MockRepository(); IFoo54 demo = mocks.DynamicMock <IFoo54>(); mocks.Replay(demo); demo.DoSomething(); demo.AssertWasCalled(x => x.DoSomething()); }
public void WillRaiseErrorIfNoExpectationWasSetup() { MockRepository mocks = new MockRepository(); IFoo54 demo = mocks.DynamicMock <IFoo54>(); mocks.Replay(demo); Assert.Throws <InvalidOperationException>( "No expectations were setup to be verified, ensure that the method call in the action is a virtual (C#) / overridable (VB.Net) method call", () => demo.AssertWasCalled(x => { })); }
public void UsingExpectWithoutSettingReturnValueThrows() { MockRepository mocks = new MockRepository(); IFoo54 demo = mocks.DynamicMock <IFoo54>(); demo.Expect(x => x.DoSomething()); mocks.Replay(demo); Assert.Throws <InvalidOperationException>( "Method 'IFoo54.DoSomething();' requires a return value or an exception to throw.", () => Assert.Equal(1, demo.DoSomething())); }
public void CanAssertOnMethodCallUsingConstraints() { MockRepository mocks = new MockRepository(); IFoo54 demo = mocks.DynamicMock <IFoo54>(); mocks.Replay(demo); demo.Bar("blah baba"); demo.AssertWasCalled(x => x.Bar(Arg <string> .Matches((string a) => a.StartsWith("b") && a.Contains("ba")))); }
public void CanUseNonRecordReplayModel_Stub_AndThenVerify_WhenNotCalled_WillCauseError() { MockRepository mocks = new MockRepository(); IFoo54 demo = mocks.DynamicMock <IFoo54>(); demo.Stub(x => x.DoSomething()).Return(1); mocks.Replay(demo); Assert.Throws <ExpectationViolationException>( "IFoo54.DoSomething(); Expected #1, Actual #0.", () => demo.AssertWasCalled(x => x.DoSomething())); }
public void CanUseNonRecordReplayModel_Expect_OnVoidMethod_WhenMethodNotcall_WillFailTest() { MockRepository mocks = new MockRepository(); IFoo54 demo = mocks.DynamicMock <IFoo54>(); demo.Expect(x => x.DoSomethingElse()); mocks.Replay(demo); Assert.Throws <ExpectationViolationException>( "IFoo54.DoSomethingElse(); Expected #1, Actual #0.", () => mocks.VerifyAll()); }
public void TypeShouldBeInferredFromMockNotReference() { MockRepository mocks = new MockRepository(); IFoo54 demo = mocks.DynamicMock <Foo54>(0); demo.Stub(x => x.DoSomethingElse()); mocks.Replay(demo); demo.DoSomethingElse(); demo.AssertWasCalled(x => x.DoSomethingElse()); }
public void CanUseNonRecordReplayModel_Expect() { MockRepository mocks = new MockRepository(); IFoo54 demo = mocks.DynamicMock <IFoo54>(); demo.Expect(x => x.DoSomething()).Return(1).Repeat.Once(); mocks.Replay(demo); Assert.Equal(1, demo.DoSomething()); demo.Expect(x => x.DoSomething()).Return(15).Repeat.Once(); Assert.Equal(15, demo.DoSomething()); mocks.VerifyAll(); }
public void CanAssertOnPropertyAccessWithConstraints() { MockRepository mocks = new MockRepository(); IFoo54 demo = mocks.DynamicMock <IFoo54>(); mocks.Replay(demo); var result = demo.FooBar; result = demo.FooBar; demo.AssertWasCalled(x => x.FooBar, o => o.Repeat.Twice()); }
public void CanAssertOnMethodCallUsingConstraints_WhenMethodNotFound() { MockRepository mocks = new MockRepository(); IFoo54 demo = mocks.DynamicMock <IFoo54>(); mocks.ReplayAll(); demo.Bar("yoho"); Assert.Throws <ExpectationViolationException>( "IFoo54.Bar(a => (a.StartsWith(\"b\") && a.Contains(\"ba\"))); Expected #1, Actual #0." , () => demo.AssertWasCalled(x => x.Bar(Arg <string> .Matches((string a) => a.StartsWith("b") && a.Contains("ba"))))); }
public void CanOnlyPassSingleExpectationToVerify() { MockRepository mocks = new MockRepository(); IFoo54 demo = mocks.DynamicMock <IFoo54>(); mocks.Replay(demo); Assert.Throws <InvalidOperationException>( "You can only use a single expectation on AssertWasCalled(), use separate calls to AssertWasCalled() if you want to verify several expectations", () => demo.AssertWasCalled(x => { x.DoSomethingElse(); x.DoSomethingElse(); })); }
public void CanUseNonRecordReplayModel_Stub_OnVoidMethod() { MockRepository mocks = new MockRepository(); IFoo54 demo = mocks.DynamicMock <IFoo54>(); demo.Stub(x => x.DoSomethingElse()).Throw(new InvalidOperationException("foo")); mocks.Replay(demo); try { demo.DoSomethingElse(); Assert.False(true, "Should throw"); } catch (InvalidOperationException e) { Assert.Equal("foo", e.Message); } }