diff --git a/GoToBible.Model/ExtensionMethods.cs b/GoToBible.Model/ExtensionMethods.cs index 9edfb45..7927e22 100644 --- a/GoToBible.Model/ExtensionMethods.cs +++ b/GoToBible.Model/ExtensionMethods.cs @@ -237,18 +237,18 @@ public static PassageReference AsPassageReference(this string passage, int defau } // Sanitise the passage reference for retrieving the book and verse - string sanitisedPassage = SanitisePassageReference(passage); + string sanitisedPassage = passage.SanitisePassageReference(); // Get the book - string book = GetBook(sanitisedPassage); + string book = sanitisedPassage.GetBook(); if (!string.IsNullOrWhiteSpace(book) && BookLengths[book] is int[] chapters) { if (chapters.Length == 1) { - sanitisedPassage = NormaliseSingleChapterReference(sanitisedPassage); + sanitisedPassage = sanitisedPassage.NormaliseSingleChapterReference(); } - string[] ranges = GetRanges(sanitisedPassage); + string[] ranges = sanitisedPassage.GetRanges(); foreach (string range in ranges) { if (!int.TryParse(range.Split(':')[0], out int chapter)) @@ -496,7 +496,7 @@ public static string RenderCss(this RenderingParameters parameters) /// /// The book from the passage reference. /// - private static string GetBook(string passage) + internal static string GetBook(this string passage) { // Prepare the passage reference for the regex passage = passage.Replace(":", string.Empty); @@ -534,7 +534,7 @@ private static string GetBook(string passage) /// /// The passage. /// The ranges. - private static string[] GetRanges(string passage) + internal static string[] GetRanges(this string passage) { // Validate input if (string.IsNullOrWhiteSpace(passage) || passage.Length == 1) @@ -545,7 +545,7 @@ private static string[] GetRanges(string passage) passage = passage[1..]; Regex rangePartRegex = new Regex(@"\d", RegexOptions.Compiled); string rangePart = passage[rangePartRegex.Match(passage).Index..]; - rangePart = NormaliseCommas(rangePart); + rangePart = rangePart.NormaliseCommas(); string[] semiParts = rangePart.Split(';'); rangePart = semiParts[0]; semiParts = semiParts.Skip(1).ToArray(); @@ -584,7 +584,7 @@ private static string[] GetRanges(string passage) } } - ranges.AddRange(GetRanges("Book" + semiParts[i])); + ranges.AddRange($"Book{semiParts[i]}".GetRanges()); } return ranges.ToArray(); @@ -597,7 +597,7 @@ private static string[] GetRanges(string passage) /// /// The range part with commas normalised. /// - private static string NormaliseCommas(string rangePart) + internal static string NormaliseCommas(this string rangePart) { string[] parts = rangePart.Split(','); @@ -630,7 +630,7 @@ private static string NormaliseCommas(string rangePart) /// /// The single chapter reference normalised. /// - private static string NormaliseSingleChapterReference(string passage) + internal static string NormaliseSingleChapterReference(this string passage) { string[] semiParts = passage.Split(';'); if (!semiParts[0].Contains(":")) @@ -652,7 +652,7 @@ private static string NormaliseSingleChapterReference(string passage) /// /// The passage reference ready for cleaning. /// - private static string SanitisePassageReference(string passage) + internal static string SanitisePassageReference(this string passage) { Regex dashRegex = new Regex(@"[‐‑‒–—-]", RegexOptions.Compiled); return dashRegex.Replace(passage.Replace(" ", string.Empty).Replace('.', ':').ToLowerInvariant(), "-"); diff --git a/GoToBible.Model/GoToBible.Model.csproj b/GoToBible.Model/GoToBible.Model.csproj index e110ffb..6c08446 100644 --- a/GoToBible.Model/GoToBible.Model.csproj +++ b/GoToBible.Model/GoToBible.Model.csproj @@ -1,9 +1,10 @@ - + net5.0 true GoToBible.Model.snk + true enable true true @@ -25,8 +26,8 @@ App.ico LGPL-3.0-or-later git - Bug fixes and improvements from the port to Swift - 1.1.3 + Bug fixes and improvements found when porting the unit tests from Swift + 1.1.4 @@ -56,4 +57,10 @@ + + + <_Parameter1>GoToBible.Tests.Model, PublicKey=0024000004800000940000000602000000240000525341310004000001000100451405b438b9725f449dd5b93d547517f8e31d58f90db632f8dae6d329245b7d7fea4ccec586e0285e6067e14030379d2c813efb46abd5db044ee781fef435fb38c6cacfa007d739424291880fbfc1b0fe5171fb5e78f5d6d8b00fb80b371ac2f278d26c2feab7b54a545c976839a5502c811689a5b2528e89d890d5358ccce5 + + + diff --git a/GoToBible.Model/PassageReference.cs b/GoToBible.Model/PassageReference.cs index 6bd8df0..4c984b5 100644 --- a/GoToBible.Model/PassageReference.cs +++ b/GoToBible.Model/PassageReference.cs @@ -7,11 +7,12 @@ namespace GoToBible.Model { using System; + using System.Linq; /// /// A passage reference. /// - public record PassageReference + public record PassageReference : IEquatable { /// /// Gets or sets the chapter reference. @@ -47,5 +48,27 @@ public record PassageReference /// We only require the chapter reference. This method assumes you used AsPassageReference() to generate this object. /// public bool IsValid => this.ChapterReference.IsValid; + + /// + public virtual bool Equals(PassageReference? other) + => other is not null + && this.ChapterReference == other.ChapterReference + && this.Display == other.Display + && this.HighlightedVerses.SequenceEqual(other.HighlightedVerses) + && this.IsValid == other.IsValid; + + /// + public override int GetHashCode() + { + HashCode hashCode = default; + hashCode.Add(this.ChapterReference); + hashCode.Add(this.Display); + foreach (int highlightedVerse in this.HighlightedVerses) + { + hashCode.Add(highlightedVerse); + } + + return hashCode.ToHashCode(); + } } } diff --git a/GoToBible.Tests.Model/BookTests.cs b/GoToBible.Tests.Model/BookTests.cs new file mode 100644 index 0000000..94409b0 --- /dev/null +++ b/GoToBible.Tests.Model/BookTests.cs @@ -0,0 +1,45 @@ +// ----------------------------------------------------------------------- +// +// Copyright 2020-2021 Conglomo Limited. Please see LICENSE for license details. +// +// ----------------------------------------------------------------------- + +namespace GoToBible.Tests.Model +{ + using GoToBible.Model; + using Microsoft.VisualStudio.TestTools.UnitTesting; + + /// + /// Tests the class. + /// + [TestClass] + public class BookTests + { + /// + /// Tests the empty object. + /// + [TestMethod] + public void TestEmpty() + { + Book book = new Book(); + Assert.AreEqual(book.Name, string.Empty); + Assert.AreEqual(book.Chapters.Count, 0); + Assert.AreEqual(book.ToString(), string.Empty); + } + + /// + /// Tests the property. + /// + [TestMethod] + public void TestName() + { + Book book = new Book() + { + Name = "Genesis", + }; + Assert.AreEqual(book.Name, "Genesis"); + Assert.AreEqual(book.Chapters.Count, 0); + Assert.AreEqual(book.ToString(), "Genesis"); + } + } +} diff --git a/GoToBible.Tests.Model/ChapterReferenceTests.cs b/GoToBible.Tests.Model/ChapterReferenceTests.cs new file mode 100644 index 0000000..a8f8a7c --- /dev/null +++ b/GoToBible.Tests.Model/ChapterReferenceTests.cs @@ -0,0 +1,122 @@ +// ----------------------------------------------------------------------- +// +// Copyright 2020-2021 Conglomo Limited. Please see LICENSE for license details. +// +// ----------------------------------------------------------------------- + +namespace GoToBible.Tests.Model +{ + using GoToBible.Model; + using Microsoft.VisualStudio.TestTools.UnitTesting; + + /// + /// Tests the class. + /// + [TestClass] + public class ChapterReferenceTests + { + /// + /// Tests the empty constructor. + /// + [TestMethod] + public void TestEmpty() + { + ChapterReference chapterReference = new ChapterReference(); + Assert.AreEqual(chapterReference.Book, string.Empty); + Assert.AreEqual(chapterReference.ChapterNumber, 0); + Assert.AreEqual(chapterReference.ToString(), string.Empty); + Assert.IsFalse(chapterReference.IsValid); + } + + /// + /// Tests an invalid constructor. + /// + [TestMethod] + public void TestBookAndChapterInvalidConstructor() + { + ChapterReference chapterReference = new ChapterReference(string.Empty); + Assert.AreEqual(chapterReference.Book, string.Empty); + Assert.AreEqual(chapterReference.ChapterNumber, 0); + Assert.AreEqual(chapterReference.ToString(), string.Empty); + Assert.IsFalse(chapterReference.IsValid); + } + + /// + /// Tests an invalid chapter constructor. + /// + [TestMethod] + public void TestBookAndChapterInvalidChapterConstructor() + { + ChapterReference chapterReference = new ChapterReference("Genesis Fifty"); + Assert.AreEqual(chapterReference.Book, "Genesis"); + Assert.AreEqual(chapterReference.ChapterNumber, 0); + Assert.AreEqual(chapterReference.ToString(), "Genesis 0"); + Assert.IsTrue(chapterReference.IsValid); + } + + /// + /// Tests a missing chapter constructor. + /// + [TestMethod] + public void TestBookAndChapterMissingChapterConstructor() + { + ChapterReference chapterReference = new ChapterReference("Genesis"); + Assert.AreEqual(chapterReference.Book, "Genesis"); + Assert.AreEqual(chapterReference.ChapterNumber, 0); + Assert.AreEqual(chapterReference.ToString(), "Genesis 0"); + Assert.IsTrue(chapterReference.IsValid); + } + + /// + /// Tests a valid chapter constructor. + /// + [TestMethod] + public void TestBookAndChapterValidChapterConstructor() + { + ChapterReference chapterReference = new ChapterReference("Genesis 50"); + Assert.AreEqual(chapterReference.Book, "Genesis"); + Assert.AreEqual(chapterReference.ChapterNumber, 50); + Assert.AreEqual(chapterReference.ToString(), "Genesis 50"); + Assert.IsTrue(chapterReference.IsValid); + } + + /// + /// Tests an invalid two parameter constructor. + /// + [TestMethod] + public void TestTwoParameterInvalidConstructor() + { + ChapterReference chapterReference = new ChapterReference(string.Empty, 0); + Assert.AreEqual(chapterReference.Book, string.Empty); + Assert.AreEqual(chapterReference.ChapterNumber, 0); + Assert.AreEqual(chapterReference.ToString(), string.Empty); + Assert.IsFalse(chapterReference.IsValid); + } + + /// + /// Tests an invalid two parameter constructor for Psalm 151. + /// + [TestMethod] + public void TestTwoParameterPsalm151Constructor() + { + ChapterReference chapterReference = new ChapterReference("Psalm 151", 0); + Assert.AreEqual(chapterReference.Book, "Psalm"); + Assert.AreEqual(chapterReference.ChapterNumber, 151); + Assert.AreEqual(chapterReference.ToString(), "Psalm 151"); + Assert.IsTrue(chapterReference.IsValid); + } + + /// + /// Tests a valid two parameter constructor. + /// + [TestMethod] + public void TestTwoParameterValidConstructor() + { + ChapterReference chapterReference = new ChapterReference("Genesis", 50); + Assert.AreEqual(chapterReference.Book, "Genesis"); + Assert.AreEqual(chapterReference.ChapterNumber, 50); + Assert.AreEqual(chapterReference.ToString(), "Genesis 50"); + Assert.IsTrue(chapterReference.IsValid); + } + } +} diff --git a/GoToBible.Tests.Model/ChapterTests.cs b/GoToBible.Tests.Model/ChapterTests.cs new file mode 100644 index 0000000..806f7db --- /dev/null +++ b/GoToBible.Tests.Model/ChapterTests.cs @@ -0,0 +1,35 @@ +// ----------------------------------------------------------------------- +// +// Copyright 2020-2021 Conglomo Limited. Please see LICENSE for license details. +// +// ----------------------------------------------------------------------- + +namespace GoToBible.Tests.Model +{ + using GoToBible.Model; + using Microsoft.VisualStudio.TestTools.UnitTesting; + + /// + /// Tests the class. + /// + [TestClass] + public class ChapterTests + { + /// + /// Tests the empty object. + /// + [TestMethod] + public void TestEmpty() + { + Chapter chapter = new Chapter(); + Assert.AreEqual(chapter.Book, string.Empty); + Assert.AreEqual(chapter.ChapterNumber, 0); + Assert.AreEqual(chapter.Copyright, string.Empty); + Assert.AreEqual(chapter.NextChapterReference.ToString(), string.Empty); + Assert.AreEqual(chapter.PreviousChapterReference.ToString(), string.Empty); + Assert.IsFalse(chapter.SupportsItalics); + Assert.AreEqual(chapter.Text, string.Empty); + Assert.AreEqual(chapter.Translation, string.Empty); + } + } +} diff --git a/GoToBible.Tests.Model/ExtensionMethodTests.cs b/GoToBible.Tests.Model/ExtensionMethodTests.cs new file mode 100644 index 0000000..6283957 --- /dev/null +++ b/GoToBible.Tests.Model/ExtensionMethodTests.cs @@ -0,0 +1,182 @@ +// ----------------------------------------------------------------------- +// +// Copyright 2020-2021 Conglomo Limited. Please see LICENSE for license details. +// +// ----------------------------------------------------------------------- + +namespace GoToBible.Tests.Model +{ + using System; + using System.Linq; + using GoToBible.Model; + using Microsoft.VisualStudio.TestTools.UnitTesting; + + /// + /// Tests the class. + /// + [TestClass] + public class ExtensionMethodTests + { + /// + /// Tests . + /// + [TestMethod] + public void TestChapterReferenceAsPassageReference() + { + ChapterReference chapterReference = new ChapterReference("1 John", 1); + PassageReference expected = new PassageReference() + { + ChapterReference = chapterReference, + Display = "1 John 1", + HighlightedVerses = Array.Empty(), + }; + PassageReference actual = chapterReference.AsPassageReference(); + Assert.AreEqual(expected, actual); + } + + /// + /// Tests . + /// + [TestMethod] + public void TestStringAsPassageReference() + { + PassageReference expected = new PassageReference() + { + ChapterReference = new ChapterReference("1 John", 1), + Display = "1 John 1:3,6-7,9-12", + HighlightedVerses = new int[] { 3, 6, 7, 9, 10, 11, 12 }, + }; + PassageReference actual = "1 John 1:3,6-7,9-12".AsPassageReference(); + Assert.AreEqual(expected, actual); + } + + /// + /// Tests for an empty . + /// + [TestMethod] + public void TestAsUrl_RenderingParametersEmpty() + { + RenderingParameters renderingParameters = new RenderingParameters(); + Assert.AreEqual(renderingParameters.AsUrl(), new Uri("https://goto.bible/")); + } + + /// + /// Tests for a with one translation. + /// + [TestMethod] + public void TestAsUrl_RenderingParametersOneTranslation() + { + RenderingParameters renderingParameters = new RenderingParameters(); + renderingParameters.PassageReference.Display = "1 John 1:3,6-7"; + renderingParameters.PrimaryTranslation = "ESV"; + Assert.AreEqual(renderingParameters.AsUrl(), new Uri("https://goto.bible/1.John.1_3~6-7/ESV")); + } + + /// + /// Tests for a with two translations. + /// + [TestMethod] + public void TestAsUrl_RenderingParametersTwoTranslations() + { + RenderingParameters renderingParameters = new RenderingParameters(); + renderingParameters.PassageReference.Display = "1 John 1:3,6-7"; + renderingParameters.PrimaryTranslation = "ESV"; + renderingParameters.SecondaryTranslation = "NET"; + Assert.AreEqual(renderingParameters.AsUrl(), new Uri("https://goto.bible/1.John.1_3~6-7/ESV/NET")); + } + + /// + /// Tests . + /// + [TestMethod] + public void TestDecodePassageFromUrl() => Assert.AreEqual("/1.John.1_3~6-7/".DecodePassageFromUrl(), "1 John 1:3,6-7"); + + /// + /// Tests . + /// + [TestMethod] + public void TestEncodePassageFromUrl() => Assert.AreEqual("1 John 1:3,6-7".EncodePassageForUrl(), "1.John.1_3~6-7"); + + /// + /// Tests . + /// + [TestMethod] + public void TestGetBook() => Assert.AreEqual("1jn1:1".GetBook(), "1 john"); + + /// + /// Tests for a book with brackets. + /// + [TestMethod] + public void TestGetBookWithBrackets() => Assert.AreEqual("est(greek)1:1".GetBook(), "esther (greek)"); + + /// + /// Tests . + /// + [TestMethod] + public void TestGetRanges() + { + string[] expected = new string[] { "1:1", "1:2", "...", "1:3", "1:4", "1:5", "...", "1:6" }; + Assert.IsTrue("1john1:1,2-3,4,5-6".GetRanges().SequenceEqual(expected)); + } + + /// + /// Tests . + /// + [TestMethod] + public void TestNormaliseCommas() => Assert.AreEqual("1john1:1,2-3,4,5-6".NormaliseCommas(), "1john1:1;1john1:2-3;1john1:4;1john1:5-6"); + + /// + /// Tests for a single chapter reference. + /// + [TestMethod] + public void TestNormaliseSingleChapterReference() => Assert.AreEqual("jude1".NormaliseSingleChapterReference(), "jude1:1"); + + /// + /// Tests for a single chapter reference with a chapter already specified. + /// + [TestMethod] + public void TestNormaliseSingleChapterReferenceWithChapterAlreadySpecified() => Assert.AreEqual("jude1:1".NormaliseSingleChapterReference(), "jude1:1"); + + /// + /// Tests for blank . + /// + [TestMethod] + public void TestRenderCssBlank() => Assert.AreNotEqual(new RenderingParameters().RenderCss(), string.Empty); + + /// + /// Tests . + /// + [TestMethod] + public void TestSanitisePassageReference() => Assert.AreEqual("1 John 1.1‐2".SanitisePassageReference(), "1john1:1-2"); + + /// + /// Tests for black. + /// + [TestMethod] + public void TestToHtml_Black() => Assert.AreEqual(new RenderColour { R = 0, G = 0, B = 0 }.ToHtml(), "#000000"); + + /// + /// Tests for blue. + /// + [TestMethod] + public void TestToHtml_Blue() => Assert.AreEqual(new RenderColour { R = 0, G = 0, B = 255 }.ToHtml(), "#0000FF"); + + /// + /// Tests for green. + /// + [TestMethod] + public void TestToHtml_Green() => Assert.AreEqual(new RenderColour { R = 0, G = 255, B = 0 }.ToHtml(), "#00FF00"); + + /// + /// Tests for red. + /// + [TestMethod] + public void TestToHtml_Red() => Assert.AreEqual(new RenderColour { R = 255, G = 0, B = 0 }.ToHtml(), "#FF0000"); + + /// + /// Tests for white. + /// + [TestMethod] + public void TestToHtml_White() => Assert.AreEqual(new RenderColour { R = 255, G = 255, B = 255 }.ToHtml(), "#FFFFFF"); + } +} diff --git a/GoToBible.Tests.Model/GoToBible.Tests.Model.csproj b/GoToBible.Tests.Model/GoToBible.Tests.Model.csproj new file mode 100644 index 0000000..9ebfe8f --- /dev/null +++ b/GoToBible.Tests.Model/GoToBible.Tests.Model.csproj @@ -0,0 +1,41 @@ + + + + net5.0 + + false + + true + + GoToBible.Tests.Model.snk + + false + + + + bin\GoToBible.Tests.Model.xml + + + + + + + + + + + + + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + + + + + + diff --git a/GoToBible.Tests.Model/GoToBible.Tests.Model.snk b/GoToBible.Tests.Model/GoToBible.Tests.Model.snk new file mode 100644 index 0000000..e8ec4d6 Binary files /dev/null and b/GoToBible.Tests.Model/GoToBible.Tests.Model.snk differ diff --git a/GoToBible.Tests.Model/LanguageComparerTests.cs b/GoToBible.Tests.Model/LanguageComparerTests.cs new file mode 100644 index 0000000..b4d986b --- /dev/null +++ b/GoToBible.Tests.Model/LanguageComparerTests.cs @@ -0,0 +1,52 @@ +// ----------------------------------------------------------------------- +// +// Copyright 2020-2021 Conglomo Limited. Please see LICENSE for license details. +// +// ----------------------------------------------------------------------- + +namespace GoToBible.Tests.Model +{ + using System; + using System.Linq; + using GoToBible.Model; + using Microsoft.VisualStudio.TestTools.UnitTesting; + + /// + /// Tests the class. + /// + [TestClass] + public class LanguageComparerTests + { + /// + /// Tests the sort order of the . + /// + [TestMethod] + public void TestSortOrder() + { + string[] actual = new string[] + { + "German", + "Latin", + "Aramaic", + "Greek", + "French", + "English", + "Ugaritic", + "Hebrew", + }; + string[] expected = new string[] + { + "English", + "Greek", + "Hebrew", + "Latin", + "Aramaic", + "French", + "German", + "Ugaritic", + }; + Array.Sort(actual, new LanguageComparer()); + Assert.IsTrue(actual.SequenceEqual(expected)); + } + } +} diff --git a/GoToBible.Tests.Model/PassageReferenceTests.cs b/GoToBible.Tests.Model/PassageReferenceTests.cs new file mode 100644 index 0000000..c5d7f28 --- /dev/null +++ b/GoToBible.Tests.Model/PassageReferenceTests.cs @@ -0,0 +1,47 @@ +// ----------------------------------------------------------------------- +// +// Copyright 2020-2021 Conglomo Limited. Please see LICENSE for license details. +// +// ----------------------------------------------------------------------- + +namespace GoToBible.Tests.Model +{ + using GoToBible.Model; + using Microsoft.VisualStudio.TestTools.UnitTesting; + + /// + /// Tests the class. + /// + [TestClass] + public class PassageReferenceTests + { + /// + /// Tests an invalid . + /// + [TestMethod] + public void TestInvalid() + { + PassageReference passageReference = new PassageReference(); + Assert.IsFalse(passageReference.ChapterReference.IsValid); + Assert.AreEqual(passageReference.Display, string.Empty); + Assert.AreEqual(passageReference.HighlightedVerses.Length, 0); + Assert.IsFalse(passageReference.IsValid); + } + + /// + /// Tests a valid . + /// + [TestMethod] + public void TestValid() + { + PassageReference passageReference = new PassageReference + { + ChapterReference = new ChapterReference("Psalm 151"), + }; + Assert.IsTrue(passageReference.ChapterReference.IsValid); + Assert.AreEqual(passageReference.Display, string.Empty); + Assert.AreEqual(passageReference.HighlightedVerses.Length, 0); + Assert.IsTrue(passageReference.IsValid); + } + } +} diff --git a/GoToBible.Tests.Model/RenderColourTests.cs b/GoToBible.Tests.Model/RenderColourTests.cs new file mode 100644 index 0000000..87734e6 --- /dev/null +++ b/GoToBible.Tests.Model/RenderColourTests.cs @@ -0,0 +1,30 @@ +// ----------------------------------------------------------------------- +// +// Copyright 2020-2021 Conglomo Limited. Please see LICENSE for license details. +// +// ----------------------------------------------------------------------- + +namespace GoToBible.Tests.Model +{ + using GoToBible.Model; + using Microsoft.VisualStudio.TestTools.UnitTesting; + + /// + /// Tests the class. + /// + [TestClass] + public class RenderColourTests + { + /// + /// Tests the empty object. + /// + [TestMethod] + public void TestEmpty() + { + RenderColour renderColour = new RenderColour(); + Assert.AreEqual(renderColour.R, 0); + Assert.AreEqual(renderColour.G, 0); + Assert.AreEqual(renderColour.B, 0); + } + } +} diff --git a/GoToBible.Tests.Model/RenderFontTests.cs b/GoToBible.Tests.Model/RenderFontTests.cs new file mode 100644 index 0000000..6e1c948 --- /dev/null +++ b/GoToBible.Tests.Model/RenderFontTests.cs @@ -0,0 +1,33 @@ +// ----------------------------------------------------------------------- +// +// Copyright 2020-2021 Conglomo Limited. Please see LICENSE for license details. +// +// ----------------------------------------------------------------------- + +namespace GoToBible.Tests.Model +{ + using GoToBible.Model; + using Microsoft.VisualStudio.TestTools.UnitTesting; + + /// + /// Tests the class. + /// + [TestClass] + public class RenderFontTests + { + /// + /// Tests the empty object. + /// + [TestMethod] + public void TestEmpty() + { + RenderFont renderFont = new RenderFont(); + Assert.IsFalse(renderFont.Bold); + Assert.AreEqual(renderFont.FamilyName, string.Empty); + Assert.IsFalse(renderFont.Italic); + Assert.AreEqual(renderFont.SizeInPoints, 0); + Assert.IsFalse(renderFont.Strikeout); + Assert.IsFalse(renderFont.Underline); + } + } +} diff --git a/GoToBible.Tests.Model/RenderFormatTests.cs b/GoToBible.Tests.Model/RenderFormatTests.cs new file mode 100644 index 0000000..a851622 --- /dev/null +++ b/GoToBible.Tests.Model/RenderFormatTests.cs @@ -0,0 +1,36 @@ +// ----------------------------------------------------------------------- +// +// Copyright 2020-2021 Conglomo Limited. Please see LICENSE for license details. +// +// ----------------------------------------------------------------------- + +namespace GoToBible.Tests.Model +{ + using GoToBible.Model; + using Microsoft.VisualStudio.TestTools.UnitTesting; + + /// + /// Tests the enumeration. + /// + [TestClass] + public class RenderFormatTests + { + /// + /// Tests . + /// + [TestMethod] + public void TestAccordance() => Assert.AreEqual((int)RenderFormat.Accordance, 2); + + /// + /// Tests . + /// + [TestMethod] + public void TestHtml() => Assert.AreEqual((int)RenderFormat.Html, 1); + + /// + /// Tests . + /// + [TestMethod] + public void TestText() => Assert.AreEqual((int)RenderFormat.Text, 0); + } +} diff --git a/GoToBible.Tests.Model/RenderedPassageTests.cs b/GoToBible.Tests.Model/RenderedPassageTests.cs new file mode 100644 index 0000000..27f9fbf --- /dev/null +++ b/GoToBible.Tests.Model/RenderedPassageTests.cs @@ -0,0 +1,32 @@ +// ----------------------------------------------------------------------- +// +// Copyright 2020-2021 Conglomo Limited. Please see LICENSE for license details. +// +// ----------------------------------------------------------------------- + +namespace GoToBible.Tests.Model +{ + using GoToBible.Model; + using Microsoft.VisualStudio.TestTools.UnitTesting; + + /// + /// Tests the class. + /// + [TestClass] + public class RenderedPassageTests + { + /// + /// Tests the empty object. + /// + [TestMethod] + public void TestEmpty() + { + RenderedPassage renderedPassage = new RenderedPassage(); + Assert.AreEqual(renderedPassage.Content, string.Empty); + Assert.IsFalse(renderedPassage.NextPassage.IsValid); + Assert.IsFalse(renderedPassage.PreviousPassage.IsValid); + Assert.IsFalse(renderedPassage.Suggestions.IgnoreCaseDiacriticsAndPunctuation); + Assert.IsNull(renderedPassage.Suggestions.NavigateToChapter); + } + } +} diff --git a/GoToBible.Tests.Model/RenderingParametersTests.cs b/GoToBible.Tests.Model/RenderingParametersTests.cs new file mode 100644 index 0000000..7173682 --- /dev/null +++ b/GoToBible.Tests.Model/RenderingParametersTests.cs @@ -0,0 +1,42 @@ +// ----------------------------------------------------------------------- +// +// Copyright 2020-2021 Conglomo Limited. Please see LICENSE for license details. +// +// ----------------------------------------------------------------------- + +namespace GoToBible.Tests.Model +{ + using GoToBible.Model; + using Microsoft.VisualStudio.TestTools.UnitTesting; + + /// + /// Tests the class. + /// + [TestClass] + public class RenderingParametersTests + { + /// + /// Tests the empty object. + /// + [TestMethod] + public void TestEmpty() + { + RenderingParameters renderingParameters = new RenderingParameters(); + Assert.AreEqual(renderingParameters.BackgroundColour, Default.BackgroundColour); + Assert.AreEqual(renderingParameters.Font, Default.Font); + Assert.AreEqual(renderingParameters.ForegroundColour, Default.ForegroundColour); + Assert.AreEqual(renderingParameters.Format, RenderFormat.Html); + Assert.AreEqual(renderingParameters.HighlightColour, Default.HighlightColour); + Assert.IsFalse(renderingParameters.InterlinearIgnoresCase); + Assert.IsFalse(renderingParameters.InterlinearIgnoresDiacritics); + Assert.IsFalse(renderingParameters.InterlinearIgnoresPunctuation); + Assert.IsFalse(renderingParameters.IsDebug); + Assert.AreEqual(renderingParameters.PassageReference, Default.PassageReference); + Assert.AreEqual(renderingParameters.PrimaryProvider, string.Empty); + Assert.AreEqual(renderingParameters.PrimaryTranslation, string.Empty); + Assert.IsTrue(renderingParameters.RenderItalics); + Assert.IsNull(renderingParameters.SecondaryProvider); + Assert.IsNull(renderingParameters.SecondaryTranslation); + } + } +} diff --git a/GoToBible.Tests.Model/RenderingSuggestionsTests.cs b/GoToBible.Tests.Model/RenderingSuggestionsTests.cs new file mode 100644 index 0000000..7b58057 --- /dev/null +++ b/GoToBible.Tests.Model/RenderingSuggestionsTests.cs @@ -0,0 +1,29 @@ +// ----------------------------------------------------------------------- +// +// Copyright 2020-2021 Conglomo Limited. Please see LICENSE for license details. +// +// ----------------------------------------------------------------------- + +namespace GoToBible.Tests.Model +{ + using GoToBible.Model; + using Microsoft.VisualStudio.TestTools.UnitTesting; + + /// + /// Tests the class. + /// + [TestClass] + public class RenderingSuggestionsTests + { + /// + /// Tests the empty object. + /// + [TestMethod] + public void TestEmpty() + { + RenderingSuggestions renderingSuggestions = new RenderingSuggestions(); + Assert.IsFalse(renderingSuggestions.IgnoreCaseDiacriticsAndPunctuation); + Assert.IsNull(renderingSuggestions.NavigateToChapter); + } + } +} diff --git a/GoToBible.Tests.Model/TranslationTests.cs b/GoToBible.Tests.Model/TranslationTests.cs new file mode 100644 index 0000000..ab6a6c2 --- /dev/null +++ b/GoToBible.Tests.Model/TranslationTests.cs @@ -0,0 +1,85 @@ +// ----------------------------------------------------------------------- +// +// Copyright 2020-2021 Conglomo Limited. Please see LICENSE for license details. +// +// ----------------------------------------------------------------------- + +namespace GoToBible.Tests.Model +{ + using GoToBible.Model; + using Microsoft.VisualStudio.TestTools.UnitTesting; + + /// + /// Tests the class. + /// + [TestClass] + public class TranslationTests + { + /// + /// Tests the empty object. + /// + [TestMethod] + public void TestEmpty() + { + Translation translation = new Translation(); + Assert.IsNull(translation.Author); + Assert.IsFalse(translation.CanBeExported); + Assert.AreEqual(translation.Code, string.Empty); + Assert.IsFalse(translation.Commentary); + Assert.IsNull(translation.Copyright); + Assert.IsNull(translation.Dialect); + Assert.IsNull(translation.Language); + Assert.AreEqual(translation.Provider, string.Empty); + Assert.AreEqual(translation.Name, string.Empty); + Assert.AreEqual(translation.Year, 0); + Assert.AreEqual(translation.ToString(), string.Empty); + } + + /// + /// Tests the with a name specified. + /// + [TestMethod] + public void TestName() + { + Translation translation = new Translation + { + Name = "KJV", + }; + Assert.IsNull(translation.Author); + Assert.IsFalse(translation.CanBeExported); + Assert.AreEqual(translation.Code, string.Empty); + Assert.IsFalse(translation.Commentary); + Assert.IsNull(translation.Copyright); + Assert.IsNull(translation.Dialect); + Assert.IsNull(translation.Language); + Assert.AreEqual(translation.Provider, string.Empty); + Assert.AreEqual(translation.Name, "KJV"); + Assert.AreEqual(translation.Year, 0); + Assert.AreEqual(translation.ToString(), "KJV"); + } + + /// + /// Tests the with a name and language specified. + /// + [TestMethod] + public void TestNameAndLanguage() + { + Translation translation = new Translation + { + Language = "English", + Name = "KJV", + }; + Assert.IsNull(translation.Author); + Assert.IsFalse(translation.CanBeExported); + Assert.AreEqual(translation.Code, string.Empty); + Assert.IsFalse(translation.Commentary); + Assert.IsNull(translation.Copyright); + Assert.IsNull(translation.Dialect); + Assert.AreEqual(translation.Language, "English"); + Assert.AreEqual(translation.Provider, string.Empty); + Assert.AreEqual(translation.Name, "KJV"); + Assert.AreEqual(translation.Year, 0); + Assert.AreEqual(translation.ToString(), "English: KJV"); + } + } +} diff --git a/GoToBible.Tests.Model/stylecop.json b/GoToBible.Tests.Model/stylecop.json new file mode 100644 index 0000000..fea9768 --- /dev/null +++ b/GoToBible.Tests.Model/stylecop.json @@ -0,0 +1,19 @@ +{ + // ACTION REQUIRED: This file was automatically added to your project, but it + // will not take effect until additional steps are taken to enable it. See the + // following page for additional information: + // + // https://github.com/DotNetAnalyzers/StyleCopAnalyzers/blob/master/documentation/EnableConfiguration.md + + "$schema": "https://raw.githubusercontent.com/DotNetAnalyzers/StyleCopAnalyzers/master/StyleCop.Analyzers/StyleCop.Analyzers/Settings/stylecop.schema.json", + "settings": { + "documentationRules": { + "companyName": "Conglomo", + "copyrightText": "Copyright 2020-2021 Conglomo Limited. Please see LICENSE for license details.", + "documentationCulture": "en-GB" + }, + "layoutRules": { + "newlineAtEndOfFile": "require" + } + } +} diff --git a/GoToBible.sln b/GoToBible.sln index 630f2d0..714d104 100644 --- a/GoToBible.sln +++ b/GoToBible.sln @@ -18,9 +18,11 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "GoToBible.Windows.Designer", "GoToBible.Windows.Designer\GoToBible.Windows.Designer.csproj", "{B7449871-72A5-404D-B395-31D8EF6E7C0D}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "GoToBible.Web.Server", "GoToBible.Web\Server\GoToBible.Web.Server.csproj", "{9EF01BC7-C417-45F3-9AEF-D8262215C143}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "GoToBible.Web.Server", "GoToBible.Web\Server\GoToBible.Web.Server.csproj", "{9EF01BC7-C417-45F3-9AEF-D8262215C143}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "GoToBible.Web.Client", "GoToBible.Web\Client\GoToBible.Web.Client.csproj", "{11862BB6-D43F-4D21-B157-19CEC506AFDD}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "GoToBible.Web.Client", "GoToBible.Web\Client\GoToBible.Web.Client.csproj", "{11862BB6-D43F-4D21-B157-19CEC506AFDD}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "GoToBible.Tests.Model", "GoToBible.Tests.Model\GoToBible.Tests.Model.csproj", "{A87A4E40-B6A8-4C5A-A755-E212ABB855E6}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -54,6 +56,10 @@ Global {11862BB6-D43F-4D21-B157-19CEC506AFDD}.Debug|Any CPU.Build.0 = Debug|Any CPU {11862BB6-D43F-4D21-B157-19CEC506AFDD}.Release|Any CPU.ActiveCfg = Release|Any CPU {11862BB6-D43F-4D21-B157-19CEC506AFDD}.Release|Any CPU.Build.0 = Release|Any CPU + {A87A4E40-B6A8-4C5A-A755-E212ABB855E6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {A87A4E40-B6A8-4C5A-A755-E212ABB855E6}.Debug|Any CPU.Build.0 = Debug|Any CPU + {A87A4E40-B6A8-4C5A-A755-E212ABB855E6}.Release|Any CPU.ActiveCfg = Release|Any CPU + {A87A4E40-B6A8-4C5A-A755-E212ABB855E6}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE