feat: initial project commit
All checks were successful
default / default (8.0) (push) Successful in 1m7s
All checks were successful
default / default (8.0) (push) Successful in 1m7s
This commit is contained in:
commit
30ef7bd477
40 changed files with 3752 additions and 0 deletions
119
src/Result.Tests/PreludeTests.cs
Normal file
119
src/Result.Tests/PreludeTests.cs
Normal file
|
@ -0,0 +1,119 @@
|
|||
namespace Geekeey.Extensions.Result.Tests;
|
||||
|
||||
[TestFixture]
|
||||
internal sealed class PreludeTests
|
||||
{
|
||||
[Test]
|
||||
public void Try_ReturnsSuccess_WithoutThrowing()
|
||||
{
|
||||
var result = Try(() => 2);
|
||||
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
Assert.That(result.IsSuccess, Is.True);
|
||||
Assert.That(result.Value, Is.EqualTo(2));
|
||||
});
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Try_ReturnsFailure_WithThrowing()
|
||||
{
|
||||
var result = Try<int>(() => throw new CustomTestException());
|
||||
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
Assert.That(result.IsSuccess, Is.False);
|
||||
Assert.That(result.Error, Is.InstanceOf<ExceptionError>());
|
||||
var instance = result.Error as ExceptionError;
|
||||
Assert.That(instance?.Exception, Is.InstanceOf<CustomTestException>());
|
||||
});
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task TryAsync_ReturnsSuccess_WithoutThrowing_Task()
|
||||
{
|
||||
var result = await TryAsync(() => Task.FromResult(2));
|
||||
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
Assert.That(result.IsSuccess, Is.True);
|
||||
Assert.That(result.Value, Is.EqualTo(2));
|
||||
});
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task TryAsync_ReturnsFailure_WithThrowing_Task()
|
||||
{
|
||||
var result = await TryAsync(Task<int> () => throw new CustomTestException());
|
||||
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
Assert.That(result.IsSuccess, Is.False);
|
||||
Assert.That(result.Error, Is.InstanceOf<ExceptionError>());
|
||||
var instance = result.Error as ExceptionError;
|
||||
Assert.That(instance?.Exception, Is.InstanceOf<CustomTestException>());
|
||||
});
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task TryAsync_ReturnsFailure_WithAwaitThrowing_Task()
|
||||
{
|
||||
var result = await TryAsync(async Task<int> () =>
|
||||
{
|
||||
await Task.CompletedTask;
|
||||
throw new CustomTestException();
|
||||
});
|
||||
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
Assert.That(result.IsSuccess, Is.False);
|
||||
Assert.That(result.Error, Is.InstanceOf<ExceptionError>());
|
||||
var instance = result.Error as ExceptionError;
|
||||
Assert.That(instance?.Exception, Is.InstanceOf<CustomTestException>());
|
||||
});
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task TryAsync_ReturnsSuccess_WithoutThrowing_ValueTask()
|
||||
{
|
||||
var result = await TryAsync(() => ValueTask.FromResult(2));
|
||||
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
Assert.That(result.IsSuccess, Is.True);
|
||||
Assert.That(result.Value, Is.EqualTo(2));
|
||||
});
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task TryAsync_ReturnsFailure_WithThrowing_ValueTask()
|
||||
{
|
||||
var result = await TryAsync(ValueTask<int> () => throw new CustomTestException());
|
||||
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
Assert.That(result.IsSuccess, Is.False);
|
||||
Assert.That(result.Error, Is.InstanceOf<ExceptionError>());
|
||||
var instance = result.Error as ExceptionError;
|
||||
Assert.That(instance?.Exception, Is.InstanceOf<CustomTestException>());
|
||||
});
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task TryAsync_ReturnsFailure_WithAwaitThrowing_ValueTask()
|
||||
{
|
||||
var result = await TryAsync(async ValueTask<int> () =>
|
||||
{
|
||||
await Task.CompletedTask;
|
||||
throw new CustomTestException();
|
||||
});
|
||||
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
Assert.That(result.IsSuccess, Is.False);
|
||||
Assert.That(result.Error, Is.InstanceOf<ExceptionError>());
|
||||
var instance = result.Error as ExceptionError;
|
||||
Assert.That(instance?.Exception, Is.InstanceOf<CustomTestException>());
|
||||
});
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue