Read() публичный Метод

Reads from a stream that contains xml text. Creates the XmlReader that reads the stream and then uses a default 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.
public Read ( Stream stream ) : IEnumerable
stream Stream The stream to read from. This stream must contain xml text
Результат IEnumerable
        public void Read_ShouldLoadObjectsAsNew_WhenNotInExistingDataStore()
        {
            //---------------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 ObjectTreeXmlReader();
            //---------------Assert Precondition----------------
            Assert.AreEqual(1, savedDataStore.Count);
            //---------------Execute Test ----------------------
            var loadedObjects = reader.Read(writeStream);
            //---------------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_ShouldUpdatedExistingObject_WhenFoundInDataAccessor()
 {
     //---------------Set up test pack-------------------
     LoadMyBOClassDefsWithNoUIDefs();
     var newBo = new MyBO { TestProp = "characters" };
     var stream = GetStreamForBusinessObject(newBo);
     newBo.TestProp = "oldvalue";
     newBo.Save();
     var reader = new ObjectTreeXmlReader();
     //---------------Assert Precondition----------------
     Assert.AreEqual("oldvalue", newBo.TestProp);
     //---------------Execute Test ----------------------
     var loadedObjects = reader.Read(stream);
     //---------------Test Result -----------------------
     var businessObjects = loadedObjects.ToList();
     Assert.AreEqual(1, businessObjects.Count);
     Assert.AreSame(newBo, businessObjects[0]);
     Assert.AreEqual("characters", newBo.TestProp);
 }
        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 ObjectTreeXmlReader();
            //---------------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 ObjectTreeXmlReader();
     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 ObjectTreeXmlReader();
            //---------------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 ObjectTreeXmlReader();
     //---------------Assert Precondition----------------
     //---------------Execute Test ----------------------
     reader.Read(toStream);
     //---------------Test Result -----------------------
     Assert.IsNotNull(reader.ReadResult);
     Assert.IsTrue(reader.ReadResult.Successful);
 }
 public void Read_ShouldSet_ReadResult()
 {
     //---------------Set up test pack-------------------
     LoadMyBOClassDefsWithNoUIDefs();
     var writeStream = GetStreamForBusinessObject(new MyBO());
     var reader = new ObjectTreeXmlReader();
     //---------------Execute Test ----------------------
     var loadedObjects = reader.Read(writeStream, new BusinessObjectXmlReaderWithError());
     //---------------Test Result -----------------------
     Assert.AreEqual(1, loadedObjects.Count());
     Assert.IsNotNull(reader.ReadResult);
     Assert.IsFalse(reader.ReadResult.Successful);
 }