public void Setup() { notForSaleSKU = new PhysicalGameProduct { ProductAvailabilityStatus = AvailabilityStatus.NotForSale }; availableSKU = new PhysicalGameProduct { ProductAvailabilityStatus = AvailabilityStatus.Available }; preOrderSKU = new PhysicalGameProduct { ProductAvailabilityStatus = AvailabilityStatus.PreOrder }; discontinuedSKU = new PhysicalGameProduct { ProductAvailabilityStatus = AvailabilityStatus.DiscontinuedByManufacturer }; gameId = new Guid("44B0752E-998B-466A-AAAD-3ED535BA3559"); gameSKUId = new Guid("281B0B14-F775-497B-AAFB-F1036FAB630D"); tag = new Tag { Name = "Test" }; everyoneESRBRating = new ESRBRating { RatingId = "E", Description = "Everyone", MinimumAge = 0}; matureESRBRating = new ESRBRating { RatingId = "M", Description = "Mature", MinimumAge = 17 }; }
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 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 }; }
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() { 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 }; }
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 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)); }
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)); }
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 PartialViewResult RenderPhysicalGameProductPartial(PhysicalGameProduct gameProduct) { PhysicalGameProductViewModel model = new PhysicalGameProductViewModel { GameProduct = gameProduct }; Member currentMember = db.Members.Find(idGetter.GetUserId(User.Identity)); if (currentMember != null) { model.NewIsInCart = currentMember.Cart.Items. Any(i => i.ProductId == gameProduct.Id && i.IsNew); model.UsedIsInCart = currentMember.Cart.Items. Any(i => i.ProductId == gameProduct.Id && !i.IsNew); model.ProductIsOnWishlist = currentMember.Wishlist. Any(p => p.Id == gameProduct.Id); } return PartialView("_PhysicalGameProductPartial", model); }
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>()); }
public async void GameDetailWithOrders_CorrectQuantitiesAndSales() { Guid gameId = new Guid("40D655DF-FB62-4FD5-8065-A81C9868B145"); Guid productId = new Guid("9AEE5E2E-378D-4828-B142-F69B81C53D8C"); int newQty = 1; decimal newPrice = 9.99m; int usedQty = 2; decimal usedPrice = 0.99m; GameProduct gameProduct = new PhysicalGameProduct { Id = productId, GameId = gameId }; Game game = new Game { GameSKUs = new List<GameProduct> { gameProduct } }; WebOrder webOrder = new WebOrder { OrderItems = new List<OrderItem> { new OrderItem { Product = gameProduct, ProductId = gameProduct.Id, IsNew = true, Quantity = newQty, ListPrice = newPrice }, new OrderItem { Product = gameProduct, ProductId = gameProduct.Id, IsNew = false, Quantity = usedQty, ListPrice = usedPrice } }, OrderStatus = OrderStatus.Processed }; 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<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> { 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; decimal totalNewSales = newPrice*newQty; decimal totalUsedSales = usedPrice*usedQty; Assert.That(model.TotalNewSales, Is.EqualTo(totalNewSales)); Assert.That(model.TotalUsedSales, Is.EqualTo(totalUsedSales)); Assert.That(model.TotalSales, Is.EqualTo(totalNewSales + totalUsedSales)); Assert.That(model.TotalNewQuantity, Is.EqualTo(newQty)); Assert.That(model.TotalUsedQuantity, Is.EqualTo(usedQty)); Assert.That(model.TotalQuantity, Is.EqualTo(newQty + usedQty)); }
public void AddItem_NullCart() { Game game = new Game() { Id = GameId, Name = "game" }; GameProduct gameProduct = new PhysicalGameProduct() { Id = Id, BoxArtImageURL = "boxart", NewWebPrice = 79.99m, UsedWebPrice = 44.99m, Platform = new Platform { PlatformName = "PS4", }, Game = game }; Cart cart = new Cart { MemberId = new Guid("45B0752E-998B-477A-AAAD-3ED535BA3559"), Items = new List<CartItem>(), }; Mock<IVeilDataAccess> dbStub = TestHelpers.GetVeilDataAccessFake(); Mock<DbSet<Cart>> cartDbSetStub = TestHelpers.GetFakeAsyncDbSet(new List<Cart> { cart }.AsQueryable()); Mock<DbSet<GameProduct>> gameProductDbSetStub = TestHelpers.GetFakeAsyncDbSet(new List<GameProduct> { gameProduct }.AsQueryable()); cartDbSetStub.Setup(db => db.FindAsync(cart.MemberId)).ReturnsAsync(cart); gameProductDbSetStub.Setup(db => db.FindAsync(gameProduct.Id)).ReturnsAsync(gameProduct); gameProductDbSetStub.SetupForInclude(); dbStub.Setup(db => db.Carts).Returns(cartDbSetStub.Object); dbStub.Setup(db => db.GameProducts).Returns(gameProductDbSetStub.Object); Mock<ControllerContext> contextStub = new Mock<ControllerContext>(); contextStub.Setup(c => c.HttpContext.User.Identity).Returns<IIdentity>(null); contextStub.Setup(c => c.HttpContext.User.Identity.IsAuthenticated).Returns(true); Mock<IGuidUserIdGetter> idGetterStub = new Mock<IGuidUserIdGetter>(); idGetterStub.Setup(id => id.GetUserId(It.IsAny<IIdentity>())).Returns(UserId); CartController controller = new CartController(dbStub.Object, idGetterStub.Object, shippingCostService: null) { ControllerContext = contextStub.Object }; Assert.That(async () => await controller.AddItem(gameProduct.Id, true), Throws.InstanceOf<HttpException>().And.Matches<HttpException>(ex => ex.GetHttpCode() == 404)); }
public void RenderPhysicalGameProduct_CurrentUserIsMember() { Guid gameProductId = new Guid("976ACE77-D87C-4EBE-83A0-46F911F6490E"); PhysicalGameProduct gameProduct = new PhysicalGameProduct() { Id = gameProductId }; Member wishlistOwner = new Member { UserId = Id, WishListVisibility = WishListVisibility.FriendsOnly, RequestedFriendships = new List<Friendship>(), ReceivedFriendships = new List<Friendship>(), UserAccount = new DataModels.Models.Identity.User() { UserName = "******" } }; Member currentMember = new Member { UserId = UserId, Wishlist = new List<Product> { gameProduct }, Cart = new Cart { Items = new List<CartItem> { new CartItem { Product = gameProduct, ProductId = gameProduct.Id, IsNew = true, MemberId = UserId, Quantity = 1 }, new CartItem { Product = gameProduct, ProductId = gameProduct.Id, IsNew = false, MemberId = UserId, Quantity = 1 } } } }; List<Member> members = new List<Member> { wishlistOwner, currentMember }; Mock<IVeilDataAccess> dbStub = TestHelpers.GetVeilDataAccessFake(); Mock<DbSet<Member>> memberDbSetStub = TestHelpers.GetFakeAsyncDbSet(members.AsQueryable()); memberDbSetStub.Setup(db => db.Find(currentMember.UserId)).Returns(currentMember); memberDbSetStub.Setup(db => db.Find(wishlistOwner.UserId)).Returns(wishlistOwner); dbStub.Setup(db => db.Members).Returns(memberDbSetStub.Object); Mock<ControllerContext> context = new Mock<ControllerContext>(); context.Setup(c => c.HttpContext.User.Identity).Returns<IIdentity>(null); context.Setup(c => c.HttpContext.User.Identity.IsAuthenticated).Returns(true); Mock<IGuidUserIdGetter> idGetterStub = new Mock<IGuidUserIdGetter>(); idGetterStub.Setup(id => id.GetUserId(It.IsAny<IIdentity>())).Returns(currentMember.UserId); WishlistController controller = new WishlistController(dbStub.Object, idGetterStub.Object) { ControllerContext = context.Object }; var result = controller.RenderPhysicalGameProduct(gameProduct, wishlistOwner.UserId) as PartialViewResult; Assert.That(result != null); Assert.That(result.Model, Is.InstanceOf<WishlistPhysicalGameProductViewModel>()); var model = (WishlistPhysicalGameProductViewModel)result.Model; Assert.That(model.GameProduct.Id, Is.EqualTo(gameProduct.Id)); Assert.That(model.NewIsInCart); Assert.That(model.UsedIsInCart); Assert.That(model.ProductIsOnWishlist); Assert.That(!model.MemberIsCurrentUser); }
public async void Remove_IdInDb_RedirectsToIndex(bool itemAlreadyInWishlist) { Guid gameProductId = new Guid("976ACE77-D87C-4EBE-83A0-46F911F6490E"); PhysicalGameProduct gameProduct = new PhysicalGameProduct() { Game = new Game() { Name = "TestGame" }, SKUNameSuffix = "TestGameProductName", Id = gameProductId }; Member currentMember = new Member { UserId = UserId, Wishlist = new List<Product>() }; if (itemAlreadyInWishlist) { currentMember.Wishlist.Add(gameProduct); } Mock<IVeilDataAccess> dbStub = TestHelpers.GetVeilDataAccessFake(); Mock<DbSet<Product>> productDbSetStub = TestHelpers.GetFakeAsyncDbSet(new List<Product>().AsQueryable()); productDbSetStub.Setup(db => db.FindAsync(gameProduct.Id)).ReturnsAsync(gameProduct); dbStub.Setup(db => db.Products).Returns(productDbSetStub.Object); Mock<DbSet<Member>> memberDbSetStub = TestHelpers.GetFakeAsyncDbSet(new List<Member> { currentMember }.AsQueryable()); memberDbSetStub.Setup(db => db.FindAsync(currentMember.UserId)).ReturnsAsync(currentMember); 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(currentMember.UserId); WishlistController controller = new WishlistController(dbStub.Object, idGetterStub.Object) { ControllerContext = context.Object }; var result = await controller.Remove(gameProduct.Id) as RedirectToRouteResult; Assert.That(result != null); Assert.That(result.RouteValues["action"], Is.EqualTo("Index")); Assert.That(currentMember.Wishlist.Contains(gameProduct), Is.False); }
public void UpdateQuantity_ItemIsNotInCart_Throws404Exception() { Guid gameProductId = new Guid("976ACE77-D87C-4EBE-83A0-46F911F6490E"); PhysicalGameProduct gameProduct = new PhysicalGameProduct() { Id = Id, BoxArtImageURL = "boxart", NewWebPrice = 12m, UsedWebPrice = 8m, Platform = new Platform { PlatformName = "XBAX", } }; Cart cart = new Cart { MemberId = UserId, Items = new List<CartItem> { new CartItem { Product = gameProduct, ProductId = gameProduct.Id, IsNew = true, MemberId = UserId, Quantity = 1 } } }; Mock<IVeilDataAccess> dbStub = TestHelpers.GetVeilDataAccessFake(); Mock<DbSet<Cart>> cartDbSetStub = TestHelpers.GetFakeAsyncDbSet(new List<Cart> { cart }.AsQueryable()); cartDbSetStub.Setup(db => db.FindAsync(cart.MemberId)).ReturnsAsync(cart); dbStub.Setup(db => db.Carts).Returns(cartDbSetStub.Object); Mock<ControllerContext> contextStub = new Mock<ControllerContext>(); contextStub.Setup(c => c.HttpContext.User.Identity).Returns<IIdentity>(null); contextStub.Setup(c => c.HttpContext.User.Identity.IsAuthenticated).Returns(true); Mock<IGuidUserIdGetter> idGetterStub = new Mock<IGuidUserIdGetter>(); idGetterStub.Setup(id => id.GetUserId(It.IsAny<IIdentity>())).Returns(UserId); CartController controller = new CartController(dbStub.Object, idGetterStub.Object, shippingCostService: null) { ControllerContext = contextStub.Object }; Assert.That(async () => await controller.UpdateQuantity(gameProductId, true, 2), Throws.InstanceOf<HttpException>().And.Matches<HttpException>(ex => ex.GetHttpCode() == 404)); }
public async void UpdateQuantity_ItemIsInCart_NotEnoughNewInventory_ReturnsUpdatedModel() { PhysicalGameProduct gameProduct = new PhysicalGameProduct() { Id = Id, BoxArtImageURL = "boxart", SKUNameSuffix = "GameProductName", Game = new Game { Name = "GameName" }, NewWebPrice = 12m, UsedWebPrice = 8m, Platform = new Platform { PlatformName = "XBAX", }, LocationInventories = new List<ProductLocationInventory> { new ProductLocationInventory { NewOnHand = 5, UsedOnHand = 2 } } }; Cart cart = new Cart { MemberId = UserId, Items = new List<CartItem> { new CartItem { Product = gameProduct, ProductId = gameProduct.Id, IsNew = true, MemberId = UserId, Quantity = 1 } } }; Mock<IVeilDataAccess> dbStub = TestHelpers.GetVeilDataAccessFake(); Mock<DbSet<Cart>> cartDbSetStub = TestHelpers.GetFakeAsyncDbSet(new List<Cart> { cart }.AsQueryable()); cartDbSetStub.Setup(db => db.FindAsync(cart.MemberId)).ReturnsAsync(cart); dbStub.Setup(db => db.Carts).Returns(cartDbSetStub.Object); Mock<ControllerContext> contextStub = new Mock<ControllerContext>(); contextStub.Setup(c => c.HttpContext.User.Identity).Returns<IIdentity>(null); contextStub.Setup(c => c.HttpContext.User.Identity.IsAuthenticated).Returns(true); Mock<IGuidUserIdGetter> idGetterStub = new Mock<IGuidUserIdGetter>(); idGetterStub.Setup(id => id.GetUserId(It.IsAny<IIdentity>())).Returns(UserId); CartController controller = new CartController(dbStub.Object, idGetterStub.Object, new ShippingCostService()) { ControllerContext = contextStub.Object }; var result = await controller.UpdateQuantity(gameProduct.Id, true, 8) as ViewResult; Assert.That(result != null); Assert.That(result.Model, Is.InstanceOf<CartViewModel>()); var model = (CartViewModel)result.Model; Assert.That(model.Cart.Items.Count, Is.EqualTo(1)); Assert.That(model.Cart.Items.FirstOrDefault().Quantity, Is.EqualTo(8)); }
public async void RemoveItem_CatchesOnSave() { Game game = new Game() { Id = GameId, Name = "game" }; GameProduct gameProduct = new PhysicalGameProduct() { Id = Id, BoxArtImageURL = "boxart", NewWebPrice = 79.99m, UsedWebPrice = 44.99m, Platform = new Platform { PlatformName = "PS4", }, Game = game }; CartItem cartItem = new CartItem() { ProductId = gameProduct.Id }; Cart cart = new Cart { MemberId = UserId, Items = new List<CartItem>() { cartItem } }; Member member = new Member() { UserId = UserId, Cart = cart }; Mock<IVeilDataAccess> dbStub = TestHelpers.GetVeilDataAccessFake(); Mock<DbSet<Cart>> cartDbSetStub = TestHelpers.GetFakeAsyncDbSet(new List<Cart> { cart }.AsQueryable()); Mock<DbSet<Member>> memberDbSetStub = TestHelpers.GetFakeAsyncDbSet(new List<Member> { member }.AsQueryable()); Mock<DbSet<GameProduct>> gameProductDbSetStub = TestHelpers.GetFakeAsyncDbSet(new List<GameProduct> { gameProduct }.AsQueryable()); cartDbSetStub.Setup(db => db.FindAsync(cart.MemberId)).ReturnsAsync(cart); gameProductDbSetStub.Setup(db => db.FindAsync(gameProduct.Id)).ReturnsAsync(gameProduct); memberDbSetStub.Setup(db => db.Find(member.UserId)).Returns(member); gameProductDbSetStub.SetupForInclude(); dbStub.Setup(db => db.Carts).Returns(cartDbSetStub.Object); dbStub.Setup(db => db.GameProducts).Returns(gameProductDbSetStub.Object); dbStub.Setup(db => db.Members).Returns(memberDbSetStub.Object); dbStub.Setup(db => db.SaveChangesAsync()).Throws<DbUpdateException>(); Mock<ControllerContext> contextStub = new Mock<ControllerContext>(); contextStub.Setup(c => c.HttpContext.User.Identity).Returns<IIdentity>(null); contextStub.Setup(c => c.HttpContext.User.Identity.IsAuthenticated).Returns(true); Mock<HttpSessionStateBase> sessionStub = new Mock<HttpSessionStateBase>(); contextStub.Setup(s => s.HttpContext.Session).Returns(sessionStub.Object); Mock<IGuidUserIdGetter> idGetterStub = new Mock<IGuidUserIdGetter>(); idGetterStub.Setup(id => id.GetUserId(It.IsAny<IIdentity>())).Returns(UserId); CartController controller = new CartController(dbStub.Object, idGetterStub.Object, shippingCostService: null) { ControllerContext = contextStub.Object }; var result = await controller.RemoveItem(gameProduct.Id, cartItem.IsNew) as RedirectToRouteResult; Assert.That(result != null); Assert.That(result.RouteValues["action"], Is.EqualTo("Index")); }
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); }
public async void Index_ItemsInCart_ReturnsMatchingModel() { PhysicalGameProduct gameProduct = new PhysicalGameProduct() { Id = Id, BoxArtImageURL = "boxart", NewWebPrice = 12m, UsedWebPrice = 8m, Platform = new Platform { PlatformName = "XBAX", } }; Cart cart = new Cart { MemberId = UserId, Items = new List<CartItem> { new CartItem { Product = gameProduct, ProductId = gameProduct.Id, IsNew = true, MemberId = UserId, Quantity = 1 }, new CartItem { Product = gameProduct, ProductId = gameProduct.Id, IsNew = false, MemberId = UserId, Quantity = 2 } } }; Mock<IVeilDataAccess> dbStub = TestHelpers.GetVeilDataAccessFake(); Mock<DbSet<Cart>> cartDbSetStub = TestHelpers.GetFakeAsyncDbSet(new List<Cart> { cart }.AsQueryable()); cartDbSetStub.Setup(db => db.FindAsync(cart.MemberId)).ReturnsAsync(cart); dbStub.Setup(db => db.Carts).Returns(cartDbSetStub.Object); Mock<ControllerContext> contextStub = new Mock<ControllerContext>(); contextStub.Setup(c => c.HttpContext.User.Identity).Returns<IIdentity>(null); contextStub.Setup(c => c.HttpContext.User.Identity.IsAuthenticated).Returns(true); Mock<IGuidUserIdGetter> idGetterStub = new Mock<IGuidUserIdGetter>(); idGetterStub.Setup(id => id.GetUserId(It.IsAny<IIdentity>())).Returns(UserId); CartController controller = new CartController(dbStub.Object, idGetterStub.Object, new ShippingCostService()) { ControllerContext = contextStub.Object }; var result = await controller.Index() as ViewResult; Assert.That(result != null); Assert.That(result.Model, Is.InstanceOf<CartViewModel>()); var model = (CartViewModel)result.Model; Assert.That(model.Cart.Items.Count, Is.EqualTo(2)); Assert.That(model.Cart.Items.FirstOrDefault(i => i.IsNew).ProductId, Is.EqualTo(Id)); Assert.That(model.Cart.Items.FirstOrDefault(i => !i.IsNew).ProductId, Is.EqualTo(Id)); Assert.That(model.Cart.Items.FirstOrDefault(i => i.IsNew).Quantity, Is.EqualTo(1)); Assert.That(model.Cart.Items.FirstOrDefault(i => !i.IsNew).Quantity, Is.EqualTo(2)); }