Ejemplo n.º 1
0
        public async void Details_UserIsEmployee_ReturnsViewWithModel()
        {
            Game matchingGame = new Game
            {
                Id = gameId,
                GameAvailabilityStatus = AvailabilityStatus.Available
            };

            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().InEmployeeRole();

            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));
        }
Ejemplo n.º 2
0
        public async void Wishlist_GameWithNoProducts_IsNotInModel()
        {
            var game = new Game
            {
                Id = new Guid("09BD7D30-5268-4A02-A400-1F302040B6AA"),
                GameSKUs = new List<GameProduct>()
            };

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

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

            Mock<DbSet<Platform>> platformDbSetStub = TestHelpers.GetFakeAsyncDbSet(new List<Platform>().AsQueryable());
            dbStub.Setup(db => db.Platforms).Returns(platformDbSetStub.Object);

            Mock<DbSet<Member>> memberDbSetStub = TestHelpers.GetFakeAsyncDbSet(new List<Member>().AsQueryable());
            dbStub.Setup(db => db.Members).Returns(memberDbSetStub.Object);

            ReportsController controller = new ReportsController(dbStub.Object);

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

            Assert.That(result != null);

            var model = (WishlistViewModel)result.Model;

            Assert.That(model.Games.Count(), Is.EqualTo(0));
            Assert.That(model.WishlistCount, Is.EqualTo(0));
        }
Ejemplo n.º 3
0
        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"));
        }
Ejemplo n.º 4
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>());
        }
        public void Setup()
        {
            gameId = new Guid("44B0752E-998B-466A-AAAD-3ED535BA3559");
            GameSKUId = new Guid("3FE5BFCF-0A01-4EC2-A662-ADA08A2C34D2");

            game = new Game
            {
                Id = gameId,
                Name = "A game"
            };

            ps4Platform = new Platform
            {
                PlatformCode = "PS4",
                PlatformName = "Playstation 4"
            };

            veilCompany = new Company()
            {
                Id = new Guid("B4FDA176-1EA6-469A-BB02-75125D811ED4"),
                Name = "Veil"
            };

            physicalGameProduct = new PhysicalGameProduct
            {
                Id = new Guid("E7746CD1-106E-4622-BC10-E13CCCCA7AC9"),
                GameId = game.Id
            };

            downloadGameProduct = new DownloadGameProduct
            {
                Id = new Guid("2A1474A0-7ABA-41D6-BBD1-2DF28F43786E"),
                GameId = game.Id
            };
        }
Ejemplo n.º 6
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));
        }
        public void Setup()
        {
            memberGuid = new Guid("2A384A50-E02A-43C9-AEB8-974DF0D32C38");
            gameProductGuid = new Guid("12803115-7E2B-4E34-A492-C388DD37E6AF");

            pendinGameReview = new GameReview()
            {
                MemberId = memberGuid,
                ProductReviewedId = gameProductGuid,
                ReviewStatus = ReviewStatus.Pending
            };

            approvedGameReview = new GameReview()
            {
                MemberId = memberGuid,
                ProductReviewedId = gameProductGuid,
                ReviewStatus = ReviewStatus.Approved
            };

            deniedGameReview = new GameReview()
            {
                MemberId = memberGuid,
                ProductReviewedId = gameProductGuid,
                ReviewStatus = ReviewStatus.Denied
            };

            physicalGameProduct = new PhysicalGameProduct
            {
                Reviews = new List<GameReview>()
                {
                    approvedGameReview
                }
            };

            game = new Game()
            {
                GameSKUs = new List<GameProduct> {physicalGameProduct},
            };

            memberId = new Guid("DB6EF48B-839E-4A54-AFA2-B772738D01DB");

            ratingOnlyReview = new GameReview
            {
                ProductReviewed = physicalGameProduct,
                Rating = 5
            };

            fullReview = new GameReview
            {
                ProductReviewed = physicalGameProduct,
                Rating = 4,
                ReviewText = "Test"
            };
        }
 public void Setup()
 {
     db = new VeilDataContext();
     game = new Game
     {
         Name = "A Game",
         ESRBRatingId = "E",
         MinimumPlayerCount = 1,
         MaximumPlayerCount = 1,
         ShortDescription = "Short Description"
     };
 }
Ejemplo n.º 9
0
        public void Setup()
        {
            GameProduct futureGameProduct = new PhysicalGameProduct()
            {
                ReleaseDate = DateTime.MaxValue
            };

            List<GameProduct> futureGames = new List<GameProduct>()
            {
                futureGameProduct
            };

            GameProduct pastGameProduct = new PhysicalGameProduct()
            {
                ReleaseDate = DateTime.MinValue
            };

            List<GameProduct> pastGames = new List<GameProduct>()
            {
                pastGameProduct
            };

            futureGame1 = new Game()
            {
                GameSKUs = futureGames
            };

            futureGame2 = new Game()
            {
                GameSKUs = futureGames
            };

            pastGame1 = new Game()
            {
                GameSKUs = pastGames
            };

            pastGame2 = new Game()
            {
                GameSKUs = pastGames
            };

            pastGame3 = new Game()
            {
                GameSKUs = pastGames
            };
        }
Ejemplo n.º 10
0
        public async void GameListWithOrders_ContainsOrders_CorrectQuantity()
        {
            Guid productId = new Guid("9AEE5E2E-378D-4828-B142-F69B81C53D8C");

            GameProduct gameProduct = new PhysicalGameProduct { Id = productId };

            Game game = new Game  { GameSKUs = new List<GameProduct> { gameProduct } };

            WebOrder webOrder = new WebOrder
            {
                OrderItems = new List<OrderItem>
                {
                    new OrderItem
                    {
                        Product = gameProduct,
                        ProductId = gameProduct.Id,
                        Quantity = 2
                    }
                }
            };

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

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

            Mock<DbSet<WebOrder>> dbWebOrdersStub = TestHelpers.GetFakeAsyncDbSet(new List<WebOrder> {webOrder}.AsQueryable());
            dbStub.Setup(db => db.WebOrders).Returns(dbWebOrdersStub.Object);

            ReportsController controller = new ReportsController(dbStub.Object);

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

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

            var model = (DateFilteredListViewModel<GameListRowViewModel>)result.Model;
            var items = model.Items;

            Assert.That(items.Count, Is.EqualTo(1));

            var item = items[0];

            Assert.That(item.QuantitySold, Is.EqualTo(2));
        }
Ejemplo n.º 11
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"));
        }
Ejemplo n.º 12
0
        public async void GameDetailWithOrders_NoOrders()
        {
            Guid gameId = new Guid("40D655DF-FB62-4FD5-8065-A81C9868B145");
            Guid productId = new Guid("9AEE5E2E-378D-4828-B142-F69B81C53D8C");

            GameProduct gameProduct = new PhysicalGameProduct
            {
                Id = productId,
                GameId = gameId
            };

            Game game = new Game { GameSKUs = new List<GameProduct>() };

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

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

            Mock<DbSet<GameProduct>> dbGameProductStub = TestHelpers.GetFakeAsyncDbSet(new List<GameProduct> { gameProduct }.AsQueryable());
            dbStub.Setup(db => db.GameProducts).Returns(dbGameProductStub.Object);

            Mock<DbSet<WebOrder>> dbWebOrdersStub = TestHelpers.GetFakeAsyncDbSet(new List<WebOrder>().AsQueryable());
            dbStub.Setup(db => db.WebOrders).Returns(dbWebOrdersStub.Object);

            ReportsController controller = new ReportsController(dbStub.Object);

            var result = await controller.GameDetail(gameId) as ViewResult;

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

            var model = (GameDetailViewModel)result.Model;

            Assert.That(model.Items.Count, Is.EqualTo(1));

            Assert.That(model.TotalNewSales, Is.EqualTo(0));
            Assert.That(model.TotalUsedSales, Is.EqualTo(0));
            Assert.That(model.TotalSales, Is.EqualTo(0));

            Assert.That(model.TotalNewQuantity, Is.EqualTo(0));
            Assert.That(model.TotalUsedQuantity, Is.EqualTo(0));
            Assert.That(model.TotalQuantity, Is.EqualTo(0));
        }
Ejemplo n.º 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);
        }
Ejemplo n.º 14
0
        public async void Create_POST_WithTags_GamesAddCalledOnce()
        {
            var tags = new List<Tag> { tag };
            var tagNames = new List<string> { tag.Name };
            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<Tag>> tagDbSetStub = TestHelpers.GetFakeAsyncDbSet(tags.AsQueryable());
            dbStub.Setup(db => db.Tags).Returns(tagDbSetStub.Object);

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

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

            Assert.That(() => gamesDbSetStub.Verify(gdb => gdb.Add(game), Times.Once), Throws.Nothing);
        }
Ejemplo n.º 15
0
        public async void Edit_POST_Valid_NoTags()
        {
            var game = new Game { Id = gameId, Tags = new List<Tag>(), ContentDescriptors = new List<ESRBContentDescriptor>() };

            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());
            gameDbSetStub.SetupForInclude();
            dbStub.Setup(db => db.Games).Returns(gameDbSetStub.Object);

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

            Mock<DbSet<Tag>> tagsDbSetStub = TestHelpers.GetFakeAsyncDbSet(new List<Tag>().AsQueryable());
            dbStub.Setup(db => db.Tags).Returns(tagsDbSetStub.Object);

            Mock<DbSet<ESRBContentDescriptor>> contentDescriptorStub = TestHelpers.GetFakeAsyncDbSet(new List<ESRBContentDescriptor>().AsQueryable());
            dbStub.Setup(db => db.ESRBContentDescriptors).Returns(contentDescriptorStub.Object);

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

            var result = await controller.Edit(game, null, contentDescriptors: null) as RedirectToRouteResult;

            Assert.That(result != null);
            Assert.That(game.Tags, Is.Empty);
            Assert.That(result.RouteValues["Action"], Is.EqualTo("Details"));
            Assert.That(result.RouteValues["Id"], Is.EqualTo(game.Id));
        }
Ejemplo n.º 16
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>());
        }
Ejemplo n.º 17
0
        /// <summary>
        /// Sets a Game's Tag to the provided list of tags by name. Note that this clears any existing tags.
        /// </summary>
        /// <param name="game">The game to set the tags on.</param>
        /// <param name="tagNames">A list of tag names to add to the game.</param>
        private async Task SetTags(Game game, List<string> tagNames)
        {
            //Clear any existing tags in the game
            game.Tags.Clear();

            if (tagNames == null)
            {
                return;
            }

            //Add all of the new tags by name
            foreach (var tagName in tagNames)
            {
                var tag = await db.Tags.FirstOrDefaultAsync(t => t.Name == tagName);
                if (tag != null)
                {
                    game.Tags.Add(tag);
                }
            }
        }
Ejemplo n.º 18
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));
        }
Ejemplo n.º 19
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"));
        }
Ejemplo n.º 20
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));
        }
Ejemplo n.º 21
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));
        }
Ejemplo n.º 22
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));
        }
Ejemplo n.º 23
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));
        }
Ejemplo n.º 24
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));
        }
Ejemplo n.º 25
0
        public async void DeleteConfirmed_CatchesOnSaveDelete()
        {
            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);
            dbStub.Setup(db => db.SaveChangesAsync()).Throws<DbUpdateException>();

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

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

            Assert.That(result != null);
        }
Ejemplo n.º 26
0
        public void DeleteConfirmed_SaveAsyncThrowingForeignKeyViolationException_HandlesException()
        {
            Game game = new Game
            {
                Id = gameId,
                GameSKUs = new List<GameProduct>()
            };

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

            Mock<DbSet<Game>> gameDbSetStub = TestHelpers.GetFakeAsyncDbSet(new List<Game> { game }.AsQueryable());
            gameDbSetStub.
                Setup(gdb => gdb.FindAsync(It.IsAny<Guid>())).
                ReturnsAsync(game);

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

            DbUpdateException orderConstraintException = new DbUpdateException("See inner",
                SqlExceptionCreator.Create( // This message was copied verbatim from the actual exception being thrown
                    "The DELETE statement conflicted with the REFERENCE constraint " +
                    "\"FK_dbo.ProductLocationInventory_dbo.Product_ProductId\"." +
                    "The conflict occurred in database \"prog3050\", table " +
                    "\"dbo.ProductLocationInventory\", column 'ProductId'." +
                    "The statement has been terminated.",
                    (int)SqlErrorNumbers.ConstraintViolation));

            dbStub.
                Setup(db => db.SaveChangesAsync()).
                ThrowsAsync(orderConstraintException);

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

            Assert.That(async () => await controller.DeleteGameConfirmed(game.Id), Throws.Nothing);
        }
Ejemplo n.º 27
0
        public void DeleteConfirmed_IdNotInDb()
        {
            Game aGame = new Game
            {
                Id = gameId,
                GameSKUs = new List<GameProduct>()
            };

            Guid nonMatch = Guid.Empty;

            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);

            Assert.That(async () => await controller.DeleteGameConfirmed(nonMatch), Throws.InstanceOf<HttpException>().And.Matches<HttpException>(e => e.GetHttpCode() == 404));
        }
Ejemplo n.º 28
0
        /// <summary>
        /// Sets a Game's ESRB Content Descriptors to the provided list of content descriptors by Id. Note that this clears any existing descriptors.
        /// </summary>
        /// <param name="game">The game to set the content descriptors on.</param>
        /// <param name="contentDescriptors">A list of ESRB Content Descriptor Ids to add to the game.</param>
        private async Task SetESRBContentDescriptors(Game game, List<int> contentDescriptors)
        {
            //Clear any existing content descriptors for the game
            game.ContentDescriptors.Clear();

            if (contentDescriptors == null)
            {
                return;
            }

            var results = await db.ESRBContentDescriptors.Where(e => contentDescriptors.Contains(e.Id)).ToListAsync();
            foreach (var esrbContentDescriptor in results)
            {
                game.ContentDescriptors.Add(esrbContentDescriptor);
            }
        }
Ejemplo n.º 29
0
        public async void Edit_POST_Valid_ConfirmSaveChangesAsyncCalled()
        {
            var game = new Game { Id = gameId, Tags = new List<Tag>(), ContentDescriptors = new List<ESRBContentDescriptor>() };

            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());
            gameDbSetStub.SetupForInclude();
            dbStub.Setup(db => db.Games).Returns(gameDbSetStub.Object);
            dbStub.Setup(db => db.SaveChangesAsync()).ReturnsAsync(1).Verifiable();


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

            Mock<DbSet<Tag>> tagsDbSetStub = TestHelpers.GetFakeAsyncDbSet(new List<Tag>().AsQueryable());
            dbStub.Setup(db => db.Tags).Returns(tagsDbSetStub.Object);

            Mock<DbSet<ESRBContentDescriptor>> contentDescriptorStub = TestHelpers.GetFakeAsyncDbSet(new List<ESRBContentDescriptor>().AsQueryable());
            dbStub.Setup(db => db.ESRBContentDescriptors).Returns(contentDescriptorStub.Object);

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

            await controller.Edit(game, null, contentDescriptors: null);

            //Note: this is called exactly 2 times instead of once due to the Tag saving workaround.
            Assert.That(() => dbStub.Verify(db => db.SaveChangesAsync(), Times.Exactly(2)), Throws.Nothing);
        }
Ejemplo n.º 30
0
        public async void Edit_POST_Invalid_ModelState_IsValid_False()
        {
            var game = new Game();
            Mock<IVeilDataAccess> dbStub = TestHelpers.GetVeilDataAccessFake();

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


            GamesController controller = new GamesController(dbStub.Object, idGetter: null);
            controller.ModelState.AddModelError("id", "id");

            var result = await controller.Edit(game, tags: null, contentDescriptors: null) as ViewResult;

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