Exemplo n.º 1
0
        public void CalculatePremium_WhenPassedBadData_ShouldReturnBadRequestError()
        {
            //Arrange
            UserDto userData = null;

            //Act
            var result = _controller.CalculatePremium(userData);

            //Assert
            Assert.IsInstanceOf <BadRequestObjectResult>(result);
        }
Exemplo n.º 2
0
        public void Should_Return_Bad_Request()
        {
            // Arrange

            validator.Validate(Arg.Any <LifePremiumModel>()).Returns(new LifePremiumModelValidator().Validate(new LifePremiumModel()));

            // Act
            var actionResult = sut.CalculatePremium(new LifePremiumModel());

            // Assert
            Assert.NotNull(actionResult);
            Assert.IsInstanceOf <BadRequestObjectResult>(actionResult.Result);
        }
        public void CalculatePremiumTest()
        {
            MemberModel objMemberModel = new MemberModel
            {
                Name        = "TestName",
                Age         = 20,
                DateOfBirth = DateTime.Now,
                Occupation  = "Doctor",
                SumInsured  = 200000
            };

            decimal expectedOccupationratingfactor = 1.5m;
            decimal expectedPremium = (objMemberModel.SumInsured * expectedOccupationratingfactor * objMemberModel.Age) / 1000 * 12;


            // Arrange
            var mockManager = MockRepository.GenerateMock <IOccupationRepository>();

            mockManager.Expect(x => x.GetOccupationRatingFactor(null)).IgnoreArguments().Return(expectedOccupationratingfactor).Repeat.Any();

            // Act
            var objPremiumController = new PremiumController(mockManager)
            {
                Request       = new HttpRequestMessage(),
                Configuration = new HttpConfiguration()
            };

            objPremiumController.Request = new HttpRequestMessage();
            var result = objPremiumController.CalculatePremium(objMemberModel);

            // Assert
            Assert.AreEqual("OK", result.StatusCode.ToString());
            var actualPremium = JsonConvert.DeserializeObject <decimal>(result.Content.ReadAsStringAsync().Result);

            Assert.AreEqual(expectedPremium, actualPremium);
            mockManager.VerifyAllExpectations();
        }