Esempio n. 1
0
 public void GetClaim_ClaimNotExists()
 {
     try
     {
         _claimsController.Get("test.performance.a");
     }
     catch (ResponseException) { }
 }
Esempio n. 2
0
        public void ClaimsController_Get()
        {
            ClaimsController _controller = new ClaimsController(_mockService.Object, _logger.Object);
            var result = _controller.Get();

            Assert.IsNotNull(result);
        }
Esempio n. 3
0
        public async Task GetClaims()
        {
            // Arrange
            var mockRepository = new Mock <IRepositoryClaims>();

            mockRepository.Setup(c => c.Get(Guid.Parse("5570d15a-b679-4f20-83f8-f96b2b3b9bc8")))
            .ReturnsAsync(new Claim
            {
                ClaimId     = Guid.Parse("5570d15a-b679-4f20-83f8-f96b2b3b9bc8"),
                Description = "Mocked claim number 1",
                Payout      = 2000
            });

            var controller = new ClaimsController(mockRepository.Object);

            // Act
            var result = await controller.Get(Guid.Parse("5570d15a-b679-4f20-83f8-f96b2b3b9bc8"));


            var contentResult = result as OkObjectResult;
            var returnValue   = contentResult.Value as Claim;

            // Assert
            Assert.AreEqual(contentResult.StatusCode, 200);
            Assert.IsNotNull(returnValue);
            Assert.AreEqual(Guid.Parse("5570d15a-b679-4f20-83f8-f96b2b3b9bc8"), returnValue.ClaimId);
        }
Esempio n. 4
0
        public void TestDeleteNotExistentClaim()
        {
            string        newClaimNumber = TestDataGenerator.GenerateUniqueClaimNumber();
            MitchellClaim testClaim      = TestDataGenerator.GetTestClaim(newClaimNumber);

            HttpResponseMessage response = ClaimsController.Post(testClaim);

            Assert.AreEqual(HttpStatusCode.Created, response.StatusCode, "A POST of a new claim should succeed.");

            MitchellClaim retrievedClaim = ClaimsController.Get(newClaimNumber);

            Assert.AreEqual(testClaim, retrievedClaim, "The posted and retrieved claim should have the same values.");

            response = ClaimsController.Delete(newClaimNumber);
            Assert.AreEqual(HttpStatusCode.OK, response.StatusCode, "Deleting an existing claim should succeed.");

            try
            {
                response = ClaimsController.Delete(newClaimNumber);
                Assert.Fail("An attempt to delete a claim that does not exist should result in an error.");
            }
            catch (HttpResponseException ex) when(ex.Response.StatusCode == HttpStatusCode.NotFound)
            {
                // This is the expected behavior
            }
        }
Esempio n. 5
0
        public void TestPutWithRequiredParametersNotSpecified()
        {
            string        newClaimNumber = TestDataGenerator.GenerateUniqueClaimNumber();
            MitchellClaim expectedClaim  = TestDataGenerator.GetTestClaim(newClaimNumber);

            // Create a new claim
            HttpResponseMessage response = ClaimsController.Post(expectedClaim);

            Assert.AreEqual(HttpStatusCode.Created, response.StatusCode, "A POST of a new claim should succeed.");

            // Prepare a claim "updater".
            MitchellClaim updater = new MitchellClaim();

            updater.ClaimantLastName = "NewLastName";

            updater.Vehicles = new List <VehicleDetails>();

            // We'll request a new vehicle to be added. However, this vehicle has required parameters that are not specified.
            updater.Vehicles.Add(new VehicleDetails()
            {
                Vin = TestDataGenerator.GenerateUniqueVinNumber(), Mileage = 100
            });

            // Update the claim.
            response = ClaimsController.Put(newClaimNumber, updater);
            Assert.AreEqual(HttpStatusCode.Forbidden, response.StatusCode, "An update of a claim that would results in required fields that are not specified should fail with a specific status.");

            // Retrieved the claim we attempted to update and make sure it did not change.
            MitchellClaim retrievedClaim = ClaimsController.Get(newClaimNumber);

            Assert.AreEqual(expectedClaim, retrievedClaim, "The claim that was subject to a failed update should not have changed.");
        }
Esempio n. 6
0
        public void TestPutClaimWithEmptyVehicleList()
        {
            string        newClaimNumber = TestDataGenerator.GenerateUniqueClaimNumber();
            MitchellClaim expectedClaim  = TestDataGenerator.GetTestClaim(newClaimNumber);

            // Create a new claim
            HttpResponseMessage response = ClaimsController.Post(expectedClaim);

            Assert.AreEqual(HttpStatusCode.Created, response.StatusCode, "A POST of a new claim should succeed.");

            // Prepare a claim "updater".
            MitchellClaim updater = new MitchellClaim();

            updater.ClaimantLastName       = "NewLastName";
            expectedClaim.ClaimantLastName = updater.ClaimantLastName;

            updater.Vehicles = new List <VehicleDetails>();

            // Update the claim.
            response = ClaimsController.Put(newClaimNumber, updater);
            Assert.AreEqual(HttpStatusCode.Forbidden, response.StatusCode, "An update request where the updater has an empty vehicle list is not legal.");

            // Retrieved the claim we attempted to update and make sure it did not change.
            MitchellClaim retrievedClaim = ClaimsController.Get(newClaimNumber);

            Assert.AreEqual(expectedClaim, retrievedClaim, "The claim that was subject to a failed update should not have changed.");
        }
Esempio n. 7
0
        public void TestPutClaimWithNoVehicleList()
        {
            string        newClaimNumber = TestDataGenerator.GenerateUniqueClaimNumber();
            MitchellClaim expectedClaim  = TestDataGenerator.GetTestClaim(newClaimNumber);

            // Create a new claim
            HttpResponseMessage response = ClaimsController.Post(expectedClaim);

            Assert.AreEqual(HttpStatusCode.Created, response.StatusCode, "A POST of a new claim should succeed.");

            // Prepare a claim "updater".
            MitchellClaim updater = new MitchellClaim();

            updater.ClaimantLastName       = "NewLastName";
            expectedClaim.ClaimantLastName = updater.ClaimantLastName;

            // Update the claim.
            response = ClaimsController.Put(newClaimNumber, updater);
            Assert.AreEqual(HttpStatusCode.OK, response.StatusCode, "A PUT of an existing claim should succeed.");

            // Retrieved the updated claim and compare it with the expected value.
            MitchellClaim retrievedClaim = ClaimsController.Get(newClaimNumber);

            Assert.AreEqual(expectedClaim.Vehicles.Count, 2, "Defensive check - making sure that the expected claim was setup correctly.");
            Assert.AreEqual(expectedClaim, retrievedClaim, "The claim that was created, updated and retrieved should have the expected values.");
        }
Esempio n. 8
0
        //[TestMethod]
        async public Task GetAllClaims()
        {
            var result = await controller.Get();

            OkNegotiatedContentResult <IEnumerable <MitchellClaimType> > conNegResult = result as OkNegotiatedContentResult <IEnumerable <MitchellClaimType> >;

            Assert.IsTrue(conNegResult != null && conNegResult.Content.GetEnumerator().MoveNext());
        }
        public async Task Get_ExistedClaimIdPassed_ProperMethodsCalledAndReturnMatchedClaim()
        {
            _mediatorMock.Setup(mediator => mediator.Send(It.IsAny <GetClaimQuery>(), It.IsAny <CancellationToken>())).ReturnsAsync(new ClaimDTO()).Verifiable();
            //Act
            var controller = new ClaimsController(_mediatorMock.Object);
            var result     = await controller.Get(1);

            //Assert
            Assert.NotNull(result.Value);
            _mediatorMock.Verify();
        }
Esempio n. 10
0
        public async Task Get_UnexistedClaimIdPassed_ProperMethodsCalledAndReturnNotFoundResult()
        {
            _mediatorMock.Setup(mediator => mediator.Send(It.IsAny <GetClaimQuery>(), It.IsAny <CancellationToken>())).ReturnsAsync((ClaimDTO)null).Verifiable();
            //Act
            var controller = new ClaimsController(_mediatorMock.Object);
            var result     = await controller.Get(1);

            //Assert
            Assert.True(((StatusCodeResult)result.Result).StatusCode == (int)HttpStatusCode.NotFound);
            _mediatorMock.Verify();
        }
Esempio n. 11
0
        public void TestPutClaimAndAddNewVehicle()
        {
            string        newClaimNumber = TestDataGenerator.GenerateUniqueClaimNumber();
            MitchellClaim expectedClaim  = TestDataGenerator.GetTestClaim(newClaimNumber);

            // Create a new claim
            HttpResponseMessage response = ClaimsController.Post(expectedClaim);

            Assert.AreEqual(HttpStatusCode.Created, response.StatusCode, "A POST of a new claim should succeed.");

            // Prepare a claim "updater".
            MitchellClaim updater = new MitchellClaim();

            updater.ClaimantLastName       = "NewLastName";
            expectedClaim.ClaimantLastName = updater.ClaimantLastName;

            // Note:  The updater will have to include both vehicles that are changed and those who are not changed.
            //        The vehicles that are not changed will only have the Vin field set.
            //        This system enables us to delete vehicles with the update request. The tread-off is that when we
            //        specify a list of vehicles then that list must include vehicles that are not changed.
            updater.Vehicles = new List <VehicleDetails>();

            updater.Vehicles.Add(new VehicleDetails()
            {
                Vin = expectedClaim.Vehicles[0].Vin
            });
            updater.Vehicles.Add(new VehicleDetails()
            {
                Vin = expectedClaim.Vehicles[1].Vin
            });

            // We'll request a new vehicle to be added. However, this vehicle has required parameters that are not specified.
            VehicleDetails newVehicle = new VehicleDetails()
            {
                Vin       = TestDataGenerator.GenerateUniqueVinNumber(),
                ModelYear = 2015,
                Mileage   = 200
            };

            updater.Vehicles.Add(newVehicle);
            expectedClaim.Vehicles.Add(newVehicle.DeepClone());

            // Update the claim.
            response = ClaimsController.Put(newClaimNumber, updater);
            Assert.AreEqual(HttpStatusCode.OK, response.StatusCode, "A PUT of an existing claim should succeed.");

            // Retrieved the updated claim and compare it with the expected value.
            MitchellClaim retrievedClaim = ClaimsController.Get(newClaimNumber);

            Assert.AreEqual(expectedClaim.Vehicles.Count, 3, "Defensive check - making sure that the expected claim was setup correctly.");
            Assert.AreEqual(expectedClaim, retrievedClaim, "The claim that was created, updated and retrieved should have the expected values.");
        }
Esempio n. 12
0
        public void TestPostSimple()
        {
            string        newClaimNumber = TestDataGenerator.GenerateUniqueClaimNumber();
            MitchellClaim testClaim      = TestDataGenerator.GetTestClaim(newClaimNumber);

            HttpResponseMessage response = ClaimsController.Post(testClaim);

            Assert.AreEqual(HttpStatusCode.Created, response.StatusCode, "A POST of a new claim should succeed.");

            MitchellClaim retrievedClaim = ClaimsController.Get(newClaimNumber);

            Assert.AreEqual(testClaim, retrievedClaim, "The posted and retrieved claim should have the same values.");
        }
Esempio n. 13
0
        public async Task Get_ProperMethodsCalledAndReturnListOfClaims()
        {
            _mediatorMock.Setup(mediator => mediator.Send(It.IsAny <GetAllClaimsQuery>(), It.IsAny <CancellationToken>())).ReturnsAsync(new List <ClaimDTO> {
                new ClaimDTO(), new ClaimDTO()
            }).Verifiable();
            //Act
            var controller = new ClaimsController(_mediatorMock.Object);
            var result     = await controller.Get();

            //Assert
            Assert.NotNull(result);
            Assert.Equal(2, result.Count());
        }
Esempio n. 14
0
        public void TestPutSimple()
        {
            string        newClaimNumber = TestDataGenerator.GenerateUniqueClaimNumber();
            MitchellClaim expectedClaim  = TestDataGenerator.GetTestClaim(newClaimNumber);

            // Create a new claim
            HttpResponseMessage response = ClaimsController.Post(expectedClaim);

            Assert.AreEqual(HttpStatusCode.Created, response.StatusCode, "A POST of a new claim should succeed.");

            // Prepare a claim "updater".
            MitchellClaim updater = new MitchellClaim();

            updater.ClaimantLastName       = "NewLastName";
            expectedClaim.ClaimantLastName = updater.ClaimantLastName;

            updater.LossDate       = expectedClaim.LossDate.Value.AddDays(1);
            expectedClaim.LossDate = updater.LossDate;

            // Note:  The updater will have to include both vehicles that are changed and those who are not changed.
            //        The vehicles that are not changed will only have the Vin field set.
            //        This system enables us to delete vehicles with the update request. The tread-off is that when we
            //        specify a list of vehicles then that list must include vehicles that are not changed.
            updater.Vehicles = new List <VehicleDetails>();

            updater.Vehicles.Add(new VehicleDetails()
            {
                Vin = expectedClaim.Vehicles[0].Vin
            });

            VehicleDetails sourceVehicle  = expectedClaim.Vehicles[1];
            VehicleDetails updaterVehicle = new VehicleDetails()
            {
                Vin     = sourceVehicle.Vin,
                Mileage = sourceVehicle.Mileage + 100
            };

            updater.Vehicles.Add(updaterVehicle);
            sourceVehicle.Mileage = updaterVehicle.Mileage;

            // Update the claim.
            response = ClaimsController.Put(newClaimNumber, updater);
            Assert.AreEqual(HttpStatusCode.OK, response.StatusCode, "A PUT of an existing claim should succeed.");

            // Retrieved the updated claim and compare it with the expected value.
            MitchellClaim retrievedClaim = ClaimsController.Get(newClaimNumber);

            Assert.AreEqual(expectedClaim, retrievedClaim, "The claim that was created, updated and retrieved should have the expected values.");
        }
Esempio n. 15
0
        public void GetTest()
        {
            var data = claimsController.Get();

            Assert.True(data.Any());
        }