コード例 #1
0
ファイル: GameService.cs プロジェクト: MaxShustov/GameStore
 public void Edit(GameDTO game)
 {
     if (game == null)
         throw new ArgumentNullException("Game can not be null!!!");
     NotNullGameProperties(game, true);
     _unitOfWork.Games.Update( Mapper.Map<GameDTO, Game>(game) );
     _unitOfWork.SaveChanges();
 }
コード例 #2
0
        public void Test_AddCommentToGame_Body_Is_Null()
        {
            //arrange
            CommentService servise = new CommentService(_unitOfWork.Object);
            CommentDTO comment = new CommentDTO() { ParentCommentId = 2, Body = null, Name = "Autor2" };
            GameDTO game = new GameDTO() { Key = "me3" };

            //act
            servise.AddCommentToGame(comment, game);
        }
コード例 #3
0
 public void AddCommentToGame(CommentDTO comment, GameDTO game)
 {
     if (comment == null || game == null ||comment.Name == null || comment.Body == null || game.Key == null)
         throw new ArgumentNullException();
     IGameRepository games = _unitOfWork.Games as IGameRepository;
     IGenericRepository<Comment> comments = _unitOfWork.Comments;
     Comment fullComment = Mapper.Map<CommentDTO, Comment>(comment);
     fullComment.ParentComment = comment.ParentCommentId != 0 ? comments.GetById(comment.ParentCommentId) : null;
     fullComment.Game = games.GetGameByKey(game.Key);
     comments.Insert(fullComment);
     if (fullComment.ParentComment != null)
     {
         Comment parentComment = fullComment.ParentComment;
         parentComment.ChildComments.Add(fullComment);
         comments.Update(parentComment);
     }
     _unitOfWork.SaveChanges();
 }
コード例 #4
0
        public void Test_UpdateGame()
        {
            //arrange
            GamesController controller = new GamesController(_gameService.Object, null, null, null, null);
            GameDTO game = new GameDTO() { Key = "key", Description = "description", GameId = 1, Name = "name" };

            //act
            var result = controller.Update(game);

            //assert
            _gameService.Verify(s => s.Edit(It.IsAny<GameDTO>()), Times.Once());
        }
コード例 #5
0
        public void Test_EditGame_GameId_Less_Zero()
        {
            //arrange
            GameService servise = new GameService(_unitOfWork.Object, null);
            GameDTO game = new GameDTO()
            {
                GameId = -1,
                Key = "key",
                Description = "Description",
                Name = "Name",
                Genres = genres.Object.GetAll().Take(1).Select(Mapper.Map<Genre, GenreDTO>),
                PlatformTypes = platformTypes.Object.GetAll().Take(1).Select(Mapper.Map<PlatformType, PlatformTypeDTO>),
                Publisher = new PublisherDTO() { CompanyName = "name", PublisherId = 1, Description = "description", HomePage = "home.page" },
                Price = 1,
                Discontinued = false,
                UnitsInStock = 20
            };

            //act
            servise.Edit(game);
        }
コード例 #6
0
        public void Test_EditGame_GameId_Is_Zero()
        {
            //arrange
            GameService servise = new GameService(_unitOfWork.Object, null);
            GameDTO game = new GameDTO()
            {
                GameId = 0,
                Key = "key",
                Description = "Description",
                Name = "Name",
                Genres = genres.Object.GetAll().Take(1).Select(Mapper.Map<Genre, GenreDTO>),
                PlatformTypes = platformTypes.Object.GetAll().Take(1).Select(Mapper.Map<PlatformType, PlatformTypeDTO>)
            };

            //act
            servise.Edit(game);
        }
コード例 #7
0
        public void Test_DeleteGame_Call_Delete()
        {
            //arrange
            GameService servise = new GameService(_unitOfWork.Object, null);
            GameDTO game = new GameDTO()
            {
                GameId = 1,
                Key = "key",
                Description = "Description",
                Name = "Name",
                Genres = genres.Object.GetAll().Take(1).Select(Mapper.Map<Genre, GenreDTO>),
                PlatformTypes = platformTypes.Object.GetAll().Take(1).Select(Mapper.Map<PlatformType, PlatformTypeDTO>),
                Publisher = new PublisherDTO() { CompanyName = "name", PublisherId = 1, Description = "description", HomePage = "home.page" },
                Price = 1,
                Discontinued = false,
                UnitsInStock = 20
            };

            //act
            servise.Delete(game);

            //assert
            games.Verify(g => g.Delete(It.IsAny<Game>()), Times.Once());
        }
コード例 #8
0
        public void Test_CreateGame_Game_PlatformType_Is_Null()
        {
            //arrange
            GameService servise = new GameService(_unitOfWork.Object, null);
            GameDTO game = new GameDTO()
            {
                Key = "key",
                Description = "Description",
                Name = "Name",
                Genres = genres.Object.GetAll().Take(1).Select(Mapper.Map<Genre, GenreDTO>),
                PlatformTypes = null
            };

            //act
            servise.CreateGame(game);
        }
コード例 #9
0
        public void Test_CreateGame_Game_PlatformTypes_Has_PlatfromType_With_Id_Less_Zero()
        {
            //arrange
            GameService servise = new GameService(_unitOfWork.Object, null);
            GameDTO game = new GameDTO()
            {
                Key = "key",
                Description = "Description",
                Name = "Name",
                Genres = new List<GenreDTO>() { new GenreDTO() { GenreId = 1, Name = "Name" } },
                PlatformTypes = new List<PlatformTypeDTO>() { new PlatformTypeDTO() { PlatformTypeId = -1, Name = "Name" } }
            };

            //act
            servise.CreateGame(game);
        }
コード例 #10
0
        public void Test_CreateGame_Game_Genres_Has_Genre_With_Id_Less_Zero()
        {
            //arrange
            GameService servise = new GameService(_unitOfWork.Object, null);
            GameDTO game = new GameDTO()
            {
                Key = "key",
                Description = "Description",
                Name = "Name",
                Genres = new List<GenreDTO>() { new GenreDTO() { GenreId = -1, Name = "Name" } },
                PlatformTypes = platformTypes.Object.GetAll().Take(1).Select(Mapper.Map<PlatformType, PlatformTypeDTO>)
            };

            //act
            servise.CreateGame(game);
        }
コード例 #11
0
        public void Test_AddCommentToGame_With_ParrentId()
        {
            //arrange
            CommentService servise = new CommentService(_unitOfWork.Object);
            CommentDTO comment = new CommentDTO() { ParentCommentId = 2, Body = "Text4", Name = "Autor2" };
            GameDTO game = new GameDTO() { Key = "me3" };

            //act
            servise.AddCommentToGame(comment, game);

            //assert
            _comments.Verify(c => c.Insert(It.IsAny<Comment>()), Times.Once());
        }
コード例 #12
0
 public ActionResult Update(GameDTO game)
 {
     _gameService.Edit(game);
     return Json(game);
 }
コード例 #13
0
 public ActionResult Remove(GameDTO game)
 {
     _gameService.Delete(game);
     return Json(game);
 }
コード例 #14
0
ファイル: GameService.cs プロジェクト: MaxShustov/GameStore
 private void NotNullGameProperties( GameDTO game, bool editMode = false )
 {
     if (string.IsNullOrEmpty(game.Key))
         throw new ArgumentNullException("Game key can not be null or empty!!!");
     if (string.IsNullOrEmpty(game.Description))
         throw new ArgumentNullException("Game description can not be null or empty");
     if (string.IsNullOrEmpty(game.Name))
         throw new ArgumentNullException("Game name can not be null or empty");
     if (game.Genres == null || !game.Genres.Any())
         throw new ArgumentNullException("Game must have at least one genre");
     if (game.PlatformTypes == null || !game.PlatformTypes.Any())
         throw new ArgumentNullException("Game must have at least one platform type");
     if (game.Publisher == null || !NotNullPublisherProperties(game.Publisher))
         throw new ArgumentNullException("Publisher can not be null");
     if (editMode && game.GameId <= 0 )
         throw new ArgumentNullException("Game must have not zero id");
     foreach (GenreDTO genreDto in game.Genres)
     {
         NotNullGenreProperties(genreDto, true);
     }
     foreach (PlatformTypeDTO platformTypeDto in game.PlatformTypes)
     {
         NotNullPlatformTypeProperties(platformTypeDto,true);
     }
 }