Skip to content

Commit

Permalink
fix: Null reference when the value is null
Browse files Browse the repository at this point in the history
  • Loading branch information
NelsonBN committed May 5, 2023
1 parent f71d6cd commit 37992eb
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/ValueResult.cs
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ public new Type GetType()
return this.OfTypeFirstError();
}

return _value.GetType();
return typeof(TValue);
}

/// <summary>
Expand Down
15 changes: 15 additions & 0 deletions tests/PowerUtils.Results.Tests/ValueResults/MethodGetTypeTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,5 +51,20 @@ public void WithNotFoundError_GetType_NotFoundError()
// Assert
act.Should().Be(typeof(NotFoundError));
}

[Fact]
public void Null_GetType_TypeOfModel()
{
// Arrange
var result = Result<FakeModel>.Ok(null);


// Act
var act = result.GetType();


// Assert
act.Should().Be(typeof(FakeModel));
}
}
}

0 comments on commit 37992eb

Please sign in to comment.