This class reads an xml stream and loads the objects in it into a DataStoreInMemory The class assumes you are loading afresh. Before doing the load, we recommend that you clear your BusinessObjectManager too so that you only have one instance of each object.
        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");
        }
 public void Test_Construct()
 {
     //---------------Set up test pack-------------------
     //---------------Assert PreConditions---------------            
     //---------------Execute Test ----------------------
     var reader = new DataStoreInMemoryXmlReader();
     //---------------Test Result -----------------------
     
     //---------------Tear Down -------------------------          
 }
 public void Read_ShouldSet_ReadResult()
 {
     //---------------Set up test pack-------------------
     LoadMyBOClassDefsWithNoUIDefs();
     var writeStream = GetStreamForBusinessObject(new MyBO());
     var reader = new DataStoreInMemoryXmlReader();
     //---------------Execute Test ----------------------
     var loadedDataStore = reader.Read(writeStream, new BusinessObjectXmlReaderWithError());
     //---------------Test Result -----------------------
     Assert.AreEqual(1, loadedDataStore.Count);
     Assert.IsNotNull(reader.ReadResult);
     Assert.IsFalse(reader.ReadResult.Successful);
 }
        public void Read_FromString()
        {
            //---------------Set up test pack-------------------
            var dataStore = new DataStoreInMemory();
            dataStore.Add(new Car());
            var writer = new DataStoreInMemoryXmlWriter();
            var sb = new StringBuilder();
            writer.Write(sb, dataStore);
            var xml = sb.ToString();

            var reader = new DataStoreInMemoryXmlReader();
            //---------------Assert Precondition----------------
            Assert.AreEqual(1, dataStore.Count);
            Assert.Greater(xml.Length, 100);
            //---------------Execute Test ----------------------
            var businessObjects =  reader.Read(xml);
            //---------------Test Result -----------------------
            Assert.AreEqual(1, businessObjects.Count);
        }
 public void Read_WhenCalledWithPropertyReadExceptions_ShouldSetReadResultSuccessfulFalseAndMessage_Bug1336()
 {
     //---------------Set up test pack-------------------
     LoadMyBOClassDefsWithNoUIDefs();
     var bo = new MyBO {TestProp = "characters"};
     var stream = GetStreamForBusinessObject(bo);
     var reader = new DataStoreInMemoryXmlReader();
     var boReader = new BusinessObjectXmlReaderWithError();
     //---------------Assert Precondition----------------
     Assert.IsNull(reader.ReadResult);
     //---------------Execute Test ----------------------
     var businessObjects = reader.Read(stream, boReader);
     //---------------Test Result -----------------------
     Assert.AreEqual(1, businessObjects.Count);
     Assert.IsNotNull(reader.ReadResult);
     Assert.IsFalse(reader.ReadResult.Successful);
     StringAssert.Contains("An error occured when attempting to set property 'MyBO.MyBoID'.", reader.ReadResult.Message);
     StringAssert.Contains("An error occured when attempting to set property 'MyBO.TestProp'.", reader.ReadResult.Message);
     StringAssert.Contains("An error occured when attempting to set property 'MyBO.TestProp2'.", reader.ReadResult.Message);
 }
        public void Acceptance_Read_WhenCalledWithPropertyReadExceptions_ShouldSetReadResultSuccessfulFalseAndMessage_Bug1336()
        {
            //---------------Set up test pack-------------------
            var classDef = LoadMyBOClassDefsWithNoUIDefs();
            var bo = new MyBO {TestProp = "characters"};
            var propDef = classDef.PropDefcol["TestProp"];
            classDef.PropDefcol.Remove(propDef);
            var propDefWithDifferentType = propDef.Clone();

            // Change type to force property read exception
            propDefWithDifferentType.PropertyType = typeof(int);
            classDef.PropDefcol.Add(propDefWithDifferentType);
            var toStream = GetStreamForBusinessObject(bo);
            var reader = new DataStoreInMemoryXmlReader();
            //---------------Assert Precondition----------------
            Assert.IsNull(reader.ReadResult);
            //---------------Execute Test ----------------------
            var businessObjects = reader.Read(toStream);
            //---------------Test Result -----------------------
            Assert.AreEqual(1, businessObjects.Count);
            Assert.IsNotNull(reader.ReadResult);
            Assert.IsFalse(reader.ReadResult.Successful);
            StringAssert.Contains("An error occured when attempting to set property 'MyBO.TestProp'.", reader.ReadResult.Message);
        }
 public void Read_WhenNoPropertyReadExceptions_ShouldSetReadResultSuccessfulTrue_Bug1336()
 {
     //---------------Set up test pack-------------------
     LoadMyBOClassDefsWithNoUIDefs();
     var toStream = GetStreamForBusinessObject(new MyBO());
     var reader = new DataStoreInMemoryXmlReader();
     //---------------Assert Precondition----------------
     //---------------Execute Test ----------------------
     reader.Read(toStream);
     //---------------Test Result -----------------------
     Assert.IsNotNull(reader.ReadResult);
     Assert.IsTrue(reader.ReadResult.Successful);
 }