diff --git a/Wave.Tests/Utilities/ArticleUtilitiesTest.cs b/Wave.Tests/Utilities/ArticleUtilitiesTest.cs new file mode 100644 index 0000000..081d7fe --- /dev/null +++ b/Wave.Tests/Utilities/ArticleUtilitiesTest.cs @@ -0,0 +1,35 @@ +using NUnit.Framework.Constraints; +using Wave.Data; +using Wave.Utilities; + +namespace Wave.Tests.Utilities; + +[TestFixture] +[TestOf(typeof(ArticleUtilities))] +public class ArticleUtilitiesTest { + + [Test] + public void GenerateArticleLink() { + var testArticle = new Article { + Id = Guid.Parse("e7a94905-d83a-4146-8061-de2ef7869a82"), + Title = "Test Article", + Body = "This is the body of the test Article", + Author = new ApplicationUser { + UserName = "test@example.com", + FullName = "Test User" + }, + PublishDate = DateTimeOffset.MaxValue, + Slug = "test-article" + }; + + string linkWithoutPublishDate = ArticleUtilities.GenerateArticleLink(testArticle, null); + Assert.That(linkWithoutPublishDate, Is.EqualTo("/article/e7a94905-d83a-4146-8061-de2ef7869a82")); + + testArticle.PublishDate = new DateTimeOffset(new DateOnly(2024, 4, 24), TimeOnly.MinValue, TimeSpan.Zero); + string linkWithPublishDate = ArticleUtilities.GenerateArticleLink(testArticle, null); + Assert.That(linkWithPublishDate, Is.EqualTo("/2024/04/24/test-article")); + + string testHttps = ArticleUtilities.GenerateArticleLink(testArticle, new Uri("http://example.com", UriKind.Absolute)); + Assert.That(testHttps, new StartsWithConstraint("https://")); + } +} \ No newline at end of file diff --git a/Wave.Tests/Wave.Tests.csproj b/Wave.Tests/Wave.Tests.csproj new file mode 100644 index 0000000..4e9adf0 --- /dev/null +++ b/Wave.Tests/Wave.Tests.csproj @@ -0,0 +1,32 @@ + + + + net8.0 + enable + enable + + false + true + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Wave.sln b/Wave.sln index f6aca46..92ec29f 100644 --- a/Wave.sln +++ b/Wave.sln @@ -7,6 +7,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Wave", "Wave\Wave.csproj", EndProject Project("{E53339B2-1760-4266-BCC7-CA923CBCF16C}") = "docker-compose", "docker-compose.dcproj", "{FE5DA24A-8490-4DCE-BDFB-49C9CF656F8A}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Wave.Tests", "Wave.Tests\Wave.Tests.csproj", "{54BFBF0E-5918-4830-BCDD-135BAD702529}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -21,6 +23,10 @@ Global {FE5DA24A-8490-4DCE-BDFB-49C9CF656F8A}.Debug|Any CPU.Build.0 = Debug|Any CPU {FE5DA24A-8490-4DCE-BDFB-49C9CF656F8A}.Release|Any CPU.ActiveCfg = Release|Any CPU {FE5DA24A-8490-4DCE-BDFB-49C9CF656F8A}.Release|Any CPU.Build.0 = Release|Any CPU + {54BFBF0E-5918-4830-BCDD-135BAD702529}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {54BFBF0E-5918-4830-BCDD-135BAD702529}.Debug|Any CPU.Build.0 = Debug|Any CPU + {54BFBF0E-5918-4830-BCDD-135BAD702529}.Release|Any CPU.ActiveCfg = Release|Any CPU + {54BFBF0E-5918-4830-BCDD-135BAD702529}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE