public async Task ShouldDeleteAuthorById() { //Arrange var author = CreateAuthor(); //Act var postResponse = (ObjectResult)await _controller.Post(author); var authorResponse = (AuthorEntity)postResponse.Value; var deleteResponse = (ObjectResult)await _controller.Delete(authorResponse.Id); var isDeleted = (bool)deleteResponse.Value; var getResponse = await _controller.Get(authorResponse.Id); var getAllResponse = (ObjectResult)await _controller.GetAll(); var authorList = (IEnumerable <AuthorEntity>)getAllResponse.Value; //Assert Assert.AreEqual(200, postResponse.StatusCode); Assert.AreEqual(200, deleteResponse.StatusCode); Assert.AreEqual(200, getAllResponse.StatusCode); Assert.IsTrue(isDeleted); Assert.IsInstanceOfType(getResponse, typeof(NotFoundResult)); Assert.AreEqual(0, authorList.Count()); }
public void DeleteView_NotNull() { var mock = new Mock <IAuthorLogic>(); mock.Setup(a => a.Delete(1)); AuthorController controller = new AuthorController(mock.Object); ViewResult result = controller.Delete(1) as ViewResult; Assert.IsNotNull(result); }
public async void DeleteAuthorTest() { AuthorController authorController = new AuthorController(new AuthorRepository(_dataContext)); var author = (Author)((OkObjectResult)await authorController.GetAuthorByName("Daniel")).Value; await authorController.Delete(author); var result = (Author)((OkObjectResult)await authorController.GetAuthorByName("Daniel")).Value; Assert.Null(result); }
public void Task_DeleteAuthor_Return_View() { //Arrange var controller = new AuthorController(context); var id = 1; //Act var data = controller.Delete(id); //Assert Assert.IsType <ViewResult>(data); }
public void CanDeleteValidAuthor(int size) { var mock = CreateAndSetupMock(size); AuthorController target = new AuthorController(mock.Object); for (int i = 1; i <= size; ++i) { target.Delete(i); mock.Verify(elm => elm.DeleteAuthor(i)); } }
public async Task ShouldDeleteAuthorById() { Author author = new Author { Name = "Comedy" }; ObjectResult responsePost = (ObjectResult)await _controller.Post(author); Author respPost = (Author)responsePost.Value; ObjectResult responseDelete = (ObjectResult)await _controller.Delete(respPost.Id); ResponseEntity respDelete = (ResponseEntity)responseDelete.Value; var responseGet = await _controller.Get(respPost.Id); Assert.AreEqual(200, (int)responsePost.StatusCode); Assert.AreEqual(200, respDelete.Status); }
public async Task DeleteReturnNotFoundResult() { //Arrange //Act var result = await _authorController.Delete(-2); //Assert Assert.NotNull(result); Assert.IsType <NotFoundResult>(result); }
public void Delete_ShouldRemoveItem() { var resultBefore = _context.Authors.FirstOrDefault(c => c.Id == _JackLondonId); Assert.NotNull(resultBefore); _controller.Delete(_JackLondonId); var resultAfter = _context.Authors.FirstOrDefault(c => c.Id == _JackLondonId); Assert.Null(resultAfter); }
public async void Task_Delete_Author_Return_OkResult() { //Arrange var controller = new AuthorController(context); var id = 2; //Act var data = await controller.Delete(id); //Assert Assert.IsType <OkObjectResult>(data); }
public async void Task_Delete_Return_NotFound() { //Arrange var controller = new AuthorController(context); var id = 10; //Act var data = await controller.Delete(id); //Assert Assert.IsType <NotFoundResult>(data); }
public async void Task_Delete_Author_Return_BadRequest() { //Arrange var controller = new AuthorController(context); int?id = null; //Act var data = await controller.Delete(id); //Assert Assert.IsType <BadRequestResult>(data); }
public void Delete_GET_InvalidId_ReturnsHttpNotFound() { //Arrange IRepository mockRepo = Substitute.For <IRepository>(); int invalidid = 999; mockRepo.Authors.Returns(_authors); //Act AuthorController target = new AuthorController(mockRepo); ActionResult result = target.Delete(invalidid); //Assert Assert.IsInstanceOf <NotFoundResult>(result); }
public void TestDelete(AuthorViewModel model, int id, string test) { _init(); AuthorController controler = new AuthorController(_service); controler.New(model).GetAwaiter().GetResult(); controler.Delete(id).GetAwaiter().GetResult(); try { var r = controler.Vizualise(1) as PartialViewResult; Assert.Fail($"Erro no Teste: {test}"); } catch (Exception) { Assert.Pass(); } }
public void Delete_GET_ValidId_ReturnsCorrectView() { //Arrange IRepository mockRepo = Substitute.For <IRepository>(); int validid = 1; mockRepo.Authors.Returns(_authors); Author expected = _authors.Where(a => a.AuthorId == validid).First(); //Act AuthorController target = new AuthorController(mockRepo); ActionResult result = target.Delete(validid); //Assert Assert.IsInstanceOf <ViewResult>(result); Author model = (result as ViewResult).Model as Author; Assert.AreEqual(expected, model); }