示例#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
                );
        }
示例#3
0
        public void Index()
        {
            // Disponer
            InsuranceController controller = new InsuranceController();

            // Actuar
            ViewResult result = controller.Index() as ViewResult;

            // Declarar
            Assert.IsNotNull(result);
            Assert.AreEqual("Insurance Page", result.ViewBag.Title);
        }
        public void SetUp()
        {
            controllerContext = new HttpControllerContext();

            HttpContext.Current = new HttpContext(new HttpRequest(null, "http://localhost", null), new HttpResponse(null));

            controllerContext.Request = new HttpRequestMessage();

            controllerContext.Request.Headers.Add("Basic", "password");

            controller = new InsuranceController();

            controller.ControllerContext = controllerContext;
        }
示例#5
0
        public async Task CalculateInsuranceForOrder_GivenOrderEntriesIncludesCamera_ShouldAdd500ToTotalInsuranceValue()
        {
            // Arrange
            var orderEntries = Enumerable.Empty <ProductType>()
                               .Append(new()
            {
                Id           = 0,
                CanBeInsured = true,
                Name         = "Digital cameras"
            });

            var mockRepo = new Mock <IProductTypeRepository>();

            mockRepo.Setup(repo => repo.ListAllAsync())
            .ReturnsAsync(orderEntries);

            var controller = new InsuranceController(_mapper, _logger, mockRepo.Object);
            var input      = Enumerable.Empty <OrderEntryDto>()
                             .Append(new()
            {
                Product = new()
                {
                    ProductTypeId = 0,
                    SalesPrice    = 0f
                },
                Quantity = 2
            });

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

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

            Assert.Equal(
                expected: 500,
                actual: output.InsuranceValue
                );
        }
示例#6
0
        static void Main(string[] args)
        {
            var controller = new InsuranceController();

            controller.Run();
        }
 public void Setup()
 {
     _insuranceCalculatorServiceMock = new Mock <IInsuranceCalculatorService>();
     _sut = new InsuranceController(_insuranceCalculatorServiceMock.Object);
 }
示例#8
0
 static void Main(string[] args)
 {
     var controller = new InsuranceController();
     controller.Run();
 }