public void TestFindAll_UsingClassDef() { //---------------Set up test pack------------------- BORegistry.DataAccessor = new DataAccessorInMemory(new DataStoreInMemory()); ClassDef.ClassDefs.Clear(); ContactPersonTestBO.LoadDefaultClassDef(); OrganisationTestBO.LoadDefaultClassDef(); DataStoreInMemory dataStore = new DataStoreInMemory(); DateTime now = DateTime.Now; ContactPersonTestBO cp1 = new ContactPersonTestBO(); cp1.DateOfBirth = now; cp1.Surname = TestUtil.GetRandomString(); cp1.Save(); dataStore.Add(cp1); ContactPersonTestBO cp2 = new ContactPersonTestBO(); cp2.DateOfBirth = now; cp2.Surname = TestUtil.GetRandomString(); cp2.Save(); dataStore.Add(cp2); Criteria criteria = new Criteria("DateOfBirth", Criteria.ComparisonOp.Equals, now); dataStore.Add(OrganisationTestBO.CreateSavedOrganisation()); //---------------Execute Test ---------------------- IBusinessObjectCollection col = dataStore.FindAll(ClassDef.Get <ContactPersonTestBO>(), criteria); //---------------Test Result ----------------------- Assert.AreEqual(2, col.Count); Assert.Contains(cp1, col); Assert.Contains(cp2, col); }
public void TestFind_UsingGuidCriteriaString_Typed() { //---------------Set up test pack------------------- BORegistry.DataAccessor = new DataAccessorInMemory(new DataStoreInMemory()); ClassDef.ClassDefs.Clear(); ContactPersonTestBO.LoadDefaultClassDef_WOrganisationID(); OrganisationTestBO.LoadDefaultClassDef(); ContactPersonTestBO cp = new ContactPersonTestBO { Surname = Guid.NewGuid().ToString("N") }; cp.OrganisationID = OrganisationTestBO.CreateSavedOrganisation().OrganisationID; cp.Save(); DataStoreInMemory dataStore = new DataStoreInMemory(); dataStore.Add(cp); Criteria criteria = CriteriaParser.CreateCriteria("OrganisationID = " + cp.OrganisationID); //---------------Assert Precondtions--------------- Assert.IsNotNull(cp.OrganisationID); //---------------Execute Test ---------------------- ContactPersonTestBO loadedCP = dataStore.Find <ContactPersonTestBO>(criteria); //---------------Test Result ----------------------- Assert.IsNotNull(loadedCP); Assert.AreSame(cp.ID, loadedCP.ID); }
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 SetupTest() { ClassDef.ClassDefs.Clear(); GlobalRegistry.UIExceptionNotifier = new RethrowingExceptionNotifier(); BORegistry.DataAccessor = new DataAccessorInMemory(); ContactPersonTestBO.LoadClassDefOrganisationTestBORelationship_MultipleReverse(); OrganisationTestBO.LoadDefaultClassDef(); }
public void TestFixtureSetup() { ClassDef.ClassDefs.Clear(); GlobalRegistry.UIExceptionNotifier = new RethrowingExceptionNotifier(); BORegistry.DataAccessor = new DataAccessorInMemory(); BORegistry.BusinessObjectManager = new BusinessObjectManagerNull(); AddressTestBO.LoadDefaultClassDef(); ContactPersonTestBO.LoadClassDefOrganisationTestBORelationship_MultipleReverse(); OrganisationTestBO.LoadDefaultClassDef(); }
public void Test_EditDataTable_WhenMultipleLevelProp_ShouldEditRelatedBO() { //---------------Set up test pack------------------- RecordingExceptionNotifier recordingExceptionNotifier = new RecordingExceptionNotifier(); GlobalRegistry.UIExceptionNotifier = recordingExceptionNotifier; AddressTestBO.LoadDefaultClassDef(); ContactPersonTestBO.LoadClassDefWithOrganisationAndAddressRelationships(); OrganisationTestBO.LoadDefaultClassDef(); BusinessObjectCollection <AddressTestBO> addresses = new BusinessObjectCollection <AddressTestBO>(); addresses.Add(new AddressTestBO { ContactPersonTestBO = new ContactPersonTestBO() }); addresses.Add(new AddressTestBO { ContactPersonTestBO = new ContactPersonTestBO() }); addresses.Add(new AddressTestBO { ContactPersonTestBO = new ContactPersonTestBO() }); OrganisationTestBO organisation = new OrganisationTestBO(); UIGrid uiGrid = new UIGrid(); const string propertyName = "ContactPersonTestBO.OrganisationID"; uiGrid.Add(new UIGridColumn("Contact Organisation", propertyName, typeof(DataGridViewTextBoxColumn), true, 100, PropAlignment.left, new Hashtable())); IDataSetProvider dataSetProvider = CreateDataSetProvider(addresses); DataTable table = dataSetProvider.GetDataTable(uiGrid); //---------------Assert Precondition---------------- Assert.IsTrue(dataSetProvider is EditableDataSetProvider); Assert.AreEqual(3, table.Rows.Count); Assert.AreEqual(DBNull.Value, table.Rows[0][propertyName]); //---------------Execute Test ---------------------- table.Rows[0][propertyName] = organisation.OrganisationID; //---------------Test Result ----------------------- Assert.AreEqual(organisation.OrganisationID, table.Rows[0][propertyName]); Assert.AreEqual(organisation.OrganisationID, addresses[0].ContactPersonTestBO.OrganisationID); recordingExceptionNotifier.RethrowRecordedException(); }
public void Test_UpdateRelatedObject_ShouldRaiseEvent() { //---------------Set up test pack------------------- ClassDef.ClassDefs.Clear(); ContactPersonTestBO.LoadClassDefOrganisationTestBORelationship_MultipleReverse(); OrganisationTestBO.LoadDefaultClassDef(); OrganisationTestBO organisationTestBO = OrganisationTestBO.CreateSavedOrganisation(); ContactPersonTestBO contactPersonTestBO = ContactPersonTestBO.CreateUnsavedContactPerson(); ISingleRelationship relationship = (ISingleRelationship)contactPersonTestBO.Relationships["Organisation"]; bool eventCalled = false; relationship.RelKey.RelatedPropValueChanged += delegate { eventCalled = true; }; //---------------Assert Precondition---------------- Assert.IsTrue(contactPersonTestBO.Relationships.GetSingle <OrganisationTestBO>("Organisation").OwningBOHasForeignKey); Assert.IsFalse(eventCalled); //---------------Execute Test ---------------------- contactPersonTestBO.Organisation = organisationTestBO; //---------------Test Result ----------------------- Assert.IsTrue(eventCalled); }
public void Test_EditDataTable_WhenVirtualProp_ShouldEditRelatedVirtualProp() { //---------------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>(); contactPersonTestBOS.Add(new ContactPersonTestBO(), new ContactPersonTestBO(), new 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(3, table.Rows.Count); Assert.AreEqual(DBNull.Value, table.Rows[0][propertyName]); Assert.AreEqual(null, contactPersonTestBOS[0].Organisation); //---------------Execute Test ---------------------- table.Rows[0][propertyName] = organisation; //---------------Test Result ----------------------- Assert.AreSame(organisation, table.Rows[0][propertyName]); Assert.AreSame(organisation, contactPersonTestBOS[0].Organisation); recordingExceptionNotifier.RethrowRecordedException(); }
public void TestFindAll_NullCriteria() { //---------------Set up test pack------------------- ClassDef.ClassDefs.Clear(); ContactPersonTestBO.LoadDefaultClassDef(); OrganisationTestBO.LoadDefaultClassDef(); DataStoreInMemory dataStore = new DataStoreInMemory(); DateTime now = DateTime.Now; ContactPersonTestBO cp1 = new ContactPersonTestBO(); cp1.DateOfBirth = now; dataStore.Add(cp1); dataStore.Add(OrganisationTestBO.CreateSavedOrganisation()); //---------------Execute Test ---------------------- BusinessObjectCollection <ContactPersonTestBO> col = dataStore.FindAll <ContactPersonTestBO>(null); //---------------Test Result ----------------------- Assert.AreEqual(1, col.Count); Assert.Contains(cp1, col); Assert.IsNull(col.SelectQuery.Criteria); }
public void Test_UpdatePropValue_ShouldRaiseEvent() { //---------------Set up test pack------------------- ClassDef.ClassDefs.Clear(); ContactPersonTestBO.LoadClassDefOrganisationTestBORelationship_MultipleReverse(); OrganisationTestBO.LoadDefaultClassDef(); ContactPersonTestBO contactPersonTestBO = ContactPersonTestBO.CreateUnsavedContactPerson(); ISingleRelationship relationship = (ISingleRelationship)contactPersonTestBO.Relationships["Organisation"]; bool eventCalled = false; IRelKey key = relationship.RelKey; IRelProp relProp = key[0]; IBOProp prop = relProp.BOProp; relProp.PropValueUpdated += delegate { eventCalled = true; }; //---------------Assert Precondition---------------- Assert.IsTrue(contactPersonTestBO.Relationships.GetSingle <OrganisationTestBO>("Organisation").OwningBOHasForeignKey); Assert.IsFalse(eventCalled); //---------------Execute Test ---------------------- prop.Value = Guid.NewGuid(); //---------------Test Result ----------------------- Assert.IsTrue(eventCalled); }
public void TestFind_UsingGuidCriteria_Untyped() { //---------------Set up test pack------------------- BORegistry.DataAccessor = new DataAccessorInMemory(new DataStoreInMemory()); ClassDef.ClassDefs.Clear(); ContactPersonTestBO.LoadDefaultClassDef_WOrganisationID(); OrganisationTestBO.LoadDefaultClassDef(); ContactPersonTestBO cp = new ContactPersonTestBO { Surname = Guid.NewGuid().ToString("N") }; cp.OrganisationID = OrganisationTestBO.CreateSavedOrganisation().OrganisationID; cp.Save(); DataStoreInMemory dataStore = new DataStoreInMemory(); dataStore.Add(cp); Criteria criteria = new Criteria("OrganisationID", Criteria.ComparisonOp.Equals, cp.OrganisationID); //---------------Execute Test ---------------------- ContactPersonTestBO loadedCP = (ContactPersonTestBO)dataStore.Find(typeof(ContactPersonTestBO), criteria); //---------------Test Result ----------------------- Assert.AreSame(cp.ID, loadedCP.ID); }
public void TestFindAll_UsingClassDef_BUGFIX_ShouldBeThreadsafe(string aaa) { //---------------Set up test pack------------------- BORegistry.DataAccessor = new DataAccessorInMemory(new DataStoreInMemory()); ClassDef.ClassDefs.Clear(); ContactPersonTestBO.LoadDefaultClassDef(); OrganisationTestBO.LoadDefaultClassDef(); var dataStore = new DataStoreInMemory(); var now = DateTime.Now; var cp1 = new ContactPersonTestBO { DateOfBirth = now, Surname = TestUtil.GetRandomString() }; cp1.Save(); dataStore.Add(cp1); var cp2 = new ContactPersonTestBO { DateOfBirth = now, Surname = TestUtil.GetRandomString() }; cp2.Save(); dataStore.Add(cp2); //var criteria = MockRepository.GenerateStub<Criteria>("DateOfBirth", Criteria.ComparisonOp.Equals, now); //criteria.Stub(o => o.IsMatch(Arg<IBusinessObject>.Is.Anything)).WhenCalled(invocation => //{ // Thread.Sleep(100); // invocation.ReturnValue = true; //}).Return(true); var criteria = new Criteria("DateOfBirth", Criteria.ComparisonOp.Equals, now); for (int i1 = 0; i1 < 1000; i1++) { dataStore.Add(OrganisationTestBO.CreateSavedOrganisation()); } var threads = new List <Thread>(); threads.Add(new Thread(() => { for (int i1 = 0; i1 < 1000; i1++) { dataStore.Add(OrganisationTestBO.CreateSavedOrganisation()); } })); var exceptions = new List <Exception>(); threads.Add(new Thread(() => { try { for (int i = 0; i < 10; i++) { dataStore.FindAll(ClassDef.Get <ContactPersonTestBO>(), criteria); } } catch (Exception ex) { exceptions.Add(ex); } })); //---------------Execute Test ---------------------- threads.AsParallel().ForAll(thread => thread.Start()); threads.AsParallel().ForAll(thread => thread.Join()); //Assert.DoesNotThrow(() => //{ //var col = dataStore.FindAll(ClassDef.Get<ContactPersonTestBO>(), criteria); //thread.Join(); //}); //---------------Test Result ----------------------- if (exceptions.Count > 0) { Assert.Fail("Has an Exception: " + exceptions[0].ToString()); } }