Beispiel #1
0
        public void Can_Save_Valid_Changes()
        {
            var mock = new Mock<IGameRepository>();
            var controller = new AdminController(mock.Object);
            var game = new Game {Name = "Test"};
            var result = controller.Edit(game);
            mock.Verify(m => m.SaveGame(game));

            Assert.IsNotInstanceOfType(result, typeof (ViewResult));
        }
Beispiel #2
0
        public void AddItem(Game game, int quantity)
        {
            var line = _lines.FirstOrDefault(g => g.Game.GameId == game.GameId);

            if(line == null)
            {
                _lines.Add(new CartLine{
                    Game = game,
                    Quantity = quantity
                });
            }
            else
                line.Quantity += quantity;
        }
Beispiel #3
0
        public void Can_Add_New_Lines()
        {
            var game1 = new Game {GameId = 1, Name = "Игра1"};
            var game2 = new Game {GameId = 2, Name = "Игра2"};

            var cart = new Cart();

            cart.AddItem(game1, 1);
            cart.AddItem(game2, 1);
            var results = cart.Lines.ToList();

            Assert.AreEqual(results.Count(), 2);
            Assert.AreEqual(results[0].Game, game1);
            Assert.AreEqual(results[1].Game, game2);
        }
Beispiel #4
0
        public void Calculate_Cart_Total()
        {
            var game1 = new Game {GameId = 1, Name = "Игра1", Price = 100};
            var game2 = new Game {GameId = 2, Name = "Игра2", Price = 50};

            var cart = new Cart();

            cart.AddItem(game1, 1);
            cart.AddItem(game2, 1);
            cart.AddItem(game1, 5);

            var result = cart.ComputeTotalValue();

            Assert.AreEqual(result, 650);
        }
Beispiel #5
0
        public void Can_Add_Quantity_For_Existing_Lines()
        {
            var game1 = new Game {GameId = 1, Name = "Игра1"};
            var game2 = new Game {GameId = 2, Name = "Игра2"};

            var cart = new Cart();

            cart.AddItem(game1, 1);
            cart.AddItem(game2, 1);
            cart.AddItem(game1, 5);
            var results = cart.Lines.OrderBy(c => c.Game.GameId).ToList();

            Assert.AreEqual(results.Count(), 2);
            Assert.AreEqual(results[0].Quantity, 6);
            Assert.AreEqual(results[1].Quantity, 1);
        }
        public ActionResult Edit(Game game, HttpPostedFileBase image = null)
        {
            if (ModelState.IsValid)
            {
                if (image != null)
                {
                    game.ImageMimeType = image.ContentType;
                    game.ImageData = new byte[image.ContentLength];
                    image.InputStream.Read(game.ImageData, 0, image.ContentLength);
                }

                _repository.SaveGame(game);
                TempData["message"] = string.Format("Изменения в игре \"{0}\" были сохранены", game.Name);

                return RedirectToAction("Index");
            }

            return View(game);
        }
        public void SaveGame(Game game)
        {
            if (game.GameId == 0)
                _context.Games.Add(game);
            else
            {
                var dbEntry = _context.Games.Find(game.GameId);
                if (dbEntry != null)
                {
                    dbEntry.Name = game.Name;
                    dbEntry.Description = game.Description;
                    dbEntry.Price = game.Price;
                    dbEntry.Category = game.Category;
                    dbEntry.ImageData = game.ImageData;
                    dbEntry.ImageMimeType = game.ImageMimeType;
                }
            }

            _context.SaveChanges();
        }
Beispiel #8
0
        public void Can_Delete_Valid_Games()
        {
            var game = new Game
            {
                GameId = 2,
                Name = "Игра2"
            };

            var mock = new Mock<IGameRepository>();
            mock.Setup(m => m.Games).Returns(new List<Game>
            {
                new Game {GameId = 1, Name = "Игра1"},
                new Game {GameId = 2, Name = "Игра2"},
                new Game {GameId = 3, Name = "Игра3"},
                new Game {GameId = 4, Name = "Игра4"},
                new Game {GameId = 5, Name = "Игра5"}
            });

            var controller = new AdminController(mock.Object);
            controller.Delete(game.GameId);

            mock.Verify(m => m.DeleteGame(game.GameId));
        }
Beispiel #9
0
        public void Can_Clear_Cart()
        {
            var game1 = new Game {GameId = 1, Name = "Игра1", Price = 100};
            var game2 = new Game {GameId = 2, Name = "Игра2", Price = 55};

            var cart = new Cart();

            cart.AddItem(game1, 1);
            cart.AddItem(game2, 1);
            cart.AddItem(game1, 5);
            cart.Clear();

            Assert.AreEqual(cart.Lines.Count(), 0);
        }
Beispiel #10
0
        public void Can_Remove_Line()
        {
            var game1 = new Game {GameId = 1, Name = "Игра1"};
            var game2 = new Game {GameId = 2, Name = "Игра2"};
            var game3 = new Game {GameId = 3, Name = "Игра3"};

            var cart = new Cart();

            cart.AddItem(game1, 1);
            cart.AddItem(game2, 4);
            cart.AddItem(game3, 2);
            cart.AddItem(game2, 1);

            cart.RemoveLine(game2);

            Assert.AreEqual(cart.Lines.Count(c => c.Game == game2), 0);
            Assert.AreEqual(cart.Lines.Count(), 2);
        }
Beispiel #11
0
 public void RemoveLine(Game game)
 {
     _lines.RemoveAll(g => g.Game.GameId == game.GameId);
 }