Ejemplo n.º 1
0
        public async Task GetDetailsGetsCorrectDetails()
        {
            // Arrange
            var mediaRepoMock = new Mock <IRepository <Media> >();

            var mediaList = this.GetMedia();

            var media = mediaList[0];
            var mock  = mediaList.AsQueryable().BuildMock();

            mediaRepoMock.Setup(x => x.AllAsNoTracking()).Returns(mock.Object);

            var expectedMedia = mediaList.FirstOrDefault();

            var mediaService = new MediaService(
                mediaRepoMock.Object,
                this.genreRepo,
                this.keywordRepo,
                this.mediaKeywordRepo
                );

            var expectedKeywords = media.Keywords.Select(x => new
            {
                Value = x.Keyword.Name,
                Id    = x.KeywordId,
            });

            // Act
            var viewModel = await mediaService.GetDetailsAsync <MediaDetailsViewModel>(media.Id);

            // Arrange
            Assert.Equal(media.Title, viewModel.Title);
            Assert.Equal(media.Overview, viewModel.Overview);
            Assert.Equal(JsonConvert.SerializeObject(expectedKeywords), JsonConvert.SerializeObject(viewModel.Keywords));
        }