Пример #1
0
        public async void Delete_ValidDelete()
        {
            GameProduct aGameProduct = new PhysicalGameProduct()
            {
                GameId = game.Id,
                Id = GameSKUId,
                PlatformCode = ps4Platform.PlatformCode,
                Game = game,
                Platform = ps4Platform,
            };

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

            Mock<DbSet<GameProduct>> gameProductDbSetStub = TestHelpers.GetFakeAsyncDbSet(new List<GameProduct> { aGameProduct }.AsQueryable());

            gameProductDbSetStub.Setup(gp => gp.FindAsync(aGameProduct.Id)).ReturnsAsync(aGameProduct);
            dbStub.Setup(db => db.GameProducts).Returns(gameProductDbSetStub.Object);


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

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

            Assert.That(result != null);
            Assert.That(result.Model, Is.InstanceOf<GameProduct>());
        }
        public void EditDownload_POST_InvalidId_Throws404()
        {
            Mock<IVeilDataAccess> dbStub = TestHelpers.GetVeilDataAccessFake();
            MockDownloadGameProducts(dbStub);

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

            Assert.That(async () => await controller.EditDownloadSKU(id: null, gameProduct: null), Throws.InstanceOf<HttpException>().And.Matches<HttpException>(ex => ex.GetHttpCode() == 404));
        }
        public void EditPhysical_GET_NullId_Throws404()
        {
            Mock<IVeilDataAccess> dbStub = TestHelpers.GetVeilDataAccessFake();
            MockPhysicalGameProducts(dbStub, new List<PhysicalGameProduct>().AsQueryable());

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

            Assert.That(async () => await controller.EditPhysicalSKU(id: null), Throws.InstanceOf<HttpException>().And.Matches<HttpException>(ex => ex.GetHttpCode() == 404));
        }
        public void CreateDownloadSKU_GET_InvalidGameId_Throws404()
        {
            Mock<IVeilDataAccess> dbStub = TestHelpers.GetVeilDataAccessFake();
            MockGames(dbStub);

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

            Assert.That(async () => await controller.CreateDownloadSKU(Guid.Empty), Throws.InstanceOf<HttpException>().And.Matches<HttpException>(e => e.GetHttpCode() == 404));
        }
        public async void CreateDownloadSKU_GET_ValidGameId_ReturnsView()
        {
            Mock<IVeilDataAccess> dbStub = TestHelpers.GetVeilDataAccessFake();
            MockGames(dbStub);
            MockPlatforms(dbStub);
            MockCompanies(dbStub);

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

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

            Assert.That(result != null);
        }
        public async void CreateDownloadSKU_POST_SaveChangesCalledOnce()
        {
            Mock<IVeilDataAccess> dbStub = TestHelpers.GetVeilDataAccessFake();
            dbStub.Setup(db => db.SaveChangesAsync()).ReturnsAsync(1).Verifiable();
            MockGames(dbStub);
            MockEmptyGameProducts(dbStub);

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

            var gameProduct = new DownloadGameProduct();

            await controller.CreateDownloadSKU(game.Id, gameProduct);

            Assert.That(() => dbStub.Verify(db => db.SaveChangesAsync(), Times.Once), Throws.Nothing);
        }
        public async void EditPhysical_POST_HasModelErrors_ShowEditPage()
        {
            Mock<IVeilDataAccess> dbStub = TestHelpers.GetVeilDataAccessFake();
            MockDownloadGameProducts(dbStub);
            MockPlatforms(dbStub);
            MockCompanies(dbStub);

            GameProductsController controller = new GameProductsController(dbStub.Object, idGetter: null);
            controller.ModelState.AddModelError("Name", "Name is required");

            var result = await controller.EditDownloadSKU(downloadGameProduct.Id, downloadGameProduct) as ViewResult;

            Assert.That(result != null);
            Assert.That(result.Model, Is.InstanceOf<DownloadGameProduct>());
            Assert.That(result.Model, Is.EqualTo(downloadGameProduct));
        }
        public async void EditDownload_GET_ValidId_ReturnsView()
        {
            Mock<IVeilDataAccess> dbStub = TestHelpers.GetVeilDataAccessFake();
            MockPlatforms(dbStub);
            MockCompanies(dbStub);
            var downloadGameProductsDbStub = MockDownloadGameProducts(dbStub);
            downloadGameProductsDbStub.Setup(db => db.FindAsync(downloadGameProduct.Id)).ReturnsAsync(downloadGameProduct);

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

            var result = await controller.EditDownloadSKU(downloadGameProduct.Id) as ViewResult;

            Assert.That(result != null);
            Assert.That(result.Model, Is.InstanceOf<DownloadGameProduct>());
            Assert.That(result.Model, Is.EqualTo(downloadGameProduct));
        }
Пример #9
0
        public void Delete_NullID()
        {
            GameProduct gameSku = new PhysicalGameProduct();
            gameSku.GameId = gameId;
            gameSku.Id = GameSKUId;

            Mock<IVeilDataAccess> dbStub = TestHelpers.GetVeilDataAccessFake();
            Mock<DbSet<GameProduct>> gameProductDbSetStub = TestHelpers.GetFakeAsyncDbSet(new List<GameProduct> { gameSku }.AsQueryable());
            gameProductDbSetStub.SetupForInclude();

            gameProductDbSetStub.Setup(gp => gp.FindAsync(gameId)).ReturnsAsync(gameSku);
            dbStub.Setup(db => db.GameProducts).Returns(gameProductDbSetStub.Object);

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

            Assert.That(async () => await controller.Delete(null), Throws.InstanceOf<HttpException>().And.Matches<HttpException>(e => e.GetHttpCode() == 404));
        }
        public async void CreateDownloadSKU_POST_ModelStateIsNotValid()
        {
            Mock<IVeilDataAccess> dbStub = TestHelpers.GetVeilDataAccessFake();
            MockGames(dbStub);
            MockPlatforms(dbStub);
            MockCompanies(dbStub);

            GameProductsController controller = new GameProductsController(dbStub.Object, idGetter: null);
            controller.ModelState.AddModelError("Name", "Name is required");

            var gameProduct = new DownloadGameProduct();

            var result = await controller.CreateDownloadSKU(game.Id, gameProduct) as ViewResult;

            Assert.That(result != null);
            Assert.That(result.Model, Is.InstanceOf<DownloadGameProduct>());
        }
        public void RenderPhysicalGameProductPartial_NullUser_ReturnsPartialViewWithFalseModelProperties()
        {
            PhysicalGameProduct gameProduct = new PhysicalGameProduct();

            Mock<IVeilDataAccess> dbStub = TestHelpers.GetVeilDataAccessFake();
            Mock<DbSet<Member>> memberDbSetStub =
                TestHelpers.GetFakeAsyncDbSet(new List<Member>().AsQueryable());
            memberDbSetStub.
                Setup(mdb => mdb.Find(It.IsAny<Guid>())).
                Returns<Member>(null);

            dbStub.
                Setup(db => db.Members).
                Returns(memberDbSetStub.Object);

            Mock<IGuidUserIdGetter> idGetterStub = TestHelpers.GetSetupIUserIdGetterFake(Guid.Empty);

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

            GameProductsController controller = new GameProductsController(dbStub.Object, idGetterStub.Object)
            {
                ControllerContext = contextStub.Object
            };

            var result = controller.RenderPhysicalGameProductPartial(gameProduct);

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

            var model = (PhysicalGameProductViewModel) result.Model;

            Assert.That(model.GameProduct, Is.SameAs(gameProduct));
            Assert.That(model.NewIsInCart, Is.False);
            Assert.That(model.UsedIsInCart, Is.False);
            Assert.That(model.ProductIsOnWishlist, Is.False);
        }
        public void RenderPhysicalGameProductPartial_UserWithAllInCart_ReturnsPartialViewWithTrueModelProperties()
        {
            PhysicalGameProduct gameProduct = new PhysicalGameProduct
            {
                Id = GameSKUId
            };

            Member member = new Member
            {
                UserId = new Guid("1901C42C-1094-456C-9EAA-87DDC7AFEEC8"),
                Cart = new Cart
                {
                    Items = new List<CartItem>
                    {
                        new CartItem
                        {
                            ProductId = gameProduct.Id,
                            IsNew = true
                        },
                        new CartItem
                        {
                            ProductId = gameProduct.Id,
                            IsNew = false
                        }
                    }
                },
                Wishlist = new List<Product>
                {
                    gameProduct
                }
            };

            Mock<IVeilDataAccess> dbStub = TestHelpers.GetVeilDataAccessFake();
            Mock<DbSet<Member>> memberDbSetStub =
                TestHelpers.GetFakeAsyncDbSet(new List<Member> { member }.AsQueryable());
            memberDbSetStub.
                Setup(mdb => mdb.Find(member.UserId)).
                Returns(member);

            dbStub.
                Setup(db => db.Members).
                Returns(memberDbSetStub.Object);

            Mock<IGuidUserIdGetter> idGetterStub = TestHelpers.GetSetupIUserIdGetterFake(member.UserId);

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

            GameProductsController controller = new GameProductsController(dbStub.Object, idGetterStub.Object)
            {
                ControllerContext = contextStub.Object
            };

            var result = controller.RenderPhysicalGameProductPartial(gameProduct);

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

            var model = (PhysicalGameProductViewModel)result.Model;

            Assert.That(model.GameProduct, Is.SameAs(gameProduct));
            Assert.That(model.NewIsInCart, Is.True);
            Assert.That(model.UsedIsInCart, Is.True);
            Assert.That(model.ProductIsOnWishlist, Is.True);
        }
Пример #13
0
        public async void EditDownload_POST_Valid_RedirectsToGameDetails()
        {
            Mock<IVeilDataAccess> dbStub = TestHelpers.GetVeilDataAccessFake();
            MockDownloadGameProducts(dbStub)
                .Setup(db => db.FindAsync(downloadGameProduct.Id))
                .ReturnsAsync(downloadGameProduct);

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

            var result = await controller.EditDownloadSKU(downloadGameProduct.Id, downloadGameProduct) as RedirectToRouteResult;

            Assert.That(result != null);
            Assert.That(result.RouteValues["Controller"], Is.EqualTo("Games"));
            Assert.That(result.RouteValues["Action"], Is.EqualTo("Details"));
            Assert.That(result.RouteValues["Id"], Is.EqualTo(downloadGameProduct.GameId));
        }
Пример #14
0
        public async void EditDownload_POST_Valid_SaveChangesCalledOnce()
        {
            Mock<IVeilDataAccess> dbStub = TestHelpers.GetVeilDataAccessFake();
            MockDownloadGameProducts(dbStub)
                .Setup(db => db.FindAsync(downloadGameProduct.Id))
                .ReturnsAsync(downloadGameProduct);
            dbStub.Setup(db => db.SaveChangesAsync()).ReturnsAsync(1).Verifiable();

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

            await controller.EditDownloadSKU(downloadGameProduct.Id, downloadGameProduct);

            Assert.That(() => dbStub.Verify(db => db.SaveChangesAsync(), Times.Once), Throws.Nothing);
        }
        public async void CreateDownloadSKU_POST_Valid_RedirectsToGameDetails()
        {
            Mock<IVeilDataAccess> dbStub = TestHelpers.GetVeilDataAccessFake();
            MockGames(dbStub);
            MockEmptyGameProducts(dbStub);

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

            var result = await controller.CreateDownloadSKU(game.Id, new DownloadGameProduct()) as RedirectToRouteResult;

            Assert.That(result != null);
            Assert.That(result.RouteValues["Controller"], Is.EqualTo("Games"));
            Assert.That(result.RouteValues["Action"], Is.EqualTo("Details"));
            Assert.That(result.RouteValues["Id"], Is.EqualTo(game.Id));
        }