public void Test_RefreshCollectionRefreshesNonDirtyObjects() { //---------------Set up test pack------------------- BORegistry.DataAccessor = new DataAccessorDB(); OrganisationTestBO.DeleteAllOrganisations(); ContactPersonTestBO.DeleteAllContactPeople(); SetupDefaultContactPersonBO(); var col = new BusinessObjectCollection <ContactPersonTestBO>(); var cp1 = CreateContactPersonTestBO(); FixtureEnvironment.ClearBusinessObjectManager(); CreateContactPersonTestBO(); CreateContactPersonTestBO(); col.LoadAll(); var newSurname = Guid.NewGuid().ToString(); cp1.Surname = newSurname; cp1.Save(); var secondInstanceOfCP1 = col.Find(cp1.ContactPersonID); //--------------------Assert Preconditions---------- AssertNotContains(cp1, col); Assert.AreEqual(newSurname, cp1.Surname); Assert.AreNotSame(secondInstanceOfCP1, cp1); Assert.AreNotEqual(newSurname, secondInstanceOfCP1.Surname); Assert.IsFalse(cp1.Status.IsDirty); //---------------Execute Test ---------------------- col.Refresh(); //---------------Test Result ----------------------- Assert.AreNotSame(secondInstanceOfCP1, cp1); Assert.AreEqual(newSurname, secondInstanceOfCP1.Surname); }
public void Test_FindByGuid() { BusinessObjectCollection<MyBO> col = new BusinessObjectCollection<MyBO>(); MyBO bo1 = new MyBO(); col.Add(bo1); col.Add(new MyBO()); Assert.AreSame(bo1, col.Find(bo1.MyBoID.GetValueOrDefault())); }
public void TestRefreshCollectionRefreshesNonDirtyObjects() { //---------------Set up test pack------------------- BORegistry.DataAccessor = new DataAccessorDB(); ContactPersonTestBO.DeleteAllContactPeople(); SetupDefaultContactPersonBO(); var col = new BusinessObjectCollection<ContactPersonTestBO>(); var cp1 = ContactPersonTestBO.CreateSavedContactPerson(); FixtureEnvironment.ClearBusinessObjectManager(); ContactPersonTestBO.CreateSavedContactPerson(); ContactPersonTestBO.CreateSavedContactPerson(); col.LoadAll(); var newSurname = Guid.NewGuid().ToString(); cp1.Surname = newSurname; cp1.Save(); var secondInstanceOfCP1 = col.Find(cp1.ContactPersonID); //--------------------Assert Preconditions---------- Assert.IsFalse(col.Contains(cp1)); Assert.AreEqual(3, col.Count); Assert.AreEqual(newSurname, cp1.Surname); Assert.AreNotSame(secondInstanceOfCP1, cp1); Assert.AreNotEqual(newSurname, secondInstanceOfCP1.Surname); Assert.IsFalse(cp1.Status.IsDirty); //---------------Execute Test ---------------------- BORegistry.DataAccessor.BusinessObjectLoader.Refresh(col); //---------------Test Result ----------------------- Assert.AreEqual(3, col.Count); Assert.AreNotSame(secondInstanceOfCP1, cp1); Assert.AreEqual(newSurname, secondInstanceOfCP1.Surname); }
public void Test_Find_ShouldReturnObject() { //---------------Set up test pack------------------- ContactPersonTestBO.LoadDefaultClassDef(); // DateTime now = DateTime.Now; const string firstName = "abab"; ContactPersonTestBO cp1 = ContactPersonTestBO.CreateSavedContactPerson("zzzz", firstName); ContactPersonTestBO cp2 = ContactPersonTestBO.CreateSavedContactPerson("aaaa", firstName); // Criteria criteria = new Criteria("DateOfBirth", Criteria.ComparisonOp.Equals, now); const string criteria = "FirstName = '" + firstName + "'"; BusinessObjectCollection<ContactPersonTestBO> col = new BusinessObjectCollection<ContactPersonTestBO>(); col.Load(criteria, "Surname"); col.Sort("Surname", true, true); //---------------Assert Precondition---------------- Assert.AreEqual(2, col.Count); Assert.AreSame(cp2, col[0], "Collection should be in Surname Asc Order"); Assert.AreSame(cp1, col[1], "Collection should be in Surname Asc Order"); //---------------Execute Test ---------------------- ContactPersonTestBO foundCp = col.Find(bo => bo.Surname == "zzzz"); //---------------Test Result ----------------------- Assert.IsNotNull(foundCp); Assert.AreSame(cp1, foundCp); }