public void Test_SetRelationship_WhenHasValue_AndValueRegistered_ShouldSetToRegisteredValue()
        {
            //---------------Set up test pack-------------------
            var bo           = new BOTestFactory(typeof(FakeBO)).CreateValidBusinessObject();
            var relationship = bo.Relationships["NonCompulsoryRelationship"] as ISingleRelationship;

            var factory = new BOTestFactory <FakeBO>();

            factory.SetRelationshipToValidValue(relationship);
            var expectedRelationshipValue = new RelatedFakeBo();

            //---------------Assert Precondition----------------
            Assert.IsNotNull(relationship);
            var origionalBO = relationship.GetRelatedObject();

            Assert.IsNotNull(relationship.GetRelatedObject());
            //---------------Execute Test ----------------------
            factory.SetValueFor(fakeBO => fakeBO.NonCompulsoryRelationship, expectedRelationshipValue);
            factory.SetRelationshipToValidValue(relationship);
            var actualRelatedObject = relationship.GetRelatedObject();

            //---------------Test Result -----------------------
            Assert.IsNotNull(actualRelatedObject);
            Assert.AreSame(expectedRelationshipValue, actualRelatedObject);
        }
        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_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_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));
        }
Exemplo n.º 5
0
 private BOTestFactory GetTestFactory()
 {
     if (_boTestFactory == null)
     {
         _boTestFactory = BOTestFactoryRegistry.Instance.Resolve(ClassType);
     }
     return(_boTestFactory);
 }
Exemplo n.º 6
0
 public BOTester(IBusinessObject businessObject)
 {
     if (businessObject == null)
     {
         throw new ArgumentNullException("businessObject");
     }
     _boTestFactory = new BOTestFactory(businessObject.GetType());
     BusinessObject = businessObject;
 }
        public void Test_Resolve_WithType_WhenNoFactoryRegistered_AndHasSpecialisedFactory_ShouldRetSpecialisedFactory()
        {
            //---------------Set up test pack-------------------
            var boTestFactoryRegistry = new BOTestFactoryRegistry();
            //---------------Execute Test ----------------------
            BOTestFactory boTestFactory = boTestFactoryRegistry.Resolve(typeof(FakeBO));

            Assert.IsInstanceOf <BOTestFactoryFakeBO>(boTestFactory);
            Assert.IsInstanceOf <BOTestFactory <FakeBO> >(boTestFactory);
        }
        public void Test_Register_WhenCustomBOTestFactory_WithFactoryType_ShouldReturnWhenResolved()
        {
            //---------------Set up test pack-------------------
            BOTestFactoryRegistry registry = new BOTestFactoryRegistry();

            registry.Register <FakeBO>(typeof(BOTestFactoryFakeBO));
            //---------------Assert Precondition----------------
            //---------------Execute Test ----------------------
            BOTestFactory boTestFactory = registry.Resolve <FakeBO>();

            //---------------Test Result -----------------------
            Assert.IsInstanceOf <BOTestFactoryFakeBO>(boTestFactory);
        }
        public void Test_RegisterInstance_ShouldRegister()
        {
            //---------------Set up test pack-------------------
            BOTestFactoryRegistry registry            = new BOTestFactoryRegistry();
            BOTestFactoryFakeBO   boTestFactoryFakeBO = new BOTestFactoryFakeBO();

            //---------------Assert Precondition----------------
            registry.Register <FakeBO>(boTestFactoryFakeBO);
            //---------------Execute Test ----------------------
            BOTestFactory boTestFactory = registry.Resolve <FakeBO>();

            Assert.AreSame(boTestFactoryFakeBO, boTestFactory);
        }
        public void Test_CreateValidBusinessObject_ShouldReturnBOWithCompulsoryPropsPopulated()
        {
            //---------------Set up test pack-------------------
            //---------------Assert Precondition----------------
            var factory = new BOTestFactory(typeof(FakeBO));
            //---------------Execute Test ----------------------
            var businessObject = factory.CreateValidBusinessObject() as FakeBO;

            //---------------Test Result -----------------------
            Assert.IsNotNull(businessObject);
            Assert.IsInstanceOf <FakeBO>(businessObject);
            Assert.IsNotNull(businessObject.CompulsoryString);
        }
        public void Test_SetDefaultValue_WhenRelationship_ShouldCreateWithValueSet()
        {
            //---------------Set up test pack-------------------
            var relatedBO        = new RelatedFakeBo();
            var boWithRelFactory = new BOTestFactory(typeof(FakeBOWithRelationship));

            //---------------Assert Precondition----------------
            //---------------Execute Test ----------------------
            boWithRelFactory.SetValueFor("SingleRelationship", relatedBO);
            var boWithRelationship = boWithRelFactory.CreateValidBusinessObject() as FakeBOWithRelationship;

            //---------------Test Result -----------------------
            Assert.IsNotNull(boWithRelationship);
            Assert.AreSame(relatedBO, boWithRelationship.SingleRelationship);
        }
Exemplo n.º 12
0
        public void Test_GetValidValueGenerator_WhenEnum_ShouldRetEnumGenerator()
        {
            //---------------Set up test pack-------------------
            IPropDef def = new PropDefFake
            {
                PropertyType = typeof(FakeEnum)
            };
            //---------------Assert Precondition----------------
            //---------------Execute Test ----------------------
            var generator = new BOTestFactory <FakeBOWithRules>().GetValidValueGenerator(def);

            //---------------Test Result -----------------------
            Assert.IsNotNull(generator);
            Assert.IsInstanceOf <ValidValueGeneratorEnum>(generator);
        }
        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_RegisterTwice_WhenInstanceThenType_ShouldStoreSecond()
        {
            //---------------Set up test pack-------------------
            BOTestFactoryRegistry registry    = new BOTestFactoryRegistry();
            BOTestFactoryFakeBO   origFactory = new BOTestFactoryFakeBO();

            registry.Register <FakeBO>(origFactory);
            //---------------Assert Precondition----------------
            Assert.IsNotNull(registry.Resolve <FakeBO>());
            //---------------Execute Test ----------------------
            registry.Register <FakeBO, BOTestFactory <FakeBO> >();
            BOTestFactory boTestFactory = registry.Resolve <FakeBO>();

            Assert.AreNotSame(origFactory, boTestFactory);
        }
        public void Test_SetRelationship_WhenNull_ShouldSetValue()
        {
            //---------------Set up test pack-------------------
            var bo           = new BOTestFactory(typeof(FakeBO)).CreateValidBusinessObject();
            var relationship = bo.Relationships["NonCompulsoryRelationship"] as ISingleRelationship;

            var factory = new BOTestFactory <FakeBO>();

            //---------------Assert Precondition----------------
            Assert.IsNotNull(relationship);
            Assert.IsNull(relationship.GetRelatedObject());
            //---------------Execute Test ----------------------
            factory.SetRelationshipToValidValue(relationship);
            //---------------Test Result -----------------------
            Assert.IsNotNull(relationship.GetRelatedObject());
        }
        public void Test_GetValidRelationshipValue_ShouldRetValidValue()
        {
            //---------------Set up test pack-------------------
            var relationship = new BOTestFactory(typeof(FakeBO)).CreateValidBusinessObject().Relationships["NonCompulsoryRelationship"] as ISingleRelationship;
            var factory      = new BOTestFactory(typeof(FakeBO));

            //---------------Assert Precondition----------------
            Assert.IsNotNull(relationship);
            Assert.IsNull(relationship.GetRelatedObject());
            //---------------Execute Test ----------------------
            var validRelationshipValue = factory.GetValidRelationshipValue(relationship.RelationshipDef as ISingleValueDef);

            //---------------Test Result -----------------------
            Assert.IsNotNull(validRelationshipValue);
            Assert.AreSame(validRelationshipValue.ClassDef, relationship.RelatedObjectClassDef);
        }
        public void Test_GetValidRelationshipValue_ShouldCreateRelatedBO()
        {
            //---------------Set up test pack-------------------
            var boTestFactory  = new BOTestFactory(typeof(FakeBO));
            var businessObject = (FakeBO)boTestFactory.CreateValidBusinessObject();
            var relationship   = businessObject.Relationships["NonCompulsoryRelationship"] as ISingleRelationship;

            //---------------Assert Precondition----------------
            Assert.IsNotNull(relationship);
            Assert.IsNull(relationship.GetRelatedObject());
            //---------------Execute Test ----------------------
            IRelationshipDef relationshipDef        = relationship.RelationshipDef;
            IBusinessObject  validRelationshipValue = boTestFactory.GetValidRelationshipValue(relationshipDef as ISingleValueDef);

            //---------------Test Result -----------------------
            Assert.IsNotNull(validRelationshipValue);
            Assert.IsTrue(validRelationshipValue.Status.IsNew);
        }
Exemplo n.º 18
0
        public void Test_GetValidValueGenerator_WhenHasLookup_ShouldRetLookupGenerator()
        {
            //---------------Set up test pack-------------------
            IPropDef def = new PropDefFake
            {
                PropertyType = typeof(string),
                LookupList   = MockRepository.GenerateStub <IBusinessObjectLookupList>()
            };

            //---------------Assert Precondition----------------
            Assert.IsTrue(def.HasLookupList());
            //---------------Execute Test ----------------------
            var generator = new BOTestFactory <FakeBOWithRules>().GetValidValueGenerator(def);

            //---------------Test Result -----------------------
            Assert.IsNotNull(generator);
            Assert.IsInstanceOf <ValidValueGeneratorLookupList>(generator);
        }
        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);
            }
        }
Exemplo n.º 20
0
        public void Test_GetdataPage_WhenRecordsInDataSource_ShouldReturnRecords()
        {
            //---------------Set up test pack-------------------
            BindingListRequest <FakeBO> request      = new BindingListRequest <FakeBO>();
            PageProvider <FakeBO>       pageProvider = new PageProvider <FakeBO>(request);
            BOTestFactory <FakeBO>      assetFactory = BOTestFactoryRegistry.Instance.Resolve <FakeBO>();

            assetFactory.CreateManySavedBusinessObject(40);
            //---------------Assert Precondition----------------
            Assert.IsNullOrEmpty(pageProvider.Filter);
            Assert.AreEqual(0, request.PageNumber);
            Assert.AreEqual(20, request.RowsPerPage);
            //---------------Execute Test ----------------------
            IList <FakeBO> dataPage = pageProvider.GetDataPage(0);

            //---------------Test Result -----------------------
            Assert.AreEqual(request.RowsPerPage, dataPage.Count);
            //dataPage.
        }
        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_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);
            }
        }
        public void Test_SetRelationship_WhenHasValue_ShouldNotChange()
        {
            //---------------Set up test pack-------------------
            var bo           = new BOTestFactory(typeof(FakeBO)).CreateValidBusinessObject();
            var relationship = bo.Relationships["NonCompulsoryRelationship"] as ISingleRelationship;

            var factory = new BOTestFactory <FakeBO>();

            factory.SetRelationshipToValidValue(relationship);
            //---------------Assert Precondition----------------
            Assert.IsNotNull(relationship);
            var origionalBO = relationship.GetRelatedObject();

            Assert.IsNotNull(relationship.GetRelatedObject());
            //---------------Execute Test ----------------------
            factory.SetRelationshipToValidValue(relationship);
            var actualRelatedObject = relationship.GetRelatedObject();

            //---------------Test Result -----------------------
            Assert.IsNotNull(actualRelatedObject);
            Assert.AreSame(origionalBO, actualRelatedObject);
        }
        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));
        }
 private BOTestFactory GetTestFactory()
 {
     if (_boTestFactory == null)
     {
         _boTestFactory = BOTestFactoryRegistry.Instance.Resolve(ClassType);
     }
     return _boTestFactory;
 }
Exemplo n.º 27
0
 public BOTester(IBusinessObject businessObject)
 {
     if (businessObject == null) throw new ArgumentNullException("businessObject");
     _boTestFactory = new BOTestFactory(businessObject.GetType());
     BusinessObject = businessObject;
 }