public void Test_ShouldHaveSingleRelationshipMapped_WithLambda_WhenGetterAndSetterMappedToIncorrectprop_ShouldAssertFalse() { //---------------Set up test pack------------------- CreateClassDefs <FakeBOWithNothing, FakeBoWithSingleRel>(); const string propName = "SingleRelGetterAndSetterNotMapped"; var boTester = CreateGenericTester <FakeBoWithSingleRel>(); FakeBoWithSingleRel bo = (FakeBoWithSingleRel)boTester.BusinessObject; var newValue = new FakeBOWithNothing(); bo.SingleRelGetterAndSetterNotMapped = newValue; var singleRelationship = bo.Relationships[propName] as ISingleRelationship; //---------------Assert Precondition---------------- Assert.IsNotNull(singleRelationship); Assert.AreEqual(newValue, bo.SingleRelGetterAndSetterNotMapped); Assert.AreNotEqual(singleRelationship.GetRelatedObject(), newValue); //---------------Test Result ----------------------- try { boTester.ShouldHaveSingleRelationshipMapped(rel => rel.SingleRelGetterAndSetterNotMapped); Assert.Fail("Expected to throw an AssertionException"); } //---------------Test Result ----------------------- catch (AssertionException ex) { string expected = string.Format( "The Setter for the Property '{0}' for class '{1}' is mapped to the incorrect BOProp. Check the Property in your code", propName, "FakeBoWithSingleRel"); StringAssert.Contains(expected, ex.Message); } }
public void Test_ShouldHaveSingleRelationshipMapped_WithLambda_WhenGetterNotMapped_ShouldAssertFalse() { //---------------Set up test pack------------------- CreateClassDefs <FakeBOWithNothing, FakeBoWithSingleRel>(); const string relationshipName = "SingleRelGetterNotMapped"; var newValue = new FakeBOWithNothing(); var boTester = CreateGenericTester <FakeBoWithSingleRel>(); FakeBoWithSingleRel bo = (FakeBoWithSingleRel)boTester.BusinessObject; bo.SingleRelGetterNotMapped = newValue; //---------------Assert Precondition---------------- Assert.AreNotEqual(newValue, bo.SingleRelGetterNotMapped); //---------------Execute Test ----------------------- try { boTester.ShouldHaveSingleRelationshipMapped(rel => rel.SingleRelGetterNotMapped); Assert.Fail("Expected to throw an AssertionException"); } //---------------Test Result ----------------------- catch (AssertionException ex) { string expected = string.Format( "The Getter And Setter for the Property '{0}' for class '{1}' are not both mapped to the same BOProp. Check the Property in your code", relationshipName, "FakeBoWithSingleRel"); StringAssert.Contains(expected, ex.Message); } }