From b350abaa9d6f8a989238eda6a4379e72c382df28 Mon Sep 17 00:00:00 2001 From: Anders Bjerner Date: Sun, 21 Apr 2024 11:42:30 +0200 Subject: [PATCH] Added additional unit tests --- src/TestProject1/Security/Md5Tests.cs | 31 +++++++++++++++++ src/TestProject1/Strings/JoinTests.cs | 34 +++++++++++++++++++ src/TestProject1/Time/EssentialsMonthTests.cs | 17 ++++++++++ src/TestProject1/Time/EssentialsWeekTests.cs | 17 ++++++++++ .../Time/Time/EssentialsTimeTests.cs | 12 ++++--- .../Time/Time/EssentialsWeekTests.cs | 2 +- 6 files changed, 108 insertions(+), 5 deletions(-) create mode 100644 src/TestProject1/Security/Md5Tests.cs create mode 100644 src/TestProject1/Strings/JoinTests.cs create mode 100644 src/TestProject1/Time/EssentialsMonthTests.cs create mode 100644 src/TestProject1/Time/EssentialsWeekTests.cs diff --git a/src/TestProject1/Security/Md5Tests.cs b/src/TestProject1/Security/Md5Tests.cs new file mode 100644 index 0000000..afd102a --- /dev/null +++ b/src/TestProject1/Security/Md5Tests.cs @@ -0,0 +1,31 @@ +using System.Text; +using Skybrud.Essentials.Security; +using Skybrud.Essentials.Strings; + +namespace TestProject1.Security; + +[TestClass] +public class Md5Tests { + + [TestMethod] + public void GetMd5Hash() { + + string a = SecurityUtils.GetMd5Hash("Hello there!"); + string b = SecurityUtils.GetMd5Hash("Hello there!", HexFormat.LowerCase); + string c = SecurityUtils.GetMd5Hash("Hello there!", HexFormat.UpperCase); + + string d = SecurityUtils.GetMd5Hash("Hello there!", Encoding.UTF8); + string e = SecurityUtils.GetMd5Hash("Hello there!", HexFormat.LowerCase, Encoding.UTF8); + string f = SecurityUtils.GetMd5Hash("Hello there!", HexFormat.UpperCase, Encoding.UTF8); + + Assert.AreEqual("a77b55332699835c035957df17630d28", a, "#a"); + Assert.AreEqual("a77b55332699835c035957df17630d28", b, "#b"); + Assert.AreEqual("A77B55332699835C035957DF17630D28", c, "#c"); + + Assert.AreEqual("a77b55332699835c035957df17630d28", d, "#d"); + Assert.AreEqual("a77b55332699835c035957df17630d28", e, "#e"); + Assert.AreEqual("A77B55332699835C035957DF17630D28", f, "#f"); + + } + +} \ No newline at end of file diff --git a/src/TestProject1/Strings/JoinTests.cs b/src/TestProject1/Strings/JoinTests.cs new file mode 100644 index 0000000..f64c1aa --- /dev/null +++ b/src/TestProject1/Strings/JoinTests.cs @@ -0,0 +1,34 @@ +using Skybrud.Essentials.Strings.Extensions; + +namespace TestProject1.Strings; + +[TestClass] +public class JoinTests { + + [TestMethod] + public void JoinT() { + + string[] array = { "hello", "world" }; + + Assert.AreEqual("hello,world", array.Join(',')); + Assert.AreEqual("hello,world", array.Join(",")); + + Assert.AreEqual("hello,world", array.Join(',')); + Assert.AreEqual("hello,world", array.Join(",")); + + } + + [TestMethod] + public void JoinObject() { + + object[] array = { "hello", "world" }; + + Assert.AreEqual("hello,world", array.Join(',')); + Assert.AreEqual("hello,world", array.Join(",")); + + Assert.AreEqual("hello,world", array.Join(',')); + Assert.AreEqual("hello,world", array.Join(",")); + + } + +} \ No newline at end of file diff --git a/src/TestProject1/Time/EssentialsMonthTests.cs b/src/TestProject1/Time/EssentialsMonthTests.cs new file mode 100644 index 0000000..9711980 --- /dev/null +++ b/src/TestProject1/Time/EssentialsMonthTests.cs @@ -0,0 +1,17 @@ +using Skybrud.Essentials.Time; + +namespace TestProject1.Time; + +[TestClass] +public class EssentialsMonthTests { + + [TestMethod] + public void ToStringDefault() { + + EssentialsMonth month = new(2024, 3); + + Assert.AreEqual("2024-03", month.ToString()); + + } + +} \ No newline at end of file diff --git a/src/TestProject1/Time/EssentialsWeekTests.cs b/src/TestProject1/Time/EssentialsWeekTests.cs new file mode 100644 index 0000000..b695c4e --- /dev/null +++ b/src/TestProject1/Time/EssentialsWeekTests.cs @@ -0,0 +1,17 @@ +using Skybrud.Essentials.Time; + +namespace TestProject1.Time; + +[TestClass] +public class EssentialsWeekTests { + + [TestMethod] + public void ToStringDefault() { + + EssentialsWeek week = new(2024, 13); + + Assert.AreEqual("2024-W13", week.ToString()); + + } + +} \ No newline at end of file diff --git a/src/UnitTestProject1/Time/Time/EssentialsTimeTests.cs b/src/UnitTestProject1/Time/Time/EssentialsTimeTests.cs index 14c0d9e..83b9886 100644 --- a/src/UnitTestProject1/Time/Time/EssentialsTimeTests.cs +++ b/src/UnitTestProject1/Time/Time/EssentialsTimeTests.cs @@ -501,12 +501,14 @@ public void FromTicksLocalUtc() { using (new CultureDisposable(InvariantCulture)) { string actual = time.ToString(); - Assert.AreEqual("2022-03-07T17:50:23.123+01:00", actual, "#1"); + Assert.AreEqual("2022-03-07T17:50:23.123+01:00", actual, "#1a"); + Assert.AreEqual("2022-03-07T17:50:23.123+01:00", $"{time}", "#1b"); } using (new CultureDisposable(DanishCulture)) { string actual = time.ToString(); - Assert.AreEqual("2022-03-07T17:50:23.123+01:00", actual, "#2"); + Assert.AreEqual("2022-03-07T17:50:23.123+01:00", actual, "#2a"); + Assert.AreEqual("2022-03-07T17:50:23.123+01:00", $"{time}", "#2b"); } } @@ -521,12 +523,14 @@ public void ToStringFormat() { using (new CultureDisposable(InvariantCulture)) { string actual = time.ToString("F"); - Assert.AreEqual("Monday, 07 March 2022 17:50:23", actual, "#1"); + Assert.AreEqual("Monday, 07 March 2022 17:50:23", actual, "#1a"); + Assert.AreEqual("Monday, 07 March 2022 17:50:23", $"{time:F}", "#1b"); } using (new CultureDisposable(DanishCulture)) { string actual = time.ToString("F"); - Assert.AreEqual("Monday, 07 March 2022 17:50:23", actual, "#2"); + Assert.AreEqual("Monday, 07 March 2022 17:50:23", actual, "#2a"); + Assert.AreEqual("7. marts 2022 17:50:23", $"{time:F}", "#2b"); } diff --git a/src/UnitTestProject1/Time/Time/EssentialsWeekTests.cs b/src/UnitTestProject1/Time/Time/EssentialsWeekTests.cs index b5ef6ef..257e99b 100644 --- a/src/UnitTestProject1/Time/Time/EssentialsWeekTests.cs +++ b/src/UnitTestProject1/Time/Time/EssentialsWeekTests.cs @@ -411,7 +411,7 @@ public void GetStartOfWeekFromDate() { TimeZoneInfo greenland = TimeZoneInfo.FindSystemTimeZoneById("Greenland Standard Time"); EssentialsDate date1 = new EssentialsDate(2022, 3, 24); // Thursday - EssentialsDate date2 = new EssentialsDate(2022, 3, 27); // Thursday + EssentialsDate date2 = new EssentialsDate(2022, 3, 27); // Sunday EssentialsDate date3 = new EssentialsDate(2022, 10, 30); // Sunday EssentialsDate date4 = new EssentialsDate(2022, 11, 9); // Wednesday