Exemplo n.º 1
0
        public void FlattenObjectAsColumns()
        {
            // Arrange
            var serializer = new Serializer();
            var order = new Order
            {
                Id = "Order/12",
                OrderDate = new DateTime(2015, 06, 01),
                Customer = new Person { FirstName = "Nate", LastName = "Zaugg" }
            };
            var ms = new MemoryStream();
            string expected = "Id,OrderDate,Customer.FirstName,Customer.LastName,Subtotal,Tax,Total\r\nOrder/12,6/1/2015 12:00:00 AM,Nate,Zaugg,0,0,0\r\n";

            string actual;

            // Act
            serializer.Serialize(ms, order);
            actual = Encoding.UTF8.GetString(ms.ToArray());

            // Assert
            Assert.AreEqual(expected, actual);
        }
Exemplo n.º 2
0
        public void FlattenCollectionsAsColumns()
        {
            // Arrange
            var serializer = new Serializer();
            var order = new Order
            {
                Id = "Order/12",
                OrderDate = new DateTime(2015, 06, 01),
                Customer = new Person { FirstName = "Nate", LastName = "Zaugg" },
                Subtotal = 300,
                Tax = 22,
                Total = 322
            };
            order.Add(new OrderItem { Id = "1", Name = "Galaxy S5", ShortDescription = "My phone is nice!", Qty = 1, PricePerQty = 200, LineTotal = 200 });
            order.Add(new OrderItem { Id = "2", Name = "Xoom Tablet", ShortDescription = "I like Xoom tab", Qty = 1, PricePerQty = 100, LineTotal = 100 });

            var ms = new MemoryStream();
            string expected = "Id,OrderDate,Customer.FirstName,Customer.LastName,Subtotal,Tax,Total,Items1.Name,Items1.ShortDescription,Items1.PricePerQty,Items1.Qty,Items1.LineTotal,Items2.Name,Items2.ShortDescription,Items2.PricePerQty,Items2.Qty,Items2.LineTotal\r\nOrder/12,6/1/2015 12:00:00 AM,Nate,Zaugg,300,22,322,Galaxy S5,My phone is nice!,200,1,200,Xoom Tablet,I like Xoom tab,100,1,100\r\n";

            string actual;

            // Act
            serializer.Serialize(ms, order);
            actual = Encoding.UTF8.GetString(ms.ToArray());

            // Assert
            Assert.AreEqual(expected, actual);
        }