Skip to content

Commit

Permalink
Merge branch 'main' into release
Browse files Browse the repository at this point in the history
  • Loading branch information
MrMatthewLayton committed Jan 5, 2025
2 parents 098fd1e + 10d86b4 commit b928596
Show file tree
Hide file tree
Showing 31 changed files with 374 additions and 117 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/dotnet.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ jobs:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
- name: Setup .NET
uses: actions/setup-dotnet@v1
uses: actions/setup-dotnet@v4
with:
dotnet-version: 9.0.x
global-json-file: global.json
- name: Restore dependencies
run: dotnet restore
- name: Build
Expand Down
8 changes: 4 additions & 4 deletions Directory.Build.props
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
<Project>
<PropertyGroup>
<TargetFramework>net9.0</TargetFramework>
<TargetFrameworks>net8.0;net9.0</TargetFrameworks>
<LangVersion>13</LangVersion>
<Nullable>enable</Nullable>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<Authors>ONIXLabs</Authors>
<NeutralLanguage>en</NeutralLanguage>
<Copyright>Copyright © ONIXLabs 2020</Copyright>
<RepositoryUrl>https://github.com/onix-labs/onixlabs-dotnet</RepositoryUrl>
<Version>11.0.0</Version>
<PackageVersion>11.0.0</PackageVersion>
<AssemblyVersion>11.0.0</AssemblyVersion>
<Version>11.1.0</Version>
<PackageVersion>11.1.0</PackageVersion>
<AssemblyVersion>11.1.0</AssemblyVersion>
</PropertyGroup>
</Project>
30 changes: 30 additions & 0 deletions OnixLabs.Core.UnitTests/ObjectExtensionTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
// limitations under the License.

using System;
using System.Threading.Tasks;
using OnixLabs.Core.UnitTests.Data;
using Xunit;

Expand Down Expand Up @@ -223,4 +224,33 @@ public void ToStringOrNullShouldProduceExpectedResultWhenObjectIsNotNull()
// Then
Assert.Equal(expected, actual);
}

[Fact(DisplayName = "ToSuccessResult should produce the expected result")]
public void ToSuccessResultShouldProduceTheExpectedResult()
{
// Given
const string expected = "abc";

// When
Result<string> result = expected.ToSuccessResult();

// Then
Success<string> success = Assert.IsType<Success<string>>(result);
Assert.Equal(expected, success.Value);
}

[Fact(DisplayName = "ToSuccessResultAsync should produce the expected result")]
public async Task ToSuccessResultAsyncShouldProduceTheExpectedResult()
{
// Given
const string expected = "abc";

// When
Task<string> task = Task.FromResult(expected);
Result<string> result = await task.ToSuccessResultAsync();

// Then
Success<string> success = Assert.IsType<Success<string>>(result);
Assert.Equal(expected, success.Value);
}
}
2 changes: 1 addition & 1 deletion OnixLabs.Core.UnitTests/OptionalEqualityComparerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ public void OptionalEqualityComparerEqualsShouldReturnFalseWhenComparingNonIdent
public void OptionalEqualityComparerGetHashCodeShouldReturnZeroWhenOptionalValueIsNone()
{
// Given
const int expected = default;
const int expected = 0;
Optional<string> optional = Optional<string>.None;
OptionalEqualityComparer<string> comparer = new();

Expand Down
14 changes: 7 additions & 7 deletions OnixLabs.Core.UnitTests/OptionalTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ public void OptionalNoneShouldProduceExpectedResult()
public void OptionalOfShouldProduceExpectedResultForImplicitDefaultValues()
{
// Given / When
Optional<int> number = Optional<int>.Of(default);
Optional<string> text = Optional<string>.Of(default);
Optional<int> number = Optional<int>.Of(0);
Optional<string> text = Optional<string>.Of(null);

// Then
Assert.True(Optional<int>.IsNone(number));
Expand Down Expand Up @@ -100,7 +100,7 @@ public void OptionalOfShouldProduceExpectedResultForNullNullableStructValues()
{
// Given / When
Optional<int> number = Optional<int>.Of((int?)null);
Optional<Guid> identifier = Optional<Guid>.Of((Guid?)default);
Optional<Guid> identifier = Optional<Guid>.Of((Guid?)null);

// Then
Assert.False(number.HasValue);
Expand Down Expand Up @@ -171,7 +171,7 @@ public void OptionalImplicitOperatorShouldProduceExpectedSomeResult()
public void OptionalImplicitOperatorShouldProduceExpectedNoneResult()
{
// Given / When
const string? value = default;
const string? value = null;
Optional<string> optional = value;

// Then
Expand Down Expand Up @@ -297,7 +297,7 @@ public void OptionalSomeGetHashCodeShouldProduceExpectedResult()
public void OptionalNoneGetHashCodeShouldProduceExpectedResult()
{
// Given
const int expected = default;
const int expected = 0;
Optional<int> optional = Optional<int>.None;

// When
Expand Down Expand Up @@ -335,8 +335,8 @@ public void OptionalNoneGetValueOrDefaultShouldProduceExpectedResult()
string? actualText = text.GetValueOrDefault();

// Then
Assert.Equal(default, actualNumber);
Assert.Equal(default, actualText);
Assert.Equal(0, actualNumber);
Assert.Equal(null, actualText);

Check warning on line 339 in OnixLabs.Core.UnitTests/OptionalTests.cs

View workflow job for this annotation

GitHub Actions / build

Do not use Assert.Equal() to check for null value. Use Assert.Null instead. (https://xunit.net/xunit.analyzers/rules/xUnit2003)

Check warning on line 339 in OnixLabs.Core.UnitTests/OptionalTests.cs

View workflow job for this annotation

GitHub Actions / build

Do not use Assert.Equal() to check for null value. Use Assert.Null instead. (https://xunit.net/xunit.analyzers/rules/xUnit2003)

Check warning on line 339 in OnixLabs.Core.UnitTests/OptionalTests.cs

View workflow job for this annotation

GitHub Actions / build

Do not use Assert.Equal() to check for null value. Use Assert.Null instead. (https://xunit.net/xunit.analyzers/rules/xUnit2003)

Check warning on line 339 in OnixLabs.Core.UnitTests/OptionalTests.cs

View workflow job for this annotation

GitHub Actions / build

Do not use Assert.Equal() to check for null value. Use Assert.Null instead. (https://xunit.net/xunit.analyzers/rules/xUnit2003)
}

[Fact(DisplayName = "Optional Some.GetValueOrDefault with default value should produce the expected result.")]
Expand Down
8 changes: 4 additions & 4 deletions OnixLabs.Core.UnitTests/PreconditionTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -217,13 +217,13 @@ public void CheckNotNullOfValueTypeShouldThrowInvalidOperationExceptionWhenCondi
{
// Given
int? expected = null;
int actual = default;
int actual = 0;

// When
Exception exception = Assert.Throws<InvalidOperationException>(() => actual = CheckNotNull(expected));

// Then
Assert.Equal(default, actual);
Assert.Equal(0, actual);
Assert.Equal("Argument must not be null.", exception.Message);
}

Expand Down Expand Up @@ -593,13 +593,13 @@ public void RequireNotNullOfValueTypeShouldThrowInvalidOperationExceptionWhenCon
{
// Given
int? expected = null;
int actual = default;
int actual = 0;

// When
Exception exception = Assert.Throws<ArgumentNullException>(() => actual = RequireNotNull(expected));

// Then
Assert.Equal(default, actual);
Assert.Equal(0, actual);
Assert.Equal("Argument must not be null.", exception.Message);
}

Expand Down
6 changes: 3 additions & 3 deletions OnixLabs.Core.UnitTests/ResultExtensionTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ public async Task ResultGetValueOrDefaultAsyncShouldReturnDefaultWhenResultIsFai
string? actualText = await textTask.GetValueOrDefaultAsync();

// Then
Assert.Equal(default, actualNumber);
Assert.Equal(0, actualNumber);
Assert.Null(actualText);
}

Expand Down Expand Up @@ -364,8 +364,8 @@ public async Task ResultGetValueOrNoneAsyncShouldReturnOptionalValueWhenResultIs
public async Task ResultGetValueOrNoneAsyncShouldReturnNoneWhenResultIsSuccessAndValueIsNone()
{
// Given
Result<int> numberResult = Result<int>.Success(default);
Result<string> textResult = Result<string>.Success(default!);
Result<int> numberResult = Result<int>.Success(0);
Result<string> textResult = Result<string>.Success(null!);

// When
Optional<int> actualNumber = await Task.FromResult(numberResult).GetValueOrNoneAsync();
Expand Down
Loading

0 comments on commit b928596

Please sign in to comment.