Skip to content

Commit

Permalink
feat: Created factory Success.Create();
Browse files Browse the repository at this point in the history
  • Loading branch information
NelsonBN committed Mar 9, 2023
1 parent fd6c30e commit 44e6145
Show file tree
Hide file tree
Showing 9 changed files with 80 additions and 37 deletions.
7 changes: 5 additions & 2 deletions src/Types.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,11 @@
public interface IType { }

#if NET6_0_OR_GREATER
public readonly record struct Success : IType;
public readonly record struct Success : IType
#else
public readonly struct Success : IType { }
public readonly struct Success : IType
#endif
{
public static Success Create() => new();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ namespace PowerUtils.Results.Tests.Errors.ConflictErrors
public class DifferentsEqualityOperatorsTests
{
[Fact]
public void LeftNullRightNull_Equals_False()
public void LeftNullRightNull_Differents_False()
{
// Arrange
ConflictError? left = null;
Expand All @@ -22,7 +22,7 @@ public void LeftNullRightNull_Equals_False()
}

[Fact]
public void LeftNotNullRightNull_Equals_True()
public void LeftNotNullRightNull_Differents_True()
{
// Arrange
ConflictError? left = Error.Conflict("fake", "fake", "fake");
Expand All @@ -38,7 +38,7 @@ public void LeftNotNullRightNull_Equals_True()
}

[Fact]
public void LeftNullRightNotNull_Equals_True()
public void LeftNullRightNotNull_Differents_True()
{
// Arrange
ConflictError? left = null;
Expand All @@ -54,7 +54,7 @@ public void LeftNullRightNotNull_Equals_True()
}

[Fact]
public void BothDifferents_Equals_True()
public void BothDifferents_Differents_True()
{
// Arrange
ConflictError? left = Error.Conflict("fake1", "fake", "fake");
Expand All @@ -70,7 +70,7 @@ public void BothDifferents_Equals_True()
}

[Fact]
public void BothEquals_Equals_False()
public void BothEquals_Differents_False()
{
// Arrange
ConflictError? left = Error.Conflict("fake", "fake", "fake");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ namespace PowerUtils.Results.Tests.Errors.ForbiddenErrors
public class DifferentsEqualityOperatorsTests
{
[Fact]
public void LeftNullRightNull_Equals_False()
public void LeftNullRightNull_Differents_False()
{
// Arrange
ForbiddenError? left = null;
Expand All @@ -22,7 +22,7 @@ public void LeftNullRightNull_Equals_False()
}

[Fact]
public void LeftNotNullRightNull_Equals_True()
public void LeftNotNullRightNull_Differents_True()
{
// Arrange
ForbiddenError? left = Error.Forbidden("fake", "fake", "fake");
Expand All @@ -38,7 +38,7 @@ public void LeftNotNullRightNull_Equals_True()
}

[Fact]
public void LeftNullRightNotNull_Equals_True()
public void LeftNullRightNotNull_Differents_True()
{
// Arrange
ForbiddenError? left = null;
Expand All @@ -54,7 +54,7 @@ public void LeftNullRightNotNull_Equals_True()
}

[Fact]
public void BothDifferents_Equals_True()
public void BothDifferents_Differents_True()
{
// Arrange
ForbiddenError? left = Error.Forbidden("fake1", "fake", "fake");
Expand All @@ -70,7 +70,7 @@ public void BothDifferents_Equals_True()
}

[Fact]
public void BothEquals_Equals_False()
public void BothEquals_Differents_False()
{
// Arrange
ForbiddenError? left = Error.Forbidden("fake", "fake", "fake");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ namespace PowerUtils.Results.Tests.Errors.GenericErrors
public class DifferentsEqualityOperatorsTests
{
[Fact]
public void LeftNullRightNull_Equals_False()
public void LeftNullRightNull_Differents_False()
{
// Arrange
Error? left = null;
Expand All @@ -22,7 +22,7 @@ public void LeftNullRightNull_Equals_False()
}

[Fact]
public void LeftNotNullRightNull_Equals_True()
public void LeftNotNullRightNull_Differents_True()
{
// Arrange
Error? left = Error.Failure("fake", "fake", "fake");
Expand All @@ -38,7 +38,7 @@ public void LeftNotNullRightNull_Equals_True()
}

[Fact]
public void LeftNullRightNotNull_Equals_True()
public void LeftNullRightNotNull_Differents_True()
{
// Arrange
Error? left = null;
Expand All @@ -54,7 +54,7 @@ public void LeftNullRightNotNull_Equals_True()
}

[Fact]
public void BothDifferents_Equals_True()
public void BothDifferents_Differents_True()
{
// Arrange
Error? left = Error.Failure("fake1", "fake", "fake");
Expand All @@ -70,7 +70,7 @@ public void BothDifferents_Equals_True()
}

[Fact]
public void BothEquals_Equals_False()
public void BothEquals_Differents_False()
{
// Arrange
Error? left = Error.Failure("fake", "fake", "fake");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ namespace PowerUtils.Results.Tests.Errors.NotFoundErrors
public class DifferentsEqualityOperatorsTests
{
[Fact]
public void LeftNullRightNull_Equals_False()
public void LeftNullRightNull_Differents_False()
{
// Arrange
NotFoundError? left = null;
Expand All @@ -22,7 +22,7 @@ public void LeftNullRightNull_Equals_False()
}

[Fact]
public void LeftNotNullRightNull_Equals_True()
public void LeftNotNullRightNull_Differents_True()
{
// Arrange
NotFoundError? left = Error.NotFound("fake", "fake", "fake");
Expand All @@ -38,7 +38,7 @@ public void LeftNotNullRightNull_Equals_True()
}

[Fact]
public void LeftNullRightNotNull_Equals_True()
public void LeftNullRightNotNull_Differents_True()
{
// Arrange
NotFoundError? left = null;
Expand All @@ -54,7 +54,7 @@ public void LeftNullRightNotNull_Equals_True()
}

[Fact]
public void BothDifferents_Equals_True()
public void BothDifferents_Differents_True()
{
// Arrange
NotFoundError? left = Error.NotFound("fake1", "fake", "fake");
Expand All @@ -70,7 +70,7 @@ public void BothDifferents_Equals_True()
}

[Fact]
public void BothEquals_Equals_False()
public void BothEquals_Differents_False()
{
// Arrange
NotFoundError? left = Error.NotFound("fake", "fake", "fake");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ namespace PowerUtils.Results.Tests.Errors.UnauthorizedErrors
public class DifferentsEqualityOperatorsTests
{
[Fact]
public void LeftNullRightNull_Equals_False()
public void LeftNullRightNull_Differents_False()
{
// Arrange
UnauthorizedError? left = null;
Expand All @@ -22,7 +22,7 @@ public void LeftNullRightNull_Equals_False()
}

[Fact]
public void LeftNotNullRightNull_Equals_True()
public void LeftNotNullRightNull_Differents_True()
{
// Arrange
UnauthorizedError? left = Error.Unauthorized("fake", "fake", "fake");
Expand All @@ -38,7 +38,7 @@ public void LeftNotNullRightNull_Equals_True()
}

[Fact]
public void LeftNullRightNotNull_Equals_True()
public void LeftNullRightNotNull_Differents_True()
{
// Arrange
UnauthorizedError? left = null;
Expand All @@ -54,7 +54,7 @@ public void LeftNullRightNotNull_Equals_True()
}

[Fact]
public void BothDifferents_Equals_True()
public void BothDifferents_Differents_True()
{
// Arrange
UnauthorizedError? left = Error.Unauthorized("fake1", "fake", "fake");
Expand All @@ -70,7 +70,7 @@ public void BothDifferents_Equals_True()
}

[Fact]
public void BothEquals_Equals_False()
public void BothEquals_Differents_False()
{
// Arrange
UnauthorizedError? left = Error.Unauthorized("fake", "fake", "fake");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ namespace PowerUtils.Results.Tests.Errors.UnexpectedErrors
public class DifferentsEqualityOperatorsTests
{
[Fact]
public void LeftNullRightNull_Equals_False()
public void LeftNullRightNull_Differents_False()
{
// Arrange
UnexpectedError? left = null;
Expand All @@ -22,7 +22,7 @@ public void LeftNullRightNull_Equals_False()
}

[Fact]
public void LeftNotNullRightNull_Equals_True()
public void LeftNotNullRightNull_Differents_True()
{
// Arrange
UnexpectedError? left = Error.Unexpected("fake", "fake", "fake");
Expand All @@ -38,7 +38,7 @@ public void LeftNotNullRightNull_Equals_True()
}

[Fact]
public void LeftNullRightNotNull_Equals_True()
public void LeftNullRightNotNull_Differents_True()
{
// Arrange
UnexpectedError? left = null;
Expand All @@ -54,7 +54,7 @@ public void LeftNullRightNotNull_Equals_True()
}

[Fact]
public void BothDifferents_Equals_True()
public void BothDifferents_Differents_True()
{
// Arrange
UnexpectedError? left = Error.Unexpected("fake1", "fake", "fake");
Expand All @@ -70,7 +70,7 @@ public void BothDifferents_Equals_True()
}

[Fact]
public void BothEquals_Equals_False()
public void BothEquals_Differents_False()
{
// Arrange
UnexpectedError? left = Error.Unexpected("fake", "fake", "fake");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ namespace PowerUtils.Results.Tests.Errors.ValidationErrors
public class DifferentsEqualityOperatorsTests
{
[Fact]
public void LeftNullRightNull_Equals_False()
public void LeftNullRightNull_Differents_False()
{
// Arrange
ValidationError? left = null;
Expand All @@ -22,7 +22,7 @@ public void LeftNullRightNull_Equals_False()
}

[Fact]
public void LeftNotNullRightNull_Equals_True()
public void LeftNotNullRightNull_Differents_True()
{
// Arrange
ValidationError? left = Error.Validation("fake", "fake", "fake");
Expand All @@ -38,7 +38,7 @@ public void LeftNotNullRightNull_Equals_True()
}

[Fact]
public void LeftNullRightNotNull_Equals_True()
public void LeftNullRightNotNull_Differents_True()
{
// Arrange
ValidationError? left = null;
Expand All @@ -54,7 +54,7 @@ public void LeftNullRightNotNull_Equals_True()
}

[Fact]
public void BothDifferents_Equals_True()
public void BothDifferents_Differents_True()
{
// Arrange
ValidationError? left = Error.Validation("fake1", "fake", "fake");
Expand All @@ -70,7 +70,7 @@ public void BothDifferents_Equals_True()
}

[Fact]
public void BothEquals_Equals_False()
public void BothEquals_Differents_False()
{
// Arrange
ValidationError? left = Error.Validation("fake", "fake", "fake");
Expand Down
40 changes: 40 additions & 0 deletions tests/PowerUtils.Results.Tests/Types/SuccessTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
using FluentAssertions;
using Xunit;

namespace PowerUtils.Results.Tests.Types
{
public class SuccessTests
{
[Fact]
public void TwoDifferentsSuccess_MethodEquals_True()
{
// Arrange
var left = Success.Create();
var right = new Success();


// Act
var act = left.Equals(right);


// Assert
act.Should().BeTrue();
}

[Fact]
public void TwoDifferentsSuccess_GetHashCode_True()
{
// Arrange
var left = new Success();
var right = Success.Create();


// Act
var act = left.GetHashCode() == right.GetHashCode();


// Assert
act.Should().BeTrue();
}
}
}

0 comments on commit 44e6145

Please sign in to comment.