コード例 #1
0
        public void Db_DeleteNoExistentCustomer()
        {
            // arrange
            var customerDb = new CustomerDb(_connectionString);
            var customer   = new Customer.EF.Customer {
                Id = 0, FirstName = "John", LastName = "Doddle", Password = "******"
            };

            // act
            var result = customerDb.DeleteCustomer(customer);

            // assert
            Assert.AreEqual(result, 0);
        }
コード例 #2
0
        public void Db_CreateCustomer()
        {
            // arrange
            var customerDb = new CustomerDb(_connectionString);
            var customer   = new Customer.EF.Customer {
                Id = 0, FirstName = "John", LastName = "Doddle", Password = "******"
            };

            // act
            customer = customerDb.AddCustomer(customer);

            // assert
            Assert.IsTrue(customer.Id > 0);
        }
コード例 #3
0
        public void Db_UpdateNonExistentCustomer()
        {
            // arrange
            var customerDb = new CustomerDb(_connectionString);
            var customer   = new Customer.EF.Customer {
                Id = 0, FirstName = "Marli", LastName = "Smith", Password = "******"
            };

            // act
            customer.FirstName = "Marlo";
            customer           = customerDb.UpdateCustomer(customer);

            // assert
            Assert.IsTrue(customer == null);
        }
コード例 #4
0
        public void Api_DeleteNonExistentCustomer_InMemory()
        {
            // arrange
            CustomerController customerController = new CustomerController(new InMemoryCustomerDb());
            var customer = new Customer.EF.Customer {
                Id = 0, FirstName = "John", LastName = "Doddle", Password = "******"
            };

            // act
            var result         = customerController.Delete(customer.Id);
            var notFoundResult = (NotFoundResult)result;

            // assert
            Assert.AreEqual(StatusCodes.Status404NotFound, notFoundResult.StatusCode);
        }
コード例 #5
0
        public void Db_GetCustomerById()
        {
            // arrange
            var customerDb = new CustomerDb(_connectionString);
            var customer   = new Customer.EF.Customer {
                Id = 0, FirstName = "John", LastName = "Doddle", Password = "******"
            };

            // act
            customer = customerDb.AddCustomer(customer);
            customer = customerDb.Customers.SingleOrDefault(c => c.Id == customer.Id);

            // assert
            Assert.IsNotNull(customer);
        }
コード例 #6
0
        public void Db_UpdateCustomer()
        {
            // arrange
            var customerDb = new CustomerDb(_connectionString);
            var customer   = new Customer.EF.Customer {
                Id = 0, FirstName = "Marli", LastName = "Smith", Password = "******"
            };

            // act
            customer           = customerDb.AddCustomer(customer);
            customer.FirstName = "Marlo";
            customer           = customerDb.UpdateCustomer(customer);

            // assert
            Assert.AreEqual(customer.FirstName, "Marlo");
        }
コード例 #7
0
        public void Api_CreateCustomer_InMemory()
        {
            // arrange
            CustomerController customerController = new CustomerController(new InMemoryCustomerDb());
            var customer = new Customer.EF.Customer {
                Id = 0, FirstName = "John", LastName = "Doddle", Password = "******"
            };

            // act
            var result = customerController.Create(customer);

            customer = (Customer.EF.Customer)((OkObjectResult)result).Value;

            // assert
            Assert.IsTrue(customer.Id > 0);
        }
コード例 #8
0
        public void Api_UpdateNonExistentCustomer_InMemory()
        {
            // arrange
            CustomerController customerController = new CustomerController(new InMemoryCustomerDb());
            var customer = new Customer.EF.Customer {
                Id = 0, FirstName = "Marli", LastName = "Smith", Password = "******"
            };

            // act

            customer.FirstName = "Marlo";
            var result         = customerController.Update(customer);
            var notFoundResult = (NotFoundResult)result;

            // assert
            Assert.AreEqual(StatusCodes.Status404NotFound, notFoundResult.StatusCode);
        }
コード例 #9
0
        public void Api_DeleteCustomer()
        {
            // arrange
            CustomerController customerController = new CustomerController(new CustomerDb(_connectionString));
            var customer = new Customer.EF.Customer {
                Id = 0, FirstName = "John", LastName = "Doddle", Password = "******"
            };

            // act
            var result1 = customerController.Create(customer);

            customer = (Customer.EF.Customer)((OkObjectResult)result1).Value;
            var result2 = customerController.Delete(customer.Id);
            var result3 = (bool)((OkObjectResult)result2).Value;

            // assert
            Assert.IsTrue(result3);
        }
コード例 #10
0
        public void Api_GetCustomerById_InMemoryDb()
        {
            // arrange
            CustomerController customerController = new CustomerController(new InMemoryCustomerDb());
            var customer = new Customer.EF.Customer {
                Id = 0, FirstName = "John", LastName = "Doddle", Password = "******"
            };


            // act
            var result1 = customerController.Create(customer);

            customer = (Customer.EF.Customer)((OkObjectResult)result1).Value;
            var result2 = customerController.Get(customer.Id);

            customer = (Customer.EF.Customer)((OkObjectResult)result2).Value;

            // assert
            Assert.IsNotNull(customer);
        }
コード例 #11
0
        public void Api_UpdateCustomer_InMemory()
        {
            // arrange
            CustomerController customerController = new CustomerController(new InMemoryCustomerDb());
            var customer = new Customer.EF.Customer {
                Id = 0, FirstName = "Marli", LastName = "Smith", Password = "******"
            };

            // act
            var result1 = customerController.Create(customer);

            customer = (Customer.EF.Customer)((OkObjectResult)result1).Value;

            customer.FirstName = "Marlo";
            var result2 = customerController.Update(customer);

            customer = (Customer.EF.Customer)((OkObjectResult)result2).Value;

            // assert
            Assert.AreEqual(customer.FirstName, "Marlo");
            Assert.AreEqual(customer.LastName, "Smith");
        }