public HttpResponseMessage DeleteMilestone(Guid id) { try { _milestoneService.DeleteMilestone(id); return(Request.CreateResponse(HttpStatusCode.OK, "Successfully deleted a milestone!")); } catch (Exception ex) { return(Request.CreateResponse(HttpStatusCode.InternalServerError, ex.Message)); } }
/// <summary> /// Delete milestone(s) /// </summary> /// <param name="Ids">Ids of milestones to be deleted</param> public ActionResult MilestoneDelete(List <int> Ids) { try { //Get user id int?userId = Session.GetUserId(); MilestoneService milestoneService = new MilestoneService(); milestoneService.DeleteMilestone(Ids, userId); return(new HttpStatusCodeResult(200)); } catch (Exception e) { return(new HttpStatusCodeAndErrorResult(500, e.Message)); } }
public void ShouldNotDeleteMilestoneFromSystemIfItHasBeenCompleted() { int expectedMilestoneId = 10; Milestone expectedMilestone = new Milestone(expectedMilestoneId, 100d, "Testing", DateTime.Now); //Setup the mocks mockRepository.Setup(r => r.Get(It.Is<int>(val => val == expectedMilestoneId))).Returns(expectedMilestone); IMilestoneService service = new MilestoneService(mockRepository.Object); //Act Action failAction = () => service.DeleteMilestone(expectedMilestoneId); //Assert failAction.Should().Throw<Exception>(); }
public void ShouldDeleteMilestoneFromSystemByKnownId() { int expectedMilestoneId = 10; Milestone expectedMilestone = new Milestone(expectedMilestoneId, 100d, "Testing", null); //Setup the mocks mockRepository.Setup(r => r.Get(It.Is<int>(val => val == expectedMilestoneId))).Returns(expectedMilestone); mockRepository.Setup(r => r.Delete(It.Is<int>(val => val == expectedMilestoneId))).Returns(expectedMilestone); IMilestoneService service = new MilestoneService(mockRepository.Object); //Act Milestone removedMilestone = service.DeleteMilestone(expectedMilestoneId); //Assert removedMilestone.Should().NotBeNull(); removedMilestone.Id.Should().Be(expectedMilestoneId); removedMilestone.Should().BeEquivalentTo(expectedMilestone); }