예제 #1
0
        public void Test3LayerLoadRelated()
        {
            //---------------Set up test pack-------------------
            BusinessObjectManager.Instance.ClearLoadedObjects();
            ContactPersonTestBO.DeleteAllContactPeople();
            BORegistry.DataAccessor = new DataAccessorDB();
            OrganisationTestBO.LoadDefaultClassDef();
            TestUtil.WaitForGC();
            Address             address;
            ContactPersonTestBO contactPersonTestBO =
                ContactPersonTestBO.CreateContactPersonWithOneAddress_CascadeDelete(out address);

            OrganisationTestBO org = new OrganisationTestBO();

            contactPersonTestBO.SetPropertyValue("OrganisationID", org.OrganisationID);
            org.Save();
            contactPersonTestBO.Save();

            //---------------Assert Preconditions --------------
            Assert.AreEqual(3, BusinessObjectManager.Instance.Count);

            //---------------Execute Test ----------------------
            IBusinessObjectCollection colContactPeople = org.Relationships["ContactPeople"].GetRelatedBusinessObjectCol();
            ContactPersonTestBO       loadedCP         = (ContactPersonTestBO)colContactPeople[0];
            IBusinessObjectCollection colAddresses     = loadedCP.Relationships["Addresses"].GetRelatedBusinessObjectCol();
            Address loadedAdddress = (Address)colAddresses[0];

            //---------------Test Result -----------------------
            Assert.AreEqual(3, BusinessObjectManager.Instance.Count);
            Assert.AreEqual(1, colAddresses.Count);
            Assert.AreSame(contactPersonTestBO, loadedCP);
            Assert.AreSame(address, loadedAdddress);
        }
        public void ShouldMapValuesToCorrectType_WhenPropertyIsNotStringAndDatabaseTypeIs()
        {
            //---------------Set up test pack-------------------
            var classDef = ContactPersonTestBO.LoadDefaultClassDef();

            classDef.PropDefcol["FirstName"].PropertyType = typeof(int);
            var cp1 = new ContactPersonTestBO();

            cp1.Surname = Guid.NewGuid().ToString("N");
            var firstNameValue = 20;

            cp1.SetPropertyValue("FirstName", firstNameValue);
            cp1.Save();
            var selectQuery = QueryBuilder.CreateSelectQuery(classDef);

            selectQuery.Fields.Clear();
            selectQuery.Fields.Add("FirstName", QueryBuilder.CreateQueryField(classDef, "FirstName"));
            //---------------Execute Test ----------------------
            var resultSet = _queryResultLoader.GetResultSet(selectQuery);
            //---------------Test Result -----------------------
            var rows = resultSet.Rows.ToList();

            Assert.AreEqual(firstNameValue, rows[0].Values[0]);
        }
 public void ShouldMapValuesToCorrectType_WhenPropertyIsNotStringAndDatabaseTypeIs()
 {
     //---------------Set up test pack-------------------
     var classDef = ContactPersonTestBO.LoadDefaultClassDef();
     classDef.PropDefcol["FirstName"].PropertyType = typeof(int);
     var cp1 = new ContactPersonTestBO();
     cp1.Surname = Guid.NewGuid().ToString("N");
     var firstNameValue = 20;
     cp1.SetPropertyValue("FirstName", firstNameValue);
     cp1.Save();
     var selectQuery = QueryBuilder.CreateSelectQuery(classDef);
     selectQuery.Fields.Clear();
     selectQuery.Fields.Add("FirstName", QueryBuilder.CreateQueryField(classDef, "FirstName"));
     //---------------Execute Test ----------------------
     var resultSet = _queryResultLoader.GetResultSet(selectQuery);
     //---------------Test Result -----------------------
     var rows = resultSet.Rows.ToList();
     Assert.AreEqual(firstNameValue, rows[0].Values[0]);
 }
예제 #4
0
        public void Test_SetPropertyValue_WithExpression_WhenInvalidProperty()
        {
            //---------------Set up test pack-------------------
            SetupDefaultContactPersonBO();
            ContactPersonTestBO contactPersonTestBO = new ContactPersonTestBO();
            var firstName = TestUtil.GetRandomString();
            //---------------Assert Precondition----------------

            //---------------Execute Test ----------------------
            try
            {
                contactPersonTestBO.SetPropertyValue(testBo => testBo.FirstName + "123", firstName);
            }
            //---------------Test Result -----------------------
            catch (Exception ex)
            {
                Assert.IsInstanceOf<ArgumentException>(ex);
                StringAssert.Contains("testBo => (testBo.FirstName + \"123\") is not a valid property on ContactPersonTestBO", ex.Message);
            }
        }
예제 #5
0
 public void Test_SetPropertyValue_WithExpression()
 {
     //---------------Set up test pack-------------------
     SetupDefaultContactPersonBO();
     ContactPersonTestBO contactPersonTestBO = new ContactPersonTestBO();
     var firstName = TestUtil.GetRandomString();
     //---------------Assert Precondition----------------
     Assert.IsNullOrEmpty(contactPersonTestBO.FirstName);
     //---------------Execute Test ----------------------
     contactPersonTestBO.SetPropertyValue(bo => bo.FirstName, firstName);
     //---------------Test Result -----------------------
     Assert.AreEqual(firstName, contactPersonTestBO.FirstName);
 }
예제 #6
0
        public void Test_SetPropertyValue_WithEnumString_Invalid()
        {
            //---------------Set up test pack-------------------
            ContactPersonTestBO.LoadDefaultClassDefWithEnum();
            ContactPersonTestBO contactPersonTestBO = new ContactPersonTestBO();
            const string newValue = "InvalidOption";
            //-------------Assert Preconditions -------------

            //---------------Execute Test ----------------------
            InvalidPropertyValueException exception = null;
            try
            {
                contactPersonTestBO.SetPropertyValue("ContactType", newValue);
            }
            catch (InvalidPropertyValueException ex)
            {
                exception = ex;
            }
            //---------------Test Result -----------------------
            Assert.IsNotNull(exception, "Expected exception of type InvalidPropertyValueException");
            StringAssert.Contains(
                "An error occurred while attempting to convert the loaded property value of 'ContactType' to its specified type of 'Habanero.Test.BO.ContactPersonTestBO+ContactType'. The property value is 'InvalidOption'. See log for details",
                exception.Message);

//            object value = contactPersonTestBO.GetPropertyValue("ContactType");
//            Assert.IsInstanceOf(typeof (string), value);
//            Assert.AreEqual(newValue, value);
//            IBOProp prop = contactPersonTestBO.Props["ContactType"];
//            Assert.IsFalse(prop.IsValid);
//            StringAssert.Contains(
//                "for property 'Contact Type' is not valid. It is not a type of ContactPersonTestBO+ContactType.",
//                prop.InvalidReason);

            //Habanero.BO.InvalidPropertyValueException: An error occurred while attempting to convert the loaded property value of 'ContactType' to its specified type of 'Habanero.Test.BO.ContactPersonTestBO+ContactType'. The property value is 'InvalidOption'. See log for details
        }
예제 #7
0
        public void Test_SetPropertyValue_WithEnumString()
        {
            //---------------Set up test pack-------------------
            ContactPersonTestBO.LoadDefaultClassDefWithEnum();
            ContactPersonTestBO contactPersonTestBO = new ContactPersonTestBO();
            //-------------Assert Preconditions -------------

            //---------------Execute Test ----------------------
            contactPersonTestBO.SetPropertyValue("ContactType", "Business");
            //---------------Test Result -----------------------
            object value = contactPersonTestBO.GetPropertyValue("ContactType");
            Assert.IsInstanceOf(typeof (ContactPersonTestBO.ContactType), value);
            Assert.AreEqual(ContactPersonTestBO.ContactType.Business, value);
        }
예제 #8
0
 public void Test_SetPropertyValue_WithDateTimeString_Invalid()
 {
     //---------------Set up test pack-------------------
     SetupDefaultContactPersonBO();
     ContactPersonTestBO contactPersonTestBO = new ContactPersonTestBO();
     const string newDateTime = "31/11/2008";
     IBOProp prop = contactPersonTestBO.Props["DateOfBirth"];
     //-------------Assert Preconditions -------------
     Assert.IsNull(prop.Value);
     Assert.IsTrue(prop.IsValid);
     //---------------Execute Test ----------------------
     try
     {
         contactPersonTestBO.SetPropertyValue("DateOfBirth", newDateTime);
         Assert.Fail("expected Err");
     }
         //---------------Test Result -----------------------
     catch (HabaneroDeveloperException ex)
     {
         string message = string.Format("{0} cannot be set to {1}. It is not a type of"
                                        , "DateOfBirth", newDateTime);
         StringAssert.Contains(message, ex.Message);
         StringAssert.Contains("DateTime", ex.Message);
         object value = contactPersonTestBO.GetPropertyValue("DateOfBirth");
         Assert.IsNull(value);
         Assert.IsTrue(prop.IsValid);
     }
 }
예제 #9
0
 public void Test_SetPropertyValue_WithDateTimeString()
 {
     //---------------Set up test pack-------------------
     SetupDefaultContactPersonBO();
     ContactPersonTestBO contactPersonTestBO = new ContactPersonTestBO();
     DateTime newDateTime = DateTime.Today.Add(new TimeSpan(6, 3, 2));
     //-------------Assert Preconditions -------------
     //---------------Execute Test ----------------------
     contactPersonTestBO.SetPropertyValue("DateOfBirth", newDateTime.ToString());
     //---------------Test Result -----------------------
     object value = contactPersonTestBO.GetPropertyValue("DateOfBirth");
     Assert.IsInstanceOf(typeof (DateTime), value);
     Assert.AreEqual(newDateTime, value);
 }
예제 #10
0
        public void Test_GetPropertyValue_WithExpression_ValueType()
        {
            //---------------Set up test pack-------------------
            SetupDefaultContactPersonBO();
            ContactPersonTestBO contactPersonTestBO = new ContactPersonTestBO();
            var originalDateTime = DateTime.Today.AddDays(-TestUtil.GetRandomInt(365));
            contactPersonTestBO.SetPropertyValue(bo => bo.DateOfBirth, originalDateTime);
            //---------------Assert Precondition----------------

            //---------------Execute Test ----------------------
            var dateOfBirth = contactPersonTestBO.GetPropertyValue(testBo => testBo.DateOfBirth);
            //---------------Test Result -----------------------
            Assert.AreEqual(originalDateTime, dateOfBirth);
        }
예제 #11
0
 public void Test_GetPropertyValue_WithExpression()
 {
     //---------------Set up test pack-------------------
     SetupDefaultContactPersonBO();
     ContactPersonTestBO contactPersonTestBO = new ContactPersonTestBO();
     var originalFirstName = TestUtil.GetRandomString();
     contactPersonTestBO.SetPropertyValue(bo => bo.FirstName, originalFirstName);
     //---------------Assert Precondition----------------
     
     //---------------Execute Test ----------------------
     var firstName = contactPersonTestBO.GetPropertyValue(testBo => testBo.FirstName);
     //---------------Test Result -----------------------
     Assert.AreEqual(originalFirstName, firstName);
 }
예제 #12
0
        public void TestIsMatch_NotLike_Incomparable()
        {
            //---------------Set up test pack-------------------
            ClassDef.ClassDefs.Clear();
            ContactPersonTestBO.LoadClassDefWithImageProperty();
            ContactPersonTestBO cp = new ContactPersonTestBO();
            cp.SetPropertyValue("Image", new System.Drawing.Bitmap(10, 10));
            Criteria nameCriteria = new Criteria("Image", Criteria.ComparisonOp.NotLike, new System.Drawing.Bitmap(20, 20));
            cp.Surname = TestUtil.GetRandomString();
            cp.Save();
            
            //---------------Assert PreConditions---------------            
            //---------------Execute Test ----------------------
            try
            {
                nameCriteria.IsMatch(cp);
                Assert.Fail("expected InvalidOperationException because you Bitmap does not implement IComparable");

                //---------------Test Result -----------------------
            }
            catch (InvalidOperationException ex)
            {
                StringAssert.Contains("does not implement IComparable and cannot be matched", ex.Message);
            }
        }
		private static ContactPersonTestBO CreateSavedContactPerson(string surnameValue, int integerPropertyValue)
		{
			ContactPersonTestBO cp = new ContactPersonTestBO();
			cp.Surname = surnameValue;
			cp.SetPropertyValue("IntegerProperty", integerPropertyValue);
			cp.Save();
			return cp;
		}