Esempio n. 1
0
        public Stream ConvertToStream(IDataEntity entity)
        {
            var builder = new StringBuilder();

            builder.AppendLine(@"<?xml version=""1.0"" encoding=""UTF32Encoding-8""?>");
            builder.AppendLine(@"<Document>");

            var cars = entity.GetCars();

            foreach (var car in cars)
            {
                builder.AppendLine(@"  <Car>");
                builder.AppendFormat(@"    <Date>{0}</Date>", car.GetDate());
                builder.AppendLine();
                builder.AppendFormat(@"    <BrandName>{0}</BrandName>", car.GetBrandName());
                builder.AppendLine();
                builder.AppendFormat(@"    <Price>{0}</Price>", car.GetPrice());
                builder.AppendLine(@"  </Car>");
            }

            builder.AppendLine(@"</Document>");

            var stream = StreamHelper.StreamFromStr(builder.ToString());

            return(stream);
        }
Esempio n. 2
0
        public Stream ConvertToStream(IDataEntity entity)
        {
            var stream = new MemoryStream();
            var cars   = entity.GetCars();

            using (var sw = new BinaryWriter(stream, Encoding.Unicode, true))
            {
                WriteHeader(sw);
                WriteCars(cars, sw);
            }

            return(stream);
        }
Esempio n. 3
0
        public void TestConvertToStreamAndBack()
        {
            var stream         = _converter.ConvertToStream(_dataStub);
            var testFromStream = _converter.ConvertFromStream(stream);

            var testCars = _dataStub.GetCars();
            var cars     = testFromStream.GetCars();

            // Here we can use more than one assert because there no matter why collecation are different
            Assert.True(testCars.Length == cars.Length);

            for (var i = 0; i < cars.Length; i++)
            {
                var car     = cars[i];
                var testCar = testCars[i];
                Assert.AreEqual(car.GetBrandName(), testCar.GetBrandName());
                Assert.AreEqual(car.GetBrandName(), BrandByIterator(i));
                Assert.AreEqual(car.GetDate(), testCar.GetDate());
                Assert.AreEqual(car.GetDate(), DateByIterator(i));
                Assert.AreEqual(car.GetPrice(), testCar.GetPrice());
                Assert.AreEqual(car.GetPrice(), PriceByIterator(i));
            }
        }