Esempio n. 1
0
        public void Edit(EditingGameDto editingGame)
        {
            CheckGameTranslationArgumentsValidity(editingGame.LanguagesNames, editingGame.LanguagesDescriptions);

            Game game = GetNotDeletedGame(editingGame.GameId);

            ICollection <Genre> fullGenreTree;

            if (editingGame.GenreIds.Any())
            {
                ICollection <Genre> selectedGenres = GetGenresFromIds(editingGame.GenreIds);
                fullGenreTree = BuildGenreTree(selectedGenres);
            }
            else
            {
                fullGenreTree = new List <Genre> {
                    GetDefaultGenre()
                };
            }

            MapperToModel.MapToModel(
                editingGame,
                game,
                GetPublishersFromIds(editingGame.PublisherIds),
                GetPlatformTypesFromIds(editingGame.PlatformTypeIds),
                fullGenreTree);

            SetTranslationsForGame(game, editingGame.LanguagesNames, editingGame.LanguagesDescriptions);

            UnitOfWork.Games.Update(game);
            UnitOfWork.Save();
        }
Esempio n. 2
0
        public static void MapToModel(
            EditingGameDto game,
            Game model,
            ICollection <Publisher> publishers,
            ICollection <PlatformType> platformTypes,
            ICollection <Genre> genres)
        {
            model.PlatformTypes.Clear();
            model.Publishers.Clear();
            model.Genres.Clear();

            model.Name          = game.LanguagesNames["ru"];
            model.Description   = game.LanguagesDescriptions["ru"];
            model.Price         = game.Price;
            model.UnitsInStock  = game.UnitsInStock;
            model.Discounted    = game.Discounted;
            model.Publishers    = publishers;
            model.PlatformTypes = platformTypes;
            model.Genres        = genres;
        }
Esempio n. 3
0
        public void ShouldEditGame()
        {
            var game = new Game()
            {
                Key           = "key",
                Name          = "name",
                Description   = "description",
                PlatformTypes = new List <PlatformType>(),
            };
            var gameDto = new GameDto
            {
                Key            = "key",
                LanguagesNames = new Dictionary <string, string> {
                    { "ru", "имя" }
                },
                LanguagesDescriptions = new Dictionary <string, string> {
                    { "ru", "описание" }
                }
            };
            var platformTypes = new List <PlatformType>
            {
                new PlatformType(),
                new PlatformType()
            };
            var publishers = new List <Publisher> {
                new Publisher {
                    CompanyName = "CompanyName"
                }
            };
            var genres = new List <Genre> {
                new Genre()
            };

            _unitOfWorkMock
            .Setup(m => m.PlatformTypes.Find(It.IsAny <IPipeline <PlatformType> >()))
            .Returns(platformTypes);

            _unitOfWorkMock
            .Setup(m => m.Publishers.Find(It.IsAny <IPipeline <Publisher> >()))
            .Returns(publishers);

            _unitOfWorkMock
            .Setup(m => m.Genres.Find(It.IsAny <IPipeline <Genre> >()))
            .Returns(genres);

            _unitOfWorkMock
            .Setup(m => m.Games.Get(It.IsAny <int>()))
            .Returns(game);

            var editingGame = new EditingGameDto
            {
                GameId         = 1,
                LanguagesNames = new Dictionary <string, string>()
                {
                    { "ru", "имя" }
                },
                LanguagesDescriptions = new Dictionary <string, string>()
                {
                    { "ru", "описание" }
                },
                Price           = 10,
                UnitsInStock    = 2,
                Discounted      = false,
                PlatformTypeIds = new List <int>()
                {
                    1, 2
                },
                PublisherIds = new List <int>()
                {
                    1
                },
                GenreIds = new List <int>()
                {
                    1
                }
            };

            _service.Edit(editingGame);

            Assert.IsTrue(gameDto.Equals(game.ToDto()));
        }