Exemplo n.º 1
0
        public void Test_ClickCancel_WhenNotIsNew_ShouldCancelEditsAndNotMarkForDelete()
        {
            //---------------Set up test pack-------------------
            IBusinessObject bo = _classDefMyBo.CreateNewBusinessObject();

            bo.Save();
            IDefaultBOEditorForm boEditorForm = GetControlFactory()
                                                .CreateBOEditorForm((BusinessObject)bo, "default", () => null);

            ShowFormIfNecessary(boEditorForm);
            EditControlValueOnForm(boEditorForm, "TestProp", "TestValue");
            EditControlValueOnForm(boEditorForm, "TestProp2", "TestValue2");
            bo.SetPropertyValue("TestProp", "TestValue");
            IButton cancelButton = boEditorForm.Buttons["Cancel"];

            //--------------Assert PreConditions----------------
            Assert.IsNotNull(cancelButton);
            Assert.IsTrue(bo.Status.IsDirty, "BO should be dirty prior to cancelling");
            //---------------Execute Test ----------------------
            cancelButton.PerformClick();
            //---------------Test Result -----------------------
            Assert.AreEqual(DialogResult.Cancel, boEditorForm.DialogResult);
            Assert.AreEqual(null, bo.GetPropertyValue("TestProp"));
            Assert.AreEqual(null, bo.GetPropertyValue("TestProp2"));
            Assert.IsFalse(bo.Status.IsDirty, "BO should not be dirty after cancelling");
            Assert.IsFalse(bo.Status.IsDeleted, "Saved BO should not be deleted on cancelling edits");
            Assert.IsNull(boEditorForm.PanelInfo.BusinessObject);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Determines whether the Expression LeftProp ComparisonOperator RightProp is true or false.
        /// </summary>
        /// <param name="bo"></param>
        /// <returns></returns>
        public bool IsValid(IBusinessObject bo)
        {
            _prop1Value = (IComparable)bo.GetPropertyValue(this.LeftProp.PropertyName);
            _prop2Value = (IComparable)bo.GetPropertyValue(this.RightProp.PropertyName);
            if (_prop1Value == null || _prop2Value == null)
            {
                return(true);
            }
            int compareTo = _prop1Value.CompareTo(_prop2Value);

            if (this.ComparisonOp == ComparisonOperator.LessThan)
            {
                return(compareTo <= -1);
            }
            if (this.ComparisonOp == ComparisonOperator.LessThanOrEqual)
            {
                return(compareTo <= 0);
            }
            if (this.ComparisonOp == ComparisonOperator.EqualTo)
            {
                return(compareTo == 0);
            }
            if (this.ComparisonOp == ComparisonOperator.GreaterThan)
            {
                return(compareTo > 0);
            }
            return(compareTo > -1);
        }
Exemplo n.º 3
0
        public void TestSetPropertyValueWithString()
        {
            IBusinessObject bo = _itsClassDef.CreateNewBusinessObject();

            bo.SetPropertyValue("TestProp", "test");
            Assert.AreSame(typeof(SimpleValueObjectStub), bo.GetPropertyValue("TestProp").GetType());
            Assert.AreEqual("test", bo.GetPropertyValue("TestProp").ToString());
        }
Exemplo n.º 4
0
 private static void AssertPersonsAreEqual(IBusinessObject originalPerson, IBusinessObject deserialisedPerson)
 {
     foreach (IBOProp prop in originalPerson.Props)
     {
         Assert.AreEqual(prop.Value, deserialisedPerson.GetPropertyValue(prop.PropertyName));
     }
 }
Exemplo n.º 5
0
        public void Test_IsValid_WhenLTPasses_ShouldBeTrue()
        {
            //---------------Set up test pack-------------------
            PropDefFake     prop1 = new PropDefFake();
            PropDefFake     prop2 = new PropDefFake();
            InterPropRule   rule  = new InterPropRule(prop1, ComparisonOperator.LessThan, prop2);
            IBusinessObject bo    = GetBOWithPropValueSet(prop1, DateTime.Now.AddDays(-1), prop2, DateTime.Now);

            //---------------Assert Precondition----------------
            Assert.Less((DateTime)bo.GetPropertyValue(prop1.PropertyName), (DateTime)bo.GetPropertyValue(prop2.PropertyName));
            //---------------Execute Test ----------------------
            bool isValid = rule.IsValid(bo);

            //---------------Test Result -----------------------
            Assert.IsTrue(isValid);
        }
Exemplo n.º 6
0
 private void UpdateExistingBo(IBusinessObject bo, IBusinessObject existingBo)
 {
     foreach (var prop in existingBo.Props)
     {
         existingBo.SetPropertyValue(prop.PropertyName, bo.GetPropertyValue(prop.PropertyName));
     }
 }
Exemplo n.º 7
0
        /// <summary>
        /// Initialises the given object
        /// </summary>
        /// <param name="objToInitialise">The object to initialise</param>
        public void InitialiseObject(IBusinessObject objToInitialise)
        {
            BusinessObject newBo = (BusinessObject)objToInitialise;

            foreach (RelPropDef propDef in _relationship.RelKeyDef)
            {
                newBo.SetPropertyValue(propDef.OwnerPropertyName,
                                       _parentObject.GetPropertyValue(propDef.RelatedClassPropName));
            }
            newBo.Relationships.SetRelatedObject(_correspondingRelationshipName, _parentObject);
        }
Exemplo n.º 8
0
        public void Test_ClickOK_ShouldCommitEdits()
        {
            //---------------Set up test pack-------------------
            ShowFormIfNecessary(_defaultBOEditorForm);
            EditControlValueOnForm(_defaultBOEditorForm, "TestProp", "TestValue");
            EditControlValueOnForm(_defaultBOEditorForm, "TestProp2", "TestValue2");
            IButton okButton = _defaultBOEditorForm.Buttons["OK"];

            //--------------Assert PreConditions----------------
            Assert.IsNotNull(okButton);
            //---------------Execute Test ----------------------
            okButton.PerformClick();
            //---------------Test Result -----------------------
            Assert.IsFalse(_defaultBOEditorForm.Visible);
            Assert.AreEqual(DialogResult.OK, _defaultBOEditorForm.DialogResult);
            Assert.AreEqual("TestValue", _bo.GetPropertyValue("TestProp"));
            Assert.AreEqual("TestValue2", _bo.GetPropertyValue("TestProp2"));
            Assert.IsFalse(_bo.Status.IsDirty);
            Assert.IsNull(_defaultBOEditorForm.PanelInfo.BusinessObject);
            //TearDown--------------------------
            //_defaultBOEditorForm.Dispose();
        }
Exemplo n.º 9
0
        public void Test_IsValid_WhenGt_WhenNotGtEqual_ShouldBeFalse()
        {
            //---------------Set up test pack-------------------
            PropDefFake     prop1      = new PropDefFake();
            PropDefFake     prop2      = new PropDefFake();
            InterPropRule   rule       = new InterPropRule(prop1, ComparisonOperator.GreaterThan, prop2);
            DateTime        prop1Value = DateTime.Now.AddDays(-1);
            DateTime        prop2Value = DateTime.Now;
            IBusinessObject bo         = GetBOWithPropValueSet(prop1, prop1Value, prop2, prop2Value);

            //---------------Assert Precondition----------------
            Assert.Less((DateTime)bo.GetPropertyValue(prop1.PropertyName), (DateTime)bo.GetPropertyValue(prop2.PropertyName));
            //---------------Execute Test ----------------------
            bool isValid = rule.IsValid(bo);

            //---------------Test Result -----------------------
            Assert.IsFalse(isValid);
            string expectedMessage = string.Format("Property '{0}' with value '{1}'  should "
                                                   + "be GreaterThan property '{2}' with value '{3}'"
                                                   , prop1.PropertyName, prop1Value, prop2.PropertyName, prop2Value);

            Assert.AreEqual(expectedMessage, rule.Message);
        }
Exemplo n.º 10
0
        public void TestPropertyValue()
        {
            //---------------Set up test pack-------------------
            IBusinessObject bo       = _itsClassDef.CreateNewBusinessObject();
            LongText        longText = new LongText("test");

            //---------------Assert Precondition----------------

            //---------------Execute Test ----------------------
            bo.SetPropertyValue("TestProp", longText);
            object actualValue = bo.GetPropertyValue("TestProp");

            //---------------Test Result -----------------------
            Assert.IsNotNull(actualValue);
            Assert.IsInstanceOf(typeof(LongText), actualValue);
            Assert.AreSame(longText, actualValue);
        }
Exemplo n.º 11
0
        public void TestPropertyValue()
        {
            //---------------Set up test pack-------------------
            IBusinessObject bo          = _itsClassDef.CreateNewBusinessObject();
            var             valueObject = new SimpleValueObjectStub("test");

            //---------------Assert Precondition----------------

            //---------------Execute Test ----------------------
            bo.SetPropertyValue("TestProp", valueObject);
            object actualValue = bo.GetPropertyValue("TestProp");

            //---------------Test Result -----------------------
            Assert.IsNotNull(actualValue);
            Assert.IsInstanceOf(typeof(SimpleValueObjectStub), actualValue);
            Assert.AreSame(valueObject, actualValue);
        }
Exemplo n.º 12
0
        public void Test_IsValid_WhenGt_WhenEq_ShouldBeFalse()
        {
            //---------------Set up test pack-------------------
            PropDefFake     prop1     = new PropDefFake();
            PropDefFake     prop2     = new PropDefFake();
            InterPropRule   rule      = new InterPropRule(prop1, ComparisonOperator.GreaterThan, prop2);
            DateTime        propValue = DateTime.Now;
            IBusinessObject bo        = GetBOWithPropValueSet(prop1, propValue, prop2, propValue);

            //---------------Assert Precondition----------------
            Assert.AreEqual((DateTime)bo.GetPropertyValue(prop1.PropertyName), (DateTime)bo.GetPropertyValue(prop2.PropertyName));
            //---------------Execute Test ----------------------
            bool isValid = rule.IsValid(bo);

            //---------------Test Result -----------------------
            Assert.IsFalse(isValid);
        }
Exemplo n.º 13
0
        public void Test_IsValid_WhenLeftPropNull_ShouldRetTrue()
        {
            //---------------Set up test pack-------------------
            PropDefFake     propLeft   = new PropDefFake();
            PropDefFake     propRight  = new PropDefFake();
            InterPropRule   rule       = new InterPropRule(propLeft, ComparisonOperator.GreaterThan, propRight);
            DateTime?       prop1Value = null;
            DateTime?       prop2Value = DateTime.Now;
            IBusinessObject bo         = GetBOWithPropValueSet(propLeft, prop1Value, propRight, prop2Value);

            //---------------Assert Precondition----------------
            Assert.IsNull(bo.GetPropertyValue(propLeft.PropertyName));
            //---------------Execute Test ----------------------
            bool isValid = rule.IsValid(bo);

            //---------------Test Result -----------------------
            Assert.IsTrue(isValid);
        }
 private static void AssertPersonsAreEqual(IBusinessObject originalPerson, IBusinessObject deserialisedPerson)
 {
     foreach (IBOProp prop in originalPerson.Props)
     {
         Assert.AreEqual(prop.Value, deserialisedPerson.GetPropertyValue(prop.PropertyName));
     }
 }
Exemplo n.º 15
0
        /// <summary>
        /// Returns a valid prop value for <paramref name="propName"/> for the
        /// <see cref="IBusinessObject"/> using any <see cref="IPropRule"/>s for the Prop and any
        /// <see cref="InterPropRule"/>s for the BusinessObject.
        /// </summary>
        /// <param name="bo"></param>
        /// <param name="propName"></param>
        /// <returns></returns>
        public object GetValidPropValue(IBusinessObject bo, string propName)
        {
            //TODO brett 18 Mar 2010: This will not take into consideration multiple InterPropRules
            // this should find the most restrictive rule and then return a result using the most restrictive rule.
            IEnumerable <IBusinessObjectRule> businessObjectRules = GetBusinessObjectRules(bo);

            if (businessObjectRules != null)
            {
                IValidValueGeneratorNumeric validValueGenerator;
                var interPropRules = from rule in businessObjectRules.OfType <InterPropRule>()
                                     where rule.RightProp.PropertyName == propName
                                     select rule;
                foreach (InterPropRule businessObjectRule in interPropRules)
                {
                    object leftPropValue = bo.GetPropertyValue(businessObjectRule.LeftProp.PropertyName);
                    if (leftPropValue != null)
                    {
                        validValueGenerator =
                            GetValidValueGenerator(businessObjectRule.RightProp) as IValidValueGeneratorNumeric;
                        if (validValueGenerator != null)
                        {
                            switch (businessObjectRule.ComparisonOp)
                            {
                            case ComparisonOperator.GreaterThan:
                            case ComparisonOperator.GreaterThanOrEqual:
                                return(validValueGenerator.GenerateValidValueLessThan(leftPropValue));

                            case ComparisonOperator.EqualTo:
                                return(leftPropValue);

                            case ComparisonOperator.LessThanOrEqual:
                            case ComparisonOperator.LessThan:
                                return(validValueGenerator.GenerateValidValueGreaterThan(leftPropValue));
                            }
                            return(null);
                        }
                    }
                }
                interPropRules = from rule in businessObjectRules.OfType <InterPropRule>()
                                 where rule.LeftProp.PropertyName == propName
                                 select rule;
                foreach (InterPropRule businessObjectRule in interPropRules)
                {
                    object rightPropValue = bo.GetPropertyValue(businessObjectRule.RightProp.PropertyName);
                    if (rightPropValue != null)
                    {
                        validValueGenerator =
                            GetValidValueGenerator(businessObjectRule.RightProp) as IValidValueGeneratorNumeric;
                        if (validValueGenerator != null)
                        {
                            switch (businessObjectRule.ComparisonOp)
                            {
                            case ComparisonOperator.GreaterThan:
                            case ComparisonOperator.GreaterThanOrEqual:
                                return(validValueGenerator.GenerateValidValueGreaterThan(rightPropValue));

                            case ComparisonOperator.EqualTo:
                                return(rightPropValue);

                            case ComparisonOperator.LessThanOrEqual:
                            case ComparisonOperator.LessThan:
                                return(validValueGenerator.GenerateValidValueLessThan(rightPropValue));
                            }
                            return(null);
                        }
                    }
                }
            }
            return(this.GetValidPropValue(bo.ClassDef, propName));
        }
        /// <summary>
        /// Returns a valid prop value for <paramref name="propName"/> for the 
        /// <see cref="IBusinessObject"/> using any <see cref="IPropRule"/>s for the Prop and any 
        /// <see cref="InterPropRule"/>s for the BusinessObject.
        /// </summary>
        /// <param name="bo"></param>
        /// <param name="propName"></param>
        /// <returns></returns>
        public object GetValidPropValue(IBusinessObject bo, string propName)
        {
            //TODO brett 18 Mar 2010: This will not take into consideration multiple InterPropRules
            // this should find the most restrictive rule and then return a result using the most restrictive rule.
            IEnumerable<IBusinessObjectRule> businessObjectRules = GetBusinessObjectRules(bo);
            if (businessObjectRules != null)
            {
                IValidValueGeneratorNumeric validValueGenerator;
                var interPropRules = from rule in businessObjectRules.OfType<InterPropRule>()
                                                            where rule.RightProp.PropertyName == propName
                                                            select rule;
                foreach (InterPropRule businessObjectRule in interPropRules)
                {
                    object leftPropValue = bo.GetPropertyValue(businessObjectRule.LeftProp.PropertyName);
                    if (leftPropValue != null)
                    {
                        validValueGenerator =
                            GetValidValueGenerator(businessObjectRule.RightProp) as IValidValueGeneratorNumeric;
                        if (validValueGenerator != null)
                        {
                            switch (businessObjectRule.ComparisonOp)
                            {
                                case ComparisonOperator.GreaterThan:
                                case ComparisonOperator.GreaterThanOrEqual:
                                    return validValueGenerator.GenerateValidValueLessThan(leftPropValue);

                                case ComparisonOperator.EqualTo:
                                    return leftPropValue;

                                case ComparisonOperator.LessThanOrEqual:
                                case ComparisonOperator.LessThan:
                                    return validValueGenerator.GenerateValidValueGreaterThan(leftPropValue);
                            }
                            return null;
                        }
                    }
                }
                interPropRules = from rule in businessObjectRules.OfType<InterPropRule>()
                                 where rule.LeftProp.PropertyName == propName
                                 select rule;
                foreach (InterPropRule businessObjectRule in interPropRules)
                {
                    object rightPropValue = bo.GetPropertyValue(businessObjectRule.RightProp.PropertyName);
                    if (rightPropValue != null)
                    {
                        validValueGenerator =
                            GetValidValueGenerator(businessObjectRule.RightProp) as IValidValueGeneratorNumeric;
                        if (validValueGenerator != null)
                        {
                            switch (businessObjectRule.ComparisonOp)
                            {
                                case ComparisonOperator.GreaterThan:
                                case ComparisonOperator.GreaterThanOrEqual:
                                    return validValueGenerator.GenerateValidValueGreaterThan(rightPropValue);

                                case ComparisonOperator.EqualTo:
                                    return rightPropValue;

                                case ComparisonOperator.LessThanOrEqual:
                                case ComparisonOperator.LessThan:
                                    return validValueGenerator.GenerateValidValueLessThan(rightPropValue);
                            }
                            return null;
                        }
                    }
                }
            }
            return this.GetValidPropValue(bo.ClassDef, propName);
        }
Exemplo n.º 17
0
 /// <summary>
 /// Determines whether the Expression LeftProp ComparisonOperator RightProp is true or false.
 /// </summary>
 /// <param name="bo"></param>
 /// <returns></returns>
 public bool IsValid(IBusinessObject bo)
 {
     _prop1Value = (IComparable) bo.GetPropertyValue(this.LeftProp.PropertyName);
     _prop2Value = (IComparable) bo.GetPropertyValue(this.RightProp.PropertyName);
     if(_prop1Value == null || _prop2Value == null) return true;
     int compareTo = _prop1Value.CompareTo(_prop2Value);
     if (this.ComparisonOp == ComparisonOperator.LessThan) return compareTo <= -1;
     if (this.ComparisonOp == ComparisonOperator.LessThanOrEqual) return compareTo <= 0;
     if (this.ComparisonOp == ComparisonOperator.EqualTo) return compareTo == 0;
     if (this.ComparisonOp == ComparisonOperator.GreaterThan) return compareTo > 0;
     return compareTo > -1;
 }
Exemplo n.º 18
0
 private void UpdateExistingBo(IBusinessObject bo, IBusinessObject existingBo)
 {
     foreach (var prop in existingBo.Props)
     {
         existingBo.SetPropertyValue(prop.PropertyName, bo.GetPropertyValue(prop.PropertyName));
     }
 }
Exemplo n.º 19
0
 protected object GetOrganisationID(IBusinessObject businessObject)
 {
     if (businessObject == null) return null;
     return businessObject.GetPropertyValue("OrganisationID");
 }