public void LazyLoaded_Implicit_Conversion_When_Not_IsLoad_Should_Call_DB_Once()
        {
            // Arrange
            StubResultSet rsOffices = new StubResultSet("Number");

            rsOffices.AddRow(1);
            rsOffices.AddRow(2);

            var db = CreateDB_ForQuery(rsOffices);

            Building building  = new Building();
            int      calls     = 0;
            var      lazyProxy = new LazyLoaded <Building, List <Office> >((d, b) => {
                calls++;
                return(d.Query <Office>().ToList());
            }, RelationshipTypes.Many);

            lazyProxy.Prepare(() => db, building, "Offices");
            building._offices = lazyProxy;

            // Act
            int count = building.Offices.Count;

            // Assert
            Assert.AreEqual(2, count);
            Assert.AreEqual(1, calls);

            // Act again (should not hit db)
            count = building.Offices.Count;

            // Assert
            Assert.AreEqual(2, count);
            Assert.AreEqual(1, calls);
        }
Beispiel #2
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);
        }
Beispiel #3
0
        public void QueryToGraph_WithNestedRelationships_UnsortedResults_ShouldMapToGraph()
        {
            // Arrange
            StubResultSet rs = new StubResultSet("ID", "OrderName", "OrderItemID", "OrderID", "ItemDescription", "Price", "AmountPaid");

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

            // Act
            var          db     = CreateDB_ForQuery(rs);
            List <Order> orders = db.Query <Order>().Graph().QueryText("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);
        }
Beispiel #4
0
        public void QueryToGraph_WithNestedRelationships_ShouldMapToGraph()
        {
            // Arrange
            StubResultSet rs = new StubResultSet("ID", "OrderName", "OrderItemID", "OrderID", "ItemDescription", "Price", "AmountPaid");

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

            // Act
            var          db     = CreateDB_ForQuery(rs);
            List <Order> orders = db.Query <Order>().Graph().QueryText("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);
        }
Beispiel #5
0
        public void DataReader_Test()
        {
            // 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));
            rs.AddRow(3, "Guy", 29, false, new DateTime(1981, 10, 3));


            // Act
            var db = CreateDB_ForQuery(rs);

            List <Person> people = new List <Person>();

            db.Query <Person>()
            .QueryText("sql...")
            .DataReader(r =>
            {
                while (r.Read())
                {
                    Person p    = new Person();
                    p.ID        = r.GetInt32(r.GetOrdinal("ID"));
                    p.Name      = r.GetString(r.GetOrdinal("Name"));
                    p.Age       = r.GetInt32(r.GetOrdinal("Age"));
                    p.IsHappy   = r.GetBoolean(r.GetOrdinal("IsHappy"));
                    p.BirthDate = r.GetDateTime(r.GetOrdinal("BirthDate"));
                    people.Add(p);
                }
            });

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

            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 WhenQueryingManyIntegers_ShouldReturnListOfIntegers()
        {
            StubResultSet rs = new StubResultSet("ID");
            rs.AddRow(1);
            rs.AddRow(2);
            rs.AddRow(3);
            var db = CreateDB_ForQuery(rs);

            List<int> ids = db.Query<int>("SELECT [ID] FROM Person");

            Assert.AreEqual(1, ids[0]);
            Assert.AreEqual(2, ids[1]);
            Assert.AreEqual(3, ids[2]);
        }
        public void WhenQueryingManyStrings_ShouldReturnListOfStrings()
        {
            StubResultSet rs = new StubResultSet("Name");
            rs.AddRow("Person1");
            rs.AddRow("Person2");
            rs.AddRow("Person3");
            var db = CreateDB_ForQuery(rs);

            List<string> names = db.Query<string>("SELECT [Name] FROM Person");

            Assert.AreEqual("Person1", names[0]);
            Assert.AreEqual("Person2", names[1]);
            Assert.AreEqual("Person3", names[2]);
        }
        public void WhenQueryingManyStrings_ShouldReturnListOfStrings()
        {
            StubResultSet rs = new StubResultSet("Name");

            rs.AddRow("Person1");
            rs.AddRow("Person2");
            rs.AddRow("Person3");
            var db = CreateDB_ForQuery(rs);

            List <string> names = db.Query <string>("SELECT [Name] FROM Person");

            Assert.AreEqual("Person1", names[0]);
            Assert.AreEqual("Person2", names[1]);
            Assert.AreEqual("Person3", names[2]);
        }
        public void WhenQueryingManyIntegers_ShouldReturnListOfIntegers()
        {
            StubResultSet rs = new StubResultSet("ID");

            rs.AddRow(1);
            rs.AddRow(2);
            rs.AddRow(3);
            var db = CreateDB_ForQuery(rs);

            List <int> ids = db.Query <int>("SELECT [ID] FROM Person");

            Assert.AreEqual(1, ids[0]);
            Assert.AreEqual(2, ids[1]);
            Assert.AreEqual(3, ids[2]);
        }
Beispiel #10
0
        public void DupesAtSameLevel_WithDifferentIDs()
        {
            // Arrange
            var rs1 = new StubResultSet("ID", "Dupe1ID", "Dupe2ID");

            rs1.AddRow(1, 100, 101);

            var rs2 = new StubResultSet("ID", "Name", "ChildID");

            rs2.AddRow(100, "Dupe_100", 1000);

            var rs3 = new StubResultSet("ID", "Name", "ChildID");

            rs3.AddRow(101, "Dupe_101", 1001);

            var db = CreateDB_ForQuery(rs1, rs2, rs3);

            // Act
            var rootEnt = db.Query <RootClass>()
                          .Graph(r => r.Dupe1, r => r.Dupe2)
                          .FirstOrDefault();

            // Assert
            Assert.AreEqual(100, rootEnt.Dupe1ID);
            Assert.AreEqual(101, rootEnt.Dupe2ID);

            Assert.IsNotNull(rootEnt.Dupe1);
            Assert.IsNotNull(rootEnt.Dupe2);

            Assert.AreEqual(100, rootEnt.Dupe1.ID);
            Assert.AreEqual(101, rootEnt.Dupe2.ID);
        }
        public StubResultSet CreateIsDBNullResultSet()
        {
            StubResultSet srs = new StubResultSet("IsNull", "IsDBNull", "NotNull");

            srs.AddRow(null, DBNull.Value, "abc");

            return(srs);
        }
        public void ExecuteReaderAction_ShouldLoadEntityDictionary()
        {
            StubResultSet rs = new StubResultSet("ID", "Hash");
            rs.AddRow(1, "Hash1");
            rs.AddRow(2, "Hash2");
            rs.AddRow(3, "Hash3");
            var db = CreateDB_ForQuery(rs);

            Dictionary<string, int> people = new Dictionary<string, int>();

            db.ExecuteReader("SELECT PersonName FROM tbl", r => { people.Add(r.GetString(1), r.GetInt32(0)); });

            Assert.AreEqual(3, people.Count);
            Assert.AreEqual(1, people["Hash1"]);
            Assert.AreEqual(2, people["Hash2"]);
            Assert.AreEqual(3, people["Hash3"]);
        }
Beispiel #13
0
        //[TestMethod]
        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
                                  .Query <Order>()
                                  .Graph(o => o.OrderItems);
        }
        public void ShouldLoadEntityListWithDelegateSyntax()
        {
            StubResultSet rs = new StubResultSet("ID", "Name", "Age");
            rs.AddRow(1, "Person1", 31);
            rs.AddRow(2, "Person2", 32);
            rs.AddRow(3, "Person3", 33);
            var db = CreateDB_ForQuery(rs);

            List<Person> people = db.ExecuteReader("SELECT PersonName FROM tbl WHERE ID=2",
                r => new Person { ID = r.GetInt32(0), Name = r.GetString(1), Age = r.GetInt32(2) }
                ).ToList();
            
            Assert.AreEqual(3, people.Count);
            Assert.AreEqual(1, people[0].ID);
            Assert.AreEqual(2, people[1].ID);
            Assert.AreEqual(3, people[2].ID);
        }
        public void ExecuteReaderAction_ShouldLoadEntityDictionary()
        {
            StubResultSet rs = new StubResultSet("ID", "Hash");

            rs.AddRow(1, "Hash1");
            rs.AddRow(2, "Hash2");
            rs.AddRow(3, "Hash3");
            var db = CreateDB_ForQuery(rs);

            Dictionary <string, int> people = new Dictionary <string, int>();

            db.ExecuteReader("SELECT PersonName FROM tbl", r => { people.Add(r.GetString(1), r.GetInt32(0)); });

            Assert.AreEqual(3, people.Count);
            Assert.AreEqual(1, people["Hash1"]);
            Assert.AreEqual(2, people["Hash2"]);
            Assert.AreEqual(3, people["Hash3"]);
        }
        public void WhenFindingOneString_ShouldReturnAString()
        {
            StubResultSet rs = new StubResultSet("Name");
            rs.AddRow("Person1");
            var db = CreateDB_ForQuery(rs);

            string name = db.Find<string>("SELECT [Name] FROM Person");

            Assert.AreEqual("Person1", name);
        }
        public void ShouldLoadEntityWithDelegateSyntax()
        {
            StubResultSet rs = new StubResultSet("ID", "Name", "Age");
            rs.AddRow(2, "Person2", 35);
            var db = CreateDB_ForQuery(rs);

            Person p = db.ExecuteReader<Person>("SELECT PersonName FROM tbl WHERE ID=2", LoadPerson).FirstOrDefault();

            Assert.AreEqual("Person2", p.Name);
        }
        public void NoCastsRequired_ShouldPassWithoutConverter()
        {
            // Arrange
            _rs.AddRow((decimal)1, (double)1, (Single)1, (long)1, (int)1, (short)1, (Byte)1);

            // Act
            var db = CreateDB_ForQuery(_rs);
            var implicitProperties = db.Find <ImplicitProperties>("sql...");

            // Assert
            Assert.IsNotNull(implicitProperties);
        }
        public void WhenFindingOneString_ShouldReturnAString()
        {
            StubResultSet rs = new StubResultSet("Name");

            rs.AddRow("Person1");
            var db = CreateDB_ForQuery(rs);

            string name = db.Find <string>("SELECT [Name] FROM Person");

            Assert.AreEqual("Person1", name);
        }
        public void ShouldLoadEntityWithDelegateSyntax()
        {
            StubResultSet rs = new StubResultSet("ID", "Name", "Age");

            rs.AddRow(2, "Person2", 35);
            var db = CreateDB_ForQuery(rs);

            Person p = db.ExecuteReader <Person>("SELECT PersonName FROM tbl WHERE ID=2", LoadPerson).FirstOrDefault();

            Assert.AreEqual("Person2", p.Name);
        }
        public void ShouldLoadEntityListWithDelegateSyntax()
        {
            StubResultSet rs = new StubResultSet("ID", "Name", "Age");

            rs.AddRow(1, "Person1", 31);
            rs.AddRow(2, "Person2", 32);
            rs.AddRow(3, "Person3", 33);
            var db = CreateDB_ForQuery(rs);

            List <Person> people = db.ExecuteReader("SELECT PersonName FROM tbl WHERE ID=2",
                                                    r => new Person {
                ID = r.GetInt32(0), Name = r.GetString(1), Age = r.GetInt32(2)
            }
                                                    ).ToList();

            Assert.AreEqual(3, people.Count);
            Assert.AreEqual(1, people[0].ID);
            Assert.AreEqual(2, people[1].ID);
            Assert.AreEqual(3, people[2].ID);
        }
        public void ShouldLoadEntityWithLambdaSyntax()
        {
            StubResultSet rs = new StubResultSet("ID", "Name", "Age");
            rs.AddRow(2, "Person2", 35);
            var db = CreateDB_ForQuery(rs);

            Person p = db.ExecuteReader("SELECT PersonName FROM tbl WHERE ID=2",
                r => new Person { ID = r.GetValue<int>("ID"), Name = r.GetValue<string>("Name"), Age = r.GetValue<int>("Age") }
                ).FirstOrDefault();

            Assert.AreEqual("Person2", p.Name);
        }
Beispiel #23
0
        public void QueryToGraph_ShouldMapToList()
        {
            // Arrange
            StubResultSet rs = new StubResultSet("ID", "Name", "Age", "IsHappy", "BirthDate", "Pet_ID", "Pet_Name");

            rs.AddRow(1, "Jordan", 33, true, new DateTime(1977, 1, 22), 1, "Chuy");
            rs.AddRow(1, "Jordan", 33, true, new DateTime(1977, 1, 22), 2, "Bela");
            rs.AddRow(2, "Amyme", 31, false, new DateTime(1979, 10, 19), 3, "Bird");
            rs.AddRow(2, "Amyme", 31, false, new DateTime(1979, 10, 19), 4, "Alligator");

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

            // 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);
            Assert.IsTrue(jordan.Pets.Count == 2);
            Assert.AreEqual("Chuy", jordan.Pets.ElementAt(0).Name);
            Assert.AreEqual("Bela", jordan.Pets.ElementAt(1).Name);

            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);
            Assert.IsTrue(amyme.Pets.Count == 2);
            Assert.AreEqual("Bird", amyme.Pets.ElementAt(0).Name);
            Assert.AreEqual("Alligator", amyme.Pets.ElementAt(1).Name);
        }
        public void StubResultSet_AddRow_Success()
        {
            var result       = new StubResultSet("e", "f", "g");
            var addRowResult = result.AddRow(3, 4, 5);

            Assert.AreSame(result, addRowResult, "AddRow() should have returned a reference to its owning result set");

            result.Read();

            Assert.AreEqual(3, result.CurrentRow[0], "The first value given to AddRow() was not preserved");
            Assert.AreEqual(4, result.CurrentRow[1], "The second value given to AddRow() was not preserved");
            Assert.AreEqual(5, result.CurrentRow[2], "The third value given to AddRow() was not preserved");
        }
        public void LazyLoadedException_ShouldThrowDataMappingException()
        {
            // Arrange
            StubResultSet rsOffices = new StubResultSet("Number");

            rsOffices.AddRow(1);
            rsOffices.AddRow(2);

            var db = CreateDB_ForQuery(rsOffices);

            Building building  = new Building();
            var      lazyProxy = new LazyLoaded <Building, List <Office> >((d, b) =>
            {
                throw new Exception("Oops!");
                //return d.Query<Office>().ToList();
            }, RelationshipTypes.Many);

            lazyProxy.Prepare(() => db, building, "Offices");
            building._offices = lazyProxy;

            // Act
            int count = building.Offices.Count;
        }
        public void ShouldLoadEntityWithLambdaSyntax()
        {
            StubResultSet rs = new StubResultSet("ID", "Name", "Age");

            rs.AddRow(2, "Person2", 35);
            var db = CreateDB_ForQuery(rs);

            Person p = db.ExecuteReader("SELECT PersonName FROM tbl WHERE ID=2",
                                        r => new Person {
                ID = r.GetValue <int>("ID"), Name = r.GetValue <string>("Name"), Age = r.GetValue <int>("Age")
            }
                                        ).FirstOrDefault();

            Assert.AreEqual("Person2", p.Name);
        }
Beispiel #27
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);
        }
Beispiel #28
0
        public void DupesAtSameLevel_WithSameIDs_OneWithJoin()
        {
            // Arrange
            var rsRoot = new StubResultSet("ID", "Dupe1ID", "Dupe2ID");

            rsRoot.AddRow(1, 100, 100);

            var rsDupe1 = new StubResultSet("ID", "Name", "ChildID", "dccID", "dccName");

            rsDupe1.AddRow(100, "Dupe_100", 1000, 1000, "Child_1000");

            var rsDupe2 = new StubResultSet("ID", "Name", "ChildID");

            rsDupe2.AddRow(100, "Dupe_100", 1000);

            var db = CreateDB_ForQuery(rsRoot, rsDupe1, rsDupe2);

            // Act
            var rootEnt = db.Query <RootClass>()
                          .Graph(
                r => r.Dupe1,
                r => r.Dupe2,
                r => r.Dupe1.Child)
                          .FirstOrDefault();

            // Assert
            Assert.AreEqual(100, rootEnt.Dupe1ID);
            Assert.AreEqual(100, rootEnt.Dupe2ID);

            Assert.IsNotNull(rootEnt.Dupe1);
            Assert.IsNotNull(rootEnt.Dupe2);

            Assert.AreEqual(100, rootEnt.Dupe1.ID);
            Assert.AreEqual(100, rootEnt.Dupe2.ID);

            Assert.IsNotNull(rootEnt.Dupe1.Child);
            Assert.IsNull(rootEnt.Dupe2.Child);

            Assert.AreEqual(1000, rootEnt.Dupe1.Child.ID);
            Assert.AreEqual("Child_1000", rootEnt.Dupe1.Child.Name);
        }
        public void WhenQuerying_CastingError_ShouldGiveCustomErrorMessage()
        {
            // Create a result set with a long value and then
            // purposefully cast it to a string to create a cast exception
            StubResultSet rs = new StubResultSet("LongValue");
            rs.AddRow(12345678L);
            var db = CreateDB_ForQuery(rs);

            bool exceptionWasThrown = false;

            try
            {
                string name = db.Query<string>("SELECT [LongValue] FROM Tbl").FirstOrDefault();
            }
            catch (Exception ex)
            {
                exceptionWasThrown = true;
                Assert.IsInstanceOfType(ex, typeof(DataMappingException));
            }

            Assert.IsTrue(exceptionWasThrown);
        }
        public void WhenQuerying_CastingError_ShouldGiveCustomErrorMessage()
        {
            // Create a result set with a long value and then
            // purposefully cast it to a string to create a cast exception
            StubResultSet rs = new StubResultSet("LongValue");

            rs.AddRow(12345678L);
            var db = CreateDB_ForQuery(rs);

            bool exceptionWasThrown = false;

            try
            {
                string name = db.Query <string>("SELECT [LongValue] FROM Tbl").FirstOrDefault();
            }
            catch (Exception ex)
            {
                exceptionWasThrown = true;
                Assert.IsInstanceOfType(ex, typeof(DataMappingException));
            }

            Assert.IsTrue(exceptionWasThrown);
        }