public void Test_GetValidValue_WhenNotRelOrProp_ShouldRaiseError() { //---------------Set up test pack------------------- var factory = new BOTestFactory(typeof(FakeBO)); //---------------Assert Precondition---------------- //---------------Execute Test ---------------------- try { factory.GetValidValue("InvalidProp"); Assert.Fail("Expected to throw an HabaneroApplicationException"); } //---------------Test Result ----------------------- catch (HabaneroDeveloperException ex) { const string message = "is not defined as either a SingleRelationshipDef or a PropertyDef"; StringAssert.Contains(message, ex.Message); } }
public void Test_GetValidValue_WithBO_WhenIsRelationship_ShouldRetValidValue() { //---------------Set up test pack------------------- const string relName = "NonCompulsoryRelationship"; Type boType = typeof(FakeBO); var relationship = new BOTestFactory(boType).CreateValidBusinessObject().Relationships[relName] as ISingleRelationship; var factory = new BOTestFactory(boType); //---------------Assert Precondition---------------- Assert.IsNotNull(relationship); Assert.IsNull(relationship.GetRelatedObject()); //---------------Execute Test ---------------------- object validValue = factory.GetValidValue(new FakeBO(), relName); //---------------Test Result ----------------------- Assert.IsNotNull(validValue); Assert.IsInstanceOf <IBusinessObject>(validValue); var validRelationshipValue = validValue as IBusinessObject; Assert.IsNotNull(validRelationshipValue); Assert.AreSame(validRelationshipValue.ClassDef, relationship.RelatedObjectClassDef); }
public void Test_GetValidValue_WithBO_WhenIsProp_ShouldRetValidValue() { //---------------Set up test pack------------------- var classDef = ClassDef.Get <FakeBO>(); var factory = new BOTestFactory(typeof(FakeBO)); IPropDef def = classDef.PropDefcol.FirstOrDefault(propDef => propDef.PropertyName == "CompulsoryString"); //---------------Assert Precondition---------------- Assert.IsNotNull(def); def.AddPropRule(CreatePropRuleString(3, 7)); //---------------Execute Test ---------------------- var validPropValue = factory.GetValidValue(new FakeBO(), "CompulsoryString"); //---------------Test Result ----------------------- Assert.IsNotNull(validPropValue); string validPropStringValue = validPropValue.ToString(); Assert.GreaterOrEqual(validPropStringValue.Length, 3); Assert.LessOrEqual(validPropStringValue.Length, 7); string errMessage = ""; Assert.IsTrue(def.IsValueValid(validPropStringValue, ref errMessage)); }