예제 #1
0
        public async Task TransactionCommitAsync()
        {
            TestUtilities.ResetDatabase();

            using (var scope = TransactionFactory.CreateAsync())
            {
                Company companyGwiSoftware = new Company();
                companyGwiSoftware.Name     = "GWI Software";
                companyGwiSoftware.Location = "Vancouver";
                await CompanyService.SaveAsync(companyGwiSoftware);

                Customer customerDanGreen = new Customer();
                customerDanGreen.FirstName = "Dan";
                customerDanGreen.LastName  = "Green";
                customerDanGreen.CompanyId = companyGwiSoftware.Id;
                await CustomerService.SaveAsync(customerDanGreen);

                Assert.AreNotEqual(null, customerDanGreen.Id);

                scope.Complete();
            }

            var companies = await CompanyService.GetCollectionAsync();

            Assert.AreEqual(2, companies.Count);

            var customers = await CustomerService.GetCollectionAsync();

            Assert.AreEqual(3, customers.Count);
        }
예제 #2
0
        public async Task TransactionValidationErrorRollbackAsync()
        {
            TestUtilities.ResetDatabase();

            try
            {
                using (var scope = TransactionFactory.CreateAsync())
                {
                    Company companyGwiSoftware = new Company();
                    companyGwiSoftware.Name     = "GWI Software";
                    companyGwiSoftware.Location = "Vancouver";
                    await CompanyService.SaveAsync(companyGwiSoftware);

                    Customer customerDanGreen = new Customer();
                    customerDanGreen.FirstName = "Dan";
                    customerDanGreen.CompanyId = companyGwiSoftware.Id;
                    await CustomerService.SaveAsync(customerDanGreen);

                    Assert.AreNotEqual(null, customerDanGreen.Id);

                    scope.Complete();
                }

                Assert.Fail("Customer.LastName is required.");
            }
            catch
            {
            }

            var companies = await CompanyService.GetCollectionAsync();

            Assert.AreEqual(1, companies.Count);

            var customers = await CustomerService.GetCollectionAsync();

            Assert.AreEqual(2, customers.Count);
        }