feat: add inital in memory dispatcher
Add a simple in memory dispatcher for scalar requests and stream request.
This commit is contained in:
commit
1218d3617a
145 changed files with 6388 additions and 0 deletions
100
src/request.result.tests/PreludeTests.cs
Normal file
100
src/request.result.tests/PreludeTests.cs
Normal file
|
|
@ -0,0 +1,100 @@
|
|||
// Copyright (c) The Geekeey Authors
|
||||
// SPDX-License-Identifier: EUPL-1.2
|
||||
|
||||
namespace Geekeey.Request.Result.Tests;
|
||||
|
||||
internal sealed class PreludeTests
|
||||
{
|
||||
[Test]
|
||||
public async Task I_can_try_with_success_value_and_get_a_success_result()
|
||||
{
|
||||
var result = Prelude.Try(() => 2);
|
||||
|
||||
using var scope = Assert.Multiple();
|
||||
await Assert.That(result.IsSuccess).IsTrue();
|
||||
await Assert.That(result.Value).IsEqualTo(2);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task I_can_try_with_throwing_exception_and_get_a_failure_result()
|
||||
{
|
||||
var result = Prelude.Try<int>(() => throw new CustomTestException());
|
||||
|
||||
using var scope = Assert.Multiple();
|
||||
await Assert.That(result.IsSuccess).IsFalse();
|
||||
var instance = await Assert.That(result.Error).IsTypeOf<ExceptionError>();
|
||||
await Assert.That(instance?.Exception).IsTypeOf<CustomTestException>();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task I_can_try_with_async_success_value_and_get_a_success_result()
|
||||
{
|
||||
var result = await Prelude.TryAsync(() => Task.FromResult(2));
|
||||
|
||||
using var scope = Assert.Multiple();
|
||||
await Assert.That(result.IsSuccess).IsTrue();
|
||||
await Assert.That(result.Value).IsEqualTo(2);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task I_can_try_with_async_throwing_exception_and_get_a_failure_result()
|
||||
{
|
||||
var result = await Prelude.TryAsync(Task<int> () => throw new CustomTestException());
|
||||
|
||||
using var scope = Assert.Multiple();
|
||||
await Assert.That(result.IsSuccess).IsFalse();
|
||||
var instance = await Assert.That(result.Error).IsTypeOf<ExceptionError>();
|
||||
await Assert.That(instance?.Exception).IsTypeOf<CustomTestException>();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task I_can_try_with_async_await_throwing_exception_and_get_a_failure_result()
|
||||
{
|
||||
var result = await Prelude.TryAsync(async Task<int> () =>
|
||||
{
|
||||
await Task.CompletedTask;
|
||||
throw new CustomTestException();
|
||||
});
|
||||
|
||||
using var scope = Assert.Multiple();
|
||||
await Assert.That(result.IsSuccess).IsFalse();
|
||||
var instance = await Assert.That(result.Error).IsTypeOf<ExceptionError>();
|
||||
await Assert.That(instance?.Exception).IsTypeOf<CustomTestException>();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task I_can_try_with_async_success_value_and_get_a_success_result_of_type_ValueTask()
|
||||
{
|
||||
var result = await Prelude.TryAsync(() => ValueTask.FromResult(2));
|
||||
|
||||
using var scope = Assert.Multiple();
|
||||
await Assert.That(result.IsSuccess).IsTrue();
|
||||
await Assert.That(result.Value).IsEqualTo(2);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task I_can_try_with_async_throwing_exception_and_get_a_failure_result_of_type_ValueTask()
|
||||
{
|
||||
var result = await Prelude.TryAsync(ValueTask<int> () => throw new CustomTestException());
|
||||
|
||||
using var scope = Assert.Multiple();
|
||||
await Assert.That(result.IsSuccess).IsFalse();
|
||||
var instance = await Assert.That(result.Error).IsTypeOf<ExceptionError>();
|
||||
await Assert.That(instance?.Exception).IsTypeOf<CustomTestException>();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task I_can_try_with_async_await_throwing_exception_and_get_a_failure_result_of_type_ValueTask()
|
||||
{
|
||||
var result = await Prelude.TryAsync(async ValueTask<int> () =>
|
||||
{
|
||||
await Task.CompletedTask;
|
||||
throw new CustomTestException();
|
||||
});
|
||||
|
||||
using var scope = Assert.Multiple();
|
||||
await Assert.That(result.IsSuccess).IsFalse();
|
||||
var instance = await Assert.That(result.Error).IsTypeOf<ExceptionError>();
|
||||
await Assert.That(instance?.Exception).IsTypeOf<CustomTestException>();
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue