public void PostCustomerCreatesCustomer()
        {
            //Arrange
            var customerController = new CustomersController();

            //Act
            var newCustomer = new CustomerModel
            {
                FirstName = "Testy",
                LastName = "McTesterson",
                Address1 = "123 Main Street",
                Address2 = "Suite 2",
                City = "San Diego",
                States = "CA",
                Zip = "92101"
            };

            //The result of the Post Request
            IHttpActionResult result = customerController.PostCustomer(newCustomer);

            //Assert

            //If not 'true' Assert False
            Assert.IsInstanceOfType(result, typeof(CreatedAtRouteNegotiatedContentResult<CustomerModel>));

            //Cast
            CreatedAtRouteNegotiatedContentResult<CustomerModel> contentResult = (CreatedAtRouteNegotiatedContentResult<CustomerModel>)result;

            //Check if Customer is posted to the database
            //Check to see if Customer ID is NOT equal to zero.  If Customer Id us equal to zero,
            //then customer was NOT added to Database
            Assert.IsTrue(contentResult.Content.CustomerId != 0);
        }
        public void DeleteCustomerDeletesCustomer()
        {
            //Arrange:
            // Instantiate CustomersController so its methods can be called
            // Create a new customer to be deleted, and get its customer ID
            var customerController = new CustomersController();

            var customer = new CustomerModel
            {
                FirstName = "Jim",
                LastName = "McDonald",
                Address1 = "Farm",
                Address2 = "Yard",
                City = "Denver",
                State = "CO",
                Zip = "56432"
            };
            IHttpActionResult result = customerController.PostCustomer(customer);
            CreatedAtRouteNegotiatedContentResult<CustomerModel> contentResult =
                (CreatedAtRouteNegotiatedContentResult<CustomerModel>)result;

            int customerIdToDelete = contentResult.Content.CustomerId;

            //Act: Call DeleteCustomer
            result = customerController.DeleteCustomer(customerIdToDelete);

            //Assert:
            // Verify that HTTP result is OK
            // Verify that reading deleted customer returns result not found
            Assert.IsInstanceOfType(result, typeof(OkNegotiatedContentResult<Customer>));

            result = customerController.GetCustomer(customerIdToDelete);
            Assert.IsInstanceOfType(result, typeof(NotFoundResult));
        }
        public void PutCustomerUpdatesCustomer()
        {
            //Arrange
            var cusomersContoller = new CustomersController();

            var newCustomer = new CustomerModel
            {
                FirstName = "Testy",
                LastName = "McTesterson",
                Address1 = "123 Main Street",
                Address2 = "Suite 2",
                City = "San Diego",
                States = "CA",
                Zip = "92101"
            };

            //The result of the Post Request
            IHttpActionResult result = cusomersContoller.PostCustomer(newCustomer);

            //Cast result as Content Result so that I can gather information from ContentResult
            CreatedAtRouteNegotiatedContentResult<CustomerModel> contentResult = (CreatedAtRouteNegotiatedContentResult<CustomerModel>)result;


            //Result contains the customer I had JUST createad
            result = cusomersContoller.GetCustomer(contentResult.Content.CustomerId);

            //Get CustomerModel from 'result'
            OkNegotiatedContentResult<CustomerModel> customerResult = (OkNegotiatedContentResult<CustomerModel>)result;


            //Act
            //The result of the Put Request
            result = cusomersContoller.PutCustomer(customerResult.Content.CustomerId, newCustomer);

            //Assert
            Assert.IsInstanceOfType(result, typeof(StatusCodeResult));

        }
        public void DeleteCustomerRecord()
        {
            //Arrange
            //Create Controller
            var customersController = new CustomersController();

            //Create a customer to be deleted
            var dbCustomer = new CustomerModel
            {
                FirstName = "Testy",
                LastName = "McTesterson",
                Address1 = "123 Main Street",
                Address2 = "Suite 2",
                City = "San Diego",
                States = "CA",
                Zip = "92101",
           
            };

            //Add 'new customer' to the DB using a POST
            //Save returned value as RESULT
            IHttpActionResult result = customersController.PostCustomer(dbCustomer);

            //Cast result as Content Result so that I can gather information from ContentResult
            CreatedAtRouteNegotiatedContentResult<CustomerModel> contentResult = (CreatedAtRouteNegotiatedContentResult<CustomerModel>)result;


            //Result contains the customer I had JUST createad
            result = customersController.GetCustomer(contentResult.Content.CustomerId);

            //Get CustomerModel from 'result'
            OkNegotiatedContentResult<CustomerModel> customerResult = (OkNegotiatedContentResult<CustomerModel>)result;


            //Act
            //The result of the Delete Request
             result = customersController.DeleteCustomer(customerResult.Content.CustomerId);

            //Assert

            //If action returns: NotFound()
            Assert.IsNotInstanceOfType(result, typeof(NotFoundResult));

            Assert.IsInstanceOfType(result, typeof(OkNegotiatedContentResult<CustomerModel>));         
        }
        public void PostCustomerCreatesCustomer()
        {
            //Arrange: Instantiate CustomersController so its methods can be called
            var customerController = new CustomersController();

            //Act:
            // Create a CustomerModel object populated with test data,
            //  and call PostCustomer
            var newCustomer = new CustomerModel
            {
                FirstName = "Testy",
                LastName = "McTesterson",
                Address1 = "Land of QA",
                Address2 = "34 Broome St",
                City = "San Francisco",
                State = "CA",
                Zip = "92456"
            };
            IHttpActionResult result = customerController.PostCustomer(newCustomer);

            //Assert:
            // Verify that the HTTP result is CreatedAtRouteNegotiatedContentResult
            // Verify that the HTTP result body contains a nonzero customer ID
            Assert.IsInstanceOfType
                (result, typeof(CreatedAtRouteNegotiatedContentResult<CustomerModel>));
            CreatedAtRouteNegotiatedContentResult<CustomerModel> contentResult =
                (CreatedAtRouteNegotiatedContentResult<CustomerModel>)result;
            Assert.IsTrue(contentResult.Content.CustomerId != 0);

            // Delete the test customer
            result = customerController.DeleteCustomer(contentResult.Content.CustomerId);
        }