示例#1
0
        public async Task CalculateInsuranceForProduct_GivenSalesPriceOver2000Euros_ShouldAdd2000ToInsuranceValue()
        {
            // Arrange.
            var productType = new ProductType()
            {
                CanBeInsured = true,
            };

            var mockRepo = new Mock <IProductTypeRepository>();

            mockRepo.Setup(repo => repo.GetByIdAsync(0))
            .ReturnsAsync(productType);

            var controller = new InsuranceController(_mapper, _logger, mockRepo.Object);

            var input = new ProductDto
            {
                SalesPrice = 666
            };

            // Act.
            var result = await controller.CalculateInsuranceForProductAsync(input);

            // Assert.
            var requestResult = Assert.IsType <OkObjectResult>(result);
            var output        = Assert.IsType <InsuredProductDto>(requestResult.Value);

            Assert.Equal(
                expected: 1000,
                actual: output.InsuranceValue
                );
        }
示例#2
0
        public async Task CalculateInsuranceForProduct_GivenSalesPriceBelow500_ShouldHaveNoInsuranceValue()
        {
            // Arrange
            var mockRepo = new Mock <IProductTypeRepository>();

            mockRepo.Setup(repo => repo.GetByIdAsync(0))
            .ReturnsAsync(new ProductType()
            {
                CanBeInsured = true
            });

            var controller = new InsuranceController(_mapper, _logger, mockRepo.Object);

            var input = new ProductDto
            {
                SalesPrice = 299
            };

            // Act
            var result = await controller.CalculateInsuranceForProductAsync(input);

            // Assert
            var requestResult = Assert.IsType <OkObjectResult>(result);
            var output        = Assert.IsType <InsuredProductDto>(requestResult.Value);

            Assert.Equal(
                expected: 0,
                actual: output.InsuranceValue
                );
        }