コード例 #1
0
        public void TestAddGameToCart()
        {
            //Arrange
            var            db = MockDb.CreateMockDb();
            CartController cc = new CartController(db);

            var user = new ClaimsPrincipal(new ClaimsIdentity(new Claim[]
            {
                new Claim(ClaimTypes.Name, "Justin"),
                new Claim(ClaimTypes.NameIdentifier, "*****@*****.**"),
            }, "mock"));

            cc.ControllerContext = new ControllerContext()
            {
                HttpContext = new DefaultHttpContext()
                {
                    User = user
                }
            };

            //Act

            var r = cc.AddToCart(1);

            //Assert
            var result = Assert.IsType <PartialViewResult>(r);

            Assert.NotNull(db.Users.First().CartId);
            Assert.Equal(1, db.CartItems.Count());
        }
コード例 #2
0
        public async void IndexTest()
        {
            //Arrange
            var            dbContext = MockDb.CreateMockDb();
            ShopController sc        = new ShopController(dbContext);
            //Act
            var r = await sc.Index();

            //Assert
            var result = Assert.IsType <ViewResult>(r);
            var model  = Assert.IsAssignableFrom <List <Game> >(result.ViewData.Model);

            Assert.Equal(1, model.Count());
        }
コード例 #3
0
        public void testTotalCartValueWhenCartIsEmpty()
        {
            //Arrange
            var db   = MockDb.CreateMockDb();
            var user = new ClaimsPrincipal(new ClaimsIdentity(new Claim[]
            {
                new Claim(ClaimTypes.Name, "Justin"),
                new Claim(ClaimTypes.NameIdentifier, "*****@*****.**"),
            }, "mock"));
            ShoppingCart shoppingCart = new ShoppingCart(db, user);

            //Act

            //Assert
            Assert.Equal(0, shoppingCart.total);
        }
コード例 #4
0
        public async void TestAddGame()
        {
            //Arrange
            var db = MockDb.CreateMockDb();
            var c  = new GameManagerController(db);

            var game = new Game {
                Name = "Game 2", Description = "Desc 2", DeveloperId = 1, GenreId = 1, ImageUrl = "", MinimumRequirements = "REQ", Price = 29.99m
            };
            //Act
            var r = await c.Create(game);

            //Assert
            var result = Assert.IsType <RedirectToActionResult>(r);

            Assert.Equal("Index", result.ActionName);
            Assert.Equal(1, db.Game.Where(x => x.Name == game.Name && x.Description == game.Description && x.DeveloperId == game.DeveloperId).Count()
                         );
        }
コード例 #5
0
        public async void TestAddInvalidGame()
        {
            //Arrange
            var db = MockDb.CreateMockDb();
            var c  = new GameManagerController(db);

            var game = new Game {
                Description = "Desc 2", DeveloperId = 1, GenreId = 1, ImageUrl = "", MinimumRequirements = "REQ", Price = 29.99m
            };

            c.ModelState.AddModelError("Name", "Required");

            //Act

            var r = await c.Create(game);

            //Assert
            var result = Assert.IsType <ViewResult>(r);
            var model  = Assert.IsAssignableFrom <Game>(result.ViewData.Model);

            Assert.Equal(game, model);
            Assert.IsType <SelectList>(result.ViewData["DeveloperId"]);
            Assert.IsType <SelectList>(result.ViewData["GenreId"]);
        }