public void TestGenericSetupDefaultNegative() { Assert.Throws <Exception>(() => Mock.SetupDefault(() => TestStaticClass.TestMethodReturn1WithoutParameters(), () => { TestStaticClass.TestMethodReturn1WithoutParameters(); })); }
public void TestThrowsTestMethodReturn1WithoutParameters() { Mock.Setup(() => TestStaticClass.TestMethodReturn1WithoutParameters(), () => { Assert.Throws <Exception>(() => TestStaticClass.TestMethodReturn1WithoutParameters()); }).Throws <Exception>(); }
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(); })); }
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)); }
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>(); }
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); }
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); }
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); }
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); }); }
public void TestGenericSetup() { Mock.Setup(() => TestStaticClass.TestMethodReturn1WithoutParameters(), () => { }); }