예제 #1
0
    public void TestNestedThrowsMockWithDifferentFunctionsParentAfterChild()
    {
        Mock.Setup(() => TestStaticClass.TestMethodReturn1WithoutParameters(), () =>
        {
            Mock.Setup(() => TestStaticClass.TestMethodReturnWithParameter(2), () =>
            {
                Assert.Throws <ArgumentNullException>(() => TestStaticClass.TestMethodReturnWithParameter(2));
            }).Throws(typeof(ArgumentNullException));

            Assert.Throws <Exception>(() => TestStaticClass.TestMethodReturn1WithoutParameters());
        }).Throws(typeof(Exception));
    }
예제 #2
0
    public void TestGenericSetupReturnsWithTestMethodReturnParameter()
    {
        var originalResult = TestStaticClass.TestMethodReturnWithParameter(10);
        var expectedResult = 2;

        Mock.Setup(
            () => TestStaticClass.TestMethodReturnWithParameter(10),
            () =>
        {
            var actualResult = TestStaticClass.TestMethodReturnWithParameter(10);

            Assert.AreNotEqual(originalResult, actualResult);
            Assert.AreEqual(expectedResult, actualResult);
        })
        .Returns(expectedResult);
    }
예제 #3
0
    public void TestNestedInChildReturnThrowsMockWithDifferentFunctions()
    {
        const int expectedParentResult = 2;

        Mock.Setup(() => TestStaticClass.TestMethodReturn1WithoutParameters(), () =>
        {
            Mock.Setup(() => TestStaticClass.TestMethodReturnWithParameter(2), () =>
            {
                var actualParentResult = TestStaticClass.TestMethodReturn1WithoutParameters();
                Assert.AreEqual(expectedParentResult, actualParentResult);
                Assert.Throws <Exception>(() => TestStaticClass.TestMethodReturnWithParameter(2));
                actualParentResult = TestStaticClass.TestMethodReturn1WithoutParameters();
                Assert.AreEqual(expectedParentResult, actualParentResult);
            }).Throws <Exception>();
        }).Returns(expectedParentResult);
    }
예제 #4
0
    public void TestNestedReturnMockWithDifferentFunctions()
    {
        const int expectedParentResult = 2;
        const int expectedChildResult  = 3;

        Mock.Setup(() => TestStaticClass.TestMethodReturn1WithoutParameters(), () =>
        {
            var actualParentResult = TestStaticClass.TestMethodReturn1WithoutParameters();
            Mock.Setup(() => TestStaticClass.TestMethodReturnWithParameter(2), () =>
            {
                var actualChildResult = TestStaticClass.TestMethodReturnWithParameter(2);
                Assert.AreEqual(expectedParentResult, actualParentResult);
                Assert.AreEqual(expectedChildResult, actualChildResult);
            }).Returns(expectedChildResult);
        }).Returns(expectedParentResult);
    }