Exemplo n.º 1
0
        public void GetAllByGameIdShouldReturnAllModsDependingOnSortType()
        {
            var options = new DbContextOptionsBuilder <ApplicationDbContext>()
                          .UseInMemoryDatabase(databaseName: "AddGalleryUrlsShouldAddMultipleImagesToMod_DB")
                          .Options;

            var dbContext  = new ApplicationDbContext(options);
            var modService = new ModService(dbContext);

            var game = new Game();

            dbContext.Games.Add(game);

            var mod1 = new Mod
            {
                GameId             = game.Id,
                Views              = 100,
                TotalDownloadCount = 25,
                VoteCount          = 50,
            };
            var mod2 = new Mod
            {
                GameId             = game.Id,
                Views              = 25,
                TotalDownloadCount = 100,
                VoteCount          = 50,
            };
            var mod3 = new Mod
            {
                GameId             = game.Id,
                Views              = 25,
                TotalDownloadCount = 50,
                VoteCount          = 100,
            };

            dbContext.Mods.Add(mod1);
            dbContext.Mods.Add(mod2);
            dbContext.Mods.Add(mod3);
            dbContext.SaveChanges();

            var viewsSort     = modService.GetAllByGameId(game.Id, "Views").First();
            var votesSort     = modService.GetAllByGameId(game.Id, "Votes").First();
            var downloadsSort = modService.GetAllByGameId(game.Id, "Downloads").First();

            Assert.Equal(mod1.Views, viewsSort.Views);
            Assert.Equal(mod2.TotalDownloadCount, downloadsSort.TotalDownloadCount);
            Assert.Equal(mod3.VoteCount, votesSort.VoteCount);
        }