public void Arrange_CallBackFourArguments_InvokesCallback() { var mockContext = new MockContext <IFoo>(); var fooMock = new FooMock(mockContext); int firstResult = 0; int secondResult = 0; int thirdResult = 0; int fourthResult = 0; mockContext.Arrange( f => f.Execute(The <int> .IsAnyValue, The <int> .IsAnyValue, The <int> .IsAnyValue, The <int> .IsAnyValue)) .Callback <int, int, int, int>( (i1, i2, i3, i4) => { firstResult = i1; secondResult = i2; thirdResult = i3; fourthResult = i4; }); fooMock.Execute(1, 2, 3, 4); Assert.AreEqual(1, firstResult); Assert.AreEqual(2, secondResult); Assert.AreEqual(3, thirdResult); Assert.AreEqual(4, fourthResult); }
public void Arrange_ExceptionFactory_ThrowsException() { var mockContext = new MockContext <IFoo>(); var fooMock = new FooMock(mockContext); mockContext.Arrange(f => f.Execute("SomeValue")).Throws(() => new InvalidOperationException()); fooMock.Execute("SomeValue"); }
public void Assert_WithValidMatchPredicate_IsVerified() { var mockContext = new MockContext <IFoo>(); var fooMock = new FooMock(mockContext); fooMock.Execute("SomeValue"); mockContext.Assert(f => f.Execute(The <string> .Is(s => s.StartsWith("Some"))), Invoked.Once); }
public void Assert_Once_IsVerified() { var mockContext = new MockContext <IFoo>(); var fooMock = new FooMock(mockContext); fooMock.Execute("SomeValue"); mockContext.Assert(f => f.Execute("SomeValue")); }
public void Assert_IsAnyValue_IsVerified() { var mockContext = new MockContext <IFoo>(); var fooMock = new FooMock(mockContext); fooMock.Execute("SomeValue"); mockContext.Assert(f => f.Execute(The <string> .IsAnyValue), Invoked.Once); }
public void Assert_InvokedOnceExpectedOnce_IsVerified() { var mockContext = new MockContext <IFoo>(); var fooMock = new FooMock(mockContext); fooMock.Execute("SomeValue"); mockContext.Assert(f => f.Execute("SomeValue"), Invoked.Once); }
public void Assert_NeverWhenInvoked_ThrowsException() { var mockContext = new MockContext <IFoo>(); var fooMock = new FooMock(mockContext); fooMock.Execute("SomeValue"); mockContext.Assert(f => f.Execute("SomeValue"), Invoked.Never); }
public void Assert_WithInvalidMatchPredicate_ThrowsException() { var mockContext = new MockContext <IFoo>(); var fooMock = new FooMock(mockContext); fooMock.Execute("SomeValue"); mockContext.Assert(f => f.Execute(The <string> .Is(s => s == "AnotherValue")), Invoked.Once); }
public void Assert_Null_IsVerified() { var mockContext = new MockContext <IFoo>(); var fooMock = new FooMock(mockContext); fooMock.Execute((string)null); mockContext.Assert(f => f.Execute((string)null)); }
public void Execute_MethodCallInInvocation_IsVerified() { var mockContext = new MockContext <IFoo>(); var fooMock = new FooMock(mockContext); string[] strings = { "SomeValue", "AnotherValue" }; fooMock.Execute(strings.First(s => s.StartsWith("Some"))); }
public void Assert_ExpectedExactly3TimesAnd2TimesInvoked_ThrowsException() { var mockContext = new MockContext <IFoo>(); var fooMock = new FooMock(mockContext); fooMock.Execute("SomeValue"); fooMock.Execute("SomeValue"); mockContext.Assert(f => f.Execute("SomeValue"), Invoked.Exactly(3)); }
public void Assert_InvokedTwiceWithExpectedOnce_ThrowsException() { var mockContext = new MockContext <IFoo>(); var fooMock = new FooMock(mockContext); fooMock.Execute("SomeValue"); fooMock.Execute("SomeValue"); mockContext.Assert(f => f.Execute("SomeValue"), Invoked.Once); }
public void Assert_StringEmpty_IsVerified() { var mockContext = new MockContext <IFoo>(); var fooMock = new FooMock(mockContext); fooMock.Execute(string.Empty); mockContext.Assert(f => f.Execute(string.Empty)); }
public void Execute_NoArrangement_ReturnsDefaultValue() { var mockContext = new MockContext <IFoo>(); var fooMock = new FooMock(mockContext); string result = fooMock.Execute(); Assert.AreEqual(default(string), result); }
public void Arrange_ReturnsWithOneArgument_InvokesGetResult() { var mockContext = new MockContext <IFoo>(); var fooMock = new FooMock(mockContext); mockContext.Arrange(f => f.Execute(The <string> .IsAnyValue)).Returns <string>(a => "This" + a); var result = fooMock.Execute(" is"); Assert.AreEqual("This is", result); }
public void Assert_ExpectedAtLeast3TimesAnd3TimesInvoked_IsVerified() { var mockContext = new MockContext <IFoo>(); var fooMock = new FooMock(mockContext); fooMock.Execute("SomeValue"); fooMock.Execute("SomeValue"); fooMock.Execute("SomeValue"); mockContext.Assert(f => f.Execute("SomeValue"), Invoked.AtLeast(3)); }
public void Arrange_CallBackNoArguments_InvokesCallback() { var mockContext = new MockContext <IFoo>(); var fooMock = new FooMock(mockContext); bool isCalled = false; mockContext.Arrange(f => f.Execute()).Callback(() => isCalled = true); fooMock.Execute(); Assert.IsTrue(isCalled); }
public void Arrange_ReturnsWithNoArguments_InvokesGetResult() { var mockContext = new MockContext <IFoo>(); var fooMock = new FooMock(mockContext); mockContext.Arrange(f => f.Execute()).Returns(() => "This"); var result = fooMock.Execute(); Assert.AreEqual("This", result); }
public void Arrange_CallBackOneArgument_InvokesCallback() { var mockContext = new MockContext <IFoo>(); var fooMock = new FooMock(mockContext); int callBackResult = 0; mockContext.Arrange(f => f.Execute(The <int> .IsAnyValue)).Callback <int>(s => callBackResult = s); fooMock.Execute(1); Assert.AreEqual(1, callBackResult); }
public void Arrange_ReturnsWithTwoArguments_InvokesGetResult() { var mockContext = new MockContext <IFoo>(); var fooMock = new FooMock(mockContext); mockContext.Arrange(f => f.Execute(The <string> .IsAnyValue, The <string> .IsAnyValue)) .Returns <string, string>((a, b) => "This" + a + b); var result = fooMock.Execute(" is", " really"); Assert.AreEqual("This is really", result); }
public void Execute_ArrengedReturnValue_ReturnsValue() { var mockContext = new MockContext <IFoo>(); var fooMock = new FooMock(mockContext); mockContext.Arrange(f => f.Execute()).Returns("SomeValue"); var result = fooMock.Execute(); Assert.AreEqual("SomeValue", result); }
public void Execute_ArrangedRuturnValue_ArrayElementContraintSupport() { var mockContext = new MockContext <IFoo>(); var fooMock = new FooMock(mockContext); var inputData = new byte[] { 1, 2, 3, 4, 5 }; mockContext.Arrange( f => f.Execute(The <byte[]> .Is(a => a[4] == 5))) .Returns <byte[]>(a => a); var result = fooMock.Execute(inputData); Assert.AreEqual(inputData, result); }
public void Execute_ArrangedRuturnValue_ArrayLengthContraintSupport() { var mockContext = new MockContext <IFoo>(); var fooMock = new FooMock(mockContext); var inputData = Enumerable.Repeat((byte)1, 10).ToArray(); mockContext.Arrange( f => f.Execute(The <byte[]> .Is(a => a.Length < 20))) .Returns <byte[]>(a => a); var result = fooMock.Execute(inputData); Assert.AreEqual(inputData, result); }
public void Arrange_CallBackTwoArguments_InvokesCallback() { var mockContext = new MockContext <IFoo>(); var fooMock = new FooMock(mockContext); int firstResult = 0; int secondResult = 0; mockContext.Arrange(f => f.Execute(The <int> .IsAnyValue, The <int> .IsAnyValue)).Callback <int, int>( (i, i1) => { firstResult = i; secondResult = i1; }); fooMock.Execute(1, 2); Assert.AreEqual(1, firstResult); Assert.AreEqual(2, secondResult); }
public void Execute_ArrangedReturnValue_ReturnsValueUsingLambda() { var mockContext = new MockContext <IFoo>(); var fooMock = new FooMock(mockContext); var outerVariable = " works"; mockContext.Arrange(f => f.Execute(The <string> .IsAnyValue)).Returns <string>( a => { var r = a + outerVariable + "!"; return(r); }); var result = fooMock.Execute("It"); Assert.AreEqual("It works!", result); }