Exemplo n.º 1
0
        public void Should_ReturnCourseCoAuthorWithFullnamesakeMark_WhenAuthorNameInFullnamesakeContainer()
        {
            // Arrange
            var author = new PluralsightAuthor
            {
                FullName = "John Smith"
            };

            var course = new PluralsightCourse();

            var fullnamesakesAuthorsContainer =
                new Dictionary <IAuthorFullNameNaturalKey, PluralsightAuthor>(
                    FullNameNaturalKeyEqualityComparer <IAuthorFullNameNaturalKey> .Instance);

            var allAuthorsExceptFullnamesakesContainer =
                new Dictionary <IAuthorFullNameNaturalKey, PluralsightAuthor>(
                    FullNameNaturalKeyEqualityComparer <IAuthorFullNameNaturalKey> .Instance);

            fullnamesakesAuthorsContainer.Add(author, author);

            var nodeSelector = Mock.Of <INodeSelector>();
            var nodeParser   = Mock.Of <INodeParser>();

            var sut = new PluralsightCatalogParser(nodeSelector, nodeParser);

            // Act
            var result = sut.GetCourseCoAuthor(course, author, allAuthorsExceptFullnamesakesContainer, fullnamesakesAuthorsContainer);

            // Assert
            Assert.NotNull(result);
            Assert.Same(course, result.Course);
            Assert.Same(author, result.Author);

            Assert.Equal(true, result.HasFullnamesake);
        }
      /// <exception cref="ArgumentNullException"><paramref name="authorNode"/> is <see langword="null" />.</exception>
      public PluralsightAuthor ParseAuthor(INode authorNode)
      {
         if (authorNode == null) 
            throw new ArgumentNullException("authorNode");

         var authorFullName = authorNode.GetAttributeValue(Constants.AuthorFullNameAttribute);
         var authorUrl = authorNode.GetAttributeValue(Constants.AuthorUrlAttribute);
         var authorUriBuilder = new UriBuilder(new Uri(authorUrl))
         {
            Scheme = Uri.UriSchemeHttp
         };

         var authorUri = authorUriBuilder.Uri;

         var author = new PluralsightAuthor
         {
            FullName = HttpUtility.HtmlDecode(authorFullName),
            SiteUrl = authorUri.ToString(),
            UrlName = authorUri.Segments.Last()
         };

         return author;
      }
Exemplo n.º 3
0
        public void Should_ReturnCourseAuthors()
        {
            // Arrange
            var coAuthors = new[] { "Eric Burke", "Steve Evans", "Rob Windsor" }
            .Select(x => new PluralsightAuthor {
                FullName = x
            }).ToList();

            var author = new PluralsightAuthor {
                FullName = "John Smith", UrlName = "john-smith"
            };

            var coAuthorNode = Mock.Of <INode>();
            var authorNode   = Mock.Of <INode>();

            var course = new PluralsightCourse();

            var fullnamesakesAuthorsContainer = new Dictionary <IAuthorFullNameNaturalKey, PluralsightAuthor>(
                FullNameNaturalKeyEqualityComparer <IAuthorFullNameNaturalKey> .Instance);

            fullnamesakesAuthorsContainer.Add(coAuthors[1], coAuthors[1]);


            var allAuthorsExceptFullnamesakesContainer = new Dictionary <IAuthorFullNameNaturalKey, PluralsightAuthor>(
                FullNameNaturalKeyEqualityComparer <IAuthorFullNameNaturalKey> .Instance);

            allAuthorsExceptFullnamesakesContainer.Add(coAuthors[0], coAuthors[0]);
            allAuthorsExceptFullnamesakesContainer.Add(coAuthors[2], coAuthors[2]);
            allAuthorsExceptFullnamesakesContainer.Add(author, author);

            var allAuthorsExceptWhoseUrlNullContainer = new Dictionary <IAuthorUrlNameNaturalKey, PluralsightAuthor>(
                UrlNameNaturalKeyEqualityComparer <IAuthorUrlNameNaturalKey> .Instance);

            allAuthorsExceptWhoseUrlNullContainer.Add(author, author);

            var authorsParseResult = new PluralsightCatalogParser.AuthorsParseResult
            {
                FullnamesakesAuthorsContainer = fullnamesakesAuthorsContainer,
                AllAuthorsByFullNameExceptFullnamesakesContainer = allAuthorsExceptFullnamesakesContainer,
                AllAuthorsExceptWhoseUrlNullContainer            = allAuthorsExceptWhoseUrlNullContainer
            };


            var nodeSelector = Mock.Of <INodeSelector>();

            var nodeParser = Mock.Of <INodeParser>(x =>
                                                   x.IsCoAuthorNode(coAuthorNode) == true &&
                                                   x.ParseCoAuthors(coAuthorNode) == coAuthors &&

                                                   x.IsCoAuthorNode(authorNode) == false &&
                                                   x.ParseAuthor(authorNode) == author);

            var sut = new PluralsightCatalogParser(nodeSelector, nodeParser);

            // Act
            var result = sut.GetCourseAuthors(new[] { authorNode, coAuthorNode }, course, authorsParseResult);

            // Assert
            Assert.NotNull(result);
            Assert.Equal(4, result.Count);

            foreach (var courseAuthor in result)
            {
                Assert.Same(course, courseAuthor.Course);
            }

            Assert.Equal(coAuthors.OrderBy(x => x.FullName),
                         result.Where(x => x.IsAuthorCoAuthor).Select(x => x.Author).OrderBy(x => x.FullName),
                         ReferenceEqualityComparer.Instance);

            Assert.Same(author, result.Single(x => x.IsAuthorCoAuthor == false).Author);

            Assert.Same(coAuthors[1], result.Single(x => x.HasFullnamesake).Author);
        }
      public void Should_ReturnCourseAuthors()
      {
         // Arrange
         var coAuthors = new[] { "Eric Burke", "Steve Evans", "Rob Windsor" }
            .Select(x => new PluralsightAuthor { FullName = x }).ToList();

         var author = new PluralsightAuthor { FullName = "John Smith", UrlName = "john-smith"};

         var coAuthorNode = Mock.Of<INode>();
         var authorNode = Mock.Of<INode>();

         var course = new PluralsightCourse();

         var fullnamesakesAuthorsContainer = new Dictionary<IAuthorFullNameNaturalKey, PluralsightAuthor>(
            FullNameNaturalKeyEqualityComparer<IAuthorFullNameNaturalKey>.Instance);

         fullnamesakesAuthorsContainer.Add(coAuthors[1], coAuthors[1]);


         var allAuthorsExceptFullnamesakesContainer = new Dictionary<IAuthorFullNameNaturalKey, PluralsightAuthor>(
            FullNameNaturalKeyEqualityComparer<IAuthorFullNameNaturalKey>.Instance);

         allAuthorsExceptFullnamesakesContainer.Add(coAuthors[0], coAuthors[0]);
         allAuthorsExceptFullnamesakesContainer.Add(coAuthors[2], coAuthors[2]);
         allAuthorsExceptFullnamesakesContainer.Add(author, author);

         var allAuthorsExceptWhoseUrlNullContainer = new Dictionary<IAuthorUrlNameNaturalKey, PluralsightAuthor>(
            UrlNameNaturalKeyEqualityComparer<IAuthorUrlNameNaturalKey>.Instance);
         allAuthorsExceptWhoseUrlNullContainer.Add(author, author);

         var authorsParseResult = new PluralsightCatalogParser.AuthorsParseResult
         {
            FullnamesakesAuthorsContainer = fullnamesakesAuthorsContainer,
            AllAuthorsByFullNameExceptFullnamesakesContainer = allAuthorsExceptFullnamesakesContainer,
            AllAuthorsExceptWhoseUrlNullContainer = allAuthorsExceptWhoseUrlNullContainer
         };


         var nodeSelector = Mock.Of<INodeSelector>();

         var nodeParser = Mock.Of<INodeParser>(x =>
            x.IsCoAuthorNode(coAuthorNode) == true &&
            x.ParseCoAuthors(coAuthorNode) == coAuthors &&

            x.IsCoAuthorNode(authorNode) == false &&
            x.ParseAuthor(authorNode) == author);

         var sut = new PluralsightCatalogParser(nodeSelector, nodeParser);

         // Act
         var result = sut.GetCourseAuthors(new[] { authorNode, coAuthorNode }, course, authorsParseResult);

         // Assert
         Assert.NotNull(result);
         Assert.Equal(4, result.Count);

         foreach (var courseAuthor in result)
         {
            Assert.Same(course, courseAuthor.Course);
         }
         
         Assert.Equal(coAuthors.OrderBy(x => x.FullName),
            result.Where(x => x.IsAuthorCoAuthor).Select(x => x.Author).OrderBy(x => x.FullName),
            ReferenceEqualityComparer.Instance);

         Assert.Same(author, result.Single(x => x.IsAuthorCoAuthor == false).Author);

         Assert.Same(coAuthors[1], result.Single(x => x.HasFullnamesake).Author);
      }
      public void Should_ReturnCourseCoAuthorWithoutFullnamesakeMark_WhenAuthorNotInFullnamesakeContainer()
      {
         // Arrange
         var author = new PluralsightAuthor
         {
            FullName = "John Smith"
         };

         var course = new PluralsightCourse();

         var fullnamesakesAuthorsContainer =
            new Dictionary<IAuthorFullNameNaturalKey, PluralsightAuthor>(
               FullNameNaturalKeyEqualityComparer<IAuthorFullNameNaturalKey>.Instance);

         var allAuthorsExceptFullnamesakesContainer =
            new Dictionary<IAuthorFullNameNaturalKey, PluralsightAuthor>(FullNameNaturalKeyEqualityComparer<IAuthorFullNameNaturalKey>.Instance)
            {
               {author, author}
            };


         var nodeSelector = Mock.Of<INodeSelector>();
         var nodeParser = Mock.Of<INodeParser>();

         var sut = new PluralsightCatalogParser(nodeSelector, nodeParser);

         // Act
         var result = sut.GetCourseCoAuthor(course, author, allAuthorsExceptFullnamesakesContainer, fullnamesakesAuthorsContainer);

         // Assert
         Assert.NotNull(result);
         Assert.Same(course, result.Course);
         Assert.Same(author, result.Author);

         Assert.Equal(false, result.HasFullnamesake);
      }