Esempio n. 1
0
        public void DeepSaveEntitiesTest()
        {
            try
            {
                var sqlFactory = SqlClientFactory.Instance;
                var dbProvider = new DbDataProvider(sqlFactory, TestSqlConnection);

                var query = new DataModelQuery <DataModel <Company> >()
                            .WhereProperty["ID"] == 1;
                var decompany = dbProvider.DeepLoadModel(query);
                var company   = decompany.Entity;
                company.CompanyName += "_";
                foreach (var c in company.Contacts)
                {
                    c.Name += "_";
                }

                var query2 = new DataModelQuery <DataModel <Company> >()
                             .WhereProperty["ID"] == 2;
                var decompany2 = dbProvider.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 = dbProvider;

                col.Save(true);

                query = new DataModelQuery <DataModel <Company> >()
                        .WhereProperty["ID"] == 1;
                decompany = dbProvider.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"] == 2;
                decompany = dbProvider.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("_"));
            }
            finally
            {
                ReloadData_CompanyContact(); // clean-up
            }
        }
Esempio n. 2
0
        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("_"));
        }