public void Test_ShouldHaveReadWriteRule_WithLambda_WriteNew_WhenIsNot_ShouldAssertFalse() { //---------------Set up test pack------------------- IClassDef classDef = SetupClassDef <FakeBOWithReadWriteRuleProp>(); BOTester <FakeBOWithReadWriteRuleProp> boTester = CreateGenericTester <FakeBOWithReadWriteRuleProp>(); const string propName = "ReadWriteRuleReadOnly"; var propertyInfo = ReflectionUtilities.GetPropertyInfo <FakeBOWithReadWriteRuleProp, object>(bo => bo.ReadWriteRuleReadOnly); var propertyWrapper = propertyInfo.ToPropertyWrapper(); const PropReadWriteRule expectedReadWriteRule = PropReadWriteRule.WriteNew; //---------------Assert Precondition---------------- Assert.IsTrue(propertyWrapper.HasAttribute <AutoMapReadWriteRuleAttribute>()); IPropDef propDef = classDef.GetPropDef(propName); Assert.IsNotNull(propDef); Assert.AreNotEqual(expectedReadWriteRule, propDef.ReadWriteRule); //---------------Test Result ----------------------- try { boTester.ShouldHaveReadWriteRule(bo => bo.ReadWriteRuleReadOnly, expectedReadWriteRule); Assert.Fail("Expected to throw an AssertionException"); } //---------------Test Result ----------------------- catch (AssertionException ex) { string expected = string.Format( "The Property '{0}' for class '{1}' should have a ReadWriteRule '{2}' but is '{3}'", propDef.PropertyName, propDef.ClassName, expectedReadWriteRule, propDef.ReadWriteRule); StringAssert.Contains(expected, ex.Message); } }
public void Test_ShouldHaveReadWriteRule_WithLambda_ReadOnly_WhenIs_ShouldAssertTrue() { //---------------Set up test pack------------------- IClassDef classDef = SetupClassDef <FakeBOWithReadWriteRuleProp>(); BOTester <FakeBOWithReadWriteRuleProp> boTester = CreateGenericTester <FakeBOWithReadWriteRuleProp>(); const string propName = "ReadWriteRuleReadOnly"; var propertyInfo = ReflectionUtilities.GetPropertyInfo <FakeBOWithReadWriteRuleProp, object>(bo => bo.ReadWriteRuleReadOnly); var propertyWrapper = propertyInfo.ToPropertyWrapper(); //---------------Assert Precondition---------------- Assert.IsTrue(propertyWrapper.HasAttribute <AutoMapReadWriteRuleAttribute>()); Assert.IsNotNull(classDef.GetPropDef(propName)); //---------------Execute Test ---------------------- boTester.ShouldHaveReadWriteRule(bo => bo.ReadWriteRuleReadOnly, PropReadWriteRule.ReadOnly); //---------------Test Result ----------------------- Assert.IsTrue(true, "If it has got here then passed"); }