Beispiel #1
0
        public ViewResult GetGameByKey(string gamekey)
        {
            GameDto game = _gameService.GetGameByKey(gamekey);

            _gameService.AddView(game.Id);
            game.ViewCount++;

            GameViewModel model = game.ToViewModel();

            return(View(model));
        }
        public void ShouldMap_GameDto_To_GameViewModel()
        {
            var game = new GameDto
            {
                Id             = 1,
                Deleted        = false,
                Key            = "key",
                LanguagesNames = new Dictionary <string, string> {
                    { "ru", "name" }
                },
                LanguagesDescriptions = new Dictionary <string, string> {
                    { "ru", "descriptions" }
                },
                Price          = 10,
                UnitsInStock   = 10,
                ViewCount      = 10,
                PublishingDate = DateTime.UtcNow,
                AddingDate     = DateTime.UtcNow,
                Genres         = new List <GenreDto> {
                    new GenreDto(1, "name", null)
                },
                PlatformTypes = new List <PlatformTypeDto> {
                    new PlatformTypeDto(1, "type")
                },
                Publishers = new List <PublisherDto> {
                    new PublisherDto {
                        CompanyName = "companyName"
                    }
                }
            };

            GameViewModel result = game.ToViewModel();

            Assert.AreEqual(game.Id, result.Id);
            Assert.AreEqual(game.Deleted, result.IsDeleted);
            Assert.AreEqual(game.Key, result.Key);
            Assert.AreEqual(game.LanguagesNames.Values.First(), result.Name);
            Assert.AreEqual(game.LanguagesDescriptions.Values.First(), result.Description);
            Assert.AreEqual(game.Price, result.Price);
            Assert.AreEqual(game.UnitsInStock, result.UnitsInStock);
            Assert.AreEqual(game.ViewCount, result.ViewsCount);
            Assert.AreEqual(game.PublishingDate, result.PublishingDate);
            Assert.AreEqual(game.AddingDate, result.AddingDate);
            Assert.AreEqual(game.Genres.Count, result.Genres.Count);
            Assert.AreEqual(game.PlatformTypes.Count, result.PlatformTypes.Count);
            Assert.AreEqual(game.Publishers.Count, result.Publishers.Count);
        }