public void DeleteTags_DeleteTagsByTagIds_Succeed() { TagsController controller = new TagsController(mockTagService.Object); this.SetupControllerTests(controller, "http://localhost/STCRMService/api/tags", HttpMethod.Delete); var mockResponse = mockRepository.Create <DeleteTagResponse>(); mockTagService.Setup(c => c.DeleteTags(It.IsAny <DeleteTagIdsRequest>())). Returns(mockResponse.Object); var httpResponseMessage = controller.Delete(SAMPLE_TAG_IDS); var noteResponse = httpResponseMessage.Content.ReadAsAsync <DeleteTagResponse>().ContinueWith( t => { return(t.Result); }).Result; mockRepository.VerifyAll(); Assert.AreEqual(httpResponseMessage.StatusCode, HttpStatusCode.OK); }
protected void btnDelete_Click(object sender, EventArgs e) { try { string del_list = hdfCheck.Value; string[] sp_list = del_list.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries); for (int i = 0; i < sp_list.Length; i++) { objTags.Delete(Convert.ToInt32(sp_list[i])); objNewsTags.removeTagsID(sp_list[i] + ";"); } loadTags(); } catch (Exception ex) { divMessage.InnerHtml = O2S_Message.Error("Cảnh Báo", "Phát hiện lỗi! " + ex.Message); } }
public async void Delete_Errors() { TagsControllerMockFacade mock = new TagsControllerMockFacade(); var mockResult = new Mock <ActionResponse>(); mockResult.SetupGet(x => x.Success).Returns(false); mock.ServiceMock.Setup(x => x.Delete(It.IsAny <int>())).Returns(Task.FromResult <ActionResponse>(mockResult.Object)); TagsController controller = new TagsController(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(int)); response.Should().BeOfType <ObjectResult>(); (response as ObjectResult).StatusCode.Should().Be((int)HttpStatusCode.UnprocessableEntity); mock.ServiceMock.Verify(x => x.Delete(It.IsAny <int>())); }
public async Task DeleteTag_ReturnsNotFound_WhenTagIsNotInTheSystem() { // Arrange var mockTagRepo = new Mock <ITagService>(); mockTagRepo.Setup(repo => repo.DeleteTagAsync("tag")) .ReturnsAsync(false); var autoMapperConfiguration = new MapperConfiguration(cfg => {}); var mapper = autoMapperConfiguration.CreateMapper(); var tagController = new TagsController(mapper, mockTagRepo.Object); // Act var result = await tagController.Delete("tag"); // Assert result.Should().BeNotFoundResult(); }
public async Task DeleteShouldReturnOkResultWithModelId() { // Arrange var model = new Tag(); var fakeSql = Substitute.For <IDatabase>(); fakeSql.DeleteAsync(model).ReturnsForAnyArgs(Task.FromResult(true)); var controller = new TagsController(fakeSql); // Act var result = await controller.Delete(1); // Assert var viewResult = Assert.IsType <OkNegotiatedContentResult <int> >(result); Assert.Equal(viewResult.Content, 1); }
public async Task DeleteShouldReturnBadRequestResultWhenResultFalse() { // Arrange var model = new Tag(); var fakeSql = Substitute.For <IDatabase>(); fakeSql.DeleteAsync(model).ReturnsForAnyArgs(Task.FromResult(false)); var controller = new TagsController(fakeSql); // Act var result = await controller.Delete(1); // Assert var viewResult = Assert.IsType <BadRequestResult>(result); Assert.NotNull(viewResult); }
public void DeleteTags_DeleteTagByIds_RuntimeError_500InternalServerError() { TagsController controller = new TagsController(mockTagService.Object); this.SetupControllerTests(controller, "http://localhost/STCRMService/api/tags", HttpMethod.Delete); var mockResponse = mockRepository.Create <DeleteTagResponse>(); mockTagService.Setup(c => c.DeleteTags(It.IsAny <DeleteTagIdsRequest>())). Returns(mockResponse.Object); mockResponse.Setup(r => r.Exception).Returns(new InvalidOperationException()); var httpResponseMessage = controller.Delete(SAMPLE_TAG_IDS); var postResponse = httpResponseMessage.Content.ReadAsAsync <DeleteTagResponse>().ContinueWith( t => { return(t.Result); }).Result; mockRepository.VerifyAll(); Assert.AreEqual(httpResponseMessage.StatusCode, HttpStatusCode.InternalServerError); Assert.AreNotEqual(postResponse.Exception, null); }
public void TagsControllerDelete() { var result = _ctrl.Delete("test"); Assert.AreEqual(HttpStatusCode.OK, result.StatusCode); }
public async Task DeleteShouldReturnOkResultWithModelId() { // Arrange var model = new Tag(); var fakeSql = Substitute.For<IDatabase>(); fakeSql.DeleteAsync(model).ReturnsForAnyArgs(Task.FromResult(true)); var controller = new TagsController(fakeSql); // Act var result = await controller.Delete(1); // Assert var viewResult = Assert.IsType<OkNegotiatedContentResult<int>>(result); Assert.Equal(viewResult.Content, 1); }
public async Task DeleteShouldReturnBadRequestResultWhenResultFalse() { // Arrange var model = new Tag(); var fakeSql = Substitute.For<IDatabase>(); fakeSql.DeleteAsync(model).ReturnsForAnyArgs(Task.FromResult(false)); var controller = new TagsController(fakeSql); // Act var result = await controller.Delete(1); // Assert var viewResult = Assert.IsType<BadRequestResult>(result); Assert.NotNull(viewResult); }