Read() public méthode

Uses the XmlReader given to read an xml stream and instantiates IBusinessObjects for each bo node in the stream. The resultant IEnumerable can only be iterated once, so convert it to a list or array (using ToList() or ToArray()) if you want to iterate through it more than once (this includes using Count() etc). The XmlReader is closed once you have iterated.
public Read ( XmlReader xmlReader ) : IEnumerable
xmlReader System.Xml.XmlReader The reader to read from
Résultat IEnumerable
 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_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_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());
 }
 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)));
 }