コード例 #1
0
        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);
        }
コード例 #2
0
        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);
        }
コード例 #3
0
        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);
        }
コード例 #4
0
        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);
        }
コード例 #5
0
        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);
        }