Example #1
0
        public async Task Map_Should_Return_Null_If_Meetup_Is_Null()
        {
            PodcastModelMapperMock mock = PodcastModelMapperMock.Create();

            IPodcast podcast = null;

            IPodcastModel podcastModel = await mock.Map(podcast);

            Assert.Null(podcastModel);
        }
Example #2
0
        public async Task <IPodcastModel> GetSpecialBySlug(string slug)
        {
            if (slug == null)
            {
                throw new ArgumentNullException(nameof(slug));
            }

            Special special = await _podcastRepository.GetSpecialBySlug(slug);

            IPodcastModel podcastModel = await _podcastModelMapper.Map(special);

            return(podcastModel);
        }
        public async Task <IActionResult> PodcastBySlug(string slug)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            IPodcastModel podcastModel = await _podcastService.GetPodcastBySlug(slug);

            if (podcastModel == null)
            {
                return(NotFound());
            }

            return(Ok(podcastModel));
        }
Example #4
0
        public async Task <IEnumerable <IPodcastModel> > Map(IEnumerable <IPodcast> podcasts)
        {
            if (podcasts == null)
            {
                return(null);
            }

            IList <IPodcastModel> podcastModels = new List <IPodcastModel>();

            foreach (IPodcast podcast in podcasts)
            {
                IPodcastModel podcastModel = await Map(podcast);

                podcastModels.Add(podcastModel);
            }

            return(podcastModels);
        }
        public async Task GetPodcastBySlug_Should_Return_Call_IPodcastRepository_GetPodcastBySlug()
        {
            PodcastServiceMock mock = PodcastServiceMock.Create();

            var slug = "birinci-bolum-dotnet-core";

            mock.PodcastRepository
            .Setup(repository => repository.GetPodcastBySlug(It.Is <string>(s => s == slug)))
            .ReturnsAsync(() => new Podcast());

            mock.PodcastModelMapper
            .Setup(mapper => mapper.Map(It.IsAny <Podcast>()))
            .ReturnsAsync(() => new PodcastModel());

            IPodcastModel podcastModel = await mock.GetPodcastBySlug(slug);

            mock.PodcastRepository.Verify(repository => repository.GetPodcastBySlug(It.IsAny <string>()), Times.Once);
            Assert.NotNull(podcastModel);
        }
        public async Task GetSpecialBySlug_Should_Return_Call_IPodcastRepository_GetSpecialBySlug()
        {
            PodcastServiceMock mock = PodcastServiceMock.Create();

            var slug = "microsoft-ozel-yayini";

            mock.PodcastRepository
            .Setup(repository => repository.GetSpecialBySlug(It.Is <string>(s => s == slug)))
            .ReturnsAsync(() => new Special());

            mock.PodcastModelMapper
            .Setup(mapper => mapper.Map(It.IsAny <Special>()))
            .ReturnsAsync(() => new SpecialModel());

            IPodcastModel specialModel = await mock.GetSpecialBySlug(slug);

            mock.PodcastRepository.Verify(repository => repository.GetSpecialBySlug(It.IsAny <string>()), Times.Once);
            Assert.NotNull(specialModel);
        }
Example #7
0
        public async Task Map_Should_Set_IPodcastModel_Attendees_If_IPodcast_Attendees_Is_Not_Null_Or_Empty()
        {
            PodcastModelMapperMock mock = PodcastModelMapperMock.Create();

            var attendeeName = "Deniz İrgin";

            IPodcast podcast = new Podcast()
            {
                Id               = 1,
                Season           = 1,
                Title            = "Dotnet Core",
                Slug             = "dotnet-core",
                YoutubeUrl       = "youtube.com",
                SoundcloudId     = "2313333",
                ShortDescription = "Çok Kısa",
                LongDescription  = "Long",
                Tags             = new[] { "dotnet", "microsoft" },
                PublishDate      = DateTime.Now,
                Relations        = new[] { new Relation()
                                           {
                                               Id = 1, Type = "medium"
                                           } },
                Attendees = new [] { attendeeName }
            };

            mock.PersonService
            .Setup(service => service.GetPeopleByNames(It.Is <IList <string> >(list => list.Any(s => podcast.Attendees.Contains(s)))))
            .ReturnsAsync(() => new List <Person> {
                new Person()
                {
                    Id = 1, Name = attendeeName
                }
            });

            IPodcastModel podcastModel = await mock.Map(podcast);

            mock.PersonService.Verify(service => service.GetPeopleByNames(It.IsAny <IList <string> >()), Times.Once);
            mock.PersonService.Verify(service => service.GetPersonByName(It.IsAny <string>()), Times.Never);

            Assert.NotNull(podcastModel.Attendees);
            Assert.Equal(podcastModel.Attendees.Length, podcast.Attendees.Length);
            Assert.Equal(attendeeName, podcastModel.Attendees[0].Name);
        }
Example #8
0
        public async Task Map_Should_Not_Set_IPodcastModel_Attendees_If_IPodcast_Attendees_Is_Null_Or_Empty()
        {
            PodcastModelMapperMock mock = PodcastModelMapperMock.Create();

            IPodcast podcast = new Podcast()
            {
                Id               = 1,
                Season           = 1,
                Title            = "Dotnet Core",
                Slug             = "dotnet-core",
                YoutubeUrl       = "youtube.com",
                SoundcloudId     = "2313333",
                ShortDescription = "Çok Kısa",
                LongDescription  = "Long",
                Tags             = new[] { "dotnet", "microsoft" },
                PublishDate      = DateTime.Now,
                Relations        = new[] { new Relation()
                                           {
                                               Id = 1, Type = "medium"
                                           } },
                Attendees = null
            };

            IPodcastModel podcastModel = await mock.Map(podcast);

            void AssertVerify()
            {
                mock.PersonService.Reset();

                mock.PersonService.Verify(service => service.GetPeopleByNames(It.IsAny <IList <string> >()), Times.Never);
                Assert.Null(podcastModel.Attendees);
            }

            AssertVerify();

            podcast.Attendees = new string[0];
            podcastModel      = await mock.Map(podcast);

            AssertVerify();
        }
        public async Task GetP2PBySlug_Should_Return_Call_IPodcastModelMapper_Map()
        {
            PodcastServiceMock mock = PodcastServiceMock.Create();

            var slug = "yalin-kod-bilgem-cakir";

            var p2p = new P2P {
                Id = 1, Title = "Yalın Kod - Bilgem Çakır"
            };

            mock.PodcastRepository
            .Setup(repository => repository.GetP2PBySlug(It.Is <string>(s => s == slug)))
            .ReturnsAsync(() => p2p);

            mock.PodcastModelMapper
            .Setup(mapper => mapper.Map(It.Is <P2P>(p => p.Id == p2p.Id && p.Title == p2p.Title)))
            .ReturnsAsync(() => new P2PModel());

            IPodcastModel p2pModel = await mock.GetP2PBySlug(slug);

            mock.PodcastModelMapper.Verify(repository => repository.Map(It.IsAny <P2P>()), Times.Once);
            Assert.NotNull(p2pModel);
        }
Example #10
0
        public async Task Map_Should_Set_IPodcastModel_Properties_Based_On_IPodcast_Properties()
        {
            PodcastModelMapperMock mock = PodcastModelMapperMock.Create();

            var guestName    = "Fırat Özbolat";
            var attendeeName = "Deniz İrgin";

            IPodcast podcast = new Podcast()
            {
                Id               = 1,
                Season           = 1,
                Title            = "Dotnet Core",
                Slug             = "dotnet-core",
                YoutubeUrl       = "youtube.com",
                SoundcloudId     = "2313333",
                ShortDescription = "Çok Kısa",
                LongDescription  = "Long",
                Tags             = new[] { "dotnet", "microsoft" },
                PublishDate      = DateTime.Now,
                Relations        = new[] { new Relation()
                                           {
                                               Id = 1, Type = "medium"
                                           } },
                Attendees = new[] { attendeeName },
                Guest     = guestName
            };

            mock.PersonService
            .Setup(service => service.GetPeopleByNames(It.Is <IList <string> >(list => list.Any(s => podcast.Attendees.Contains(s)))))
            .ReturnsAsync(() => new List <Person> {
                new Person()
                {
                    Id = 1, Name = attendeeName
                }
            });

            mock.PersonService
            .Setup(service => service.GetPersonByName(It.Is <string>(s => s == guestName)))
            .ReturnsAsync(() => new Person()
            {
                Id = 1, Name = guestName
            });

            IPodcastModel podcastModel = await mock.Map(podcast);

            mock.PersonService.Verify(service => service.GetPeopleByNames(It.IsAny <IList <string> >()), Times.Once);
            mock.PersonService.Verify(service => service.GetPersonByName(It.IsAny <string>()), Times.Once);

            Assert.Equal(podcast.Id, podcastModel.Id);
            Assert.Equal(podcast.Season, podcastModel.Season);
            Assert.Equal(podcast.Title, podcastModel.Title);
            Assert.Equal(podcast.Slug, podcastModel.Slug);
            Assert.Equal(podcast.YoutubeUrl, podcastModel.YoutubeUrl);
            Assert.Equal(podcast.ShortDescription, podcastModel.ShortDescription);
            Assert.Equal(podcast.LongDescription, podcastModel.LongDescription);
            Assert.True(podcast.Tags.Any(s => podcastModel.Tags.Contains(s)));
            Assert.Equal(podcast.PublishDate, podcastModel.PublishDate);
            Assert.Equal(podcast.Relations.Length, podcastModel.Relations.Length);
            Assert.NotNull(podcastModel.Attendees);
            Assert.Equal(podcastModel.Attendees.Length, podcast.Attendees.Length);
            Assert.Equal(attendeeName, podcastModel.Attendees[0].Name);
            Assert.NotNull(podcastModel.Guest);
            Assert.Equal(guestName, podcastModel.Guest.Name);
        }