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 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); }
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 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); }