示例#1
0
        public async Task <ActionResult <LegalCaseDTO> > UpdateLegalCaseAsync([FromRoute] int id, [FromBody] LegalCase legalCase)
        {
            LegalCase legalCaseResult = await _genericRepository.GetOneByAsync(lc => lc.Id == legalCase.Id);

            if (legalCaseResult is null)
            {
                var logData = new
                {
                    Id           = id,
                    LegalCase    = legalCase,
                    Action       = ControllerContext.ActionDescriptor.DisplayName,
                    Verb         = HttpContext.Request.Method,
                    EndpointPath = HttpContext.Request.Path.Value,
                    User         = HttpContext.User.Claims.First(usr => usr.Type == "preferred_username").Value
                };
                _logger.LogInformation("No LegalCase was updated for Id {id} and Legalcase {@legalCase}. Data: {@logData}", id, legalCase, logData);

                return(NotFound("No Legal Case was updated"));
            }

            int updated = await _genericRepository.UpdateTAsync(legalCase);

            LegalCaseDTO legalCaseDTO = _mapper.Map <LegalCaseDTO>(legalCase);

            return(Ok(legalCaseDTO));
        }
示例#2
0
        public async Task <ActionResult <LegalCaseDTO> > AddLegalCaseAsync([FromBody] LegalCase legalCase)
        {
            int created = await _genericRepository.AddTAsync(legalCase);

            if (created == 0)
            {
                var logData = new
                {
                    LegalCase    = legalCase,
                    Action       = ControllerContext.ActionDescriptor.DisplayName,
                    Verb         = HttpContext.Request.Method,
                    EndpointPath = HttpContext.Request.Path.Value,
                    User         = HttpContext.User.Claims.First(usr => usr.Type == "preferred_username").Value
                };
                _logger.LogInformation("No LegalCase was created for Legalcase {@legalCase}. Data: {@logData}", legalCase, logData);

                return(NotFound("No Legal Case was created"));
            }

            var newLegalCase = await _genericRepository.GetOneByAsync(lc =>
                                                                      lc.Client_Id == legalCase.Client_Id &&
                                                                      lc.Title == legalCase.Title);

            LegalCaseDTO legalCaseDTO = _mapper.Map <LegalCaseDTO>(newLegalCase);

            return(Created("", legalCaseDTO));
        }
示例#3
0
        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>());
        }
示例#4
0
        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>());
        }
示例#5
0
        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>());
        }
示例#6
0
        public async Task <ActionResult <LegalCaseDTO> > GetLegalCaseByIdAsync([FromRoute] int id)
        {
            var legalCase = await _genericRepository.GetOneByAsync(lc => lc.Id == id);

            if (legalCase is null)
            {
                var logData = new
                {
                    Id           = id,
                    Action       = ControllerContext.ActionDescriptor.DisplayName,
                    Verb         = HttpContext.Request.Method,
                    EndpointPath = HttpContext.Request.Path.Value,
                    User         = HttpContext.User.Claims.First(usr => usr.Type == "preferred_username").Value
                };
                _logger.LogInformation("No LegalCases were found for Id {id}. Data: {@logData}", id, logData);

                return(NotFound("No data was found"));
            }

            LegalCaseDTO legalCaseDTO = _mapper.Map <LegalCaseDTO>(legalCase);

            return(Ok(legalCaseDTO));
        }