public void PostOrder_ShouldReturnBadRequestForCustomerThatDoesNotExist()
        {
            // Arrange
            var dataSourceEntities = new UnitTestDataSourceEntities();

            dataSourceEntities.CustomerOrders.Add(new CustomerOrder {
                id = 1, Price = 200, CreatedDate = Convert.ToDateTime("10/7/2017"), CustomerId = 2
            });
            var controller = new CustomersController(dataSourceEntities);

            // Act
            var task_actionResult = controller.PostOrderAsync(new CustomerOrder {
                id = 1, Price = 200, CreatedDate = Convert.ToDateTime("10/7/2017"), CustomerId = 5
            });

            // Assert
            Assert.IsInstanceOfType(task_actionResult.Result, typeof(BadRequestResult)); // Cannot post order for a customer that does not exist
        }
        public void PostOrder_ShouldReturnBadRequestForPostedOrderThatExistsAlready()
        {
            // Arrange
            var dataSourceEntities = new UnitTestDataSourceEntities();

            dataSourceEntities.CustomerOrders.Add(new CustomerOrder {
                id = 1, Price = 200, CreatedDate = Convert.ToDateTime("10/7/2017"), CustomerId = 2
            });
            var controller = new CustomersController(dataSourceEntities);

            // Act
            var task_actionResult = controller.PostOrderAsync(new CustomerOrder {
                id = 1, Price = 200, CreatedDate = Convert.ToDateTime("10/7/2017"), CustomerId = 2
            });
            var result = task_actionResult.Result;

            // Assert
            Assert.IsInstanceOfType(result, typeof(BadRequestResult)); // Returned bad request because order already exists.
        }
        public void PostCustomer_ShouldReturnBadRequestWhenPostedCustomerAlreadyExists()
        {
            // Arrange
            var dataSourceEntities = new UnitTestDataSourceEntities();

            dataSourceEntities.Customers.Add(new Customer {
                id = 4, FirstName = "Ya", LastName = "Is", Email = "Is@g,ail.com"
            });
            var controller = new CustomersController(dataSourceEntities);

            //Act
            var task_actionResult = controller.PostCustomerAsync(new Customer {
                id = 4, FirstName = "Ya", LastName = "Is", Email = "Is@g,ail.com"
            });
            var result = task_actionResult.Result;

            //Assert
            Assert.IsInstanceOfType(result, typeof(BadRequestResult)); // Returned bad request for a customer that already exists
        }
        public void PostOrder_ShouldReturnThePostedOrderOnSuccess()
        {
            //Arrange
            var dataSourceEntities = new UnitTestDataSourceEntities();

            dataSourceEntities.CustomerOrders.Add(new CustomerOrder {
                id = 1, Price = 100, CreatedDate = Convert.ToDateTime("10/7/2017"), CustomerId = 2
            });
            var controller = new CustomersController(dataSourceEntities);

            //Arrange
            var task_actionResult = controller.PostOrderAsync(new CustomerOrder {
                id = 2, Price = 200, CreatedDate = Convert.ToDateTime("5/6/2016"), CustomerId = 2
            });
            var actionResult = task_actionResult.Result;
            var content      = actionResult as NegotiatedContentResult <CustomerOrder>;

            //Assert
            Assert.IsNotNull(content);                                                    // Should not be null for a successful post
            Assert.AreEqual(Convert.ToDateTime("5/6/2016"), content.Content.CreatedDate); // The created date of a returned content should match with one posted
            Assert.AreEqual(200, content.Content.Price);                                  // The price of returned content should match with one posted
        }