Esempio n. 1
0
        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);
        }
Esempio n. 2
0
        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);
        }
Esempio n. 3
0
        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);
        }
Esempio n. 4
0
        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);
        }
Esempio n. 5
0
        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);
        }