Details() public méthode

public Details ( [ cache, int id ) : Task
cache [
id int
Résultat Task
        public async Task Details_ReturnsAlbumDetail()
        {
            // Arrange
            var albumId = 1;

            var dbContext = _serviceProvider.GetRequiredService <MusicStoreContext>();
            var genres    = CreateTestGenres(numberOfGenres: 3, numberOfAlbums: 3, dbContext: dbContext);

            var cache = _serviceProvider.GetRequiredService <IMemoryCache>();

            var controller = new StoreController(dbContext, new TestAppSettings());

            // Act
            var result = await controller.Details(cache, albumId);

            // Assert
            var viewResult = Assert.IsType <ViewResult>(result);

            Assert.Null(viewResult.ViewName);

            Assert.NotNull(viewResult.ViewData);
            var viewModel = Assert.IsType <Album>(viewResult.ViewData.Model);

            Assert.NotNull(viewModel.Genre);
            var genre = genres.SingleOrDefault(g => g.GenreId == viewModel.GenreId);

            Assert.NotNull(genre);
            Assert.NotNull(genre.Albums.SingleOrDefault(a => a.AlbumId == albumId));
            Assert.Null(viewModel.Artist);

            var cachedAlbum = cache.Get <Album>("album_1");

            Assert.NotNull(cachedAlbum);
            Assert.Equal(albumId, cachedAlbum.AlbumId);
        }
        public async Task Details_ReturnsHttpNotFoundWhenNoAlbumData()
        {
            // Arrange
            var albumId    = int.MinValue;
            var controller = new StoreController(_serviceProvider.GetRequiredService <MusicStoreContext>());

            // Act
            var result = await controller.Details(_serviceProvider.GetRequiredService <IMemoryCache>(), albumId);

            // Assert
            Assert.IsType <HttpNotFoundResult>(result);
        }
        public async Task Details_ReturnsHttpNotFoundWhenNoAlbumData()
        {
            // Arrange
            var albumId = int.MinValue;
            var controller = new StoreController()
            {
                DbContext = _serviceProvider.GetRequiredService<MusicStoreContext>(),
                Cache = _serviceProvider.GetRequiredService<IMemoryCache>(),
            };

            // Act
            var result = await controller.Details(albumId);

            // Assert
            Assert.IsType<HttpNotFoundResult>(result);
        }
        public async Task Details_ReturnsAlbumDetail()
        {
            // Arrange
            var albumId = 1;

            var dbContext = _serviceProvider.GetRequiredService<MusicStoreContext>();
            var genres = CreateTestGenres(numberOfGenres: 3, numberOfAlbums: 3, dbContext: dbContext);

            var cache = _serviceProvider.GetRequiredService<IMemoryCache>();

            var controller = new StoreController()
            {
                DbContext = dbContext,
                Cache = cache,
            };

            // Act
            var result = await controller.Details(albumId);

            // Assert
            var viewResult = Assert.IsType<ViewResult>(result);
            Assert.Null(viewResult.ViewName);

            Assert.NotNull(viewResult.ViewData);
            var viewModel = Assert.IsType<Album>(viewResult.ViewData.Model);
            Assert.NotNull(viewModel.Genre);
            var genre = genres.SingleOrDefault(g => g.GenreId == viewModel.GenreId);
            Assert.NotNull(genre);
            Assert.NotNull(genre.Albums.SingleOrDefault(a => a.AlbumId == albumId));
            Assert.Null(viewModel.Artist);

            var cachedAlbum = cache.Get<Album>("album_1");
            Assert.NotNull(cachedAlbum);
            Assert.Equal(albumId, cachedAlbum.AlbumId);
        }