コード例 #1
0
        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);
        }
コード例 #2
0
        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);
        }
コード例 #3
0
        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);
        }
コード例 #4
0
        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);
        }
コード例 #5
0
        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);
        }
コード例 #6
0
        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());
            }
        }