Esempio n. 1
0
        public async Task PutGame_ExistingIdCorrectGameWithPublisherIdChangedToNegative_NoContentResultPublisherIdDoesntChanged()
        {
            // Arrange
            const int gameId = 3, publisherId = -1;

            InitializeInmemoryDatabase(out DbContextOptions <GameReviewsContext> options, GetFakeList());

            Game gameToUpdate = GetFakeList().Where(d => d.ID == gameId).FirstOrDefault(),
            // Should use ICopyable interface here
                 expectedGame = GetFakeList().Where(d => d.ID == gameId).FirstOrDefault();

            // Act
            using (var context = new GameReviewsContext(options))
            {
                gameToUpdate.PublisherId = publisherId;

                GamesController gamesController = new GamesController(context);
                var             result          = (await gamesController.PutGame(gameId, gameToUpdate));

                Game actualGame = await context.Games.Where(d => d.ID == gameId).FirstOrDefaultAsync();

                // Assert
                Assert.IsType <BadRequestResult>(result);
            }
        }
Esempio n. 2
0
        private void InitializeInmemoryDatabase(out DbContextOptions <GameReviewsContext> options, IEnumerable <Game> values)
        {
            options = new DbContextOptionsBuilder <GameReviewsContext>()
                      .UseInMemoryDatabase(databaseName: "GamesDatabase" + InMemoryDbIndex++)
                      .Options;

            // Insert seed data into the database using one instance of the context
            using (var context = new GameReviewsContext(options))
            {
                foreach (Game game in values)
                {
                    context.Games.Add(game);
                }

                for (int i = 0; i < 10; ++i)
                {
                    context.Developers.Add(new Developer()
                    {
                        Name = i.ToString(), Website = "Website" + i
                    });
                    context.Publishers.Add(new Publisher()
                    {
                        Name = i.ToString(), Website = "Website" + i
                    });
                }

                context.SaveChanges();
            }
        }
Esempio n. 3
0
        public async Task PutGame_ExistingIdCorrectGameWithDeveloperIdChangedToExisting_NoContentResultDeveloperIdChanged()
        {
            // Arrange
            const int gameId = 3, developerId = 7;

            InitializeInmemoryDatabase(out DbContextOptions <GameReviewsContext> options, GetFakeList());

            Game gameToUpdate = GetFakeList().Where(d => d.ID == gameId).FirstOrDefault(),
            // Should use ICopyable interface here
                 expectedGame = GetFakeList().Where(d => d.ID == gameId).FirstOrDefault();

            // Act
            using (var context = new GameReviewsContext(options))
            {
                gameToUpdate.DeveloperId = developerId;
                expectedGame.DeveloperId = developerId;

                GamesController gamesController = new GamesController(context);
                var             result          = (await gamesController.PutGame(gameId, gameToUpdate));

                Game actualGame = await context.Games.Where(d => d.ID == gameId).FirstOrDefaultAsync();

                // Assert
                Assert.True(AreEqual(expectedGame, actualGame));
                Assert.IsType <NoContentResult>(result);
            }
        }
Esempio n. 4
0
        public async Task PostDeveloper_CorrectDeveloperWithCorrectValuesAndZeroIdSetted_CreatedAtActionResultWithGeneratedId()
        {
            // Arrange
            const int idToSet = 0;

            InitializeInmemoryDatabase(out DbContextOptions <GameReviewsContext> options, GetFakeList());

            Developer developerToCreate = new Developer()
            {
                Name    = "NewDevelope",
                Website = "NewWebsite",
                ID      = idToSet
            };

            // Act
            using (var context = new GameReviewsContext(options))
            {
                DevelopersController developersController = new DevelopersController(context);
                var result = (await developersController.PostDeveloper(developerToCreate)).Result;

                // Assert
                Assert.True(developerToCreate.ID != idToSet);
                Assert.IsType <CreatedAtActionResult>(result);
            }
        }
Esempio n. 5
0
        public async Task PostUser_CorrectUserWithCorrectValuesAndZeroIdSetted_CreatedAtActionResultWithGeneratedId()
        {
            // Arrange
            const int idToSet = 0;

            InitializeInmemoryDatabase(out DbContextOptions <GameReviewsContext> options, GetFakeList());

            User userToCreate = new User()
            {
                Name             = "NewDevelope",
                RegistrationDate = DateTime.Parse("15-10-2020"),
                ID = idToSet
            };

            // Act
            using (var context = new GameReviewsContext(options))
            {
                UsersController usersController = new UsersController(context);
                var             result          = (await usersController.PostUser(userToCreate)).Result;

                // Assert
                Assert.True(userToCreate.ID != idToSet);
                Assert.IsType <CreatedAtActionResult>(result);
            }
        }
Esempio n. 6
0
        public async Task PutUser_ExistingIdCorrectUserWithWebsiteChanged_NoContentResult()
        {
            // Arrange
            const int userId = 3;

            InitializeInmemoryDatabase(out DbContextOptions <GameReviewsContext> options, GetFakeList());

            User userToUpdate = GetFakeList().Where(d => d.ID == userId).FirstOrDefault(),
            // Should use ICopyable interface here
                 expectedUser = GetFakeList().Where(d => d.ID == userId).FirstOrDefault();

            // Act
            using (var context = new GameReviewsContext(options))
            {
                userToUpdate.RegistrationDate = DateTime.Parse("15-10-2020");
                expectedUser.RegistrationDate = DateTime.Parse("15-10-2020");

                UsersController usersController = new UsersController(context);
                var             result          = (await usersController.PutUser(userId, userToUpdate));

                User actualUser = await context.Users.Where(d => d.ID == userId).FirstOrDefaultAsync();

                // Assert
                Assert.True(AreEqual(expectedUser, actualUser));
                Assert.IsType <NoContentResult>(result);
            }
        }
Esempio n. 7
0
        public async Task PostGame_CorrectGameWithCorrectValuesAndZeroIdSetted_CreatedAtActionResultWithGeneratedId()
        {
            // Arrange
            const int idToSet = 0;

            InitializeInmemoryDatabase(out DbContextOptions <GameReviewsContext> options, GetFakeList());

            Game gameToCreate = new Game()
            {
                Name             = "NewGame",
                Description      = "NewDescription",
                PublisherId      = 1,
                DeveloperId      = 2,
                AnnouncementDate = DateTime.Parse("10-05-2015"),
                ReleaseDate      = DateTime.Parse("27-12-2018"),
                ID = idToSet
            };

            // Act
            using (var context = new GameReviewsContext(options))
            {
                GamesController gamesController = new GamesController(context);
                var             result          = (await gamesController.PostGame(gameToCreate)).Result;

                // Assert
                Assert.True(gameToCreate.ID != idToSet);
                Assert.IsType <CreatedAtActionResult>(result);
            }
        }
Esempio n. 8
0
        public async Task PutDeveloper_ExistingIdCorrectDeveloperWithWebsiteChanged_NoContentResult()
        {
            // Arrange
            const int developerId = 3;

            InitializeInmemoryDatabase(out DbContextOptions <GameReviewsContext> options, GetFakeList());

            Developer developerToUpdate = GetFakeList().Where(d => d.ID == developerId).FirstOrDefault(),
            // Should use ICopyable interface here
                      expectedDeveloper = GetFakeList().Where(d => d.ID == developerId).FirstOrDefault();

            // Act
            using (var context = new GameReviewsContext(options))
            {
                developerToUpdate.Website = "newWebsite";
                expectedDeveloper.Website = "newWebsite";

                DevelopersController developersController = new DevelopersController(context);
                var result = (await developersController.PutDeveloper(developerId, developerToUpdate));

                Developer actualDeveloper = await context.Developers.Where(d => d.ID == developerId).FirstOrDefaultAsync();

                // Assert
                Assert.True(AreEqual(expectedDeveloper, actualDeveloper));
                Assert.IsType <NoContentResult>(result);
            }
        }
Esempio n. 9
0
        private void InitializeInmemoryDatabase(out DbContextOptions <GameReviewsContext> options)
        {
            options = new DbContextOptionsBuilder <GameReviewsContext>()
                      .UseInMemoryDatabase(databaseName: "GamesDatabase" + InMemoryDbIndex++)
                      .Options;

            // Insert seed data into the database using one instance of the context
            using (var context = new GameReviewsContext(options))
            {
                context.Games.Add(new Game
                {
                    Name             = "BBB",
                    ID               = 2,
                    Description      = "DdD",
                    AnnouncementDate = DateTime.Parse("13-09-2019"),
                    ReleaseDate      = DateTime.Parse("13-09-2019"),
                    DeveloperId      = 2,
                    PublisherId      = 3,
                    GameGenres       = new List <GameGenre>(),
                    GamePlatforms    = new List <GamePlatform>()
                });
                context.Games.Add(new Game {
                    Name             = "ZZZ",
                    ID               = 3,
                    Description      = "OOo",
                    AnnouncementDate = DateTime.Parse("15-11-2017"),
                    ReleaseDate      = DateTime.Parse("03-03-2021"),
                    DeveloperId      = 4,
                    PublisherId      = 5,
                    GameGenres       = new List <GameGenre>(),
                    GamePlatforms    = new List <GamePlatform>()
                });
                context.Games.Add(new Game {
                    Name             = "AAA",
                    ID               = 4,
                    Description      = "-><",
                    AnnouncementDate = DateTime.Parse("01-01-2018"),
                    ReleaseDate      = DateTime.Parse("24-12-2022"),
                    DeveloperId      = 6,
                    PublisherId      = 7,
                    GameGenres       = new List <GameGenre>(),
                    GamePlatforms    = new List <GamePlatform>()
                });

                for (int i = 0; i < 10; ++i)
                {
                    context.Developers.Add(new Developer()
                    {
                        Name = i.ToString(), Website = "Website" + i
                    });
                    context.Publishers.Add(new Publisher()
                    {
                        Name = i.ToString(), Website = "Website" + i
                    });
                }
                context.SaveChanges();
            }
        }
        private void InitializeInmemoryDatabase(out DbContextOptions <GameReviewsContext> options, IEnumerable <Review> values)
        {
            options = new DbContextOptionsBuilder <GameReviewsContext>()
                      .UseInMemoryDatabase(databaseName: "ReviewsDatabase" + InMemoryDbIndex++)
                      .Options;

            // Insert seed data into the database using one instance of the context
            using (var context = new GameReviewsContext(options))
            {
                foreach (Review review in values)
                {
                    context.Reviews.Add(review);
                }

                for (int i = 0; i < 15; ++i)
                {
                    context.Users.Add(new User()
                    {
                        Name = i.ToString(), RegistrationDate = DateTime.Now.AddDays(i)
                    });
                    context.Languages.Add(new Language()
                    {
                        Name = i.ToString()
                    });

                    context.Developers.Add(new Developer()
                    {
                        Name = i.ToString(), Website = "Website" + i
                    });
                    context.Publishers.Add(new Publisher()
                    {
                        Name = i.ToString(), Website = "Website" + i
                    });
                }

                for (int i = 0; i < 10; ++i)
                {
                    context.Games.Add(new Game
                    {
                        Name             = "BBB" + i,
                        ID               = 1 + i,
                        Description      = "DdD" + i,
                        AnnouncementDate = DateTime.Parse("13-09-2019").AddDays(i),
                        ReleaseDate      = DateTime.Parse("13-09-2019").AddDays(i),
                        DeveloperId      = 2 + i,
                        PublisherId      = 3 + i,
                        GameGenres       = new List <GameGenre>(),
                        GamePlatforms    = new List <GamePlatform>()
                    });
                }

                context.SaveChanges();
            }
        }
        public async Task GetReview_NonexistentZeroId_NotFoundResult()
        {
            // Arrange
            const int reviewId = 0;

            InitializeInmemoryDatabase(out DbContextOptions <GameReviewsContext> options, GetFakeList());

            // Act
            using (var context = new GameReviewsContext(options))
            {
                ReviewsController reviewsController = new ReviewsController(context);
                var result = (await reviewsController.GetReview(reviewId)).Result;

                // Assert
                Assert.IsType <NotFoundResult>(result);
            }
        }
Esempio n. 12
0
        public async Task GetPlatform_NonexistentId_NotFoundResult()
        {
            // Arrange
            const int platformId = 5;

            InitializeInmemoryDatabase(out DbContextOptions <GameReviewsContext> options, GetFakeList());

            // Act
            using (var context = new GameReviewsContext(options))
            {
                PlatformsController platformsController = new PlatformsController(context);
                var result = (await platformsController.GetPlatform(platformId)).Result;

                // Assert
                Assert.IsType <NotFoundResult>(result);
            }
        }
Esempio n. 13
0
        public async Task GetGenre_NonexistentNegativeId_NotFoundResult()
        {
            // Arrange
            const int genreId = -1;

            InitializeInmemoryDatabase(out DbContextOptions <GameReviewsContext> options, GetFakeList());

            // Act
            using (var context = new GameReviewsContext(options))
            {
                GenresController genresController = new GenresController(context);
                var result = (await genresController.GetGenre(genreId)).Result;

                // Assert
                Assert.IsType <NotFoundResult>(result);
            }
        }
Esempio n. 14
0
        private void InitializeInmemoryDatabase(out DbContextOptions <GameReviewsContext> options, IEnumerable <Genre> values)
        {
            options = new DbContextOptionsBuilder <GameReviewsContext>()
                      .UseInMemoryDatabase(databaseName: "GenresDatabase" + InMemoryDbIndex++)
                      .Options;

            // Insert seed data into the database using one instance of the context
            using (var context = new GameReviewsContext(options))
            {
                foreach (Genre genre in values)
                {
                    context.Genres.Add(genre);
                }

                context.SaveChanges();
            }
        }
Esempio n. 15
0
        public async Task DeletePlatform_NonexistingId_NotFoundResult()
        {
            // Arrange
            const int platformIdToDelete = 10;

            InitializeInmemoryDatabase(out DbContextOptions <GameReviewsContext> options, GetFakeList());
            Platform expectedPlatform = GetFakeList().Where(d => d.ID == platformIdToDelete).FirstOrDefault();

            // Act
            using (var context = new GameReviewsContext(options))
            {
                PlatformsController platformsController = new PlatformsController(context);
                var actionResult = (await platformsController.DeletePlatform(platformIdToDelete));
                var result       = actionResult.Result;

                // Assert
                Assert.IsType <NotFoundResult>(result);
            }
        }
        public async Task DeleteReview_NegativeId_NotFoundResult()
        {
            // Arrange
            const int reviewIdToDelete = -10;

            InitializeInmemoryDatabase(out DbContextOptions <GameReviewsContext> options, GetFakeList());
            Review expectedReview = GetFakeList().Where(d => d.ID == reviewIdToDelete).FirstOrDefault();

            // Act
            using (var context = new GameReviewsContext(options))
            {
                ReviewsController reviewsController = new ReviewsController(context);
                var actionResult = (await reviewsController.DeleteReview(reviewIdToDelete));
                var result       = actionResult.Result;

                // Assert
                Assert.IsType <NotFoundResult>(result);
            }
        }
Esempio n. 17
0
        public async Task DeleteLanguage_NonexistingId_NotFoundResult()
        {
            // Arrange
            const int languageIdToDelete = 10;

            InitializeInmemoryDatabase(out DbContextOptions <GameReviewsContext> options, GetFakeList());
            Language expectedLanguage = GetFakeList().Where(d => d.ID == languageIdToDelete).FirstOrDefault();

            // Act
            using (var context = new GameReviewsContext(options))
            {
                LanguagesController languagesController = new LanguagesController(context);
                var actionResult = (await languagesController.DeleteLanguage(languageIdToDelete));
                var result       = actionResult.Result;

                // Assert
                Assert.IsType <NotFoundResult>(result);
            }
        }
Esempio n. 18
0
        public async Task DeleteDeveloper_NonexistingId_NotFoundResult()
        {
            // Arrange
            const int developerIdToDelete = 10;

            InitializeInmemoryDatabase(out DbContextOptions <GameReviewsContext> options, GetFakeList());
            Developer expectedDeveloper = GetFakeList().Where(d => d.ID == developerIdToDelete).FirstOrDefault();

            // Act
            using (var context = new GameReviewsContext(options))
            {
                DevelopersController developersController = new DevelopersController(context);
                var actionResult = (await developersController.DeleteDeveloper(developerIdToDelete));
                var result       = actionResult.Result;

                // Assert
                Assert.IsType <NotFoundResult>(result);
            }
        }
Esempio n. 19
0
        public async Task DeleteGenre_ZeroId_NotFoundResult()
        {
            // Arrange
            const int genreIdToDelete = 0;

            InitializeInmemoryDatabase(out DbContextOptions <GameReviewsContext> options, GetFakeList());
            Genre expectedGenre = GetFakeList().Where(d => d.ID == genreIdToDelete).FirstOrDefault();

            // Act
            using (var context = new GameReviewsContext(options))
            {
                GenresController genresController = new GenresController(context);
                var actionResult = (await genresController.DeleteGenre(genreIdToDelete));
                var result       = actionResult.Result;

                // Assert
                Assert.IsType <NotFoundResult>(result);
            }
        }
        private void InitializeInmemoryDatabase(out DbContextOptions <GameReviewsContext> options)
        {
            options = new DbContextOptionsBuilder <GameReviewsContext>()
                      .UseInMemoryDatabase(databaseName: "PublishersDatabase" + InMemoryDbIndex++)
                      .Options;

            // Insert seed data into the database using one instance of the context
            using (var context = new GameReviewsContext(options))
            {
                context.Publishers.Add(new Publisher {
                    Name = "BBB", ID = 2, Website = "DdD"
                });
                context.Publishers.Add(new Publisher {
                    Name = "ZZZ", ID = 3, Website = "OOo"
                });
                context.Publishers.Add(new Publisher {
                    Name = "AAA", ID = 4, Website = "-><"
                });
                context.SaveChanges();
            }
        }
Esempio n. 21
0
        public async Task PostGenre_CorrectGenreWithCorrectValuesAndIdNotSet_CreatedAtActionResult()
        {
            // Arrange
            InitializeInmemoryDatabase(out DbContextOptions <GameReviewsContext> options, GetFakeList());

            Genre genreToCreate = new Genre()
            {
                Name = "NewDevelope"
            };

            // Act
            using (var context = new GameReviewsContext(options))
            {
                GenresController genresController = new GenresController(context);
                var result = (await genresController.PostGenre(genreToCreate)).Result;

                // Assert
                Assert.True(context.Genres.Contains(genreToCreate));
                Assert.IsType <CreatedAtActionResult>(result);
            }
        }
Esempio n. 22
0
        public async Task PostPlatform_CorrectPlatformWithCorrectValuesAndIdNotSet_CreatedAtActionResult()
        {
            // Arrange
            InitializeInmemoryDatabase(out DbContextOptions <GameReviewsContext> options, GetFakeList());

            Platform platformToCreate = new Platform()
            {
                Name = "NewDevelope"
            };

            // Act
            using (var context = new GameReviewsContext(options))
            {
                PlatformsController platformsController = new PlatformsController(context);
                var result = (await platformsController.PostPlatform(platformToCreate)).Result;

                // Assert
                Assert.True(context.Platforms.Contains(platformToCreate));
                Assert.IsType <CreatedAtActionResult>(result);
            }
        }
Esempio n. 23
0
        private void InitializeInmemoryDatabase(out DbContextOptions <GameReviewsContext> options)
        {
            options = new DbContextOptionsBuilder <GameReviewsContext>()
                      .UseInMemoryDatabase(databaseName: "UsersDatabase" + InMemoryDbIndex++)
                      .Options;

            // Insert seed data into the database using one instance of the context
            using (var context = new GameReviewsContext(options))
            {
                context.Users.Add(new User {
                    Name = "BBB", ID = 2, RegistrationDate = DateTime.Parse("04-03-2017")
                });
                context.Users.Add(new User {
                    Name = "ZZZ", ID = 3, RegistrationDate = DateTime.Parse("28-02-2015")
                });
                context.Users.Add(new User {
                    Name = "AAA", ID = 4, RegistrationDate = DateTime.Parse("13-07-2001")
                });
                context.SaveChanges();
            }
        }
Esempio n. 24
0
        private void InitializeInmemoryDatabase(out DbContextOptions <GameReviewsContext> options)
        {
            options = new DbContextOptionsBuilder <GameReviewsContext>()
                      .UseInMemoryDatabase(databaseName: "GenresDatabase" + InMemoryDbIndex++)
                      .Options;

            // Insert seed data into the database using one instance of the context
            using (var context = new GameReviewsContext(options))
            {
                context.Genres.Add(new Genre {
                    Name = "BBB", ID = 2, GameGenres = new List <GameGenre>()
                });
                context.Genres.Add(new Genre {
                    Name = "ZZZ", ID = 3, GameGenres = new List <GameGenre>()
                });
                context.Genres.Add(new Genre {
                    Name = "AAA", ID = 4, GameGenres = new List <GameGenre>()
                });
                context.SaveChanges();
            }
        }
        public async Task GetReviews_Void_TaskActionResultContainsIEnumerableOfReview()
        {
            // Arrange
            List <Review> expectedData = GetFakeList();

            InitializeInmemoryDatabase(out DbContextOptions <GameReviewsContext> options, GetFakeList());

            // Act
            using (var context = new GameReviewsContext(options))
            {
                ReviewsController    reviewsController = new ReviewsController(context);
                IEnumerable <Review> reviews           = (await reviewsController.GetReviews()).Value;

                // Assert
                Assert.Equal(expectedData.Count, reviews.Count());

                for (int i = 0; i < expectedData.Count; ++i)
                {
                    Assert.True(AreEqual(expectedData[i], reviews.ElementAt(i)));
                }
            }
        }
Esempio n. 26
0
        public async Task DeleteLanguage_ExistingId_TaskActionResultContainsDeletedLanguage()
        {
            // Arrange
            const int languageIdToDelete = 3;

            InitializeInmemoryDatabase(out DbContextOptions <GameReviewsContext> options, GetFakeList());
            Language expectedLanguage = GetFakeList().Where(d => d.ID == languageIdToDelete).FirstOrDefault();

            // Act
            using (var context = new GameReviewsContext(options))
            {
                LanguagesController languagesController = new LanguagesController(context);
                var      actionResult   = (await languagesController.DeleteLanguage(languageIdToDelete));
                var      result         = actionResult.Result;
                Language actualLanguage = actionResult.Value;

                // Assert
                Assert.IsNotType <NotFoundResult>(result);
                Assert.True(context.Languages.Find(languageIdToDelete) == null);
                Assert.True(AreEqual(expectedLanguage, actualLanguage));
            }
        }
Esempio n. 27
0
        public async Task GetUser_ExistingId_TaskActionResultContainsUser()
        {
            // Arrange
            const int userId = 3;

            User expectedUser = GetFakeList().Where(d => d.ID == userId).FirstOrDefault();

            InitializeInmemoryDatabase(out DbContextOptions <GameReviewsContext> options, GetFakeList());

            // Act
            using (var context = new GameReviewsContext(options))
            {
                UsersController usersController = new UsersController(context);
                var             actionResult    = (await usersController.GetUser(userId));
                User            user            = actionResult.Value;
                ActionResult    result          = actionResult.Result;

                // Assert
                Assert.True(AreEqual(expectedUser, user));
                Assert.IsNotType <NotFoundResult>(result);
            }
        }
        public async Task DeleteReview_ExistingId_TaskActionResultContainsDeletedReview()
        {
            // Arrange
            const int reviewIdToDelete = 3;

            InitializeInmemoryDatabase(out DbContextOptions <GameReviewsContext> options, GetFakeList());
            Review expectedReview = GetFakeList().Where(d => d.ID == reviewIdToDelete).FirstOrDefault();

            // Act
            using (var context = new GameReviewsContext(options))
            {
                ReviewsController reviewsController = new ReviewsController(context);
                var    actionResult = (await reviewsController.DeleteReview(reviewIdToDelete));
                var    result       = actionResult.Result;
                Review actualReview = actionResult.Value;

                // Assert
                Assert.IsNotType <NotFoundResult>(result);
                Assert.True(context.Reviews.Find(reviewIdToDelete) == null);
                Assert.True(AreEqual(expectedReview, actualReview));
            }
        }
Esempio n. 29
0
        public async Task GetPlatform_ExistingId_TaskActionResultContainsPlatform()
        {
            // Arrange
            const int platformId = 3;

            Platform expectedPlatform = GetFakeList().Where(d => d.ID == platformId).FirstOrDefault();

            InitializeInmemoryDatabase(out DbContextOptions <GameReviewsContext> options, GetFakeList());

            // Act
            using (var context = new GameReviewsContext(options))
            {
                PlatformsController platformsController = new PlatformsController(context);
                var          actionResult = (await platformsController.GetPlatform(platformId));
                Platform     platform     = actionResult.Value;
                ActionResult result       = actionResult.Result;

                // Assert
                Assert.True(AreEqual(expectedPlatform, platform));
                Assert.IsNotType <NotFoundResult>(result);
            }
        }
Esempio n. 30
0
        public async Task GetGenre_ExistingId_TaskActionResultContainsGenre()
        {
            // Arrange
            const int genreId = 3;

            Genre expectedGenre = GetFakeList().Where(d => d.ID == genreId).FirstOrDefault();

            InitializeInmemoryDatabase(out DbContextOptions <GameReviewsContext> options, GetFakeList());

            // Act
            using (var context = new GameReviewsContext(options))
            {
                GenresController genresController = new GenresController(context);
                var          actionResult         = (await genresController.GetGenre(genreId));
                Genre        genre  = actionResult.Value;
                ActionResult result = actionResult.Result;

                // Assert
                Assert.True(AreEqual(expectedGenre, genre));
                Assert.IsNotType <NotFoundResult>(result);
            }
        }