/// <summary> /// Generates and returns an instance of type <see cref="ClaimsController"/> /// that can be used in the context of test automation. /// </summary> public static ClaimsController GenerateClaimsController() { var claimsController = new ClaimsController(); SetupControllerForTests(claimsController); return(claimsController); }
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 } }
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."); }
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); }
public void ClaimsController_Get() { ClaimsController _controller = new ClaimsController(_mockService.Object, _logger.Object); var result = _controller.Get(); Assert.IsNotNull(result); }
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."); }
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."); }
public void ClaimsController_DeleteById() { ClaimsController _controller = new ClaimsController(_mockService.Object, _logger.Object); var result = _controller.Delete(1); Assert.IsNotNull(result); }
public void TestPostClaimWithNoClaimNumber() { MitchellClaim testClaim = TestDataGenerator.GetTestClaim(null); HttpResponseMessage response = ClaimsController.Post(testClaim); Assert.AreEqual(HttpStatusCode.Forbidden, response.StatusCode, "A POST of a claim that contains no claim number should fail with a specific status."); }
public void ControllerGetStatusFail(int claimID, int policyID) { Mock <IClaimRepository> mock = new Mock <IClaimRepository>(); mock.Setup(p => p.GetClaimStatus(claimID, policyID)).Returns(s); ClaimsController pc = new ClaimsController(mock.Object); var result = pc.GetClaimStatus(claimID, policyID).Result; Assert.IsNotNull(result); }
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(); }
public async Task Delete_UnexistedClaimdIdPassed_ProperMethodsCalledAndReturNotFoundResult() { _mediatorMock.Setup(mediator => mediator.Send(It.IsAny <DeleteClaimCommand>(), It.IsAny <CancellationToken>())).ReturnsAsync(false).Verifiable(); //Act var controller = new ClaimsController(_mediatorMock.Object); var result = await controller.Delete(1); //Assert Assert.IsAssignableFrom <NotFoundResult>(result); _mediatorMock.Verify(); }
public async Task Update_UpdateUnexistedClaim_ProperMethodsCalledAndReturnNotFoundResult() { _mediatorMock.Setup(mediator => mediator.Send(It.IsAny <UpdateClaimCommand>(), It.IsAny <CancellationToken>())).ReturnsAsync(false).Verifiable(); //Act var controller = new ClaimsController(_mediatorMock.Object); var result = await controller.Update(new UpdateClaimCommand(1, DateTime.UtcNow, 2, "descripton", "incidence", "Review", "damagedItem", "street", "city", "country")); //Assert Assert.True(((StatusCodeResult)result).StatusCode == (int)HttpStatusCode.NotFound); _mediatorMock.Verify(); }
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(); }
public void TestPostClaimWithNoVehicles() { string newClaimNumber = TestDataGenerator.GenerateUniqueClaimNumber(); MitchellClaim testClaim = TestDataGenerator.GetTestClaim(newClaimNumber); testClaim.Vehicles.Clear(); HttpResponseMessage response = ClaimsController.Post(testClaim); Assert.AreEqual(HttpStatusCode.Forbidden, response.StatusCode, "A POST of a claim that contains no vehicle information should fail with a specific status."); }
public void TestPostClaimWithRequiredParametersNotSpecified() { string newClaimNumber = TestDataGenerator.GenerateUniqueClaimNumber(); MitchellClaim testClaim = TestDataGenerator.GetTestClaim(newClaimNumber); testClaim.Vehicles[0].ModelYear = null; HttpResponseMessage response = ClaimsController.Post(testClaim); Assert.AreEqual(HttpStatusCode.Forbidden, response.StatusCode, "A POST of a claim that has required fields that are not specified should fail with a specific status."); }
public async Task Create_CreateClaimCommandObjectPassed_ProperMethodsCalledAndReturnCreateResult() { _mediatorMock.Setup(mediator => mediator.Send(It.IsAny <CreateClaimCommand>(), It.IsAny <CancellationToken>())).ReturnsAsync(1).Verifiable(); //Act var controller = new ClaimsController(_mediatorMock.Object); var result = await controller.Create(new CreateClaimCommand(DateTime.UtcNow, 2, "descripton", "incidence", "damagedItem", "street", "city", "country")); //Assert Assert.IsAssignableFrom <CreatedAtActionResult>(result); _mediatorMock.Verify(); }
public void TestPostDuplicateClaim() { 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."); response = ClaimsController.Post(testClaim); Assert.AreEqual(HttpStatusCode.Conflict, response.StatusCode, "A POST of a duplicate should fail with a specific status."); }
public void Setup() { _csvLoader = Substitute.For <ICsvLoader>(); _csvOutput = Substitute.For <ICsvOutput>(); _directoryFinder = Substitute.For <IDirectoryFinder>(); _configuration = Substitute.For <IConfiguration>(); _configuration.GetValue <string>("InputFilesDirectory") .Returns("D:\\WTWDIP\\ClaimsReserving\\ClaimsReserving\\InputFiles"); _fileValidator = Substitute.For <IFileValidator>(); _recordsPerProduct = Substitute.For <IRecordsPerProduct>(); _target = new ClaimsController(_csvLoader, _directoryFinder, _configuration, _csvOutput, _fileValidator, _recordsPerProduct); }
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."); }
public void ClaimsController_Post() { Claim application = new Claim() { ClaimCode = "CRUD_ACCOUNTS", Description = "Manage Accounts", Title = "Manage Accounts Claim" }; ClaimsController _controller = new ClaimsController(_mockService.Object, _logger.Object); var result = _controller.Post(application); Assert.IsNotNull(result); }
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()); }
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."); }
public void ClaimsController_DeleteFromBody() { Claim application = new Claim() { ClaimCode = "VIEW_ONLY", ClaimId = 1, Description = "View Only", Title = "View Only Claim" }; ClaimsController _controller = new ClaimsController(_mockService.Object, _logger.Object); var result = _controller.Delete(application); Assert.IsNotNull(result); }
public void GlobalSetupGetUser() { _claimDataMock = new Mock <IClaimData>(); _claimBase = ClaimsData(_claimCode); _claimData = _claimDataMock.Object; _claimsController = new ClaimsController( new GetClaimByCodeQuery(_claimData), new SaveClaimCommand(_claimData), new UpdateClaimCommand(_claimData), new SetObsoleteClaimCommnad(_claimData)); }
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."); }
public void TestPostClaimWithDuplicateVehicles() { string newClaimNumber = TestDataGenerator.GenerateUniqueClaimNumber(); MitchellClaim testClaim = TestDataGenerator.GetTestClaim(newClaimNumber); testClaim.Vehicles.Clear(); VehicleDetails vehicleDetails = TestDataGenerator.GetTestVehicle("1M8GDM9AXKP000001"); testClaim.Vehicles.Add(vehicleDetails); testClaim.Vehicles.Add(vehicleDetails); HttpResponseMessage response = ClaimsController.Post(testClaim); Assert.AreEqual(HttpStatusCode.Forbidden, response.StatusCode, "A POST of a claim that contains duplicate vehicles should fail with a specific status."); }
public void TestClaims_Valid() { try { // generate the token GenerateController generate = new GenerateController(); ClaimsController claims = new ClaimsController(); var generateFunc = new TestDelegate <List <JwtClaim> >(generate.Post); var generateTask = Task.Run(() => this.RunTestAsync(generateFunc)); generateTask.Wait(); string tokenResult = JsonConvert.DeserializeObject <string>((generateTask.Result as ContentResult).Content); Assert.NotNull(tokenResult); // get the claims from the token var claimsFunc = new TestDelegate <string>(claims.Post); var claimsTask = Task.Run(() => this.RunTestAsync(claimsFunc, JsonConvert.SerializeObject(tokenResult))); claimsTask.Wait(); var result = claimsTask.Result as ContentResult; Assert.NotNull(result); // ensure the claims match List <JwtClaim> claimList1 = JsonConvert.DeserializeObject <List <JwtClaim> >(result.Content); List <JwtClaim> claimList2 = this.GetTestData <List <JwtClaim> >(nameof(TestClaims_Valid)); Assert.Equal(claimList1.Count, claimList2.Count); for (int i = 0; i < claimList1.Count; ++i) { Assert.Equal(claimList1[i].ClaimType, claimList2[i].ClaimType); Assert.Equal(claimList1[i].ClaimValue, claimList2[i].ClaimValue); } } catch (Exception e) { m_logger.WriteLine(e.Message); Assert.Null(e); } }
public ClaimsControllerTest() { claimRepository = new ClaimsRepository(); claimService = new ClaimsService(claimRepository); controller = new ClaimsController(claimService); }
public void InitializeForTests() { repository = new MockRepositoryClaims(); claimController = new ClaimsController(repository); }