From 92cf03c9e7b740de02cec5db42ab35a83d07ba65 Mon Sep 17 00:00:00 2001 From: AlexejLiebenthal Date: Sat, 3 Feb 2018 18:18:11 +0100 Subject: [PATCH] Added some unittests for the HtmlFormatter --- .../Properties/AssemblyInfo.cs | 33 +++++++++ .../Formatters/HtmlFormatterTests.cs | 71 +++++++++++++++++++ .../Xceed.Wpf.Toolkit.Tests.csproj | 63 ++++++++++++++++ .../Xceed.Wpf.Toolkit.Tests/packages.config | 4 ++ .../Xceed.Wpf.Toolkit.sln | 48 ++++++++++++- 5 files changed, 216 insertions(+), 3 deletions(-) create mode 100644 ExtendedWPFToolkitSolution/Xceed.Wpf.Toolkit.Tests/Properties/AssemblyInfo.cs create mode 100644 ExtendedWPFToolkitSolution/Xceed.Wpf.Toolkit.Tests/RichTextBox/Formatters/HtmlFormatterTests.cs create mode 100644 ExtendedWPFToolkitSolution/Xceed.Wpf.Toolkit.Tests/Xceed.Wpf.Toolkit.Tests.csproj create mode 100644 ExtendedWPFToolkitSolution/Xceed.Wpf.Toolkit.Tests/packages.config diff --git a/ExtendedWPFToolkitSolution/Xceed.Wpf.Toolkit.Tests/Properties/AssemblyInfo.cs b/ExtendedWPFToolkitSolution/Xceed.Wpf.Toolkit.Tests/Properties/AssemblyInfo.cs new file mode 100644 index 00000000..b387f019 --- /dev/null +++ b/ExtendedWPFToolkitSolution/Xceed.Wpf.Toolkit.Tests/Properties/AssemblyInfo.cs @@ -0,0 +1,33 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +[assembly: AssemblyTitle("Xceed.Wpf.Toolkit.Tests")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("nunit.tests")] +[assembly: AssemblyCopyright("Copyright © 2017")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from +// COM, set the ComVisible attribute to true on that type. +[assembly: ComVisible(false)] + +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the values or you can default the Build and Revision Numbers +// by using the '*' as shown below: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/ExtendedWPFToolkitSolution/Xceed.Wpf.Toolkit.Tests/RichTextBox/Formatters/HtmlFormatterTests.cs b/ExtendedWPFToolkitSolution/Xceed.Wpf.Toolkit.Tests/RichTextBox/Formatters/HtmlFormatterTests.cs new file mode 100644 index 00000000..8d46e1e9 --- /dev/null +++ b/ExtendedWPFToolkitSolution/Xceed.Wpf.Toolkit.Tests/RichTextBox/Formatters/HtmlFormatterTests.cs @@ -0,0 +1,71 @@ +using System.Diagnostics; +using System.IO; +using System.Security.Cryptography.X509Certificates; +using System.Text; +using System.Windows; +using NUnit.Framework; +using System.Windows.Documents; +using System.Xml.Linq; + +namespace Xceed.Wpf.Toolkit.Tests +{ + [TestFixture] + public class HtmlFormatterTests + { + public HtmlFormatter CreateInstance() => new HtmlFormatter(); + + public FlowDocument CreateSimpleFlowDocument() + { + var r = new Run("Hallo Welt!"); + var b = new Bold(r); + var p = new Paragraph(b); + return new FlowDocument(p); + } + + public string CreateSimpleHtml() => + "

Hallo Welt!

"; + + [Test] + public void GetText_ShouldReturnAHtmlText() + { + var sut = CreateInstance(); + var doc = CreateSimpleFlowDocument(); + + var actual = sut.GetText(doc); + + const string expectedText = "Hallo Welt!"; + const string expectedBoldStyle = "bold"; + const string expectedHtmlTag = ""; + + Assert.Multiple(delegate + { + Assert.That(actual, Does.Contain(expectedText)); + Assert.That(actual, Does.Contain(expectedBoldStyle)); + Assert.That(actual, Does.Contain(expectedHtmlTag)); + }); + } + + [Test] + public void SetText_ShouldSetAHtmlTextToAFlowDocument() + { + var sut = CreateInstance(); + var doc = new FlowDocument(); + var text = CreateSimpleHtml(); + + sut.SetText(doc, text); + + var actual = new XamlFormatter().GetText(doc); + + const string expectedText = "Hallo Welt!"; + const string expectedBoldStyle = "Bold"; + const string expectedSection = "Section"; + + Assert.Multiple(() => + { + Assert.That(actual, Does.Contain(expectedText)); + Assert.That(actual, Does.Contain(expectedBoldStyle)); + Assert.That(actual, Does.Contain(expectedSection)); + }); + } + } +} \ No newline at end of file diff --git a/ExtendedWPFToolkitSolution/Xceed.Wpf.Toolkit.Tests/Xceed.Wpf.Toolkit.Tests.csproj b/ExtendedWPFToolkitSolution/Xceed.Wpf.Toolkit.Tests/Xceed.Wpf.Toolkit.Tests.csproj new file mode 100644 index 00000000..93874f2b --- /dev/null +++ b/ExtendedWPFToolkitSolution/Xceed.Wpf.Toolkit.Tests/Xceed.Wpf.Toolkit.Tests.csproj @@ -0,0 +1,63 @@ + + + + + Debug + AnyCPU + {8EDF4429-251A-416D-BB68-93F227191BCF} + Library + Properties + Xceed.Wpf.Toolkit.Tests + Xceed.Wpf.Toolkit.Tests + v4.5 + 512 + + + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + ..\packages\NUnit.3.6.1\lib\net45\nunit.framework.dll + + + + + + + + + + + + + + + + + {72E591D6-8F83-4D8C-8F67-9C325E623234} + Xceed.Wpf.Toolkit + + + + + \ No newline at end of file diff --git a/ExtendedWPFToolkitSolution/Xceed.Wpf.Toolkit.Tests/packages.config b/ExtendedWPFToolkitSolution/Xceed.Wpf.Toolkit.Tests/packages.config new file mode 100644 index 00000000..8e3be789 --- /dev/null +++ b/ExtendedWPFToolkitSolution/Xceed.Wpf.Toolkit.Tests/packages.config @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/ExtendedWPFToolkitSolution/Xceed.Wpf.Toolkit.sln b/ExtendedWPFToolkitSolution/Xceed.Wpf.Toolkit.sln index 4a6b2f46..d7adb40c 100644 --- a/ExtendedWPFToolkitSolution/Xceed.Wpf.Toolkit.sln +++ b/ExtendedWPFToolkitSolution/Xceed.Wpf.Toolkit.sln @@ -1,6 +1,8 @@  -Microsoft Visual Studio Solution File, Format Version 11.00 -# Visual Studio 2010 +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio 15 +VisualStudioVersion = 15.0.27130.2027 +MinimumVisualStudioVersion = 10.0.40219.1 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Xceed.Wpf.Toolkit.LiveExplorer", "Src\Xceed.Wpf.Toolkit.LiveExplorer\Xceed.Wpf.Toolkit.LiveExplorer.csproj", "{5E7DC9C8-3E27-400C-B84C-29FF9E710CB3}" EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Xceed.Wpf.Toolkit", "Src\Xceed.Wpf.Toolkit\Xceed.Wpf.Toolkit.csproj", "{72E591D6-8F83-4D8C-8F67-9C325E623234}" @@ -17,41 +19,78 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Xceed.Wpf.AvalonDock.Themes EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Xceed.Wpf.AvalonDock.Themes.Aero", "Src\Xceed.Wpf.AvalonDock.Themes.Aero\Xceed.Wpf.AvalonDock.Themes.Aero.csproj", "{BA72CCE0-A9FB-4995-B496-7FEC5C87B85B}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Xceed.Wpf.Toolkit.Tests", "Xceed.Wpf.Toolkit.Tests\Xceed.Wpf.Toolkit.Tests.csproj", "{8EDF4429-251A-416D-BB68-93F227191BCF}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU Debug|Mixed Platforms = Debug|Mixed Platforms + Release|Any CPU = Release|Any CPU Release|Mixed Platforms = Release|Mixed Platforms EndGlobalSection GlobalSection(ProjectConfigurationPlatforms) = postSolution + {5E7DC9C8-3E27-400C-B84C-29FF9E710CB3}.Debug|Any CPU.ActiveCfg = Debug|x86 {5E7DC9C8-3E27-400C-B84C-29FF9E710CB3}.Debug|Mixed Platforms.ActiveCfg = Debug|x86 {5E7DC9C8-3E27-400C-B84C-29FF9E710CB3}.Debug|Mixed Platforms.Build.0 = Debug|x86 + {5E7DC9C8-3E27-400C-B84C-29FF9E710CB3}.Release|Any CPU.ActiveCfg = Release|x86 {5E7DC9C8-3E27-400C-B84C-29FF9E710CB3}.Release|Mixed Platforms.ActiveCfg = Release|x86 {5E7DC9C8-3E27-400C-B84C-29FF9E710CB3}.Release|Mixed Platforms.Build.0 = Release|x86 + {72E591D6-8F83-4D8C-8F67-9C325E623234}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {72E591D6-8F83-4D8C-8F67-9C325E623234}.Debug|Any CPU.Build.0 = Debug|Any CPU {72E591D6-8F83-4D8C-8F67-9C325E623234}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU {72E591D6-8F83-4D8C-8F67-9C325E623234}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU + {72E591D6-8F83-4D8C-8F67-9C325E623234}.Release|Any CPU.ActiveCfg = Release|Any CPU + {72E591D6-8F83-4D8C-8F67-9C325E623234}.Release|Any CPU.Build.0 = Release|Any CPU {72E591D6-8F83-4D8C-8F67-9C325E623234}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU {72E591D6-8F83-4D8C-8F67-9C325E623234}.Release|Mixed Platforms.Build.0 = Release|Any CPU + {63648392-6CE9-4A60-96D4-F9FD718D29B0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {63648392-6CE9-4A60-96D4-F9FD718D29B0}.Debug|Any CPU.Build.0 = Debug|Any CPU {63648392-6CE9-4A60-96D4-F9FD718D29B0}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU {63648392-6CE9-4A60-96D4-F9FD718D29B0}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU + {63648392-6CE9-4A60-96D4-F9FD718D29B0}.Release|Any CPU.ActiveCfg = Release|Any CPU + {63648392-6CE9-4A60-96D4-F9FD718D29B0}.Release|Any CPU.Build.0 = Release|Any CPU {63648392-6CE9-4A60-96D4-F9FD718D29B0}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU {63648392-6CE9-4A60-96D4-F9FD718D29B0}.Release|Mixed Platforms.Build.0 = Release|Any CPU + {DB81988F-E0F2-45A0-A1FD-8C37F3D35244}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {DB81988F-E0F2-45A0-A1FD-8C37F3D35244}.Debug|Any CPU.Build.0 = Debug|Any CPU {DB81988F-E0F2-45A0-A1FD-8C37F3D35244}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU {DB81988F-E0F2-45A0-A1FD-8C37F3D35244}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU + {DB81988F-E0F2-45A0-A1FD-8C37F3D35244}.Release|Any CPU.ActiveCfg = Release|Any CPU + {DB81988F-E0F2-45A0-A1FD-8C37F3D35244}.Release|Any CPU.Build.0 = Release|Any CPU {DB81988F-E0F2-45A0-A1FD-8C37F3D35244}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU {DB81988F-E0F2-45A0-A1FD-8C37F3D35244}.Release|Mixed Platforms.Build.0 = Release|Any CPU + {B3FC3E21-5F2D-4581-AEA2-59F671CFFC21}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {B3FC3E21-5F2D-4581-AEA2-59F671CFFC21}.Debug|Any CPU.Build.0 = Debug|Any CPU {B3FC3E21-5F2D-4581-AEA2-59F671CFFC21}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU {B3FC3E21-5F2D-4581-AEA2-59F671CFFC21}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU + {B3FC3E21-5F2D-4581-AEA2-59F671CFFC21}.Release|Any CPU.ActiveCfg = Release|Any CPU + {B3FC3E21-5F2D-4581-AEA2-59F671CFFC21}.Release|Any CPU.Build.0 = Release|Any CPU {B3FC3E21-5F2D-4581-AEA2-59F671CFFC21}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU {B3FC3E21-5F2D-4581-AEA2-59F671CFFC21}.Release|Mixed Platforms.Build.0 = Release|Any CPU + {89286EB4-B4A1-418C-839A-067B00F442D8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {89286EB4-B4A1-418C-839A-067B00F442D8}.Debug|Any CPU.Build.0 = Debug|Any CPU {89286EB4-B4A1-418C-839A-067B00F442D8}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU {89286EB4-B4A1-418C-839A-067B00F442D8}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU + {89286EB4-B4A1-418C-839A-067B00F442D8}.Release|Any CPU.ActiveCfg = Release|Any CPU + {89286EB4-B4A1-418C-839A-067B00F442D8}.Release|Any CPU.Build.0 = Release|Any CPU {89286EB4-B4A1-418C-839A-067B00F442D8}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU {89286EB4-B4A1-418C-839A-067B00F442D8}.Release|Mixed Platforms.Build.0 = Release|Any CPU + {BA72CCE0-A9FB-4995-B496-7FEC5C87B85B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {BA72CCE0-A9FB-4995-B496-7FEC5C87B85B}.Debug|Any CPU.Build.0 = Debug|Any CPU {BA72CCE0-A9FB-4995-B496-7FEC5C87B85B}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU {BA72CCE0-A9FB-4995-B496-7FEC5C87B85B}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU + {BA72CCE0-A9FB-4995-B496-7FEC5C87B85B}.Release|Any CPU.ActiveCfg = Release|Any CPU + {BA72CCE0-A9FB-4995-B496-7FEC5C87B85B}.Release|Any CPU.Build.0 = Release|Any CPU {BA72CCE0-A9FB-4995-B496-7FEC5C87B85B}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU {BA72CCE0-A9FB-4995-B496-7FEC5C87B85B}.Release|Mixed Platforms.Build.0 = Release|Any CPU - + {8EDF4429-251A-416D-BB68-93F227191BCF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {8EDF4429-251A-416D-BB68-93F227191BCF}.Debug|Any CPU.Build.0 = Debug|Any CPU + {8EDF4429-251A-416D-BB68-93F227191BCF}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU + {8EDF4429-251A-416D-BB68-93F227191BCF}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU + {8EDF4429-251A-416D-BB68-93F227191BCF}.Release|Any CPU.ActiveCfg = Release|Any CPU + {8EDF4429-251A-416D-BB68-93F227191BCF}.Release|Any CPU.Build.0 = Release|Any CPU + {8EDF4429-251A-416D-BB68-93F227191BCF}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU + {8EDF4429-251A-416D-BB68-93F227191BCF}.Release|Mixed Platforms.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -61,4 +100,7 @@ Global {89286EB4-B4A1-418C-839A-067B00F442D8} = {8976E4A6-FF5F-44C5-AC57-FEDA249DD199} {BA72CCE0-A9FB-4995-B496-7FEC5C87B85B} = {8976E4A6-FF5F-44C5-AC57-FEDA249DD199} EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {15EEF6F5-5537-4DDA-87C8-01EA9B3C3A98} + EndGlobalSection EndGlobal