GetValidValue() 공개 메소드

Returns a valid prop value for Property or single relationship with the name name for the IBusinessObject.
public GetValidValue ( IBusinessObject bo, string name ) : object
bo IBusinessObject
name string
리턴 object
 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_WhenNotRelOrProp_ShouldRaiseError()
        {
            //---------------Set up test pack-------------------
            var factory = new BOTestFactory(typeof(FakeBO));
            //---------------Assert Precondition----------------

            //---------------Execute Test ----------------------
            try
            {
                factory.GetValidValue(new FakeBO(), "InvalidProp");
                Assert.Fail("Expected to throw an HabaneroApplicationException");
            }
                //---------------Test Result -----------------------
            catch (HabaneroDeveloperException ex)
            {
                string message = "The property 'InvalidProp' for the ClassDef";
                StringAssert.Contains(message, ex.Message);
                message = "is not defined";
                StringAssert.Contains(message, ex.Message);
            }
        }
 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));
 }