public void Test_GetValidPropValue_WhenStringAndMaxLengthWhenPropName_ShouldRetValidValue()
        {
            //---------------Set up test pack-------------------
            var classDef = ClassDef.Get <FakeBO>();
            var def      = classDef.PropDefcol.FirstOrDefault(propDef => propDef.PropertyName == "CompulsoryString");

            //---------------Assert Precondition----------------
            Assert.IsNotNull(def);
            def.AddPropRule(CreatePropRuleString(3, 7));
            var factory = new BOTestFactory(typeof(FakeBO));

            Assert.AreSame(typeof(string), def.PropertyType);
            Assert.IsNotEmpty(def.PropRules.OfType <PropRuleString>().ToList());
            var propRule = def.PropRules.OfType <PropRuleString>().First();

            Assert.AreEqual(3, propRule.MinLength);
            Assert.AreEqual(7, propRule.MaxLength);
            //---------------Execute Test ----------------------
            var validPropValue = factory.GetValidPropValue(typeof(FakeBO), "CompulsoryString").ToString();

            //---------------Test Result -----------------------
            Assert.IsNotNull(validPropValue);
            Assert.GreaterOrEqual(validPropValue.Length, 3);
            Assert.LessOrEqual(validPropValue.Length, 7);
            string errMessage = "";

            Assert.IsTrue(def.IsValueValid(validPropValue, ref errMessage));
        }
        public void Test_GetValidPropValue_WhenStringAndMaxLength_ShouldRetValidValue()
        {
            //---------------Set up test pack-------------------
            IPropDef def = new PropDefFake {
                PropertyType = typeof(string)
            };

            def.AddPropRule(CreatePropRuleString(3, 7));
            IBOProp prop    = new BOProp(def);
            var     factory = new BOTestFactory(typeof(FakeBO));

            //---------------Assert Precondition----------------
            Assert.AreSame(typeof(string), prop.PropertyType);
            Assert.IsNotEmpty(def.PropRules.OfType <PropRuleString>().ToList());
            var propRule = def.PropRules.OfType <PropRuleString>().First();

            Assert.AreEqual(3, propRule.MinLength);
            Assert.AreEqual(7, propRule.MaxLength);
            //---------------Execute Test ----------------------
            var validPropValue = factory.GetValidPropValue(prop);

            //---------------Test Result -----------------------
            Assert.IsNotNull(validPropValue);
            Assert.GreaterOrEqual(validPropValue.ToString().Length, 3);
            Assert.LessOrEqual(validPropValue.ToString().Length, 7);
        }
        public void Test_GetValidPropValue_WhenDateTimeAndMaxValue_WhenPropName_ShouldRetValidValue()
        {
            //---------------Set up test pack-------------------
            IPropDef def = new PropDefFake {
                PropertyType = typeof(DateTime)
            };
            DateTime min = RandomValueGen.GetAbsoluteMin <DateTime>().AddDays(5555.0);
            DateTime max = RandomValueGen.GetAbsoluteMin <DateTime>().AddDays(5565.0);

            def.AddPropRule(TestUtilsFactory.CreatePropRuleDateTime(min, max));
            var factory = new BOTestFactory(typeof(FakeBO));

            //---------------Assert Precondition----------------
            Assert.AreSame(typeof(DateTime), def.PropertyType);
            Assert.IsNotEmpty(def.PropRules.OfType <PropRuleDate>().ToList());
            var propRule = def.PropRules.OfType <PropRuleDate>().First();

            Assert.AreEqual(min, propRule.MinValue);
            Assert.AreEqual(max, propRule.MaxValue.Date);
            //---------------Execute Test ----------------------
            var validPropValue = factory.GetValidPropValue(def);

            //---------------Test Result -----------------------
            Assert.GreaterOrEqual((DateTime)validPropValue, min);
            Assert.LessOrEqual((DateTime)validPropValue, max);
            string errMessage = "";

            Assert.IsTrue(def.IsValueValid(validPropValue, ref errMessage), errMessage);
        }
        public void Test_SetDefaultValue_WhenProperty_ShouldReturnSetValue()
        {
            //---------------Set up test pack-------------------
            const string expectedPropValue = "SomeValue";
            const string propName          = "SomeProp";
            var          boWithRelFactory  = new BOTestFactory(typeof(FakeBO));

            //---------------Assert Precondition----------------
            //---------------Execute Test ----------------------
            boWithRelFactory.SetValueFor(propName, expectedPropValue);
            var actualValue = boWithRelFactory.GetValidPropValue(typeof(FakeBOWithRelationship), propName);

            //---------------Test Result -----------------------
            Assert.AreSame(expectedPropValue, actualValue);
        }
        public void Test_GetValidPropValue_WhenClassNotInClassDefs_ShouldRaiseError()
        {
            //---------------Assert Precondition----------------
            Type type    = typeof(Unmapped);
            var  factory = new BOTestFactory(typeof(FakeBO));

            Assert.IsFalse(ClassDef.ClassDefs.Contains(type));
            //---------------Execute Test ----------------------
            try
            {
                factory.GetValidPropValue(type, "SomeProp");
                Assert.Fail("Expected to throw an HabaneroDeveloperException");
            }
            catch (HabaneroDeveloperException ex)
            {
                StringAssert.Contains(string.Format("The ClassDef for '{0}' does not have any classDefs Loaded", type), ex.Message);
                StringAssert.Contains("The BOTestFactory class is designed to be used in Testing so it is likely that your classdefs are not being loaded as part of your testing process", ex.DeveloperMessage);
            }
        }
        public void Test_GetValidPropValue_WhenNoPropDefForClassDef_ShouldRaiseError()
        {
            //---------------Set up test pack-------------------
            Type type    = typeof(FakeBO);
            var  factory = new BOTestFactory(typeof(FakeBO));

            //---------------Assert Precondition----------------
            Assert.IsTrue(ClassDef.ClassDefs.Contains(type));
            //---------------Execute Test ----------------------
            try
            {
                factory.GetValidPropValue(type, "InvalidProp");
                Assert.Fail("Expected to throw an HabaneroDeveloperException");
            }
            catch (HabaneroDeveloperException ex)
            {
                StringAssert.Contains(string.Format("The property '{0}' for the ClassDef for '{1}' is not defined", "InvalidProp", type), ex.Message);
                StringAssert.Contains("The BOTestFactory class is designed to be used in Testing so it is likely that your classdefs are not being loaded as part of your testing process.", ex.DeveloperMessage);
            }
        }