Example #1
0
            public void AddsNonExistingEntity()
            {
                using (var dbContext = new TestDbContextContainer())
                {
                    using (var repository = new DbContextCustomerRepository(dbContext))
                    {
                        var customer = EFTestHelper.CreateCustomer(1234);

                        repository.Add(customer);

                        dbContext.SaveChanges();

                        var fetchedCustomer = repository.GetByKey(1234);
                        Assert.AreEqual(customer, fetchedCustomer);
                    }
                }
            }
Example #2
0
        public static void CreateCustomerIfNotAlreadyExists(int id)
        {
            using (var dbContext = new TestDbContextContainer())
            {
                using (var repository = new DbContextCustomerRepository(dbContext))
                {
                    var existingCustomer = repository.FirstOrDefault(x => x.Id == id);
                    if (existingCustomer == null)
                    {
                        var customer = CreateCustomer(id);

                        repository.Add(customer);

                        dbContext.SaveChanges();
                    }
                }
            }
        }
Example #3
0
        public static void CreateCustomerIfNotAlreadyExists(int id)
        {
            using (var dbContext = new TestDbContextContainer())
            {
                using (var repository = new DbContextCustomerRepository(dbContext))
                {
                    var existingCustomer = repository.FirstOrDefault(x => x.Id == id);
                    if (existingCustomer == null)
                    {
                        var customer = CreateCustomer(id);

                        repository.Add(customer);

                        dbContext.SaveChanges();
                    }
                }
            }
        }
Example #4
0
 public void ThrowsArgumentNullExceptionForNullEntity()
 {
     using (var dbContext = new TestDbContextContainer())
     {
         using (var repository = new DbContextCustomerRepository(dbContext))
         {
             ExceptionTester.CallMethodAndExpectException <ArgumentNullException>(() => repository.Add(null));
         }
     }
 }
            public void AddsNonExistingEntity()
            {
                using (var dbContext = new TestDbContextContainer())
                {
                    using (var repository = new DbContextCustomerRepository(dbContext))
                    {
                        var customer = EFTestHelper.CreateCustomer(1234);

                        repository.Add(customer);

                        dbContext.SaveChanges();

                        var fetchedCustomer = repository.GetByKey(1234);
                        Assert.AreEqual(customer, fetchedCustomer);
                    }
                }  
            }
 public void ThrowsArgumentNullExceptionForNullEntity()
 {
     using (var dbContext = new TestDbContextContainer())
     {
         using (var repository = new DbContextCustomerRepository(dbContext))
         {
             ExceptionTester.CallMethodAndExpectException<ArgumentNullException>(() => repository.Add(null));
         }
     }  
 }