public static CapitalPlan MapFromDomainEntity(CapitalPlanDTO projectCapitalPlan) { if (projectCapitalPlan == null) { return(null); } return(new CapitalPlan { Id = projectCapitalPlan.Id, Rollover = projectCapitalPlan.Rollover, BusinessDriver = projectCapitalPlan.BusinessDriver, ProjectId = projectCapitalPlan.ProjectId, LeaseExpiry = projectCapitalPlan.LeaseExpiry, StartDate = projectCapitalPlan.StartDate, Group = projectCapitalPlan.Group, PartOfPBASubmission = projectCapitalPlan.PartOfPBASubmission, Priority = projectCapitalPlan.Priority, EndDate = projectCapitalPlan.EndDate, BusinessPriority = projectCapitalPlan.BusinessPriority, RiskToBusinessByNotDoingIt = projectCapitalPlan.RiskToBusinessByNotDoingIt, RolloverCategory = projectCapitalPlan.RolloverCategory, BusinessRequirementsDone = projectCapitalPlan.BusinessRequirementsDone, Theme = projectCapitalPlan.Theme, Comments = projectCapitalPlan.Comments }); }
public void MapFromDomainEntity_NullContent_ReturnNull() { //Act var response = CapitalPlanDTO.MapFromDatabaseEntity(null); //Assert Assert.IsNull(response); }
public void Update(Guid id, CapitalPlanDTO capitalPlanDTO) { if (id != capitalPlanDTO.ProjectId) { throw new BusinessValidationException("The Id informed does not match the Id in the Entity"); } _repository.Update(id, CapitalPlan.MapFromDomainEntity(capitalPlanDTO)); }
public void Update_ProjectIdAndCapitalPlanDTO_CallRepositoryToUpdateContent() { //Arrange var id = new Guid("2509d0dc-fa61-48a5-8650-684592539742"); var capitalPlanDTO = new CapitalPlanDTO { ProjectId = id }; //Act _service.Update(id, capitalPlanDTO); //Assert _repository.Received(1).Update(id, Arg.Is <CapitalPlan>(c => c.ProjectId == id)); }
public void MapFromDomainEntity_ValidEntity_ReturnDTOEntity() { //Arrange var capitalPlan = new CapitalPlanDTO { Id = Guid.NewGuid(), ProjectId = new Guid("b58b6a58-2064-4c71-9b3d-c8c4514159a9"), Priority = 1, Rollover = false, RolloverCategory = 0, PartOfPBASubmission = false, BusinessPriority = 1, Theme = "Theme", BusinessDriver = "Business Driver", Group = "Group", LeaseExpiry = "Lease Expiry", StartDate = new DateTime(2018, 08, 01), EndDate = new DateTime(2020, 08, 01), RiskToBusinessByNotDoingIt = "Risk to Business", BusinessRequirementsDone = false, Comments = "Comments" }; //Act var response = CapitalPlan.MapFromDomainEntity(capitalPlan); //Assert Assert.IsNotNull(response); Assert.AreEqual(capitalPlan.Id, response.Id); Assert.AreEqual(capitalPlan.ProjectId, response.ProjectId); Assert.AreEqual(capitalPlan.Priority, response.Priority); Assert.AreEqual(capitalPlan.Rollover, response.Rollover); Assert.AreEqual(capitalPlan.RolloverCategory, response.RolloverCategory); Assert.AreEqual(capitalPlan.PartOfPBASubmission, response.PartOfPBASubmission); Assert.AreEqual(capitalPlan.BusinessPriority, response.BusinessPriority); Assert.AreEqual(capitalPlan.Theme, response.Theme); Assert.AreEqual(capitalPlan.BusinessDriver, response.BusinessDriver); Assert.AreEqual(capitalPlan.Group, response.Group); Assert.AreEqual(capitalPlan.LeaseExpiry, response.LeaseExpiry); Assert.AreEqual(capitalPlan.StartDate, response.StartDate); Assert.AreEqual(capitalPlan.EndDate, response.EndDate); Assert.AreEqual(capitalPlan.RiskToBusinessByNotDoingIt, response.RiskToBusinessByNotDoingIt); Assert.AreEqual(capitalPlan.BusinessRequirementsDone, response.BusinessRequirementsDone); Assert.AreEqual(capitalPlan.Comments, response.Comments); }
public async Task <IActionResult> Put(Guid id, [FromBody] CapitalPlanDTO capitalPlanDTO) { if (capitalPlanDTO == null) { return(BadRequest("Could not convert the content of the Body to a Project Information.")); } _capitalPlanService.Update(id, capitalPlanDTO); var response = await _unitOfWork.SaveChangesAsync(); if (response == 0) { return(NotFound()); } return(NoContent()); }
public void Update_CapitalPlanIdDoesNotMatchProjectIdInEntity_ThrowBusinessValidationException() { //Arrange var id = new Guid("2509d0dc-fa61-48a5-8650-684592539742"); var anotherId = new Guid("b80d67ad-112d-4368-9074-d5bf0e3c0fa0"); var capitalPlanDTO = new CapitalPlanDTO { ProjectId = id }; //Act var ex = Assert.Throws <BusinessValidationException>(() => { _service.Update(anotherId, capitalPlanDTO); }); //Assert Assert.IsNotNull(ex); StringAssert.Contains("The Id informed does not match the Id in the Entity", ex.Message); }
public void Put_ProjectIdProjectInformationDTO_ReturnsNoContent() { //Arrange var id = new Guid("8e1e1161-d83d-4962-8094-4cee0a9dc210"); var projectInformationDTO = new CapitalPlanDTO { ProjectId = id }; _unitOfWork.SaveChangesAsync() .Returns(Task.FromResult(1)); //Act var response = _controller.Put(id, projectInformationDTO).Result; var contentResult = response as NoContentResult; //Assert Assert.IsNotNull(contentResult); _service.Received(1).Update(id, projectInformationDTO); }
public void Get_ExistingProjectId_ReturnProjectDTO() { //Arrange var id = new Guid("2509d0dc-fa61-48a5-8650-684592539742"); var projectDTO = new CapitalPlanDTO { ProjectId = id }; _service.Get(id) .Returns(projectDTO); //Act var response = _controller.Get(id) as ObjectResult; //Assert Assert.IsNotNull(response); var resultAsDTO = (CapitalPlanDTO)response.Value; Assert.IsNotNull(resultAsDTO); Assert.AreEqual(id, resultAsDTO.ProjectId); }
public CapitalPlanDTO Get(Guid id) { return(CapitalPlanDTO.MapFromDatabaseEntity(_repository.Get(id))); }