Exemple #1
0
        public void DeletePayment()
        {
            using (var uow = new CapriconContext())
            {
                var paymentRep      = new PaymentRepository(uow);
                var existingPayment = paymentRep.Find(p => p.PaymentId == 2).FirstOrDefault();

                Assert.IsNotNull(existingPayment);

                int paymentId;
                if (existingPayment != null)
                {
                    paymentId = existingPayment.PaymentId;

                    //Delete payment
                    paymentRep.Delete(existingPayment);

                    try
                    {
                        uow.SaveChanges();
                    }
                    catch (DbEntityValidationException ex)
                    {
                        //Retrieve validation errors
                        ex.EntityValidationErrors.ToList().ForEach
                        (
                            v =>
                        {
                            v.ValidationErrors.ToList().ForEach
                            (
                                e =>
                            {
                                System.Diagnostics.Debug.WriteLine(e.ErrorMessage);
                            }
                            );
                        }
                        );
                        Assert.Fail("Test failed");
                    }

                    Assert.IsNull(paymentRep.Find(p => p.PaymentId == paymentId).FirstOrDefault());
                }
                else //no payments were selected
                {
                    Assert.Fail("No payment was selected");
                }
            }
        }
Exemple #2
0
        public async void Test_GenericRepository_Update()
        {
            var options = new DbContextOptionsBuilder <AccountContext>()
                          .UseInMemoryDatabase(databaseName: "Test2G")
                          .Options;

            using (var ctx = new AccountContext(options))
            {
                var profiles   = new ProfileRepository(ctx);
                var payment    = new PaymentRepository(ctx);
                var newProfile = new ProfileModel()
                {
                    Id        = 0,
                    Email     = "*****@*****.**",
                    Name      = null,
                    Phone     = "1234567897",
                    Age       = "Adult",
                    AccountId = 1,
                    Account   = null
                };
                var updateProfile = new ProfileModel()
                {
                    Id        = 1,
                    Email     = "*****@*****.**",
                    Name      = null,
                    Phone     = "2222222222",
                    Age       = "Child",
                    AccountId = 1,
                    Account   = null
                };
                await profiles.Add(newProfile);

                await ctx.SaveChangesAsync();

                ctx.Entry <ProfileModel>(newProfile).State = EntityState.Detached;
                await profiles.Update(updateProfile);

                await ctx.SaveChangesAsync();

                var actual = await profiles.GetAll();

                var payments = await payment.GetAll();

                var payments2 = await payment.Find(payment => payment.AccountId == 1);

                var phone = actual.First().Phone;

                Assert.Equal("2222222222", phone);
                Assert.Empty(payments);
                Assert.Empty(payments2);
            }
        }
        public void DeletePayment()
        {
            using (var uow = new CapriconContext())
            {
                var paymentRep = new PaymentRepository(uow);
                var existingPayment = paymentRep.Find(p => p.PaymentId == 2).FirstOrDefault();

                Assert.IsNotNull(existingPayment);

                int paymentId;
                if (existingPayment != null)
                {
                    paymentId = existingPayment.PaymentId;

                    //Delete payment
                    paymentRep.Delete(existingPayment);

                    try
                    {
                        uow.SaveChanges();
                    }
                    catch (DbEntityValidationException ex)
                    {
                        //Retrieve validation errors
                        ex.EntityValidationErrors.ToList().ForEach
                        (
                            v =>
                            {
                                v.ValidationErrors.ToList().ForEach
                                    (
                                        e =>
                                        {
                                            System.Diagnostics.Debug.WriteLine(e.ErrorMessage);
                                        }
                                    );
                            }
                        );
                        Assert.Fail("Test failed");
                    }

                    Assert.IsNull(paymentRep.Find(p => p.PaymentId == paymentId).FirstOrDefault());
                }
                else //no payments were selected
                    Assert.Fail("No payment was selected");
            }
        }