private static ContactPersonTestBO CreateContactPersonTestBO()
 {
     ContactPersonTestBO bo = new ContactPersonTestBO();
     string newSurname = Guid.NewGuid().ToString();
     bo.Surname = newSurname;
     bo.Save();
     return bo;
 }
        public void TestTypeOfMultipleCollection()
        {
            ClassDef.ClassDefs.Clear();
            ContactPersonTestBO.LoadClassDefWithAddressesRelationship_DeleteRelated();
            new AddressTestBO();

            ContactPersonTestBO cp = new ContactPersonTestBO();

            Assert.AreSame(typeof(RelatedBusinessObjectCollection<AddressTestBO>), cp.Addresses.GetType());
        }
        public void TestReloadingRelationship()
        {
            ClassDef.ClassDefs.Clear();
            ContactPersonTestBO.LoadClassDefWithAddressesRelationship_DeleteRelated();
            new AddressTestBO();

            ContactPersonTestBO cp = new ContactPersonTestBO();
            IBusinessObjectCollection addresses = cp.Addresses;
            Assert.AreSame(addresses, cp.Addresses);
        }
 protected void CreateDirtyChildren(BusinessObjectCollection<ContactPersonTestBO> cpCol,
                         out ContactPersonTestBO existingChild,
                         out ContactPersonTestBO editedChild,
                         out ContactPersonTestBO deletedChild,
                         out ContactPersonTestBO createdChildWithEdits,
                         out ContactPersonTestBO createdChild)
 {
     createdChild = CreateCreatedChild(cpCol);
     createdChildWithEdits = CreateCreatedChildWithEdits(cpCol);
     existingChild = CreateExistingChild(cpCol);
     editedChild = CreateEditedChild(cpCol);
     deletedChild = CreateDeletedChild(cpCol);
 }
        public void Test_Constructor()
        {
            //---------------Set up test pack-------------------
            ContactPersonTestBO contactPersonTestBO = new ContactPersonTestBO();
            SingleRelationship<OrganisationTestBO> singleRelationship = contactPersonTestBO.Relationships.GetSingle<OrganisationTestBO>("Organisation");

            //---------------Execute Test ----------------------
            TransactionalSingleRelationship_Added tsr = new TransactionalSingleRelationship_Added(singleRelationship, new OrganisationTestBO());
            //---------------Test Result -----------------------

            Assert.AreSame(singleRelationship, tsr.Relationship);
            //---------------Tear Down -------------------------          
        }
 public void Test_Create_WhenRelatedProp_ShouldCreateBOPropMapper()
 {
     //---------------Set up test pack-------------------
     const string propName = "Organisation.Name";
     var bo = new ContactPersonTestBO();
     //---------------Assert Precondition----------------
     Assert.IsTrue(bo.Relationships.Contains("Organisation"));
     //---------------Execute Test ----------------------
     IBOPropertyMapper propMapper = BOPropMapperFactory.CreateMapper(bo, propName);
     //---------------Test Result -----------------------
     Assert.IsInstanceOf<BOPropertyMapper>(propMapper);
     Assert.AreEqual(propName, propMapper.PropertyName);
     Assert.AreSame(bo, propMapper.BusinessObject);
 }
 public void Test_SetToNull()
 {
     //---------------Set up test pack-------------------
     OrganisationTestBO organisationTestBO = OrganisationTestBO.CreateSavedOrganisation();
     SingleRelationship<ContactPersonTestBO> relationship = GetAssociationRelationship(organisationTestBO);
     relationship.OwningBOHasForeignKey = false;
     ContactPersonTestBO contactPerson = new ContactPersonTestBO();
     contactPerson.Surname = TestUtil.GetRandomString();
     contactPerson.FirstName = TestUtil.GetRandomString();
     contactPerson.Organisation = organisationTestBO;
     contactPerson.Save();
     //---------------Assert Precondition----------------
     Assert.AreSame(contactPerson, organisationTestBO.ContactPerson);
     //---------------Execute Test ----------------------
     organisationTestBO.ContactPerson = null;
     //---------------Test Result -----------------------
     Assert.IsNull(organisationTestBO.ContactPerson);
 }
        public void Test_BusinessObject()
        {
            //---------------Set up test pack-------------------
            var readOnlyGrid = GetControlFactory().CreateReadOnlyGrid();

            const string propName = "Addresses";
            var mapper = CreateReadOnlyGridMapper(readOnlyGrid, propName);
            ContactPersonTestBO.LoadClassDefWithAddressesRelationship_DeleteRelated();
            ContactPersonTestBO contactPersonTestBO = new ContactPersonTestBO();
            RelatedBusinessObjectCollection<AddressTestBO> addresses = contactPersonTestBO.Addresses;
            //---------------Assert PreConditions---------------        
            Assert.IsNull(mapper.BusinessObject);

            //---------------Execute Test ----------------------
            mapper.BusinessObject = contactPersonTestBO;
            //---------------Test Result -----------------------
            Assert.AreSame(contactPersonTestBO, mapper.BusinessObject);
            Assert.AreSame(addresses, readOnlyGrid.BusinessObjectCollection);
        }
 public void Test_AddMethod()
 {
     //---------------Set up test pack-------------------
     //ContactPersonTestBO.LoadDefaultClassDef();
     BusinessObjectCollection<ContactPersonTestBO> cpCol = new BusinessObjectCollection<ContactPersonTestBO>();
     ContactPersonTestBO myBO = new ContactPersonTestBO();
     _businessObjectCollectionTestHelper.RegisterForAddedEvent(cpCol);
     //---------------Assert Precondition----------------
     Assert.AreEqual(0, cpCol.Count);
     Assert.AreEqual(0, cpCol.AddedBusinessObjects.Count);
     _businessObjectCollectionTestHelper.AssertAddedEventNotFired();
     //---------------Execute Test ----------------------
     cpCol.Add(myBO);
     //---------------Test Result -----------------------
     Assert.AreEqual(1, cpCol.Count, "One object should be in the cpCollection");
     BusinessObjectCollectionTestHelper.AssertOneObjectInCurrentAndCreatedCollection(cpCol);
     _businessObjectCollectionTestHelper.AssertAddedEventFired();
     Assert.AreEqual(myBO, cpCol[0], "Added object should be in the cpCollection");
 }
        public void Test_BusinessObject_WhenNull()
        {
            //---------------Set up test pack-------------------
            IEditableGridControl editableGrid = GetControlFactory().CreateEditableGridControl();

            const string propName = "Addresses";
            EditableGridControlMapper mapper = new EditableGridControlMapper(editableGrid, propName, false, GetControlFactory());
            ContactPersonTestBO.LoadClassDefWithAddressesRelationship_DeleteRelated();
            ContactPersonTestBO contactPersonTestBO = new ContactPersonTestBO();
            mapper.BusinessObject = contactPersonTestBO;
            RelatedBusinessObjectCollection<AddressTestBO> addresses = contactPersonTestBO.Addresses;
            //---------------Assert PreConditions---------------        
            Assert.AreSame(contactPersonTestBO, mapper.BusinessObject);
            Assert.AreSame(addresses, editableGrid.BusinessObjectCollection);
            //---------------Execute Test ----------------------
            mapper.BusinessObject = null;
            //---------------Test Result -----------------------
            Assert.IsNull(mapper.BusinessObject);
            Assert.AreSame(null, editableGrid.BusinessObjectCollection);
        }
        public void Test_ConcurrentSave()
        {
            //---------------Set up test pack-------------------
            ClassDef.ClassDefs.Clear();
            var classDef = ContactPersonTestBO.LoadDefaultClassDef();
            FixtureEnvironment.ClearBusinessObjectManager();
            TestUtil.WaitForGC();
            
            //---------------Assert Precondition----------------

            //---------------Execute Test ----------------------
            Parallel.For(0, 1000, i =>
                                  {
                                      var person = new ContactPersonTestBO();
                                      person.Surname = RandomValueGen.GetRandomString(1, 10);
                                      person.Save();
                                  });

            //---------------Test Result -----------------------
        }
예제 #12
0
        public void Test_BusinessObject_WhenSetToNull_HavingPropertyOnRelatedBO_ShouldReturnNullProperty()
        {
            //---------------Set up test pack-------------------
            const string        innerPropertyName   = "Name";
            const string        propertyName        = "Organisation." + innerPropertyName;
            BOPropertyMapper    boPropertyMapper    = new BOPropertyMapper(propertyName);
            ContactPersonTestBO contactPersonTestBO = new ContactPersonTestBO {
                Organisation = new OrganisationTestBO()
            };

            boPropertyMapper.BusinessObject = contactPersonTestBO;
            //---------------Assert Precondition----------------
            Assert.IsNotNull(boPropertyMapper.BusinessObject);
            Assert.IsNotNull(boPropertyMapper.Property);
            Assert.IsNotNull(contactPersonTestBO.Organisation);
            //---------------Execute Test ----------------------
            boPropertyMapper.BusinessObject = null;
            //---------------Test Result -----------------------
            Assert.IsNull(boPropertyMapper.BusinessObject);
            Assert.IsNull(boPropertyMapper.Property);
        }
예제 #13
0
        public void Test_SaveDuplicateObject_DoesNotAddItselfToObjectManager()
        {
            //This scenario is unlikely to ever happen in normal use but is frequently hit during testing.
            //An object that has a reference to it is removed from the object manager (usually via ClearLoadedObjects).
            // A second instance of the same object is now loaded. This new instance is therefore added to the object manager.
            // The first object is saved. This must not remove the second instance of the object from the object manager and insert a itself.
            //---------------Set up test pack-------------------
            ContactPersonTestBO.LoadDefaultClassDef();
            BusinessObjectManager boMan = BusinessObjectManager.Instance;
            ContactPersonTestBO   originalContactPerson = new ContactPersonTestBO();

            originalContactPerson.Surname = "FirstSurname";
            originalContactPerson.Save();
            IPrimaryKey origCPID = originalContactPerson.ID;

            BusinessObjectManager.Instance.ClearLoadedObjects();

            //---------------Assert Precondition----------------
            Assert.AreEqual(0, boMan.Count);
            Assert.IsFalse(boMan.Contains(originalContactPerson));

            //---------------Execute Test Step 1----------------------
            ContactPersonTestBO myContact2 =
                BORegistry.DataAccessor.BusinessObjectLoader.GetBusinessObject <ContactPersonTestBO>(origCPID);

            //---------------Test Result Step 1-----------------------
            Assert.AreEqual(1, boMan.Count);
            Assert.IsTrue(boMan.Contains(myContact2));


            //---------------Execute Test Step 2----------------------
            originalContactPerson.Surname = TestUtil.CreateRandomString();
            originalContactPerson.Save();

            //---------------Test Result Step 1-----------------------
            Assert.AreNotSame(originalContactPerson, myContact2);
            Assert.AreEqual(1, boMan.Count);
            Assert.IsTrue(boMan.Contains(myContact2));
            Assert.IsFalse(boMan.Contains(originalContactPerson));
        }
예제 #14
0
        public void Test_LoadRelatedBoCol()
        {
            //---------------Set up test pack-------------------
            OrganisationTestBO    organisationTestBO = OrganisationTestBO.CreateSavedOrganisation();
            IMultipleRelationship cpRelationship     =
                (IMultipleRelationship)organisationTestBO.Relationships["ContactPeople"];
            ContactPersonTestBO cp =
                (ContactPersonTestBO)cpRelationship.BusinessObjectCollection.CreateBusinessObject();

            cp.FirstName = TestUtil.GetRandomString();
            cp.Surname   = TestUtil.GetRandomString();
            cp.Save();
            //---------------Assert Precondition----------------

            //---------------Execute Test ----------------------
            IBusinessObjectCollection cpCol =
                BORegistry.DataAccessor.BusinessObjectLoader.GetRelatedBusinessObjectCollection
                    (typeof(ContactPersonTestBO), cpRelationship);

            //---------------Test Result -----------------------
            AssertOneObjectInCurrentAndPersistedCollection(cpCol);
        }
예제 #15
0
        public void Test_DirtyIfHasRemoveChildren()
        {
            //---------------Set up test pack-------------------
            OrganisationTestBO organisationTestBO = OrganisationTestBO.CreateSavedOrganisation();
            BusinessObjectCollection <ContactPersonTestBO> cpCol;
            MultipleRelationship <ContactPersonTestBO>     relationship = GetAggregationRelationship
                                                                              (organisationTestBO, out cpCol);
            ContactPersonTestBO myBO = cpCol.CreateBusinessObject();

            myBO.Surname   = TestUtil.GetRandomString();
            myBO.FirstName = TestUtil.GetRandomString();
            myBO.Save();
            organisationTestBO.Save();
            //---------------Assert Precondition----------------
            Assert.IsFalse(relationship.IsDirty);

            //---------------Execute Test ----------------------
            cpCol.Remove(myBO);

            //---------------Test Result -----------------------
            Assert.IsTrue(relationship.IsDirty);
        }
예제 #16
0
        public void TestGetBusinessObject_SelectQuery_Fresh()
        {
            //---------------Set up test pack-------------------
            SetupDataAccessor();
            SetupDefaultContactPersonBO();
            ContactPersonTestBO cp = new ContactPersonTestBO();

            cp.Surname   = Guid.NewGuid().ToString("N");
            cp.FirstName = Guid.NewGuid().ToString("N");
            cp.Save();
            BORegistry.BusinessObjectManager = new BusinessObjectManagerSpy();//Ensures a new BOMan is created and used for each test

            SelectQuery query = CreateSelectQuery(cp);

            //                new SelectQuery(new Criteria("Surname", Criteria.ComparisonOp.Equals, cp.Surname)));
            //                query.Fields.Add("Surname", new QueryField("Surname", "Surname_field", null));
            //                query.Fields.Add("ContactPersonID", new QueryField("ContactPersonID", "ContactPersonID", null));
            //                query.Source = new Source(cp.ClassDef.TableName);

            //---------------Assert Precondition ---------------
            //Object not loaded in all loaded business objects
            BORegistry.BusinessObjectManager = new BusinessObjectManagerSpy();//Ensures a new BOMan is created and used for each test

            //---------------Execute Test ----------------------
            ContactPersonTestBO loadedCp =
                BORegistry.DataAccessor.BusinessObjectLoader.GetBusinessObject <ContactPersonTestBO>(query);

            //---------------Test Result -----------------------
            Assert.AreEqual(1, BORegistry.BusinessObjectManager.Count);
            Assert.AreNotSame(loadedCp, cp);
            Assert.AreEqual(cp.ContactPersonID, loadedCp.ContactPersonID);
            Assert.AreEqual(cp.Surname, loadedCp.Surname);
            Assert.IsTrue(String.IsNullOrEmpty(loadedCp.FirstName), "Firstname is not being loaded");
            // not being loaded
            Assert.IsFalse(loadedCp.Status.IsNew);
            Assert.IsFalse(loadedCp.Status.IsDeleted);
            Assert.IsFalse(loadedCp.Status.IsDirty);
            Assert.IsTrue(loadedCp.Status.IsValid());
        }
예제 #17
0
        public void TestGetBusinessObjectWithPrimaryKey()
        {
            //---------------Set up test pack-------------------
            ClassDef.ClassDefs.Clear();
            ContactPersonTestBO.LoadDefaultClassDef();
            ContactPersonTestBO cp = new ContactPersonTestBO();

            cp.Surname = Guid.NewGuid().ToString("N");
            cp.Save();
            BOLoader.Instance.ClearLoadedBusinessObjects();
            BusinessObjectLoaderDB loader = new BusinessObjectLoaderDB(DatabaseConnection.CurrentConnection);

            //--------------Assert PreConditions----------------

            //---------------Execute Test ----------------------
            ContactPersonTestBO loadedCP = loader.GetBusinessObject <ContactPersonTestBO>(cp.PrimaryKey);

            //---------------Test Result -----------------------
            Assert.AreNotSame(cp, loadedCP);
            Assert.AreEqual(cp.ID, loadedCP.ID);
            //---------------Tear Down -------------------------
        }
예제 #18
0
        public void Test_BusinessObject_WhenSetToNull_ShouldFireRelationshipChangedEvent()
        {
            //---------------Set up test pack-------------------
            ContactPersonTestBO  contactPersonTestBO  = new ContactPersonTestBO();
            const string         relationshipName     = "Organisation";
            BORelationshipMapper boRelationshipMapper = new BORelationshipMapper(relationshipName);

            boRelationshipMapper.BusinessObject = contactPersonTestBO;
            bool eventFired = false;

            boRelationshipMapper.RelationshipChanged += (sender, e) => eventFired = true;
            //---------------Assert Precondition----------------
            Assert.IsNotNull(boRelationshipMapper.BusinessObject);
            Assert.IsNotNull(boRelationshipMapper.Relationship);
            Assert.IsFalse(eventFired);
            //---------------Execute Test ----------------------
            boRelationshipMapper.BusinessObject = null;
            //---------------Test Result -----------------------
            Assert.IsNull(boRelationshipMapper.BusinessObject);
            Assert.IsNull(boRelationshipMapper.Relationship);
            Assert.IsTrue(eventFired);
        }
예제 #19
0
        public void Test_CancelEdits()
        {
            //---------------Set up test pack-------------------
            new AddressTestBO();
            ContactPersonTestBO.LoadClassDefOrganisationTestBORelationship_MultipleReverse();
            OrganisationTestBO.LoadDefaultClassDef_WithMultipleRelationshipToAddress();
            OrganisationTestBO organisationTestBO = OrganisationTestBO.CreateSavedOrganisation();
            RelationshipCol    relationships      = organisationTestBO.Relationships;
            MultipleRelationship <ContactPersonTestBO>     contactPersonRelationship = organisationTestBO.Relationships.GetMultiple <ContactPersonTestBO>("ContactPeople");
            BusinessObjectCollection <ContactPersonTestBO> contactPersonCol          = contactPersonRelationship.BusinessObjectCollection;
            MultipleRelationship <AddressTestBO>           addressRelationship       = organisationTestBO.Relationships.GetMultiple <AddressTestBO>("Addresses");
            BusinessObjectCollection <AddressTestBO>       addressCol = addressRelationship.BusinessObjectCollection;

            contactPersonCol.CreateBusinessObject();
            addressCol.CreateBusinessObject();
            //---------------Assert Precondition----------------
            Assert.IsTrue(relationships.IsDirty);
            //---------------Execute Test ----------------------
            relationships.CancelEdits();
            //---------------Test Result -----------------------
            Assert.IsFalse(relationships.IsDirty);
        }
예제 #20
0
        public void Test_AutoLoadingMapper_WhenCreateFromControlMapper_ShouldSetupCollection()
        {
            //---------------Set up test pack-------------------
            var cmbox         = _controlFactory.CreateComboBox();
            var controlMapper = ControlMapper.Create
                                    ("AutoLoadingRelationshipComboBoxMapper", "Habanero.Faces.Base", cmbox, "ContactPersonTestBO", false,
                                    GetControlFactory());

            var person1 = ContactPersonTestBO.CreateSavedContactPerson();
            var person2 = ContactPersonTestBO.CreateSavedContactPerson();

            var addressTestBo = new AddressTestBO();

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

            //---------------Execute Test ----------------------
            controlMapper.BusinessObject = addressTestBo;
            //---------------Test Result -----------------------
            Assert.AreEqual(3, cmbox.Items.Count);
            Assert.IsTrue(cmbox.Items.Contains(person1));
            Assert.IsTrue(cmbox.Items.Contains(person2));
        }
        public void Test_CreatedChild_WhenInsertParentAction_DoNothing_DoesNotSavesWhenParentSaves()
        {
            //---------------Set up test pack-------------------
            OrganisationTestBO  organisationTestBO = OrganisationTestBO.CreateSavedOrganisation();
            ContactPersonTestBO contactPerson      = organisationTestBO.ContactPeople.CreateBusinessObject();
            RelationshipDef     relationshipDef    =
                (RelationshipDef)organisationTestBO.Relationships["ContactPeople"].RelationshipDef;

            relationshipDef.InsertParentAction = InsertParentAction.DoNothing;
            relationshipDef.RelationshipType   = RelationshipType.Association;
            contactPerson.Surname   = TestUtil.GetRandomString();
            contactPerson.FirstName = TestUtil.GetRandomString();
            //---------------AssertPrecondtion------------------
            Assert.AreEqual(InsertParentAction.DoNothing, relationshipDef.InsertParentAction);
            Assert.IsTrue(contactPerson.Status.IsDirty);
            Assert.IsTrue(contactPerson.Status.IsNew);
            //---------------Execute Test ----------------------
            organisationTestBO.Save();
            //---------------Test Result -----------------------
            Assert.IsTrue(contactPerson.Status.IsDirty);
            Assert.IsTrue(contactPerson.Status.IsNew);
        }
        public void Test_AddMethod_AddNewChild()
        {
            //•(In habanero a new tyre can be added to a car).
            //---------------Set up test pack-------------------
            OrganisationTestBO organisationTestBO = OrganisationTestBO.CreateSavedOrganisation();
            BusinessObjectCollection <ContactPersonTestBO> cpCol;
            MultipleRelationship <ContactPersonTestBO>     aggregateRelationship = GetAggregateRelationship(organisationTestBO, out cpCol);
            ContactPersonTestBO contactPerson = ContactPersonTestBO.CreateUnsavedContactPerson();

            util.RegisterForAddedAndRemovedEvents(cpCol);

            //---------------Assert Precondition----------------
            util.AssertAllCollectionsHaveNoItems(cpCol);

            //---------------Execute Test ----------------------
            cpCol.Add(contactPerson);

            //---------------Test Result -----------------------
            util.AssertAddedEventFired();
            util.AssertOneObjectInCurrentAndCreatedCollection(cpCol);
            Assert.AreSame(contactPerson.Organisation, aggregateRelationship.OwningBO);
        }
예제 #23
0
        public void TestLoadedObjectIsAddedToObjectManager()
        {
            //---------------Set up test pack-------------------
            ContactPerson.DeleteAllContactPeople();
            SetupDefaultContactPersonBO();
            ContactPersonTestBO contactPerson1 = ContactPersonTestBO.CreateSavedContactPerson
                                                     (Guid.NewGuid().ToString("N"), Guid.NewGuid().ToString("N"));

            FixtureEnvironment.ClearBusinessObjectManager();

            //---------------Assert Precondition----------------
            Assert.AreEqual(0, BORegistry.BusinessObjectManager.Count);

            //---------------Execute Test ----------------------
            ContactPersonTestBO contactPerson =
                BORegistry.DataAccessor.BusinessObjectLoader.GetBusinessObject <ContactPersonTestBO>
                    (contactPerson1.ID);

            //---------------Test Result -----------------------
            Assert.AreEqual(1, BORegistry.BusinessObjectManager.Count);
            Assert.IsTrue(BORegistry.BusinessObjectManager.Contains(contactPerson));
        }
예제 #24
0
        public void TestFind_Untyped()
        {
            //---------------Set up test pack-------------------
            BORegistry.DataAccessor = new DataAccessorInMemory(new DataStoreInMemory());
            ClassDef.ClassDefs.Clear();
            ContactPersonTestBO.LoadDefaultClassDef();
            ContactPersonTestBO cp = new ContactPersonTestBO();

            cp.Surname = Guid.NewGuid().ToString("N");
            cp.Save();
            DataStoreInMemory dataStore = new DataStoreInMemory();

            dataStore.Add(cp);
            Criteria criteria = new Criteria("Surname", Criteria.ComparisonOp.Equals, cp.Surname);

            //---------------Execute Test ----------------------
            ContactPersonTestBO loadedCP = (ContactPersonTestBO)dataStore.Find(typeof(ContactPersonTestBO), criteria);

            //---------------Test Result -----------------------
            Assert.AreSame(cp.ID, loadedCP.ID);
            //---------------Tear Down -------------------------
        }
예제 #25
0
        public void Test_UpdateErrorProviderError_WhenBOInvalid_ShouldSetErrorMessage()
        {
            //---------------Set up test pack-------------------
            ContactPersonTestBO.LoadDefaultClassDefWithUIDef();
            ContactPersonTestBO person = ContactPersonTestBO.CreateUnsavedContactPerson("", "");

            Habanero.Faces.Base.PanelBuilder panelBuilder = new Habanero.Faces.Base.PanelBuilder(GetControlFactory());
            IPanelInfo panelInfo = panelBuilder.BuildPanelForTab((UIFormTab)person.ClassDef.UIDefCol["default"].UIForm[0]);

            person.Surname           = TestUtil.GetRandomString();
            panelInfo.BusinessObject = person;
            IControlMapper SurnameControlMapper = panelInfo.FieldInfos["Surname"].ControlMapper;

            person.Surname = "";
            //---------------Assert Precondition----------------
            Assert.IsFalse(person.Status.IsValid());
            Assert.AreEqual("", SurnameControlMapper.GetErrorMessage());
            //---------------Execute Test ----------------------
            panelInfo.UpdateErrorProvidersErrorMessages();
            //---------------Test Result -----------------------
            Assert.AreNotEqual("", SurnameControlMapper.GetErrorMessage());
        }
예제 #26
0
        public void TestFindAll_ClassDef_NullCriteria()
        {
            //---------------Set up test pack-------------------
            ClassDef.ClassDefs.Clear();
            ContactPersonTestBO.LoadDefaultClassDef();
            OrganisationTestBO.LoadDefaultClassDef();
            DataStoreInMemory   dataStore = new DataStoreInMemory();
            DateTime            now       = DateTime.Now;
            ContactPersonTestBO cp1       = new ContactPersonTestBO {
                DateOfBirth = now
            };

            dataStore.Add(cp1);
            dataStore.Add(OrganisationTestBO.CreateSavedOrganisation());
            //---------------Execute Test ----------------------
            IBusinessObjectCollection col = dataStore.FindAll(ClassDef.Get <ContactPersonTestBO>(), null);

            //---------------Test Result -----------------------
            Assert.AreEqual(1, col.Count);
            Assert.Contains(cp1, col);
            Assert.IsNull(col.SelectQuery.Criteria);
        }
예제 #27
0
        public void Test_GetDirtyChildren_Edited()
        {
            //---------------Set up test pack-------------------
            OrganisationTestBO organisationTestBO = OrganisationTestBO.CreateSavedOrganisation();
            BusinessObjectCollection <ContactPersonTestBO> cpCol;
            MultipleRelationship <ContactPersonTestBO>     relationship = GetAggregationRelationship
                                                                              (organisationTestBO, out cpCol);

            ContactPersonTestBO contactPerson = cpCol.CreateBusinessObject();

            contactPerson.Surname   = TestUtil.GetRandomString();
            contactPerson.FirstName = TestUtil.GetRandomString();
            contactPerson.Save();
            contactPerson.FirstName = TestUtil.GetRandomString();

            //---------------Execute Test ----------------------
            IList <ContactPersonTestBO> dirtyChildren = relationship.GetDirtyChildren();

            //---------------Test Result -----------------------
            Assert.AreEqual(1, dirtyChildren.Count);
            Assert.IsTrue(dirtyChildren.Contains(contactPerson));
        }
예제 #28
0
        public void Test_CreatedBusinessObject_ColMarkForDelete_ShouldRemoveFromCurrentAndCreatedCol()
        {
            //---------------Set up test pack-------------------
            //ContactPersonTestBO.LoadDefaultClassDef();
            RelatedBusinessObjectCollection <ContactPersonTestBO> cpCol = CreateRelatedCPCol();

            ContactPersonTestBO newCP = cpCol.CreateBusinessObject();

            newCP.Surname = TestUtil.GetRandomString();

            //---------------Assert Precondition----------------
            AssertOneObjectInCurrentAndCreatedCollection(cpCol);

            //---------------Execute Test ----------------------
            cpCol.MarkForDelete(newCP);

            //---------------Test Result -----------------------
            Assert.AreEqual(0, cpCol.Count);
            Assert.AreEqual(0, cpCol.CreatedBusinessObjects.Count);
            Assert.AreEqual(0, cpCol.MarkedForDeleteBusinessObjects.Count);
            Assert.IsTrue(newCP.Status.IsDeleted);
        }
예제 #29
0
        public void Test_GetDirtyChildren_WhenCreated_WhenInsertParentAction_DoNothing_ShouldNotReturnCreatedChildren()
        {
            //---------------Set up test pack-------------------
            OrganisationTestBO organisationTestBO = OrganisationTestBO.CreateSavedOrganisation();
            BusinessObjectCollection <ContactPersonTestBO> cpCol;
            MultipleRelationship <ContactPersonTestBO>     relationship = GetAggregationRelationship
                                                                              (organisationTestBO, out cpCol);
            RelationshipDef relationshipDef = (RelationshipDef)relationship.RelationshipDef;

            relationshipDef.InsertParentAction = InsertParentAction.DoNothing;
            ContactPersonTestBO contactPerson = cpCol.CreateBusinessObject();

            contactPerson.Surname   = TestUtil.GetRandomString();
            contactPerson.FirstName = TestUtil.GetRandomString();
            //---------------Assert Precondition----------------
            Assert.AreEqual(InsertParentAction.DoNothing, relationshipDef.InsertParentAction);
            //---------------Execute Test ----------------------
            IList <ContactPersonTestBO> dirtyChildren = relationship.GetDirtyChildren();

            //---------------Test Result -----------------------
            Assert.AreEqual(0, dirtyChildren.Count);
        }
        public void Test_SetChild_PersistedChild()
        {
            //An already persi`sted Brain cannot be set as the brain of a person.
            //---------------Set up test pack-------------------
            OrganisationTestBO  organisation            = OrganisationTestBO.CreateSavedOrganisation();
            ISingleRelationship compositionRelationship = GetCompositionRelationship(organisation);

            ContactPersonTestBO contactPerson = ContactPersonTestBO.CreateSavedContactPerson();

            //---------------Execute Test ----------------------
            try
            {
                compositionRelationship.SetRelatedObject(contactPerson);
                Assert.Fail("expected Err");
            }
            //---------------Test Result -----------------------
            catch (HabaneroDeveloperException ex)
            {
                StringAssert.Contains("The " + compositionRelationship.RelationshipDef.RelatedObjectClassName, ex.Message);
                StringAssert.Contains("could not be added since the " + compositionRelationship.RelationshipName + " relationship is set up as ", ex.Message);
            }
        }
예제 #31
0
        public void Test_TestGetReverseRelationship()
        {
            //This is probably a temporary test as this method is hacked together due
            // to the fact that reverse relationships are not currently defined In Habanero.
            //---------------Set up test pack-------------------
            ClassDef.ClassDefs.Clear();
            BORegistry.DataAccessor = new DataAccessorInMemory();
            ContactPersonTestBO.LoadClassDefWithAddresBOsRelationship_AddressReverseRelationshipConfigured();
            ContactPersonTestBO contactPersonTestBO =
                ContactPersonTestBO.CreateUnsavedContactPerson(TestUtil.GetRandomString(), TestUtil.GetRandomString());

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

            //---------------Execute Test ----------------------
            AddressTestBO address = contactPersonTestBO.AddressTestBOs.CreateBusinessObject();

            //---------------Test Result -----------------------
            IRelationship relationship = contactPersonTestBO.AddressTestBOs.GetReverseRelationship(address);

            Assert.IsNotNull(relationship);
            Assert.AreSame(address.Relationships["ContactPersonTestBO"], relationship);
        }
예제 #32
0
        public void TestGetReverseRelationship()
        {
            //---------------Set up test pack-------------------
            OrganisationTestBO.LoadDefaultClassDef_WithTwoRelationshipsToContactPerson();
            IClassDef cpClassDef = ContactPersonTestBO.LoadClassDefOrganisationTestBORelationship_MultipleReverse();

            cpClassDef.RelationshipDefCol["Organisation"].ReverseRelationshipName = "OtherContactPeople";

            OrganisationTestBO  organisation  = OrganisationTestBO.CreateSavedOrganisation();
            ContactPersonTestBO contactPerson = ContactPersonTestBO.CreateUnsavedContactPerson();

            SingleRelationship <OrganisationTestBO> organisationRel =
                contactPerson.Relationships.GetSingle <OrganisationTestBO>("Organisation");
            MultipleRelationship <ContactPersonTestBO> contactPeopleRel =
                organisation.Relationships.GetMultiple <ContactPersonTestBO>("OtherContactPeople");

            //---------------Execute Test ----------------------
            IRelationship reverseRelationship = organisationRel.GetReverseRelationship(organisation);

            //---------------Test Result -----------------------
            Assert.AreSame(contactPeopleRel, reverseRelationship);
        }
        public void Test_AddRow_WhenVirtualProp_ShouldAddBOWithRelatedVirtualPropSet()
        {
            //---------------Set up test pack-------------------
            RecordingExceptionNotifier recordingExceptionNotifier = new RecordingExceptionNotifier();

            GlobalRegistry.UIExceptionNotifier = recordingExceptionNotifier;
            AddressTestBO.LoadDefaultClassDef();
            var contactPersonClassDef = ContactPersonTestBO.LoadClassDefWithOrganisationAndAddressRelationships();

            OrganisationTestBO.LoadDefaultClassDef();
            BusinessObjectCollection <ContactPersonTestBO> contactPersonTestBOS = new BusinessObjectCollection <ContactPersonTestBO>();

            OrganisationTestBO organisation = new OrganisationTestBO();

            UIGrid uiGrid = new UIGrid();

            new UIDef("fdafdas", new UIForm(), uiGrid)
            {
                ClassDef = contactPersonClassDef
            };
            const string propertyName = "-Organisation-";

            uiGrid.Add(new UIGridColumn("Contact Organisation", propertyName, typeof(DataGridViewTextBoxColumn), true, 100, PropAlignment.left, new Hashtable()));

            IDataSetProvider dataSetProvider = CreateDataSetProvider(contactPersonTestBOS);
            DataTable        table           = dataSetProvider.GetDataTable(uiGrid);

            //---------------Assert Precondition----------------
            Assert.IsTrue(dataSetProvider is EditableDataSetProvider);
            Assert.AreEqual(0, table.Rows.Count);
            Assert.AreEqual(0, contactPersonTestBOS.Count);
            //---------------Execute Test ----------------------
            table.Rows.Add(new object[] { null, organisation });
            //---------------Test Result -----------------------
            Assert.AreEqual(1, table.Rows.Count);
            Assert.AreEqual(1, contactPersonTestBOS.Count);
            Assert.AreSame(organisation, table.Rows[0][propertyName]);
            Assert.AreSame(organisation, contactPersonTestBOS[0].Organisation);
        }
        public virtual void Test_KeyPressStrategy_UpdatesBusinessObject_WhenEnterKeyPressed()
        {
            //---------------Set up test pack-------------------
            ComboBoxWinStub cmbox = new ComboBoxWinStub();
            BusinessObjectCollection <OrganisationTestBO> boCol;
            RelationshipComboBoxMapper mapper = GetMapperBoColHasOneItem(cmbox, out boCol);

            mapper.MapperStrategy = GetControlFactory().CreateLookupKeyPressMapperStrategy();
            OrganisationTestBO  newBO = boCol.CreateBusinessObject();
            OrganisationTestBO  organisationTestBO = boCol[0];
            ContactPersonTestBO person             = CreateCPWithRelatedOrganisation(organisationTestBO);

            mapper.BusinessObject = person;
            cmbox.Text            = newBO.ToString();
            //---------------Assert Precondition----------------
            Assert.AreNotSame(newBO, person.Organisation, "For Windows the value should be changed.");
            //---------------Execute Test ----------------------
            cmbox.CallSendKeyBob();
            //---------------Test Result -----------------------
            Assert.IsInstanceOf(typeof(ComboBoxKeyPressMapperStrategyWin), mapper.MapperStrategy);
            Assert.AreSame(newBO, person.Organisation, "For Windows the value should be changed.");
        }
예제 #35
0
        public virtual void Test_IsDirty_WhenControlIsEdited_ShouldBeTrue()
        {
            //---------------Set up test pack-------------------
            TestBOEditorControl.GetCustomClassDef();
            GlobalUIRegistry.ControlFactory = GetControlFactory();
            BORegistry.DataAccessor         = new DataAccessorInMemory();
            ContactPersonTestBO   person     = ContactPersonTestBO.CreateSavedContactPerson();
            IBOPanelEditorControl controlWin = CreateEditorControl(person.ClassDef);

            controlWin.BusinessObject = person;
            //---------------Assert Precondition----------------
            Assert.IsTrue(controlWin.BusinessObject.Status.IsValid());
            Assert.IsFalse(controlWin.IsDirty);
            TestUtil.AssertStringNotEmpty(person.Surname, "person.Surname");
            //---------------Execute Test ----------------------
            SetSurnameTextBoxToNull(controlWin);
            bool isDirty = controlWin.IsDirty;

            //---------------Test Result -----------------------
            Assert.IsTrue(isDirty);
            TestUtil.AssertStringEmpty(person.Surname, "person.Surname");
        }
        public void Test_DirtyIfHasMarkForDeleteChildren()
        {
            //---------------Set up test pack-------------------
            OrganisationTestBO organisationTestBO = OrganisationTestBO.CreateSavedOrganisation();
            SingleRelationship <ContactPersonTestBO> relationship = GetCompositionRelationship(organisationTestBO);
            ContactPersonTestBO myBO = new ContactPersonTestBO();

            myBO.Surname      = TestUtil.GetRandomString();
            myBO.FirstName    = TestUtil.GetRandomString();
            myBO.Organisation = organisationTestBO;
            organisationTestBO.Save();

            //---------------Assert Precondition----------------
            Assert.IsFalse(relationship.IsDirty);

            //---------------Execute Test ----------------------
            myBO.MarkForDelete();
            bool isDirty = relationship.IsDirty;

            //---------------Test Result -----------------------
            Assert.IsTrue(isDirty);
        }
예제 #37
0
        public void Test_SetChildNull_NewChild_NonPersistedParent()
        {
            //---------------Set up test pack-------------------
            OrganisationTestBO organisation = OrganisationTestBO.CreateUnsavedOrganisation();
            SingleRelationship <ContactPersonTestBO> relationship = GetAggregationRelationshipContactPerson(organisation, "ContactPerson");

            ContactPersonTestBO contactPerson = ContactPersonTestBO.CreateUnsavedContactPerson();

            contactPerson.Organisation = organisation;
            //---------------Assert Precondition----------------
            Assert.IsFalse(relationship.OwningBOHasForeignKey);
            Assert.IsNotNull(contactPerson.Organisation);
            Assert.IsNotNull(contactPerson.Organisation);
            Assert.IsNotNull(organisation.ContactPerson);
            AssertIsAggregateRelationship(organisation);
            //---------------Execute Test ----------------------
            organisation.ContactPerson = null;
            //---------------Test Result -----------------------
            Assert.IsNull(contactPerson.Organisation);
            Assert.IsNotNull(organisation.OrganisationID);
            Assert.IsNull(organisation.ContactPerson);
        }
예제 #38
0
        public void Test_AddedToObjectManager()
        {
            //---------------Set up test pack-------------------
            ContactPersonTestBO.LoadDefaultClassDef();

            ContactPersonTestBO cp = new ContactPersonTestBO();
            BusinessObjectManager boMan = BusinessObjectManager.Instance;
            //---------------Assert Precondition----------------
            Assert.AreEqual(0, boMan.Count);

            //---------------Execute Test ----------------------
            cp.Surname = TestUtil.CreateRandomString();
            boMan.Add(cp);

            //---------------Test Result -----------------------
            Assert.AreEqual(1, boMan.Count);

            Assert.IsTrue(boMan.Contains(cp));
            Assert.IsTrue(boMan.Contains(cp.ID));
            Assert.IsTrue(boMan.Contains(cp.ID.GetObjectId()));
            Assert.AreSame(cp, boMan[cp.ID.GetObjectId()]);
            Assert.AreSame(cp, boMan[cp.ID]);
        }
        public void Test_UpdateStateAsCommitted()
        {
            //---------------Set up test pack-------------------
            ContactPersonTestBO contactPersonTestBO = new ContactPersonTestBO();
            OrganisationTestBO organisationTestBO = new OrganisationTestBO();

            SingleRelationship<OrganisationTestBO> singleRelationship = contactPersonTestBO.Relationships.GetSingle<OrganisationTestBO>("Organisation");
            singleRelationship.SetRelatedObject(organisationTestBO);

            IRelationship relationship = organisationTestBO.Relationships.GetMultiple<ContactPersonTestBO>("ContactPeople");
            TransactionalSingleRelationship_Added tsr = new TransactionalSingleRelationship_Added(relationship, contactPersonTestBO);
            IBOProp relationshipProp = contactPersonTestBO.Props["OrganisationID"];
            
            //---------------Assert PreConditions--------------- 
            Assert.IsTrue(relationshipProp.IsDirty);
            Assert.AreNotEqual(relationshipProp.Value, relationshipProp.PersistedPropertyValue);
            
            //---------------Execute Test ----------------------
            tsr.UpdateStateAsCommitted();
            
            //---------------Test Result -----------------------
            Assert.IsFalse(relationshipProp.IsDirty);
            Assert.AreEqual(relationshipProp.Value, relationshipProp.PersistedPropertyValue);
        }
 public void Test_SelectButtonWhenClicked_ShouldApplyBusinessObjectChanges(bool enableEditing)
 {
     //---------------Set up test pack-------------------
     GetClassDefs();
     IControlFactory controlFactory = GetControlFactory();
     ExtendedTextBoxWin extendedTextBoxWin = new ExtendedTextBoxWin(controlFactory);
     const string propName = "OrganisationID";
     ExtendedTextBoxMapperSpy mapperSpy = new ExtendedTextBoxMapperSpy(
         extendedTextBoxWin, propName, true, controlFactory);
     mapperSpy.EnableEditing = enableEditing;
     ContactPersonTestBO contactPersonTestBo = new ContactPersonTestBO();
     mapperSpy.BusinessObject = contactPersonTestBo;
     var expectedSelectedBO = new OrganisationTestBO();
     //---------------Assert Precondition----------------
     Assert.AreSame(contactPersonTestBo, mapperSpy.BusinessObject);
     Assert.IsNull(contactPersonTestBo.OrganisationID);
     //---------------Execute Test ----------------------
     mapperSpy.CallSetupPopupForm();
     mapperSpy.SetSelectedBusinessObject(expectedSelectedBO);
     mapperSpy.CallSelectClick();
     //---------------Test Result -----------------------
     Assert.IsNotNull(contactPersonTestBo.OrganisationID);
     Assert.AreSame(expectedSelectedBO, contactPersonTestBo.Organisation);
 }
 public void Test_SetBusinessObject_WhenPropValueNull_ShouldSetTextOnExtendedTextBoxToEmpty()
 {
     //--------------- Set up test pack ------------------
     ExtendedTextBoxMapper mapper = CreateExtendedLookupComboBoxMapper("Surname");
     ContactPersonTestBO businessObjectInfo = new ContactPersonTestBO {Surname = null};
     //--------------- Test Preconditions ----------------
     Assert.IsNull(businessObjectInfo.Surname);
     //--------------- Execute Test ----------------------
     mapper.BusinessObject = businessObjectInfo;
     //--------------- Test Result -----------------------
     Assert.AreSame(businessObjectInfo, mapper.BusinessObject);
     IExtendedTextBox extendedTextBox = (IExtendedTextBox)mapper.Control;
     Assert.AreEqual("", extendedTextBox.Text, "Text on TextBox should be set to EmptyString");
 }
 public void Test_SetBusinessObject_ShouldSetTextOnExtendedTextBox()
 {
     //--------------- Set up test pack ------------------
     ExtendedTextBoxMapper mapper = CreateExtendedLookupComboBoxMapper("Surname");
     ContactPersonTestBO businessObjectInfo = new ContactPersonTestBO();
     var expectedTextBoxValue = TestUtil.GetRandomString();
     businessObjectInfo.Surname = expectedTextBoxValue;
     //--------------- Test Preconditions ----------------
     Assert.IsNotNullOrEmpty(businessObjectInfo.Surname);
     //--------------- Execute Test ----------------------
     mapper.BusinessObject = businessObjectInfo;
     //--------------- Test Result -----------------------
     Assert.AreSame(businessObjectInfo, mapper.BusinessObject);
     IExtendedTextBox extendedTextBox = (IExtendedTextBox)mapper.Control;
     Assert.AreEqual(expectedTextBoxValue, extendedTextBox.Text, "Text should be set on TextBox");
 }
 public void Test_SetBusinessObject_OnInternalLookupComboBoxMapper()
 {
     //--------------- Set up test pack ------------------
     ExtendedTextBoxMapper mapper = CreateExtendedLookupComboBoxMapper("Surname");
     //--------------- Test Preconditions ----------------
     Assert.IsNull(mapper.BusinessObject);
     Assert.IsNull(mapper.BusinessObject);
     ContactPersonTestBO businessObjectInfo = new ContactPersonTestBO();
     //--------------- Execute Test ----------------------
     mapper.BusinessObject = businessObjectInfo;
     //--------------- Test Result -----------------------
     Assert.AreSame(businessObjectInfo, mapper.BusinessObject);
 }
        public void Test_ItemsShowingInComboBox()
        {
            //--------------- Set up test pack ------------------

            ContactPersonTestBO contactPersonTestBO = new ContactPersonTestBO();
            contactPersonTestBO.Surname = TestUtil.GetRandomString();
            contactPersonTestBO.FirstName = TestUtil.GetRandomString();
            OrganisationTestBO.LoadDefaultClassDef();
            OrganisationTestBO.CreateSavedOrganisation();
            OrganisationTestBO.CreateSavedOrganisation();

            IControlFactory controlFactory = GetControlFactory();
            ExtendedTextBoxWin extendedTextBoxWin = new ExtendedTextBoxWin(controlFactory);
            const string propName = "OrganisationID";
            ExtendedTextBoxMapper mapper = new ExtendedTextBoxMapper(
                extendedTextBoxWin, propName, true, controlFactory);
            //--------------- Test Preconditions ----------------
            Assert.IsNull(mapper.BusinessObject);
            Assert.IsNull(mapper.BusinessObject);
          
            //--------------- Execute Test ----------------------
            mapper.BusinessObject = contactPersonTestBO;
            //--------------- Test Result -----------------------
            Assert.AreSame(contactPersonTestBO, mapper.BusinessObject);
            Assert.AreSame(contactPersonTestBO, mapper.BusinessObject);
//            Assert.AreEqual(2, mapper.LookupList.Count);
        }
 private static OrganisationTestBO CreateSavedOrganisation_WithOneValidRemovedContactPerson
     (out ContactPersonTestBO contactPerson, out MultipleRelationship<ContactPersonTestBO> relationship)
 {
     OrganisationTestBO organisationTestBO = OrganisationTestBO.CreateSavedOrganisation();
     BusinessObjectCollection<ContactPersonTestBO> cpCol;
     relationship = GetAssociationRelationship(organisationTestBO, out cpCol);
     contactPerson = ContactPersonTestBO.CreateSavedContactPerson
         (TestUtil.GetRandomString(), TestUtil.GetRandomString());
     cpCol.Add(contactPerson);
     cpCol.SaveAll();
     organisationTestBO.Save();
     cpCol.Remove(contactPerson);
     return organisationTestBO;
 }
 public override void Test_ApplyChangesToBusinessObject_WhenNewItemIsSelected_ShouldUpdateBusinessObjectWithSelectedValue()
 {
     //---------------Set up test pack-------------------
     var cmbox = CreateComboBox();
     BusinessObjectCollection<OrganisationTestBO> boCol;
     var mapper = GetMapperBoColHasOneItem(cmbox, out boCol);
     var relatedBo = boCol[0];
     var newOrganisation = boCol.CreateBusinessObject();
     newOrganisation.Save();
     var person = new ContactPersonTestBO { Organisation = relatedBo };
     mapper.BusinessObject = person;
     //---------------Assert Precondition----------------
     Assert.AreNotSame(newOrganisation, person.Organisation);
     Assert.AreSame(person, mapper.BusinessObject);
     Assert.AreNotSame(newOrganisation, cmbox.SelectedItem, "Selected Item should not be set.");
     //---------------Execute Test ----------------------
     cmbox.SelectedItem = newOrganisation;
     Assert.AreSame(newOrganisation, cmbox.SelectedItem, "Selected Item should be set.");
     mapper.ApplyChangesToBusinessObject();
     //---------------Test Result -----------------------
     Assert.AreSame(newOrganisation, cmbox.SelectedItem);
     Assert.AreSame(newOrganisation, person.Organisation);
 }
        public override void Test_ApplyChangesToBusinessObject_WhenNewItemIsSelected_WhenSet_WhenRelationshipIsLevelsDeep_ShouldUpdateRelatedBusinessObjectWithSelectedValue()
        {
            //---------------Set up test pack-------------------
            ClassDef.ClassDefs.Clear();
            ContactPersonTestBO.LoadClassDefWithOrganisationAndAddressRelationships();
            OrganisationTestBO.LoadDefaultClassDef();
            AddressTestBO.LoadDefaultClassDef();

            const string relationshipName = "ContactPersonTestBO.Organisation";
            var mapper = GetMapperBoColHasOneItem(relationshipName);
            var cmbox = mapper.Control;
            var boCol = (BusinessObjectCollection<OrganisationTestBO>)mapper.BusinessObjectCollection;
            var person = new ContactPersonTestBO { Organisation = boCol[0] };
            var addressTestBO = new AddressTestBO { ContactPersonTestBO = person };
            
            var newOrganisation = new OrganisationTestBO();
            newOrganisation.Save();
            mapper.BusinessObject = addressTestBO;
            //---------------Assert Precondition----------------
            Assert.AreSame(addressTestBO, mapper.BusinessObject);
            Assert.AreSame(person.Organisation, cmbox.SelectedItem);
            Assert.AreNotSame(person.Organisation, newOrganisation);
            //---------------Execute Test ----------------------
            cmbox.SelectedItem = newOrganisation;
            Assert.AreSame(newOrganisation, cmbox.SelectedItem, "Selected Item should be set.");
            mapper.ApplyChangesToBusinessObject();
            //---------------Test Result -----------------------
            Assert.AreSame(newOrganisation, cmbox.SelectedItem);
            Assert.AreSame(newOrganisation, person.Organisation);
        }
예제 #48
0
        public void Test_GetBusinessObjectFromObjectManager_WriteNewProp()
        {
            //---------------Set up test pack-------------------
            FixtureEnvironment.ClearBusinessObjectManager();
            ClassDef.ClassDefs.Clear();
            BORegistry.DataAccessor = new DataAccessorInMemory();
            ContactPersonTestBO.LoadClassDefWithSurnameAsPrimaryKey_WriteNew();
            ContactPersonTestBO contactPersonTestBO = new ContactPersonTestBO();
            string surname = TestUtil.GetRandomString();
            contactPersonTestBO.Surname = surname;
            PropDef propDef = new PropDef("PropName", typeof(string), PropReadWriteRule.ReadWrite, null);
            propDef.LookupList = new BusinessObjectLookupList(typeof(ContactPersonTestBO));
            //---------------Assert Precondition----------------

            //---------------Execute Test ----------------------
            IBusinessObject returnedBO = propDef.GetlookupBusinessObjectFromObjectManager(contactPersonTestBO.Surname);
            //---------------Test Result -----------------------
            Assert.AreSame(contactPersonTestBO, returnedBO);
        }
 public void Test_SetSelectedItem_WhenAnItemIsSelectedAndRelatedBusnessObjectWasNull_ShouldUpdateBusinessObjectWithSelectedValue()
 {
     //---------------Set up test pack-------------------
     IComboBox cmbox = CreateComboBox();
     BusinessObjectCollection<OrganisationTestBO> boCol;
     RelationshipComboBoxMapper mapper = GetMapperBoColHasOneItem(cmbox, out boCol);
     var newOrganisation = boCol.CreateBusinessObject();
     newOrganisation.Save();
     ContactPersonTestBO person = new ContactPersonTestBO();
     mapper.BusinessObject = person;
     //---------------Assert Precondition----------------
     Assert.IsNull(person.Organisation);
     //---------------Execute Test ----------------------
     cmbox.SelectedItem = newOrganisation;
     //---------------Test Result -----------------------
     Assert.AreSame(newOrganisation, cmbox.SelectedItem);
     Assert.AreSame(newOrganisation, person.Organisation);
 }
 public void Test_SelectButtonWhenClicked_ShouldClosePopupForm()
 {
     GetClassDefs();
     IControlFactory controlFactory = GetControlFactory();
     ExtendedTextBoxWin extendedTextBoxWin = new ExtendedTextBoxWin(controlFactory);
     const string propName = "OrganisationID";
     ExtendedTextBoxMapperSpy mapperSpy = new ExtendedTextBoxMapperSpy(
         extendedTextBoxWin, propName, true, controlFactory);
     ContactPersonTestBO contactPersonTestBo = new ContactPersonTestBO();
     mapperSpy.BusinessObject = contactPersonTestBo;
     //---------------Assert Precondition----------------
     Assert.IsFalse(mapperSpy.FormClosed);
     //---------------Execute Test ----------------------
     mapperSpy.CallSetupPopupForm();
     mapperSpy.CallSelectClick();
     //---------------Test Result -----------------------
     Assert.IsTrue(mapperSpy.FormClosed);
 }
예제 #51
0
        public void Test_AddMethod_WithCollection()
        {
            //---------------Set up test pack-------------------
            //ContactPersonTestBO.LoadDefaultClassDef();
            RelatedBusinessObjectCollection<ContactPersonTestBO> cpCol =
                new RelatedBusinessObjectCollection<ContactPersonTestBO>(GetContactPersonRelationship());
            ContactPersonTestBO myBO = new ContactPersonTestBO();
            ContactPersonTestBO myBO2 = new ContactPersonTestBO();
            ContactPersonTestBO myBO3 = new ContactPersonTestBO();
            cpCol.Add(myBO, myBO2, myBO3);

            //-------Assert Preconditions
            Assert.AreEqual(3, cpCol.Count, "Three objects should be in the cpCollection");

            //---------------Execute Test ----------------------
            RelatedBusinessObjectCollection<ContactPersonTestBO> cpColCopied =
                new RelatedBusinessObjectCollection<ContactPersonTestBO>(GetContactPersonRelationship());
            cpColCopied.Add(cpCol);

            //---------------Test Result ----------------------- - Result
            Assert.AreEqual(3, cpColCopied.Count, "Three objects should be in the copied cpCollection");
            Assert.AreEqual(3, cpColCopied.CreatedBusinessObjects.Count);
            Assert.AreEqual(0, cpColCopied.AddedBusinessObjects.Count);
            Assert.AreEqual(myBO, cpColCopied[0], "Added object should be in the copied cpCollection");
            Assert.AreEqual(myBO2, cpColCopied[1], "Added object should be in the copied cpCollection");
            Assert.AreEqual(myBO3, cpColCopied[2], "Added object should be in the copied cpCollection");
        }
예제 #52
0
        public void TestAddMethod_IgnoresAddWhenItemAlreadyExists()
        {
            //---------------Set up test pack-------------------
            RelatedBusinessObjectCollection<ContactPersonTestBO> cpCol =
                new RelatedBusinessObjectCollection<ContactPersonTestBO>(GetContactPersonRelationship());
            ContactPersonTestBO myBO = new ContactPersonTestBO();
            cpCol.Add(myBO);
            util.RegisterForAddedEvent(cpCol);
            //---------------Assert Precondition----------------
            util.AssertOneObjectInCurrentAndCreatedCollection(cpCol);
            Assert.IsFalse(util.AddedEventFired);

            //---------------Execute Test ----------------------
            cpCol.Add(myBO);

            //---------------Test Result -----------------------
            util.AssertOneObjectInCurrentAndCreatedCollection(cpCol);
            Assert.IsFalse(util.AddedEventFired);
        }
 public void Test_SelectButtonWhenClicked_AndContactPersonNotValid_ShouldCloseWithoutError_FixBugBug541()
 {
     GetClassDefs();
     IControlFactory controlFactory = GetControlFactory();
     ExtendedTextBoxWin extendedTextBoxWin = new ExtendedTextBoxWin(controlFactory);
     const string propName = "OrganisationID";
     ExtendedTextBoxMapperSpy mapperSpy = new ExtendedTextBoxMapperSpy(
         extendedTextBoxWin, propName, true, controlFactory);
     ContactPersonTestBO contactPersonTestBo = new ContactPersonTestBO();
     mapperSpy.BusinessObject = contactPersonTestBo;
     mapperSpy.SelectedBO = new OrganisationTestBO();
     //---------------Assert Precondition----------------
     Assert.IsFalse(mapperSpy.FormClosed);
     Assert.IsFalse(contactPersonTestBo.Status.IsValid());
     Assert.IsTrue(mapperSpy.SelectedBO.Status.IsValid());
     Assert.IsNotNull(mapperSpy.SelectedBO);
     //---------------Execute Test ----------------------
     mapperSpy.CallSetupPopupForm();
     mapperSpy.CallSelectClick();
     //---------------Test Result -----------------------
     Assert.IsFalse(contactPersonTestBo.Status.IsValid());
     Assert.IsTrue(mapperSpy.FormClosed);
 }
 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 Test_MustDeregisterForEvents_WhenSetBOToAnotherBO_ThenChangePropValue_ShouldNotUpdateControlValue()
 {
     //---------------Set up test pack-------------------
     IComboBox cmbox = CreateComboBox();
     BusinessObjectCollection<OrganisationTestBO> boCol;
     RelationshipComboBoxMapper mapper = GetMapperBoColHasOneItem(cmbox, out boCol);
     OrganisationTestBO newBO = boCol.CreateBusinessObject();
     OrganisationTestBO organisationTestBO = boCol[0];
     ContactPersonTestBO person = CreateCPWithRelatedOrganisation(organisationTestBO);
     mapper.BusinessObject = person;
     ContactPersonTestBO newCP = new ContactPersonTestBO();
     //---------------Assert precondition----------------
     Assert.AreSame(organisationTestBO, person.Organisation);
     Assert.AreSame(organisationTestBO, cmbox.SelectedItem);
     //---------------Execute Test ----------------------
     mapper.BusinessObject = newCP;
     person.Organisation = newBO;
     //---------------Test Result -----------------------
     Assert.AreSame(newBO, person.Organisation);
     Assert.AreSame(null, newCP.Organisation);
     Assert.AreSame(null, cmbox.SelectedItem, "Value is not set after changing bo relationship");
 }
 private ContactPersonTestBO CreateContactPerson(string surname)
 {
     var cp1 = new ContactPersonTestBO();
     cp1.Surname = surname;
     cp1.FirstName = Guid.NewGuid().ToString("N");
     cp1.Save();
     return cp1;
 }