public void TestIfAnd_NowConnectsToTwoValidPredicaments() { // Arrange bool actionCalled = false; object target = new object(); object received_parameter = null; var verifiable = new MockVerifiable<object>( new Verifiable<object>( new Assertion<object>(target), p => { actionCalled = true; received_parameter = p; })); StubVerifiable<string> right = null; // Act right = new StubVerifiable<string>(verifiable.And("data") .IsEqualTo("data")); right.Now(); // Assert Assert.IsTrue(verifiable.NowCalled, "No se mandó llamar Now()"); Assert.IsTrue(actionCalled, "No se ejctuó la acción sobre el Target"); Assert.AreEqual(target, received_parameter); Assert.IsFalse(verifiable.TargetGetCalled, "No se debe pedir el Target del Verifiable en la conexión"); Assert.IsTrue(right.NowCalled); }
public void TestIfAnd_NowConnectsAnInvalidLeftPredicament() { // Arrange object target = new object(); var left = new MockVerifiable<object>( new Verifiable<object>( new Assertion<object>(target), p => { throw new Exception(); })); StubVerifiable<string> right = null; bool rightPredicamentCalled = false; // Act Exception ex = null; try { right = new StubVerifiable<string>( left.And("data") .ItsTrueThat(_ => rightPredicamentCalled = true)); right.Now(); } catch (Exception e) { ex = e; } // Assert Assert.IsTrue(left.NowCalled, "No se mandó llamar Now()"); Assert.IsFalse(rightPredicamentCalled, "No se debió mandar llamar el segundo Target_get(), pues ya debió fallar el primero"); Assert.IsNotNull(ex); }
public void TestIfAnd_NowConnectsAnInvalidRightPredicament() { // Arrange bool actionCalled = false; object target = new object(); object received_parameter = null; var verifiable = new MockVerifiable<object>( new Verifiable<object>( new Assertion<object>(target), p => { actionCalled = true; received_parameter = p; })); StubVerifiable<string> right = null; // Act Exception x = null; try { right = new StubVerifiable<string>( verifiable.And("data") .IsEqualTo("bad")); right.Now(); } catch (Exception ex) { x = ex; } // Assert Assert.IsNotNull(x); Assert.IsTrue(verifiable.NowCalled, "Se mandó llamar Now()"); Assert.IsTrue(actionCalled, "Se ejecutó la acción sobre el Target"); Assert.IsTrue(right.NowCalled); }
public void TestIfAnd_NowChainsTheNowCallsAndRedirectsTheTarget() { // Arrange var mock = new Mock<IVerifiable<string>>(); var mocked = mock.Object; StubVerifiable<object> right = null; // Act right = new StubVerifiable<object>(mocked .And(new object()) .IsNotNull()); right.Now(); // Assert mock.Verify(m => m.Now(), Times.Once()); mock.VerifyGet(m => m.Target, Times.Never()); Assert.IsTrue(right.NowCalled); }