Converts the content of an XmlReader into a set of IBusinessObject. This is the default implementation, and converts xml written by the BusinessObjectXmlWriter into business objects. It's easiest to use this class via ObjectTreeXmlReader or DataStoreInMemoryXmlReader. However, if you need to change how objects are read/written from xml, implement your own IBusinessObjectXmlReader and IBusinessObjectXmlWriter and use them with those classes.
Inheritance: IBusinessObjectXmlReader
 public void Construct()
 {
     //---------------Set up test pack-------------------
     //---------------Assert PreConditions---------------            
     //---------------Execute Test ----------------------
     var reader = new BusinessObjectXmlReader();
     //---------------Test Result -----------------------
     
     //---------------Tear Down -------------------------          
 }
 public void Read()
 {
     //---------------Set up test pack-------------------
     LoadMyBOClassDefsWithNoUIDefs();
     var stream = GetStreamForBusinessObject(new MyBO());
     var xmlReader = GetXmlReader(stream);
     var reader = new BusinessObjectXmlReader();
     //---------------Execute Test ----------------------
     var loadedObjects = reader.Read(xmlReader);
     //---------------Test Result -----------------------
     Assert.AreEqual(1, loadedObjects.Count());
 }
 public void Read_WhenPropHasBeenRemoved_ShouldReadWithoutProp()
 {
     //---------------Set up test pack-------------------
     IClassDef def = LoadMyBOClassDefsWithNoUIDefs();
     var stream = GetStreamForBusinessObject(new MyBO());
     var xmlReader = GetXmlReader(stream);
     var reader = new BusinessObjectXmlReader();
     const string propertyName = "TestProp2";
     //---------------Execute Test ----------------------
     def.PropDefcol.Remove(def.PropDefcol[propertyName]);
     var loadedObjects = reader.Read(xmlReader);
     //---------------Test Result -----------------------
     Assert.AreEqual(1, loadedObjects.Count());
     Assert.AreEqual(1, reader.PropertyReadExceptions.Count());
     StringAssert.Contains(propertyName, reader.PropertyReadExceptions.First());
     StringAssert.Contains("does not exist in the prop collection", reader.PropertyReadExceptions.First());
 }
 /// <summary>
 /// Reads from an XmlReader. Uses a default <see cref="IBusinessObjectXmlReader"/> to 
 /// create the objects from the xml.
 /// Any errors that occur when setting properties on objects will be added to the ReadResult property.
 /// Once this method returns, check the Successful flag of the ReadResult to see if there are errors, and
 /// check the Message flag to see what the errors were.
 /// </summary>
 /// <param name="xmlReader">The reader to use</param>
 /// <returns>A <see cref="DataStoreInMemory"/> containing all objects that were in the xml</returns>
 public DataStoreInMemory Read(XmlReader xmlReader)
 {
     var boReader = new BusinessObjectXmlReader();
     return Read(xmlReader, boReader);
 }
Exemplo n.º 5
0
        /// <summary>
        /// Reads from an XmlReader. Uses a default <see cref="IBusinessObjectXmlReader"/> to
        /// create the objects from the xml.
        /// Any errors that occur when setting properties on objects will be added to the ReadResult property.
        /// Once this method returns, check the Successful flag of the ReadResult to see if there are errors, and
        /// check the Message flag to see what the errors were.
        /// </summary>
        /// <param name="xmlReader">The reader to use</param>
        /// <returns>A <see cref="DataStoreInMemory"/> containing all objects that were in the xml</returns>
        public IEnumerable <IBusinessObject> Read(XmlReader xmlReader)
        {
            var boReader = new BusinessObjectXmlReader();

            return(Read(xmlReader, boReader));
        }
Exemplo n.º 6
0
 /// <summary>
 /// Reads from an XmlReader. Uses a default <see cref="IBusinessObjectXmlReader"/> to 
 /// create the objects from the xml.
 /// Any errors that occur when setting properties on objects will be added to the ReadResult property.
 /// Once this method returns, check the Successful flag of the ReadResult to see if there are errors, and
 /// check the Message flag to see what the errors were.
 /// </summary>
 /// <param name="xmlReader">The reader to use</param>
 /// <returns>A <see cref="DataStoreInMemory"/> containing all objects that were in the xml</returns>
 public IEnumerable<IBusinessObject> Read(XmlReader xmlReader)
 {
     var boReader = new BusinessObjectXmlReader();
     return Read(xmlReader, boReader);
 }
 public void Read_ShouldLoadPropertiesCorrectly()
 {
     //---------------Set up test pack-------------------
     LoadMyBOClassDefsWithNoUIDefs();
     var savedBo = new MyBO {TestProp = TestUtil.GetRandomString(), TestProp2 = TestUtil.GetRandomString()};
     var savedDataStore = new DataStoreInMemory();
     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 myBos = businessObjects.Select(o => (MyBO)o);
     var matchedBos = myBos.Where(bo => bo.TestProp.Equals(savedBo.TestProp));
      Assert.AreEqual(1, matchedBos.Count());
     var loadedMyBo = matchedBos.First();
     Assert.AreNotSame(savedBo, loadedMyBo);
     Assert.AreEqual(savedBo.MyBoID, loadedMyBo.MyBoID);
     Assert.AreEqual(savedBo.Props["MyBoID"].PersistedPropertyValue, loadedMyBo.Props["MyBoID"].PersistedPropertyValue);
     Assert.AreEqual(savedBo.TestProp, loadedMyBo.TestProp);
     Assert.AreEqual(savedBo.Props["TestProp"].PersistedPropertyValue, loadedMyBo.Props["TestProp"].PersistedPropertyValue);
     Assert.AreEqual(savedBo.TestProp2, loadedMyBo.TestProp2);
     Assert.AreEqual(savedBo.Props["TestProp2"].PersistedPropertyValue, loadedMyBo.Props["TestProp2"].PersistedPropertyValue);
 }
 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");
 }
 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)));
 }
Exemplo n.º 10
0
        /// <summary>
        /// Reads from an XmlReader. Uses a default <see cref="IBusinessObjectXmlReader"/> to
        /// create the objects from the xml.
        /// Any errors that occur when setting properties on objects will be added to the ReadResult property.
        /// Once this method returns, check the Successful flag of the ReadResult to see if there are errors, and
        /// check the Message flag to see what the errors were.
        /// </summary>
        /// <param name="xmlReader">The reader to use</param>
        /// <returns>A <see cref="DataStoreInMemory"/> containing all objects that were in the xml</returns>
        public DataStoreInMemory Read(XmlReader xmlReader)
        {
            var boReader = new BusinessObjectXmlReader();

            return(Read(xmlReader, boReader));
        }