Esempio n. 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);
        }
Esempio n. 2
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);
        }
Esempio n. 3
0
        public void TestFindAll_ClassDef_WhenIsSubType()
        {
            //---------------Set up test pack-------------------
            ClassDef.ClassDefs.Clear();
            CircleNoPrimaryKey.GetClassDef().SuperClassDef =
                new SuperClassDef(Shape.GetClassDef(), ORMapping.SingleTableInheritance);
            CircleNoPrimaryKey.GetClassDef().SuperClassDef.Discriminator = "ShapeType_field";
            Shape.GetClassDef().PropDefcol.Add(new PropDef("ShapeType_field", typeof(string), PropReadWriteRule.WriteOnce, "ShapeType_field", null));

            DataStoreInMemory  dataStore          = new DataStoreInMemory();
            CircleNoPrimaryKey circleNoPrimaryKey = new CircleNoPrimaryKey();

            dataStore.Add(circleNoPrimaryKey);
            //---------------Execute Test ----------------------
            IBusinessObjectCollection col = dataStore.FindAll(ClassDef.Get <Shape>(), null);

            //---------------Test Result -----------------------
            Assert.AreEqual(1, col.Count);
            Assert.Contains(circleNoPrimaryKey, col);
            Assert.IsNull(col.SelectQuery.Criteria);
        }
Esempio n. 4
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());
            }
        }