Esempio n. 1
0
        public void Read_ShouldLoadObjectsAsSaved()
        {
            //---------------Set up test pack-------------------
            LoadMyBOClassDefsWithNoUIDefs();
            var savedDataStore       = new DataStoreInMemory();
            var savedBo              = new MyBO();
            var transactionCommitter = new TransactionCommitterInMemory(savedDataStore);

            transactionCommitter.AddBusinessObject(savedBo);
            transactionCommitter.CommitTransaction();
            var writeStream = GetStreamForDataStore(savedDataStore);
            var reader      = new DataStoreInMemoryXmlReader();

            //---------------Assert Precondition----------------
            Assert.AreEqual(1, savedDataStore.Count);
            //---------------Execute Test ----------------------
            var loadedDataStore = reader.Read(writeStream);

            //---------------Test Result -----------------------
            Assert.AreEqual(1, loadedDataStore.Count);
            IBusinessObject loadedBo;
            var             success = loadedDataStore.AllObjects.TryGetValue(savedBo.MyBoID.GetValueOrDefault(), out loadedBo);

            Assert.IsTrue(success);
            Assert.IsNotNull(loadedBo);
            Assert.IsInstanceOf(typeof(MyBO), loadedBo);
            var loadedMyBo = (MyBO)loadedBo;

            Assert.AreNotSame(savedBo, loadedMyBo);

            Assert.IsFalse(loadedBo.Status.IsNew, "Should not be New");
            Assert.IsFalse(loadedBo.Status.IsDeleted, "Should not be Deleted");
            Assert.IsFalse(loadedBo.Status.IsDirty, "Should not be Dirty");
            Assert.IsFalse(loadedBo.Status.IsEditing, "Should not be Editing");
        }
Esempio n. 2
0
        public void Test_GetNextAutoIncrementingNumber_WhenNoNumberGeneratorForClassDef_ShouldCreateNumberGenerator()
        {
            //---------------Set up test pack-------------------
            DataStoreInMemory dataStoreInMemory = new DataStoreInMemory();

            BORegistry.DataAccessor = new DataAccessorInMemory(dataStoreInMemory);
            IClassDef        classDef        = MockRepository.GenerateStub <IClassDef>();
            IClassDef        classDef2       = MockRepository.GenerateStub <IClassDef>();
            INumberGenerator numberGenerator = MockRepository.GenerateStub <INumberGenerator>();

            dataStoreInMemory.AutoIncrementNumberGenerators.Add(classDef, numberGenerator);
            //---------------Assert Precondition----------------
            Assert.AreEqual(1, dataStoreInMemory.AutoIncrementNumberGenerators.Count);
            Assert.AreSame(numberGenerator, dataStoreInMemory.AutoIncrementNumberGenerators[classDef]);
            Assert.IsFalse(dataStoreInMemory.AutoIncrementNumberGenerators.ContainsKey(classDef2));
            //---------------Execute Test ----------------------
            long defaultNumber = dataStoreInMemory.GetNextAutoIncrementingNumber(classDef2);

            //---------------Test Result -----------------------
            Assert.AreEqual(2, dataStoreInMemory.AutoIncrementNumberGenerators.Count);
            numberGenerator.AssertWasNotCalled(t => t.NextNumber());
            Assert.AreEqual(1, defaultNumber);
            INumberGenerator createdNumberGenerator = dataStoreInMemory.AutoIncrementNumberGenerators[classDef2];

            Assert.IsNotNull(createdNumberGenerator);
            TestUtil.AssertIsInstanceOf <NumberGenerator>(createdNumberGenerator);
        }
Esempio n. 3
0
        public void Test_MutableKeyObject_TwoObjectsWithSameFieldNameAndValueAsPrimaryKey()
        {
            //---------------Set up test pack-------------------
            ClassDef.ClassDefs.Clear();
            BOWithIntID_DifferentType.LoadClassDefWithIntID();
            BOWithIntID.LoadClassDefWithIntID();
            DataStoreInMemory dataStore = new DataStoreInMemory();

            BORegistry.DataAccessor = new DataAccessorInMemory(dataStore);
            new Car();
            BOWithIntID boWithIntID = new BOWithIntID();

            boWithIntID.IntID = TestUtil.GetRandomInt();
            boWithIntID.Save();
            BOWithIntID_DifferentType intID_DifferentType = new BOWithIntID_DifferentType();

            intID_DifferentType.IntID = TestUtil.GetRandomInt();
            intID_DifferentType.Save();
            //---------------Assert Precondition----------------
            Assert.AreEqual(2, dataStore.Count);
            //---------------Execute Test ----------------------
//            dataStore.Add(intID_DifferentType);
//            // in the save process the ID is updated to the persisted field values, so the hash of the ID changes
//            // this is why the object is removed and re-added to the BusinessObjectManager (to ensure the dictionary
//            // of objects is hashed on the correct, updated value.
//            intID_DifferentType.Save();
            IBusinessObject returnedBOWitID          = dataStore.AllObjects[boWithIntID.ID.ObjectID];
            IBusinessObject returnedBOWitID_diffType = dataStore.AllObjects[intID_DifferentType.ID.ObjectID];

            //---------------Test Result -----------------------
            Assert.AreSame(boWithIntID, returnedBOWitID);
            Assert.AreSame(intID_DifferentType, returnedBOWitID_diffType);
        }
Esempio n. 4
0
        public void TestMutableCompositeKeyObject_TwoObjectsWithSameFieldNameAndValueAsPrimaryKey()
        {
            //---------------Set up test pack-------------------
            ClassDef.ClassDefs.Clear();
            BOWithIntID_DifferentType.LoadClassDefWithIntID_CompositeKey();
            BOWithIntID.LoadClassDefWithIntID_WithCompositeKey();
            DataStoreInMemory dataStore = new DataStoreInMemory();

            BORegistry.DataAccessor = new DataAccessorInMemory(dataStore);
            new Car();
            BOWithIntID boWithIntID = new BOWithIntID {
                IntID = TestUtil.GetRandomInt()
            };

            boWithIntID.Save();
            BOWithIntID_DifferentType intID_DifferentType = new BOWithIntID_DifferentType();

            intID_DifferentType.IntID = boWithIntID.IntID;
            //---------------Assert Precondition----------------
            //---------------Execute Test ----------------------
            intID_DifferentType.Save();
            //---------------Test Result -----------------------
            Assert.AreEqual(2, dataStore.Count);

            Assert.IsTrue(dataStore.AllObjects.ContainsKey(boWithIntID.ID.ObjectID));
            Assert.IsTrue(dataStore.AllObjects.ContainsKey(intID_DifferentType.ID.ObjectID));

            IBusinessObject returnedBOWitID          = dataStore.AllObjects[boWithIntID.ID.ObjectID];
            IBusinessObject returnedBOWitID_diffType = dataStore.AllObjects[intID_DifferentType.ID.ObjectID];

            Assert.AreSame(boWithIntID, returnedBOWitID);
            Assert.AreSame(intID_DifferentType, returnedBOWitID_diffType);
        }
Esempio n. 5
0
        public void Test_Read()
        {
            //---------------Set up test pack-------------------
            ClassDef.ClassDefs.Clear();
            MyBO.LoadClassDefsNoUIDef();
            DataStoreInMemory savedDataStore = new DataStoreInMemory();

            savedDataStore.Add(new MyBO());
            MemoryStream writeStream             = new MemoryStream();
            DataStoreInMemoryBinaryWriter writer = new DataStoreInMemoryBinaryWriter(writeStream);

            writer.Write(savedDataStore);
            BORegistry.BusinessObjectManager = new BusinessObjectManager();
            DataStoreInMemory loadedDataStore = new DataStoreInMemory();

            writeStream.Seek(0, SeekOrigin.Begin);
            DataStoreInMemoryBinaryReader reader = new DataStoreInMemoryBinaryReader(writeStream);

            //---------------Assert Precondition----------------
            Assert.AreEqual(1, savedDataStore.Count);
            //---------------Execute Test ----------------------
            loadedDataStore.AllObjects = reader.Read();
            //---------------Test Result -----------------------
            Assert.AreEqual(1, loadedDataStore.Count);
        }
Esempio n. 6
0
        public void TestCompositeKeyObject()
        {
            //---------------Set up test pack-------------------
            ClassDef.ClassDefs.Clear();
            //Ther are two datastores so that you can manually add an item to a datastore without
            // the save effecting the datastore you are testing.
            DataStoreInMemory dataStore      = new DataStoreInMemory();
            DataStoreInMemory otherDataStore = new DataStoreInMemory();

            BORegistry.DataAccessor = new DataAccessorInMemory(otherDataStore);
            new Car();
            ContactPersonCompositeKey contactPerson = new ContactPersonCompositeKey();

            contactPerson.Save();
            //---------------Assert Precondition----------------
            Assert.IsFalse(dataStore.AllObjects.ContainsKey(contactPerson.ID.ObjectID));
            //---------------Execute Test ----------------------
            dataStore.Add(contactPerson);
            //In the save process the ID is updated to the persisted field values, so the hash of the ID changes
            // this is why the object is removed and re-added to the BusinessObjectManager (to ensure the dictionary
            // of objects is hashed on the correct, updated value.
            contactPerson.PK1Prop1 = TestUtil.GetRandomString();
            contactPerson.Save();
            //---------------Test Result -----------------------
            Assert.IsTrue(dataStore.AllObjects.ContainsKey(contactPerson.ID.ObjectID));
        }
Esempio n. 7
0
        public void Test_Read_WhenWrittenWithListOfKeyValuePairs_ShouldStillReturnEquivalentConcurrentDictionary()
        {
            //---------------Set up test pack-------------------
            ClassDef.ClassDefs.Clear();
            MyBO.LoadClassDefsNoUIDef();
            var myBo            = new MyBO();
            var businessObjects = new List <KeyValuePair <Guid, IBusinessObject> > {
                new KeyValuePair <Guid, IBusinessObject>(myBo.ID.GetAsGuid(), myBo)
            };
            var writeStream = new MemoryStream();

            new BinaryFormatter().Serialize(writeStream, businessObjects);
            BORegistry.BusinessObjectManager = new BusinessObjectManager();
            var loadedDataStore = new DataStoreInMemory();

            writeStream.Seek(0, SeekOrigin.Begin);
            var reader = new DataStoreInMemoryBinaryReader(writeStream);

            //---------------Assert Precondition----------------
            Assert.AreEqual(1, businessObjects.Count);
            //---------------Execute Test ----------------------
            loadedDataStore.AllObjects = reader.Read();
            //---------------Test Result -----------------------
            Assert.AreEqual(1, loadedDataStore.Count);
        }
Esempio n. 8
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. 9
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);
        }
        public void Read_MultipleObjects()
        {
            //---------------Set up test pack-------------------
            LoadMyBOClassDefsWithNoUIDefs();
            var savedDataStore = new DataStoreInMemory();
            var bo1            = new MyBO();
            var bo2            = new Car();

            savedDataStore.Add(bo1);
            savedDataStore.Add(bo2);
            var stream    = GetStreamForDataStore(savedDataStore);
            var xmlReader = GetXmlReader(stream);
            var reader    = new BusinessObjectXmlReader();

            //---------------Assert Precondition----------------
            Assert.AreEqual(2, savedDataStore.Count);
            //---------------Execute Test ----------------------
            var loadedObjects = reader.Read(xmlReader);
            //---------------Test Result -----------------------
            var businessObjects = loadedObjects.ToList();

            Assert.AreEqual(2, businessObjects.Count);
            Assert.IsNotNull(businessObjects.Find(o => o.ID.Equals(bo1.ID)));
            Assert.IsNotNull(businessObjects.Find(o => o.ID.Equals(bo2.ID)));
        }
        public void Read_ShouldLoadObjectsAsNew()
        {
            //---------------Set up test pack-------------------
            LoadMyBOClassDefsWithNoUIDefs();
            var savedDataStore       = new DataStoreInMemory();
            var savedBo              = new MyBO();
            var transactionCommitter = new TransactionCommitterInMemory(savedDataStore);

            transactionCommitter.AddBusinessObject(savedBo);
            transactionCommitter.CommitTransaction();
            var stream    = GetStreamForDataStore(savedDataStore);
            var xmlReader = GetXmlReader(stream);
            var reader    = new BusinessObjectXmlReader();

            //---------------Assert Precondition----------------
            Assert.AreEqual(1, savedDataStore.Count);
            //---------------Execute Test ----------------------
            var loadedObjects = reader.Read(xmlReader);
            //---------------Test Result -----------------------
            var businessObjects = loadedObjects.ToList();

            Assert.AreEqual(1, businessObjects.Count);
            var loadedMyBo = (MyBO)businessObjects[0];

            Assert.AreNotSame(savedBo, loadedMyBo);
            Assert.IsTrue(loadedMyBo.Status.IsNew, "Should not be New");
            Assert.IsFalse(loadedMyBo.Status.IsDeleted, "Should not be Deleted");
        }
Esempio n. 12
0
        public void Test_GetNextAutoIncrementingNumber_ShouldCreateNumberGenerators_BUGFIX_ShouldBeThreadSafe()
        {
            //---------------Set up test pack-------------------
            var dataStoreInMemory = new DataStoreInMemory();

            BORegistry.DataAccessor = new DataAccessorInMemory(dataStoreInMemory);
            var classDef1 = MockRepository.GenerateStub <IClassDef>();
            var classDef2 = MockRepository.GenerateStub <IClassDef>();

            //---------------Assert Precondition----------------
            Assert.AreEqual(0, dataStoreInMemory.AutoIncrementNumberGenerators.Count);
            Assert.IsFalse(dataStoreInMemory.AutoIncrementNumberGenerators.ContainsKey(classDef1));
            Assert.IsFalse(dataStoreInMemory.AutoIncrementNumberGenerators.ContainsKey(classDef2));
            //---------------Execute Test ----------------------
            var exceptions = new List <Exception>();

            TestUtil.ExecuteInParallelThreads(2, () =>
            {
                try
                {
                    dataStoreInMemory.GetNextAutoIncrementingNumber(classDef1);
                }
                catch (Exception ex)
                {
                    exceptions.Add(ex);
                }
            });
            //---------------Test Result -----------------------
            if (exceptions.Count > 0)
            {
                Assert.Fail(exceptions[0].ToString());
            }
            Assert.AreEqual(1, dataStoreInMemory.AutoIncrementNumberGenerators.Count);
        }
Esempio n. 13
0
        public void Test_SavingToMultipleSources()
        {
            //---------------Set up test pack-------------------
            DataStoreInMemory dataStore1 = new DataStoreInMemory();
            DataStoreInMemory dataStore2 = new DataStoreInMemory();

            DataAccessorInMemory dataAccessorInMemory1 = new DataAccessorInMemory(dataStore1);
            DataAccessorInMemory dataAccessorInMemory2 = new DataAccessorInMemory(dataStore2);

            DataAccessorMultiSource dataAccessor = new DataAccessorMultiSource(new DataAccessorInMemory());

            dataAccessor.AddDataAccessor(typeof(MyBO), dataAccessorInMemory1);
            dataAccessor.AddDataAccessor(typeof(MyRelatedBo), dataAccessorInMemory2);
            MyBO.LoadDefaultClassDef();
            MyRelatedBo.LoadClassDef();
            var bo1 = new MyBO();
            var bo2 = new MyRelatedBo();
            //---------------Execute Test ----------------------
            ITransactionCommitter committer1 = dataAccessor.CreateTransactionCommitter();

            committer1.AddBusinessObject(bo1);
            committer1.CommitTransaction();

            ITransactionCommitter committer2 = dataAccessor.CreateTransactionCommitter();

            committer2.AddBusinessObject(bo2);
            committer2.CommitTransaction();

            //---------------Test Result -----------------------
            Assert.IsNotNull(dataStore1.Find <MyBO>(bo1.ID));
            Assert.IsNotNull(dataStore2.Find <MyRelatedBo>(bo2.ID));
            //---------------Tear down -------------------------
        }
        private MemoryStream GetStreamForDataStore(DataStoreInMemory dataStore)
        {
            var writeStream = new MemoryStream();
            var writer      = new DataStoreInMemoryXmlWriter();

            writer.Write(writeStream, dataStore);
            writeStream.Seek(0, SeekOrigin.Begin);
            return(writeStream);
        }
Esempio n. 15
0
        public void Test_Construct()
        {
            //---------------Set up test pack-------------------
            DataStoreInMemory dataStore = new DataStoreInMemory();
            //---------------Assert PreConditions---------------
            //---------------Execute Test ----------------------
            DataStoreInMemoryBinaryWriter writer = new DataStoreInMemoryBinaryWriter(new MemoryStream());
            //---------------Test Result -----------------------

            //---------------Tear Down -------------------------
        }
Esempio n. 16
0
        public void Test_AutoIncrementNumberGenerators_IsNotNull()
        {
            //---------------Set up test pack-------------------

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

            //---------------Execute Test ----------------------
            DataStoreInMemory dataStoreInMemory = new DataStoreInMemory();

            //---------------Test Result -----------------------
            Assert.IsNotNull(dataStoreInMemory.AutoIncrementNumberGenerators);
        }
        private MemoryStream GetStreamForBusinessObject(MyBO businessObject)
        {
            var savedDataStore = new DataStoreInMemory();

            savedDataStore.Add(businessObject);
            var writeStream = new MemoryStream();
            var writer      = new DataStoreInMemoryXmlWriter();

            writer.Write(writeStream, savedDataStore);
            writeStream.Seek(0, SeekOrigin.Begin);
            return(writeStream);
        }
Esempio n. 18
0
        public void TestDataStoreConstructor()
        {
            //---------------Set up test pack-------------------

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

            //---------------Execute Test ----------------------
            DataStoreInMemory dataStore = new DataStoreInMemory();

            //---------------Test Result -----------------------
            Assert.AreEqual(0, dataStore.Count);
            //---------------Tear Down -------------------------
        }
        public void TestDataStoreAdd()
        {
            //---------------Set up test pack-------------------
            DataStoreInMemory dataStore = new DataStoreInMemory();

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

            //---------------Execute Test ----------------------
            dataStore.Add(new ContactPerson());
            //---------------Test Result -----------------------
            Assert.AreEqual(1, dataStore.Count);
            //---------------Tear Down -------------------------
        }
Esempio n. 20
0
        public void TestDataStoreRemove()
        {
            //---------------Set up test pack-------------------
            DataStoreInMemory dataStore = new DataStoreInMemory();

            ContactPersonTestBO.LoadDefaultClassDef();
            ContactPersonTestBO cp = new ContactPersonTestBO();

            dataStore.Add(cp);
            //---------------Execute Test ----------------------
            dataStore.Remove(cp);
            //---------------Test Result -----------------------
            Assert.AreEqual(0, dataStore.Count);
            //---------------Tear Down -------------------------
        }
Esempio n. 21
0
        public void Test_ClearAll()
        {
            //---------------Set up test pack-------------------
            DataStoreInMemory dataStore = new DataStoreInMemory();

            ContactPersonTestBO.LoadDefaultClassDef();
            dataStore.Add(new ContactPersonTestBO());
            //---------------Assert Precondition----------------
            Assert.AreEqual(1, dataStore.Count);

            //---------------Execute Test ----------------------
            dataStore.ClearAllBusinessObjects();

            //---------------Test Result -----------------------
            Assert.AreEqual(0, dataStore.Count);
        }
Esempio n. 22
0
        public void Test_Write()
        {
            //---------------Set up test pack-------------------
            DataStoreInMemory dataStore = new DataStoreInMemory();

            dataStore.Add(new Car());
            MemoryStream stream = new MemoryStream();
            DataStoreInMemoryBinaryWriter writer = new DataStoreInMemoryBinaryWriter(stream);

            //---------------Assert Precondition----------------
            Assert.AreEqual(1, dataStore.Count);
            Assert.AreEqual(0, stream.Length);
            //---------------Execute Test ----------------------
            writer.Write(dataStore);
            //---------------Test Result -----------------------
            Assert.AreNotEqual(0, stream.Length);
        }
        public void Write()
        {
            //---------------Set up test pack-------------------
            var dataStore = new DataStoreInMemory();

            dataStore.Add(new Car());
            var stream = new MemoryStream();
            var writer = new DataStoreInMemoryXmlWriter();

            //---------------Assert Precondition----------------
            Assert.AreEqual(1, dataStore.Count);
            Assert.AreEqual(0, stream.Length);
            //---------------Execute Test ----------------------
            writer.Write(stream, dataStore);
            //---------------Test Result -----------------------
            Assert.AreNotEqual(0, stream.Length);
        }
        public void Write_ToString()
        {
            //---------------Set up test pack-------------------
            var dataStore = new DataStoreInMemory();

            dataStore.Add(new Car());
            var writer = new DataStoreInMemoryXmlWriter();
            var sb     = new StringBuilder();

            //---------------Assert Precondition----------------
            Assert.AreEqual(1, dataStore.Count);
            Assert.AreEqual(0, sb.Length);
            //---------------Execute Test ----------------------
            writer.Write(sb, dataStore);
            //---------------Test Result -----------------------
            Assert.AreNotEqual(0, sb.Length);
        }
        public void TestGetBusinessObjectWhenNotExists()
        {
            //---------------Set up test pack-------------------
            ClassDef.ClassDefs.Clear();
            DataStoreInMemory dataStore = new DataStoreInMemory();

            ContactPersonTestBO.LoadDefaultClassDef();
            BusinessObjectLoaderInMemory loader = new BusinessObjectLoaderInMemory(dataStore);
            //--------------Assert PreConditions----------------

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

            //---------------Test Result -----------------------
            Assert.IsNull(loadedCP);
            //---------------Tear Down -------------------------
        }
Esempio n. 26
0
        public void Test_Write_WithConcurrentDictionary()
        {
            //---------------Set up test pack-------------------
            var dataStore = new DataStoreInMemory();

            dataStore.Add(new Car());
            var businessObjects = dataStore.AllObjects;
            var stream          = new MemoryStream();
            var writer          = new DataStoreInMemoryBinaryWriter(stream);

            //---------------Assert Precondition----------------
            Assert.AreEqual(1, dataStore.Count);
            Assert.AreEqual(0, stream.Length);
            //---------------Execute Test ----------------------
            writer.Write(businessObjects);
            //---------------Test Result -----------------------
            Assert.AreNotEqual(0, stream.Length);
        }
Esempio n. 27
0
        public void TestFind_PrimaryKey()
        {
            //---------------Set up test pack-------------------
            ClassDef.ClassDefs.Clear();
            ContactPersonTestBO.LoadDefaultClassDef();
            ContactPersonTestBO cp = new ContactPersonTestBO();

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

            dataStore.Add(cp);

            //---------------Execute Test ----------------------
            ContactPersonTestBO loadedCP = dataStore.Find <ContactPersonTestBO>(cp.ID);

            //---------------Test Result -----------------------
            Assert.AreSame(cp.ID, loadedCP.ID);
            //---------------Tear Down -------------------------
        }
Esempio n. 28
0
        public void Test_GetNextAutoIncrementingNumber_ShouldUseNumberGenerator()
        {
            //---------------Set up test pack-------------------
            DataStoreInMemory dataStoreInMemory = new DataStoreInMemory();
            IClassDef         classDef          = MockRepository.GenerateStub <IClassDef>();
            INumberGenerator  numberGenerator   = MockRepository.GenerateStub <INumberGenerator>();
            long numberFromNumberGenerator      = TestUtil.GetRandomInt();

            numberGenerator.Stub(t => t.NextNumber()).Return(numberFromNumberGenerator);
            dataStoreInMemory.AutoIncrementNumberGenerators.Add(classDef, numberGenerator);
            //---------------Assert Precondition----------------
            Assert.AreEqual(1, dataStoreInMemory.AutoIncrementNumberGenerators.Count);
            Assert.AreSame(numberGenerator, dataStoreInMemory.AutoIncrementNumberGenerators[classDef]);
            //---------------Execute Test ----------------------
            long autoIncrementingNumber = dataStoreInMemory.GetNextAutoIncrementingNumber(classDef);

            //---------------Test Result -----------------------
            Assert.AreEqual(numberFromNumberGenerator, autoIncrementingNumber);
            numberGenerator.AssertWasCalled(t => t.NextNumber());
        }
Esempio n. 29
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);
        }
        public void Write_WithXmlWriterSettings()
        {
            //---------------Set up test pack-------------------
            var dataStore = new DataStoreInMemory();

            dataStore.Add(new Car());
            var stream            = new MemoryStream();
            var xmlWriterSettings = new XmlWriterSettings();

            xmlWriterSettings.ConformanceLevel    = ConformanceLevel.Auto;
            xmlWriterSettings.NewLineOnAttributes = true;
            var writer = new DataStoreInMemoryXmlWriter(xmlWriterSettings);

            //---------------Assert Precondition----------------
            Assert.AreEqual(1, dataStore.Count);
            Assert.AreEqual(0, stream.Length);
            //---------------Execute Test ----------------------
            writer.Write(stream, dataStore);
            //---------------Test Result -----------------------
            Assert.AreNotEqual(0, stream.Length);
        }