<commit_before>using System;
using System.Collections.Generic;
using System.Xml;

using MbUnit.Framework;
using Subtext.Framework;
using Subtext.Framework.Exceptions;
using Subtext.Plugins.Core.TextLinkAds;

namespace UnitTests.Subtext.Plugins.Core
{
    [TestFixture]
    public class FeedvertisingTests
    {
		[Test]
		public void ParseGoodAdXml()
		{
			IList<Advertisement> ads;
			IFeedvertisingService service = new FeedvertisingService();

			string adXml = "<Links><Link><URL>URL</URL><Text>Text</Text><BeforeText>BeforeText</BeforeText><AfterText>AfterText</AfterText><RssText>RssText</RssText><RssBeforeText>RssBeforeText</RssBeforeText><RssAfterText>RssAfterText</RssAfterText><RssPrefix>RssPrefix</RssPrefix><RssMaxAds>RssMaxAds</RssMaxAds></Link></Links>";
			ads = service.ParseAdvertisementXml(adXml);
			Assert.AreEqual(1, ads.Count);

		    Advertisement ad = ads[0];
			Assert.AreEqual("URL", ad.Url);
			Assert.AreEqual("Text", ad.Text);
			Assert.AreEqual("BeforeText", ad.BeforeText);
			Assert.AreEqual("AfterText", ad.AfterText);
			Assert.AreEqual("RssText", ad.RssText);
			Assert.AreEqual("RssBeforeText", ad.RssBeforeText);
			Assert.AreEqual("RssAfterText", ad.RssAfterText);
			Assert.AreEqual("RssPrefix", ad.RssPrefix);
		}

		[Test]
		public void AdsWithNoRssPrefixAreNotReturned()
		{
			IList<Advertisement> ads;
			IFeedvertisingService service = new FeedvertisingService();

			string adXml = "<Links><Link><URL>URL</URL><Text>Text</Text><BeforeText>BeforeText</BeforeText><AfterText>AfterText</AfterText><RssText>RssText</RssText><RssBeforeText>RssBeforeText</RssBeforeText><RssAfterText>RssAfterText</RssAfterText><RssPrefix></RssPrefix><RssMaxAds>RssMaxAds</RssMaxAds></Link></Links>";
			ads = service.ParseAdvertisementXml(adXml);
			Assert.AreEqual(0, ads.Count);
		}

		[Test]
		public void AdsWithNoRssTextAreNotReturned()
		{
			IList<Advertisement> ads;
			IFeedvertisingService service = new FeedvertisingService();

			string adXml = "<Links><Link><URL>URL</URL><Text>Text</Text><BeforeText>BeforeText</BeforeText><AfterText>AfterText</AfterText><RssText></RssText><RssBeforeText>RssBeforeText</RssBeforeText><RssAfterText>RssAfterText</RssAfterText><RssPrefix>RssPrefix</RssPrefix><RssMaxAds>RssMaxAds</RssMaxAds></Link></Links>";
		    ads = service.ParseAdvertisementXml(adXml);
			Assert.AreEqual(0, ads.Count);
		}

		[Test]
		public void ParseMultipleAdXml()
		{
			IList<Advertisement> ads;
			IFeedvertisingService service = new FeedvertisingService();

			string adXml = "<Links><Link><URL>URL</URL><Text>Text</Text><BeforeText>BeforeText</BeforeText><AfterText>AfterText</AfterText><RssText>RssText</RssText><RssBeforeText>RssBeforeText</RssBeforeText><RssAfterText>RssAfterText</RssAfterText><RssPrefix>RssPrefix</RssPrefix><RssMaxAds>RssMaxAds</RssMaxAds></Link><Link><URL>URL</URL><Text>Text</Text><BeforeText>BeforeText</BeforeText><AfterText>AfterText</AfterText><RssText>RssText</RssText><RssBeforeText>RssBeforeText</RssBeforeText><RssAfterText>RssAfterText</RssAfterText><RssPrefix>RssPrefix</RssPrefix><RssMaxAds>RssMaxAds</RssMaxAds></Link></Links>";
			ads = service.ParseAdvertisementXml(adXml);
			Assert.AreEqual(2, ads.Count);
		}

		[Test]
		public void BadAdXmlReturnsEmptyList()
		{
			IList<Advertisement> ads;
			IFeedvertisingService service = new FeedvertisingService();

			string adXml = "<Links<Link><URL>URL</URL><Text>Text</Text><BeforeText>BeforeText</BeforeText><AfterText>AfterText</AfterText><RssText>RssText</RssText><RssBeforeText>RssBeforeText</RssBeforeText><RssAfterText>RssAfterText</RssAfterText><RssPrefix>RssPrefix</RssPrefix><RssMaxAds>RssMaxAds</RssMaxAds></Link><Link><URL>URL</URL><Text>Text</Text><BeforeText>BeforeText</BeforeText><AfterText>AfterText</AfterText><RssText>RssText</RssText><RssBeforeText>RssBeforeText</RssBeforeText><RssAfterText>RssAfterText</RssAfterText><RssPrefix>RssPrefix</RssPrefix><RssMaxAds>RssMaxAds</RssMaxAds></Link></Links>";
			ads = service.ParseAdvertisementXml(adXml);
			Assert.AreEqual(0, ads.Count);
		}

		public Advertisement GetValidAdvertisement()
		{
			Advertisement ad = new Advertisement();
			ad.Url = "Url";
			ad.RssPrefix = "Prefix";
			ad.RssText = "Text";
			ad.RssBeforeText = "Before";
			ad.RssAfterText = "After";

			return ad;
		}

		[Test]
		public void AdHtmlRendersProperly()
		{
			Advertisement ad = GetValidAdvertisement();
			IFeedvertisingService service = new FeedvertisingService();
			Assert.AreEqual("<strong><em>Prefix</em></strong>: Before <a href=\"Url\">Text</a><em> </em>After<br />", service.GetAdvertisementHtml(ad));
		}

		[Test]
		public void AdHtmlEmptyIfNoRssPrefix()
		{<commit_msg>Fixed a Feedvertising plugin test<commit_after>using System;
using System.Collections.Generic;
using System.Xml;

using MbUnit.Framework;
using Subtext.Framework;
using Subtext.Framework.Exceptions;
using Subtext.Plugins.Core.TextLinkAds;

namespace UnitTests.Subtext.Plugins.Core
{
    [TestFixture]
    public class FeedvertisingTests
    {
		[Test]
		public void ParseGoodAdXml()
		{
			IList<Advertisement> ads;
			IFeedvertisingService service = new FeedvertisingService();

			string adXml = "<Links><Link><URL>URL</URL><Text>Text</Text><BeforeText>BeforeText</BeforeText><AfterText>AfterText</AfterText><RssText>RssText</RssText><RssBeforeText>RssBeforeText</RssBeforeText><RssAfterText>RssAfterText</RssAfterText><RssPrefix>RssPrefix</RssPrefix><RssMaxAds>RssMaxAds</RssMaxAds></Link></Links>";
			ads = service.ParseAdvertisementXml(adXml);
			Assert.AreEqual(1, ads.Count);

		    Advertisement ad = ads[0];
			Assert.AreEqual("URL", ad.Url);
			Assert.AreEqual("Text", ad.Text);
			Assert.AreEqual("BeforeText", ad.BeforeText);
			Assert.AreEqual("AfterText", ad.AfterText);
			Assert.AreEqual("RssText", ad.RssText);
			Assert.AreEqual("RssBeforeText", ad.RssBeforeText);
			Assert.AreEqual("RssAfterText", ad.RssAfterText);
			Assert.AreEqual("RssPrefix", ad.RssPrefix);
		}

		[Test]
		public void AdsWithNoRssPrefixAreNotReturned()
		{
			IList<Advertisement> ads;
			IFeedvertisingService service = new FeedvertisingService();

			string adXml = "<Links><Link><URL>URL</URL><Text>Text</Text><BeforeText>BeforeText</BeforeText><AfterText>AfterText</AfterText><RssText>RssText</RssText><RssBeforeText>RssBeforeText</RssBeforeText><RssAfterText>RssAfterText</RssAfterText><RssPrefix></RssPrefix><RssMaxAds>RssMaxAds</RssMaxAds></Link></Links>";
			ads = service.ParseAdvertisementXml(adXml);
			Assert.AreEqual(0, ads.Count);
		}

		[Test]
		public void AdsWithNoRssTextAreNotReturned()
		{
			IList<Advertisement> ads;
			IFeedvertisingService service = new FeedvertisingService();

			string adXml = "<Links><Link><URL>URL</URL><Text>Text</Text><BeforeText>BeforeText</BeforeText><AfterText>AfterText</AfterText><RssText></RssText><RssBeforeText>RssBeforeText</RssBeforeText><RssAfterText>RssAfterText</RssAfterText><RssPrefix>RssPrefix</RssPrefix><RssMaxAds>RssMaxAds</RssMaxAds></Link></Links>";
		    ads = service.ParseAdvertisementXml(adXml);
			Assert.AreEqual(0, ads.Count);
		}

		[Test]
		public void ParseMultipleAdXml()
		{
			IList<Advertisement> ads;
			IFeedvertisingService service = new FeedvertisingService();

			string adXml = "<Links><Link><URL>URL</URL><Text>Text</Text><BeforeText>BeforeText</BeforeText><AfterText>AfterText</AfterText><RssText>RssText</RssText><RssBeforeText>RssBeforeText</RssBeforeText><RssAfterText>RssAfterText</RssAfterText><RssPrefix>RssPrefix</RssPrefix><RssMaxAds>RssMaxAds</RssMaxAds></Link><Link><URL>URL</URL><Text>Text</Text><BeforeText>BeforeText</BeforeText><AfterText>AfterText</AfterText><RssText>RssText</RssText><RssBeforeText>RssBeforeText</RssBeforeText><RssAfterText>RssAfterText</RssAfterText><RssPrefix>RssPrefix</RssPrefix><RssMaxAds>RssMaxAds</RssMaxAds></Link></Links>";
			ads = service.ParseAdvertisementXml(adXml);
			Assert.AreEqual(2, ads.Count);
		}

		[Test]
		public void BadAdXmlReturnsEmptyList()
		{
			IList<Advertisement> ads;
			IFeedvertisingService service = new FeedvertisingService();

			string adXml = "<Links<Link><URL>URL</URL><Text>Text</Text><BeforeText>BeforeText</BeforeText><AfterText>AfterText</AfterText><RssText>RssText</RssText><RssBeforeText>RssBeforeText</RssBeforeText><RssAfterText>RssAfterText</RssAfterText><RssPrefix>RssPrefix</RssPrefix><RssMaxAds>RssMaxAds</RssMaxAds></Link><Link><URL>URL</URL><Text>Text</Text><BeforeText>BeforeText</BeforeText><AfterText>AfterText</AfterText><RssText>RssText</RssText><RssBeforeText>RssBeforeText</RssBeforeText><RssAfterText>RssAfterText</RssAfterText><RssPrefix>RssPrefix</RssPrefix><RssMaxAds>RssMaxAds</RssMaxAds></Link></Links>";
			ads = service.ParseAdvertisementXml(adXml);
			Assert.AreEqual(0, ads.Count);
		}

		public Advertisement GetValidAdvertisement()
		{
			Advertisement ad = new Advertisement();
			ad.Url = "Url";
			ad.RssPrefix = "Prefix";
			ad.RssText = "Text";
			ad.RssBeforeText = "Before";
			ad.RssAfterText = "After";

			return ad;
		}

		[Test]
		public void AdHtmlRendersProperly()
		{
			Advertisement ad = GetValidAdvertisement();
			IFeedvertisingService service = new FeedvertisingService();
			Assert.AreEqual("<p><strong><em>Prefix</em></strong>: Before <a href=\"Url\">Text</a><em> </em>After<br /></p>", service.GetAdvertisementHtml(ad));
		}

		[Test]
		public void AdHtmlEmptyIfNoRssPrefix()
		{
{'fraction_non_alphanumeric': 0.15024025627335824, 'fraction_numerical': 0.0012813667912439936, 'mean_word_length': 7.2592592592592595, 'pattern_counts': {'":': 0, '<': 333, '<?xml version=': 0, '>': 331, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3228598', 'n_tokens_mistral': 3568, 'n_tokens_neox': 3160, 'n_words': 333}