Пример #1
0
        public void Test_CompanyAddressesAll()
        {
            var connection = new SqliteConnection("DataSource=:memory:");

            connection.Open();

            try {
                var options = new DbContextOptionsBuilder <HOSContext>()
                              .UseSqlite(connection)
                              .Options;

                using (var context = new HOSContext(options))
                {
                    context.Database.EnsureCreated();
                }

                using (var context = new HOSContext(options))
                {
                    HOSTestData.LoadCompanyTable(context);
                    HOSTestData.LoadStateProvinceCodeTable(context);
                    HOSTestData.LoadCompanyAddresses(context);
                }

                using (var context = new HOSContext(options))
                {
                    IRepository repository = new Repository(context);
                    var         addresses  = repository.All <Address>();
                    Assert.NotNull(addresses);
                    Assert.Equal(6, addresses.Count());
                }
            } finally {
                connection.Close();
            }
        }
Пример #2
0
        public void Test_CompanyAddressUpdate()
        {
            var connection = new SqliteConnection("DataSource=:memory:");

            connection.Open();

            try {
                var options = new DbContextOptionsBuilder <HOSContext>()
                              .UseSqlite(connection)
                              .Options;

                using (var context = new HOSContext(options))
                {
                    context.Database.EnsureCreated();
                }

                using (var context = new HOSContext(options))
                {
                    HOSTestData.LoadCompanyTable(context);
                    HOSTestData.LoadStateProvinceCodeTable(context);
                    HOSTestData.LoadCompanyAddresses(context);
                }

                using (var context = new HOSContext(options))
                {
                    IRepository repository = new Repository(context);
                    var         company    = repository.Find <Company>(c => c.CompanyCode == "FCT001");
                    Assert.NotNull(company);

                    var address = repository.Find <Address>(a =>
                                                            a.CompanyId == company.ID && a.AddressLine1 == "1346 Markum Ranch Rd");

                    Assert.NotNull(address);

                    address.AddressLine1 = "1346 Markum Ranch Road";
                    address.AddressLine2 = "Bldg One";
                    address.UpdatedBy    = "sysadmin";
                    address.UpdatedOn    = DateTime.Now;

                    repository.Update <Address>(address);
                    repository.Save();

                    var test = repository.Find <Address>(a => a.ID == address.ID);
                    Assert.NotNull(test);
                    Assert.Equal(address.AddressLine1, test.AddressLine1);
                    Assert.Equal(address.AddressLine2, test.AddressLine2);
                    Assert.Equal(address.UpdatedOn, test.UpdatedOn);
                }
            } finally {
                connection.Close();
            }
        }
        public void Test_CompanyAddressMgr_Update()
        {
            var connection = new SqliteConnection("DataSource=:memory:");

            connection.Open();

            try {
                var options = new DbContextOptionsBuilder <HOSContext>()
                              .UseSqlite(connection)
                              .EnableSensitiveDataLogging()
                              .Options;

                using (var context = new HOSContext(options))
                {
                    context.Database.EnsureCreated();
                }

                using (var context = new HOSContext(options))
                {
                    HOSTestData.LoadCompanyTable(context);
                    HOSTestData.LoadStateProvinceCodeTable(context);
                    HOSTestData.LoadCompanyAddresses(context);
                }

                using (var context = new HOSContext(options))
                {
                    // context.ChangeTracker.QueryTrackingBehavior = QueryTrackingBehavior.NoTracking;
                    ICompanyAddressManager companyAddressMgr = new CompanyAddressManager(new Repository(context));

                    var companyAddress = companyAddressMgr.GetCompanyAddress(5, 4);
                    Assert.NotNull(companyAddress);

                    DateTime currentTimeStamp = DateTime.Now;
                    companyAddress.UpdatedOn = currentTimeStamp;
                    companyAddressMgr.Update(companyAddress);
                    companyAddressMgr.SaveChanges();

                    companyAddress = companyAddressMgr.GetCompanyAddress(a => a.CompanyId == 5 && a.ID == 4);
                    Assert.NotNull(companyAddress);
                    Assert.Equal(currentTimeStamp, companyAddress.UpdatedOn);
                }
            } finally {
                connection.Close();
            }
        }
        public void Test_CompanyAddressMgr_Delete()
        {
            var connection = new SqliteConnection("DataSource=:memory:");

            connection.Open();

            try {
                var options = new DbContextOptionsBuilder <HOSContext>()
                              .UseSqlite(connection)
                              .EnableSensitiveDataLogging()
                              .Options;

                using (var context = new HOSContext(options))
                {
                    context.Database.EnsureCreated();
                }

                using (var context = new HOSContext(options))
                {
                    HOSTestData.LoadCompanyTable(context);
                    HOSTestData.LoadStateProvinceCodeTable(context);
                    HOSTestData.LoadCompanyAddresses(context);
                }

                using (var context = new HOSContext(options))
                {
                    ICompanyAddressManager addressMgr = new CompanyAddressManager(new Repository(context));

                    var address = addressMgr.GetCompanyAddress(a => a.CompanyId == 5 && a.AddressLine1 == "2150 Cabot Boulevard West");
                    Assert.NotNull(address);

                    addressMgr.Delete(address);
                    addressMgr.SaveChanges();

                    address = addressMgr.GetCompanyAddress(a => a.CompanyId == 5 && a.AddressLine1 == "2150 Cabot Boulevard West");
                    Assert.Null(address);
                }
            } finally {
                connection.Close();
            }
        }
        public void Test_CompanyAddressMgr_SelectAll()
        {
            var connection = new SqliteConnection("DataSource=:memory:");

            connection.Open();

            try {
                var options = new DbContextOptionsBuilder <HOSContext>()
                              .UseSqlite(connection)
                              .EnableSensitiveDataLogging()
                              .Options;

                using (var context = new HOSContext(options))
                {
                    context.Database.EnsureCreated();
                }

                using (var context = new HOSContext(options))
                {
                    HOSTestData.LoadCompanyTable(context);
                    HOSTestData.LoadStateProvinceCodeTable(context);
                    HOSTestData.LoadCompanyAddresses(context);
                }

                using (var context = new HOSContext(options))
                {
                    ICompanyAddressManager addressMgr = new CompanyAddressManager(new Repository(context));

                    var addresses = addressMgr.GetCompanyAddresses(2).ToList();
                    Assert.NotNull(addresses);
                    Assert.Equal(2, addresses.Count());
                }
            } finally {
                connection.Close();
            }
        }