/// <summary> /// Deletes the project. /// </summary> /// <param name="id">The id.</param> /// <returns></returns> public override void Delete(int id) { // unassign all users from the given project UnassignUsers(id); // delete the project _projectController.Delete(id); }
public void TestDeleteProject() { var origProject = _projectService.Create(RandomProject()).Result; Assert.That(_projectService.GetAllProjects().Result, Has.Count.EqualTo(1)); _ = _controller.Delete(origProject.Id).Result; Assert.That(_projectService.GetAllProjects().Result, Has.Count.EqualTo(0)); }
public void Delete() { // Arrange projectBL.Setup(m => m.DeleteProject(It.IsAny <int>())); // Act var result = projectController.Delete(1) as OkResult; // Assert Assert.NotNull(result); }
public void DeleteTest() { var result = _controller.Delete(null) as HttpStatusCodeResult; Assert.AreEqual((int)HttpStatusCode.BadRequest, result.StatusCode); result = _controller.Delete(long.MaxValue) as HttpNotFoundResult; Assert.AreEqual((int)HttpStatusCode.NotFound, result.StatusCode); ViewResult vr = _controller.Delete(1) as ViewResult; if (vr != null) { Assert.AreEqual("Delete", vr.ViewName); } }
public void Delete_ShouldNotDeleteWhenProjectHasTasks() { //arrange var projectToBeDeleted = new Project() { Id = 4, Tasks = new List <Task>() { new Task() { Id = 1 } } }; var mockProjectRepository = new Mock <IProjectRepository>().Object; Mock.Get <IProjectRepository>(mockProjectRepository).Setup(r => r.Get(projectToBeDeleted.Id)).Returns(projectToBeDeleted); var projectFacade = new ProjectFacade(mockProjectRepository); var projectController = new ProjectController(projectFacade); //act var result = projectController.Delete(projectToBeDeleted.Id) as OkNegotiatedContentResult <bool>; //assert Assert.Null(result); }
public void DeleteTest(string id) { var response = _projectController.Get(); var okObjectResult = response.Result as OkObjectResult; var projects = okObjectResult.Value as IOrderedEnumerable <ProjectModel>; Assert.AreEqual(projects.Count(), 2); response = _projectController.Delete(id); var okResult = response.Result as OkResult; Assert.AreEqual(okResult.StatusCode, 200); if (id != "" && id != "aaaaaaaaaaaaaaaaaaaaaaaa") { response = _projectController.Get(); okObjectResult = response.Result as OkObjectResult; projects = okObjectResult.Value as IOrderedEnumerable <ProjectModel>; Assert.AreEqual(projects.Count(), 1); } else { response = _projectController.Get(); okObjectResult = response.Result as OkObjectResult; projects = okObjectResult.Value as IOrderedEnumerable <ProjectModel>; Assert.AreEqual(projects.Count(), 2); } }
public void DeleteInvalidIdTest() { ProjectController controller = new ProjectController(); controller.Request = new System.Net.Http.HttpRequestMessage { RequestUri = new Uri("http://localhost:50328/api/project") }; controller.Configuration = new System.Web.Http.HttpConfiguration(); controller.Configuration.Routes.MapHttpRoute( name: "DefaultApi", routeTemplate: "api/{controller}/{id}", defaults: new { id = RouteParameter.Optional }); controller.RequestContext.RouteData = new HttpRouteData( route: new HttpRoute(), values: new HttpRouteValueDictionary { { "controller", "project" } }); var result = controller.Delete(0); Assert.That(result.StatusCode, Is.EqualTo(System.Net.HttpStatusCode.NotFound)); }
public void DeleteProject_Test_ReturnSuccess() { mockObject.Setup(m => m.Delete(1)).Returns(() => Task <int> .FromResult(1)); ProjectController projectController = new ProjectController(mockObject.Object); var result = projectController.Delete(1); Assert.NotNull(result); }
public void ProjectControllerDeleteShouldCallDeleteProjectServiceAsExpected() { var request = 12345; subject = new ProjectController(this.mockService.Object); subject.Delete(request); this.mockService.Verify(x => x.DeleteProject(request), Times.Once); }
public void DeleteTest() { var mockRepos = new Mock <IProjectService>(); mockRepos.Setup(x => x.Delete(It.IsAny <int>())).Returns(1); var controller = new ProjectController(mockRepos.Object); var result = controller.Delete(12); Assert.IsNotNull(result); Assert.AreEqual(1, result); }
public async Task Delete_RemoveAsyncIsCalledInRepository() { // Arrange _repository.Setup(x => x.UserIsClientAsync(1, It.IsAny <IPrincipal>())).Returns(Task.FromResult <bool>(true)); var controller = new ProjectController(_repository.Object); // Act await controller.Delete(1); // Assert _repository.Verify(x => x.RemoveAsync(1, It.IsAny <IPrincipal>()), Times.Exactly(1)); }
public void DeleteThrowExceptionTest() { var mockRepos = new Mock <IProjectService>(); mockRepos.Setup(x => x.Delete(It.IsAny <int>())).Throws(new System.Exception("Error")); var controller = new ProjectController(mockRepos.Object); var result = controller.Delete(12); Assert.IsNotNull(result); Assert.AreEqual(0, result); }
public void DeletePostNotLoggedUserTest() { // Arrange ProjectController controller = ControllersMocks.GetControllerAsNotLoggedUser <ProjectController>(); // Act JsonResult action = controller.Delete(ModelsMocks.ProjectModelSecond.ID, ModelsMocks.Form) as JsonResult; var forbidden = (TaskVlopper.Models.JsonHttpViewModel)action.Data; // Assert Assert.AreEqual(403, forbidden.HttpCode); }
public void DeleteProject() { // Arrange ProjectController controller = new ProjectController(); var actResult = controller.Delete(1); // Act var result = actResult as OkNegotiatedContentResult <bool>; // Assert Assert.IsNotNull(result); Assert.IsTrue(result.Content == true); }
public void DeleteExistingProject() { var dto = new ProjectDTO { Project_ID = 1, ProjectName = "SampleProject", Priority = 1, StartDate = DateTime.Now }; mock.Setup(a => a.DeleteProject(1)).Returns(true); ProjectController controller = new ProjectController(mock.Object); var result = controller.Delete(1); Assert.AreEqual(true, result); }
public async Task Delete_ReturnsNotFoundIfIdIsNull() { // Arrange var controller = new ProjectController(_repository.Object); // Act int?id = null; var result = await controller.Delete(id); // Assert Assert.IsNotNull(result, "View Result is null"); Assert.IsInstanceOfType(result, typeof(NotFoundObjectResult)); }
public async Task Delete_RedirectsIfUserIsNotClient() { // Arrange _repository.Setup(x => x.UserIsClientAsync(1, It.IsAny <IPrincipal>())).Returns(Task.FromResult <bool>(false)); var controller = new ProjectController(_repository.Object); // Act var result = await controller.Delete(1) as RedirectToActionResult; // Assert Assert.IsNotNull(result, "Redirect result is null"); Assert.AreEqual("Index", result.ActionName as String); Assert.AreEqual("Home", result.ControllerName as String); }
public void DeleteProject() { mockRepository.Setup(x => x.Delete(1)). Callback(() => isCreateOrUpdateInvokedInRepository = true); ProjectController = new ProjectController( mockRepository.Object); ProjectController.Request = new HttpRequestMessage() { Properties = { { HttpPropertyKeys.HttpConfigurationKey, new HttpConfiguration() } } }; // Remove last Product var actualResult = ProjectController.Delete(1); Assert.AreEqual(actualResult.StatusCode, HttpStatusCode.OK); }
public void DeleteProjectNullCheck(Project pro) { var context = new TaskTestContext(); context.Project.Add(pro); ProjectController controller = new ProjectController(context); controller.Request = new HttpRequestMessage(); controller.Request.Properties.Add(HttpPropertyKeys.HttpConfigurationKey, new HttpConfiguration()); controller.Request.SetConfiguration(new HttpConfiguration()); HttpResponseMessage http; http = controller.Delete(-1); Assert.AreEqual(HttpStatusCode.Conflict, http.StatusCode); }
public void DeleteProject() { //Add 2 Tasks// AddNewProject(); //Delete 1 task// projectController.Delete(GetProjID(0)); //Check if Deleted// There should be 1 task IHttpActionResult response = projectController.Get(); var contentResult = response as NotFoundResult; Assert.IsNotNull(contentResult); }
public void Delete() { // Arrange int projectId = 0; ProjectController controller = new ProjectController(); List <ProjectModel> result = controller.GetTaskDetails(); projectId = result.ElementAt(0).ProjectId; // Act var success = controller.Delete(projectId); // Assert Assert.IsNotNull(success); Assert.AreEqual(true, success); }
public void DeleteProject() { for (int i = 0; i < numberOfThreads; i++) { mockRepository.Setup(x => x.Delete(1)); ProjectController = new ProjectController( mockRepository.Object); ProjectController.Request = new HttpRequestMessage() { Properties = { { HttpPropertyKeys.HttpConfigurationKey, new HttpConfiguration() } } }; // Remove last Product var actualResult = ProjectController.Delete(1); _counter.Increment(); } }
public void Delete_project() { //Arrange var dto = new ProjectDTO { Project_Id = 1, ProjectName = "TestProject", Start_Date = DateTime.Now, Priority = 1 }; mock.Setup(a => a.DeleteProject(1)).Returns(true); ProjectController controller = new ProjectController(mock.Object); // Act var result = controller.Delete(1); // Assert Assert.AreEqual(true, result); }
public async void Delete_Errors() { ProjectControllerMockFacade mock = new ProjectControllerMockFacade(); var mockResult = new Mock <ActionResponse>(); mockResult.SetupGet(x => x.Success).Returns(false); mock.ServiceMock.Setup(x => x.Delete(It.IsAny <string>())).Returns(Task.FromResult <ActionResponse>(mockResult.Object)); ProjectController controller = new ProjectController(mock.ApiSettingsMoc.Object, mock.LoggerMock.Object, mock.TransactionCoordinatorMock.Object, mock.ServiceMock.Object, mock.ModelMapperMock.Object); controller.ControllerContext = new ControllerContext(); controller.ControllerContext.HttpContext = new DefaultHttpContext(); IActionResult response = await controller.Delete(default(string)); response.Should().BeOfType <ObjectResult>(); (response as ObjectResult).StatusCode.Should().Be((int)HttpStatusCode.UnprocessableEntity); mock.ServiceMock.Verify(x => x.Delete(It.IsAny <string>())); }
public void Delete_ShouldNotDeleteWhenProjectNotFound() { //arrange var ProjectIdToBDeleted = 4; var mockProjectRepository = new Mock <IProjectRepository>().Object; Mock.Get <IProjectRepository>(mockProjectRepository).Setup(r => r.Get(ProjectIdToBDeleted)); var projectFacade = new ProjectFacade(mockProjectRepository); var projectController = new ProjectController(projectFacade); //act var result = projectController.Delete(ProjectIdToBDeleted) as OkNegotiatedContentResult <bool>; //assert Assert.Null(result); }
public void DeleteProjectTest() { var controller = new ProjectController(projectRepository); controller.Request = new HttpRequestMessage(); controller.Configuration = new HttpConfiguration(); Project task = new Project() { Project_ID = 1, Priority = 1 }; // Act var response = controller.Delete(1); Assert.IsNotNull(response.Content); Assert.IsNotNull(response.Content.Headers.ContentType); Assert.IsTrue(response.StatusCode == System.Net.HttpStatusCode.OK); Assert.AreEqual(_randomProjects.Count, 0); }
public void DeleteGetLoggedUserTest() { using (IUnityContainer container = UnityConfig.GetConfiguredContainer()) { var repository = container.Resolve <IProjectRepository>(); repository.RemoveAll(); repository.Add(ModelsMocks.ProjectModelSecond); // Arrange ProjectController controller = ControllersMocks.GetControllerAsLoggedUser <ProjectController>(); // Act JsonResult action = controller.Delete(ModelsMocks.ProjectModelSecond.ID) as JsonResult; var project = (Models.ProjectViewModel)action.Data; // Assert Assert.IsNotNull(project); } }
public void DeletePostLoggedUserTest() { using (IUnityContainer container = UnityConfig.GetConfiguredContainer()) { var repository = container.Resolve <IProjectRepository>(); repository.RemoveAll(); // Arrange ProjectController controller = ControllersMocks.GetControllerAsLoggedUser <ProjectController>(); JsonResult actionCreate = controller.Create(ModelsMocks.ProjectModelFirst) as JsonResult; // Act JsonResult actionDelete = controller.Delete(repository.GetAll().First().ID, ModelsMocks.Form) as JsonResult; // Assert Assert.AreEqual(0, repository.GetAll().Count()); } }
public void Project_Owner_Can_Delete_Project() { // Spoof an authenticated user by generating a ClaimsPrincipal var user = new ClaimsPrincipal(new ClaimsIdentity(new Claim[] { new Claim(ClaimTypes.NameIdentifier, "FIREBASE_USER2"), }, "TestAuthentication")); // Spoof UserController var controller = new ProjectController(_fakeUserRepo.Object, _fakeProjectRepo.Object, _fakeProjColRepo.Object); controller.ControllerContext = new ControllerContext(); // Required to create the controller controller.ControllerContext.HttpContext = new DefaultHttpContext { User = user }; // Pretend the user is making a request to the controller // Attempt to get this user's project var response = controller.Delete(2); // Returns Ok Assert.IsType <NoContentResult>(response); }
private void btnDelete_Click(object sender, EventArgs e) { if (this.lstProject.SelectedIndices.Count == 0) { MessageBox.Show("Bạn chưa chọn đối tượng ?", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } DialogResult dlr = MessageBox.Show("Bạn có muốn xóa đối tượng?", "Thông báo", MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (dlr == DialogResult.No) { return; } //this.listProject.RemoveAt(this.lstProject.SelectedItems[0].Index); ProjectController.Delete(this.lstProject.SelectedItems[0].SubItems[1].Text); this.lstProject.Items.RemoveAt(this.lstProject.SelectedItems[0].Index); DisplayListProject(); }