Exemple #1
0
        public void Query_ShouldMapToList()
        {
            // Arrange
            StubResultSet rs = new StubResultSet("ID", "Name", "Age", "IsHappy", "BirthDate");

            rs.AddRow(1, "Jordan", 33, true, new DateTime(1977, 1, 22));
            rs.AddRow(2, "Amyme", 31, false, new DateTime(1979, 10, 19));

            // Act
            var db     = CreateDB_ForQuery(rs);
            var people = db.Query <Person>("sql...");

            // Assert
            Assert.IsTrue(people.Count == 2);

            Person jordan = people[0];

            Assert.AreEqual(1, jordan.ID);
            Assert.AreEqual("Jordan", jordan.Name);
            Assert.AreEqual(33, jordan.Age);
            Assert.AreEqual(true, jordan.IsHappy);
            Assert.AreEqual(new DateTime(1977, 1, 22), jordan.BirthDate);

            Person amyme = people[1];

            Assert.AreEqual(2, amyme.ID);
            Assert.AreEqual("Amyme", amyme.Name);
            Assert.AreEqual(31, amyme.Age);
            Assert.AreEqual(false, amyme.IsHappy);
            Assert.AreEqual(new DateTime(1979, 10, 19), amyme.BirthDate);
        }
        public void Query_ShouldMapToList()
        {
            // Arrange
            StubResultSet rs = new StubResultSet("ID", "Name", "Age", "IsHappy", "BirthDate");
            rs.AddRow(1, "Jordan", 33, true, new DateTime(1977, 1, 22));
            rs.AddRow(2, "Amyme", 31, false, new DateTime(1979, 10, 19));

            // Act
            var db = CreateDB_ForQuery(rs);
            var people = db.Query<Person>("sql...");

            // Assert
            Assert.IsTrue(people.Count == 2);

            Person jordan = people[0];
            Assert.AreEqual(1, jordan.ID);
            Assert.AreEqual("Jordan", jordan.Name);
            Assert.AreEqual(33, jordan.Age);
            Assert.AreEqual(true, jordan.IsHappy);
            Assert.AreEqual(new DateTime(1977, 1, 22), jordan.BirthDate);

            Person amyme = people[1];
            Assert.AreEqual(2, amyme.ID);
            Assert.AreEqual("Amyme", amyme.Name);
            Assert.AreEqual(31, amyme.Age);
            Assert.AreEqual(false, amyme.IsHappy);
            Assert.AreEqual(new DateTime(1979, 10, 19), amyme.BirthDate);
        }
Exemple #3
0
        public void QueryToGraph_WithNestedRelationships_UnsortedResults_ShouldMapToGraph()
        {
            // Arrange
            StubResultSet rs = new StubResultSet("ID", "OrderName", "OrderItemID", "ItemDescription", "Price", "AmountPaid");

            // For this test, results are purposefully out of order
            rs.AddRow(3, "Order3", DBNull.Value, DBNull.Value, DBNull.Value, DBNull.Value);
            rs.AddRow(1, "Order1", 50, "Red car", 100.35m, DBNull.Value);
            rs.AddRow(2, "Order2", 60, "Guitar", 1500.50m, 1500.50m);
            rs.AddRow(1, "Order1", 51, "Blue wagon", 44.87m, DBNull.Value);
            rs.AddRow(2, "Order2", 61, "Bass", 2380.00m, 50.00m);

            // Act
            var          db     = CreateDB_ForQuery(rs);
            List <Order> orders = db.QueryToGraph <Order>("sql...");

            // Assert
            Assert.IsTrue(orders.Count == 3);
            // NOTE: Cannot assume that orders are sorted, so get by OrderName to verify children
            Order order1 = orders.Where(o => o.OrderName == "Order1").FirstOrDefault();
            Order order2 = orders.Where(o => o.OrderName == "Order2").FirstOrDefault();
            Order order3 = orders.Where(o => o.OrderName == "Order3").FirstOrDefault();

            Assert.IsTrue(order1.OrderItems.Count == 2);
            Assert.IsTrue(order2.OrderItems.Count == 2);
            Assert.IsTrue(order3.OrderItems.Count == 0);

            // Order 1
            Assert.AreEqual(1, order1.ID);
            Assert.AreEqual("Order1", order1.OrderName);

            // Order 1 -> Item 1
            Assert.AreEqual(50, order1.OrderItems[0].ID);
            Assert.AreEqual("Red car", order1.OrderItems[0].ItemDescription);
            Assert.AreEqual(100.35m, order1.OrderItems[0].Price);
            Assert.IsNull(order1.OrderItems[0].ItemReceipt.AmountPaid);

            // Order 1 -> Item 2
            Assert.AreEqual(51, order1.OrderItems[1].ID);
            Assert.AreEqual("Blue wagon", order1.OrderItems[1].ItemDescription);
            Assert.AreEqual(44.87m, order1.OrderItems[1].Price);
            Assert.IsNull(order1.OrderItems[1].ItemReceipt.AmountPaid);

            // Order 2 -> Item 1
            Assert.AreEqual(60, order2.OrderItems[0].ID);
            Assert.AreEqual("Guitar", order2.OrderItems[0].ItemDescription);
            Assert.AreEqual(1500.50m, order2.OrderItems[0].Price);
            Assert.AreEqual(1500.50m, order2.OrderItems[0].ItemReceipt.AmountPaid);

            // Order 2 -> Item 2
            Assert.AreEqual(61, order2.OrderItems[1].ID);
            Assert.AreEqual("Bass", order2.OrderItems[1].ItemDescription);
            Assert.AreEqual(2380.00m, order2.OrderItems[1].Price);
            Assert.AreEqual(50.00m, order2.OrderItems[1].ItemReceipt.AmountPaid);
        }
Exemple #4
0
        public void QueryToGraph_WithNestedRelationships_ShouldMapToGraph()
        {
            // Arrange
            StubResultSet rs = new StubResultSet("ID", "OrderName", "OrderItemID", "ItemDescription", "Price", "AmountPaid");

            rs.AddRow(1, "Order1", 50, "Red car", 100.35m, DBNull.Value);
            rs.AddRow(1, "Order1", 51, "Blue wagon", 44.87m, DBNull.Value);
            rs.AddRow(2, "Order2", 60, "Guitar", 1500.50m, 1500.50m);
            rs.AddRow(2, "Order2", 61, "Bass", 2380.00m, 50.00m);
            rs.AddRow(3, "Order3", DBNull.Value, DBNull.Value, DBNull.Value, DBNull.Value);

            // Act
            var          db     = CreateDB_ForQuery(rs);
            List <Order> orders = db.QueryToGraph <Order>("sql...");

            // Assert
            Assert.IsTrue(orders.Count == 3);
            Order order1 = orders[0];
            Order order2 = orders[1];
            Order order3 = orders[2];

            Assert.IsTrue(order1.OrderItems.Count == 2);
            Assert.IsTrue(order2.OrderItems.Count == 2);
            Assert.IsTrue(order3.OrderItems.Count == 0);

            // Order 1
            Assert.AreEqual(1, order1.ID);
            Assert.AreEqual("Order1", order1.OrderName);

            // Order 1 -> Item 1
            Assert.AreEqual(50, order1.OrderItems[0].ID);
            Assert.AreEqual("Red car", order1.OrderItems[0].ItemDescription);
            Assert.AreEqual(100.35m, order1.OrderItems[0].Price);
            Assert.IsNull(order1.OrderItems[0].ItemReceipt.AmountPaid);

            // Order 1 -> Item 2
            Assert.AreEqual(51, order1.OrderItems[1].ID);
            Assert.AreEqual("Blue wagon", order1.OrderItems[1].ItemDescription);
            Assert.AreEqual(44.87m, order1.OrderItems[1].Price);
            Assert.IsNull(order1.OrderItems[1].ItemReceipt.AmountPaid);

            // Order 2 -> Item 1
            Assert.AreEqual(60, order2.OrderItems[0].ID);
            Assert.AreEqual("Guitar", order2.OrderItems[0].ItemDescription);
            Assert.AreEqual(1500.50m, order2.OrderItems[0].Price);
            Assert.AreEqual(1500.50m, order2.OrderItems[0].ItemReceipt.AmountPaid);

            // Order 2 -> Item 2
            Assert.AreEqual(61, order2.OrderItems[1].ID);
            Assert.AreEqual("Bass", order2.OrderItems[1].ItemDescription);
            Assert.AreEqual(2380.00m, order2.OrderItems[1].Price);
            Assert.AreEqual(50.00m, order2.OrderItems[1].ItemReceipt.AmountPaid);
        }
Exemple #5
0
        public void MultiEntityTest()
        {
            // Arrange
            StubResultSet rs = new StubResultSet("ID", "OrderName", "OrderItemID", "ItemDescription", "Price", "AmountPaid");

            rs.AddRow(1, "Order1", 50, "Red car", 100.35m, DBNull.Value);
            rs.AddRow(1, "Order1", 51, "Blue wagon", 44.87m, DBNull.Value);
            rs.AddRow(2, "Order2", 60, "Guitar", 1500.50m, 1500.50m);
            rs.AddRow(2, "Order2", 61, "Bass", 2380.00m, 50.00m);
            rs.AddRow(3, "Order3", DBNull.Value, DBNull.Value, DBNull.Value, DBNull.Value);

            // Act
            var          db     = CreateDB_ForQuery(rs);
            List <Order> people = db.AutoQueryToGraph <Order>()
                                  .Load(o => o.OrderItems)
                                  .Load(o => o.OrderItems, o => o.OrderItems.First().ItemReceipt)
                                  .Where(o => o.ID > 1);
        }
        public void Find_ShouldMapToEntity()
        {
            // Arrange
            StubResultSet rs = new StubResultSet("ID", "Name", "Age", "IsHappy", "BirthDate");
            rs.AddRow(1, "Jordan", 33, true, new DateTime(1977, 1, 22));

            // Act
            var db = CreateDB_ForQuery(rs);
            Person person = db.Find<Person>("sql...");

            // Assert
            Assert.IsNotNull(person);

            Assert.AreEqual(1, person.ID);
            Assert.AreEqual("Jordan", person.Name);
            Assert.AreEqual(33, person.Age);
            Assert.AreEqual(true, person.IsHappy);
            Assert.AreEqual(new DateTime(1977, 1, 22), person.BirthDate);
        }
Exemple #7
0
        public void Find_ShouldMapToEntity()
        {
            // Arrange
            StubResultSet rs = new StubResultSet("ID", "Name", "Age", "IsHappy", "BirthDate");

            rs.AddRow(1, "Jordan", 33, true, new DateTime(1977, 1, 22));

            // Act
            var    db     = CreateDB_ForQuery(rs);
            Person person = db.Find <Person>("sql...");

            // Assert
            Assert.IsNotNull(person);

            Assert.AreEqual(1, person.ID);
            Assert.AreEqual("Jordan", person.Name);
            Assert.AreEqual(33, person.Age);
            Assert.AreEqual(true, person.IsHappy);
            Assert.AreEqual(new DateTime(1977, 1, 22), person.BirthDate);
        }
        public void QueryToGraph_WithNestedRelationships_ShouldMapToGraph()
        {
            // Arrange
            StubResultSet rs = new StubResultSet("ID", "OrderName", "OrderItemID", "ItemDescription", "Price", "AmountPaid");
            rs.AddRow(1, "Order1", 50, "Red car", 100.35m, DBNull.Value);
            rs.AddRow(1, "Order1", 51, "Blue wagon", 44.87m, DBNull.Value);
            rs.AddRow(2, "Order2", 60, "Guitar", 1500.50m, 1500.50m);
            rs.AddRow(2, "Order2", 61, "Bass", 2380.00m, 50.00m);
            rs.AddRow(3, "Order3", DBNull.Value, DBNull.Value, DBNull.Value, DBNull.Value);
            
            // Act
            var db = CreateDB_ForQuery(rs);
            List<Order> orders = db.QueryToGraph<Order>("sql...");

            // Assert
            Assert.IsTrue(orders.Count == 3);
            Order order1 = orders[0];
            Order order2 = orders[1];
            Order order3 = orders[2];
            Assert.IsTrue(order1.OrderItems.Count == 2);
            Assert.IsTrue(order2.OrderItems.Count == 2);
            Assert.IsTrue(order3.OrderItems.Count == 0);

            // Order 1
            Assert.AreEqual(1, order1.ID);
            Assert.AreEqual("Order1", order1.OrderName);

            // Order 1 -> Item 1
            Assert.AreEqual(50, order1.OrderItems[0].ID);
            Assert.AreEqual("Red car", order1.OrderItems[0].ItemDescription);
            Assert.AreEqual(100.35m, order1.OrderItems[0].Price);
            Assert.IsNull(order1.OrderItems[0].ItemReceipt.AmountPaid);

            // Order 1 -> Item 2
            Assert.AreEqual(51, order1.OrderItems[1].ID);
            Assert.AreEqual("Blue wagon", order1.OrderItems[1].ItemDescription);
            Assert.AreEqual(44.87m, order1.OrderItems[1].Price);
            Assert.IsNull(order1.OrderItems[1].ItemReceipt.AmountPaid);

            // Order 2 -> Item 1
            Assert.AreEqual(60, order2.OrderItems[0].ID);
            Assert.AreEqual("Guitar", order2.OrderItems[0].ItemDescription);
            Assert.AreEqual(1500.50m, order2.OrderItems[0].Price);
            Assert.AreEqual(1500.50m, order2.OrderItems[0].ItemReceipt.AmountPaid);

            // Order 2 -> Item 2
            Assert.AreEqual(61, order2.OrderItems[1].ID);
            Assert.AreEqual("Bass", order2.OrderItems[1].ItemDescription);
            Assert.AreEqual(2380.00m, order2.OrderItems[1].Price);
            Assert.AreEqual(50.00m, order2.OrderItems[1].ItemReceipt.AmountPaid);
        }
        public void MultiEntityTest()
        {
            // Arrange
            StubResultSet rs = new StubResultSet("ID", "OrderName", "OrderItemID", "ItemDescription", "Price", "AmountPaid");
            rs.AddRow(1, "Order1", 50, "Red car", 100.35m, DBNull.Value);
            rs.AddRow(1, "Order1", 51, "Blue wagon", 44.87m, DBNull.Value);
            rs.AddRow(2, "Order2", 60, "Guitar", 1500.50m, 1500.50m);
            rs.AddRow(2, "Order2", 61, "Bass", 2380.00m, 50.00m);
            rs.AddRow(3, "Order3", DBNull.Value, DBNull.Value, DBNull.Value, DBNull.Value);

            // Act
            var db = CreateDB_ForQuery(rs);
            List<Order> people = db.AutoQueryToGraph<Order>()
                .Load(o => o.OrderItems)
                .Load(o => o.OrderItems, o => o.OrderItems.First().ItemReceipt)
                .Where(o => o.ID > 1);
                
                
        }
        public void QueryToGraph_WithNestedRelationships_UnsortedResults_ShouldMapToGraph()
        {
            // Arrange
            StubResultSet rs = new StubResultSet("ID", "OrderName", "OrderItemID", "ItemDescription", "Price", "AmountPaid");

            // For this test, results are purposefully out of order
            rs.AddRow(3, "Order3", DBNull.Value, DBNull.Value, DBNull.Value, DBNull.Value);
            rs.AddRow(1, "Order1", 50, "Red car", 100.35m, DBNull.Value);
            rs.AddRow(2, "Order2", 60, "Guitar", 1500.50m, 1500.50m);
            rs.AddRow(1, "Order1", 51, "Blue wagon", 44.87m, DBNull.Value);
            rs.AddRow(2, "Order2", 61, "Bass", 2380.00m, 50.00m);

            // Act
            var db = CreateDB_ForQuery(rs);
            List<Order> orders = db.QueryToGraph<Order>("sql...");

            // Assert
            Assert.IsTrue(orders.Count == 3);
            // NOTE: Cannot assume that orders are sorted, so get by OrderName to verify children
            Order order1 = orders.Where(o => o.OrderName == "Order1").FirstOrDefault();
            Order order2 = orders.Where(o => o.OrderName == "Order2").FirstOrDefault();
            Order order3 = orders.Where(o => o.OrderName == "Order3").FirstOrDefault();
            Assert.IsTrue(order1.OrderItems.Count == 2);
            Assert.IsTrue(order2.OrderItems.Count == 2);
            Assert.IsTrue(order3.OrderItems.Count == 0);

            // Order 1
            Assert.AreEqual(1, order1.ID);
            Assert.AreEqual("Order1", order1.OrderName);

            // Order 1 -> Item 1
            Assert.AreEqual(50, order1.OrderItems[0].ID);
            Assert.AreEqual("Red car", order1.OrderItems[0].ItemDescription);
            Assert.AreEqual(100.35m, order1.OrderItems[0].Price);
            Assert.IsNull(order1.OrderItems[0].ItemReceipt.AmountPaid);

            // Order 1 -> Item 2
            Assert.AreEqual(51, order1.OrderItems[1].ID);
            Assert.AreEqual("Blue wagon", order1.OrderItems[1].ItemDescription);
            Assert.AreEqual(44.87m, order1.OrderItems[1].Price);
            Assert.IsNull(order1.OrderItems[1].ItemReceipt.AmountPaid);

            // Order 2 -> Item 1
            Assert.AreEqual(60, order2.OrderItems[0].ID);
            Assert.AreEqual("Guitar", order2.OrderItems[0].ItemDescription);
            Assert.AreEqual(1500.50m, order2.OrderItems[0].Price);
            Assert.AreEqual(1500.50m, order2.OrderItems[0].ItemReceipt.AmountPaid);

            // Order 2 -> Item 2
            Assert.AreEqual(61, order2.OrderItems[1].ID);
            Assert.AreEqual("Bass", order2.OrderItems[1].ItemDescription);
            Assert.AreEqual(2380.00m, order2.OrderItems[1].Price);
            Assert.AreEqual(50.00m, order2.OrderItems[1].ItemReceipt.AmountPaid);
        }