Ejemplo n.º 1
0
 public void ReturnsNullWhenTableContainsEntity()
 {
     using (var dbContext = new TestDbContextContainer())
     {
         using (var repository = new DbContextCustomerRepository(dbContext))
         {
             var customer = repository.FirstOrDefault(x => x.Id == 999);
             Assert.IsNull(customer);
         }
     }
 }
Ejemplo n.º 2
0
            public void ReturnsEntityWhenTableContainsEntity()
            {
                using (var dbContext = new TestDbContextContainer())
                {
                    using (var repository = new DbContextCustomerRepository(dbContext))
                    {
                        EFTestHelper.CreateCustomerIfNotAlreadyExists(1);

                        var customer = repository.FirstOrDefault();

                        Assert.IsNotNull(customer);
                        Assert.AreEqual(1, customer.Id);
                    }
                }
            }
Ejemplo n.º 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();
                    }
                }
            }
        }
Ejemplo n.º 4
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();
                    }
                }
            }
        }
Ejemplo n.º 5
0
            public void ReturnsEntityWhenTableContainsEntity()
            {
                using (var dbContext = new TestDbContextContainer())
                {
                    using (var repository = new DbContextCustomerRepository(dbContext))
                    {
                        EFTestHelper.CreateCustomerIfNotAlreadyExists(1);

                        var customer = repository.FirstOrDefault();

                        Assert.IsNotNull(customer);
                        Assert.AreEqual(1, customer.Id);
                    }
                }
            }
Ejemplo n.º 6
0
 public void ReturnsNullWhenTableContainsEntity()
 {
     using (var dbContext = new TestDbContextContainer())
     {
         using (var repository = new DbContextCustomerRepository(dbContext))
         {
             var customer = repository.FirstOrDefault(x => x.Id == 999);
             Assert.IsNull(customer);
         }
     }
 }