Beispiel #1
0
        public async Task TestPostPaymentValid()
        {
            // Arrange
            var mockPaymentRepo  = new Mock <IPaymentRepository>();
            var mockCustomerRepo = new Mock <ICustomerRepository>();
            var paymentDTO       = CreatePaymentData();

            mockPaymentRepo.Setup(repo => repo.GetPaymentFromCustomer(paymentDTO.CustomerId))
            .ReturnsAsync(paymentDTO);
            mockCustomerRepo.Setup(repo => repo.GetCustomer(paymentDTO.CustomerId))
            .ReturnsAsync(paymentDTO.Customer);

            // Act
            var controller = new PaymentsController(mockPaymentRepo.Object, mockCustomerRepo.Object);

            SimulateModelValidation.Validate(mockPaymentRepo, controller);
            var result = await controller.PostPayment(paymentDTO);

            // Assert
            var okResult = Assert.IsType <CreatedAtActionResult>(result);
            var res      = Assert.IsType <Payment>(okResult.Value);
            var idea     = res as Payment;

            Assert.Equal(1, idea.PaymentId);
            Assert.NotNull(idea.Customer);
            Assert.NotNull(idea.Domain);
            Assert.Equal(GetLastDayOfMonth(), idea.DueDate);
            Assert.Equal(PaymentStatus.CREATED, idea.Status);
        }
Beispiel #2
0
        public async Task TestPostDomainsValidDomainName()
        {
            // Arrange
            var domainDTO   = CreateDomainTestData()[0];
            var customerDTO = CreateCustomerData()[0];

            var mockDomainRepo   = new Mock <IDomainRepository>();
            var mockCustomerRepo = new Mock <ICustomerRepository>();
            var mockVerifyRepo   = new Mock <IVerificationProviderRepository>();

            mockDomainRepo.Setup(repo => repo.AddDomain(domainDTO))
            .ReturnsAsync(domainDTO);
            mockCustomerRepo.Setup(repo => repo.GetCustomer(1))
            .ReturnsAsync(customerDTO);
            mockVerifyRepo.Setup(repo => repo.GetAllByName(customerDTO.ProviderName))
            .Returns(CreateVerificationProvider());

            // Act
            var controller = new DomainsController(mockDomainRepo.Object, mockCustomerRepo.Object);

            SimulateModelValidation.Validate(domainDTO, controller);
            var result = await controller.PostDomain(domainDTO, TimeDuration.YEAR, 1);

            // Assert
            var okResult = Assert.IsType <CreatedAtActionResult>(result);
            var res      = Assert.IsType <Domain>(okResult.Value);
            var idea     = res as Domain;

            Assert.Equal(1, idea.DomainId);
            Assert.Equal("abcdefghi.software", idea.Name);
            Assert.Equal(DateTime.Today.AddYears(1), idea.ExpiriationDate);
        }
Beispiel #3
0
        public async Task TestPostInvalidDomainName()
        {
            // Arrange
            var domainDTO   = CreateDomainTestData()[1];
            var customerDTO = CreateCustomerData()[0];


            var mockDomainRepo   = new Mock <IDomainRepository>();
            var mockCustomerRepo = new Mock <ICustomerRepository>();
            var mockVerifyRepo   = new Mock <IVerificationProviderRepository>();

            mockDomainRepo.Setup(repo => repo.AddDomain(domainDTO))
            .ReturnsAsync(domainDTO);
            mockCustomerRepo.Setup(repo => repo.GetCustomer(1))
            .ReturnsAsync(customerDTO);

            // Act
            var controller = new DomainsController(mockDomainRepo.Object, mockCustomerRepo.Object);

            SimulateModelValidation.Validate(domainDTO, controller);
            var result = await controller.PostDomain(domainDTO, TimeDuration.YEAR, 1);

            // Assert
            Assert.IsType <BadRequestObjectResult>(result);
        }
Beispiel #4
0
        public async Task TestPostPaymentNoAmount()
        {
            // Arrange
            var mockPaymentRepo  = new Mock <IPaymentRepository>();
            var mockCustomerRepo = new Mock <ICustomerRepository>();
            var paymentDTO       = CreatePaymentData();

            paymentDTO.Amount = 0;
            mockPaymentRepo.Setup(repo => repo.GetPaymentFromCustomer(paymentDTO.CustomerId))
            .ReturnsAsync(paymentDTO);
            mockCustomerRepo.Setup(repo => repo.GetCustomer(paymentDTO.CustomerId))
            .ReturnsAsync(paymentDTO.Customer);

            // Act
            var controller = new PaymentsController(mockPaymentRepo.Object, mockCustomerRepo.Object);

            SimulateModelValidation.Validate(mockPaymentRepo, controller);
            var result = await controller.PostPayment(paymentDTO);

            // Assert
            Assert.IsType <BadRequestObjectResult>(result);
        }
Beispiel #5
0
        public async Task TestPutPaymentAmount(decimal amountPaid)
        {
            // Arrange
            var mockPaymentRepo  = new Mock <IPaymentRepository>();
            var mockCustomerRepo = new Mock <ICustomerRepository>();
            var paymentDTO       = CreatePaymentData();

            paymentDTO.AmountPaid = amountPaid;

            mockPaymentRepo.Setup(repo => repo.GetPaymentFromCustomer(paymentDTO.CustomerId))
            .ReturnsAsync(paymentDTO);
            mockCustomerRepo.Setup(repo => repo.GetCustomer(paymentDTO.CustomerId))
            .ReturnsAsync(paymentDTO.Customer);

            // Act
            var controller = new PaymentsController(mockPaymentRepo.Object, mockCustomerRepo.Object);

            SimulateModelValidation.Validate(mockPaymentRepo, controller);
            var result = await controller.PutPayment(paymentDTO.PaymentId, paymentDTO);

            // Assert
            var okResult = Assert.IsType <OkObjectResult>(result);
            var res      = Assert.IsType <Payment>(okResult.Value);
            var idea     = res as Payment;

            Assert.Equal(1, idea.PaymentId);
            Assert.NotNull(idea.Customer);
            Assert.NotNull(idea.Domain);
            if (paymentDTO.Amount == 0)
            {
                Assert.Equal(PaymentStatus.COMPLETE, idea.Status);
                Assert.Null(idea.DueDate);
            }
            else
            {
                Assert.NotNull(idea.DueDate);
                Assert.Equal(PaymentStatus.PROCESSING, idea.Status);
            }
        }