Beispiel #1
0
        public void CreateMethodSetsLocationHeader()
        {
            // Arrange
            var mockRepository = new Mock <IClaimRepository>();

            var service    = new ClaimService(mockRepository.Object);
            var controller = new ClaimController(service);

            // Act
            IHttpActionResult actionResult = controller.CreateClaim(new ClaimBusinessEntities.Claim
            {
                ClaimNumber       = "testClaimNo",
                ClaimantFirstName = "test",
                Vehicles          = new List <ClaimBusinessEntities.VehicleDetails>()
                {
                    new ClaimBusinessEntities.VehicleDetails()
                    {
                        VehicleId = 2, Vin = "100"
                    }
                }
            });
            var createdResult = actionResult as CreatedAtRouteNegotiatedContentResult <ClaimBusinessEntities.Claim>;

            // Assert
            Assert.IsNotNull(createdResult);
            Assert.AreEqual("GetByClaimNo", createdResult.RouteName);
            Assert.AreEqual("testClaimNo", createdResult.RouteValues["claimNo"]);
        }
Beispiel #2
0
        public void ExpenseClaim_ClaimController_POSTExpense_ShouldGetCreated()
        {
            var mockInvalidxMLChar              = new Mock <IRemoveInvalidCharFromXML>();
            var mockClaimRepository             = new Mock <IClaimRepository>();
            IRemoveInvalidCharFromXML removeXml = new RemoveInvalidCharFromXML();
            var mockLogger = Mock.Of <ILogger <ClaimController> >();

            mockClaimRepository.Setup(a => a.AddClaim(mockExpenseResult.FirstOrDefault()));
            mockClaimRepository.Setup(a => a.Save()).Returns(true);

            mockInvalidxMLChar.Setup(a => a.GetCleanXML(GetTestSessionExpenseEmail())).Returns(removeXml.GetCleanXML(GetTestSessionExpenseEmail()));

            var controller = new ClaimController(mockClaimRepository.Object, mockInvalidxMLChar.Object, mockLogger);

            var objectValidator = new Mock <IObjectModelValidator>();

            objectValidator.Setup(o => o.Validate(It.IsAny <ActionContext>(),
                                                  It.IsAny <ValidationStateDictionary>(),
                                                  It.IsAny <string>(),
                                                  It.IsAny <Object>()));
            controller.ObjectValidator = objectValidator.Object;

            var actionResult = controller.CreateClaim(GetTestSessionExpenseEmail());
            var okResult     = actionResult as CreatedAtRouteResult;

            Assert.Equal(201, okResult.StatusCode);
        }
Beispiel #3
0
        public void CreateMethodReturnsBadRequest()
        {
            // Arrange
            var mockRepository = new Mock <IClaimRepository>();

            var service    = new ClaimService(mockRepository.Object);
            var controller = new ClaimController(service);

            // Act
            IHttpActionResult actionResult = controller.CreateClaim(null);

            // Assert
            Assert.IsInstanceOfType(actionResult, typeof(BadRequestResult));
        }