Пример #1
0
        public void NullOrEmptyStringProducesEmptyArray(string sourceValue)
        {
            var translator  = new HtmlAgilityPackDataTranslator();
            var outputValue = translator.Translate(sourceValue);

            Assert.Empty(outputValue);
        }
        public void CanTranslateParagraphWithAdjacentLists()
        {
            var translator  = new HtmlAgilityPackDataTranslator();
            var sourceValue = @"
<p>You'll need to have some practical experience and be able to show you have a real enthusiasm for sports commentating. </p>
<p>To get some work experience you could:</p>
<ul>
<li>volunteer to commentate on charity events like fun runs</li>
<li>commentate for amateur matches at schools, college or for local teams </li>
<li> record commentary for websites or internet radio stations </li>
<li>volunteer for community, hospital or student radio, or TV</li>
</ul>
<p>You can get a list of radio stations from:</p>
<ul>
<li><a href=""http://www.commedia.org.uk/"">Community Media Association</a></li>
<li><a href=""http://www.hbauk.com/"">Hospital Broadcasting Association</a></li>
<li><a href=""http://www.radiocentre.org/"">RadioCentre</a></li>
</ul>
<p>Large broadcasters like&nbsp;<a href=""https://www.bbc.co.uk/careers/work-experience/"">BBC Careers</a>, <a href=""http://www.itvjobs.com/workinghere/entry-careers/"">ITV</a> &nbsp; and <a href=""https://careers.channel4.com/4talent"">Channel 4</a> offer work experience placements, insight and talent days.</p>
<p>
The <a href = ""https://www.sportsjournalists.co.uk/training/work-experience/"" > Sports Journalists &rsquo; Association </a> has more ideas about where to look 
for work experience.</p>
<p>With experience<br/><br/>You could move into other roles. Find more <a href='http://ncs.com'>information</a> here</p>";
            var outputValue = translator.Translate(sourceValue);

            Assert.Equal(7, outputValue.Count);
            Assert.Equal("You'll need to have some practical experience and be able to show you have a real enthusiasm for sports commentating.", outputValue.ElementAt(0));
            Assert.Equal("To get some work experience you could:volunteer to commentate on charity events like fun runs; commentate for amateur matches at schools, college or for local teams; record commentary for websites or internet radio stations; volunteer for community, hospital or student radio, or TV", outputValue.ElementAt(1));
            Assert.Equal("You can get a list of radio stations from:[Community Media Association | http://www.commedia.org.uk/]; [Hospital Broadcasting Association | http://www.hbauk.com/]; [RadioCentre | http://www.radiocentre.org/]", outputValue.ElementAt(2));
            Assert.Equal("Large broadcasters like [BBC Careers | https://www.bbc.co.uk/careers/work-experience/], [ITV | http://www.itvjobs.com/workinghere/entry-careers/]   and [Channel 4 | https://careers.channel4.com/4talent] offer work experience placements, insight and talent days.", outputValue.ElementAt(3));
            Assert.Equal("The [Sports Journalists ’ Association | https://www.sportsjournalists.co.uk/training/work-experience/] has more ideas about where to look \r\nfor work experience.", outputValue.ElementAt(4));
            Assert.Equal("With experience", outputValue.ElementAt(5));
            Assert.Equal("You could move into other roles. Find more [information | http://ncs.com] here", outputValue.ElementAt(6));
        }
        public void CanInject()
        {
            //Arrange
            var htmlDataTranslator        = new HtmlAgilityPackDataTranslator();
            var htmltoStringTypeConverter = new HtmlToStringTypeConverter(htmlDataTranslator);

            var config = new MapperConfiguration(options =>
            {
                options.CreateMap <string, List <string> >().ConvertUsing(htmltoStringTypeConverter);
                options.CreateMap <DataModel, ViewModel>();
            });

            var mapper    = config.CreateMapper();
            var markup    = @"<p>p1<a href=""http://www.google.com"">Google</a></p>";
            var dataModel = new DataModel()
            {
                Id = Guid.NewGuid(), Markup = markup
            };

            //Act
            var viewModel = mapper.Map <ViewModel>(dataModel);

            //Asset
            Assert.Single(viewModel.Markup);
            Assert.Equal("p1[Google | http://www.google.com]", viewModel.Markup.First());
        }
Пример #4
0
        public void BlankStringReturnsEmptyList()
        {
            var translator  = new HtmlAgilityPackDataTranslator();
            var sourceValue = string.Empty;
            var outputValue = translator.Translate(sourceValue);

            Assert.Empty(outputValue);
        }
Пример #5
0
        public void ContentWithSpacesIsTrimmed(string sourceValue, string expectedValue)
        {
            var translator  = new HtmlAgilityPackDataTranslator();
            var outputValue = translator.Translate(sourceValue);

            Assert.Single(outputValue);
            Assert.Equal(expectedValue, outputValue.First());
        }
        public void CanTranslateLinkThatWithHrefAndText()
        {
            var translator  = new HtmlAgilityPackDataTranslator();
            var sourceValue = @"<a href='https://www.dta-uk.org/join_us.php'>The Dental Technologists Association</a>";
            var outputValue = translator.Translate(sourceValue);

            Assert.Single(outputValue);
            Assert.Equal("[The Dental Technologists Association | https://www.dta-uk.org/join_us.php]", outputValue.First());
        }
        public void CanTranslateLinksWithNoHrefAttribute()
        {
            var translator  = new HtmlAgilityPackDataTranslator();
            var sourceValue = @"<a>The Dental Technologists Association</a>";
            var outputValue = translator.Translate(sourceValue);

            Assert.Single(outputValue);
            Assert.Equal("[The Dental Technologists Association | ]", outputValue.First());
        }
Пример #8
0
        public void CanTranslateUnorderedList()
        {
            var translator  = new HtmlAgilityPackDataTranslator();
            var sourceValue = @"<ul><li>item1</li><li>item2</li><li>item3</li></ul>";
            var outputValue = translator.Translate(sourceValue);

            Assert.Single(outputValue);
            Assert.Equal("item1; item2; item3", outputValue.First());
        }
Пример #9
0
        public void CanTranslateParagraphs()
        {
            var translator  = new HtmlAgilityPackDataTranslator();
            var sourceValue = @"<p>Your duties include</p>";
            var outputValue = translator.Translate(sourceValue);

            Assert.Single(outputValue);
            Assert.Equal("Your duties include", outputValue.First());
        }
Пример #10
0
        public void CanTranslateTextWithLinks()
        {
            var translator  = new HtmlAgilityPackDataTranslator();
            var sourceValue = @"content not in html tags <a href='http://www.google.com'>link1</a> more content";
            var outputValue = translator.Translate(sourceValue);

            Assert.Single(outputValue);
            Assert.Equal("content not in html tags [link1 | http://www.google.com] more content", outputValue.ElementAt(0));
        }
Пример #11
0
        public void NonHtmlContentIsReturnedAsIs()
        {
            var translator  = new HtmlAgilityPackDataTranslator();
            var sourceValue = "some text";
            var outputValue = translator.Translate(sourceValue);

            Assert.Single(outputValue);
            Assert.Equal(sourceValue, outputValue.First());
        }
Пример #12
0
        public ApiModelProfile()
        {
            var htmlTranslator             = new HtmlAgilityPackDataTranslator();
            var htmlToStringValueConverter = new HtmlToStringValueConverter(htmlTranslator);

            CreateMap <CareerPathSegmentDataModel, CareerPathAndProgressionApiModel>()
            .ForMember(d => d.CareerPathAndProgression, opt => opt.ConvertUsing(htmlToStringValueConverter, s => s.Markup))
            ;
        }
        public void ExtraLineBreaksAreIgnored(string sourceValue)
        {
            var translator  = new HtmlAgilityPackDataTranslator();
            var outputValue = translator.Translate(sourceValue);

            Assert.Equal(2, outputValue.Count);
            Assert.Equal("content1", outputValue.First());
            Assert.Equal("p1", outputValue.Last());
        }
        public void CanTranslateParagraphWithLink()
        {
            var translator  = new HtmlAgilityPackDataTranslator();
            var sourceValue = @"<p>Large broadcasters like&nbsp;<a href=""https://www.bbc.co.uk/careers/work-experience/"">BBC Careers</a>, <a href=""http://www.itvjobs.com/workinghere/entry-careers/"">ITV</a>&nbsp;and <a href=""https://careers.channel4.com/4talent"">Channel 4</a> offer work experience placements, insight and talent days.</p>";
            var outputValue = translator.Translate(sourceValue);

            Assert.Single(outputValue);
            Assert.Equal("Large broadcasters like�[BBC Careers | https://www.bbc.co.uk/careers/work-experience/], [ITV | http://www.itvjobs.com/workinghere/entry-careers/]�and [Channel 4 | https://careers.channel4.com/4talent] offer work experience placements, insight and talent days.", outputValue.First());
        }
Пример #15
0
        public void CanTranslateTextFollowedByPTag()
        {
            var translator  = new HtmlAgilityPackDataTranslator();
            var sourceValue = @"this is some content<p>p1</p>";
            var outputValue = translator.Translate(sourceValue);

            Assert.Equal(2, outputValue.Count);
            Assert.Equal("this is some content", outputValue.First());
            Assert.Equal("p1", outputValue.Last());
        }
Пример #16
0
        public void CanTranslateMultipleParagraphs()
        {
            var translator  = new HtmlAgilityPackDataTranslator();
            var sourceValue = @"<p>p1</p><p>p2</p>";
            var outputValue = translator.Translate(sourceValue);

            Assert.Equal(2, outputValue.Count);
            Assert.Equal("p1", outputValue.First());
            Assert.Equal("p2", outputValue.Last());
        }
Пример #17
0
        public void CanTranslateTextInMiddleWithPTag()
        {
            var translator  = new HtmlAgilityPackDataTranslator();
            var sourceValue = @"<p>p1</p>this is some content<p>p2</p>";
            var outputValue = translator.Translate(sourceValue);

            Assert.Equal(3, outputValue.Count);
            Assert.Equal("p1", outputValue.ElementAt(0));
            Assert.Equal("this is some content", outputValue.ElementAt(1));
            Assert.Equal("p2", outputValue.ElementAt(2));
        }
Пример #18
0
        public void CanTranslateTextInMiddleWithPTagAndLink()
        {
            var translator  = new HtmlAgilityPackDataTranslator();
            var sourceValue = @"<p>p1</p>this is some <a href='http://www.yahoo.com'>link1</a>content<p>p2</p>";
            var outputValue = translator.Translate(sourceValue);

            Assert.Equal(3, outputValue.Count);
            Assert.Equal("p1", outputValue.ElementAt(0));
            Assert.Equal("this is some [link1 | http://www.yahoo.com]content", outputValue.ElementAt(1));
            Assert.Equal("p2", outputValue.ElementAt(2));
        }
        public void CanTranslate()
        {
            var translator  = new HtmlAgilityPackDataTranslator();
            var sourceValue = @"
<ul>
<li><a href=""http://www.commedia.org.uk/"">Community Media Association </a></li>
<li><a href=""http://www.hbauk.com/"">Hospital Broadcasting Association</a></li>
<li><a href=""http://www.radiocentre.org/"">RadioCentre</a></li>
</ul>";

            var outputValue = translator.Translate(sourceValue);

            Assert.Single(outputValue);
            Assert.Equal("[Community Media Association | http://www.commedia.org.uk/]; [Hospital Broadcasting Association | http://www.hbauk.com/]; [RadioCentre | http://www.radiocentre.org/]", outputValue.First());
        }
Пример #20
0
        public ApiModelProfile()
        {
            var htmlDataTranslator         = new HtmlAgilityPackDataTranslator();
            var htmlToStringValueConverter = new HtmlToStringValueConverter(htmlDataTranslator);

            CreateMap <JobProfileTasksDataSegmentModel, WhatYouWillDoApiModel>()
            .ForMember(d => d.WYDDayToDayTasks, opt => opt.ConvertUsing(htmlToStringValueConverter, s => s.Tasks))
            .ForMember(d => d.WorkingEnvironment, s => s.MapFrom(a => a))
            ;

            CreateMap <JobProfileTasksDataSegmentModel, WorkingEnvironmentApiModel>()
            .ForMember(d => d.Environment, opt => opt.ConvertUsing(new EnvironmentFormatter(htmlDataTranslator), s => s.Environments != null ? s.Environments.Select(x => x.Description) : null))
            .ForMember(d => d.Location, opt => opt.ConvertUsing(new LocationFormatter(htmlDataTranslator), s => s.Locations != null ? s.Locations.Select(x => x.Description) : null))
            .ForMember(d => d.Uniform, opt => opt.ConvertUsing(new UniformFormatter(htmlDataTranslator), s => s.Uniforms != null ? s.Uniforms.Select(x => x.Description) : null))
            ;
        }
Пример #21
0
        public void CanTranslateParagraphWithAdjacentLists()
        {
            var translator  = new HtmlAgilityPackDataTranslator();
            var sourceValue = @"<p>Your duties may include:</p>
<ul>
<li>preparing for an event by researching clubs or players</li>
<li>working with a production team</li>
<li>taking direction from a producer</li>
<li>interviewing sports professionals</li>
<li>commentating on events before, during and after the fixture</li>
<li>working with experts who give their opinion or statistics</li>
<li>updating your website, blog or social media feed</li>
</ul>";
            var outputValue = translator.Translate(sourceValue);

            Assert.Single(outputValue);
            Assert.Equal("Your duties may include:preparing for an event by researching clubs or players; working with a production team; taking direction from a producer; interviewing sports professionals; commentating on events before, during and after the fixture; working with experts who give their opinion or statistics; updating your website, blog or social media feed", outputValue.First());
        }