public void DeepLoadEntityOneToManyTest()
        {
            var companyTable = CreateAndPopulateMockTable("Company");
            var contactTable = CreateAndPopulateMockTable("Contact");

            var memProvider = new MemoryDataProvider();

            memProvider.AddTable(companyTable);
            memProvider.AddTable(contactTable);
            var query = new DataModelQuery <DataModel <Company> >()
                        .WhereProperty["ID"].IsEqualTo(1);
            var decompany = memProvider.DeepLoadModel(query) as DataModel <Company>;

            Assert.IsNotNull(decompany);
            Company company = decompany.Entity;

            Assert.IsNotNull(company);
            Assert.IsNotNull(company.Contacts, "Contacts not populated");
            Assert.IsTrue(company.Contacts.Count == 2, company.Contacts.Count
                          + " loaded (expected 2).");
            Assert.IsTrue(company.Contacts[0].Name == "Betty Sue" ||
                          company.Contacts[0].Name == "John Doe");
            Assert.IsTrue(company.Contacts[1].Name == "Betty Sue" ||
                          company.Contacts[1].Name == "John Doe");
        }
        public void DeepSaveEntityTest()
        {
            // todo: test all four relationship types

            var companyTable = CreateAndPopulateMockTable("Company");
            var contactTable = CreateAndPopulateMockTable("Contact");

            var memProvider = new MemoryDataProvider();

            memProvider.AddTable(companyTable);
            memProvider.AddTable(contactTable);
            var query = new DataModelQuery <DataModel <Company> >()
                        .WhereProperty["ID"].IsEqualTo(1);
            var decompany = memProvider.DeepLoadModel(query);
            var company   = decompany.Entity;

            company.CompanyName += "_";
            foreach (var c in company.Contacts)
            {
                c.Name += "_";
            }
            decompany.Save(true);

            query = new DataModelQuery <DataModel <Company> >()
                    .WhereProperty["ID"].IsEqualTo(1);
            decompany = memProvider.DeepLoadModel(query);
            company   = decompany.Entity;
            Assert.IsTrue(company.CompanyName.Length > 1 &&
                          company.CompanyName.EndsWith("_"));
            Assert.IsTrue(company.Contacts[0]
                          .Name.Length > 1 &&
                          company.Contacts[0]
                          .Name.EndsWith("_"));
            Assert.IsTrue(company.Contacts[company.Contacts.Count - 1]
                          .Name.Length > 1 &&
                          company.Contacts[company.Contacts.Count - 1]
                          .Name.EndsWith("_"));
        }
        public void DeepLoadEntityManyToOneTest3()
        {
            var companyTable = CreateAndPopulateMockTable("Company");
            var contactTable = CreateAndPopulateMockTable("Contact");

            var memProvider = new MemoryDataProvider();

            memProvider.AddTable(companyTable);
            memProvider.AddTable(contactTable);
            var query = new DataModelQuery <Contact>()
                        .WhereProperty["ID"].IsEqualTo(3);
            var contact = memProvider.DeepLoadModel(query) as Contact;

            Assert.IsNotNull(contact);
            Assert.IsTrue(contact.Name == "John Doe");
            Assert.IsNotNull(contact.Company);
            Assert.IsTrue(contact.Company.CompanyName == "Acme, Inc.");
        }
        public void DeepLoadEntityManyToOneTest4()
        {
            var companyTable = CreateAndPopulateMockTable("Company");
            var contactTable = CreateAndPopulateMockTable("Contact");

            var memProvider = new MemoryDataProvider();

            memProvider.AddTable(companyTable);
            memProvider.AddTable(contactTable);
            var query = new DataModelQuery <Contact>()
                        .WhereProperty["ID"].IsEqualTo(4);
            var contact = memProvider.DeepLoadModel(query) as Contact;

            Assert.IsNotNull(contact);
            Assert.IsTrue(contact.Name == "Jane Lane");
            Assert.IsNotNull(contact.Company);
            Assert.IsTrue(contact.Company.CompanyName == "Foobar, Ltd.");
            Assert.IsTrue(contact.Company.Contacts != null);
            Assert.IsTrue(contact.Company.Contacts.Count > 0);
        }
        public void DeepLoadEntityTest()
        {
            DataProviderBase mockRepos = new MemoryDataProvider();
            var table = ((MemoryDataProvider)mockRepos).AddTable("mock_table");

            PopulateMockTable(table);
            var table2 = ((MemoryDataProvider)mockRepos).AddTable("mock_table2");

            PopulateMockTable(table2);

            var query = new DataModelQuery <DataModel <DataModelRelationshipMetadataTest.MockPocoChild> >()
                        .WhereProperty["ID"].IsEqualTo(2);
            var e = mockRepos.DeepLoadModel(query)
                    as DataModel <DataModelRelationshipMetadataTest.MockPocoChild>;

            Assert.IsNotNull(e, "Nothing was returned from DeepLoad query.");
            Assert.IsNotNull(e.Entity.MockPoco, "Child object not assigned in DeepLoad");
            Assert.IsTrue(e.Entity.MockPoco.MockDecimalValue == e.Entity.MockDecimalValue,
                          "Child object field value mismatch");
        }
        public void DeepSaveEntitiesTest()
        {
            var companyTable = CreateAndPopulateMockTable("Company");
            var contactTable = CreateAndPopulateMockTable("Contact");

            var memProvider = new MemoryDataProvider();

            memProvider.AddTable(companyTable);
            memProvider.AddTable(contactTable);

            var query = new DataModelQuery <DataModel <Company> >()
                        .WhereProperty["ID"].IsEqualTo(1);
            var decompany = memProvider.DeepLoadModel(query);
            var company   = decompany.Entity;

            company.CompanyName += "_";
            foreach (var c in company.Contacts)
            {
                c.Name += "_";
            }

            var query2 = new DataModelQuery <DataModel <Company> >()
                         .WhereProperty["ID"].IsEqualTo(2);
            var decompany2 = memProvider.DeepLoadModel(query2);
            var company2   = decompany2.Entity;

            company2.CompanyName = "_" + company2.CompanyName;
            foreach (var c in company2.Contacts)
            {
                c.Name = "_" + c.Name;
            }

            var col = new DataModelCollection <DataModel <Company> >();

            col.Add(decompany);
            col.Add(decompany2);
            col.DataProvider = memProvider;

            col.Save(true);

            query = new DataModelQuery <DataModel <Company> >()
                    .WhereProperty["ID"].IsEqualTo(1);
            decompany = memProvider.DeepLoadModel(query);
            company   = decompany.Entity;
            Assert.IsTrue(company.CompanyName.Length > 1 &&
                          company.CompanyName.EndsWith("_"));
            Assert.IsTrue(company.Contacts[0]
                          .Name.Length > 1 &&
                          company.Contacts[0]
                          .Name.EndsWith("_"));
            Assert.IsTrue(company.Contacts[company.Contacts.Count - 1]
                          .Name.Length > 1 &&
                          company.Contacts[company.Contacts.Count - 1]
                          .Name.EndsWith("_"));

            query = new DataModelQuery <DataModel <Company> >()
                    .WhereProperty["ID"].IsEqualTo(2);
            decompany = memProvider.DeepLoadModel(query);
            company   = decompany.Entity;
            Assert.IsTrue(company.CompanyName.Length > 1 &&
                          company.CompanyName.StartsWith("_"));
            Assert.IsTrue(company.Contacts[0]
                          .Name.Length > 1 &&
                          company.Contacts[0]
                          .Name.StartsWith("_"));
            Assert.IsTrue(company.Contacts[company.Contacts.Count - 1]
                          .Name.Length > 1 &&
                          company.Contacts[company.Contacts.Count - 1]
                          .Name.StartsWith("_"));
        }