Skip to content

Commit

Permalink
Added additional unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
abjerner committed Apr 21, 2024
1 parent 85316d9 commit b350aba
Show file tree
Hide file tree
Showing 6 changed files with 108 additions and 5 deletions.
31 changes: 31 additions & 0 deletions src/TestProject1/Security/Md5Tests.cs
Original file line number Diff line number Diff line change
@@ -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");

}

}
34 changes: 34 additions & 0 deletions src/TestProject1/Strings/JoinTests.cs
Original file line number Diff line number Diff line change
@@ -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(","));

}

}
17 changes: 17 additions & 0 deletions src/TestProject1/Time/EssentialsMonthTests.cs
Original file line number Diff line number Diff line change
@@ -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());

}

}
17 changes: 17 additions & 0 deletions src/TestProject1/Time/EssentialsWeekTests.cs
Original file line number Diff line number Diff line change
@@ -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());

}

}
12 changes: 8 additions & 4 deletions src/UnitTestProject1/Time/Time/EssentialsTimeTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}

}
Expand All @@ -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");
}


Expand Down
2 changes: 1 addition & 1 deletion src/UnitTestProject1/Time/Time/EssentialsWeekTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit b350aba

Please sign in to comment.