示例#1
0
 public void TestGenericSetupDefaultNegative()
 {
     Assert.Throws <Exception>(() => Mock.SetupDefault(() => TestStaticClass.TestMethodReturn1WithoutParameters(), () =>
     {
         TestStaticClass.TestMethodReturn1WithoutParameters();
     }));
 }
示例#2
0
 public void TestThrowsTestMethodReturn1WithoutParameters()
 {
     Mock.Setup(() => TestStaticClass.TestMethodReturn1WithoutParameters(), () =>
     {
         Assert.Throws <Exception>(() => TestStaticClass.TestMethodReturn1WithoutParameters());
     }).Throws <Exception>();
 }
示例#3
0
    public void TestGenericSetupDefaultNegativeIncorrectExpression()
    {
        var body = Expression.Block(
            Expression.Add(Expression.Constant(1), Expression.Constant(2)),
            Expression.Constant(3));
        var lambda = Expression.Lambda <Action>(body);

        Assert.Throws <Exception>(() => Mock.SetupDefault(lambda, () =>
        {
            TestStaticClass.TestMethodReturn1WithoutParameters();
        }));
    }
示例#4
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));
    }
示例#5
0
    public void TestNestedThrowsReturnTest()
    {
        const int expectedChildResult = 2;

        Mock.Setup(() => TestStaticClass.TestMethodReturn1WithoutParameters(), () =>
        {
            Assert.Throws <Exception>(() => TestStaticClass.TestMethodReturn1WithoutParameters());
            Mock.Setup(() => TestStaticClass.TestMethodReturn1WithoutParameters(), () =>
            {
                var actualChildResult = TestStaticClass.TestMethodReturn1WithoutParameters();
                Assert.AreEqual(expectedChildResult, actualChildResult);
            }).Returns(expectedChildResult);
        }).Throws <Exception>();
    }
示例#6
0
    public void TestGenericSetupReturnsWithTestMethodReturn1WithoutParameters()
    {
        var originalResult = TestStaticClass.TestMethodReturn1WithoutParameters();
        var expectedResult = 2;

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

            Assert.AreNotEqual(originalResult, actualResult);
            Assert.AreEqual(expectedResult, actualResult);
        })
        .Returns(expectedResult);
    }
示例#7
0
    public void TestNestedReturnMock()
    {
        const int expectedParentResult = 2;
        const int expectedChildResult  = 3;

        Mock.Setup(() => TestStaticClass.TestMethodReturn1WithoutParameters(), () =>
        {
            var actualParentResult = TestStaticClass.TestMethodReturn1WithoutParameters();
            Assert.AreEqual(expectedParentResult, actualParentResult);
            Mock.Setup(() => TestStaticClass.TestMethodReturn1WithoutParameters(), () =>
            {
                var actualChildResult = TestStaticClass.TestMethodReturn1WithoutParameters();
                Assert.AreEqual(expectedChildResult, actualChildResult);
            }).Returns(expectedChildResult);
        }).Returns(expectedParentResult);
    }
示例#8
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);
    }
示例#9
0
    public void TestNestedInChildCallbackMockWithDifferentFunctions()
    {
        const int expectedParentResult = 2;
        const int expectedChildResult  = 3;

        Mock.Setup(() => TestStaticClass.TestMethodReturn1WithoutParameters(), () =>
        {
            Mock.Setup(() => TestStaticClass.TestMethodReturnWithParameter(2), () =>
            {
                var actualChildResult = TestStaticClass.TestMethodReturnWithParameter(2);
                Assert.AreEqual(expectedChildResult, actualChildResult);
                var actualParentResult = TestStaticClass.TestMethodReturn1WithoutParameters();
                Assert.AreEqual(expectedParentResult, actualParentResult);
            }).Callback(() => expectedChildResult);
        }).Callback(() => expectedParentResult);
    }
    public void TestFuncCallback()
    {
        var originalResult = TestStaticClass.TestMethodReturn1WithoutParameters();
        var expectedResult = 2;

        Assert.AreNotEqual(expectedResult, originalResult);

        Mock.Setup(typeof(TestStaticClass), nameof(TestStaticClass.TestMethodReturn1WithoutParameters), () =>
        {
            var actualResult = TestStaticClass.TestMethodReturn1WithoutParameters();
            Assert.AreEqual(expectedResult, actualResult);
        }).Callback(() =>
        {
            var x = expectedResult;
            return(x);
        });
    }
示例#11
0
 public void TestGenericSetup()
 {
     Mock.Setup(() => TestStaticClass.TestMethodReturn1WithoutParameters(), () => { });
 }