Skip to content

Commit

Permalink
Merge pull request #8 from felsokning/maintenance/IAsyncEnumerable_Ex…
Browse files Browse the repository at this point in the history
…tensions_Add

Reverting Pre-5.0 .NET changes. Updating README.md
  • Loading branch information
felsokning authored Mar 20, 2024
2 parents 338673f + 68e35a7 commit 6f0359b
Show file tree
Hide file tree
Showing 8 changed files with 50 additions and 55 deletions.
36 changes: 18 additions & 18 deletions Felsökning.Tests/DateTimeExtensionsTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,47 +13,47 @@ public class DateTimeExtensionsTests
[TestMethod]
public void IsWeekDay_ShouldReturn_True_Monday()
{
var sut = new DateTime(1954, 11, 08);
var sut = new DateTime(1954, 11, 08, 00, 00, 00, DateTimeKind.Utc);
var result = sut.IsWeekDay();
result.Should().BeTrue();
}

[TestMethod]
public void IsWeekDay_ShouldReturn_True_Tuesday()
{
var dateTime = new DateTime(2001, 09, 11);
var dateTime = new DateTime(2001, 09, 11, 00, 00, 00, DateTimeKind.Utc);
var result = dateTime.IsWeekDay();
result.Should().BeTrue();
}

[TestMethod]
public void IsWeekDay_ShouldReturn_True_Wednesday()
{
var dateTime = new DateTime(1358, 12, 13);
var dateTime = new DateTime(1358, 12, 13, 00, 00, 00, DateTimeKind.Utc);
var result = dateTime.IsWeekDay();
result.Should().BeTrue();
}

[TestMethod]
public void IsWeekDay_ShouldReturn_True_Thursday()
{
var dateTime = new DateTime(1776, 07, 04);
var dateTime = new DateTime(1776, 07, 04, 00, 00, 00, DateTimeKind.Utc);
var result = dateTime.IsWeekDay();
result.Should().BeTrue();
}

[TestMethod]
public void IsWeekDay_ShouldReturn_False_Saturday()
{
var dateTime = new DateTime(1523, 06, 16);
var dateTime = new DateTime(1523, 06, 16, 00, 00, 00, DateTimeKind.Utc);
var result = dateTime.IsWeekDay();
result.Should().BeFalse();
}

[TestMethod]
public void ToCulturedString_ShouldReturn_ExpectedValue()
{
var dateTime = new DateTime(2023, 01, 01);
var dateTime = new DateTime(2023, 01, 01, 00, 00, 00, DateTimeKind.Utc);
var result = dateTime.ToCulturedString("sv-se");
result.Should().NotBeNullOrWhiteSpace();
result.Should().Be("2023-01-01 00:00:00");
Expand All @@ -62,7 +62,7 @@ public void ToCulturedString_ShouldReturn_ExpectedValue()
[TestMethod]
public void ToIso8601UtcString_ShouldReturn_ExpectedValue()
{
var dateTime = new DateTime(1986, 01, 28, 16, 39, 13);
var dateTime = new DateTime(1986, 01, 28, 16, 39, 13, DateTimeKind.Utc);
var result = dateTime.ToIso8601UtcString();
result.Should().NotBeNullOrWhiteSpace();
result.Should().Be("1986-01-28T16:39:13.0000000Z");
Expand All @@ -71,7 +71,7 @@ public void ToIso8601UtcString_ShouldReturn_ExpectedValue()
[TestMethod]
public void ToPosixTime_ShouldReturn_ExpectedValue()
{
var dateTime = new DateTime(1975, 01, 28, 16, 39, 13);
var dateTime = new DateTime(1975, 01, 28, 16, 39, 13, DateTimeKind.Utc);
var result = dateTime.ToPosixTime();
result.Should().BeGreaterThan(0);
result.Should().Be(160159153);
Expand All @@ -80,7 +80,7 @@ public void ToPosixTime_ShouldReturn_ExpectedValue()
[TestMethod]
public void ToRfc1123String_ShouldReturn_ExpectedValue()
{
var dateTime = new DateTime(2022, 08, 29, 10, 01, 13);
var dateTime = new DateTime(2022, 08, 29, 10, 01, 13, DateTimeKind.Utc);

var result = dateTime.ToRfc1123String();

Expand All @@ -91,7 +91,7 @@ public void ToRfc1123String_ShouldReturn_ExpectedValue()
[TestMethod]
public void ToSwedishString_ShouldReturn_ExpectedValue()
{
var dateTime = new DateTime(1995, 12, 24, 23, 59, 59);
var dateTime = new DateTime(1995, 12, 24, 23, 59, 59, DateTimeKind.Utc);

var result = dateTime.ToSwedishString();

Expand All @@ -102,9 +102,9 @@ public void ToSwedishString_ShouldReturn_ExpectedValue()
[TestMethod]
public void ToUnixEpochTime_ShouldReturn_ExpectedValue()
{
var dateTime = new DateTime(2026, 02, 17, 10, 00, 00);
var dateTime = new DateTime(2026, 02, 17, 10, 00, 00, DateTimeKind.Utc);

var result = dateTime.ToUnixEpochTime();
var result = dateTime.ToPosixTime();

result.Should().BeGreaterThan(0);
result.Should().Be(1771322400);
Expand All @@ -113,7 +113,7 @@ public void ToUnixEpochTime_ShouldReturn_ExpectedValue()
[TestMethod]
public void ToWeekNumber_ShouldReturn_ExpectedValue()
{
var dateTime = new DateTime(2005, 06, 06);
var dateTime = new DateTime(2005, 06, 06, 00, 00, 00, DateTimeKind.Utc);

var result = dateTime.ToWeekNumber();

Expand All @@ -124,17 +124,17 @@ public void ToWeekNumber_ShouldReturn_ExpectedValue()
[TestMethod]
public void ValidateVeckan1990()
{
var dateTime = new DateTime(1990, 10, 10);
var dateTime = new DateTime(1990, 10, 10, 00, 00, 00, DateTimeKind.Utc);
var weekNumber = dateTime.ToWeekNumber();
Assert.IsNotNull(weekNumber);
Assert.IsFalse(weekNumber == 0);
Assert.AreEqual(weekNumber, 41);
Assert.AreEqual(41, weekNumber);
}

[TestMethod]
public void ValidateSwedishStringIsLocalised()
{
DateTime dateTime = new DateTime(2019, 01, 01);
DateTime dateTime = new DateTime(2019, 01, 01, 00, 00, 00, DateTimeKind.Utc);
string dateTimeString = dateTime.ToSwedishString();
Assert.IsTrue(Regex.IsMatch(dateTimeString, @"^[0-9][0-9][0-9][0-9]-[0-1][0-9]-[0-3][0-9] [0-2][0-9]:[0-6][0-9]:[0-5][0-9]$"));
}
Expand All @@ -145,7 +145,7 @@ public void ValidateSwedishStringIsLocalised()
[TestMethod]
public void ValidateFirstCulturedDateString()
{
DateTime now = new DateTime(1990, 12, 25, 14, 30, 55);
DateTime now = new DateTime(1990, 12, 25, 14, 30, 55, DateTimeKind.Utc);
string culturedString = now.ToCulturedString("cs-CZ");
Assert.IsTrue(Regex.IsMatch(culturedString, @"^[0-9][0-9].[0-1][0-9].[1-2][0-9][0-9][0-9] [0-2][0-9]:[0-6][0-9]:[0-5][0-9]$"));
}
Expand All @@ -156,7 +156,7 @@ public void ValidateFirstCulturedDateString()
[TestMethod]
public void ValidateThirdCulturedDateString()
{
DateTime now = new DateTime(1990, 12, 25, 14, 30, 55);
DateTime now = new DateTime(1990, 12, 25, 14, 30, 55, DateTimeKind.Utc);
string culturedString = now.ToCulturedString("pt-BR");
Assert.IsTrue(Regex.IsMatch(culturedString, @"^[0-9][0-9]/[0-1][0-9]/[1-2][0-9][0-9][0-9] [0-2][0-9]:[0-6][0-9]:[0-5][0-9]$"));
}
Expand Down
6 changes: 2 additions & 4 deletions Felsökning/AggregateExceptionExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,8 @@ public static class AggregateExceptionExtensions
/// <returns>A string array of relevant data.</returns>
public static string[] Unbox(this AggregateException aggregateException)
{
using (AggregateInternals internals = new())
{
return internals.DelveInternally(exception: aggregateException);
}
using AggregateInternals internals = new();
return internals.DelveInternally(exception: aggregateException);
}
}
}
21 changes: 4 additions & 17 deletions Felsökning/DateTimeExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ public static class DateTimeExtensions
public static bool IsWeekDay(this DateTime dateTime)
{
return dateTime.DayOfWeek == DayOfWeek.Monday
| dateTime.DayOfWeek == DayOfWeek.Tuesday
| dateTime.DayOfWeek == DayOfWeek.Wednesday
| dateTime.DayOfWeek == DayOfWeek.Thursday
| dateTime.DayOfWeek == DayOfWeek.Friday;
|| dateTime.DayOfWeek == DayOfWeek.Tuesday
|| dateTime.DayOfWeek == DayOfWeek.Wednesday
|| dateTime.DayOfWeek == DayOfWeek.Thursday
|| dateTime.DayOfWeek == DayOfWeek.Friday;
}

/// <summary>
Expand Down Expand Up @@ -83,19 +83,6 @@ public static string ToSwedishString(this DateTime dateTime)
return dateTime.ToString(svSe);
}

/// <summary>
/// Extends the <see cref="DateTime"/> object to return a Unix Epoch time structure.
/// </summary>
/// <param name="dateTime">The current <see cref="DateTime"/> object in question.</param>
/// <returns>A long representing the Unix Epoc time.</returns>
public static long ToUnixEpochTime(this DateTime dateTime)
{
DateTime whenDinosaursRoamedTheEarth = DateTime.UnixEpoch;
long currentDateTimeTicks = dateTime.Ticks;
long whenDinosaursRoamedTheEarthTicks = whenDinosaursRoamedTheEarth.Ticks;
return (currentDateTimeTicks - whenDinosaursRoamedTheEarthTicks) / 10000000;
}

/// <summary>
/// Extends the <see cref="DateTime"/> object to include a method to return the week number.
/// </summary>
Expand Down
6 changes: 2 additions & 4 deletions Felsökning/Felsökning.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<PropertyGroup>
<TargetFrameworks>net5.0;net6.0;net7.0;net8.0;</TargetFrameworks>
<ImplicitUsings>enable</ImplicitUsings>
<LangVersion>10.0</LangVersion>
<LangVersion>11.0</LangVersion>
<Nullable>enable</Nullable>
<GenerateDocumentationFile>True</GenerateDocumentationFile>
<GeneratePackageOnBuild>false</GeneratePackageOnBuild>
Expand All @@ -28,6 +28,4 @@
<ItemGroup>
<PackageReference Include="System.IO.Abstractions" Version="20.0.15" />
</ItemGroup>
</Project>


</Project>
2 changes: 2 additions & 0 deletions Felsökning/StatusException.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,11 @@ namespace Felsökning
/// Initializes a new instance of the <see cref="StatusException"/> class.
/// </summary>
/// <inheritdoc cref="Exception"/>
#pragma warning disable S3925 // Superceded by SYSLIB0051 - See https://github.com/dotnet/docs/issues/34893
[Serializable]
public class StatusException : Exception
{
#pragma warning restore S3925
/// <summary>
/// Gets or sets the <see cref="Felsökning.HttpRecord"/> value associated with the failure.
/// </summary>
Expand Down
2 changes: 2 additions & 0 deletions Felsökning/Usings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
global using System.Runtime.Versioning;
global using System.Security.Authentication;
global using System.Text;
#if NET5_0_OR_GREATER
global using System.Text.Json;
global using System.Text.Json.Serialization;
#endif
global using System.Text.RegularExpressions;
32 changes: 20 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,20 +1,28 @@
<img src="./images/bmc_qr.png" width=10% height=10% alt="Buy Me a Coffee!"> &larr; If you would like to buy me a coffee

# Introduction
TODO: Give a short introduction of your project. Let this section explain the objectives or the motivation behind this project.
The [`Felsökning` NuGet assembly](https://www.nuget.org/packages/Fels%C3%B6kning) contains many of the "_fire-and-forget_" methods (and exension methods) used by the rest of the Felsökning NuGet packages, where applicable.

# Getting Started
TODO: Guide users through getting your code up and running on their own system. In this section you can talk about:
1. Installation process
2. Software dependencies
3. Latest releases
4. API references
1. Clone the repository: `git clone https://github.com/felsokning/Fels-kning.git`
2. cd into the folder: `cd Fels-kning`
3. Profit

# Build and Test
TODO: Describe and show how to build your code and run the tests.
From the `Fels-kning` folder:

1. To build:
1. `dotnet restore --verbosity=normal`
2. `dotnet build --verbosity=normal`
2. To Test:
1. `dotnet test --verbosity=normal`


# Contribute
TODO: Explain how other users and developers can contribute to make your code better.
PR's are more than welcome! 😊

If you want to learn more about creating good readme files then refer the following [guidelines](https://docs.microsoft.com/en-us/azure/devops/repos/git/create-a-readme?view=azure-devops). You can also seek inspiration from the below readme files:
- [ASP.NET Core](https://github.com/aspnet/Home)
- [Visual Studio Code](https://github.com/Microsoft/vscode)
- [Chakra Core](https://github.com/Microsoft/ChakraCore)
--------------------------------------------
--------------------------------------------
--------------------------------------------
--------------------------------------------
--------------------------------------------
Binary file added images/bmc_qr.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 6f0359b

Please sign in to comment.