Exemple #1
0
 private Task RemoveCustomer(string name)
 {
     using (var scope = host.Create()) {
         var customers = scope.Get <ICustomerRepository>();
         if (customers.TryGet(name, out CRM.Model.Customer item))
         {
             customers.Remove(item);
         }
         return(customers.SaveChangesAsync());
     }
 }
        public void TestUniqueKeyViolationException()
        {
            Func <Task> func = async() => {
                using (var scope = host.Create()) {
                    string name     = "test-error-handling-unique-key-violation";
                    var    repo     = scope.Get <ICustomerRepository>();
                    var    products = scope.Get <IProductRepository>();
                    repo.Add(new CRM.Model.Customer(new CRM.Messages.Customer {
                        Name = name
                    }, Admin, products));
                    repo.Add(new CRM.Model.Customer(new CRM.Messages.Customer {
                        Name = name
                    }, Admin, products));
                    await repo.SaveChangesAsync();
                }
            };

            Assert.ThrowsAsync <DbUpdateException>(func);
        }
Exemple #3
0
        public async Task Run()
        {
            using (var scope = host.Create()) {
                using (var t = scope.Get <CRMDbSession>().BeginTransaction()) {
                    string name     = "customer-test-transaction";
                    var    contacts = scope.Get <ICustomerRepository>();
                    var    products = scope.Get <IProductRepository>();
                    contacts.Add(new CRM.Model.Customer(new CRM.Messages.Customer {
                        Name = name, Company = name,
                    }, Admin, products));
                    await contacts.DbSession.SaveChangesAsync();

                    t.Commit();
                }
            }
        }