예제 #1
0
        public async void AdvancedSearch_EmptySearchParameters_ReturnsViewModelWithAllPlatforms()
        {
            List<Platform> platforms = GetPlatformList();

            Mock<IVeilDataAccess> dbStub = TestHelpers.GetVeilDataAccessFake();
            Mock<DbSet<Platform>> platformDbSetStub = TestHelpers.GetFakeAsyncDbSet(platforms.AsQueryable());

            dbStub.Setup(db => db.Platforms).Returns(platformDbSetStub.Object);

            Mock<ControllerContext> contextStub = new Mock<ControllerContext>();
            contextStub.SetupUser().InAllRoles();

            GamesController controller = new GamesController(dbStub.Object, idGetter: null)
            {
                ControllerContext = contextStub.Object
            };

            // Calling contains on the null Name would throw
            var result = await controller.AdvancedSearch(null) as ViewResult;

            Assert.That(result != null);
            Assert.That(result.Model, Is.InstanceOf<AdvancedGameSearchViewModel>());

            var model = (AdvancedGameSearchViewModel)result.Model;

            Assert.That(model.Platforms, Has.Count.EqualTo(platforms.Count));
        }
예제 #2
0
        public async void Index_Privileged_NotForSaleGame(string role)
        {
            List<Game> games = new List<Game>
            {
                new Game { GameAvailabilityStatus = AvailabilityStatus.NotForSale },
                new Game { GameAvailabilityStatus = AvailabilityStatus.Available }
            };

            Mock<IVeilDataAccess> dbStub = TestHelpers.GetVeilDataAccessFake();
            Mock<DbSet<Game>> gameDbSetStub = TestHelpers.GetFakeAsyncDbSet(games.AsQueryable());
            dbStub.Setup(db => db.Games).Returns(gameDbSetStub.Object);

            Mock<ControllerContext> contextStub = new Mock<ControllerContext>();
            contextStub.SetupUser().IsInRole(role);

            GamesController controller = new GamesController(dbStub.Object, idGetter: null)
            {
                ControllerContext = contextStub.Object
            };

            var result = await controller.Index() as ViewResult;

            Assert.That(result != null);
            Assert.That(result.Model, Is.InstanceOf<GameListViewModel>());

            var model = (GameListViewModel)result.Model;

            Assert.That(model.Games, Has.Count.EqualTo(2));
            Assert.That(model.Games, Is.EqualTo(games));
        }
예제 #3
0
        public async void DeleteGame_ValidDeleteNoGameProduct(string role)
        {
            Game aGame = new Game
            {
                Id = gameId,
                GameSKUs = new List<GameProduct>()
            };

            Mock<IVeilDataAccess> dbStub = TestHelpers.GetVeilDataAccessFake();
            Mock<DbSet<Game>> gameDbSetStub = TestHelpers.GetFakeAsyncDbSet(new List<Game> { aGame }.AsQueryable());

            gameDbSetStub.Setup(g => g.FindAsync(aGame.Id)).ReturnsAsync(aGame);
            dbStub.Setup(db => db.Games).Returns(gameDbSetStub.Object);

            Mock<ControllerContext> contextStub = new Mock<ControllerContext>();
            contextStub.SetupUser().IsInRole(role);

            GamesController controller = new GamesController(dbStub.Object, idGetter: null)
            {
                ControllerContext = contextStub.Object
            };

            var result = await controller.Delete(aGame.Id) as ViewResult;

            Assert.That(result != null);
            Assert.That(result.Model != null);
            Assert.That(result.Model, Is.InstanceOf<Game>());
        }
예제 #4
0
        public async void Edit_GET_Valid_ViewById()
        {
            var game = new Game { Id = gameId };

            var games = new List<Game>
            {
               game
            };

            var esrbRating = new List<ESRBRating>
            {
                new ESRBRating { RatingId = "E", Description = "Everyone" }
            };


            Mock<IVeilDataAccess> dbStub = TestHelpers.GetVeilDataAccessFake();
            Mock<DbSet<Game>> gameDbSetStub = TestHelpers.GetFakeAsyncDbSet(games.AsQueryable());
            dbStub.Setup(db => db.Games).Returns(gameDbSetStub.Object);
            gameDbSetStub.Setup(gdb => gdb.FindAsync(game.Id)).ReturnsAsync(game);

            Mock<DbSet<ESRBRating>> esrbRatingDbSetStub = TestHelpers.GetFakeAsyncDbSet(esrbRating.AsQueryable());
            dbStub.Setup(db => db.ESRBRatings).Returns(esrbRatingDbSetStub.Object);

            GamesController controller = new GamesController(dbStub.Object, idGetter: null);

            var result = await controller.Edit(game.Id) as ViewResult;

            Assert.That(result != null);
            Assert.That(result.Model, Is.InstanceOf<Game>());
            Assert.That(result.Model, Is.EqualTo(game));
        }
예제 #5
0
        public async void AdvancedSearch_EmptySearchParameters_ReturnsAdvancedSearchView()
        {
            Mock<IVeilDataAccess> dbStub = TestHelpers.GetVeilDataAccessFake();
            Mock<DbSet<Game>> gameDbSetStub = TestHelpers.GetFakeAsyncDbSet(GetGameSearchList().AsQueryable());
            Mock<DbSet<Tag>> tagDbSetStub = TestHelpers.GetFakeAsyncDbSet(GetTagList().AsQueryable());
            Mock<DbSet<Platform>> platformDbSetStub = TestHelpers.GetFakeAsyncDbSet(GetPlatformList().AsQueryable());

            dbStub.Setup(db => db.Games).Returns(gameDbSetStub.Object);
            dbStub.Setup(db => db.Tags).Returns(tagDbSetStub.Object);
            dbStub.Setup(db => db.Platforms).Returns(platformDbSetStub.Object);

            Mock<ControllerContext> contextStub = new Mock<ControllerContext>();
            contextStub.SetupUser().InAllRoles();

            GamesController controller = new GamesController(dbStub.Object, idGetter: null)
            {
                ControllerContext = contextStub.Object
            };

            // Calling contains on the null Name would throw
            var result = await controller.AdvancedSearch(null) as ViewResult;

            Assert.That(result != null);
            Assert.That(result.ViewName, Is.Empty);
        }
        public async void DeleteConfirmed_ValidDeleteNoGameProduct()
        {
            Game aGame = new Game
            {
                Id = gameId,
                GameSKUs = new List<GameProduct>()
            };

            Mock<IVeilDataAccess> dbStub = TestHelpers.GetVeilDataAccessFake();
            Mock<DbSet<Game>> gameDbSetStub = TestHelpers.GetFakeAsyncDbSet(new List<Game> { aGame }.AsQueryable());

            gameDbSetStub.
                Setup(g => g.FindAsync(aGame.Id)).
                ReturnsAsync(aGame);
            dbStub.
                Setup(db => db.Games).
                Returns(gameDbSetStub.Object);

            GamesController controller = new GamesController(dbStub.Object, idGetter: null);

            var result = await controller.DeleteGameConfirmed(aGame.Id) as RedirectToRouteResult;

            Assert.That(result != null);
            Assert.That(result.RouteValues["Action"], Is.EqualTo("Index"));
        }
예제 #7
0
        public async void Details_IdInDb_ReturnsViewWithModel()
        {
            Game matchingGame = new Game
            {
                Id = gameId,
                GameAvailabilityStatus = AvailabilityStatus.Available,
                GameSKUs = new List<GameProduct>()
            };

            Mock<IVeilDataAccess> dbStub = TestHelpers.GetVeilDataAccessFake();
            Mock<DbSet<Game>> gameDbSetStub = TestHelpers.GetFakeAsyncDbSet(new List<Game> { matchingGame }.AsQueryable());
            gameDbSetStub.SetupForInclude();

            dbStub.Setup(db => db.Games).Returns(gameDbSetStub.Object);

            Mock<ControllerContext> contextStub = new Mock<ControllerContext>();
            contextStub.SetupUser().InAllRoles();

            GamesController controller = new GamesController(dbStub.Object, idGetter: null)
            {
                ControllerContext = contextStub.Object
            };

            var result = await controller.Details(matchingGame.Id) as ViewResult;

            Assert.That(result != null);
            Assert.That(result.Model != null);
            Assert.That(result.Model, Is.InstanceOf<Game>());
            Assert.That(result.Model, Is.EqualTo(matchingGame));
        }
예제 #8
0
        public async void Recommended_NoFavorites_ReturnsMatchingModel()
        {
            Member member = new Member
            {
                UserId = new Guid("09EABF21-D5AC-4A5D-ADF8-27180E6D889B"),
                FavoriteTags = new List<Tag>(),
                FavoritePlatforms = new List<Platform>()
            };

            Mock<IVeilDataAccess> dbStub = TestHelpers.GetVeilDataAccessFake();

            Mock<DbSet<Member>> memberDbSetStub = TestHelpers.GetFakeAsyncDbSet(new List<Member> { member }.AsQueryable());
            memberDbSetStub.Setup(db => db.FindAsync(member.UserId)).ReturnsAsync(member);
            dbStub.Setup(db => db.Members).Returns(memberDbSetStub.Object);

            Mock<ControllerContext> context = new Mock<ControllerContext>();
            context.Setup(c => c.HttpContext.User.Identity).Returns<IIdentity>(null);

            Mock<IGuidUserIdGetter> idGetterStub = new Mock<IGuidUserIdGetter>();
            idGetterStub.Setup(id => id.GetUserId(It.IsAny<IIdentity>())).Returns(member.UserId);

            GamesController controller = new GamesController(dbStub.Object, idGetterStub.Object)
            {
                ControllerContext = context.Object
            };

            var result = await controller.Recommended() as RedirectToRouteResult;

            Assert.That(result.RouteValues["action"], Is.EqualTo("Index"));
        }
예제 #9
0
        public void Details_IdNotInDb_Throws404Exception()
        {

            Mock<IVeilDataAccess> dbStub = TestHelpers.GetVeilDataAccessFake();
            Mock<DbSet<Game>> gameDbSetStub = TestHelpers.GetFakeAsyncDbSet(new List<Game>().AsQueryable());
            gameDbSetStub.SetupForInclude();

            dbStub.Setup(db => db.Games).Returns(gameDbSetStub.Object);

            GamesController controller = new GamesController(dbStub.Object, idGetter: null);

            Assert.That(async () => await controller.Details(gameId), Throws.InstanceOf<HttpException>().And.Matches<HttpException>(e => e.GetHttpCode() == 404));
        }
예제 #10
0
        public void Edit_GET_Invalid_NonExistantId()
        {
            var games = new List<Game>
            {
                new Game {Id = gameId}
            };

            Mock<IVeilDataAccess> dbStub = TestHelpers.GetVeilDataAccessFake();
            Mock<DbSet<Game>> gameDbSetStub = TestHelpers.GetFakeAsyncDbSet(games.AsQueryable());
            dbStub.Setup(db => db.Games).Returns(gameDbSetStub.Object);

            GamesController controller = new GamesController(dbStub.Object, idGetter: null);

            Assert.That(async () => await controller.Edit(id: Guid.Empty), Throws.InstanceOf<HttpException>().And.Matches<HttpException>(e => e.GetHttpCode() == 404));
        }
예제 #11
0
        public void Create_GET_CanView()
        {
            var esrbRatings = new List<ESRBRating>
        {
                new ESRBRating { RatingId = "E", Description = "Everyone" }
            };

            Mock<IVeilDataAccess> dbStub = TestHelpers.GetVeilDataAccessFake();
            Mock<DbSet<ESRBRating>> esrbDbSetStub = TestHelpers.GetFakeAsyncDbSet(esrbRatings.AsQueryable());
            dbStub.Setup(db => db.ESRBRatings).Returns(esrbDbSetStub.Object);

            GamesController controller = new GamesController(dbStub.Object, idGetter: null);

            var result = controller.Create() as ViewResult;

            Assert.That(result != null);
        }
예제 #12
0
        public async void Create_POST_Valid_RedirectsToDetails()
        {
            var game = new Game { Id = gameId };

            Mock<IVeilDataAccess> dbStub = TestHelpers.GetVeilDataAccessFake();

            Mock<DbSet<Game>> gamesDbSetStub = TestHelpers.GetFakeAsyncDbSet(new List<Game>().AsQueryable());
            dbStub.Setup(db => db.Games).Returns(gamesDbSetStub.Object);

            GamesController controller = new GamesController(dbStub.Object, idGetter: null);

            var result = await controller.Create(game, null, null) as RedirectToRouteResult;

            Assert.That(result != null);
            Assert.That(result.RouteValues != null);
            Assert.That(result.RouteValues["Id"], Is.EqualTo(game.Id));
            Assert.That(result.RouteValues["Action"], Is.EqualTo("Details"));
        }
예제 #13
0
        public async void Create_POST_NoTags_GamesAddCalledOnce()
        {
            var esrbRatings = new List<ESRBRating> { everyoneESRBRating };
            var game = new Game();

            Mock<IVeilDataAccess> dbStub = TestHelpers.GetVeilDataAccessFake();

            Mock<DbSet<Game>> gamesDbSetStub = TestHelpers.GetFakeAsyncDbSet(new List<Game>().AsQueryable());
            gamesDbSetStub.Setup(gdb => gdb.Add(game)).Returns(game).Verifiable();
            dbStub.Setup(db => db.Games).Returns(gamesDbSetStub.Object);

            Mock<DbSet<ESRBRating>> esrbDbSetStub = TestHelpers.GetFakeAsyncDbSet(esrbRatings.AsQueryable());
            dbStub.Setup(db => db.ESRBRatings).Returns(esrbDbSetStub.Object);

            GamesController controller = new GamesController(dbStub.Object, idGetter: null);

            await controller.Create(game, null, null);

            Assert.That(() => gamesDbSetStub.Verify(gdb => gdb.Add(game), Times.Once), Throws.Nothing);
        }
예제 #14
0
        public async void DeleteGame_ValidDeleteWithGameProduct(string role)
        {
            Game aGame = new Game
            {
                Id = gameId
            };

            GameProduct aGameProduct = new PhysicalGameProduct();
            aGameProduct.GameId = aGame.Id;
            aGameProduct.Id = new Guid("44B0752E-968B-477A-AAAD-3ED535BA3559");

            Mock<IVeilDataAccess> dbStub = TestHelpers.GetVeilDataAccessFake();

            Mock<DbSet<Game>> gameDbSetStub = TestHelpers.GetFakeAsyncDbSet(new List<Game> { aGame }.AsQueryable());
            Mock<DbSet<GameProduct>> gameProductsDbSetStub = TestHelpers.GetFakeAsyncDbSet(new List<GameProduct> { aGameProduct }.AsQueryable());

            gameDbSetStub.Setup(g => g.FindAsync(aGame.Id)).ReturnsAsync(aGame);
            gameProductsDbSetStub.Setup(gp => gp.FindAsync(aGameProduct.Id)).ReturnsAsync(aGameProduct);

            dbStub.Setup(db => db.GameProducts).Returns(gameProductsDbSetStub.Object);
            dbStub.Setup(db => db.Games).Returns(gameDbSetStub.Object);

            Mock<ControllerContext> contextStub = new Mock<ControllerContext>();
            contextStub.SetupUser().IsInRole(role);

            GamesController controller = new GamesController(dbStub.Object, idGetter: null)
            {
                ControllerContext = contextStub.Object
            };

            var result = await controller.Delete(aGame.Id) as ViewResult;

            Assert.That(result != null);
            Assert.That(result.Model != null);
            Assert.That(result.Model, Is.InstanceOf<Game>());
        }
예제 #15
0
        public async void Details_UserIsUnprivilegedRole_GameWithRatingMinimumAgeGreaterThanZero_NoCookie_ReturnsAgeGateIndex(string role)
        {
            string rawUrl = "/Games/1234";

            Game matchingGame = new Game
            {
                Id = gameId,
                GameAvailabilityStatus = AvailabilityStatus.PreOrder,
                GameSKUs = GetGameSKUsListWithAllAvailabilityStatuses(),
                Rating = matureESRBRating,
                Name = "a game"
            };

            Mock<IVeilDataAccess> dbStub = TestHelpers.GetVeilDataAccessFake();
            Mock<DbSet<Game>> gameDbSetStub = TestHelpers.GetFakeAsyncDbSet(new List<Game> { matchingGame }.AsQueryable());
            gameDbSetStub.SetupForInclude();

            dbStub.
                Setup(db => db.Games).
                Returns(gameDbSetStub.Object);

            Mock<ControllerContext> contextStub = new Mock<ControllerContext>();
            contextStub.
                SetupUser().
                IsInRole(role);
            contextStub.
                Setup(c => c.HttpContext.Request.Cookies).
                Returns(new HttpCookieCollection());
            contextStub.
                Setup(c => c.HttpContext.Request.RawUrl).
                Returns(rawUrl);

            GamesController controller = new GamesController(dbStub.Object, idGetter: null)
            {
                ControllerContext = contextStub.Object
            };

            var result = await controller.Details(matchingGame.Id) as ViewResult;

            Assert.That(result != null);
            Assert.That(result.ViewName, Is.StringContaining("AgeGate").And.Contains("Index"));
            Assert.That(result.Model != null);
            Assert.That(result.Model, Is.InstanceOf<AgeGateViewModel>());

            var model = (AgeGateViewModel) result.Model;

            Assert.That(model.Name, Is.SameAs(matchingGame.Name));
            Assert.That(model.ReturnUrl, Is.SameAs(rawUrl));
        }
예제 #16
0
        public void Details_NullId_Throws404Exception()
        {
            GamesController controller = new GamesController(veilDataAccess: null, idGetter: null);

            Assert.That(async () => await controller.Details(null), Throws.InstanceOf<HttpException>().And.Matches<HttpException>(e => e.GetHttpCode() == 404));
        }
예제 #17
0
        public void Details_NotForSaleStatusAndUserInNoRoles_ReturnsErrorView()
        {
            Game matchingGame = new Game
            {
                Id = gameId,
                GameAvailabilityStatus = AvailabilityStatus.NotForSale
            };

            Mock<IVeilDataAccess> dbStub = TestHelpers.GetVeilDataAccessFake();
            Mock<DbSet<Game>> gameDbSetStub = TestHelpers.GetFakeAsyncDbSet(new List<Game> { matchingGame }.AsQueryable());

            gameDbSetStub.SetupForInclude();

            dbStub.Setup(db => db.Games).Returns(gameDbSetStub.Object);

            Mock<ControllerContext> contextStub = new Mock<ControllerContext>();
            contextStub.SetupUser().InNoRoles();

            GamesController controller = new GamesController(dbStub.Object, idGetter: null)
            {
                ControllerContext = contextStub.Object
            };

            Assert.That(async () => await controller.Details(matchingGame.Id), Throws.InstanceOf<HttpException>().And.Matches<HttpException>(e => e.GetHttpCode() == 404));
        }
예제 #18
0
        public async void Details_StatusShouldBeVisibleToMember_ReturnsViewWithModel(AvailabilityStatus status)
        {
            Game matchingGame = new Game
            {
                Id = gameId,
                GameAvailabilityStatus = status,
                GameSKUs = new List<GameProduct>(),
                Rating = everyoneESRBRating
            };

            Mock<IVeilDataAccess> dbStub = TestHelpers.GetVeilDataAccessFake();
            Mock<DbSet<Game>> gameDbSetStub = TestHelpers.GetFakeAsyncDbSet(new List<Game> { matchingGame }.AsQueryable());

            gameDbSetStub.SetupForInclude();

            dbStub.Setup(db => db.Games).Returns(gameDbSetStub.Object);

            Mock<ControllerContext> contextStub = new Mock<ControllerContext>();
            contextStub.SetupUser().InMemberRole();

            GamesController controller = new GamesController(dbStub.Object, idGetter: null)
            {
                ControllerContext = contextStub.Object
            };

            var result = await controller.Details(matchingGame.Id) as ViewResult;

            Assert.That(result != null);
            Assert.That(result.Model, Is.EqualTo(matchingGame));
        }
예제 #19
0
        public void DeleteGame_IdNotInDb(string role)
        {
            Game aGame = new Game
            {
                Id = gameId
            };

            Guid nonMatch = new Guid("44B0752E-968B-477A-AAAD-3ED535BA3559");

            Mock<IVeilDataAccess> dbStub = TestHelpers.GetVeilDataAccessFake();
            Mock<DbSet<Game>> gameDbSetStub = TestHelpers.GetFakeAsyncDbSet(new List<Game> { aGame }.AsQueryable());

            gameDbSetStub.Setup(g => g.FindAsync(aGame.Id)).ReturnsAsync(aGame);
            dbStub.Setup(db => db.Games).Returns(gameDbSetStub.Object);

            Mock<ControllerContext> contextStub = new Mock<ControllerContext>();
            contextStub.SetupUser().IsInRole(role);

            GamesController controller = new GamesController(dbStub.Object, idGetter: null)
            {
                ControllerContext = contextStub.Object
            };

            Assert.That(async () => await controller.Delete(nonMatch), Throws.InstanceOf<HttpException>().And.Matches<HttpException>(e => e.GetHttpCode() == 404));
        }
예제 #20
0
        public async void AdvancedSearch_NonDefaultPage_SetsCurrentPageToPassedPage()
        {
            List<Game> games = GetGameSearchList();
            List<Platform> platforms = GetPlatformList();

            int currentPage = 2;

            Mock<IVeilDataAccess> dbStub = TestHelpers.GetVeilDataAccessFake();
            Mock<DbSet<Game>> gameDbSetStub = TestHelpers.GetFakeAsyncDbSet(games.AsQueryable());
            Mock<DbSet<Platform>> platformDbSetStub = TestHelpers.GetFakeAsyncDbSet(platforms.AsQueryable());

            dbStub.Setup(db => db.Games).Returns(gameDbSetStub.Object);
            dbStub.Setup(db => db.Platforms).Returns(platformDbSetStub.Object);

            Mock<ControllerContext> contextStub = new Mock<ControllerContext>();
            contextStub.SetupUser().InAllRoles();

            GamesController controller = new GamesController(dbStub.Object, idGetter: null)
            {
                ControllerContext = contextStub.Object
            };

            var result = await controller.AdvancedSearch(null, title: TITLE_FRAGMENT_COMMON_TO_ALL_SEARCH_GAMES, page: currentPage) as ViewResult;

            Assert.That(result != null);
            Assert.That(result.Model, Is.InstanceOf<GameListViewModel>());

            var model = (GameListViewModel)result.Model;

            Assert.That(model.CurrentPage, Is.EqualTo(currentPage));
        }
예제 #21
0
        public void AdvancedSearch_EmptyTitleKeyword_DoesNotFilterByName()
        {
            List<Game> games = new List<Game>
            {
                new Game
                {
                    Name = null,
                    GameSKUs = GetGameSKUsListWithAllAvailabilityStatuses()
                }
            };

            List<Platform> platforms = GetPlatformList();

            Mock<IVeilDataAccess> dbStub = TestHelpers.GetVeilDataAccessFake();
            Mock<DbSet<Game>> gameDbSetStub = TestHelpers.GetFakeAsyncDbSet(games.AsQueryable());
            Mock<DbSet<Platform>> platformDbSetStub = TestHelpers.GetFakeAsyncDbSet(platforms.AsQueryable());

            dbStub.Setup(db => db.Games).Returns(gameDbSetStub.Object);
            dbStub.Setup(db => db.Platforms).Returns(platformDbSetStub.Object);

            Mock<ControllerContext> contextStub = new Mock<ControllerContext>();
            contextStub.SetupUser().InAllRoles();

            GamesController controller = new GamesController(dbStub.Object, idGetter: null)
            {
                ControllerContext = contextStub.Object
            };

            // Calling contains on the null Name would throw
            Assert.That(async () => await controller.AdvancedSearch(null, platform: platforms.First().PlatformCode), Throws.Nothing);
        }
예제 #22
0
        public async void AdvancedSearch_KeywordIsPartOfNotForSaleTitle_Employee_ReturnsThatGame(string role)
        {
            List<Game> games = GetGameSearchList();
            List<Platform> platforms = GetPlatformList();

            Mock<IVeilDataAccess> dbStub = TestHelpers.GetVeilDataAccessFake();
            Mock<DbSet<Game>> gameDbSetStub = TestHelpers.GetFakeAsyncDbSet(games.AsQueryable());
            Mock<DbSet<Platform>> platformDbSetStub = TestHelpers.GetFakeAsyncDbSet(platforms.AsQueryable());

            dbStub.Setup(db => db.Games).Returns(gameDbSetStub.Object);
            dbStub.Setup(db => db.Platforms).Returns(platformDbSetStub.Object);

            Mock<ControllerContext> contextStub = new Mock<ControllerContext>();
            contextStub.SetupUser().IsInRole(role);

            GamesController controller = new GamesController(dbStub.Object, idGetter: null)
            {
                ControllerContext = contextStub.Object
            };

            var result = await controller.AdvancedSearch(null, title: "NotForSale") as ViewResult;

            Assert.That(result != null);
            Assert.That(result.Model, Is.InstanceOf<GameListViewModel>());

            var model = (GameListViewModel)result.Model;

            Assert.That(model.Games, Has.Count.EqualTo(1));
        }
예제 #23
0
        public async void AdvancedSearch_PageGreaterThanPagesSupportedByGameCount_ReturnsEmptyGameList()
        {
            List<Game> games = GetGameSearchList();
            List<Platform> platforms = GetPlatformList();

            int gamesPerPage = games.Count;

            Mock<IVeilDataAccess> dbStub = TestHelpers.GetVeilDataAccessFake();
            Mock<DbSet<Game>> gameDbSetStub = TestHelpers.GetFakeAsyncDbSet(games.AsQueryable());
            Mock<DbSet<Platform>> platformDbSetStub = TestHelpers.GetFakeAsyncDbSet(platforms.AsQueryable());

            dbStub.Setup(db => db.Games).Returns(gameDbSetStub.Object);
            dbStub.Setup(db => db.Platforms).Returns(platformDbSetStub.Object);

            Mock<ControllerContext> contextStub = new Mock<ControllerContext>();
            contextStub.SetupUser().InAllRoles();

            GamesController controller = new GamesController(dbStub.Object, idGetter: null)
            {
                ControllerContext = contextStub.Object,
                GamesPerPage = gamesPerPage
            };

            var result = await controller.AdvancedSearch(null, title: TITLE_FRAGMENT_COMMON_TO_ALL_SEARCH_GAMES, page: 2) as ViewResult;

            Assert.That(result != null);
            Assert.That(result.Model, Is.InstanceOf<GameListViewModel>());

            var model = (GameListViewModel)result.Model;

            Assert.That(model.Games, Is.Empty);
        }
예제 #24
0
        public async void AdvancedSearch_4Games_SetsTotalPagesToListCountDividedByGamesPerPage()
        {
            List<Game> games = GetGameSearchList().GetRange(0, 4);
            List<Platform> platforms = GetPlatformList();

            int gamesPerPage = 1;

            Mock<IVeilDataAccess> dbStub = TestHelpers.GetVeilDataAccessFake();
            Mock<DbSet<Game>> gameDbSetStub = TestHelpers.GetFakeAsyncDbSet(games.AsQueryable());
            Mock<DbSet<Platform>> platformDbSetStub = TestHelpers.GetFakeAsyncDbSet(platforms.AsQueryable());

            dbStub.Setup(db => db.Games).Returns(gameDbSetStub.Object);
            dbStub.Setup(db => db.Platforms).Returns(platformDbSetStub.Object);

            Mock<ControllerContext> contextStub = new Mock<ControllerContext>();
            contextStub.SetupUser().InAllRoles();

            GamesController controller = new GamesController(dbStub.Object, idGetter: null)
            {
                ControllerContext = contextStub.Object,
                GamesPerPage = gamesPerPage
            };

            var result = await controller.AdvancedSearch(null, title: TITLE_FRAGMENT_COMMON_TO_ALL_SEARCH_GAMES) as ViewResult;

            Assert.That(result != null);
            Assert.That(result.Model, Is.InstanceOf<GameListViewModel>());

            var model = (GameListViewModel)result.Model;

            Assert.That(model.TotalPages, Is.EqualTo(4 /* 4 games, one per page */));
        }
예제 #25
0
        public async void Details_UserIsUnprivilegedRole_GameWithRatingMinimumAgeGreaterThanZero_CookieWithAgeLessThanMinimumAge_AddsAlert(string role)
        {
            Game matchingGame = new Game
            {
                Id = gameId,
                GameAvailabilityStatus = AvailabilityStatus.PreOrder,
                GameSKUs = GetGameSKUsListWithAllAvailabilityStatuses(),
                Rating = matureESRBRating,
                Name = "a game"
            };

            Mock<IVeilDataAccess> dbStub = TestHelpers.GetVeilDataAccessFake();
            Mock<DbSet<Game>> gameDbSetStub = TestHelpers.GetFakeAsyncDbSet(new List<Game> { matchingGame }.AsQueryable());
            gameDbSetStub.SetupForInclude();

            dbStub.
                Setup(db => db.Games).
                Returns(gameDbSetStub.Object);

            Mock<ControllerContext> contextStub = new Mock<ControllerContext>();
            contextStub.
                SetupUser().
                IsInRole(role);
            contextStub.
                Setup(c => c.HttpContext.Request.Cookies).
                Returns(new HttpCookieCollection
                {
                    new HttpCookie(AgeGateController.DATE_OF_BIRTH_COOKIE, DateTime.MaxValue.ToShortDateString())
                });

            GamesController controller = new GamesController(dbStub.Object, idGetter: null)
            {
                ControllerContext = contextStub.Object
            };

            await controller.Details(matchingGame.Id);

            Assert.That(controller.TempData[AlertHelper.ALERT_MESSAGE_KEY],
                Has.Some.Matches<AlertMessage>(am => am.Message == AgeGateController.AgeBlockMessage));
        }
예제 #26
0
        public async void AdvancedSearch_KeywordIsPartOfTitle_ReturnsIEnumerableOfMatchingGames()
        {
            List<Game> games = GetGameSearchList();
            List<Platform> platforms = GetPlatformList();

            Mock<IVeilDataAccess> dbStub = TestHelpers.GetVeilDataAccessFake();
            Mock<DbSet<Game>> gameDbSetStub = TestHelpers.GetFakeAsyncDbSet(games.AsQueryable());
            Mock<DbSet<Platform>> platformDbSetStub = TestHelpers.GetFakeAsyncDbSet(platforms.AsQueryable());

            dbStub.Setup(db => db.Games).Returns(gameDbSetStub.Object);
            dbStub.Setup(db => db.Platforms).Returns(platformDbSetStub.Object);

            Mock<ControllerContext> contextStub = new Mock<ControllerContext>();
            contextStub.SetupUser().InAllRoles();

            GamesController controller = new GamesController(dbStub.Object, idGetter: null)
            {
                ControllerContext = contextStub.Object
            };

            var result = await controller.AdvancedSearch(null, title: TITLE_FRAGMENT_COMMON_TO_ALL_SEARCH_GAMES) as ViewResult;

            Assert.That(result != null);
            Assert.That(result.Model, Is.InstanceOf<GameListViewModel>());

            var model = (GameListViewModel)result.Model;

            Assert.That(model.Games, Has.Count.EqualTo(games.Count));
        }
예제 #27
0
        public async void Details_UserIsUnprivilegedRole_GameWithRatingMinimumAgeGreaterThanZero_CookieWithAgeLessThanMinimumAge_RedirectsToGamesIndex(string role)
        {
            Game matchingGame = new Game
            {
                Id = gameId,
                GameAvailabilityStatus = AvailabilityStatus.PreOrder,
                GameSKUs = GetGameSKUsListWithAllAvailabilityStatuses(),
                Rating = matureESRBRating,
                Name = "a game"
            };

            Mock<IVeilDataAccess> dbStub = TestHelpers.GetVeilDataAccessFake();
            Mock<DbSet<Game>> gameDbSetStub = TestHelpers.GetFakeAsyncDbSet(new List<Game> { matchingGame }.AsQueryable());
            gameDbSetStub.SetupForInclude();

            dbStub.
                Setup(db => db.Games).
                Returns(gameDbSetStub.Object);

            Mock<ControllerContext> contextStub = new Mock<ControllerContext>();
            contextStub.
                SetupUser().
                IsInRole(role);
            contextStub.
                Setup(c => c.HttpContext.Request.Cookies).
                Returns(new HttpCookieCollection
                {
                    new HttpCookie(AgeGateController.DATE_OF_BIRTH_COOKIE, DateTime.MaxValue.ToShortDateString())
                });

            GamesController controller = new GamesController(dbStub.Object, idGetter: null)
            {
                ControllerContext = contextStub.Object
            };

            var result = await controller.Details(matchingGame.Id) as RedirectToRouteResult;

            Assert.That(result != null);
            Assert.That(result.RouteValues["Action"], Is.EqualTo(nameof(HomeController.Index)));
            Assert.That(result.RouteValues["Controller"], Is.EqualTo("Games"));
        }
예제 #28
0
        public async void AdvancedSearch_TitleMatchingAll_OrdersResultByName()
        {
            List<Game> games = GetGameSearchList();
            List<Platform> platforms = GetPlatformList();

            Mock<IVeilDataAccess> dbStub = TestHelpers.GetVeilDataAccessFake();
            Mock<DbSet<Game>> gameDbSetStub = TestHelpers.GetFakeAsyncDbSet(games.AsQueryable());
            Mock<DbSet<Platform>> platformDbSetStub = TestHelpers.GetFakeAsyncDbSet(platforms.AsQueryable());

            dbStub.Setup(db => db.Games).Returns(gameDbSetStub.Object);
            dbStub.Setup(db => db.Platforms).Returns(platformDbSetStub.Object);

            Mock<ControllerContext> contextStub = new Mock<ControllerContext>();
            contextStub.SetupUser().InAllRoles();

            GamesController controller = new GamesController(dbStub.Object, idGetter: null)
            {
                ControllerContext = contextStub.Object
            };

            var result = await controller.AdvancedSearch(null, title: TITLE_FRAGMENT_COMMON_TO_ALL_SEARCH_GAMES) as ViewResult;

            Assert.That(result != null);
            Assert.That(result.Model, Is.InstanceOf<GameListViewModel>());

            var model = (GameListViewModel)result.Model;

            Assert.That(games, Is.Not.Ordered.By(nameof(Game.Name)), "Games must not be ordered for this test to be valid");
            Assert.That(model.Games, Is.Ordered.By(nameof(Game.Name)));
        }
예제 #29
0
        public async void Details_UserIsPrivilegedRoleWithMRatedGame_ReturnsViewWithModelContainingNotForSaleSKUs(string role)
        {
            Game matchingGame = new Game
            {
                Id = gameId,
                GameAvailabilityStatus = AvailabilityStatus.PreOrder,
                GameSKUs = GetGameSKUsListWithAllAvailabilityStatuses(),
                Rating = matureESRBRating
            };

            Mock<IVeilDataAccess> dbStub = TestHelpers.GetVeilDataAccessFake();
            Mock<DbSet<Game>> gameDbSetStub = TestHelpers.GetFakeAsyncDbSet(new List<Game> { matchingGame }.AsQueryable());
            gameDbSetStub.SetupForInclude();

            dbStub.Setup(db => db.Games).Returns(gameDbSetStub.Object);

            Mock<ControllerContext> contextStub = new Mock<ControllerContext>();
            contextStub.SetupUser().IsInRole(role);

            GamesController controller = new GamesController(dbStub.Object, idGetter: null)
            {
                ControllerContext = contextStub.Object
            };

            var result = await controller.Details(matchingGame.Id) as ViewResult;

            Assert.That(result != null);
            Assert.That(result.Model != null);
            Assert.That(result.Model, Is.InstanceOf<Game>());

            var model = (Game)result.Model;

            Assert.That(model.GameSKUs, Has.Some.Matches<Product>(p => p.ProductAvailabilityStatus == AvailabilityStatus.NotForSale));
        }
예제 #30
0
        public async void AdvancedSearch_DoesNotMatchAnyTag_ReturnsEmpty()
        {
            List<Game> games = GetGameSearchList();
            List<Platform> platforms = GetPlatformList();
            List<Tag> tags = GetTagList();

            Mock<IVeilDataAccess> dbStub = TestHelpers.GetVeilDataAccessFake();
            Mock<DbSet<Game>> gameDbSetStub = TestHelpers.GetFakeAsyncDbSet(games.AsQueryable());
            Mock<DbSet<Platform>> platformDbSetStub = TestHelpers.GetFakeAsyncDbSet(platforms.AsQueryable());
            Mock<DbSet<Tag>> tagDbSetStub = TestHelpers.GetFakeAsyncDbSet(tags.AsQueryable());

            dbStub.Setup(db => db.Games).Returns(gameDbSetStub.Object);
            dbStub.Setup(db => db.Platforms).Returns(platformDbSetStub.Object);
            dbStub.Setup(db => db.Tags).Returns(tagDbSetStub.Object);

            Mock<ControllerContext> contextStub = new Mock<ControllerContext>();
            contextStub.SetupUser().InAllRoles();

            GamesController controller = new GamesController(dbStub.Object, idGetter: null)
            {
                ControllerContext = contextStub.Object
            };

            var result = await controller.AdvancedSearch(new List<string> { "not a match to any tag" }) as ViewResult;

            Assert.That(result != null);
            Assert.That(result.Model, Is.InstanceOf<GameListViewModel>());

            var model = (GameListViewModel)result.Model;

            Assert.That(model.Games, Is.Empty);
        }