public async void AddLegalCaseAsync_Creates_And_Returns_New_LegalCase() { //get expected LegalCase LegalCase legalCase = _legalCases.FirstOrDefault(); LegalCaseDTO expectedLegalCaseDTO = _mapper.Map <LegalCaseDTO>(legalCase); //configure Repo return of Adding the LegalCase _mockRepository.Setup(repo => repo.AddTAsync(legalCase)).ReturnsAsync(1); //configure Repo return of getting the newly created LegalCase _mockRepository.Setup(repo => repo.GetOneByAsync(lc => lc.Client_Id == legalCase.Client_Id && lc.Title == legalCase.Title)) .ReturnsAsync(legalCase); //call the controller method var actionResult = await _controller.AddLegalCaseAsync(legalCase); //Get the LegalCase from the ActionResult returned var createdResult = Assert.IsType <CreatedResult>(actionResult.Result); LegalCaseDTO actualLegalCaseDTO = createdResult.Value as LegalCaseDTO; int? statusCode = createdResult.StatusCode; //Assertions Assert.Equal(201, statusCode); Assert.IsType <LegalCaseDTO>(actualLegalCaseDTO); //use FluentAssertions to compare Reference types actualLegalCaseDTO.Should().BeEquivalentTo(expectedLegalCaseDTO, options => options.ComparingByMembers <LegalCaseDTO>()); }
public async void UpdateLegalCaseAsync_Updates_Existing_LegalCase_And_Returns_Updated_LegalCase() { //get expected LegalCase LegalCase legalCase = new LegalCase() { Id = 1, Client_Id = 2, Title = "Title for Case Updated", Description = "Description for Case Updated", TrustFund = 9999.99m }; LegalCaseDTO expectedLegalCaseDTO = _mapper.Map <LegalCaseDTO>(legalCase); //configure Repo return of getting the LegalCase to be updated _mockRepository.Setup(repo => repo.GetOneByAsync(lc => lc.Id == legalCase.Id)).ReturnsAsync(legalCase); //configure Repo return of the Update action _mockRepository.Setup(repo => repo.UpdateTAsync(legalCase)).ReturnsAsync(1); //call the controller method var actionResult = await _controller.UpdateLegalCaseAsync(legalCase.Id, legalCase); //Get the LegalCase from the ActionResult returned var okObjectResult = Assert.IsType <OkObjectResult>(actionResult.Result); LegalCaseDTO actualLegalCaseDTO = okObjectResult.Value as LegalCaseDTO; int? statusCode = okObjectResult.StatusCode; //Assertions Assert.Equal(200, statusCode); Assert.IsType <LegalCaseDTO>(actualLegalCaseDTO); //use FluentAssertions to compare Reference types actualLegalCaseDTO.Should().BeEquivalentTo(expectedLegalCaseDTO, options => options.ComparingByMembers <LegalCaseDTO>()); }
public async void GetLegalCaseByIdAsync_Returns_LegalCaseForAnId(int id) { //get expected LegalCases LegalCase expectedLegalCase = _legalCases.Where(lc => lc.Id == id).First(); LegalCaseDTO expectedCaseDTO = _mapper.Map <LegalCaseDTO>(expectedLegalCase); //configure the Repo return _mockRepository.Setup(repo => repo.GetOneByAsync(lc => lc.Id == id)).ReturnsAsync(expectedLegalCase); //call the controller method var actionResult = await _controller.GetLegalCaseByIdAsync(id); //Get the LegalCase from the ActionResult returned var okObjectResult = Assert.IsType <OkObjectResult>(actionResult.Result); LegalCaseDTO actualLegalCaseDTO = okObjectResult.Value as LegalCaseDTO; int? statusCode = okObjectResult.StatusCode; //Assertions Assert.Equal(200, statusCode); Assert.IsType <LegalCaseDTO>(actualLegalCaseDTO); //use FluentAssertions to compare Reference types actualLegalCaseDTO.Should().BeEquivalentTo(expectedCaseDTO, options => options.ComparingByMembers <LegalCaseDTO>()); }