public void UpdateCustomer_ReturnsOk() { // Arrange int id = 1; var customer = new CustomerDto() { AddressId = 1, PricingPackageId = 1, CustomerName = "firstname" }; // Act var mockRepo = new Mock <ICustomerRepository>(); mockRepo.Setup(x => x.CreateCustomer(It.IsAny <CustomerDto>())).Returns(customer); mockRepo.Setup(x => x.EditCustomer(id, It.IsAny <CustomerDto>())).Returns(true); var customerManipulation = new CustomerManipulation(mockRepo.Object); var controller = new CustomersController(customerManipulation); controller.CreateNewCustomer(customer); //update attributes customer.CustomerName = "Johndoe"; var result = controller.EditCustomer(id, customer); // Assert Assert.IsType <OkObjectResult>(result); }
public void GetCustomerById_ReturnsNotFound_GivenBadId() { // Arrange var customersRepo = new Mock <ICustomerRepository>(); customersRepo.Setup(x => x.GetCustomerById(It.IsAny <int>())).Returns((CustomerDto)null); var customersManipulation = new CustomerManipulation(customersRepo.Object); var controller = new CustomersController(customersManipulation); // Act var result = controller.GetCustomerById(1); // Assert Assert.IsType <NotFoundObjectResult>(result); }
public void DeleteCustomer_ReturnsNotFound_GivenBadId() { var customersRepo = new Mock <ICustomerRepository>(); customersRepo.Setup(x => x.DeleteCustomerById(It.IsAny <int>())).Returns(false); var customersManipulation = new CustomerManipulation(customersRepo.Object); var controller = new CustomersController(customersManipulation); int id = 100; // Act var result = controller.DeleteCustomer(id); // Assert Assert.IsType <NotFoundObjectResult>(result); }
public void CreateCustomerBadRequest() { // Arrange int id = 1; var customer = new CustomerDto() { AddressId = 1, PricingPackageId = 1, CustomerName = "firstname" }; var customersRepo = new Mock <ICustomerRepository>(); customersRepo.Setup(x => x.CreateCustomer(It.IsAny <CustomerDto>())).Throws <NSIException>(); var customersManipulation = new CustomerManipulation(customersRepo.Object); var controller = new CustomersController(customersManipulation); var result = controller.CreateNewCustomer(customer); Assert.IsType <BadRequestObjectResult>(result); }
public void GetCustomerById_ReturnsOK() { // Arrange int id = 1; var customer = new CustomerDto() { AddressId = 1, PricingPackageId = 1, CustomerName = "firstname" }; var customersRepo = new Mock <ICustomerRepository>(); customersRepo.Setup(x => x.GetCustomerById(It.IsAny <int>())).Returns(customer); var customersManipulation = new CustomerManipulation(customersRepo.Object); var controller = new CustomersController(customersManipulation); // Act var result = controller.GetCustomerById(1); // Assert Assert.IsType <OkObjectResult>(result); }