Exemplo n.º 1
0
        public async Task ReturnsCorrectSongWhenTheSongExists()
        {
            Song expectedSong = new Song()
            {
                Id = "SongId"
            };

            var songRepositoryStub = new Mock <IEfRepository <Song> >();

            songRepositoryStub
            .Setup(x => x.GetByIdAsync(It.IsAny <string>()))
            .ReturnsAsync(expectedSong);

            GetSongForDeleteById query = new GetSongForDeleteById();

            // Arrange
            GetSongForDeleteByIdQueryService sut = new GetSongForDeleteByIdQueryService(
                songRepository: songRepositoryStub.Object);

            // Act
            Song actualSong = await sut.ExecuteAsync(query);

            // Act && Assert
            Assert.AreEqual(expectedSong.Id, actualSong.Id);
        }
Exemplo n.º 2
0
        public void ThrowsNotFoundExceptionWhenSongDoesNotExists()
        {
            var songRepositoryStub = new Mock <IEfRepository <Song> >();

            songRepositoryStub
            .Setup(x => x.GetByIdAsync(It.IsAny <string>()))
            .ReturnsAsync((Song)null);

            GetSongForDeleteById query = new GetSongForDeleteById();

            // Arrange
            GetSongForDeleteByIdQueryService sut = new GetSongForDeleteByIdQueryService(
                songRepository: songRepositoryStub.Object);

            // Act && Assert
            Assert.ThrowsAsync <NotFoundException>(() => sut.ExecuteAsync(query));
        }
Exemplo n.º 3
0
        public async Task <IActionResult> Delete(string id, string returnUrl = null)
        {
            Song song = null;
            GetSongForDeleteById query = new GetSongForDeleteById()
            {
                SongId = id
            };

            string message = await this.CallServiceAsync(
                async() => song = await this.getSongForDelete.ExecuteAsync(query));

            if (message != null)
            {
                return(View()
                       .WithErrorMessage(message));
            }

            DeleteSongViewModel model = Mapper.Map <DeleteSongViewModel>(song);

            ViewData["ReturnUrl"] = returnUrl;

            return(View(model));
        }