コード例 #1
0
ファイル: GameEngine.cs プロジェクト: gareth-reid/Rockmelon
 public void BuildRating(Game game)
 {
     game.Ratings.Add(new Rating()
     {
         RatingValue = game.RatingValue,
         GameId = game.GameId,
         Game = game
     });
 }
コード例 #2
0
 public void Validate(Game game)
 {
     //could but this into an engine
     if(game.Ratings != null && game.Ratings.First().RatingId > 5)
     {
         throw new DataException("Rating can not be greater then 5");
     }
     if(String.IsNullOrEmpty(game.Title))
     {
         throw new DataException("Title required");
     }
 }
コード例 #3
0
ファイル: GameManager.cs プロジェクト: gareth-reid/Rockmelon
        public void SaveGame(Game game)
        {
            _GameEngine.BuildRating(game);
            _GameValidator.Validate(game);
            //TODO: cascade properly
            foreach (var rating in game.Ratings)
            {
                _RatingRepository.Save(rating);
            }

            _GameRepository.Save(game);
        }
コード例 #4
0
 public void Game_UpdateRating_ReturnZero()
 {
     base.Init();
     var g = new Game()
     {
         Description = "desc",
         GameId = 1,
         Title = "Title"
     };
     //no ratings
     var total = g.TotalRating();
     Assert.AreEqual(total, 0);
 }
コード例 #5
0
        public void Game_Save()
        {
            base.Init();
            var r = new Mock<IRepository<Game>>();
            r.Setup(o => o.GetAll()).Returns(new List<Game>() { new Game() { GameId = 1, Description = "Gears of War 3" } });
            Ioc.Container.Register<IRepository<Game>>(r.Object);

            var person = new Game()
            {
                Description = "Gareth"
            };
            var personRepo = new GameRepository(r.Object);
            var result = personRepo.Get(1);
        }
コード例 #6
0
 public void Game_Get()
 {
     base.Init();
     var gRepo = Ioc.Container.Get<IGameRepository>();
     var g = new Game()
     {
         Title = _title,
         Description = ""
     };
     gRepo.Save(g);
     var reload = gRepo.Get(g.GameId);
     Assert.IsNotNull(reload);
     Assert.AreEqual(_title, reload.Title);
 }
コード例 #7
0
 public void Game_ChangeDescription_Save()
 {
     base.Init();
     var gRepo = Ioc.Container.Get<IGameRepository>();
     var g = new Game()
     {
         Title = _title,
         Description = _description
     };
     gRepo.Save(g);
     var g2 = gRepo.Get(g.GameId);
     g2.Description = "NewDesc";
     gRepo.Save(g2);
     Assert.AreNotEqual(_description, g2.Description);
 }
コード例 #8
0
 public void Game_UpdateRating_Success()
 {
     base.Init();
     var g = new Game()
     {
         Description = "desc",
         GameId = 1,
         Title = "Title"
     };
     g.Ratings.Add(BuildRating(1));
     g.Ratings.Add(BuildRating(2));
     g.Ratings.Add(BuildRating(3));
     g.Ratings.Add(BuildRating(4));
     g.Ratings.Add(BuildRating(5));
     var total = g.TotalRating();
     //15 / 5 = 3
     Assert.AreEqual(total, 3);
 }
コード例 #9
0
        public void Game_ChangeRating_Save()
        {
            base.Init();
            var gRepo = Ioc.Container.Get<IGameRepository>();
            var g = new Game()
            {
                Title = _title,
                Description = "",
            };

            gRepo.Save(g);
            g.Ratings.Add(new Rating() { RatingValue = 3, GameId = g.GameId});
            gRepo.Save(g);

            var g2 = gRepo.Get(g.GameId);
            gRepo.Save(g2);
            g2.Ratings.Add(new Rating() { RatingValue = 5, GameId = g2.GameId});
            gRepo.Save(g2);
            Assert.AreEqual(2, g2.Ratings.Count());
            Assert.AreEqual(3, g2.Ratings.First().RatingValue);
            Assert.AreEqual(5, g2.Ratings.ToList()[1].RatingValue);
        }
コード例 #10
0
 public void Save(Game game)
 {
     _Repository.Save(game, g => g.GameId);
 }
コード例 #11
0
 public void Game_Save()
 {
     base.Init();
     var gRepo = Ioc.Container.Get<IGameRepository>();
     var g = new Game()
     {
         Title = _title,
         Description = ""
     };
     gRepo.Save(g);
     Assert.IsNotNull(g);
     Assert.IsTrue(g.GameId > 0);
 }