Skip to content

Commit

Permalink
Removed conversion of IDomainResult to ActionResult<T> (#41)
Browse files Browse the repository at this point in the history
  • Loading branch information
AKlaus authored Dec 11, 2021
1 parent 5c6b33b commit 8e30c89
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 81 deletions.
12 changes: 6 additions & 6 deletions src/Mvc/DomainResultTo200OkResult.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@ public static partial class DomainResultExtensions
/// <param name="errorAction"> Optional processing in case of an error </param>
public static IActionResult ToActionResult<T>(this IDomainResult<T> domainResult,
Action<ProblemDetails, IDomainResult<T>>? errorAction = null)
=> ToActionResult(domainResult.Value, domainResult, errorAction, (value) => new OkObjectResult(value));
=> ToActionResult(domainResult.Value, domainResult, errorAction, value => new OkObjectResult(value));

/// <summary>
/// Returns HTTP code 200 (OK) with a value or a 4xx code in case of an error.
/// The reesult is wrapped in a <see cref="Task{V}"/>
/// The result is wrapped in a <see cref="Task{V}"/>
/// </summary>
/// <typeparam name="T"> The returned value type from the domain operation in <paramref name="domainResultTask"/> </typeparam>
/// <param name="domainResultTask"> Details of the operation results (<see cref="DomainResult{T}"/>) </param>
Expand All @@ -34,7 +34,7 @@ public static async Task<IActionResult> ToActionResult<T>(this Task<IDomainResul
Action<ProblemDetails, IDomainResult<T>>? errorAction = null)
{
var domainResult = await domainResultTask;
return ToActionResult(domainResult.Value, domainResult, errorAction, (value) => new OkObjectResult(value));
return ToActionResult(domainResult.Value, domainResult, errorAction, value => new OkObjectResult(value));
}

/// <summary>
Expand All @@ -47,11 +47,11 @@ public static async Task<IActionResult> ToActionResult<T>(this Task<IDomainResul
public static IActionResult ToActionResult<V, R>(this (V, R) domainResult,
Action<ProblemDetails, R>? errorAction = null)
where R : IDomainResult
=> domainResult.ToCustomActionResult((value) => new OkObjectResult(value), errorAction);
=> domainResult.ToCustomActionResult(value => new OkObjectResult(value), errorAction);

/// <summary>
/// Returns HTTP code 200 (OK) with a value or a 4xx code in case of an error.
/// The reesult is wrapped in a <see cref="Task{T}"/>
/// The result is wrapped in a <see cref="Task{T}"/>
/// </summary>
/// <typeparam name="V"> The value type returned in a successful response </typeparam>
/// <typeparam name="R"> The type derived from <see cref="IDomainResult"/>, e.g. <see cref="DomainResult"/> </typeparam>
Expand All @@ -62,7 +62,7 @@ public static async Task<IActionResult> ToActionResult<V, R>(this Task<(V, R)> d
where R : IDomainResult
{
var domainResult = await domainResultTask;
return domainResult.ToCustomActionResult((value) => new OkObjectResult(value), errorAction);
return domainResult.ToCustomActionResult(value => new OkObjectResult(value), errorAction);
}
}
}
7 changes: 3 additions & 4 deletions src/Mvc/DomainResultTo204NoContentResult.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,11 @@

namespace DomainResults.Mvc
{
//
// Conversion to HTTP code 204 (NoContent)
//
public static partial class DomainResultExtensions
{
//
// Conversion to HTTP code 204 (NoContent)
//

/// <summary>
/// Returns HTTP code 204 (NoContent) or a 4xx code in case of an error
/// </summary>
Expand Down
37 changes: 0 additions & 37 deletions src/Mvc/DomainResultTo204NoContentResultOfT.cs

This file was deleted.

14 changes: 6 additions & 8 deletions tests/DomainResults.Tests/Mvc/To200OkResultTupleValueTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ public void ValueResult_Converted_ToActionResult_Test<TValue>((TValue, IDomainRe

public static readonly IEnumerable<object[]> SuccessfulTestCases = new List<object[]>
{
new object[] { (10, GetSuccess()) },
new object[] { ("1", GetSuccess()) },
new object[] { (new TestDto("1"), GetSuccess()) }
new object[] { (10, IDomainResult.Success()) },
new object[] { ("1", IDomainResult.Success()) },
new object[] { (new TestDto("1"), IDomainResult.Success()) }
};
#endregion // Test of successful '(TValue, IDomainResult)' response conversion ------------

Expand All @@ -63,12 +63,10 @@ public async Task ValueResult_Task_Converted_ToActionResult_Test<TValue>(Task<(T

public static readonly IEnumerable<object[]> SuccessfulTaskTestCases = new List<object[]>
{
new object[] { Task.FromResult((10, GetSuccess())) },
new object[] { Task.FromResult(("1", GetSuccess())) },
new object[] { Task.FromResult((new TestDto("1"), GetSuccess())) }
new object[] { Task.FromResult((10, IDomainResult.Success())) },
new object[] { Task.FromResult(("1", IDomainResult.Success())) },
new object[] { Task.FromResult((new TestDto("1"), IDomainResult.Success())) }
};
#endregion // Test of successful 'Task<(TValue, IDomainResult)>' response conversion ------

private static IDomainResult GetSuccess() => IDomainResult.Success();
}
}
26 changes: 0 additions & 26 deletions tests/DomainResults.Tests/Mvc/To204NoContentResultSuccessTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,31 +35,5 @@ public async Task DomainResult_Task_Converted_To_NoContent()
// THEN the response type is correct
Assert.IsType<NoContentResult>(actionRes);
}

[Fact]
public void DomainResultConverted_To_NoContentOfT()
{
// GIVEN a successful domain result
var domainRes = DomainResult.Success();

// WHEN convert it to ActionResult
var actionRes = domainRes.ToActionResultOfT();

// THEN the response type is correct
Assert.IsType<NoContentResult>(actionRes.Result);
}

[Fact]
public async Task DomainResult_Task_Converted_To_NoContentOfT()
{
// GIVEN a successful domain result
var domainRes = DomainResult.SuccessTask();

// WHEN convert it to ActionResult
var actionRes = await domainRes.ToActionResultOfT();

// THEN the response type is correct
Assert.IsType<NoContentResult>(actionRes.Result);
}
}
}

0 comments on commit 8e30c89

Please sign in to comment.