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.Equal(1, firstResult);
            Assert.Equal(2, secondResult);
            Assert.Equal(3, thirdResult);
            Assert.Equal(4, fourthResult);
        }
        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 Arrange_ExceptionFactory_ThrowsException()
        {
            var mockContext = new MockContext <IFoo>();
            var fooMock     = new FooMock(mockContext);

            mockContext.Arrange(f => f.Execute("SomeValue")).Throws(() => new InvalidOperationException());
            Assert.Throws <InvalidOperationException>(() => fooMock.Execute("SomeValue"));
        }
        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_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_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_NeverWhenInvoked_ThrowsException()
        {
            var mockContext = new MockContext <IFoo>();
            var fooMock     = new FooMock(mockContext);

            fooMock.Execute("SomeValue");
            Assert.Throws <MockException>(() => 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");
            Assert.Throws <MockException>(()
                                          => mockContext.Assert(f => f.Execute(The <string> .Is(s => s == "AnotherValue")), Invoked.Once));
        }
        public void Assert_ExpectedExactly3TimesAnd2TimesInvoked_ThrowsException()
        {
            var mockContext = new MockContext <IFoo>();
            var fooMock     = new FooMock(mockContext);

            fooMock.Execute("SomeValue");
            fooMock.Execute("SomeValue");
            Assert.Throws <MockException>(() => mockContext.Assert(f => f.Execute("SomeValue"), Invoked.Exactly(3)));
        }
        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 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 Assert_InvokedTwiceWithExpectedOnce_ThrowsException()
        {
            var mockContext = new MockContext <IFoo>();
            var fooMock     = new FooMock(mockContext);

            fooMock.Execute("SomeValue");
            fooMock.Execute("SomeValue");
            Assert.Throws <MockException>(() => mockContext.Assert(f => f.Execute("SomeValue"), Invoked.Once));
        }
        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 Execute_NoArrangement_ReturnsDefaultValue()
        {
            var mockContext = new MockContext <IFoo>();
            var fooMock     = new FooMock(mockContext);

            string?result = fooMock.Execute();

            Assert.Equal(default(string), result);
        }
        public async Task Arrange_ReturnsAsyncWithOneArgument_InvokesGetResult()
        {
            var mockContext = new MockContext <IFoo>();
            var fooMock     = new FooMock(mockContext);

            mockContext.Arrange(f => f.ExecuteAsync(The <string> .IsAnyValue)).ReturnsAsync((string a) => "This" + a);
            var result = await fooMock.ExecuteAsync(" is");

            Assert.Equal("This is", 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.Equal("This is", result);
        }
        public void Assert_ExpectedExactly3TimesAnd3TimesInvoked_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.Exactly(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.True(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.Equal("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.Equal(1, callBackResult);
        }
        public async Task Arrange_ReturnsAsyncWithNoArguments_InvokesGetResult()
        {
            var mockContext = new MockContext <IFoo>();
            var fooMock     = new FooMock(mockContext);

            mockContext.Arrange(f => f.ExecuteAsync()).ReturnsAsync(() => "This");
            var result = await fooMock.ExecuteAsync();

            Assert.Equal("This", result);
        }
        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.Equal("This is really", result);
        }
        public void Arrange_ChangeReturnValue()
        {
            var mockContext = new MockContext <IFoo>();
            var fooMock     = new FooMock(mockContext);

            mockContext.Arrange(f => f.Execute()).Returns("1");
            Assert.Equal("1", fooMock.Execute());

            mockContext.Arrange(f => f.Execute()).Returns("2");
            Assert.Equal("2", fooMock.Execute());
        }
        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.Equal("SomeValue", result);
        }
        public void Arrange_ChangeException()
        {
            var mockContext = new MockContext <IFoo>();
            var fooMock     = new FooMock(mockContext);

            mockContext.Arrange(f => f.Execute(The <int> .IsAnyValue)).Throws <System.ArgumentNullException>();
            Assert.Throws <System.ArgumentNullException>(() => fooMock.Execute(1));

            mockContext.Arrange(f => f.Execute(The <int> .IsAnyValue)).Throws <System.ArgumentOutOfRangeException>();
            Assert.Throws <System.ArgumentOutOfRangeException>(() => fooMock.Execute(1));
        }
        public async Task Arrange_ReturnsAsyncWithThreeArguments_InvokesGetResult()
        {
            var mockContext = new MockContext <IFoo>();
            var fooMock     = new FooMock(mockContext);

            mockContext.Arrange(f => f.ExecuteAsync(The <string> .IsAnyValue, The <string> .IsAnyValue, The <string> .IsAnyValue))
            .ReturnsAsync((string a, string b, string c) => "This" + a + b + c);

            var result = await fooMock.ExecuteAsync(" is", " really", " cool");

            Assert.Equal("This is really cool", 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.Equal(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.Equal(inputData, result);
        }
        public void Arrange_SimulatousReturnAndCallback()
        {
            string firstResult = "";
            var    mockContext = new MockContext <IFoo>();
            var    fooMock     = new FooMock(mockContext);

            mockContext.Arrange(f => f.Execute(The <string> .IsAnyValue)).Returns("hi");
            mockContext.Arrange(f => f.Execute(The <string> .IsAnyValue)).Callback <string>(i => firstResult = i);

            var result = fooMock.Execute("hello");

            Assert.Equal("hi", result);
            Assert.Equal("hello", firstResult);
        }
        public void Arrange_ChangeCallback()
        {
            int firstResult  = 0;
            int secondResult = 0;
            var mockContext  = new MockContext <IFoo>();
            var fooMock      = new FooMock(mockContext);

            mockContext.Arrange(f => f.Execute(The <int> .IsAnyValue)).Callback <int>(i => firstResult = i);
            fooMock.Execute(1);
            mockContext.Arrange(f => f.Execute(The <int> .IsAnyValue)).Callback <int>(i => secondResult = i);
            fooMock.Execute(2);

            Assert.Equal(1, firstResult);
            Assert.Equal(2, secondResult);
        }