public async Task Edit_NullCondition_NotFoundReturned() { var audioBooksService = new Mock <IAudioBookServiceAsync>(); var controller = new AudioBookManualController(audioBooksService.Object); var result = await controller.Edit(null); Assert.IsType <NotFoundResult>(result); }
public async Task Edit_NoAudioBook_NotFoundReturned() { var audioBooksService = new Mock<IAudioBookServiceAsync>(); audioBooksService.Setup(x => x.Update(It.IsAny<Guid>(), It.IsAny<AudioBook>())).Returns(Task.FromResult((AudioBook)null)); var controller = new AudioBookManualController(audioBooksService.Object); var result = await controller.Edit(Guid.NewGuid()); Assert.IsType<NotFoundResult>(result); }
public async Task Edit_NoCondition_ViewReturned() { var audioBook = new AudioBook(); var audioBooksService = new Mock<IAudioBookServiceAsync>(); audioBooksService.Setup(x => x.GetById(It.IsAny<Guid>())).Returns(Task.FromResult(audioBook)); var controller = new AudioBookManualController(audioBooksService.Object); var result = await controller.Edit(Guid.NewGuid()); var viewResult = Assert.IsType<ViewResult>(result); var model = Assert.IsAssignableFrom<AudioBook>( viewResult.ViewData.Model); Assert.Equal(audioBook, model); }
public async Task Edit_ModelNotValid_ViewReturned() { var id = Guid.NewGuid(); var audioBook = new AudioBook() { Id = id }; var audioBooksService = new Mock<IAudioBookServiceAsync>(); audioBooksService.Setup(x => x.Update(It.IsAny<Guid>(), It.Is<AudioBook>(ab => ab == audioBook))).Returns(Task.FromResult(audioBook)); var controller = new AudioBookManualController(audioBooksService.Object); controller.ModelState.AddModelError("Author", "Required"); var result = await controller.Edit(id, audioBook); Assert.IsType<ViewResult>(result); }
public async Task Edit_AudioBookPassed_RedirectToActionReturned() { var id = Guid.NewGuid(); var audioBook = new AudioBook() { Id = id }; var audioBooksService = new Mock<IAudioBookServiceAsync>(); audioBooksService.Setup(x => x.Update(It.IsAny<Guid>(), It.Is<AudioBook>(ab => ab == audioBook))).Returns(Task.FromResult(audioBook)); var apiController = new AudioBookManualController(audioBooksService.Object); var result = await apiController.Edit(id, audioBook); Assert.IsType<RedirectToActionResult>(result); }