Exemplo n.º 1
0
        public void Post_should_respond_Quote()
        {
            Quote quote      = GetNormalQuote();
            var   response   = controller.Post(quote);
            var   viewResult = Assert.IsType <OkObjectResult>(response);
            var   answer     = viewResult.Value as QuoteResponse;

            Assert.NotNull(answer);
        }
Exemplo n.º 2
0
        public void Should_return_bad_request_if_quoteRequest_fails_validation()
        {
            var quoteRequest = new BenefitsCostQuoteRequest();
            var quote        = new Quote();
            var mockService  = new Mock <IQuoteService>();

            mockService
            .Setup(x => x.GenerateQuote(It.IsAny <string>(), It.IsAny <string[]>()))
            .Returns(quote);

            var mockMapper = new Mock <IMapper>();

            mockMapper
            .Setup(m => m.Map <BenefitsCostQuoteResult>(It.IsAny <Quote>()))
            .Returns(new BenefitsCostQuoteResult());

            var controller = new QuoteController(mockService.Object, mockMapper.Object);


            var actionResult = controller.Post(quoteRequest);

            Assert.IsType <BadRequestResult>(actionResult);
        }
Exemplo n.º 3
0
        public void Should_generate_a_quote()
        {
            var quoteRequest = new BenefitsCostQuoteRequest {
                EmployeeId = "1"
            };
            var quote = new Quote();

            var mockService = new Mock <IQuoteService>();

            mockService
            .Setup(x => x.GenerateQuote(It.IsAny <string>(), It.IsAny <string[]>()))
            .Returns(quote);

            var mockMapper = new Mock <IMapper>();

            var controller = new QuoteController(mockService.Object, mockMapper.Object);


            var actionResult = controller.Post(quoteRequest);


            mockService.Verify(es => es.GenerateQuote(It.IsAny <string>(), It.IsAny <string[]>()), Times.Once);
        }
Exemplo n.º 4
0
        public async Task PostAsync()
        {
            // Act
            var createQuoteModel = new CreateQuoteModel
            {
                ClientName       = "ClientName 1",
                DateofBirth      = new DateTime(1992, 09, 09),
                ClientSex        = ClientSex.Male,
                Email            = "*****@*****.**",
                MobileNumber     = "1234567880",
                RetirementAge    = 62,
                InvestmentAmount = 100000,
                PensionPlan      = PensionPlan.PensionSilver
            };
            var result = await controller.Post(createQuoteModel) as CreatedResult;

            // Assert
            Assert.NotNull(result);
            Assert.AreEqual(201, result.StatusCode);
            var responseQuoteModel = result.Value as ResponseQuoteModel;

            Assert.NotNull(responseQuoteModel);
            Assert.AreEqual("ClientName 1", responseQuoteModel.ClientName);
        }
Exemplo n.º 5
0
        public async Task PostThrowsExceptionAsync()
        {
            // Act
            var createQuoteModel = new CreateQuoteModel
            {
                ClientName       = "ClientName 1",
                DateofBirth      = new DateTime(1992, 09, 09),
                ClientSex        = ClientSex.Male,
                Email            = "*****@*****.**",
                MobileNumber     = "1234567880",
                RetirementAge    = 62,
                InvestmentAmount = 100000,
                PensionPlan      = PensionPlan.PensionSilver
            };

            mediatR.Setup(m => m.Send(It.IsAny <CreateQuoteRequest>(), It.IsAny <CancellationToken>())).Throws(new InvalidOperationException());
            controller = new QuoteController(mapper, mediatR.Object);
            var result = await controller.Post(createQuoteModel) as ObjectResult;

            // Assert
            Assert.NotNull(result);
            Assert.AreEqual(400, result.StatusCode);
            Assert.AreEqual("Operation is not valid due to the current state of the object.", result.Value);
        }
Exemplo n.º 6
0
        public async Task PostNullMediatorResponseAsync()
        {
            // Act
            var createQuoteModel = new CreateQuoteModel
            {
                ClientName       = "ClientName 1",
                DateofBirth      = new DateTime(1992, 09, 09),
                ClientSex        = ClientSex.Male,
                Email            = "*****@*****.**",
                MobileNumber     = "1234567880",
                RetirementAge    = 62,
                InvestmentAmount = 100000,
                PensionPlan      = PensionPlan.PensionSilver
            };

            mediatR.Setup(m => m.Send(It.IsAny <CreateQuoteRequest>(), It.IsAny <CancellationToken>())).Returns(Task.FromResult <Quote>(null));
            controller = new QuoteController(mapper, mediatR.Object);
            var result = await controller.Post(createQuoteModel) as ObjectResult;

            // Assert
            Assert.NotNull(result);
            Assert.AreEqual(409, result.StatusCode);
            Assert.AreEqual("Error Occurred While Creating a Quote", result.Value);
        }