public ActionResult ApproveMaintenanceSave(Milestone model) { try { var milestoneService = new MilestoneService(); if (ModelState.IsValid) { //Get user id int?userId = Session.GetUserId(); //ApproveMaintenanceVO approveMaintenanceVO = new ApproveMaintenanceVO(model, userId); //var milestoneVO = new MilestoneVO(model, userId); var milestoneVO = model.Transpose(userId); milestoneService.UpdateMilestone(milestoneVO); return(new HttpStatusCodeResult(200)); } else { throw new ApplicationException(String.Format(Constants.CANNOT_SAVE, Constants.MILESTONE)); } } catch (ApplicationException e) { return(new HttpStatusCodeAndErrorResult(500, e.Message)); } }
public void ShouldUpdateMilestoneWithNewInformation() { int expectedMilestoneId = 10; Milestone milestone = new Milestone(100d, "Testing", DateTime.Now); Milestone existingMilestone = new Milestone(100d, "Testing", null); //Setup the mocks mockRepository.Setup(r => r.Get(It.Is<int>(val => val == expectedMilestoneId))).Returns(existingMilestone); mockRepository.Setup(r => r.Update(It.Is<int>(val => val == expectedMilestoneId), It.IsAny<Milestone>())).Returns<int, Milestone> ( (id, unsavedMilestone) => { unsavedMilestone.Id = id; return unsavedMilestone; } ); IMilestoneService service = new MilestoneService(mockRepository.Object); //Act Milestone updatedMilestone = service.UpdateMilestone(expectedMilestoneId, milestone); //Assert updatedMilestone.Should().NotBeNull(); updatedMilestone.Id.Should().Be(expectedMilestoneId); updatedMilestone.Should().BeEquivalentTo(milestone); }
public HttpResponseMessage UpdateMilestone(MilestoneDto milestone) { try { _milestoneService.UpdateMilestone(milestone); return(Request.CreateResponse(HttpStatusCode.OK, "Successfully updated a miletone!")); } catch (Exception ex) { return(Request.CreateResponse(HttpStatusCode.InternalServerError, ex.Message)); } }
public void ShouldNotUpdateAMilestoneIfItDoesNotExist() { int expectedMilestoneId = 10; Milestone milestone = new Milestone(100d, "Testing", DateTime.Now); //Setup the mocks mockRepository.Setup(r => r.Get(It.Is<int>(val => val == expectedMilestoneId))).Returns<Milestone>(null); IMilestoneService service = new MilestoneService(mockRepository.Object); Action failAction = () => service.UpdateMilestone(expectedMilestoneId, milestone); //Assert failAction.Should().Throw<ArgumentException>(); }
public void ShouldNotUpdateAMilestoneOnceItHasBeenCompleted() { int expectedMilestoneId = 10; Milestone milestone = new Milestone(expectedMilestoneId, 100d, "Testing", null); Milestone existingMilestone = new Milestone(expectedMilestoneId, 1100d, "Testing", DateTime.Now); //Setup the mocks mockRepository.Setup(r => r.Get(It.Is<int>(val => val == expectedMilestoneId))).Returns(existingMilestone); IMilestoneService service = new MilestoneService(mockRepository.Object); Action failAction = () => service.UpdateMilestone(expectedMilestoneId, milestone); //Assert failAction.Should().Throw<Exception>(); }