public void OneTagInTheMiddleShouldResultInThreeBlocks() { AssetPlugin plugin = new TestAssetPlugin(); plugin.AddFont(new BaseFont() { Name = "Bold", FontFilename = "Bold.otf" }); plugin.AddFont(new BaseFont() { Name = "H1", FontFilename = "H1.otf" }, new FontTag("Bold", "b")); string expectedResultWithoutTags = "this is one block"; string text = "this is <b>one</b> block"; string resultWithoutTags; var result = AttributedFontHelper.GetFontTextBlocks(text, "H1", plugin, out resultWithoutTags); result.Count.Should().Be(3); result[0].StartIndex.Should().Be(0); result[0].EndIndex.Should().Be(8); result[0].FontTag.Should().BeNull(); result[1].StartIndex.Should().Be(8); result[1].EndIndex.Should().Be(11); result[1].FontTag.Tag.Should().Be("b"); result[2].StartIndex.Should().Be(11); result[2].EndIndex.Should().Be(expectedResultWithoutTags.Length); result[2].FontTag.Should().BeNull(); resultWithoutTags.Should().Be(expectedResultWithoutTags); }
public void BeginningWithATagShouldHaveBeginTag() { AssetPlugin plugin = new TestAssetPlugin(); plugin.AddFont(new BaseFont() { Name = "Bold", FontFilename = "Bold.otf" }); plugin.AddFont(new BaseFont() { Name = "H1", FontFilename = "H1.otf" }, new FontTag("Bold", "b")); string expectedResultWithoutTags = "one block"; string text = "<b>one</b> block"; string resultWithoutTags; var result = AttributedFontHelper.GetFontTextBlocks(text, "H1", plugin, out resultWithoutTags); result.Count.Should().Be(2); result[0].StartIndex.Should().Be(0); result[0].EndIndex.Should().Be(3); result[0].FontTag.Tag.Should().Be("b"); result[1].StartIndex.Should().Be(3); result[1].EndIndex.Should().Be(9); result[1].FontTag.Should().BeNull(); resultWithoutTags.Should().Be(expectedResultWithoutTags); }
public void LinksSlashAtEndAreResolvedLikeAnyLink() { AssetPlugin plugin = new TestAssetPlugin(); plugin.AddFont(new BaseFont() { Name = "Bold", FontFilename = "Bold.otf" }); plugin.AddFont(new BaseFont() { Name = "H1", FontFilename = "H1.otf" }, new FontTag("Bold", "a", FontTagAction.Link)); string resultWithoutTags; //link with quotes string text = "this is one <a href='http://www.google.com/maps/'>font</a> to block"; var blocks = AttributedFontHelper.GetFontTextBlocks(text, "H1", plugin, out resultWithoutTags); blocks.Count.Should().Be(3); blocks[1].TagProperties.Keys.Contains("href").Should().BeTrue(); blocks[1].TagProperties.Values.Contains("http://www.google.com/maps/").Should().BeTrue(); blocks[1].FontTag.FontAction.Should().Be(FontTagAction.Link); resultWithoutTags.Should().Be("this is one font to block"); }
public void TagsCanContainMultipleAttributes() { AssetPlugin plugin = new TestAssetPlugin(); plugin.AddFont(new BaseFont() { Name = "Bold", FontFilename = "Bold.otf" }); plugin.AddFont(new BaseFont() { Name = "H1", FontFilename = "H1.otf" }, new FontTag("Bold", "q")); string resultWithoutTags; string text = "this is one <q la=1 la2=2>font</q> to block"; var blocks = AttributedFontHelper.GetFontTextBlocks(text, "H1", plugin, out resultWithoutTags); blocks.Count.Should().Be(3); blocks[1].TagProperties.Keys.Contains("la").Should().BeTrue(); blocks[1].TagProperties.Keys.Contains("la2").Should().BeTrue(); resultWithoutTags.Should().Be("this is one font to block"); }
public void LinksWithoutHrefShouldBeFlattenedAndPropertiesStripped() { AssetPlugin plugin = new TestAssetPlugin(); plugin.AddFont(new BaseFont() { Name = "Bold", FontFilename = "Bold.otf" }); plugin.AddFont(new BaseFont() { Name = "H1", FontFilename = "H1.otf" }, new FontTag("Bold", "a", FontTagAction.Link)); string resultWithoutTags; //link without attributes var text = "this is one <a>http://www.google.com</a> to block"; var blocks = AttributedFontHelper.GetFontTextBlocks(text, "H1", plugin, out resultWithoutTags); blocks.Count.Should().Be(3); blocks[1].TagProperties.Should().BeNull(); blocks[1].FontTag.FontAction.Should().Be(FontTagAction.Link); resultWithoutTags.Should().Be("this is one http://www.google.com to block"); }
public void LinkWithPlusAndMinosPropertiesAreParsedAsFull() { AssetPlugin plugin = new TestAssetPlugin(); plugin.AddFont(new BaseFont() { Name = "Bold", FontFilename = "Bold.otf" }); plugin.AddFont(new BaseFont() { Name = "H1", FontFilename = "H1.otf" }, new FontTag("Bold", "a", FontTagAction.Link)); string resultWithoutTags; //link with quotes string text = "this is one <a href='https://itunes.apple.com/cz/app/skoda-media-services/id420627875?mt=8&utm_source=32449-Importers&utm_medium=email&utm_term=1908124336&utm_content=iOS&utm_campaign=Modern+and+intuitive:+SKODA+Media+Services+app+featuring+a+new+design+and+additional+functions-2'>fiets</a> to block"; var blocks = AttributedFontHelper.GetFontTextBlocks(text, "H1", plugin, out resultWithoutTags); blocks.Count.Should().Be(3); blocks[1].TagProperties.Keys.Contains("href").Should().BeTrue(); blocks[1].TagProperties.Values.Contains("https://itunes.apple.com/cz/app/skoda-media-services/id420627875?mt=8&utm_source=32449-Importers&utm_medium=email&utm_term=1908124336&utm_content=iOS&utm_campaign=Modern+and+intuitive:+SKODA+Media+Services+app+featuring+a+new+design+and+additional+functions-2").Should().BeTrue(); blocks[1].FontTag.FontAction.Should().Be(FontTagAction.Link); resultWithoutTags.Should().Be("this is one fiets to block"); }
public void LinksShouldBeFlattenedAndPropertiesStripped() { AssetPlugin plugin = new TestAssetPlugin(); plugin.AddFont(new BaseFont() { Name = "Bold", FontFilename = "Bold.otf" }); plugin.AddFont(new BaseFont() { Name = "H1", FontFilename = "H1.otf" }, new FontTag("Bold", "a", FontTagAction.Link)); string resultWithoutTags; //standard link string text = "this is one <a href=http://www.google.com>font</a> to block"; var blocks = AttributedFontHelper.GetFontTextBlocks(text, "H1", plugin, out resultWithoutTags); blocks.Count.Should().Be(3); blocks[1].TagProperties.Keys.Contains("href").Should().BeTrue(); blocks[1].TagProperties.Values.Contains("http://www.google.com").Should().BeTrue(); blocks[2].TagProperties.Should().BeNull(); resultWithoutTags.Should().Be("this is one font to block"); }
public void PlatformSizeIsModifiedByFontSizeFactor() { AssetPlugin plugin = new TestAssetPlugin(); AssetPlugin.GetPlatformFontSize(10.0f).Should().Be(10.0f); AssetPlugin.FontSizeFactor = 2.0f; AssetPlugin.GetPlatformFontSize(10.0f).Should().Be(20.0f); }
public void AddingAFontWithoutFileNameShouldThrow() { AssetPlugin plugin = new TestAssetPlugin(); Assert.Throws <Exception>(() => plugin.AddFont(new BaseFont() { Name = "H1" })); }
public void AddingColorAddsColor() { AssetPlugin plugin = new TestAssetPlugin(); var color = Color.FromArgb(10, 0, 10); plugin.GetColor("Main").Should().Be(Color.Empty); plugin.AddColor(color, "Main"); plugin.GetColor("Main").Should().Be(color); }
public void AddingFontsWithoutNameThrows() { AssetPlugin plugin = new TestAssetPlugin(); plugin.AddColor(Color.FromArgb(255, 0, 0), "Red"); Assert.Throws <Exception>(() => plugin.AddFont(new Font() { FontFilename = "Bold.otf", Color = plugin.GetColor("Red") })); }
public void AfterAddingAFontWithNameAndFileNameShouldBeStored() { AssetPlugin plugin = new TestAssetPlugin(); plugin.AddFont(new BaseFont() { Name = "H1", FontFilename = "H1.otf" }); plugin.GetFontByName("H1").Should().NotBeNull(); }
public void GettingANonExistingTagReturnsNull() { AssetPlugin plugin = new TestAssetPlugin(); plugin.AddFont(new BaseFont() { Name = "H1", FontFilename = "H1.otf" }, new FontTag("Bold", "b")); plugin.GetFontByTag("H1", "c").Should().BeNull(); }
public void ClearingColorClearsAllColors() { AssetPlugin plugin = new TestAssetPlugin(); plugin.AddColor(Color.FromArgb(10, 0, 10), "Main"); plugin.GetColor("Main").Should().NotBe(Color.Empty); plugin.ClearColors(); plugin.GetColor("Main").Should().Be(Color.Empty); }
public void GettingFontWithoutFaultyColorsFallBackToDefaultColor() { AssetPlugin plugin = new TestAssetPlugin(); plugin.AddColor(Color.FromArgb(255, 0, 0), "Red"); plugin.AddColor(Color.FromArgb(0, 0, 255), "Blue"); plugin.AddFont(new Font() { Name = "Bold", FontFilename = "Bold.otf", Color = plugin.GetColor("Red") }); plugin.GetFontByName("Bold:").Color.R.Should().Be(255); }
public CustomTestFixture() { UnitTestCommandHelper = new MvxUnitTestCommandHelper(); Ioc.RegisterSingleton <IMvxCommandHelper>(UnitTestCommandHelper); var plugin = new TestAssetPlugin(); plugin.AddColor(Color.FromArgb(255, 0, 0), "Red"); plugin.AddColor(Color.FromArgb(0, 0, 255), "Blue"); FontToAdd = new Font() { Name = "Bold", FontFilename = "Bold.otf", Color = plugin.GetColor("Blue") }; plugin.AddFont(FontToAdd); Ioc.RegisterSingleton <IAssetPlugin>(plugin); }
public void AddingPlatformSpecificFontsAreNotAddedByOtherPlatforms() { AssetPlugin plugin = new TestAssetPlugin(); plugin.AddColor(Color.FromArgb(255, 0, 0), "Red"); var font = new iOSFont() { Name = "Bold", FontFilename = "Bold.otf", Color = plugin.GetColor("Red") }; plugin.CanAddFont(font).Should().Be(false); plugin.AddFont(font); plugin.GetFontByName("Bold").Should().BeNull(); }
public void UnknownTagsShouldBeIgnored() { AssetPlugin plugin = new TestAssetPlugin(); plugin.AddFont(new BaseFont() { Name = "Bold", FontFilename = "Bold.otf" }); plugin.AddFont(new BaseFont() { Name = "H1", FontFilename = "H1.otf" }, new FontTag("Bold", "strong")); string resultWithoutTags; string text = "las <p> this is <strong>one all</strong> block </p>"; var blocks = AttributedFontHelper.GetFontTextBlocks(text, "H1", plugin, out resultWithoutTags); blocks.Count.Should().Be(3); resultWithoutTags.Should().Be("las <p> this is one all block </p>"); text = "las <strong>this is <p>one all</p> block</strong>"; blocks = AttributedFontHelper.GetFontTextBlocks(text, "H1", plugin, out resultWithoutTags); blocks.Count.Should().Be(2); resultWithoutTags.Should().Be("las this is <p>one all</p> block"); text = "las <p>lala</p><p>lala</p> test <strong>this is <p>one all</p> block</strong>"; blocks = AttributedFontHelper.GetFontTextBlocks(text, "H1", plugin, out resultWithoutTags); blocks.Count.Should().Be(2); resultWithoutTags.Should().Be("las <p>lala</p><p>lala</p> test this is <p>one all</p> block"); text = " this is <strong>one <a href='http://www.google.com'>font</a> to rule <a>them</a> all</strong> block "; blocks = AttributedFontHelper.GetFontTextBlocks(text, "H1", plugin, out resultWithoutTags); blocks.Count.Should().Be(3); resultWithoutTags.Should().Be(" this is one <a href='http://www.google.com'>font</a> to rule <a>them</a> all block "); text = "<p> this is <strong>one <a href='http://www.google.com'>font</a> to rule <a>them</a> all</strong> block </p>"; blocks = AttributedFontHelper.GetFontTextBlocks(text, "H1", plugin, out resultWithoutTags); blocks.Count.Should().Be(3); resultWithoutTags.Should().Be("<p> this is one <a href='http://www.google.com'>font</a> to rule <a>them</a> all block </p>"); }
public void TagWithoutClosingTagShould() { AssetPlugin plugin = new TestAssetPlugin(); plugin.AddFont(new BaseFont() { Name = "Bold", FontFilename = "Bold.otf" }); plugin.AddFont(new BaseFont() { Name = "H1", FontFilename = "H1.otf" }, new FontTag("Bold", "b")); string text = "this is <b>one<b> block"; string resultWithoutTags; Assert.Throws(typeof(Exception), () => AttributedFontHelper.GetFontTextBlocks(text, "H1", plugin, out resultWithoutTags)); }
public void AfterAddingAFontWithTagFontShouldReturnAsTaggedWithTheRightTag() { AssetPlugin plugin = new TestAssetPlugin(); plugin.AddFont(new BaseFont() { Name = "Bold", FontFilename = "Bold.otf" }); plugin.AddFont(new BaseFont() { Name = "H1", FontFilename = "H1.otf" }, new FontTag("Bold", "b")); plugin.GetFontByName("H1").Should().NotBeNull(); plugin.GetFontByName("Bold").Should().NotBeNull(); plugin.GetFontByTag("H1", "b").Should().NotBeNull(); plugin.GetFontByTag("H1", "b").Name.Should().Be("Bold"); }
public void AddingColorToTheFontLookupOverridesTheColor() { AssetPlugin plugin = new TestAssetPlugin(); plugin.AddColor(Color.FromArgb(255, 0, 0), "Red"); plugin.AddColor(Color.FromArgb(0, 0, 255), "Blue"); plugin.AddFont(new Font() { Name = "Bold", FontFilename = "Bold.otf", Color = plugin.GetColor("Blue") }); plugin.GetFontByName("Bold").Color.R.Should().Be(0); plugin.GetFontByName("Bold").Color.G.Should().Be(0); plugin.GetFontByName("Bold").Color.B.Should().Be(255); plugin.GetFontByName("Bold:Red").Color.R.Should().Be(255); plugin.GetFontByName("Bold:Red").Color.G.Should().Be(0); plugin.GetFontByName("Bold:Red").Color.G.Should().Be(0); }
public void DoubleTagsShouldBeFormatted() { AssetPlugin plugin = new TestAssetPlugin(); plugin.AddFont(new BaseFont() { Name = "Bold", FontFilename = "Bold.otf" }); plugin.AddFont(new BaseFont() { Name = "H1", FontFilename = "H1.otf" }, new FontTag("Bold", "strong")); string expectedResultWithoutTags = "TestExclusieve scherpe prijsTest tot"; string resultWithoutTags; string text = "Test<strong>Exclusieve scherpe prijs</strong>Test<strong> tot</strong>"; AttributedFontHelper.GetFontTextBlocks(text, "H1", plugin, out resultWithoutTags); resultWithoutTags.Should().Be(expectedResultWithoutTags); }
public void UnregisteredFontTagsShouldBeIgnored() { AssetPlugin plugin = new TestAssetPlugin(); plugin.AddFont(new BaseFont() { Name = "Bold", FontFilename = "Bold.otf" }); plugin.AddFont(new BaseFont() { Name = "H1", FontFilename = "H1.otf" }, new FontTag("Bold", "strong")); string text = "this is <strong>one <a href='http://www.google.com'>font</a> to rule them all</strong> block"; string resultWithoutTags; AttributedFontHelper.GetFontTextBlocks(text, "H1", plugin, out resultWithoutTags); resultWithoutTags.Should().Be("this is one <a href='http://www.google.com'>font</a> to rule them all block"); }
public void ClearingFontsClearsAllFontsAndTags() { AssetPlugin plugin = new TestAssetPlugin(); plugin.AddFont(new BaseFont() { Name = "Bold", FontFilename = "Bold.otf" }); plugin.AddFont(new BaseFont() { Name = "H1", FontFilename = "H1.otf" }, new FontTag("Bold", "b")); plugin.GetFontByName("H1").Should().NotBeNull(); plugin.GetFontByName("Bold").Should().NotBeNull(); plugin.ClearFonts(); plugin.GetFontByName("H1").Should().BeNull(); plugin.GetFontByName("Bold").Should().BeNull(); }
public void NoTagTextShouldResultInOneBlock() { AssetPlugin plugin = new TestAssetPlugin(); plugin.AddFont(new BaseFont() { Name = "Bold", FontFilename = "Bold.otf" }); string text = "this is one block"; string resultWithoutTags; var result = AttributedFontHelper.GetFontTextBlocks(text, "Bold", plugin, out resultWithoutTags); result.Count.Should().Be(1); result.First().StartIndex.Should().Be(0); result.First().EndIndex.Should().Be(text.Length); result.First().FontTag.Should().BeNull();//if the font is not overriden it's not set resultWithoutTags.Should().Be(text); }
public void GettingANonExistingFontTagReturnsNull() { AssetPlugin plugin = new TestAssetPlugin(); plugin.GetFontByTag("Banana", "a").Should().BeNull(); }
public void GettingANonExistingFontColorReturnsNull() { AssetPlugin plugin = new TestAssetPlugin(); plugin.GetFontByName("Bananas:H1").Should().BeNull(); }
public void GettingANonExistingColorReturnsNull() { AssetPlugin plugin = new TestAssetPlugin(); plugin.GetColor("H1").Should().Be(Color.Empty); }
public void ShouldConstruct() { AssetPlugin plugin = new TestAssetPlugin(); plugin.Should().NotBeNull(); }