From 6c2cec8325b0b39ff49d5fc13dfd7aa00217baab Mon Sep 17 00:00:00 2001 From: Damian Edwards Date: Wed, 30 Mar 2022 15:00:55 -0700 Subject: [PATCH 01/19] Added the Results class Contributes to #40672 --- src/Http/Http.Results/src/ResultsOfT.cs | 1540 +++++++++++++++++++++++ 1 file changed, 1540 insertions(+) create mode 100644 src/Http/Http.Results/src/ResultsOfT.cs diff --git a/src/Http/Http.Results/src/ResultsOfT.cs b/src/Http/Http.Results/src/ResultsOfT.cs new file mode 100644 index 000000000000..5073b95ac3b0 --- /dev/null +++ b/src/Http/Http.Results/src/ResultsOfT.cs @@ -0,0 +1,1540 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +namespace Microsoft.AspNetCore.Http.Result; + +/// +/// Represents the result of an route handler delegate that can return one different types. +/// +/// The first result type. +public sealed class Results : IResult + where TResult1 : IResult +{ + private Results(IResult activeResult) + { + Result = activeResult; + } + + /// + /// Gets the actual returned by the route handler delegate. + /// + public IResult Result { get; } + + /// + /// Writes an HTTP response reflecting the result. + /// + /// The for the current request. + /// A that represents the asynchronous execute operation. + public async Task ExecuteAsync(HttpContext httpContext) + { + ArgumentNullException.ThrowIfNull(httpContext, nameof(httpContext)); + + await Result.ExecuteAsync(httpContext); + } + + /// + /// Converts the to a . + /// + /// The result. + public static implicit operator Results(TResult1 result) => new(result); +} + +/// +/// Represents the result of an route handler delegate that can return two different types. +/// +/// The first result type. +/// The second result type. +public sealed class Results : IResult + where TResult1 : IResult + where TResult2 : IResult +{ + private Results(IResult activeResult) + { + Result = activeResult; + } + + /// + /// Gets the actual returned by the route handler delegate. + /// + public IResult Result { get; } + + /// + /// Writes an HTTP response reflecting the result. + /// + /// The for the current request. + /// A that represents the asynchronous execute operation. + public async Task ExecuteAsync(HttpContext httpContext) + { + ArgumentNullException.ThrowIfNull(httpContext, nameof(httpContext)); + + await Result.ExecuteAsync(httpContext); + } + + /// + /// Converts the to a . + /// + /// The result. + public static implicit operator Results(TResult1 result) => new(result); + + /// + /// Converts the to a . + /// + /// The result. + public static implicit operator Results(TResult2 result) => new(result); +} + +/// +/// Represents the result of an route handler delegate that can return three different types. +/// +/// The first result type. +/// The second result type. +/// The third result type. +public sealed class Results : IResult + where TResult1 : IResult + where TResult2 : IResult + where TResult3 : IResult +{ + private Results(IResult activeResult) + { + Result = activeResult; + } + + /// + /// Gets the actual returned by the route handler delegate. + /// + public IResult Result { get; } + + /// + /// Writes an HTTP response reflecting the result. + /// + /// The for the current request. + /// A that represents the asynchronous execute operation. + public async Task ExecuteAsync(HttpContext httpContext) + { + ArgumentNullException.ThrowIfNull(httpContext, nameof(httpContext)); + + await Result.ExecuteAsync(httpContext); + } + + /// + /// Converts the to a . + /// + /// The result. + public static implicit operator Results(TResult1 result) => new(result); + + /// + /// Converts the to a . + /// + /// The result. + public static implicit operator Results(TResult2 result) => new(result); + + /// + /// Converts the to a . + /// + /// The result. + public static implicit operator Results(TResult3 result) => new(result); +} + +/// +/// Represents the result of an route handler delegate that can return four different types. +/// +/// The first result type. +/// The second result type. +/// The third result type. +/// The fourth result type. +public sealed class Results : IResult + where TResult1 : IResult + where TResult2 : IResult + where TResult3 : IResult + where TResult4 : IResult +{ + private Results(IResult activeResult) + { + Result = activeResult; + } + + /// + /// Gets the actual returned by the route handler delegate. + /// + public IResult Result { get; } + + /// + /// Writes an HTTP response reflecting the result. + /// + /// The for the current request. + /// A that represents the asynchronous execute operation. + public async Task ExecuteAsync(HttpContext httpContext) + { + ArgumentNullException.ThrowIfNull(httpContext, nameof(httpContext)); + + await Result.ExecuteAsync(httpContext); + } + + /// + /// Converts the to a . + /// + /// The result. + public static implicit operator Results(TResult1 result) => new(result); + + /// + /// Converts the to a . + /// + /// The result. + public static implicit operator Results(TResult2 result) => new(result); + + /// + /// Converts the to a . + /// + /// The result. + public static implicit operator Results(TResult3 result) => new(result); + + /// + /// Converts the to a . + /// + /// The result. + public static implicit operator Results(TResult4 result) => new(result); +} + +/// +/// Represents the result of an route handler delegate that can return five different types. +/// +/// The first result type. +/// The second result type. +/// The third result type. +/// The fourth result type. +/// The fifth result type. +public sealed class Results : IResult + where TResult1 : IResult + where TResult2 : IResult + where TResult3 : IResult + where TResult4 : IResult + where TResult5 : IResult +{ + private Results(IResult activeResult) + { + Result = activeResult; + } + + /// + /// Gets the actual returned by the route handler delegate. + /// + public IResult Result { get; } + + /// + /// Writes an HTTP response reflecting the result. + /// + /// The for the current request. + /// A that represents the asynchronous execute operation. + public async Task ExecuteAsync(HttpContext httpContext) + { + ArgumentNullException.ThrowIfNull(httpContext, nameof(httpContext)); + + await Result.ExecuteAsync(httpContext); + } + + /// + /// Converts the to a . + /// + /// The result. + public static implicit operator Results(TResult1 result) => new(result); + + /// + /// Converts the to a . + /// + /// The result. + public static implicit operator Results(TResult2 result) => new(result); + + /// + /// Converts the to a . + /// + /// The result. + public static implicit operator Results(TResult3 result) => new(result); + + /// + /// Converts the to a . + /// + /// The result. + public static implicit operator Results(TResult4 result) => new(result); + + /// + /// Converts the to a . + /// + /// The result. + public static implicit operator Results(TResult5 result) => new(result); +} + +/// +/// Represents the result of an route handler delegate that can return six different types. +/// +/// The first result type. +/// The second result type. +/// The third result type. +/// The fourth result type. +/// The fifth result type. +/// The sixth result type. +public sealed class Results : IResult + where TResult1 : IResult + where TResult2 : IResult + where TResult3 : IResult + where TResult4 : IResult + where TResult5 : IResult + where TResult6 : IResult +{ + private Results(IResult activeResult) + { + Result = activeResult; + } + + /// + /// Gets the actual returned by the route handler delegate. + /// + public IResult Result { get; } + + /// + /// Writes an HTTP response reflecting the result. + /// + /// The for the current request. + /// A that represents the asynchronous execute operation. + public async Task ExecuteAsync(HttpContext httpContext) + { + ArgumentNullException.ThrowIfNull(httpContext, nameof(httpContext)); + + await Result.ExecuteAsync(httpContext); + } + + /// + /// Converts the to a . + /// + /// The result. + public static implicit operator Results(TResult1 result) => new(result); + + /// + /// Converts the to a . + /// + /// The result. + public static implicit operator Results(TResult2 result) => new(result); + + /// + /// Converts the to a . + /// + /// The result. + public static implicit operator Results(TResult3 result) => new(result); + + /// + /// Converts the to a . + /// + /// The result. + public static implicit operator Results(TResult4 result) => new(result); + + /// + /// Converts the to a . + /// + /// The result. + public static implicit operator Results(TResult5 result) => new(result); + + /// + /// Converts the to a . + /// + /// The result. + public static implicit operator Results(TResult6 result) => new(result); +} + +/// +/// Represents the result of an route handler delegate that can return seven different types. +/// +/// The first result type. +/// The second result type. +/// The third result type. +/// The fourth result type. +/// The fifth result type. +/// The sixth result type. +/// The seventh result type. +public sealed class Results : IResult + where TResult1 : IResult + where TResult2 : IResult + where TResult3 : IResult + where TResult4 : IResult + where TResult5 : IResult + where TResult6 : IResult + where TResult7 : IResult +{ + private Results(IResult activeResult) + { + Result = activeResult; + } + + /// + /// Gets the actual returned by the route handler delegate. + /// + public IResult Result { get; } + + /// + /// Writes an HTTP response reflecting the result. + /// + /// The for the current request. + /// A that represents the asynchronous execute operation. + public async Task ExecuteAsync(HttpContext httpContext) + { + ArgumentNullException.ThrowIfNull(httpContext, nameof(httpContext)); + + await Result.ExecuteAsync(httpContext); + } + + /// + /// Converts the to a . + /// + /// The result. + public static implicit operator Results(TResult1 result) => new(result); + + /// + /// Converts the to a . + /// + /// The result. + public static implicit operator Results(TResult2 result) => new(result); + + /// + /// Converts the to a . + /// + /// The result. + public static implicit operator Results(TResult3 result) => new(result); + + /// + /// Converts the to a . + /// + /// The result. + public static implicit operator Results(TResult4 result) => new(result); + + /// + /// Converts the to a . + /// + /// The result. + public static implicit operator Results(TResult5 result) => new(result); + + /// + /// Converts the to a . + /// + /// The result. + public static implicit operator Results(TResult6 result) => new(result); + + /// + /// Converts the to a . + /// + /// The result. + public static implicit operator Results(TResult7 result) => new(result); +} + +/// +/// Represents the result of an route handler delegate that can return eight different types. +/// +/// The first result type. +/// The second result type. +/// The third result type. +/// The fourth result type. +/// The fifth result type. +/// The sixth result type. +/// The seventh result type. +/// The eighth result type. +public sealed class Results : IResult + where TResult1 : IResult + where TResult2 : IResult + where TResult3 : IResult + where TResult4 : IResult + where TResult5 : IResult + where TResult6 : IResult + where TResult7 : IResult + where TResult8 : IResult +{ + private Results(IResult activeResult) + { + Result = activeResult; + } + + /// + /// Gets the actual returned by the route handler delegate. + /// + public IResult Result { get; } + + /// + /// Writes an HTTP response reflecting the result. + /// + /// The for the current request. + /// A that represents the asynchronous execute operation. + public async Task ExecuteAsync(HttpContext httpContext) + { + ArgumentNullException.ThrowIfNull(httpContext, nameof(httpContext)); + + await Result.ExecuteAsync(httpContext); + } + + /// + /// Converts the to a . + /// + /// The result. + public static implicit operator Results(TResult1 result) => new(result); + + /// + /// Converts the to a . + /// + /// The result. + public static implicit operator Results(TResult2 result) => new(result); + + /// + /// Converts the to a . + /// + /// The result. + public static implicit operator Results(TResult3 result) => new(result); + + /// + /// Converts the to a . + /// + /// The result. + public static implicit operator Results(TResult4 result) => new(result); + + /// + /// Converts the to a . + /// + /// The result. + public static implicit operator Results(TResult5 result) => new(result); + + /// + /// Converts the to a . + /// + /// The result. + public static implicit operator Results(TResult6 result) => new(result); + + /// + /// Converts the to a . + /// + /// The result. + public static implicit operator Results(TResult7 result) => new(result); + + /// + /// Converts the to a . + /// + /// The result. + public static implicit operator Results(TResult8 result) => new(result); +} + +/// +/// Represents the result of an route handler delegate that can return nine different types. +/// +/// The first result type. +/// The second result type. +/// The third result type. +/// The fourth result type. +/// The fifth result type. +/// The sixth result type. +/// The seventh result type. +/// The eighth result type. +/// The ninth result type. +public sealed class Results : IResult + where TResult1 : IResult + where TResult2 : IResult + where TResult3 : IResult + where TResult4 : IResult + where TResult5 : IResult + where TResult6 : IResult + where TResult7 : IResult + where TResult8 : IResult + where TResult9 : IResult +{ + private Results(IResult activeResult) + { + Result = activeResult; + } + + /// + /// Gets the actual returned by the route handler delegate. + /// + public IResult Result { get; } + + /// + /// Writes an HTTP response reflecting the result. + /// + /// The for the current request. + /// A that represents the asynchronous execute operation. + public async Task ExecuteAsync(HttpContext httpContext) + { + ArgumentNullException.ThrowIfNull(httpContext, nameof(httpContext)); + + await Result.ExecuteAsync(httpContext); + } + + /// + /// Converts the to a . + /// + /// The result. + public static implicit operator Results(TResult1 result) => new(result); + + /// + /// Converts the to a . + /// + /// The result. + public static implicit operator Results(TResult2 result) => new(result); + + /// + /// Converts the to a . + /// + /// The result. + public static implicit operator Results(TResult3 result) => new(result); + + /// + /// Converts the to a . + /// + /// The result. + public static implicit operator Results(TResult4 result) => new(result); + + /// + /// Converts the to a . + /// + /// The result. + public static implicit operator Results(TResult5 result) => new(result); + + /// + /// Converts the to a . + /// + /// The result. + public static implicit operator Results(TResult6 result) => new(result); + + /// + /// Converts the to a . + /// + /// The result. + public static implicit operator Results(TResult7 result) => new(result); + + /// + /// Converts the to a . + /// + /// The result. + public static implicit operator Results(TResult8 result) => new(result); + + /// + /// Converts the to a . + /// + /// The result. + public static implicit operator Results(TResult9 result) => new(result); +} + +/// +/// Represents the result of an route handler delegate that can return ten different types. +/// +/// The first result type. +/// The second result type. +/// The third result type. +/// The fourth result type. +/// The fifth result type. +/// The sixth result type. +/// The seventh result type. +/// The eighth result type. +/// The ninth result type. +/// The tenth result type. +public sealed class Results : IResult + where TResult1 : IResult + where TResult2 : IResult + where TResult3 : IResult + where TResult4 : IResult + where TResult5 : IResult + where TResult6 : IResult + where TResult7 : IResult + where TResult8 : IResult + where TResult9 : IResult + where TResult10 : IResult +{ + private Results(IResult activeResult) + { + Result = activeResult; + } + + /// + /// Gets the actual returned by the route handler delegate. + /// + public IResult Result { get; } + + /// + /// Writes an HTTP response reflecting the result. + /// + /// The for the current request. + /// A that represents the asynchronous execute operation. + public async Task ExecuteAsync(HttpContext httpContext) + { + ArgumentNullException.ThrowIfNull(httpContext, nameof(httpContext)); + + await Result.ExecuteAsync(httpContext); + } + + /// + /// Converts the to a . + /// + /// The result. + public static implicit operator Results(TResult1 result) => new(result); + + /// + /// Converts the to a . + /// + /// The result. + public static implicit operator Results(TResult2 result) => new(result); + + /// + /// Converts the to a . + /// + /// The result. + public static implicit operator Results(TResult3 result) => new(result); + + /// + /// Converts the to a . + /// + /// The result. + public static implicit operator Results(TResult4 result) => new(result); + + /// + /// Converts the to a . + /// + /// The result. + public static implicit operator Results(TResult5 result) => new(result); + + /// + /// Converts the to a . + /// + /// The result. + public static implicit operator Results(TResult6 result) => new(result); + + /// + /// Converts the to a . + /// + /// The result. + public static implicit operator Results(TResult7 result) => new(result); + + /// + /// Converts the to a . + /// + /// The result. + public static implicit operator Results(TResult8 result) => new(result); + + /// + /// Converts the to a . + /// + /// The result. + public static implicit operator Results(TResult9 result) => new(result); + + /// + /// Converts the to a . + /// + /// The result. + public static implicit operator Results(TResult10 result) => new(result); +} + +/// +/// Represents the result of an route handler delegate that can return eleven different types. +/// +/// The first result type. +/// The second result type. +/// The third result type. +/// The fourth result type. +/// The fifth result type. +/// The sixth result type. +/// The seventh result type. +/// The eighth result type. +/// The ninth result type. +/// The tenth result type. +/// The eleventh result type. +public sealed class Results : IResult + where TResult1 : IResult + where TResult2 : IResult + where TResult3 : IResult + where TResult4 : IResult + where TResult5 : IResult + where TResult6 : IResult + where TResult7 : IResult + where TResult8 : IResult + where TResult9 : IResult + where TResult10 : IResult + where TResult11 : IResult +{ + private Results(IResult activeResult) + { + Result = activeResult; + } + + /// + /// Gets the actual returned by the route handler delegate. + /// + public IResult Result { get; } + + /// + /// Writes an HTTP response reflecting the result. + /// + /// The for the current request. + /// A that represents the asynchronous execute operation. + public async Task ExecuteAsync(HttpContext httpContext) + { + ArgumentNullException.ThrowIfNull(httpContext, nameof(httpContext)); + + await Result.ExecuteAsync(httpContext); + } + + /// + /// Converts the to a . + /// + /// The result. + public static implicit operator Results(TResult1 result) => new(result); + + /// + /// Converts the to a . + /// + /// The result. + public static implicit operator Results(TResult2 result) => new(result); + + /// + /// Converts the to a . + /// + /// The result. + public static implicit operator Results(TResult3 result) => new(result); + + /// + /// Converts the to a . + /// + /// The result. + public static implicit operator Results(TResult4 result) => new(result); + + /// + /// Converts the to a . + /// + /// The result. + public static implicit operator Results(TResult5 result) => new(result); + + /// + /// Converts the to a . + /// + /// The result. + public static implicit operator Results(TResult6 result) => new(result); + + /// + /// Converts the to a . + /// + /// The result. + public static implicit operator Results(TResult7 result) => new(result); + + /// + /// Converts the to a . + /// + /// The result. + public static implicit operator Results(TResult8 result) => new(result); + + /// + /// Converts the to a . + /// + /// The result. + public static implicit operator Results(TResult9 result) => new(result); + + /// + /// Converts the to a . + /// + /// The result. + public static implicit operator Results(TResult10 result) => new(result); + + /// + /// Converts the to a . + /// + /// The result. + public static implicit operator Results(TResult11 result) => new(result); +} + +/// +/// Represents the result of an route handler delegate that can return twelve different types. +/// +/// The first result type. +/// The second result type. +/// The third result type. +/// The fourth result type. +/// The fifth result type. +/// The sixth result type. +/// The seventh result type. +/// The eighth result type. +/// The ninth result type. +/// The tenth result type. +/// The eleventh result type. +/// The twelfth result type. +public sealed class Results : IResult + where TResult1 : IResult + where TResult2 : IResult + where TResult3 : IResult + where TResult4 : IResult + where TResult5 : IResult + where TResult6 : IResult + where TResult7 : IResult + where TResult8 : IResult + where TResult9 : IResult + where TResult10 : IResult + where TResult11 : IResult + where TResult12 : IResult +{ + private Results(IResult activeResult) + { + Result = activeResult; + } + + /// + /// Gets the actual returned by the route handler delegate. + /// + public IResult Result { get; } + + /// + /// Writes an HTTP response reflecting the result. + /// + /// The for the current request. + /// A that represents the asynchronous execute operation. + public async Task ExecuteAsync(HttpContext httpContext) + { + ArgumentNullException.ThrowIfNull(httpContext, nameof(httpContext)); + + await Result.ExecuteAsync(httpContext); + } + + /// + /// Converts the to a . + /// + /// The result. + public static implicit operator Results(TResult1 result) => new(result); + + /// + /// Converts the to a . + /// + /// The result. + public static implicit operator Results(TResult2 result) => new(result); + + /// + /// Converts the to a . + /// + /// The result. + public static implicit operator Results(TResult3 result) => new(result); + + /// + /// Converts the to a . + /// + /// The result. + public static implicit operator Results(TResult4 result) => new(result); + + /// + /// Converts the to a . + /// + /// The result. + public static implicit operator Results(TResult5 result) => new(result); + + /// + /// Converts the to a . + /// + /// The result. + public static implicit operator Results(TResult6 result) => new(result); + + /// + /// Converts the to a . + /// + /// The result. + public static implicit operator Results(TResult7 result) => new(result); + + /// + /// Converts the to a . + /// + /// The result. + public static implicit operator Results(TResult8 result) => new(result); + + /// + /// Converts the to a . + /// + /// The result. + public static implicit operator Results(TResult9 result) => new(result); + + /// + /// Converts the to a . + /// + /// The result. + public static implicit operator Results(TResult10 result) => new(result); + + /// + /// Converts the to a . + /// + /// The result. + public static implicit operator Results(TResult11 result) => new(result); + + /// + /// Converts the to a . + /// + /// The result. + public static implicit operator Results(TResult12 result) => new(result); +} + +/// +/// Represents the result of an route handler delegate that can return thirteen different types. +/// +/// The first result type. +/// The second result type. +/// The third result type. +/// The fourth result type. +/// The fifth result type. +/// The sixth result type. +/// The seventh result type. +/// The eighth result type. +/// The ninth result type. +/// The tenth result type. +/// The eleventh result type. +/// The twelfth result type. +/// The thirteenth result type. +public sealed class Results : IResult + where TResult1 : IResult + where TResult2 : IResult + where TResult3 : IResult + where TResult4 : IResult + where TResult5 : IResult + where TResult6 : IResult + where TResult7 : IResult + where TResult8 : IResult + where TResult9 : IResult + where TResult10 : IResult + where TResult11 : IResult + where TResult12 : IResult + where TResult13 : IResult +{ + private Results(IResult activeResult) + { + Result = activeResult; + } + + /// + /// Gets the actual returned by the route handler delegate. + /// + public IResult Result { get; } + + /// + /// Writes an HTTP response reflecting the result. + /// + /// The for the current request. + /// A that represents the asynchronous execute operation. + public async Task ExecuteAsync(HttpContext httpContext) + { + ArgumentNullException.ThrowIfNull(httpContext, nameof(httpContext)); + + await Result.ExecuteAsync(httpContext); + } + + /// + /// Converts the to a . + /// + /// The result. + public static implicit operator Results(TResult1 result) => new(result); + + /// + /// Converts the to a . + /// + /// The result. + public static implicit operator Results(TResult2 result) => new(result); + + /// + /// Converts the to a . + /// + /// The result. + public static implicit operator Results(TResult3 result) => new(result); + + /// + /// Converts the to a . + /// + /// The result. + public static implicit operator Results(TResult4 result) => new(result); + + /// + /// Converts the to a . + /// + /// The result. + public static implicit operator Results(TResult5 result) => new(result); + + /// + /// Converts the to a . + /// + /// The result. + public static implicit operator Results(TResult6 result) => new(result); + + /// + /// Converts the to a . + /// + /// The result. + public static implicit operator Results(TResult7 result) => new(result); + + /// + /// Converts the to a . + /// + /// The result. + public static implicit operator Results(TResult8 result) => new(result); + + /// + /// Converts the to a . + /// + /// The result. + public static implicit operator Results(TResult9 result) => new(result); + + /// + /// Converts the to a . + /// + /// The result. + public static implicit operator Results(TResult10 result) => new(result); + + /// + /// Converts the to a . + /// + /// The result. + public static implicit operator Results(TResult11 result) => new(result); + + /// + /// Converts the to a . + /// + /// The result. + public static implicit operator Results(TResult12 result) => new(result); + + /// + /// Converts the to a . + /// + /// The result. + public static implicit operator Results(TResult13 result) => new(result); +} + +/// +/// Represents the result of an route handler delegate that can return fourteen different types. +/// +/// The first result type. +/// The second result type. +/// The third result type. +/// The fourth result type. +/// The fifth result type. +/// The sixth result type. +/// The seventh result type. +/// The eighth result type. +/// The ninth result type. +/// The tenth result type. +/// The eleventh result type. +/// The twelfth result type. +/// The thirteenth result type. +/// The fourteenth result type. +public sealed class Results : IResult + where TResult1 : IResult + where TResult2 : IResult + where TResult3 : IResult + where TResult4 : IResult + where TResult5 : IResult + where TResult6 : IResult + where TResult7 : IResult + where TResult8 : IResult + where TResult9 : IResult + where TResult10 : IResult + where TResult11 : IResult + where TResult12 : IResult + where TResult13 : IResult + where TResult14 : IResult +{ + private Results(IResult activeResult) + { + Result = activeResult; + } + + /// + /// Gets the actual returned by the route handler delegate. + /// + public IResult Result { get; } + + /// + /// Writes an HTTP response reflecting the result. + /// + /// The for the current request. + /// A that represents the asynchronous execute operation. + public async Task ExecuteAsync(HttpContext httpContext) + { + ArgumentNullException.ThrowIfNull(httpContext, nameof(httpContext)); + + await Result.ExecuteAsync(httpContext); + } + + /// + /// Converts the to a . + /// + /// The result. + public static implicit operator Results(TResult1 result) => new(result); + + /// + /// Converts the to a . + /// + /// The result. + public static implicit operator Results(TResult2 result) => new(result); + + /// + /// Converts the to a . + /// + /// The result. + public static implicit operator Results(TResult3 result) => new(result); + + /// + /// Converts the to a . + /// + /// The result. + public static implicit operator Results(TResult4 result) => new(result); + + /// + /// Converts the to a . + /// + /// The result. + public static implicit operator Results(TResult5 result) => new(result); + + /// + /// Converts the to a . + /// + /// The result. + public static implicit operator Results(TResult6 result) => new(result); + + /// + /// Converts the to a . + /// + /// The result. + public static implicit operator Results(TResult7 result) => new(result); + + /// + /// Converts the to a . + /// + /// The result. + public static implicit operator Results(TResult8 result) => new(result); + + /// + /// Converts the to a . + /// + /// The result. + public static implicit operator Results(TResult9 result) => new(result); + + /// + /// Converts the to a . + /// + /// The result. + public static implicit operator Results(TResult10 result) => new(result); + + /// + /// Converts the to a . + /// + /// The result. + public static implicit operator Results(TResult11 result) => new(result); + + /// + /// Converts the to a . + /// + /// The result. + public static implicit operator Results(TResult12 result) => new(result); + + /// + /// Converts the to a . + /// + /// The result. + public static implicit operator Results(TResult13 result) => new(result); + + /// + /// Converts the to a . + /// + /// The result. + public static implicit operator Results(TResult14 result) => new(result); +} + +/// +/// Represents the result of an route handler delegate that can return fifteen different types. +/// +/// The first result type. +/// The second result type. +/// The third result type. +/// The fourth result type. +/// The fifth result type. +/// The sixth result type. +/// The seventh result type. +/// The eighth result type. +/// The ninth result type. +/// The tenth result type. +/// The eleventh result type. +/// The twelfth result type. +/// The thirteenth result type. +/// The fourteenth result type. +/// The fifteenth result type. +public sealed class Results : IResult + where TResult1 : IResult + where TResult2 : IResult + where TResult3 : IResult + where TResult4 : IResult + where TResult5 : IResult + where TResult6 : IResult + where TResult7 : IResult + where TResult8 : IResult + where TResult9 : IResult + where TResult10 : IResult + where TResult11 : IResult + where TResult12 : IResult + where TResult13 : IResult + where TResult14 : IResult + where TResult15 : IResult +{ + private Results(IResult activeResult) + { + Result = activeResult; + } + + /// + /// Gets the actual returned by the route handler delegate. + /// + public IResult Result { get; } + + /// + /// Writes an HTTP response reflecting the result. + /// + /// The for the current request. + /// A that represents the asynchronous execute operation. + public async Task ExecuteAsync(HttpContext httpContext) + { + ArgumentNullException.ThrowIfNull(httpContext, nameof(httpContext)); + + await Result.ExecuteAsync(httpContext); + } + + /// + /// Converts the to a . + /// + /// The result. + public static implicit operator Results(TResult1 result) => new(result); + + /// + /// Converts the to a . + /// + /// The result. + public static implicit operator Results(TResult2 result) => new(result); + + /// + /// Converts the to a . + /// + /// The result. + public static implicit operator Results(TResult3 result) => new(result); + + /// + /// Converts the to a . + /// + /// The result. + public static implicit operator Results(TResult4 result) => new(result); + + /// + /// Converts the to a . + /// + /// The result. + public static implicit operator Results(TResult5 result) => new(result); + + /// + /// Converts the to a . + /// + /// The result. + public static implicit operator Results(TResult6 result) => new(result); + + /// + /// Converts the to a . + /// + /// The result. + public static implicit operator Results(TResult7 result) => new(result); + + /// + /// Converts the to a . + /// + /// The result. + public static implicit operator Results(TResult8 result) => new(result); + + /// + /// Converts the to a . + /// + /// The result. + public static implicit operator Results(TResult9 result) => new(result); + + /// + /// Converts the to a . + /// + /// The result. + public static implicit operator Results(TResult10 result) => new(result); + + /// + /// Converts the to a . + /// + /// The result. + public static implicit operator Results(TResult11 result) => new(result); + + /// + /// Converts the to a . + /// + /// The result. + public static implicit operator Results(TResult12 result) => new(result); + + /// + /// Converts the to a . + /// + /// The result. + public static implicit operator Results(TResult13 result) => new(result); + + /// + /// Converts the to a . + /// + /// The result. + public static implicit operator Results(TResult14 result) => new(result); + + /// + /// Converts the to a . + /// + /// The result. + public static implicit operator Results(TResult15 result) => new(result); +} + +/// +/// Represents the result of an route handler delegate that can return sixteen different types. +/// +/// The first result type. +/// The second result type. +/// The third result type. +/// The fourth result type. +/// The fifth result type. +/// The sixth result type. +/// The seventh result type. +/// The eighth result type. +/// The ninth result type. +/// The tenth result type. +/// The eleventh result type. +/// The twelfth result type. +/// The thirteenth result type. +/// The fourteenth result type. +/// The fifteenth result type. +/// The sixteenth result type. +public sealed class Results : IResult + where TResult1 : IResult + where TResult2 : IResult + where TResult3 : IResult + where TResult4 : IResult + where TResult5 : IResult + where TResult6 : IResult + where TResult7 : IResult + where TResult8 : IResult + where TResult9 : IResult + where TResult10 : IResult + where TResult11 : IResult + where TResult12 : IResult + where TResult13 : IResult + where TResult14 : IResult + where TResult15 : IResult + where TResult16 : IResult +{ + private Results(IResult activeResult) + { + Result = activeResult; + } + + /// + /// Gets the actual returned by the route handler delegate. + /// + public IResult Result { get; } + + /// + /// Writes an HTTP response reflecting the result. + /// + /// The for the current request. + /// A that represents the asynchronous execute operation. + public async Task ExecuteAsync(HttpContext httpContext) + { + ArgumentNullException.ThrowIfNull(httpContext, nameof(httpContext)); + + await Result.ExecuteAsync(httpContext); + } + + /// + /// Converts the to a . + /// + /// The result. + public static implicit operator Results(TResult1 result) => new(result); + + /// + /// Converts the to a . + /// + /// The result. + public static implicit operator Results(TResult2 result) => new(result); + + /// + /// Converts the to a . + /// + /// The result. + public static implicit operator Results(TResult3 result) => new(result); + + /// + /// Converts the to a . + /// + /// The result. + public static implicit operator Results(TResult4 result) => new(result); + + /// + /// Converts the to a . + /// + /// The result. + public static implicit operator Results(TResult5 result) => new(result); + + /// + /// Converts the to a . + /// + /// The result. + public static implicit operator Results(TResult6 result) => new(result); + + /// + /// Converts the to a . + /// + /// The result. + public static implicit operator Results(TResult7 result) => new(result); + + /// + /// Converts the to a . + /// + /// The result. + public static implicit operator Results(TResult8 result) => new(result); + + /// + /// Converts the to a . + /// + /// The result. + public static implicit operator Results(TResult9 result) => new(result); + + /// + /// Converts the to a . + /// + /// The result. + public static implicit operator Results(TResult10 result) => new(result); + + /// + /// Converts the to a . + /// + /// The result. + public static implicit operator Results(TResult11 result) => new(result); + + /// + /// Converts the to a . + /// + /// The result. + public static implicit operator Results(TResult12 result) => new(result); + + /// + /// Converts the to a . + /// + /// The result. + public static implicit operator Results(TResult13 result) => new(result); + + /// + /// Converts the to a . + /// + /// The result. + public static implicit operator Results(TResult14 result) => new(result); + + /// + /// Converts the to a . + /// + /// The result. + public static implicit operator Results(TResult15 result) => new(result); + + /// + /// Converts the to a . + /// + /// The result. + public static implicit operator Results(TResult16 result) => new(result); +} From df7ac5e1dcd64b6c91252578deb6af143307e0b4 Mon Sep 17 00:00:00 2001 From: Damian Edwards Date: Wed, 30 Mar 2022 16:01:44 -0700 Subject: [PATCH 02/19] Add ResultsOfT code generator --- AspNetCore.sln | 19 ++ .../tools/ResultsOfTGenerator/Program.cs | 291 ++++++++++++++++++ .../Properties/launchSettings.json | 8 + .../ResultsOfTGenerator.csproj | 9 + 4 files changed, 327 insertions(+) create mode 100644 src/Http/Http.Results/tools/ResultsOfTGenerator/Program.cs create mode 100644 src/Http/Http.Results/tools/ResultsOfTGenerator/Properties/launchSettings.json create mode 100644 src/Http/Http.Results/tools/ResultsOfTGenerator/ResultsOfTGenerator.csproj diff --git a/AspNetCore.sln b/AspNetCore.sln index 2594c3c89d2f..04a250e07e04 100644 --- a/AspNetCore.sln +++ b/AspNetCore.sln @@ -1696,6 +1696,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "BuildAfterTargetingPack", " EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BuildAfterTargetingPack", "src\BuildAfterTargetingPack\BuildAfterTargetingPack.csproj", "{8FED7E65-A7DD-4F13-8980-BF03E77B6C85}" EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ResultsOfTGenerator", "src\Http\Http.Results\tools\ResultsOfTGenerator\ResultsOfTGenerator.csproj", "{9716D0D0-2251-44DD-8596-67D253EEF41C}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -10151,6 +10153,22 @@ Global {8FED7E65-A7DD-4F13-8980-BF03E77B6C85}.Release|x64.Build.0 = Release|Any CPU {8FED7E65-A7DD-4F13-8980-BF03E77B6C85}.Release|x86.ActiveCfg = Release|Any CPU {8FED7E65-A7DD-4F13-8980-BF03E77B6C85}.Release|x86.Build.0 = Release|Any CPU + {9716D0D0-2251-44DD-8596-67D253EEF41C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {9716D0D0-2251-44DD-8596-67D253EEF41C}.Debug|Any CPU.Build.0 = Debug|Any CPU + {9716D0D0-2251-44DD-8596-67D253EEF41C}.Debug|arm64.ActiveCfg = Debug|Any CPU + {9716D0D0-2251-44DD-8596-67D253EEF41C}.Debug|arm64.Build.0 = Debug|Any CPU + {9716D0D0-2251-44DD-8596-67D253EEF41C}.Debug|x64.ActiveCfg = Debug|Any CPU + {9716D0D0-2251-44DD-8596-67D253EEF41C}.Debug|x64.Build.0 = Debug|Any CPU + {9716D0D0-2251-44DD-8596-67D253EEF41C}.Debug|x86.ActiveCfg = Debug|Any CPU + {9716D0D0-2251-44DD-8596-67D253EEF41C}.Debug|x86.Build.0 = Debug|Any CPU + {9716D0D0-2251-44DD-8596-67D253EEF41C}.Release|Any CPU.ActiveCfg = Release|Any CPU + {9716D0D0-2251-44DD-8596-67D253EEF41C}.Release|Any CPU.Build.0 = Release|Any CPU + {9716D0D0-2251-44DD-8596-67D253EEF41C}.Release|arm64.ActiveCfg = Release|Any CPU + {9716D0D0-2251-44DD-8596-67D253EEF41C}.Release|arm64.Build.0 = Release|Any CPU + {9716D0D0-2251-44DD-8596-67D253EEF41C}.Release|x64.ActiveCfg = Release|Any CPU + {9716D0D0-2251-44DD-8596-67D253EEF41C}.Release|x64.Build.0 = Release|Any CPU + {9716D0D0-2251-44DD-8596-67D253EEF41C}.Release|x86.ActiveCfg = Release|Any CPU + {9716D0D0-2251-44DD-8596-67D253EEF41C}.Release|x86.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -10991,6 +11009,7 @@ Global {B7DAA48B-8E5E-4A5D-9FEB-E6D49AE76A04} = {41BB7BA4-AC08-4E9A-83EA-6D587A5B951C} {489020F2-80D9-4468-A5D3-07E785837A5D} = {017429CC-C5FB-48B4-9C46-034E29EE2F06} {8FED7E65-A7DD-4F13-8980-BF03E77B6C85} = {489020F2-80D9-4468-A5D3-07E785837A5D} + {9716D0D0-2251-44DD-8596-67D253EEF41C} = {323C3EB6-1D15-4B3D-918D-699D7F64DED9} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {3E8720B3-DBDD-498C-B383-2CC32A054E8F} diff --git a/src/Http/Http.Results/tools/ResultsOfTGenerator/Program.cs b/src/Http/Http.Results/tools/ResultsOfTGenerator/Program.cs new file mode 100644 index 000000000000..38641e98e5ed --- /dev/null +++ b/src/Http/Http.Results/tools/ResultsOfTGenerator/Program.cs @@ -0,0 +1,291 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +using System.Text; + +var className = "Results"; +var typeArgCount = 16; +var typeArgName = "TResult"; +var filePath = Path.Join(Directory.GetCurrentDirectory(), $"{className}OfT.cs"); + +Console.WriteLine($"Will generate file at {filePath}"); +Console.WriteLine("Press Enter to continue"); +Console.ReadLine(); + +using var writer = new StreamWriter(filePath, append: false); + +// File header +writer.WriteLine("// Licensed to the .NET Foundation under one or more agreements."); +writer.WriteLine("// The .NET Foundation licenses this file to you under the MIT license."); +writer.WriteLine(); + +// Namespace +writer.WriteLine("namespace Microsoft.AspNetCore.Http.Result;"); +writer.WriteLine(); + +for (int i = 1; i <= typeArgCount; i++) +{ + // Class summary doc + writer.WriteLine(@$"/// +/// Represents the result of an route handler delegate that can return {i.ToWords()} different types. +/// "); + + // Type params docs + for (int j = 1; j <= i; j++) + { + writer.WriteLine(@$"/// The {j.ToOrdinalWords()} result type."); + } + + // Class declaration + writer.Write($"public sealed class {className}<"); + + // Type args + for (int j = 1; j <= i; j++) + { + writer.Write($"{typeArgName}{j}"); + if (j != i) + { + writer.Write(", "); + } + } + + writer.WriteLine("> : IResult"); + + // Type arg contraints + for (int j = 1; j <= i; j++) + { + writer.Write($" where {typeArgName}{j} : IResult"); + if (j != i) + { + writer.Write(Environment.NewLine); + } + } + writer.WriteLine(); + writer.WriteLine("{"); + + // Ctor + writer.WriteLine($" private {className}(IResult activeResult)"); + writer.WriteLine(" {"); + writer.WriteLine(" Result = activeResult;"); + writer.WriteLine(" }"); + writer.WriteLine(); + + // Result property + writer.WriteLine(" /// "); + writer.WriteLine($" /// Gets the actual returned by the route handler delegate."); + writer.WriteLine(" /// "); + writer.WriteLine(" public IResult Result { get; }"); + writer.WriteLine(); + + // ExecuteAsync method + writer.WriteLine(" /// "); + writer.WriteLine(" /// Writes an HTTP response reflecting the result."); + writer.WriteLine(" /// "); + writer.WriteLine(" /// The for the current request."); + writer.WriteLine(" /// A that represents the asynchronous execute operation."); + writer.WriteLine(" public async Task ExecuteAsync(HttpContext httpContext)"); + writer.WriteLine(" {"); + writer.WriteLine(" ArgumentNullException.ThrowIfNull(httpContext, nameof(httpContext));"); + writer.WriteLine(); + writer.WriteLine(" await Result.ExecuteAsync(httpContext);"); + writer.WriteLine(" }"); + writer.WriteLine(); + + // Implicit converter operators + var sb = new StringBuilder(); + for (int j = 1; j <= i; j++) + { + sb.Append($"{typeArgName}{j}"); + if (j != i) + { + sb.Append(", "); + } + } + var typeArgsList = sb.ToString(); + + for (int j = 1; j <= i; j++) + { + writer.WriteLine(" /// "); + writer.WriteLine($" /// Converts the to a ."); + writer.WriteLine(" /// "); + writer.WriteLine(" /// The result."); + writer.WriteLine($" public static implicit operator {className}<{typeArgsList}>({typeArgName}{j} result) => new(result);"); + + if (i != j) + { + writer.WriteLine(); + } + } + + // Class end + writer.WriteLine("}"); + + if (i != typeArgCount) + { + writer.WriteLine(); + } +} + +writer.Flush(); + +static class StringExtensions +{ + public static string ToWords(this int number) => number switch + { + 1 => "one", + 2 => "two", + 3 => "three", + 4 => "four", + 5 => "five", + 6 => "six", + 7 => "seven", + 8 => "eight", + 9 => "nine", + 10 => "ten", + 11 => "eleven", + 12 => "twelve", + 13 => "thirteen", + 14 => "fourteen", + 15 => "fifteen", + 16 => "sixteen", + 17 => "seventeen", + 18 => "eighteen", + 19 => "nineteen", + 20 => "twenty", + _ => "!!unsupported!!" + }; + + public static string ToOrdinalWords(this int number) => number switch + { + 1 => "first", + 2 => "second", + 3 => "third", + 4 => "fourth", + 5 => "fifth", + 6 => "sixth", + 7 => "seventh", + 8 => "eighth", + 9 => "ninth", + 10 => "tenth", + 11 => "eleventh", + 12 => "twelfth", + 13 => "thirteenth", + 14 => "fourteenth", + 15 => "fifteenth", + 16 => "sixteenth", + 17 => "seventeenth", + 18 => "eighteenth", + 19 => "nineteenth", + 20 => "twentieth", + _ => "!!unsupported!!" + }; +} + +/* TEMPLATE +/// +/// Represents the result of an route handler delegate that can return ten different types. +/// +/// The first result type. +/// The second result type. +/// The third result type. +/// The fourth result type. +/// The fifth result type. +/// The sixth result type. +/// The seventh result type. +/// The eighth result type. +/// The ninth result type. +/// The tenth result type. +public sealed class Results : IResult + where TResult1 : IResult + where TResult2 : IResult + where TResult3 : IResult + where TResult4 : IResult + where TResult5 : IResult + where TResult6 : IResult + where TResult7 : IResult + where TResult8 : IResult + where TResult9 : IResult + where TResult10 : IResult +{ + private Results(IResult activeResult) + { + Result = activeResult; + } + + /// + /// Gets the actual returned by the route handler delegate. + /// + public IResult Result { get; } + + /// + /// Writes an HTTP response reflecting the result. + /// + /// The for the current request. + /// A that represents the asynchronous execute operation. + public async Task ExecuteAsync(HttpContext httpContext) + { + ArgumentNullException.ThrowIfNull(httpContext, nameof(httpContext)); + + await Result.ExecuteAsync(httpContext); + } + + /// + /// Converts the to a . + /// + /// The result. + public static implicit operator Results(TResult1 result) => new(result); + + /// + /// Converts the to a . + /// + /// The result. + public static implicit operator Results(TResult2 result) => new(result); + + /// + /// Converts the to a . + /// + /// The result. + public static implicit operator Results(TResult3 result) => new(result); + + /// + /// Converts the to a . + /// + /// The result. + public static implicit operator Results(TResult4 result) => new(result); + + /// + /// Converts the to a . + /// + /// The result. + public static implicit operator Results(TResult5 result) => new(result); + + /// + /// Converts the to a . + /// + /// The result. + public static implicit operator Results(TResult6 result) => new(result); + + /// + /// Converts the to a . + /// + /// The result. + public static implicit operator Results(TResult7 result) => new(result); + + /// + /// Converts the to a . + /// + /// The result. + public static implicit operator Results(TResult8 result) => new(result); + + /// + /// Converts the to a . + /// + /// The result. + public static implicit operator Results(TResult9 result) => new(result); + + /// + /// Converts the to a . + /// + /// The result. + public static implicit operator Results(TResult10 result) => new(result); + */ diff --git a/src/Http/Http.Results/tools/ResultsOfTGenerator/Properties/launchSettings.json b/src/Http/Http.Results/tools/ResultsOfTGenerator/Properties/launchSettings.json new file mode 100644 index 000000000000..79db7c956ac7 --- /dev/null +++ b/src/Http/Http.Results/tools/ResultsOfTGenerator/Properties/launchSettings.json @@ -0,0 +1,8 @@ +{ + "profiles": { + "ResultsOfTGenerator": { + "commandName": "Project", + "workingDirectory": "$(ProjectDir)\\..\\..\\src\\" + } + } +} diff --git a/src/Http/Http.Results/tools/ResultsOfTGenerator/ResultsOfTGenerator.csproj b/src/Http/Http.Results/tools/ResultsOfTGenerator/ResultsOfTGenerator.csproj new file mode 100644 index 000000000000..9d48f7e5cc34 --- /dev/null +++ b/src/Http/Http.Results/tools/ResultsOfTGenerator/ResultsOfTGenerator.csproj @@ -0,0 +1,9 @@ + + + + Exe + $(DefaultNetCoreTargetFramework) + enable + + + From b89af2ed668dbe458c4138c879d7440d4d6b38cb Mon Sep 17 00:00:00 2001 From: Damian Edwards Date: Wed, 30 Mar 2022 16:18:23 -0700 Subject: [PATCH 03/19] Update Http.Results.ResultsOfT - Add new API to PublicAPIUnshipped.txt - Suppress API baseline in code gen tool - Add code gen tool to the HttpAbstractsions.slnf file --- .../Http.Results/src/PublicAPI.Unshipped.txt | 184 ++++++++++++++++++ .../ResultsOfTGenerator.csproj | 1 + src/Http/HttpAbstractions.slnf | 1 + 3 files changed, 186 insertions(+) diff --git a/src/Http/Http.Results/src/PublicAPI.Unshipped.txt b/src/Http/Http.Results/src/PublicAPI.Unshipped.txt index b53f85370ac8..de620db27882 100644 --- a/src/Http/Http.Results/src/PublicAPI.Unshipped.txt +++ b/src/Http/Http.Results/src/PublicAPI.Unshipped.txt @@ -114,6 +114,54 @@ Microsoft.AspNetCore.Http.RedirectToRouteHttpResult.Permanent.get -> bool Microsoft.AspNetCore.Http.RedirectToRouteHttpResult.PreserveMethod.get -> bool Microsoft.AspNetCore.Http.RedirectToRouteHttpResult.RouteName.get -> string? Microsoft.AspNetCore.Http.RedirectToRouteHttpResult.RouteValues.get -> Microsoft.AspNetCore.Routing.RouteValueDictionary? +Microsoft.AspNetCore.Http.Result.Results +Microsoft.AspNetCore.Http.Result.Results.ExecuteAsync(Microsoft.AspNetCore.Http.HttpContext! httpContext) -> System.Threading.Tasks.Task! +Microsoft.AspNetCore.Http.Result.Results.Result.get -> Microsoft.AspNetCore.Http.IResult! +Microsoft.AspNetCore.Http.Result.Results +Microsoft.AspNetCore.Http.Result.Results.ExecuteAsync(Microsoft.AspNetCore.Http.HttpContext! httpContext) -> System.Threading.Tasks.Task! +Microsoft.AspNetCore.Http.Result.Results.Result.get -> Microsoft.AspNetCore.Http.IResult! +Microsoft.AspNetCore.Http.Result.Results +Microsoft.AspNetCore.Http.Result.Results.ExecuteAsync(Microsoft.AspNetCore.Http.HttpContext! httpContext) -> System.Threading.Tasks.Task! +Microsoft.AspNetCore.Http.Result.Results.Result.get -> Microsoft.AspNetCore.Http.IResult! +Microsoft.AspNetCore.Http.Result.Results +Microsoft.AspNetCore.Http.Result.Results.ExecuteAsync(Microsoft.AspNetCore.Http.HttpContext! httpContext) -> System.Threading.Tasks.Task! +Microsoft.AspNetCore.Http.Result.Results.Result.get -> Microsoft.AspNetCore.Http.IResult! +Microsoft.AspNetCore.Http.Result.Results +Microsoft.AspNetCore.Http.Result.Results.ExecuteAsync(Microsoft.AspNetCore.Http.HttpContext! httpContext) -> System.Threading.Tasks.Task! +Microsoft.AspNetCore.Http.Result.Results.Result.get -> Microsoft.AspNetCore.Http.IResult! +Microsoft.AspNetCore.Http.Result.Results +Microsoft.AspNetCore.Http.Result.Results.ExecuteAsync(Microsoft.AspNetCore.Http.HttpContext! httpContext) -> System.Threading.Tasks.Task! +Microsoft.AspNetCore.Http.Result.Results.Result.get -> Microsoft.AspNetCore.Http.IResult! +Microsoft.AspNetCore.Http.Result.Results +Microsoft.AspNetCore.Http.Result.Results.ExecuteAsync(Microsoft.AspNetCore.Http.HttpContext! httpContext) -> System.Threading.Tasks.Task! +Microsoft.AspNetCore.Http.Result.Results.Result.get -> Microsoft.AspNetCore.Http.IResult! +Microsoft.AspNetCore.Http.Result.Results +Microsoft.AspNetCore.Http.Result.Results.ExecuteAsync(Microsoft.AspNetCore.Http.HttpContext! httpContext) -> System.Threading.Tasks.Task! +Microsoft.AspNetCore.Http.Result.Results.Result.get -> Microsoft.AspNetCore.Http.IResult! +Microsoft.AspNetCore.Http.Result.Results +Microsoft.AspNetCore.Http.Result.Results.ExecuteAsync(Microsoft.AspNetCore.Http.HttpContext! httpContext) -> System.Threading.Tasks.Task! +Microsoft.AspNetCore.Http.Result.Results.Result.get -> Microsoft.AspNetCore.Http.IResult! +Microsoft.AspNetCore.Http.Result.Results +Microsoft.AspNetCore.Http.Result.Results.ExecuteAsync(Microsoft.AspNetCore.Http.HttpContext! httpContext) -> System.Threading.Tasks.Task! +Microsoft.AspNetCore.Http.Result.Results.Result.get -> Microsoft.AspNetCore.Http.IResult! +Microsoft.AspNetCore.Http.Result.Results +Microsoft.AspNetCore.Http.Result.Results.ExecuteAsync(Microsoft.AspNetCore.Http.HttpContext! httpContext) -> System.Threading.Tasks.Task! +Microsoft.AspNetCore.Http.Result.Results.Result.get -> Microsoft.AspNetCore.Http.IResult! +Microsoft.AspNetCore.Http.Result.Results +Microsoft.AspNetCore.Http.Result.Results.ExecuteAsync(Microsoft.AspNetCore.Http.HttpContext! httpContext) -> System.Threading.Tasks.Task! +Microsoft.AspNetCore.Http.Result.Results.Result.get -> Microsoft.AspNetCore.Http.IResult! +Microsoft.AspNetCore.Http.Result.Results +Microsoft.AspNetCore.Http.Result.Results.ExecuteAsync(Microsoft.AspNetCore.Http.HttpContext! httpContext) -> System.Threading.Tasks.Task! +Microsoft.AspNetCore.Http.Result.Results.Result.get -> Microsoft.AspNetCore.Http.IResult! +Microsoft.AspNetCore.Http.Result.Results +Microsoft.AspNetCore.Http.Result.Results.ExecuteAsync(Microsoft.AspNetCore.Http.HttpContext! httpContext) -> System.Threading.Tasks.Task! +Microsoft.AspNetCore.Http.Result.Results.Result.get -> Microsoft.AspNetCore.Http.IResult! +Microsoft.AspNetCore.Http.Result.Results +Microsoft.AspNetCore.Http.Result.Results.ExecuteAsync(Microsoft.AspNetCore.Http.HttpContext! httpContext) -> System.Threading.Tasks.Task! +Microsoft.AspNetCore.Http.Result.Results.Result.get -> Microsoft.AspNetCore.Http.IResult! +Microsoft.AspNetCore.Http.Result.Results +Microsoft.AspNetCore.Http.Result.Results.ExecuteAsync(Microsoft.AspNetCore.Http.HttpContext! httpContext) -> System.Threading.Tasks.Task! +Microsoft.AspNetCore.Http.Result.Results.Result.get -> Microsoft.AspNetCore.Http.IResult! Microsoft.AspNetCore.Http.SignInHttpResult Microsoft.AspNetCore.Http.SignInHttpResult.AuthenticationScheme.get -> string? Microsoft.AspNetCore.Http.SignInHttpResult.ExecuteAsync(Microsoft.AspNetCore.Http.HttpContext! httpContext) -> System.Threading.Tasks.Task! @@ -143,6 +191,142 @@ Microsoft.AspNetCore.Http.VirtualFileHttpResult.FileLength.get -> long? Microsoft.AspNetCore.Http.VirtualFileHttpResult.FileName.get -> string! Microsoft.AspNetCore.Http.VirtualFileHttpResult.LastModified.get -> System.DateTimeOffset? static Microsoft.AspNetCore.Http.EmptyHttpResult.Instance.get -> Microsoft.AspNetCore.Http.EmptyHttpResult! +static Microsoft.AspNetCore.Http.Result.Results.implicit operator Microsoft.AspNetCore.Http.Result.Results!(TResult1 result) -> Microsoft.AspNetCore.Http.Result.Results! +static Microsoft.AspNetCore.Http.Result.Results.implicit operator Microsoft.AspNetCore.Http.Result.Results!(TResult10 result) -> Microsoft.AspNetCore.Http.Result.Results! +static Microsoft.AspNetCore.Http.Result.Results.implicit operator Microsoft.AspNetCore.Http.Result.Results!(TResult11 result) -> Microsoft.AspNetCore.Http.Result.Results! +static Microsoft.AspNetCore.Http.Result.Results.implicit operator Microsoft.AspNetCore.Http.Result.Results!(TResult12 result) -> Microsoft.AspNetCore.Http.Result.Results! +static Microsoft.AspNetCore.Http.Result.Results.implicit operator Microsoft.AspNetCore.Http.Result.Results!(TResult13 result) -> Microsoft.AspNetCore.Http.Result.Results! +static Microsoft.AspNetCore.Http.Result.Results.implicit operator Microsoft.AspNetCore.Http.Result.Results!(TResult14 result) -> Microsoft.AspNetCore.Http.Result.Results! +static Microsoft.AspNetCore.Http.Result.Results.implicit operator Microsoft.AspNetCore.Http.Result.Results!(TResult15 result) -> Microsoft.AspNetCore.Http.Result.Results! +static Microsoft.AspNetCore.Http.Result.Results.implicit operator Microsoft.AspNetCore.Http.Result.Results!(TResult16 result) -> Microsoft.AspNetCore.Http.Result.Results! +static Microsoft.AspNetCore.Http.Result.Results.implicit operator Microsoft.AspNetCore.Http.Result.Results!(TResult2 result) -> Microsoft.AspNetCore.Http.Result.Results! +static Microsoft.AspNetCore.Http.Result.Results.implicit operator Microsoft.AspNetCore.Http.Result.Results!(TResult3 result) -> Microsoft.AspNetCore.Http.Result.Results! +static Microsoft.AspNetCore.Http.Result.Results.implicit operator Microsoft.AspNetCore.Http.Result.Results!(TResult4 result) -> Microsoft.AspNetCore.Http.Result.Results! +static Microsoft.AspNetCore.Http.Result.Results.implicit operator Microsoft.AspNetCore.Http.Result.Results!(TResult5 result) -> Microsoft.AspNetCore.Http.Result.Results! +static Microsoft.AspNetCore.Http.Result.Results.implicit operator Microsoft.AspNetCore.Http.Result.Results!(TResult6 result) -> Microsoft.AspNetCore.Http.Result.Results! +static Microsoft.AspNetCore.Http.Result.Results.implicit operator Microsoft.AspNetCore.Http.Result.Results!(TResult7 result) -> Microsoft.AspNetCore.Http.Result.Results! +static Microsoft.AspNetCore.Http.Result.Results.implicit operator Microsoft.AspNetCore.Http.Result.Results!(TResult8 result) -> Microsoft.AspNetCore.Http.Result.Results! +static Microsoft.AspNetCore.Http.Result.Results.implicit operator Microsoft.AspNetCore.Http.Result.Results!(TResult9 result) -> Microsoft.AspNetCore.Http.Result.Results! +static Microsoft.AspNetCore.Http.Result.Results.implicit operator Microsoft.AspNetCore.Http.Result.Results!(TResult1 result) -> Microsoft.AspNetCore.Http.Result.Results! +static Microsoft.AspNetCore.Http.Result.Results.implicit operator Microsoft.AspNetCore.Http.Result.Results!(TResult10 result) -> Microsoft.AspNetCore.Http.Result.Results! +static Microsoft.AspNetCore.Http.Result.Results.implicit operator Microsoft.AspNetCore.Http.Result.Results!(TResult11 result) -> Microsoft.AspNetCore.Http.Result.Results! +static Microsoft.AspNetCore.Http.Result.Results.implicit operator Microsoft.AspNetCore.Http.Result.Results!(TResult12 result) -> Microsoft.AspNetCore.Http.Result.Results! +static Microsoft.AspNetCore.Http.Result.Results.implicit operator Microsoft.AspNetCore.Http.Result.Results!(TResult13 result) -> Microsoft.AspNetCore.Http.Result.Results! +static Microsoft.AspNetCore.Http.Result.Results.implicit operator Microsoft.AspNetCore.Http.Result.Results!(TResult14 result) -> Microsoft.AspNetCore.Http.Result.Results! +static Microsoft.AspNetCore.Http.Result.Results.implicit operator Microsoft.AspNetCore.Http.Result.Results!(TResult15 result) -> Microsoft.AspNetCore.Http.Result.Results! +static Microsoft.AspNetCore.Http.Result.Results.implicit operator Microsoft.AspNetCore.Http.Result.Results!(TResult2 result) -> Microsoft.AspNetCore.Http.Result.Results! +static Microsoft.AspNetCore.Http.Result.Results.implicit operator Microsoft.AspNetCore.Http.Result.Results!(TResult3 result) -> Microsoft.AspNetCore.Http.Result.Results! +static Microsoft.AspNetCore.Http.Result.Results.implicit operator Microsoft.AspNetCore.Http.Result.Results!(TResult4 result) -> Microsoft.AspNetCore.Http.Result.Results! +static Microsoft.AspNetCore.Http.Result.Results.implicit operator Microsoft.AspNetCore.Http.Result.Results!(TResult5 result) -> Microsoft.AspNetCore.Http.Result.Results! +static Microsoft.AspNetCore.Http.Result.Results.implicit operator Microsoft.AspNetCore.Http.Result.Results!(TResult6 result) -> Microsoft.AspNetCore.Http.Result.Results! +static Microsoft.AspNetCore.Http.Result.Results.implicit operator Microsoft.AspNetCore.Http.Result.Results!(TResult7 result) -> Microsoft.AspNetCore.Http.Result.Results! +static Microsoft.AspNetCore.Http.Result.Results.implicit operator Microsoft.AspNetCore.Http.Result.Results!(TResult8 result) -> Microsoft.AspNetCore.Http.Result.Results! +static Microsoft.AspNetCore.Http.Result.Results.implicit operator Microsoft.AspNetCore.Http.Result.Results!(TResult9 result) -> Microsoft.AspNetCore.Http.Result.Results! +static Microsoft.AspNetCore.Http.Result.Results.implicit operator Microsoft.AspNetCore.Http.Result.Results!(TResult1 result) -> Microsoft.AspNetCore.Http.Result.Results! +static Microsoft.AspNetCore.Http.Result.Results.implicit operator Microsoft.AspNetCore.Http.Result.Results!(TResult10 result) -> Microsoft.AspNetCore.Http.Result.Results! +static Microsoft.AspNetCore.Http.Result.Results.implicit operator Microsoft.AspNetCore.Http.Result.Results!(TResult11 result) -> Microsoft.AspNetCore.Http.Result.Results! +static Microsoft.AspNetCore.Http.Result.Results.implicit operator Microsoft.AspNetCore.Http.Result.Results!(TResult12 result) -> Microsoft.AspNetCore.Http.Result.Results! +static Microsoft.AspNetCore.Http.Result.Results.implicit operator Microsoft.AspNetCore.Http.Result.Results!(TResult13 result) -> Microsoft.AspNetCore.Http.Result.Results! +static Microsoft.AspNetCore.Http.Result.Results.implicit operator Microsoft.AspNetCore.Http.Result.Results!(TResult14 result) -> Microsoft.AspNetCore.Http.Result.Results! +static Microsoft.AspNetCore.Http.Result.Results.implicit operator Microsoft.AspNetCore.Http.Result.Results!(TResult2 result) -> Microsoft.AspNetCore.Http.Result.Results! +static Microsoft.AspNetCore.Http.Result.Results.implicit operator Microsoft.AspNetCore.Http.Result.Results!(TResult3 result) -> Microsoft.AspNetCore.Http.Result.Results! +static Microsoft.AspNetCore.Http.Result.Results.implicit operator Microsoft.AspNetCore.Http.Result.Results!(TResult4 result) -> Microsoft.AspNetCore.Http.Result.Results! +static Microsoft.AspNetCore.Http.Result.Results.implicit operator Microsoft.AspNetCore.Http.Result.Results!(TResult5 result) -> Microsoft.AspNetCore.Http.Result.Results! +static Microsoft.AspNetCore.Http.Result.Results.implicit operator Microsoft.AspNetCore.Http.Result.Results!(TResult6 result) -> Microsoft.AspNetCore.Http.Result.Results! +static Microsoft.AspNetCore.Http.Result.Results.implicit operator Microsoft.AspNetCore.Http.Result.Results!(TResult7 result) -> Microsoft.AspNetCore.Http.Result.Results! +static Microsoft.AspNetCore.Http.Result.Results.implicit operator Microsoft.AspNetCore.Http.Result.Results!(TResult8 result) -> Microsoft.AspNetCore.Http.Result.Results! +static Microsoft.AspNetCore.Http.Result.Results.implicit operator Microsoft.AspNetCore.Http.Result.Results!(TResult9 result) -> Microsoft.AspNetCore.Http.Result.Results! +static Microsoft.AspNetCore.Http.Result.Results.implicit operator Microsoft.AspNetCore.Http.Result.Results!(TResult1 result) -> Microsoft.AspNetCore.Http.Result.Results! +static Microsoft.AspNetCore.Http.Result.Results.implicit operator Microsoft.AspNetCore.Http.Result.Results!(TResult10 result) -> Microsoft.AspNetCore.Http.Result.Results! +static Microsoft.AspNetCore.Http.Result.Results.implicit operator Microsoft.AspNetCore.Http.Result.Results!(TResult11 result) -> Microsoft.AspNetCore.Http.Result.Results! +static Microsoft.AspNetCore.Http.Result.Results.implicit operator Microsoft.AspNetCore.Http.Result.Results!(TResult12 result) -> Microsoft.AspNetCore.Http.Result.Results! +static Microsoft.AspNetCore.Http.Result.Results.implicit operator Microsoft.AspNetCore.Http.Result.Results!(TResult13 result) -> Microsoft.AspNetCore.Http.Result.Results! +static Microsoft.AspNetCore.Http.Result.Results.implicit operator Microsoft.AspNetCore.Http.Result.Results!(TResult2 result) -> Microsoft.AspNetCore.Http.Result.Results! +static Microsoft.AspNetCore.Http.Result.Results.implicit operator Microsoft.AspNetCore.Http.Result.Results!(TResult3 result) -> Microsoft.AspNetCore.Http.Result.Results! +static Microsoft.AspNetCore.Http.Result.Results.implicit operator Microsoft.AspNetCore.Http.Result.Results!(TResult4 result) -> Microsoft.AspNetCore.Http.Result.Results! +static Microsoft.AspNetCore.Http.Result.Results.implicit operator Microsoft.AspNetCore.Http.Result.Results!(TResult5 result) -> Microsoft.AspNetCore.Http.Result.Results! +static Microsoft.AspNetCore.Http.Result.Results.implicit operator Microsoft.AspNetCore.Http.Result.Results!(TResult6 result) -> Microsoft.AspNetCore.Http.Result.Results! +static Microsoft.AspNetCore.Http.Result.Results.implicit operator Microsoft.AspNetCore.Http.Result.Results!(TResult7 result) -> Microsoft.AspNetCore.Http.Result.Results! +static Microsoft.AspNetCore.Http.Result.Results.implicit operator Microsoft.AspNetCore.Http.Result.Results!(TResult8 result) -> Microsoft.AspNetCore.Http.Result.Results! +static Microsoft.AspNetCore.Http.Result.Results.implicit operator Microsoft.AspNetCore.Http.Result.Results!(TResult9 result) -> Microsoft.AspNetCore.Http.Result.Results! +static Microsoft.AspNetCore.Http.Result.Results.implicit operator Microsoft.AspNetCore.Http.Result.Results!(TResult1 result) -> Microsoft.AspNetCore.Http.Result.Results! +static Microsoft.AspNetCore.Http.Result.Results.implicit operator Microsoft.AspNetCore.Http.Result.Results!(TResult10 result) -> Microsoft.AspNetCore.Http.Result.Results! +static Microsoft.AspNetCore.Http.Result.Results.implicit operator Microsoft.AspNetCore.Http.Result.Results!(TResult11 result) -> Microsoft.AspNetCore.Http.Result.Results! +static Microsoft.AspNetCore.Http.Result.Results.implicit operator Microsoft.AspNetCore.Http.Result.Results!(TResult12 result) -> Microsoft.AspNetCore.Http.Result.Results! +static Microsoft.AspNetCore.Http.Result.Results.implicit operator Microsoft.AspNetCore.Http.Result.Results!(TResult2 result) -> Microsoft.AspNetCore.Http.Result.Results! +static Microsoft.AspNetCore.Http.Result.Results.implicit operator Microsoft.AspNetCore.Http.Result.Results!(TResult3 result) -> Microsoft.AspNetCore.Http.Result.Results! +static Microsoft.AspNetCore.Http.Result.Results.implicit operator Microsoft.AspNetCore.Http.Result.Results!(TResult4 result) -> Microsoft.AspNetCore.Http.Result.Results! +static Microsoft.AspNetCore.Http.Result.Results.implicit operator Microsoft.AspNetCore.Http.Result.Results!(TResult5 result) -> Microsoft.AspNetCore.Http.Result.Results! +static Microsoft.AspNetCore.Http.Result.Results.implicit operator Microsoft.AspNetCore.Http.Result.Results!(TResult6 result) -> Microsoft.AspNetCore.Http.Result.Results! +static Microsoft.AspNetCore.Http.Result.Results.implicit operator Microsoft.AspNetCore.Http.Result.Results!(TResult7 result) -> Microsoft.AspNetCore.Http.Result.Results! +static Microsoft.AspNetCore.Http.Result.Results.implicit operator Microsoft.AspNetCore.Http.Result.Results!(TResult8 result) -> Microsoft.AspNetCore.Http.Result.Results! +static Microsoft.AspNetCore.Http.Result.Results.implicit operator Microsoft.AspNetCore.Http.Result.Results!(TResult9 result) -> Microsoft.AspNetCore.Http.Result.Results! +static Microsoft.AspNetCore.Http.Result.Results.implicit operator Microsoft.AspNetCore.Http.Result.Results!(TResult1 result) -> Microsoft.AspNetCore.Http.Result.Results! +static Microsoft.AspNetCore.Http.Result.Results.implicit operator Microsoft.AspNetCore.Http.Result.Results!(TResult10 result) -> Microsoft.AspNetCore.Http.Result.Results! +static Microsoft.AspNetCore.Http.Result.Results.implicit operator Microsoft.AspNetCore.Http.Result.Results!(TResult11 result) -> Microsoft.AspNetCore.Http.Result.Results! +static Microsoft.AspNetCore.Http.Result.Results.implicit operator Microsoft.AspNetCore.Http.Result.Results!(TResult2 result) -> Microsoft.AspNetCore.Http.Result.Results! +static Microsoft.AspNetCore.Http.Result.Results.implicit operator Microsoft.AspNetCore.Http.Result.Results!(TResult3 result) -> Microsoft.AspNetCore.Http.Result.Results! +static Microsoft.AspNetCore.Http.Result.Results.implicit operator Microsoft.AspNetCore.Http.Result.Results!(TResult4 result) -> Microsoft.AspNetCore.Http.Result.Results! +static Microsoft.AspNetCore.Http.Result.Results.implicit operator Microsoft.AspNetCore.Http.Result.Results!(TResult5 result) -> Microsoft.AspNetCore.Http.Result.Results! +static Microsoft.AspNetCore.Http.Result.Results.implicit operator Microsoft.AspNetCore.Http.Result.Results!(TResult6 result) -> Microsoft.AspNetCore.Http.Result.Results! +static Microsoft.AspNetCore.Http.Result.Results.implicit operator Microsoft.AspNetCore.Http.Result.Results!(TResult7 result) -> Microsoft.AspNetCore.Http.Result.Results! +static Microsoft.AspNetCore.Http.Result.Results.implicit operator Microsoft.AspNetCore.Http.Result.Results!(TResult8 result) -> Microsoft.AspNetCore.Http.Result.Results! +static Microsoft.AspNetCore.Http.Result.Results.implicit operator Microsoft.AspNetCore.Http.Result.Results!(TResult9 result) -> Microsoft.AspNetCore.Http.Result.Results! +static Microsoft.AspNetCore.Http.Result.Results.implicit operator Microsoft.AspNetCore.Http.Result.Results!(TResult1 result) -> Microsoft.AspNetCore.Http.Result.Results! +static Microsoft.AspNetCore.Http.Result.Results.implicit operator Microsoft.AspNetCore.Http.Result.Results!(TResult10 result) -> Microsoft.AspNetCore.Http.Result.Results! +static Microsoft.AspNetCore.Http.Result.Results.implicit operator Microsoft.AspNetCore.Http.Result.Results!(TResult2 result) -> Microsoft.AspNetCore.Http.Result.Results! +static Microsoft.AspNetCore.Http.Result.Results.implicit operator Microsoft.AspNetCore.Http.Result.Results!(TResult3 result) -> Microsoft.AspNetCore.Http.Result.Results! +static Microsoft.AspNetCore.Http.Result.Results.implicit operator Microsoft.AspNetCore.Http.Result.Results!(TResult4 result) -> Microsoft.AspNetCore.Http.Result.Results! +static Microsoft.AspNetCore.Http.Result.Results.implicit operator Microsoft.AspNetCore.Http.Result.Results!(TResult5 result) -> Microsoft.AspNetCore.Http.Result.Results! +static Microsoft.AspNetCore.Http.Result.Results.implicit operator Microsoft.AspNetCore.Http.Result.Results!(TResult6 result) -> Microsoft.AspNetCore.Http.Result.Results! +static Microsoft.AspNetCore.Http.Result.Results.implicit operator Microsoft.AspNetCore.Http.Result.Results!(TResult7 result) -> Microsoft.AspNetCore.Http.Result.Results! +static Microsoft.AspNetCore.Http.Result.Results.implicit operator Microsoft.AspNetCore.Http.Result.Results!(TResult8 result) -> Microsoft.AspNetCore.Http.Result.Results! +static Microsoft.AspNetCore.Http.Result.Results.implicit operator Microsoft.AspNetCore.Http.Result.Results!(TResult9 result) -> Microsoft.AspNetCore.Http.Result.Results! +static Microsoft.AspNetCore.Http.Result.Results.implicit operator Microsoft.AspNetCore.Http.Result.Results!(TResult1 result) -> Microsoft.AspNetCore.Http.Result.Results! +static Microsoft.AspNetCore.Http.Result.Results.implicit operator Microsoft.AspNetCore.Http.Result.Results!(TResult2 result) -> Microsoft.AspNetCore.Http.Result.Results! +static Microsoft.AspNetCore.Http.Result.Results.implicit operator Microsoft.AspNetCore.Http.Result.Results!(TResult3 result) -> Microsoft.AspNetCore.Http.Result.Results! +static Microsoft.AspNetCore.Http.Result.Results.implicit operator Microsoft.AspNetCore.Http.Result.Results!(TResult4 result) -> Microsoft.AspNetCore.Http.Result.Results! +static Microsoft.AspNetCore.Http.Result.Results.implicit operator Microsoft.AspNetCore.Http.Result.Results!(TResult5 result) -> Microsoft.AspNetCore.Http.Result.Results! +static Microsoft.AspNetCore.Http.Result.Results.implicit operator Microsoft.AspNetCore.Http.Result.Results!(TResult6 result) -> Microsoft.AspNetCore.Http.Result.Results! +static Microsoft.AspNetCore.Http.Result.Results.implicit operator Microsoft.AspNetCore.Http.Result.Results!(TResult7 result) -> Microsoft.AspNetCore.Http.Result.Results! +static Microsoft.AspNetCore.Http.Result.Results.implicit operator Microsoft.AspNetCore.Http.Result.Results!(TResult8 result) -> Microsoft.AspNetCore.Http.Result.Results! +static Microsoft.AspNetCore.Http.Result.Results.implicit operator Microsoft.AspNetCore.Http.Result.Results!(TResult9 result) -> Microsoft.AspNetCore.Http.Result.Results! +static Microsoft.AspNetCore.Http.Result.Results.implicit operator Microsoft.AspNetCore.Http.Result.Results!(TResult1 result) -> Microsoft.AspNetCore.Http.Result.Results! +static Microsoft.AspNetCore.Http.Result.Results.implicit operator Microsoft.AspNetCore.Http.Result.Results!(TResult2 result) -> Microsoft.AspNetCore.Http.Result.Results! +static Microsoft.AspNetCore.Http.Result.Results.implicit operator Microsoft.AspNetCore.Http.Result.Results!(TResult3 result) -> Microsoft.AspNetCore.Http.Result.Results! +static Microsoft.AspNetCore.Http.Result.Results.implicit operator Microsoft.AspNetCore.Http.Result.Results!(TResult4 result) -> Microsoft.AspNetCore.Http.Result.Results! +static Microsoft.AspNetCore.Http.Result.Results.implicit operator Microsoft.AspNetCore.Http.Result.Results!(TResult5 result) -> Microsoft.AspNetCore.Http.Result.Results! +static Microsoft.AspNetCore.Http.Result.Results.implicit operator Microsoft.AspNetCore.Http.Result.Results!(TResult6 result) -> Microsoft.AspNetCore.Http.Result.Results! +static Microsoft.AspNetCore.Http.Result.Results.implicit operator Microsoft.AspNetCore.Http.Result.Results!(TResult7 result) -> Microsoft.AspNetCore.Http.Result.Results! +static Microsoft.AspNetCore.Http.Result.Results.implicit operator Microsoft.AspNetCore.Http.Result.Results!(TResult8 result) -> Microsoft.AspNetCore.Http.Result.Results! +static Microsoft.AspNetCore.Http.Result.Results.implicit operator Microsoft.AspNetCore.Http.Result.Results!(TResult1 result) -> Microsoft.AspNetCore.Http.Result.Results! +static Microsoft.AspNetCore.Http.Result.Results.implicit operator Microsoft.AspNetCore.Http.Result.Results!(TResult2 result) -> Microsoft.AspNetCore.Http.Result.Results! +static Microsoft.AspNetCore.Http.Result.Results.implicit operator Microsoft.AspNetCore.Http.Result.Results!(TResult3 result) -> Microsoft.AspNetCore.Http.Result.Results! +static Microsoft.AspNetCore.Http.Result.Results.implicit operator Microsoft.AspNetCore.Http.Result.Results!(TResult4 result) -> Microsoft.AspNetCore.Http.Result.Results! +static Microsoft.AspNetCore.Http.Result.Results.implicit operator Microsoft.AspNetCore.Http.Result.Results!(TResult5 result) -> Microsoft.AspNetCore.Http.Result.Results! +static Microsoft.AspNetCore.Http.Result.Results.implicit operator Microsoft.AspNetCore.Http.Result.Results!(TResult6 result) -> Microsoft.AspNetCore.Http.Result.Results! +static Microsoft.AspNetCore.Http.Result.Results.implicit operator Microsoft.AspNetCore.Http.Result.Results!(TResult7 result) -> Microsoft.AspNetCore.Http.Result.Results! +static Microsoft.AspNetCore.Http.Result.Results.implicit operator Microsoft.AspNetCore.Http.Result.Results!(TResult1 result) -> Microsoft.AspNetCore.Http.Result.Results! +static Microsoft.AspNetCore.Http.Result.Results.implicit operator Microsoft.AspNetCore.Http.Result.Results!(TResult2 result) -> Microsoft.AspNetCore.Http.Result.Results! +static Microsoft.AspNetCore.Http.Result.Results.implicit operator Microsoft.AspNetCore.Http.Result.Results!(TResult3 result) -> Microsoft.AspNetCore.Http.Result.Results! +static Microsoft.AspNetCore.Http.Result.Results.implicit operator Microsoft.AspNetCore.Http.Result.Results!(TResult4 result) -> Microsoft.AspNetCore.Http.Result.Results! +static Microsoft.AspNetCore.Http.Result.Results.implicit operator Microsoft.AspNetCore.Http.Result.Results!(TResult5 result) -> Microsoft.AspNetCore.Http.Result.Results! +static Microsoft.AspNetCore.Http.Result.Results.implicit operator Microsoft.AspNetCore.Http.Result.Results!(TResult6 result) -> Microsoft.AspNetCore.Http.Result.Results! +static Microsoft.AspNetCore.Http.Result.Results.implicit operator Microsoft.AspNetCore.Http.Result.Results!(TResult1 result) -> Microsoft.AspNetCore.Http.Result.Results! +static Microsoft.AspNetCore.Http.Result.Results.implicit operator Microsoft.AspNetCore.Http.Result.Results!(TResult2 result) -> Microsoft.AspNetCore.Http.Result.Results! +static Microsoft.AspNetCore.Http.Result.Results.implicit operator Microsoft.AspNetCore.Http.Result.Results!(TResult3 result) -> Microsoft.AspNetCore.Http.Result.Results! +static Microsoft.AspNetCore.Http.Result.Results.implicit operator Microsoft.AspNetCore.Http.Result.Results!(TResult4 result) -> Microsoft.AspNetCore.Http.Result.Results! +static Microsoft.AspNetCore.Http.Result.Results.implicit operator Microsoft.AspNetCore.Http.Result.Results!(TResult5 result) -> Microsoft.AspNetCore.Http.Result.Results! +static Microsoft.AspNetCore.Http.Result.Results.implicit operator Microsoft.AspNetCore.Http.Result.Results!(TResult1 result) -> Microsoft.AspNetCore.Http.Result.Results! +static Microsoft.AspNetCore.Http.Result.Results.implicit operator Microsoft.AspNetCore.Http.Result.Results!(TResult2 result) -> Microsoft.AspNetCore.Http.Result.Results! +static Microsoft.AspNetCore.Http.Result.Results.implicit operator Microsoft.AspNetCore.Http.Result.Results!(TResult3 result) -> Microsoft.AspNetCore.Http.Result.Results! +static Microsoft.AspNetCore.Http.Result.Results.implicit operator Microsoft.AspNetCore.Http.Result.Results!(TResult4 result) -> Microsoft.AspNetCore.Http.Result.Results! +static Microsoft.AspNetCore.Http.Result.Results.implicit operator Microsoft.AspNetCore.Http.Result.Results!(TResult1 result) -> Microsoft.AspNetCore.Http.Result.Results! +static Microsoft.AspNetCore.Http.Result.Results.implicit operator Microsoft.AspNetCore.Http.Result.Results!(TResult2 result) -> Microsoft.AspNetCore.Http.Result.Results! +static Microsoft.AspNetCore.Http.Result.Results.implicit operator Microsoft.AspNetCore.Http.Result.Results!(TResult3 result) -> Microsoft.AspNetCore.Http.Result.Results! +static Microsoft.AspNetCore.Http.Result.Results.implicit operator Microsoft.AspNetCore.Http.Result.Results!(TResult1 result) -> Microsoft.AspNetCore.Http.Result.Results! +static Microsoft.AspNetCore.Http.Result.Results.implicit operator Microsoft.AspNetCore.Http.Result.Results!(TResult2 result) -> Microsoft.AspNetCore.Http.Result.Results! +static Microsoft.AspNetCore.Http.Result.Results.implicit operator Microsoft.AspNetCore.Http.Result.Results!(TResult1 result) -> Microsoft.AspNetCore.Http.Result.Results! static Microsoft.AspNetCore.Http.Results.Bytes(System.ReadOnlyMemory contents, string? contentType = null, string? fileDownloadName = null, bool enableRangeProcessing = false, System.DateTimeOffset? lastModified = null, Microsoft.Net.Http.Headers.EntityTagHeaderValue? entityTag = null) -> Microsoft.AspNetCore.Http.IResult! static Microsoft.AspNetCore.Http.Results.Empty.get -> Microsoft.AspNetCore.Http.IResult! static Microsoft.AspNetCore.Http.Results.Stream(System.Func! streamWriterCallback, string? contentType = null, string? fileDownloadName = null, System.DateTimeOffset? lastModified = null, Microsoft.Net.Http.Headers.EntityTagHeaderValue? entityTag = null) -> Microsoft.AspNetCore.Http.IResult! diff --git a/src/Http/Http.Results/tools/ResultsOfTGenerator/ResultsOfTGenerator.csproj b/src/Http/Http.Results/tools/ResultsOfTGenerator/ResultsOfTGenerator.csproj index 9d48f7e5cc34..7659c277810a 100644 --- a/src/Http/Http.Results/tools/ResultsOfTGenerator/ResultsOfTGenerator.csproj +++ b/src/Http/Http.Results/tools/ResultsOfTGenerator/ResultsOfTGenerator.csproj @@ -4,6 +4,7 @@ Exe $(DefaultNetCoreTargetFramework) enable + false diff --git a/src/Http/HttpAbstractions.slnf b/src/Http/HttpAbstractions.slnf index 0551c10841a0..70fc8b56f6a8 100644 --- a/src/Http/HttpAbstractions.slnf +++ b/src/Http/HttpAbstractions.slnf @@ -21,6 +21,7 @@ "src\\Http\\Http.Features\\src\\Microsoft.AspNetCore.Http.Features.csproj", "src\\Http\\Http.Results\\src\\Microsoft.AspNetCore.Http.Results.csproj", "src\\Http\\Http.Results\\test\\Microsoft.AspNetCore.Http.Results.Tests.csproj", + "src\\Http\\Http.Results\\tools\\ResultsOfTGenerator\\ResultsOfTGenerator.csproj", "src\\Http\\Http\\perf\\Microbenchmarks\\Microsoft.AspNetCore.Http.Microbenchmarks.csproj", "src\\Http\\Http\\src\\Microsoft.AspNetCore.Http.csproj", "src\\Http\\Http\\test\\Microsoft.AspNetCore.Http.Tests.csproj", From 2cb11bc47e87ea4fc3c6b3c1a50a90d46bc8c780 Mon Sep 17 00:00:00 2001 From: Damian Edwards Date: Wed, 30 Mar 2022 16:31:43 -0700 Subject: [PATCH 04/19] ResultsOfT updates - Added README.md explaining ResultsOfT code generator tool - Added comment to top of ResultsOfT.cs pointing to code generator tool - Updated Http\README.md to include Http.Results --- src/Http/Http.Results/README.md | 13 +++++++++++++ src/Http/Http.Results/src/ResultsOfT.cs | 1 + .../tools/ResultsOfTGenerator/Program.cs | 1 + src/Http/README.md | 1 + 4 files changed, 16 insertions(+) create mode 100644 src/Http/Http.Results/README.md diff --git a/src/Http/Http.Results/README.md b/src/Http/Http.Results/README.md new file mode 100644 index 000000000000..d33d143c9868 --- /dev/null +++ b/src/Http/Http.Results/README.md @@ -0,0 +1,13 @@ +# ASP.NET Core Http.Results + +Http.Results contains the in-framework implementations of the `IResult` interface returned from Minimal APIs route handler delegates, e.g. `OkHttpResult`, `NoContentHttpResult`, etc. + +## Development Setup + +The `Results` union types are generated. Modify and run the [ResultsOfTGenerator](tools/ResultsOfTGenerator/) tool to generate an updated `ResultsOfT.cs` class file. + +Run the following command in `src\Http\Http.Results\tools\ResultsOfTGenerator`: + +``` +dotnet run +``` \ No newline at end of file diff --git a/src/Http/Http.Results/src/ResultsOfT.cs b/src/Http/Http.Results/src/ResultsOfT.cs index 5073b95ac3b0..928c5db81ced 100644 --- a/src/Http/Http.Results/src/ResultsOfT.cs +++ b/src/Http/Http.Results/src/ResultsOfT.cs @@ -1,6 +1,7 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. +// This file is generated by a tool. See: src/Http/Http.Results/tools/ResultsOfTGenerator namespace Microsoft.AspNetCore.Http.Result; /// diff --git a/src/Http/Http.Results/tools/ResultsOfTGenerator/Program.cs b/src/Http/Http.Results/tools/ResultsOfTGenerator/Program.cs index 38641e98e5ed..5f668654fa42 100644 --- a/src/Http/Http.Results/tools/ResultsOfTGenerator/Program.cs +++ b/src/Http/Http.Results/tools/ResultsOfTGenerator/Program.cs @@ -18,6 +18,7 @@ writer.WriteLine("// Licensed to the .NET Foundation under one or more agreements."); writer.WriteLine("// The .NET Foundation licenses this file to you under the MIT license."); writer.WriteLine(); +writer.WriteLine("// This file is generated by a tool. See: src/Http/Http.Results/tools/ResultsOfTGenerator"); // Namespace writer.WriteLine("namespace Microsoft.AspNetCore.Http.Result;"); diff --git a/src/Http/README.md b/src/Http/README.md index e7f09db1a7fb..b8be410bf8c4 100644 --- a/src/Http/README.md +++ b/src/Http/README.md @@ -15,6 +15,7 @@ The following contains a description of each sub-directory in the `Http` directo - [Http.Abstractions/](Http.Abstractions/): Contains HTTP object model for HTTP requests and responses and also common extension methods for registering middleware in an IApplicationBuilder. - [Http.Extensions/](Http.Extensions/): Contains common extension methods for HTTP abstractions, HTTP headers, HTTP request/response, and session state. - [Http.Features/](Http.Features/): Contains HTTP feature interface definitions. +- [Http.Results/](Http.Results/): Contains implementations of `IResult` and related types. - [Metadata/](Metadata/): Contains ASP.NET Core metadata. - [Owin/](Owin/): Contains components for running OWIN middleware in an ASP.NET Core application, and to run ASP.NET Core middleware in an OWIN application. - [Routing/](Routing/): Contains middleware for routing requests to application logic and for generating links. From 80efa17b1520913901ad8b7800ad9861e2caf7ef Mon Sep 17 00:00:00 2001 From: Damian Edwards Date: Wed, 30 Mar 2022 16:49:49 -0700 Subject: [PATCH 05/19] ResultsOfT generator tweaks --- .../tools/ResultsOfTGenerator/Program.cs | 22 +++++++++++++------ 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/src/Http/Http.Results/tools/ResultsOfTGenerator/Program.cs b/src/Http/Http.Results/tools/ResultsOfTGenerator/Program.cs index 5f668654fa42..52e338281ea2 100644 --- a/src/Http/Http.Results/tools/ResultsOfTGenerator/Program.cs +++ b/src/Http/Http.Results/tools/ResultsOfTGenerator/Program.cs @@ -9,8 +9,8 @@ var filePath = Path.Join(Directory.GetCurrentDirectory(), $"{className}OfT.cs"); Console.WriteLine($"Will generate file at {filePath}"); -Console.WriteLine("Press Enter to continue"); -Console.ReadLine(); +Console.WriteLine("Press any key to continue or Ctrl-C to cancel"); +Console.ReadKey(); using var writer = new StreamWriter(filePath, append: false); @@ -27,9 +27,9 @@ for (int i = 1; i <= typeArgCount; i++) { // Class summary doc - writer.WriteLine(@$"/// -/// Represents the result of an route handler delegate that can return {i.ToWords()} different types. -/// "); + writer.WriteLine("/// "); + writer.WriteLine($"/// Represents the result of an route handler delegate that can return {i.ToWords()} different types."); + writer.WriteLine("/// "); // Type params docs for (int j = 1; j <= i; j++) @@ -128,6 +128,14 @@ } writer.Flush(); +writer.Close(); + +var file = new FileInfo(filePath); + +if (!file.Exists) throw new FileNotFoundException(filePath); + +Console.WriteLine(); +Console.WriteLine($"{file.Length:N0} bytes written to {file.FullName} successfully!"); static class StringExtensions { @@ -153,7 +161,7 @@ static class StringExtensions 18 => "eighteen", 19 => "nineteen", 20 => "twenty", - _ => "!!unsupported!!" + _ => throw new NotImplementedException("Add more numbers") }; public static string ToOrdinalWords(this int number) => number switch @@ -178,7 +186,7 @@ static class StringExtensions 18 => "eighteenth", 19 => "nineteenth", 20 => "twentieth", - _ => "!!unsupported!!" + _ => throw new NotImplementedException("Add more numbers") }; } From 5e2e0e18cf7d9beaebd9678ef17e7437dc49332f Mon Sep 17 00:00:00 2001 From: Damian Edwards Date: Wed, 30 Mar 2022 16:55:13 -0700 Subject: [PATCH 06/19] Delete Results --- src/Http/Http.Results/src/ResultsOfT.cs | 81 +++++++------------ .../tools/ResultsOfTGenerator/Program.cs | 5 +- 2 files changed, 34 insertions(+), 52 deletions(-) diff --git a/src/Http/Http.Results/src/ResultsOfT.cs b/src/Http/Http.Results/src/ResultsOfT.cs index 928c5db81ced..a84725a999a9 100644 --- a/src/Http/Http.Results/src/ResultsOfT.cs +++ b/src/Http/Http.Results/src/ResultsOfT.cs @@ -5,43 +5,8 @@ namespace Microsoft.AspNetCore.Http.Result; /// -/// Represents the result of an route handler delegate that can return one different types. -/// -/// The first result type. -public sealed class Results : IResult - where TResult1 : IResult -{ - private Results(IResult activeResult) - { - Result = activeResult; - } - - /// - /// Gets the actual returned by the route handler delegate. - /// - public IResult Result { get; } - - /// - /// Writes an HTTP response reflecting the result. - /// - /// The for the current request. - /// A that represents the asynchronous execute operation. - public async Task ExecuteAsync(HttpContext httpContext) - { - ArgumentNullException.ThrowIfNull(httpContext, nameof(httpContext)); - - await Result.ExecuteAsync(httpContext); - } - - /// - /// Converts the to a . - /// - /// The result. - public static implicit operator Results(TResult1 result) => new(result); -} - -/// -/// Represents the result of an route handler delegate that can return two different types. +/// An that could be one of two different types. On execution will +/// execute the underlying instance that was actually returned by the HTTP endpoint. /// /// The first result type. /// The second result type. @@ -85,7 +50,8 @@ public async Task ExecuteAsync(HttpContext httpContext) } /// -/// Represents the result of an route handler delegate that can return three different types. +/// An that could be one of three different types. On execution will +/// execute the underlying instance that was actually returned by the HTTP endpoint. /// /// The first result type. /// The second result type. @@ -137,7 +103,8 @@ public async Task ExecuteAsync(HttpContext httpContext) } /// -/// Represents the result of an route handler delegate that can return four different types. +/// An that could be one of four different types. On execution will +/// execute the underlying instance that was actually returned by the HTTP endpoint. /// /// The first result type. /// The second result type. @@ -197,7 +164,8 @@ public async Task ExecuteAsync(HttpContext httpContext) } /// -/// Represents the result of an route handler delegate that can return five different types. +/// An that could be one of five different types. On execution will +/// execute the underlying instance that was actually returned by the HTTP endpoint. /// /// The first result type. /// The second result type. @@ -265,7 +233,8 @@ public async Task ExecuteAsync(HttpContext httpContext) } /// -/// Represents the result of an route handler delegate that can return six different types. +/// An that could be one of six different types. On execution will +/// execute the underlying instance that was actually returned by the HTTP endpoint. /// /// The first result type. /// The second result type. @@ -341,7 +310,8 @@ public async Task ExecuteAsync(HttpContext httpContext) } /// -/// Represents the result of an route handler delegate that can return seven different types. +/// An that could be one of seven different types. On execution will +/// execute the underlying instance that was actually returned by the HTTP endpoint. /// /// The first result type. /// The second result type. @@ -425,7 +395,8 @@ public async Task ExecuteAsync(HttpContext httpContext) } /// -/// Represents the result of an route handler delegate that can return eight different types. +/// An that could be one of eight different types. On execution will +/// execute the underlying instance that was actually returned by the HTTP endpoint. /// /// The first result type. /// The second result type. @@ -517,7 +488,8 @@ public async Task ExecuteAsync(HttpContext httpContext) } /// -/// Represents the result of an route handler delegate that can return nine different types. +/// An that could be one of nine different types. On execution will +/// execute the underlying instance that was actually returned by the HTTP endpoint. /// /// The first result type. /// The second result type. @@ -617,7 +589,8 @@ public async Task ExecuteAsync(HttpContext httpContext) } /// -/// Represents the result of an route handler delegate that can return ten different types. +/// An that could be one of ten different types. On execution will +/// execute the underlying instance that was actually returned by the HTTP endpoint. /// /// The first result type. /// The second result type. @@ -725,7 +698,8 @@ public async Task ExecuteAsync(HttpContext httpContext) } /// -/// Represents the result of an route handler delegate that can return eleven different types. +/// An that could be one of eleven different types. On execution will +/// execute the underlying instance that was actually returned by the HTTP endpoint. /// /// The first result type. /// The second result type. @@ -841,7 +815,8 @@ public async Task ExecuteAsync(HttpContext httpContext) } /// -/// Represents the result of an route handler delegate that can return twelve different types. +/// An that could be one of twelve different types. On execution will +/// execute the underlying instance that was actually returned by the HTTP endpoint. /// /// The first result type. /// The second result type. @@ -965,7 +940,8 @@ public async Task ExecuteAsync(HttpContext httpContext) } /// -/// Represents the result of an route handler delegate that can return thirteen different types. +/// An that could be one of thirteen different types. On execution will +/// execute the underlying instance that was actually returned by the HTTP endpoint. /// /// The first result type. /// The second result type. @@ -1097,7 +1073,8 @@ public async Task ExecuteAsync(HttpContext httpContext) } /// -/// Represents the result of an route handler delegate that can return fourteen different types. +/// An that could be one of fourteen different types. On execution will +/// execute the underlying instance that was actually returned by the HTTP endpoint. /// /// The first result type. /// The second result type. @@ -1237,7 +1214,8 @@ public async Task ExecuteAsync(HttpContext httpContext) } /// -/// Represents the result of an route handler delegate that can return fifteen different types. +/// An that could be one of fifteen different types. On execution will +/// execute the underlying instance that was actually returned by the HTTP endpoint. /// /// The first result type. /// The second result type. @@ -1385,7 +1363,8 @@ public async Task ExecuteAsync(HttpContext httpContext) } /// -/// Represents the result of an route handler delegate that can return sixteen different types. +/// An that could be one of sixteen different types. On execution will +/// execute the underlying instance that was actually returned by the HTTP endpoint. /// /// The first result type. /// The second result type. diff --git a/src/Http/Http.Results/tools/ResultsOfTGenerator/Program.cs b/src/Http/Http.Results/tools/ResultsOfTGenerator/Program.cs index 52e338281ea2..7f2f9535baa9 100644 --- a/src/Http/Http.Results/tools/ResultsOfTGenerator/Program.cs +++ b/src/Http/Http.Results/tools/ResultsOfTGenerator/Program.cs @@ -26,9 +26,12 @@ for (int i = 1; i <= typeArgCount; i++) { + if (i == 1) continue; + // Class summary doc writer.WriteLine("/// "); - writer.WriteLine($"/// Represents the result of an route handler delegate that can return {i.ToWords()} different types."); + writer.WriteLine($"/// An that could be one of {i.ToWords()} different types. On execution will"); + writer.WriteLine("/// execute the underlying instance that was actually returned by the HTTP endpoint."); writer.WriteLine("/// "); // Type params docs From 751cbb155901ab37058451b67f2baf61d2b32191 Mon Sep 17 00:00:00 2001 From: Damian Edwards Date: Wed, 30 Mar 2022 17:21:11 -0700 Subject: [PATCH 07/19] ResultsOfT doc comment tweak --- src/Http/Http.Results/src/ResultsOfT.cs | 180 ++++++++++-------- .../tools/ResultsOfTGenerator/Program.cs | 14 +- 2 files changed, 114 insertions(+), 80 deletions(-) diff --git a/src/Http/Http.Results/src/ResultsOfT.cs b/src/Http/Http.Results/src/ResultsOfT.cs index a84725a999a9..79fb62c5e08a 100644 --- a/src/Http/Http.Results/src/ResultsOfT.cs +++ b/src/Http/Http.Results/src/ResultsOfT.cs @@ -8,12 +8,18 @@ namespace Microsoft.AspNetCore.Http.Result; /// An that could be one of two different types. On execution will /// execute the underlying instance that was actually returned by the HTTP endpoint. /// +/// +/// An instance of this type cannot be created explicitly. Use the implicit cast operators to create an instance +/// from an instance of one of the declared type arguments, e.g. +/// Results<OkObjectHttpResult, ProblemHttpResult> result = Results.Ok(); +/// /// The first result type. /// The second result type. public sealed class Results : IResult where TResult1 : IResult where TResult2 : IResult { + // Use implicit cast operators to create an instance private Results(IResult activeResult) { Result = activeResult; @@ -24,11 +30,7 @@ private Results(IResult activeResult) /// public IResult Result { get; } - /// - /// Writes an HTTP response reflecting the result. - /// - /// The for the current request. - /// A that represents the asynchronous execute operation. + /// public async Task ExecuteAsync(HttpContext httpContext) { ArgumentNullException.ThrowIfNull(httpContext, nameof(httpContext)); @@ -53,6 +55,11 @@ public async Task ExecuteAsync(HttpContext httpContext) /// An that could be one of three different types. On execution will /// execute the underlying instance that was actually returned by the HTTP endpoint. /// +/// +/// An instance of this type cannot be created explicitly. Use the implicit cast operators to create an instance +/// from an instance of one of the declared type arguments, e.g. +/// Results<OkObjectHttpResult, ProblemHttpResult> result = Results.Ok(); +/// /// The first result type. /// The second result type. /// The third result type. @@ -61,6 +68,7 @@ public sealed class Results : IResult where TResult2 : IResult where TResult3 : IResult { + // Use implicit cast operators to create an instance private Results(IResult activeResult) { Result = activeResult; @@ -71,11 +79,7 @@ private Results(IResult activeResult) /// public IResult Result { get; } - /// - /// Writes an HTTP response reflecting the result. - /// - /// The for the current request. - /// A that represents the asynchronous execute operation. + /// public async Task ExecuteAsync(HttpContext httpContext) { ArgumentNullException.ThrowIfNull(httpContext, nameof(httpContext)); @@ -106,6 +110,11 @@ public async Task ExecuteAsync(HttpContext httpContext) /// An that could be one of four different types. On execution will /// execute the underlying instance that was actually returned by the HTTP endpoint. /// +/// +/// An instance of this type cannot be created explicitly. Use the implicit cast operators to create an instance +/// from an instance of one of the declared type arguments, e.g. +/// Results<OkObjectHttpResult, ProblemHttpResult> result = Results.Ok(); +/// /// The first result type. /// The second result type. /// The third result type. @@ -116,6 +125,7 @@ public sealed class Results : IResult where TResult3 : IResult where TResult4 : IResult { + // Use implicit cast operators to create an instance private Results(IResult activeResult) { Result = activeResult; @@ -126,11 +136,7 @@ private Results(IResult activeResult) /// public IResult Result { get; } - /// - /// Writes an HTTP response reflecting the result. - /// - /// The for the current request. - /// A that represents the asynchronous execute operation. + /// public async Task ExecuteAsync(HttpContext httpContext) { ArgumentNullException.ThrowIfNull(httpContext, nameof(httpContext)); @@ -167,6 +173,11 @@ public async Task ExecuteAsync(HttpContext httpContext) /// An that could be one of five different types. On execution will /// execute the underlying instance that was actually returned by the HTTP endpoint. /// +/// +/// An instance of this type cannot be created explicitly. Use the implicit cast operators to create an instance +/// from an instance of one of the declared type arguments, e.g. +/// Results<OkObjectHttpResult, ProblemHttpResult> result = Results.Ok(); +/// /// The first result type. /// The second result type. /// The third result type. @@ -179,6 +190,7 @@ public sealed class Results : where TResult4 : IResult where TResult5 : IResult { + // Use implicit cast operators to create an instance private Results(IResult activeResult) { Result = activeResult; @@ -189,11 +201,7 @@ private Results(IResult activeResult) /// public IResult Result { get; } - /// - /// Writes an HTTP response reflecting the result. - /// - /// The for the current request. - /// A that represents the asynchronous execute operation. + /// public async Task ExecuteAsync(HttpContext httpContext) { ArgumentNullException.ThrowIfNull(httpContext, nameof(httpContext)); @@ -236,6 +244,11 @@ public async Task ExecuteAsync(HttpContext httpContext) /// An that could be one of six different types. On execution will /// execute the underlying instance that was actually returned by the HTTP endpoint. /// +/// +/// An instance of this type cannot be created explicitly. Use the implicit cast operators to create an instance +/// from an instance of one of the declared type arguments, e.g. +/// Results<OkObjectHttpResult, ProblemHttpResult> result = Results.Ok(); +/// /// The first result type. /// The second result type. /// The third result type. @@ -250,6 +263,7 @@ public sealed class Results public IResult Result { get; } - /// - /// Writes an HTTP response reflecting the result. - /// - /// The for the current request. - /// A that represents the asynchronous execute operation. + /// public async Task ExecuteAsync(HttpContext httpContext) { ArgumentNullException.ThrowIfNull(httpContext, nameof(httpContext)); @@ -313,6 +323,11 @@ public async Task ExecuteAsync(HttpContext httpContext) /// An that could be one of seven different types. On execution will /// execute the underlying instance that was actually returned by the HTTP endpoint. /// +/// +/// An instance of this type cannot be created explicitly. Use the implicit cast operators to create an instance +/// from an instance of one of the declared type arguments, e.g. +/// Results<OkObjectHttpResult, ProblemHttpResult> result = Results.Ok(); +/// /// The first result type. /// The second result type. /// The third result type. @@ -329,6 +344,7 @@ public sealed class Results public IResult Result { get; } - /// - /// Writes an HTTP response reflecting the result. - /// - /// The for the current request. - /// A that represents the asynchronous execute operation. + /// public async Task ExecuteAsync(HttpContext httpContext) { ArgumentNullException.ThrowIfNull(httpContext, nameof(httpContext)); @@ -398,6 +410,11 @@ public async Task ExecuteAsync(HttpContext httpContext) /// An that could be one of eight different types. On execution will /// execute the underlying instance that was actually returned by the HTTP endpoint. /// +/// +/// An instance of this type cannot be created explicitly. Use the implicit cast operators to create an instance +/// from an instance of one of the declared type arguments, e.g. +/// Results<OkObjectHttpResult, ProblemHttpResult> result = Results.Ok(); +/// /// The first result type. /// The second result type. /// The third result type. @@ -416,6 +433,7 @@ public sealed class Results public IResult Result { get; } - /// - /// Writes an HTTP response reflecting the result. - /// - /// The for the current request. - /// A that represents the asynchronous execute operation. + /// public async Task ExecuteAsync(HttpContext httpContext) { ArgumentNullException.ThrowIfNull(httpContext, nameof(httpContext)); @@ -491,6 +505,11 @@ public async Task ExecuteAsync(HttpContext httpContext) /// An that could be one of nine different types. On execution will /// execute the underlying instance that was actually returned by the HTTP endpoint. /// +/// +/// An instance of this type cannot be created explicitly. Use the implicit cast operators to create an instance +/// from an instance of one of the declared type arguments, e.g. +/// Results<OkObjectHttpResult, ProblemHttpResult> result = Results.Ok(); +/// /// The first result type. /// The second result type. /// The third result type. @@ -511,6 +530,7 @@ public sealed class Results public IResult Result { get; } - /// - /// Writes an HTTP response reflecting the result. - /// - /// The for the current request. - /// A that represents the asynchronous execute operation. + /// public async Task ExecuteAsync(HttpContext httpContext) { ArgumentNullException.ThrowIfNull(httpContext, nameof(httpContext)); @@ -592,6 +608,11 @@ public async Task ExecuteAsync(HttpContext httpContext) /// An that could be one of ten different types. On execution will /// execute the underlying instance that was actually returned by the HTTP endpoint. /// +/// +/// An instance of this type cannot be created explicitly. Use the implicit cast operators to create an instance +/// from an instance of one of the declared type arguments, e.g. +/// Results<OkObjectHttpResult, ProblemHttpResult> result = Results.Ok(); +/// /// The first result type. /// The second result type. /// The third result type. @@ -614,6 +635,7 @@ public sealed class Results public IResult Result { get; } - /// - /// Writes an HTTP response reflecting the result. - /// - /// The for the current request. - /// A that represents the asynchronous execute operation. + /// public async Task ExecuteAsync(HttpContext httpContext) { ArgumentNullException.ThrowIfNull(httpContext, nameof(httpContext)); @@ -701,6 +719,11 @@ public async Task ExecuteAsync(HttpContext httpContext) /// An that could be one of eleven different types. On execution will /// execute the underlying instance that was actually returned by the HTTP endpoint. /// +/// +/// An instance of this type cannot be created explicitly. Use the implicit cast operators to create an instance +/// from an instance of one of the declared type arguments, e.g. +/// Results<OkObjectHttpResult, ProblemHttpResult> result = Results.Ok(); +/// /// The first result type. /// The second result type. /// The third result type. @@ -725,6 +748,7 @@ public sealed class Results public IResult Result { get; } - /// - /// Writes an HTTP response reflecting the result. - /// - /// The for the current request. - /// A that represents the asynchronous execute operation. + /// public async Task ExecuteAsync(HttpContext httpContext) { ArgumentNullException.ThrowIfNull(httpContext, nameof(httpContext)); @@ -818,6 +838,11 @@ public async Task ExecuteAsync(HttpContext httpContext) /// An that could be one of twelve different types. On execution will /// execute the underlying instance that was actually returned by the HTTP endpoint. /// +/// +/// An instance of this type cannot be created explicitly. Use the implicit cast operators to create an instance +/// from an instance of one of the declared type arguments, e.g. +/// Results<OkObjectHttpResult, ProblemHttpResult> result = Results.Ok(); +/// /// The first result type. /// The second result type. /// The third result type. @@ -844,6 +869,7 @@ public sealed class Results public IResult Result { get; } - /// - /// Writes an HTTP response reflecting the result. - /// - /// The for the current request. - /// A that represents the asynchronous execute operation. + /// public async Task ExecuteAsync(HttpContext httpContext) { ArgumentNullException.ThrowIfNull(httpContext, nameof(httpContext)); @@ -943,6 +965,11 @@ public async Task ExecuteAsync(HttpContext httpContext) /// An that could be one of thirteen different types. On execution will /// execute the underlying instance that was actually returned by the HTTP endpoint. /// +/// +/// An instance of this type cannot be created explicitly. Use the implicit cast operators to create an instance +/// from an instance of one of the declared type arguments, e.g. +/// Results<OkObjectHttpResult, ProblemHttpResult> result = Results.Ok(); +/// /// The first result type. /// The second result type. /// The third result type. @@ -971,6 +998,7 @@ public sealed class Results public IResult Result { get; } - /// - /// Writes an HTTP response reflecting the result. - /// - /// The for the current request. - /// A that represents the asynchronous execute operation. + /// public async Task ExecuteAsync(HttpContext httpContext) { ArgumentNullException.ThrowIfNull(httpContext, nameof(httpContext)); @@ -1076,6 +1100,11 @@ public async Task ExecuteAsync(HttpContext httpContext) /// An that could be one of fourteen different types. On execution will /// execute the underlying instance that was actually returned by the HTTP endpoint. /// +/// +/// An instance of this type cannot be created explicitly. Use the implicit cast operators to create an instance +/// from an instance of one of the declared type arguments, e.g. +/// Results<OkObjectHttpResult, ProblemHttpResult> result = Results.Ok(); +/// /// The first result type. /// The second result type. /// The third result type. @@ -1106,6 +1135,7 @@ public sealed class Results public IResult Result { get; } - /// - /// Writes an HTTP response reflecting the result. - /// - /// The for the current request. - /// A that represents the asynchronous execute operation. + /// public async Task ExecuteAsync(HttpContext httpContext) { ArgumentNullException.ThrowIfNull(httpContext, nameof(httpContext)); @@ -1217,6 +1243,11 @@ public async Task ExecuteAsync(HttpContext httpContext) /// An that could be one of fifteen different types. On execution will /// execute the underlying instance that was actually returned by the HTTP endpoint. /// +/// +/// An instance of this type cannot be created explicitly. Use the implicit cast operators to create an instance +/// from an instance of one of the declared type arguments, e.g. +/// Results<OkObjectHttpResult, ProblemHttpResult> result = Results.Ok(); +/// /// The first result type. /// The second result type. /// The third result type. @@ -1249,6 +1280,7 @@ public sealed class Results public IResult Result { get; } - /// - /// Writes an HTTP response reflecting the result. - /// - /// The for the current request. - /// A that represents the asynchronous execute operation. + /// public async Task ExecuteAsync(HttpContext httpContext) { ArgumentNullException.ThrowIfNull(httpContext, nameof(httpContext)); @@ -1366,6 +1394,11 @@ public async Task ExecuteAsync(HttpContext httpContext) /// An that could be one of sixteen different types. On execution will /// execute the underlying instance that was actually returned by the HTTP endpoint. /// +/// +/// An instance of this type cannot be created explicitly. Use the implicit cast operators to create an instance +/// from an instance of one of the declared type arguments, e.g. +/// Results<OkObjectHttpResult, ProblemHttpResult> result = Results.Ok(); +/// /// The first result type. /// The second result type. /// The third result type. @@ -1400,6 +1433,7 @@ public sealed class Results public IResult Result { get; } - /// - /// Writes an HTTP response reflecting the result. - /// - /// The for the current request. - /// A that represents the asynchronous execute operation. + /// public async Task ExecuteAsync(HttpContext httpContext) { ArgumentNullException.ThrowIfNull(httpContext, nameof(httpContext)); diff --git a/src/Http/Http.Results/tools/ResultsOfTGenerator/Program.cs b/src/Http/Http.Results/tools/ResultsOfTGenerator/Program.cs index 7f2f9535baa9..f9fb37ac9c27 100644 --- a/src/Http/Http.Results/tools/ResultsOfTGenerator/Program.cs +++ b/src/Http/Http.Results/tools/ResultsOfTGenerator/Program.cs @@ -34,6 +34,13 @@ writer.WriteLine("/// execute the underlying instance that was actually returned by the HTTP endpoint."); writer.WriteLine("/// "); + // Class remarks doc + writer.WriteLine("/// "); + writer.WriteLine("/// An instance of this type cannot be created explicitly. Use the implicit cast operators to create an instance"); + writer.WriteLine("/// from an instance of one of the declared type arguments, e.g."); + writer.WriteLine("/// Results<OkObjectHttpResult, ProblemHttpResult> result = Results.Ok();"); + writer.WriteLine("/// "); + // Type params docs for (int j = 1; j <= i; j++) { @@ -68,6 +75,7 @@ writer.WriteLine("{"); // Ctor + writer.WriteLine(" // Use implicit cast operators to create an instance"); writer.WriteLine($" private {className}(IResult activeResult)"); writer.WriteLine(" {"); writer.WriteLine(" Result = activeResult;"); @@ -82,11 +90,7 @@ writer.WriteLine(); // ExecuteAsync method - writer.WriteLine(" /// "); - writer.WriteLine(" /// Writes an HTTP response reflecting the result."); - writer.WriteLine(" /// "); - writer.WriteLine(" /// The for the current request."); - writer.WriteLine(" /// A that represents the asynchronous execute operation."); + writer.WriteLine(" /// "); writer.WriteLine(" public async Task ExecuteAsync(HttpContext httpContext)"); writer.WriteLine(" {"); writer.WriteLine(" ArgumentNullException.ThrowIfNull(httpContext, nameof(httpContext));"); From b95f6230a23058af292fc4b8b1cb372cb15d51ff Mon Sep 17 00:00:00 2001 From: Damian Edwards Date: Thu, 31 Mar 2022 08:40:40 -0700 Subject: [PATCH 08/19] Move ResultOfT to Http namespace Also added a sample --- src/Http/Http.Results/src/ResultsOfT.cs | 2 +- .../Http.Results/tools/ResultsOfTGenerator/Program.cs | 2 +- src/Http/samples/MinimalSample/Program.cs | 9 +++++++++ 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/src/Http/Http.Results/src/ResultsOfT.cs b/src/Http/Http.Results/src/ResultsOfT.cs index 79fb62c5e08a..770b257bb5f0 100644 --- a/src/Http/Http.Results/src/ResultsOfT.cs +++ b/src/Http/Http.Results/src/ResultsOfT.cs @@ -2,7 +2,7 @@ // The .NET Foundation licenses this file to you under the MIT license. // This file is generated by a tool. See: src/Http/Http.Results/tools/ResultsOfTGenerator -namespace Microsoft.AspNetCore.Http.Result; +namespace Microsoft.AspNetCore.Http; /// /// An that could be one of two different types. On execution will diff --git a/src/Http/Http.Results/tools/ResultsOfTGenerator/Program.cs b/src/Http/Http.Results/tools/ResultsOfTGenerator/Program.cs index f9fb37ac9c27..fcc19dc03bab 100644 --- a/src/Http/Http.Results/tools/ResultsOfTGenerator/Program.cs +++ b/src/Http/Http.Results/tools/ResultsOfTGenerator/Program.cs @@ -21,7 +21,7 @@ writer.WriteLine("// This file is generated by a tool. See: src/Http/Http.Results/tools/ResultsOfTGenerator"); // Namespace -writer.WriteLine("namespace Microsoft.AspNetCore.Http.Result;"); +writer.WriteLine("namespace Microsoft.AspNetCore.Http;"); writer.WriteLine(); for (int i = 1; i <= typeArgCount; i++) diff --git a/src/Http/samples/MinimalSample/Program.cs b/src/Http/samples/MinimalSample/Program.cs index 080d31fb5cb3..a68f558d2b43 100644 --- a/src/Http/samples/MinimalSample/Program.cs +++ b/src/Http/samples/MinimalSample/Program.cs @@ -19,6 +19,15 @@ string SayHello(string name) => $"Hello, {name}!"; app.MapGet("/hello/{name}", SayHello); +app.MapGet("/todo/{id}", Results (int id) => +{ + return id switch + { + >= 1 and <= 10 => (OkObjectHttpResult)Results.Ok(new { Id = id, Title = "Walk the dog" }), + _ => (NotFoundObjectHttpResult)Results.NotFound() + }; +}); + var extensions = new Dictionary() { { "traceId", "traceId123" } }; app.MapGet("/problem", () => From c10f2b0a938553a449ab9e22172388c8fb060e24 Mon Sep 17 00:00:00 2001 From: Damian Edwards Date: Thu, 31 Mar 2022 09:31:39 -0700 Subject: [PATCH 09/19] Add tests for ResultsOfT --- .../Http.Results/src/PublicAPI.Unshipped.txt | 364 +++++++++--------- src/Http/Http.Results/src/ResultsOfT.cs | 75 ++++ src/Http/Http.Results/test/ResultsOfTTests.cs | 111 ++++++ .../tools/ResultsOfTGenerator/Program.cs | 5 + src/Http/samples/MinimalSample/Program.cs | 2 + 5 files changed, 373 insertions(+), 184 deletions(-) create mode 100644 src/Http/Http.Results/test/ResultsOfTTests.cs diff --git a/src/Http/Http.Results/src/PublicAPI.Unshipped.txt b/src/Http/Http.Results/src/PublicAPI.Unshipped.txt index de620db27882..cf3faed7c709 100644 --- a/src/Http/Http.Results/src/PublicAPI.Unshipped.txt +++ b/src/Http/Http.Results/src/PublicAPI.Unshipped.txt @@ -114,54 +114,51 @@ Microsoft.AspNetCore.Http.RedirectToRouteHttpResult.Permanent.get -> bool Microsoft.AspNetCore.Http.RedirectToRouteHttpResult.PreserveMethod.get -> bool Microsoft.AspNetCore.Http.RedirectToRouteHttpResult.RouteName.get -> string? Microsoft.AspNetCore.Http.RedirectToRouteHttpResult.RouteValues.get -> Microsoft.AspNetCore.Routing.RouteValueDictionary? -Microsoft.AspNetCore.Http.Result.Results -Microsoft.AspNetCore.Http.Result.Results.ExecuteAsync(Microsoft.AspNetCore.Http.HttpContext! httpContext) -> System.Threading.Tasks.Task! -Microsoft.AspNetCore.Http.Result.Results.Result.get -> Microsoft.AspNetCore.Http.IResult! -Microsoft.AspNetCore.Http.Result.Results -Microsoft.AspNetCore.Http.Result.Results.ExecuteAsync(Microsoft.AspNetCore.Http.HttpContext! httpContext) -> System.Threading.Tasks.Task! -Microsoft.AspNetCore.Http.Result.Results.Result.get -> Microsoft.AspNetCore.Http.IResult! -Microsoft.AspNetCore.Http.Result.Results -Microsoft.AspNetCore.Http.Result.Results.ExecuteAsync(Microsoft.AspNetCore.Http.HttpContext! httpContext) -> System.Threading.Tasks.Task! -Microsoft.AspNetCore.Http.Result.Results.Result.get -> Microsoft.AspNetCore.Http.IResult! -Microsoft.AspNetCore.Http.Result.Results -Microsoft.AspNetCore.Http.Result.Results.ExecuteAsync(Microsoft.AspNetCore.Http.HttpContext! httpContext) -> System.Threading.Tasks.Task! -Microsoft.AspNetCore.Http.Result.Results.Result.get -> Microsoft.AspNetCore.Http.IResult! -Microsoft.AspNetCore.Http.Result.Results -Microsoft.AspNetCore.Http.Result.Results.ExecuteAsync(Microsoft.AspNetCore.Http.HttpContext! httpContext) -> System.Threading.Tasks.Task! -Microsoft.AspNetCore.Http.Result.Results.Result.get -> Microsoft.AspNetCore.Http.IResult! -Microsoft.AspNetCore.Http.Result.Results -Microsoft.AspNetCore.Http.Result.Results.ExecuteAsync(Microsoft.AspNetCore.Http.HttpContext! httpContext) -> System.Threading.Tasks.Task! -Microsoft.AspNetCore.Http.Result.Results.Result.get -> Microsoft.AspNetCore.Http.IResult! -Microsoft.AspNetCore.Http.Result.Results -Microsoft.AspNetCore.Http.Result.Results.ExecuteAsync(Microsoft.AspNetCore.Http.HttpContext! httpContext) -> System.Threading.Tasks.Task! -Microsoft.AspNetCore.Http.Result.Results.Result.get -> Microsoft.AspNetCore.Http.IResult! -Microsoft.AspNetCore.Http.Result.Results -Microsoft.AspNetCore.Http.Result.Results.ExecuteAsync(Microsoft.AspNetCore.Http.HttpContext! httpContext) -> System.Threading.Tasks.Task! -Microsoft.AspNetCore.Http.Result.Results.Result.get -> Microsoft.AspNetCore.Http.IResult! -Microsoft.AspNetCore.Http.Result.Results -Microsoft.AspNetCore.Http.Result.Results.ExecuteAsync(Microsoft.AspNetCore.Http.HttpContext! httpContext) -> System.Threading.Tasks.Task! -Microsoft.AspNetCore.Http.Result.Results.Result.get -> Microsoft.AspNetCore.Http.IResult! -Microsoft.AspNetCore.Http.Result.Results -Microsoft.AspNetCore.Http.Result.Results.ExecuteAsync(Microsoft.AspNetCore.Http.HttpContext! httpContext) -> System.Threading.Tasks.Task! -Microsoft.AspNetCore.Http.Result.Results.Result.get -> Microsoft.AspNetCore.Http.IResult! -Microsoft.AspNetCore.Http.Result.Results -Microsoft.AspNetCore.Http.Result.Results.ExecuteAsync(Microsoft.AspNetCore.Http.HttpContext! httpContext) -> System.Threading.Tasks.Task! -Microsoft.AspNetCore.Http.Result.Results.Result.get -> Microsoft.AspNetCore.Http.IResult! -Microsoft.AspNetCore.Http.Result.Results -Microsoft.AspNetCore.Http.Result.Results.ExecuteAsync(Microsoft.AspNetCore.Http.HttpContext! httpContext) -> System.Threading.Tasks.Task! -Microsoft.AspNetCore.Http.Result.Results.Result.get -> Microsoft.AspNetCore.Http.IResult! -Microsoft.AspNetCore.Http.Result.Results -Microsoft.AspNetCore.Http.Result.Results.ExecuteAsync(Microsoft.AspNetCore.Http.HttpContext! httpContext) -> System.Threading.Tasks.Task! -Microsoft.AspNetCore.Http.Result.Results.Result.get -> Microsoft.AspNetCore.Http.IResult! -Microsoft.AspNetCore.Http.Result.Results -Microsoft.AspNetCore.Http.Result.Results.ExecuteAsync(Microsoft.AspNetCore.Http.HttpContext! httpContext) -> System.Threading.Tasks.Task! -Microsoft.AspNetCore.Http.Result.Results.Result.get -> Microsoft.AspNetCore.Http.IResult! -Microsoft.AspNetCore.Http.Result.Results -Microsoft.AspNetCore.Http.Result.Results.ExecuteAsync(Microsoft.AspNetCore.Http.HttpContext! httpContext) -> System.Threading.Tasks.Task! -Microsoft.AspNetCore.Http.Result.Results.Result.get -> Microsoft.AspNetCore.Http.IResult! -Microsoft.AspNetCore.Http.Result.Results -Microsoft.AspNetCore.Http.Result.Results.ExecuteAsync(Microsoft.AspNetCore.Http.HttpContext! httpContext) -> System.Threading.Tasks.Task! -Microsoft.AspNetCore.Http.Result.Results.Result.get -> Microsoft.AspNetCore.Http.IResult! +Microsoft.AspNetCore.Http.Results +Microsoft.AspNetCore.Http.Results.ExecuteAsync(Microsoft.AspNetCore.Http.HttpContext! httpContext) -> System.Threading.Tasks.Task! +Microsoft.AspNetCore.Http.Results.Result.get -> Microsoft.AspNetCore.Http.IResult! +Microsoft.AspNetCore.Http.Results +Microsoft.AspNetCore.Http.Results.ExecuteAsync(Microsoft.AspNetCore.Http.HttpContext! httpContext) -> System.Threading.Tasks.Task! +Microsoft.AspNetCore.Http.Results.Result.get -> Microsoft.AspNetCore.Http.IResult! +Microsoft.AspNetCore.Http.Results +Microsoft.AspNetCore.Http.Results.ExecuteAsync(Microsoft.AspNetCore.Http.HttpContext! httpContext) -> System.Threading.Tasks.Task! +Microsoft.AspNetCore.Http.Results.Result.get -> Microsoft.AspNetCore.Http.IResult! +Microsoft.AspNetCore.Http.Results +Microsoft.AspNetCore.Http.Results.ExecuteAsync(Microsoft.AspNetCore.Http.HttpContext! httpContext) -> System.Threading.Tasks.Task! +Microsoft.AspNetCore.Http.Results.Result.get -> Microsoft.AspNetCore.Http.IResult! +Microsoft.AspNetCore.Http.Results +Microsoft.AspNetCore.Http.Results.ExecuteAsync(Microsoft.AspNetCore.Http.HttpContext! httpContext) -> System.Threading.Tasks.Task! +Microsoft.AspNetCore.Http.Results.Result.get -> Microsoft.AspNetCore.Http.IResult! +Microsoft.AspNetCore.Http.Results +Microsoft.AspNetCore.Http.Results.ExecuteAsync(Microsoft.AspNetCore.Http.HttpContext! httpContext) -> System.Threading.Tasks.Task! +Microsoft.AspNetCore.Http.Results.Result.get -> Microsoft.AspNetCore.Http.IResult! +Microsoft.AspNetCore.Http.Results +Microsoft.AspNetCore.Http.Results.ExecuteAsync(Microsoft.AspNetCore.Http.HttpContext! httpContext) -> System.Threading.Tasks.Task! +Microsoft.AspNetCore.Http.Results.Result.get -> Microsoft.AspNetCore.Http.IResult! +Microsoft.AspNetCore.Http.Results +Microsoft.AspNetCore.Http.Results.ExecuteAsync(Microsoft.AspNetCore.Http.HttpContext! httpContext) -> System.Threading.Tasks.Task! +Microsoft.AspNetCore.Http.Results.Result.get -> Microsoft.AspNetCore.Http.IResult! +Microsoft.AspNetCore.Http.Results +Microsoft.AspNetCore.Http.Results.ExecuteAsync(Microsoft.AspNetCore.Http.HttpContext! httpContext) -> System.Threading.Tasks.Task! +Microsoft.AspNetCore.Http.Results.Result.get -> Microsoft.AspNetCore.Http.IResult! +Microsoft.AspNetCore.Http.Results +Microsoft.AspNetCore.Http.Results.ExecuteAsync(Microsoft.AspNetCore.Http.HttpContext! httpContext) -> System.Threading.Tasks.Task! +Microsoft.AspNetCore.Http.Results.Result.get -> Microsoft.AspNetCore.Http.IResult! +Microsoft.AspNetCore.Http.Results +Microsoft.AspNetCore.Http.Results.ExecuteAsync(Microsoft.AspNetCore.Http.HttpContext! httpContext) -> System.Threading.Tasks.Task! +Microsoft.AspNetCore.Http.Results.Result.get -> Microsoft.AspNetCore.Http.IResult! +Microsoft.AspNetCore.Http.Results +Microsoft.AspNetCore.Http.Results.ExecuteAsync(Microsoft.AspNetCore.Http.HttpContext! httpContext) -> System.Threading.Tasks.Task! +Microsoft.AspNetCore.Http.Results.Result.get -> Microsoft.AspNetCore.Http.IResult! +Microsoft.AspNetCore.Http.Results +Microsoft.AspNetCore.Http.Results.ExecuteAsync(Microsoft.AspNetCore.Http.HttpContext! httpContext) -> System.Threading.Tasks.Task! +Microsoft.AspNetCore.Http.Results.Result.get -> Microsoft.AspNetCore.Http.IResult! +Microsoft.AspNetCore.Http.Results +Microsoft.AspNetCore.Http.Results.ExecuteAsync(Microsoft.AspNetCore.Http.HttpContext! httpContext) -> System.Threading.Tasks.Task! +Microsoft.AspNetCore.Http.Results.Result.get -> Microsoft.AspNetCore.Http.IResult! +Microsoft.AspNetCore.Http.Results +Microsoft.AspNetCore.Http.Results.ExecuteAsync(Microsoft.AspNetCore.Http.HttpContext! httpContext) -> System.Threading.Tasks.Task! +Microsoft.AspNetCore.Http.Results.Result.get -> Microsoft.AspNetCore.Http.IResult! Microsoft.AspNetCore.Http.SignInHttpResult Microsoft.AspNetCore.Http.SignInHttpResult.AuthenticationScheme.get -> string? Microsoft.AspNetCore.Http.SignInHttpResult.ExecuteAsync(Microsoft.AspNetCore.Http.HttpContext! httpContext) -> System.Threading.Tasks.Task! @@ -191,143 +188,142 @@ Microsoft.AspNetCore.Http.VirtualFileHttpResult.FileLength.get -> long? Microsoft.AspNetCore.Http.VirtualFileHttpResult.FileName.get -> string! Microsoft.AspNetCore.Http.VirtualFileHttpResult.LastModified.get -> System.DateTimeOffset? static Microsoft.AspNetCore.Http.EmptyHttpResult.Instance.get -> Microsoft.AspNetCore.Http.EmptyHttpResult! -static Microsoft.AspNetCore.Http.Result.Results.implicit operator Microsoft.AspNetCore.Http.Result.Results!(TResult1 result) -> Microsoft.AspNetCore.Http.Result.Results! -static Microsoft.AspNetCore.Http.Result.Results.implicit operator Microsoft.AspNetCore.Http.Result.Results!(TResult10 result) -> Microsoft.AspNetCore.Http.Result.Results! -static Microsoft.AspNetCore.Http.Result.Results.implicit operator Microsoft.AspNetCore.Http.Result.Results!(TResult11 result) -> Microsoft.AspNetCore.Http.Result.Results! -static Microsoft.AspNetCore.Http.Result.Results.implicit operator Microsoft.AspNetCore.Http.Result.Results!(TResult12 result) -> Microsoft.AspNetCore.Http.Result.Results! -static Microsoft.AspNetCore.Http.Result.Results.implicit operator Microsoft.AspNetCore.Http.Result.Results!(TResult13 result) -> Microsoft.AspNetCore.Http.Result.Results! -static Microsoft.AspNetCore.Http.Result.Results.implicit operator Microsoft.AspNetCore.Http.Result.Results!(TResult14 result) -> Microsoft.AspNetCore.Http.Result.Results! -static Microsoft.AspNetCore.Http.Result.Results.implicit operator Microsoft.AspNetCore.Http.Result.Results!(TResult15 result) -> Microsoft.AspNetCore.Http.Result.Results! -static Microsoft.AspNetCore.Http.Result.Results.implicit operator Microsoft.AspNetCore.Http.Result.Results!(TResult16 result) -> Microsoft.AspNetCore.Http.Result.Results! -static Microsoft.AspNetCore.Http.Result.Results.implicit operator Microsoft.AspNetCore.Http.Result.Results!(TResult2 result) -> Microsoft.AspNetCore.Http.Result.Results! -static Microsoft.AspNetCore.Http.Result.Results.implicit operator Microsoft.AspNetCore.Http.Result.Results!(TResult3 result) -> Microsoft.AspNetCore.Http.Result.Results! -static Microsoft.AspNetCore.Http.Result.Results.implicit operator Microsoft.AspNetCore.Http.Result.Results!(TResult4 result) -> Microsoft.AspNetCore.Http.Result.Results! -static Microsoft.AspNetCore.Http.Result.Results.implicit operator Microsoft.AspNetCore.Http.Result.Results!(TResult5 result) -> Microsoft.AspNetCore.Http.Result.Results! -static Microsoft.AspNetCore.Http.Result.Results.implicit operator Microsoft.AspNetCore.Http.Result.Results!(TResult6 result) -> Microsoft.AspNetCore.Http.Result.Results! -static Microsoft.AspNetCore.Http.Result.Results.implicit operator Microsoft.AspNetCore.Http.Result.Results!(TResult7 result) -> Microsoft.AspNetCore.Http.Result.Results! -static Microsoft.AspNetCore.Http.Result.Results.implicit operator Microsoft.AspNetCore.Http.Result.Results!(TResult8 result) -> Microsoft.AspNetCore.Http.Result.Results! -static Microsoft.AspNetCore.Http.Result.Results.implicit operator Microsoft.AspNetCore.Http.Result.Results!(TResult9 result) -> Microsoft.AspNetCore.Http.Result.Results! -static Microsoft.AspNetCore.Http.Result.Results.implicit operator Microsoft.AspNetCore.Http.Result.Results!(TResult1 result) -> Microsoft.AspNetCore.Http.Result.Results! -static Microsoft.AspNetCore.Http.Result.Results.implicit operator Microsoft.AspNetCore.Http.Result.Results!(TResult10 result) -> Microsoft.AspNetCore.Http.Result.Results! -static Microsoft.AspNetCore.Http.Result.Results.implicit operator Microsoft.AspNetCore.Http.Result.Results!(TResult11 result) -> Microsoft.AspNetCore.Http.Result.Results! -static Microsoft.AspNetCore.Http.Result.Results.implicit operator Microsoft.AspNetCore.Http.Result.Results!(TResult12 result) -> Microsoft.AspNetCore.Http.Result.Results! -static Microsoft.AspNetCore.Http.Result.Results.implicit operator Microsoft.AspNetCore.Http.Result.Results!(TResult13 result) -> Microsoft.AspNetCore.Http.Result.Results! -static Microsoft.AspNetCore.Http.Result.Results.implicit operator Microsoft.AspNetCore.Http.Result.Results!(TResult14 result) -> Microsoft.AspNetCore.Http.Result.Results! -static Microsoft.AspNetCore.Http.Result.Results.implicit operator Microsoft.AspNetCore.Http.Result.Results!(TResult15 result) -> Microsoft.AspNetCore.Http.Result.Results! -static Microsoft.AspNetCore.Http.Result.Results.implicit operator Microsoft.AspNetCore.Http.Result.Results!(TResult2 result) -> Microsoft.AspNetCore.Http.Result.Results! -static Microsoft.AspNetCore.Http.Result.Results.implicit operator Microsoft.AspNetCore.Http.Result.Results!(TResult3 result) -> Microsoft.AspNetCore.Http.Result.Results! -static Microsoft.AspNetCore.Http.Result.Results.implicit operator Microsoft.AspNetCore.Http.Result.Results!(TResult4 result) -> Microsoft.AspNetCore.Http.Result.Results! -static Microsoft.AspNetCore.Http.Result.Results.implicit operator Microsoft.AspNetCore.Http.Result.Results!(TResult5 result) -> Microsoft.AspNetCore.Http.Result.Results! -static Microsoft.AspNetCore.Http.Result.Results.implicit operator Microsoft.AspNetCore.Http.Result.Results!(TResult6 result) -> Microsoft.AspNetCore.Http.Result.Results! -static Microsoft.AspNetCore.Http.Result.Results.implicit operator Microsoft.AspNetCore.Http.Result.Results!(TResult7 result) -> Microsoft.AspNetCore.Http.Result.Results! -static Microsoft.AspNetCore.Http.Result.Results.implicit operator Microsoft.AspNetCore.Http.Result.Results!(TResult8 result) -> Microsoft.AspNetCore.Http.Result.Results! -static Microsoft.AspNetCore.Http.Result.Results.implicit operator Microsoft.AspNetCore.Http.Result.Results!(TResult9 result) -> Microsoft.AspNetCore.Http.Result.Results! -static Microsoft.AspNetCore.Http.Result.Results.implicit operator Microsoft.AspNetCore.Http.Result.Results!(TResult1 result) -> Microsoft.AspNetCore.Http.Result.Results! -static Microsoft.AspNetCore.Http.Result.Results.implicit operator Microsoft.AspNetCore.Http.Result.Results!(TResult10 result) -> Microsoft.AspNetCore.Http.Result.Results! -static Microsoft.AspNetCore.Http.Result.Results.implicit operator Microsoft.AspNetCore.Http.Result.Results!(TResult11 result) -> Microsoft.AspNetCore.Http.Result.Results! -static Microsoft.AspNetCore.Http.Result.Results.implicit operator Microsoft.AspNetCore.Http.Result.Results!(TResult12 result) -> Microsoft.AspNetCore.Http.Result.Results! -static Microsoft.AspNetCore.Http.Result.Results.implicit operator Microsoft.AspNetCore.Http.Result.Results!(TResult13 result) -> Microsoft.AspNetCore.Http.Result.Results! -static Microsoft.AspNetCore.Http.Result.Results.implicit operator Microsoft.AspNetCore.Http.Result.Results!(TResult14 result) -> Microsoft.AspNetCore.Http.Result.Results! -static Microsoft.AspNetCore.Http.Result.Results.implicit operator Microsoft.AspNetCore.Http.Result.Results!(TResult2 result) -> Microsoft.AspNetCore.Http.Result.Results! -static Microsoft.AspNetCore.Http.Result.Results.implicit operator Microsoft.AspNetCore.Http.Result.Results!(TResult3 result) -> Microsoft.AspNetCore.Http.Result.Results! -static Microsoft.AspNetCore.Http.Result.Results.implicit operator Microsoft.AspNetCore.Http.Result.Results!(TResult4 result) -> Microsoft.AspNetCore.Http.Result.Results! -static Microsoft.AspNetCore.Http.Result.Results.implicit operator Microsoft.AspNetCore.Http.Result.Results!(TResult5 result) -> Microsoft.AspNetCore.Http.Result.Results! -static Microsoft.AspNetCore.Http.Result.Results.implicit operator Microsoft.AspNetCore.Http.Result.Results!(TResult6 result) -> Microsoft.AspNetCore.Http.Result.Results! -static Microsoft.AspNetCore.Http.Result.Results.implicit operator Microsoft.AspNetCore.Http.Result.Results!(TResult7 result) -> Microsoft.AspNetCore.Http.Result.Results! -static Microsoft.AspNetCore.Http.Result.Results.implicit operator Microsoft.AspNetCore.Http.Result.Results!(TResult8 result) -> Microsoft.AspNetCore.Http.Result.Results! -static Microsoft.AspNetCore.Http.Result.Results.implicit operator Microsoft.AspNetCore.Http.Result.Results!(TResult9 result) -> Microsoft.AspNetCore.Http.Result.Results! -static Microsoft.AspNetCore.Http.Result.Results.implicit operator Microsoft.AspNetCore.Http.Result.Results!(TResult1 result) -> Microsoft.AspNetCore.Http.Result.Results! -static Microsoft.AspNetCore.Http.Result.Results.implicit operator Microsoft.AspNetCore.Http.Result.Results!(TResult10 result) -> Microsoft.AspNetCore.Http.Result.Results! -static Microsoft.AspNetCore.Http.Result.Results.implicit operator Microsoft.AspNetCore.Http.Result.Results!(TResult11 result) -> Microsoft.AspNetCore.Http.Result.Results! -static Microsoft.AspNetCore.Http.Result.Results.implicit operator Microsoft.AspNetCore.Http.Result.Results!(TResult12 result) -> Microsoft.AspNetCore.Http.Result.Results! -static Microsoft.AspNetCore.Http.Result.Results.implicit operator Microsoft.AspNetCore.Http.Result.Results!(TResult13 result) -> Microsoft.AspNetCore.Http.Result.Results! -static Microsoft.AspNetCore.Http.Result.Results.implicit operator Microsoft.AspNetCore.Http.Result.Results!(TResult2 result) -> Microsoft.AspNetCore.Http.Result.Results! -static Microsoft.AspNetCore.Http.Result.Results.implicit operator Microsoft.AspNetCore.Http.Result.Results!(TResult3 result) -> Microsoft.AspNetCore.Http.Result.Results! -static Microsoft.AspNetCore.Http.Result.Results.implicit operator Microsoft.AspNetCore.Http.Result.Results!(TResult4 result) -> Microsoft.AspNetCore.Http.Result.Results! -static Microsoft.AspNetCore.Http.Result.Results.implicit operator Microsoft.AspNetCore.Http.Result.Results!(TResult5 result) -> Microsoft.AspNetCore.Http.Result.Results! -static Microsoft.AspNetCore.Http.Result.Results.implicit operator Microsoft.AspNetCore.Http.Result.Results!(TResult6 result) -> Microsoft.AspNetCore.Http.Result.Results! -static Microsoft.AspNetCore.Http.Result.Results.implicit operator Microsoft.AspNetCore.Http.Result.Results!(TResult7 result) -> Microsoft.AspNetCore.Http.Result.Results! -static Microsoft.AspNetCore.Http.Result.Results.implicit operator Microsoft.AspNetCore.Http.Result.Results!(TResult8 result) -> Microsoft.AspNetCore.Http.Result.Results! -static Microsoft.AspNetCore.Http.Result.Results.implicit operator Microsoft.AspNetCore.Http.Result.Results!(TResult9 result) -> Microsoft.AspNetCore.Http.Result.Results! -static Microsoft.AspNetCore.Http.Result.Results.implicit operator Microsoft.AspNetCore.Http.Result.Results!(TResult1 result) -> Microsoft.AspNetCore.Http.Result.Results! -static Microsoft.AspNetCore.Http.Result.Results.implicit operator Microsoft.AspNetCore.Http.Result.Results!(TResult10 result) -> Microsoft.AspNetCore.Http.Result.Results! -static Microsoft.AspNetCore.Http.Result.Results.implicit operator Microsoft.AspNetCore.Http.Result.Results!(TResult11 result) -> Microsoft.AspNetCore.Http.Result.Results! -static Microsoft.AspNetCore.Http.Result.Results.implicit operator Microsoft.AspNetCore.Http.Result.Results!(TResult12 result) -> Microsoft.AspNetCore.Http.Result.Results! -static Microsoft.AspNetCore.Http.Result.Results.implicit operator Microsoft.AspNetCore.Http.Result.Results!(TResult2 result) -> Microsoft.AspNetCore.Http.Result.Results! -static Microsoft.AspNetCore.Http.Result.Results.implicit operator Microsoft.AspNetCore.Http.Result.Results!(TResult3 result) -> Microsoft.AspNetCore.Http.Result.Results! -static Microsoft.AspNetCore.Http.Result.Results.implicit operator Microsoft.AspNetCore.Http.Result.Results!(TResult4 result) -> Microsoft.AspNetCore.Http.Result.Results! -static Microsoft.AspNetCore.Http.Result.Results.implicit operator Microsoft.AspNetCore.Http.Result.Results!(TResult5 result) -> Microsoft.AspNetCore.Http.Result.Results! -static Microsoft.AspNetCore.Http.Result.Results.implicit operator Microsoft.AspNetCore.Http.Result.Results!(TResult6 result) -> Microsoft.AspNetCore.Http.Result.Results! -static Microsoft.AspNetCore.Http.Result.Results.implicit operator Microsoft.AspNetCore.Http.Result.Results!(TResult7 result) -> Microsoft.AspNetCore.Http.Result.Results! -static Microsoft.AspNetCore.Http.Result.Results.implicit operator Microsoft.AspNetCore.Http.Result.Results!(TResult8 result) -> Microsoft.AspNetCore.Http.Result.Results! -static Microsoft.AspNetCore.Http.Result.Results.implicit operator Microsoft.AspNetCore.Http.Result.Results!(TResult9 result) -> Microsoft.AspNetCore.Http.Result.Results! -static Microsoft.AspNetCore.Http.Result.Results.implicit operator Microsoft.AspNetCore.Http.Result.Results!(TResult1 result) -> Microsoft.AspNetCore.Http.Result.Results! -static Microsoft.AspNetCore.Http.Result.Results.implicit operator Microsoft.AspNetCore.Http.Result.Results!(TResult10 result) -> Microsoft.AspNetCore.Http.Result.Results! -static Microsoft.AspNetCore.Http.Result.Results.implicit operator Microsoft.AspNetCore.Http.Result.Results!(TResult11 result) -> Microsoft.AspNetCore.Http.Result.Results! -static Microsoft.AspNetCore.Http.Result.Results.implicit operator Microsoft.AspNetCore.Http.Result.Results!(TResult2 result) -> Microsoft.AspNetCore.Http.Result.Results! -static Microsoft.AspNetCore.Http.Result.Results.implicit operator Microsoft.AspNetCore.Http.Result.Results!(TResult3 result) -> Microsoft.AspNetCore.Http.Result.Results! -static Microsoft.AspNetCore.Http.Result.Results.implicit operator Microsoft.AspNetCore.Http.Result.Results!(TResult4 result) -> Microsoft.AspNetCore.Http.Result.Results! -static Microsoft.AspNetCore.Http.Result.Results.implicit operator Microsoft.AspNetCore.Http.Result.Results!(TResult5 result) -> Microsoft.AspNetCore.Http.Result.Results! -static Microsoft.AspNetCore.Http.Result.Results.implicit operator Microsoft.AspNetCore.Http.Result.Results!(TResult6 result) -> Microsoft.AspNetCore.Http.Result.Results! -static Microsoft.AspNetCore.Http.Result.Results.implicit operator Microsoft.AspNetCore.Http.Result.Results!(TResult7 result) -> Microsoft.AspNetCore.Http.Result.Results! -static Microsoft.AspNetCore.Http.Result.Results.implicit operator Microsoft.AspNetCore.Http.Result.Results!(TResult8 result) -> Microsoft.AspNetCore.Http.Result.Results! -static Microsoft.AspNetCore.Http.Result.Results.implicit operator Microsoft.AspNetCore.Http.Result.Results!(TResult9 result) -> Microsoft.AspNetCore.Http.Result.Results! -static Microsoft.AspNetCore.Http.Result.Results.implicit operator Microsoft.AspNetCore.Http.Result.Results!(TResult1 result) -> Microsoft.AspNetCore.Http.Result.Results! -static Microsoft.AspNetCore.Http.Result.Results.implicit operator Microsoft.AspNetCore.Http.Result.Results!(TResult10 result) -> Microsoft.AspNetCore.Http.Result.Results! -static Microsoft.AspNetCore.Http.Result.Results.implicit operator Microsoft.AspNetCore.Http.Result.Results!(TResult2 result) -> Microsoft.AspNetCore.Http.Result.Results! -static Microsoft.AspNetCore.Http.Result.Results.implicit operator Microsoft.AspNetCore.Http.Result.Results!(TResult3 result) -> Microsoft.AspNetCore.Http.Result.Results! -static Microsoft.AspNetCore.Http.Result.Results.implicit operator Microsoft.AspNetCore.Http.Result.Results!(TResult4 result) -> Microsoft.AspNetCore.Http.Result.Results! -static Microsoft.AspNetCore.Http.Result.Results.implicit operator Microsoft.AspNetCore.Http.Result.Results!(TResult5 result) -> Microsoft.AspNetCore.Http.Result.Results! -static Microsoft.AspNetCore.Http.Result.Results.implicit operator Microsoft.AspNetCore.Http.Result.Results!(TResult6 result) -> Microsoft.AspNetCore.Http.Result.Results! -static Microsoft.AspNetCore.Http.Result.Results.implicit operator Microsoft.AspNetCore.Http.Result.Results!(TResult7 result) -> Microsoft.AspNetCore.Http.Result.Results! -static Microsoft.AspNetCore.Http.Result.Results.implicit operator Microsoft.AspNetCore.Http.Result.Results!(TResult8 result) -> Microsoft.AspNetCore.Http.Result.Results! -static Microsoft.AspNetCore.Http.Result.Results.implicit operator Microsoft.AspNetCore.Http.Result.Results!(TResult9 result) -> Microsoft.AspNetCore.Http.Result.Results! -static Microsoft.AspNetCore.Http.Result.Results.implicit operator Microsoft.AspNetCore.Http.Result.Results!(TResult1 result) -> Microsoft.AspNetCore.Http.Result.Results! -static Microsoft.AspNetCore.Http.Result.Results.implicit operator Microsoft.AspNetCore.Http.Result.Results!(TResult2 result) -> Microsoft.AspNetCore.Http.Result.Results! -static Microsoft.AspNetCore.Http.Result.Results.implicit operator Microsoft.AspNetCore.Http.Result.Results!(TResult3 result) -> Microsoft.AspNetCore.Http.Result.Results! -static Microsoft.AspNetCore.Http.Result.Results.implicit operator Microsoft.AspNetCore.Http.Result.Results!(TResult4 result) -> Microsoft.AspNetCore.Http.Result.Results! -static Microsoft.AspNetCore.Http.Result.Results.implicit operator Microsoft.AspNetCore.Http.Result.Results!(TResult5 result) -> Microsoft.AspNetCore.Http.Result.Results! -static Microsoft.AspNetCore.Http.Result.Results.implicit operator Microsoft.AspNetCore.Http.Result.Results!(TResult6 result) -> Microsoft.AspNetCore.Http.Result.Results! -static Microsoft.AspNetCore.Http.Result.Results.implicit operator Microsoft.AspNetCore.Http.Result.Results!(TResult7 result) -> Microsoft.AspNetCore.Http.Result.Results! -static Microsoft.AspNetCore.Http.Result.Results.implicit operator Microsoft.AspNetCore.Http.Result.Results!(TResult8 result) -> Microsoft.AspNetCore.Http.Result.Results! -static Microsoft.AspNetCore.Http.Result.Results.implicit operator Microsoft.AspNetCore.Http.Result.Results!(TResult9 result) -> Microsoft.AspNetCore.Http.Result.Results! -static Microsoft.AspNetCore.Http.Result.Results.implicit operator Microsoft.AspNetCore.Http.Result.Results!(TResult1 result) -> Microsoft.AspNetCore.Http.Result.Results! -static Microsoft.AspNetCore.Http.Result.Results.implicit operator Microsoft.AspNetCore.Http.Result.Results!(TResult2 result) -> Microsoft.AspNetCore.Http.Result.Results! -static Microsoft.AspNetCore.Http.Result.Results.implicit operator Microsoft.AspNetCore.Http.Result.Results!(TResult3 result) -> Microsoft.AspNetCore.Http.Result.Results! -static Microsoft.AspNetCore.Http.Result.Results.implicit operator Microsoft.AspNetCore.Http.Result.Results!(TResult4 result) -> Microsoft.AspNetCore.Http.Result.Results! -static Microsoft.AspNetCore.Http.Result.Results.implicit operator Microsoft.AspNetCore.Http.Result.Results!(TResult5 result) -> Microsoft.AspNetCore.Http.Result.Results! -static Microsoft.AspNetCore.Http.Result.Results.implicit operator Microsoft.AspNetCore.Http.Result.Results!(TResult6 result) -> Microsoft.AspNetCore.Http.Result.Results! -static Microsoft.AspNetCore.Http.Result.Results.implicit operator Microsoft.AspNetCore.Http.Result.Results!(TResult7 result) -> Microsoft.AspNetCore.Http.Result.Results! -static Microsoft.AspNetCore.Http.Result.Results.implicit operator Microsoft.AspNetCore.Http.Result.Results!(TResult8 result) -> Microsoft.AspNetCore.Http.Result.Results! -static Microsoft.AspNetCore.Http.Result.Results.implicit operator Microsoft.AspNetCore.Http.Result.Results!(TResult1 result) -> Microsoft.AspNetCore.Http.Result.Results! -static Microsoft.AspNetCore.Http.Result.Results.implicit operator Microsoft.AspNetCore.Http.Result.Results!(TResult2 result) -> Microsoft.AspNetCore.Http.Result.Results! -static Microsoft.AspNetCore.Http.Result.Results.implicit operator Microsoft.AspNetCore.Http.Result.Results!(TResult3 result) -> Microsoft.AspNetCore.Http.Result.Results! -static Microsoft.AspNetCore.Http.Result.Results.implicit operator Microsoft.AspNetCore.Http.Result.Results!(TResult4 result) -> Microsoft.AspNetCore.Http.Result.Results! -static Microsoft.AspNetCore.Http.Result.Results.implicit operator Microsoft.AspNetCore.Http.Result.Results!(TResult5 result) -> Microsoft.AspNetCore.Http.Result.Results! -static Microsoft.AspNetCore.Http.Result.Results.implicit operator Microsoft.AspNetCore.Http.Result.Results!(TResult6 result) -> Microsoft.AspNetCore.Http.Result.Results! -static Microsoft.AspNetCore.Http.Result.Results.implicit operator Microsoft.AspNetCore.Http.Result.Results!(TResult7 result) -> Microsoft.AspNetCore.Http.Result.Results! -static Microsoft.AspNetCore.Http.Result.Results.implicit operator Microsoft.AspNetCore.Http.Result.Results!(TResult1 result) -> Microsoft.AspNetCore.Http.Result.Results! -static Microsoft.AspNetCore.Http.Result.Results.implicit operator Microsoft.AspNetCore.Http.Result.Results!(TResult2 result) -> Microsoft.AspNetCore.Http.Result.Results! -static Microsoft.AspNetCore.Http.Result.Results.implicit operator Microsoft.AspNetCore.Http.Result.Results!(TResult3 result) -> Microsoft.AspNetCore.Http.Result.Results! -static Microsoft.AspNetCore.Http.Result.Results.implicit operator Microsoft.AspNetCore.Http.Result.Results!(TResult4 result) -> Microsoft.AspNetCore.Http.Result.Results! -static Microsoft.AspNetCore.Http.Result.Results.implicit operator Microsoft.AspNetCore.Http.Result.Results!(TResult5 result) -> Microsoft.AspNetCore.Http.Result.Results! -static Microsoft.AspNetCore.Http.Result.Results.implicit operator Microsoft.AspNetCore.Http.Result.Results!(TResult6 result) -> Microsoft.AspNetCore.Http.Result.Results! -static Microsoft.AspNetCore.Http.Result.Results.implicit operator Microsoft.AspNetCore.Http.Result.Results!(TResult1 result) -> Microsoft.AspNetCore.Http.Result.Results! -static Microsoft.AspNetCore.Http.Result.Results.implicit operator Microsoft.AspNetCore.Http.Result.Results!(TResult2 result) -> Microsoft.AspNetCore.Http.Result.Results! -static Microsoft.AspNetCore.Http.Result.Results.implicit operator Microsoft.AspNetCore.Http.Result.Results!(TResult3 result) -> Microsoft.AspNetCore.Http.Result.Results! -static Microsoft.AspNetCore.Http.Result.Results.implicit operator Microsoft.AspNetCore.Http.Result.Results!(TResult4 result) -> Microsoft.AspNetCore.Http.Result.Results! -static Microsoft.AspNetCore.Http.Result.Results.implicit operator Microsoft.AspNetCore.Http.Result.Results!(TResult5 result) -> Microsoft.AspNetCore.Http.Result.Results! -static Microsoft.AspNetCore.Http.Result.Results.implicit operator Microsoft.AspNetCore.Http.Result.Results!(TResult1 result) -> Microsoft.AspNetCore.Http.Result.Results! -static Microsoft.AspNetCore.Http.Result.Results.implicit operator Microsoft.AspNetCore.Http.Result.Results!(TResult2 result) -> Microsoft.AspNetCore.Http.Result.Results! -static Microsoft.AspNetCore.Http.Result.Results.implicit operator Microsoft.AspNetCore.Http.Result.Results!(TResult3 result) -> Microsoft.AspNetCore.Http.Result.Results! -static Microsoft.AspNetCore.Http.Result.Results.implicit operator Microsoft.AspNetCore.Http.Result.Results!(TResult4 result) -> Microsoft.AspNetCore.Http.Result.Results! -static Microsoft.AspNetCore.Http.Result.Results.implicit operator Microsoft.AspNetCore.Http.Result.Results!(TResult1 result) -> Microsoft.AspNetCore.Http.Result.Results! -static Microsoft.AspNetCore.Http.Result.Results.implicit operator Microsoft.AspNetCore.Http.Result.Results!(TResult2 result) -> Microsoft.AspNetCore.Http.Result.Results! -static Microsoft.AspNetCore.Http.Result.Results.implicit operator Microsoft.AspNetCore.Http.Result.Results!(TResult3 result) -> Microsoft.AspNetCore.Http.Result.Results! -static Microsoft.AspNetCore.Http.Result.Results.implicit operator Microsoft.AspNetCore.Http.Result.Results!(TResult1 result) -> Microsoft.AspNetCore.Http.Result.Results! -static Microsoft.AspNetCore.Http.Result.Results.implicit operator Microsoft.AspNetCore.Http.Result.Results!(TResult2 result) -> Microsoft.AspNetCore.Http.Result.Results! -static Microsoft.AspNetCore.Http.Result.Results.implicit operator Microsoft.AspNetCore.Http.Result.Results!(TResult1 result) -> Microsoft.AspNetCore.Http.Result.Results! static Microsoft.AspNetCore.Http.Results.Bytes(System.ReadOnlyMemory contents, string? contentType = null, string? fileDownloadName = null, bool enableRangeProcessing = false, System.DateTimeOffset? lastModified = null, Microsoft.Net.Http.Headers.EntityTagHeaderValue? entityTag = null) -> Microsoft.AspNetCore.Http.IResult! static Microsoft.AspNetCore.Http.Results.Empty.get -> Microsoft.AspNetCore.Http.IResult! static Microsoft.AspNetCore.Http.Results.Stream(System.Func! streamWriterCallback, string? contentType = null, string? fileDownloadName = null, System.DateTimeOffset? lastModified = null, Microsoft.Net.Http.Headers.EntityTagHeaderValue? entityTag = null) -> Microsoft.AspNetCore.Http.IResult! static Microsoft.AspNetCore.Http.Results.Stream(System.IO.Pipelines.PipeReader! pipeReader, string? contentType = null, string? fileDownloadName = null, System.DateTimeOffset? lastModified = null, Microsoft.Net.Http.Headers.EntityTagHeaderValue? entityTag = null, bool enableRangeProcessing = false) -> Microsoft.AspNetCore.Http.IResult! +static Microsoft.AspNetCore.Http.Results.implicit operator Microsoft.AspNetCore.Http.Results!(TResult1 result) -> Microsoft.AspNetCore.Http.Results! +static Microsoft.AspNetCore.Http.Results.implicit operator Microsoft.AspNetCore.Http.Results!(TResult10 result) -> Microsoft.AspNetCore.Http.Results! +static Microsoft.AspNetCore.Http.Results.implicit operator Microsoft.AspNetCore.Http.Results!(TResult11 result) -> Microsoft.AspNetCore.Http.Results! +static Microsoft.AspNetCore.Http.Results.implicit operator Microsoft.AspNetCore.Http.Results!(TResult12 result) -> Microsoft.AspNetCore.Http.Results! +static Microsoft.AspNetCore.Http.Results.implicit operator Microsoft.AspNetCore.Http.Results!(TResult13 result) -> Microsoft.AspNetCore.Http.Results! +static Microsoft.AspNetCore.Http.Results.implicit operator Microsoft.AspNetCore.Http.Results!(TResult14 result) -> Microsoft.AspNetCore.Http.Results! +static Microsoft.AspNetCore.Http.Results.implicit operator Microsoft.AspNetCore.Http.Results!(TResult15 result) -> Microsoft.AspNetCore.Http.Results! +static Microsoft.AspNetCore.Http.Results.implicit operator Microsoft.AspNetCore.Http.Results!(TResult16 result) -> Microsoft.AspNetCore.Http.Results! +static Microsoft.AspNetCore.Http.Results.implicit operator Microsoft.AspNetCore.Http.Results!(TResult2 result) -> Microsoft.AspNetCore.Http.Results! +static Microsoft.AspNetCore.Http.Results.implicit operator Microsoft.AspNetCore.Http.Results!(TResult3 result) -> Microsoft.AspNetCore.Http.Results! +static Microsoft.AspNetCore.Http.Results.implicit operator Microsoft.AspNetCore.Http.Results!(TResult4 result) -> Microsoft.AspNetCore.Http.Results! +static Microsoft.AspNetCore.Http.Results.implicit operator Microsoft.AspNetCore.Http.Results!(TResult5 result) -> Microsoft.AspNetCore.Http.Results! +static Microsoft.AspNetCore.Http.Results.implicit operator Microsoft.AspNetCore.Http.Results!(TResult6 result) -> Microsoft.AspNetCore.Http.Results! +static Microsoft.AspNetCore.Http.Results.implicit operator Microsoft.AspNetCore.Http.Results!(TResult7 result) -> Microsoft.AspNetCore.Http.Results! +static Microsoft.AspNetCore.Http.Results.implicit operator Microsoft.AspNetCore.Http.Results!(TResult8 result) -> Microsoft.AspNetCore.Http.Results! +static Microsoft.AspNetCore.Http.Results.implicit operator Microsoft.AspNetCore.Http.Results!(TResult9 result) -> Microsoft.AspNetCore.Http.Results! +static Microsoft.AspNetCore.Http.Results.implicit operator Microsoft.AspNetCore.Http.Results!(TResult1 result) -> Microsoft.AspNetCore.Http.Results! +static Microsoft.AspNetCore.Http.Results.implicit operator Microsoft.AspNetCore.Http.Results!(TResult10 result) -> Microsoft.AspNetCore.Http.Results! +static Microsoft.AspNetCore.Http.Results.implicit operator Microsoft.AspNetCore.Http.Results!(TResult11 result) -> Microsoft.AspNetCore.Http.Results! +static Microsoft.AspNetCore.Http.Results.implicit operator Microsoft.AspNetCore.Http.Results!(TResult12 result) -> Microsoft.AspNetCore.Http.Results! +static Microsoft.AspNetCore.Http.Results.implicit operator Microsoft.AspNetCore.Http.Results!(TResult13 result) -> Microsoft.AspNetCore.Http.Results! +static Microsoft.AspNetCore.Http.Results.implicit operator Microsoft.AspNetCore.Http.Results!(TResult14 result) -> Microsoft.AspNetCore.Http.Results! +static Microsoft.AspNetCore.Http.Results.implicit operator Microsoft.AspNetCore.Http.Results!(TResult15 result) -> Microsoft.AspNetCore.Http.Results! +static Microsoft.AspNetCore.Http.Results.implicit operator Microsoft.AspNetCore.Http.Results!(TResult2 result) -> Microsoft.AspNetCore.Http.Results! +static Microsoft.AspNetCore.Http.Results.implicit operator Microsoft.AspNetCore.Http.Results!(TResult3 result) -> Microsoft.AspNetCore.Http.Results! +static Microsoft.AspNetCore.Http.Results.implicit operator Microsoft.AspNetCore.Http.Results!(TResult4 result) -> Microsoft.AspNetCore.Http.Results! +static Microsoft.AspNetCore.Http.Results.implicit operator Microsoft.AspNetCore.Http.Results!(TResult5 result) -> Microsoft.AspNetCore.Http.Results! +static Microsoft.AspNetCore.Http.Results.implicit operator Microsoft.AspNetCore.Http.Results!(TResult6 result) -> Microsoft.AspNetCore.Http.Results! +static Microsoft.AspNetCore.Http.Results.implicit operator Microsoft.AspNetCore.Http.Results!(TResult7 result) -> Microsoft.AspNetCore.Http.Results! +static Microsoft.AspNetCore.Http.Results.implicit operator Microsoft.AspNetCore.Http.Results!(TResult8 result) -> Microsoft.AspNetCore.Http.Results! +static Microsoft.AspNetCore.Http.Results.implicit operator Microsoft.AspNetCore.Http.Results!(TResult9 result) -> Microsoft.AspNetCore.Http.Results! +static Microsoft.AspNetCore.Http.Results.implicit operator Microsoft.AspNetCore.Http.Results!(TResult1 result) -> Microsoft.AspNetCore.Http.Results! +static Microsoft.AspNetCore.Http.Results.implicit operator Microsoft.AspNetCore.Http.Results!(TResult10 result) -> Microsoft.AspNetCore.Http.Results! +static Microsoft.AspNetCore.Http.Results.implicit operator Microsoft.AspNetCore.Http.Results!(TResult11 result) -> Microsoft.AspNetCore.Http.Results! +static Microsoft.AspNetCore.Http.Results.implicit operator Microsoft.AspNetCore.Http.Results!(TResult12 result) -> Microsoft.AspNetCore.Http.Results! +static Microsoft.AspNetCore.Http.Results.implicit operator Microsoft.AspNetCore.Http.Results!(TResult13 result) -> Microsoft.AspNetCore.Http.Results! +static Microsoft.AspNetCore.Http.Results.implicit operator Microsoft.AspNetCore.Http.Results!(TResult14 result) -> Microsoft.AspNetCore.Http.Results! +static Microsoft.AspNetCore.Http.Results.implicit operator Microsoft.AspNetCore.Http.Results!(TResult2 result) -> Microsoft.AspNetCore.Http.Results! +static Microsoft.AspNetCore.Http.Results.implicit operator Microsoft.AspNetCore.Http.Results!(TResult3 result) -> Microsoft.AspNetCore.Http.Results! +static Microsoft.AspNetCore.Http.Results.implicit operator Microsoft.AspNetCore.Http.Results!(TResult4 result) -> Microsoft.AspNetCore.Http.Results! +static Microsoft.AspNetCore.Http.Results.implicit operator Microsoft.AspNetCore.Http.Results!(TResult5 result) -> Microsoft.AspNetCore.Http.Results! +static Microsoft.AspNetCore.Http.Results.implicit operator Microsoft.AspNetCore.Http.Results!(TResult6 result) -> Microsoft.AspNetCore.Http.Results! +static Microsoft.AspNetCore.Http.Results.implicit operator Microsoft.AspNetCore.Http.Results!(TResult7 result) -> Microsoft.AspNetCore.Http.Results! +static Microsoft.AspNetCore.Http.Results.implicit operator Microsoft.AspNetCore.Http.Results!(TResult8 result) -> Microsoft.AspNetCore.Http.Results! +static Microsoft.AspNetCore.Http.Results.implicit operator Microsoft.AspNetCore.Http.Results!(TResult9 result) -> Microsoft.AspNetCore.Http.Results! +static Microsoft.AspNetCore.Http.Results.implicit operator Microsoft.AspNetCore.Http.Results!(TResult1 result) -> Microsoft.AspNetCore.Http.Results! +static Microsoft.AspNetCore.Http.Results.implicit operator Microsoft.AspNetCore.Http.Results!(TResult10 result) -> Microsoft.AspNetCore.Http.Results! +static Microsoft.AspNetCore.Http.Results.implicit operator Microsoft.AspNetCore.Http.Results!(TResult11 result) -> Microsoft.AspNetCore.Http.Results! +static Microsoft.AspNetCore.Http.Results.implicit operator Microsoft.AspNetCore.Http.Results!(TResult12 result) -> Microsoft.AspNetCore.Http.Results! +static Microsoft.AspNetCore.Http.Results.implicit operator Microsoft.AspNetCore.Http.Results!(TResult13 result) -> Microsoft.AspNetCore.Http.Results! +static Microsoft.AspNetCore.Http.Results.implicit operator Microsoft.AspNetCore.Http.Results!(TResult2 result) -> Microsoft.AspNetCore.Http.Results! +static Microsoft.AspNetCore.Http.Results.implicit operator Microsoft.AspNetCore.Http.Results!(TResult3 result) -> Microsoft.AspNetCore.Http.Results! +static Microsoft.AspNetCore.Http.Results.implicit operator Microsoft.AspNetCore.Http.Results!(TResult4 result) -> Microsoft.AspNetCore.Http.Results! +static Microsoft.AspNetCore.Http.Results.implicit operator Microsoft.AspNetCore.Http.Results!(TResult5 result) -> Microsoft.AspNetCore.Http.Results! +static Microsoft.AspNetCore.Http.Results.implicit operator Microsoft.AspNetCore.Http.Results!(TResult6 result) -> Microsoft.AspNetCore.Http.Results! +static Microsoft.AspNetCore.Http.Results.implicit operator Microsoft.AspNetCore.Http.Results!(TResult7 result) -> Microsoft.AspNetCore.Http.Results! +static Microsoft.AspNetCore.Http.Results.implicit operator Microsoft.AspNetCore.Http.Results!(TResult8 result) -> Microsoft.AspNetCore.Http.Results! +static Microsoft.AspNetCore.Http.Results.implicit operator Microsoft.AspNetCore.Http.Results!(TResult9 result) -> Microsoft.AspNetCore.Http.Results! +static Microsoft.AspNetCore.Http.Results.implicit operator Microsoft.AspNetCore.Http.Results!(TResult1 result) -> Microsoft.AspNetCore.Http.Results! +static Microsoft.AspNetCore.Http.Results.implicit operator Microsoft.AspNetCore.Http.Results!(TResult10 result) -> Microsoft.AspNetCore.Http.Results! +static Microsoft.AspNetCore.Http.Results.implicit operator Microsoft.AspNetCore.Http.Results!(TResult11 result) -> Microsoft.AspNetCore.Http.Results! +static Microsoft.AspNetCore.Http.Results.implicit operator Microsoft.AspNetCore.Http.Results!(TResult12 result) -> Microsoft.AspNetCore.Http.Results! +static Microsoft.AspNetCore.Http.Results.implicit operator Microsoft.AspNetCore.Http.Results!(TResult2 result) -> Microsoft.AspNetCore.Http.Results! +static Microsoft.AspNetCore.Http.Results.implicit operator Microsoft.AspNetCore.Http.Results!(TResult3 result) -> Microsoft.AspNetCore.Http.Results! +static Microsoft.AspNetCore.Http.Results.implicit operator Microsoft.AspNetCore.Http.Results!(TResult4 result) -> Microsoft.AspNetCore.Http.Results! +static Microsoft.AspNetCore.Http.Results.implicit operator Microsoft.AspNetCore.Http.Results!(TResult5 result) -> Microsoft.AspNetCore.Http.Results! +static Microsoft.AspNetCore.Http.Results.implicit operator Microsoft.AspNetCore.Http.Results!(TResult6 result) -> Microsoft.AspNetCore.Http.Results! +static Microsoft.AspNetCore.Http.Results.implicit operator Microsoft.AspNetCore.Http.Results!(TResult7 result) -> Microsoft.AspNetCore.Http.Results! +static Microsoft.AspNetCore.Http.Results.implicit operator Microsoft.AspNetCore.Http.Results!(TResult8 result) -> Microsoft.AspNetCore.Http.Results! +static Microsoft.AspNetCore.Http.Results.implicit operator Microsoft.AspNetCore.Http.Results!(TResult9 result) -> Microsoft.AspNetCore.Http.Results! +static Microsoft.AspNetCore.Http.Results.implicit operator Microsoft.AspNetCore.Http.Results!(TResult1 result) -> Microsoft.AspNetCore.Http.Results! +static Microsoft.AspNetCore.Http.Results.implicit operator Microsoft.AspNetCore.Http.Results!(TResult10 result) -> Microsoft.AspNetCore.Http.Results! +static Microsoft.AspNetCore.Http.Results.implicit operator Microsoft.AspNetCore.Http.Results!(TResult11 result) -> Microsoft.AspNetCore.Http.Results! +static Microsoft.AspNetCore.Http.Results.implicit operator Microsoft.AspNetCore.Http.Results!(TResult2 result) -> Microsoft.AspNetCore.Http.Results! +static Microsoft.AspNetCore.Http.Results.implicit operator Microsoft.AspNetCore.Http.Results!(TResult3 result) -> Microsoft.AspNetCore.Http.Results! +static Microsoft.AspNetCore.Http.Results.implicit operator Microsoft.AspNetCore.Http.Results!(TResult4 result) -> Microsoft.AspNetCore.Http.Results! +static Microsoft.AspNetCore.Http.Results.implicit operator Microsoft.AspNetCore.Http.Results!(TResult5 result) -> Microsoft.AspNetCore.Http.Results! +static Microsoft.AspNetCore.Http.Results.implicit operator Microsoft.AspNetCore.Http.Results!(TResult6 result) -> Microsoft.AspNetCore.Http.Results! +static Microsoft.AspNetCore.Http.Results.implicit operator Microsoft.AspNetCore.Http.Results!(TResult7 result) -> Microsoft.AspNetCore.Http.Results! +static Microsoft.AspNetCore.Http.Results.implicit operator Microsoft.AspNetCore.Http.Results!(TResult8 result) -> Microsoft.AspNetCore.Http.Results! +static Microsoft.AspNetCore.Http.Results.implicit operator Microsoft.AspNetCore.Http.Results!(TResult9 result) -> Microsoft.AspNetCore.Http.Results! +static Microsoft.AspNetCore.Http.Results.implicit operator Microsoft.AspNetCore.Http.Results!(TResult1 result) -> Microsoft.AspNetCore.Http.Results! +static Microsoft.AspNetCore.Http.Results.implicit operator Microsoft.AspNetCore.Http.Results!(TResult10 result) -> Microsoft.AspNetCore.Http.Results! +static Microsoft.AspNetCore.Http.Results.implicit operator Microsoft.AspNetCore.Http.Results!(TResult2 result) -> Microsoft.AspNetCore.Http.Results! +static Microsoft.AspNetCore.Http.Results.implicit operator Microsoft.AspNetCore.Http.Results!(TResult3 result) -> Microsoft.AspNetCore.Http.Results! +static Microsoft.AspNetCore.Http.Results.implicit operator Microsoft.AspNetCore.Http.Results!(TResult4 result) -> Microsoft.AspNetCore.Http.Results! +static Microsoft.AspNetCore.Http.Results.implicit operator Microsoft.AspNetCore.Http.Results!(TResult5 result) -> Microsoft.AspNetCore.Http.Results! +static Microsoft.AspNetCore.Http.Results.implicit operator Microsoft.AspNetCore.Http.Results!(TResult6 result) -> Microsoft.AspNetCore.Http.Results! +static Microsoft.AspNetCore.Http.Results.implicit operator Microsoft.AspNetCore.Http.Results!(TResult7 result) -> Microsoft.AspNetCore.Http.Results! +static Microsoft.AspNetCore.Http.Results.implicit operator Microsoft.AspNetCore.Http.Results!(TResult8 result) -> Microsoft.AspNetCore.Http.Results! +static Microsoft.AspNetCore.Http.Results.implicit operator Microsoft.AspNetCore.Http.Results!(TResult9 result) -> Microsoft.AspNetCore.Http.Results! +static Microsoft.AspNetCore.Http.Results.implicit operator Microsoft.AspNetCore.Http.Results!(TResult1 result) -> Microsoft.AspNetCore.Http.Results! +static Microsoft.AspNetCore.Http.Results.implicit operator Microsoft.AspNetCore.Http.Results!(TResult2 result) -> Microsoft.AspNetCore.Http.Results! +static Microsoft.AspNetCore.Http.Results.implicit operator Microsoft.AspNetCore.Http.Results!(TResult3 result) -> Microsoft.AspNetCore.Http.Results! +static Microsoft.AspNetCore.Http.Results.implicit operator Microsoft.AspNetCore.Http.Results!(TResult4 result) -> Microsoft.AspNetCore.Http.Results! +static Microsoft.AspNetCore.Http.Results.implicit operator Microsoft.AspNetCore.Http.Results!(TResult5 result) -> Microsoft.AspNetCore.Http.Results! +static Microsoft.AspNetCore.Http.Results.implicit operator Microsoft.AspNetCore.Http.Results!(TResult6 result) -> Microsoft.AspNetCore.Http.Results! +static Microsoft.AspNetCore.Http.Results.implicit operator Microsoft.AspNetCore.Http.Results!(TResult7 result) -> Microsoft.AspNetCore.Http.Results! +static Microsoft.AspNetCore.Http.Results.implicit operator Microsoft.AspNetCore.Http.Results!(TResult8 result) -> Microsoft.AspNetCore.Http.Results! +static Microsoft.AspNetCore.Http.Results.implicit operator Microsoft.AspNetCore.Http.Results!(TResult9 result) -> Microsoft.AspNetCore.Http.Results! +static Microsoft.AspNetCore.Http.Results.implicit operator Microsoft.AspNetCore.Http.Results!(TResult1 result) -> Microsoft.AspNetCore.Http.Results! +static Microsoft.AspNetCore.Http.Results.implicit operator Microsoft.AspNetCore.Http.Results!(TResult2 result) -> Microsoft.AspNetCore.Http.Results! +static Microsoft.AspNetCore.Http.Results.implicit operator Microsoft.AspNetCore.Http.Results!(TResult3 result) -> Microsoft.AspNetCore.Http.Results! +static Microsoft.AspNetCore.Http.Results.implicit operator Microsoft.AspNetCore.Http.Results!(TResult4 result) -> Microsoft.AspNetCore.Http.Results! +static Microsoft.AspNetCore.Http.Results.implicit operator Microsoft.AspNetCore.Http.Results!(TResult5 result) -> Microsoft.AspNetCore.Http.Results! +static Microsoft.AspNetCore.Http.Results.implicit operator Microsoft.AspNetCore.Http.Results!(TResult6 result) -> Microsoft.AspNetCore.Http.Results! +static Microsoft.AspNetCore.Http.Results.implicit operator Microsoft.AspNetCore.Http.Results!(TResult7 result) -> Microsoft.AspNetCore.Http.Results! +static Microsoft.AspNetCore.Http.Results.implicit operator Microsoft.AspNetCore.Http.Results!(TResult8 result) -> Microsoft.AspNetCore.Http.Results! +static Microsoft.AspNetCore.Http.Results.implicit operator Microsoft.AspNetCore.Http.Results!(TResult1 result) -> Microsoft.AspNetCore.Http.Results! +static Microsoft.AspNetCore.Http.Results.implicit operator Microsoft.AspNetCore.Http.Results!(TResult2 result) -> Microsoft.AspNetCore.Http.Results! +static Microsoft.AspNetCore.Http.Results.implicit operator Microsoft.AspNetCore.Http.Results!(TResult3 result) -> Microsoft.AspNetCore.Http.Results! +static Microsoft.AspNetCore.Http.Results.implicit operator Microsoft.AspNetCore.Http.Results!(TResult4 result) -> Microsoft.AspNetCore.Http.Results! +static Microsoft.AspNetCore.Http.Results.implicit operator Microsoft.AspNetCore.Http.Results!(TResult5 result) -> Microsoft.AspNetCore.Http.Results! +static Microsoft.AspNetCore.Http.Results.implicit operator Microsoft.AspNetCore.Http.Results!(TResult6 result) -> Microsoft.AspNetCore.Http.Results! +static Microsoft.AspNetCore.Http.Results.implicit operator Microsoft.AspNetCore.Http.Results!(TResult7 result) -> Microsoft.AspNetCore.Http.Results! +static Microsoft.AspNetCore.Http.Results.implicit operator Microsoft.AspNetCore.Http.Results!(TResult1 result) -> Microsoft.AspNetCore.Http.Results! +static Microsoft.AspNetCore.Http.Results.implicit operator Microsoft.AspNetCore.Http.Results!(TResult2 result) -> Microsoft.AspNetCore.Http.Results! +static Microsoft.AspNetCore.Http.Results.implicit operator Microsoft.AspNetCore.Http.Results!(TResult3 result) -> Microsoft.AspNetCore.Http.Results! +static Microsoft.AspNetCore.Http.Results.implicit operator Microsoft.AspNetCore.Http.Results!(TResult4 result) -> Microsoft.AspNetCore.Http.Results! +static Microsoft.AspNetCore.Http.Results.implicit operator Microsoft.AspNetCore.Http.Results!(TResult5 result) -> Microsoft.AspNetCore.Http.Results! +static Microsoft.AspNetCore.Http.Results.implicit operator Microsoft.AspNetCore.Http.Results!(TResult6 result) -> Microsoft.AspNetCore.Http.Results! +static Microsoft.AspNetCore.Http.Results.implicit operator Microsoft.AspNetCore.Http.Results!(TResult1 result) -> Microsoft.AspNetCore.Http.Results! +static Microsoft.AspNetCore.Http.Results.implicit operator Microsoft.AspNetCore.Http.Results!(TResult2 result) -> Microsoft.AspNetCore.Http.Results! +static Microsoft.AspNetCore.Http.Results.implicit operator Microsoft.AspNetCore.Http.Results!(TResult3 result) -> Microsoft.AspNetCore.Http.Results! +static Microsoft.AspNetCore.Http.Results.implicit operator Microsoft.AspNetCore.Http.Results!(TResult4 result) -> Microsoft.AspNetCore.Http.Results! +static Microsoft.AspNetCore.Http.Results.implicit operator Microsoft.AspNetCore.Http.Results!(TResult5 result) -> Microsoft.AspNetCore.Http.Results! +static Microsoft.AspNetCore.Http.Results.implicit operator Microsoft.AspNetCore.Http.Results!(TResult1 result) -> Microsoft.AspNetCore.Http.Results! +static Microsoft.AspNetCore.Http.Results.implicit operator Microsoft.AspNetCore.Http.Results!(TResult2 result) -> Microsoft.AspNetCore.Http.Results! +static Microsoft.AspNetCore.Http.Results.implicit operator Microsoft.AspNetCore.Http.Results!(TResult3 result) -> Microsoft.AspNetCore.Http.Results! +static Microsoft.AspNetCore.Http.Results.implicit operator Microsoft.AspNetCore.Http.Results!(TResult4 result) -> Microsoft.AspNetCore.Http.Results! +static Microsoft.AspNetCore.Http.Results.implicit operator Microsoft.AspNetCore.Http.Results!(TResult1 result) -> Microsoft.AspNetCore.Http.Results! +static Microsoft.AspNetCore.Http.Results.implicit operator Microsoft.AspNetCore.Http.Results!(TResult2 result) -> Microsoft.AspNetCore.Http.Results! +static Microsoft.AspNetCore.Http.Results.implicit operator Microsoft.AspNetCore.Http.Results!(TResult3 result) -> Microsoft.AspNetCore.Http.Results! +static Microsoft.AspNetCore.Http.Results.implicit operator Microsoft.AspNetCore.Http.Results!(TResult1 result) -> Microsoft.AspNetCore.Http.Results! +static Microsoft.AspNetCore.Http.Results.implicit operator Microsoft.AspNetCore.Http.Results!(TResult2 result) -> Microsoft.AspNetCore.Http.Results! diff --git a/src/Http/Http.Results/src/ResultsOfT.cs b/src/Http/Http.Results/src/ResultsOfT.cs index 770b257bb5f0..9cde02f6ff67 100644 --- a/src/Http/Http.Results/src/ResultsOfT.cs +++ b/src/Http/Http.Results/src/ResultsOfT.cs @@ -35,6 +35,11 @@ public async Task ExecuteAsync(HttpContext httpContext) { ArgumentNullException.ThrowIfNull(httpContext, nameof(httpContext)); + if (Result is null) + { + throw new InvalidOperationException("The IResult assigned to the Result property must not be null."); + } + await Result.ExecuteAsync(httpContext); } @@ -84,6 +89,11 @@ public async Task ExecuteAsync(HttpContext httpContext) { ArgumentNullException.ThrowIfNull(httpContext, nameof(httpContext)); + if (Result is null) + { + throw new InvalidOperationException("The IResult assigned to the Result property must not be null."); + } + await Result.ExecuteAsync(httpContext); } @@ -141,6 +151,11 @@ public async Task ExecuteAsync(HttpContext httpContext) { ArgumentNullException.ThrowIfNull(httpContext, nameof(httpContext)); + if (Result is null) + { + throw new InvalidOperationException("The IResult assigned to the Result property must not be null."); + } + await Result.ExecuteAsync(httpContext); } @@ -206,6 +221,11 @@ public async Task ExecuteAsync(HttpContext httpContext) { ArgumentNullException.ThrowIfNull(httpContext, nameof(httpContext)); + if (Result is null) + { + throw new InvalidOperationException("The IResult assigned to the Result property must not be null."); + } + await Result.ExecuteAsync(httpContext); } @@ -279,6 +299,11 @@ public async Task ExecuteAsync(HttpContext httpContext) { ArgumentNullException.ThrowIfNull(httpContext, nameof(httpContext)); + if (Result is null) + { + throw new InvalidOperationException("The IResult assigned to the Result property must not be null."); + } + await Result.ExecuteAsync(httpContext); } @@ -360,6 +385,11 @@ public async Task ExecuteAsync(HttpContext httpContext) { ArgumentNullException.ThrowIfNull(httpContext, nameof(httpContext)); + if (Result is null) + { + throw new InvalidOperationException("The IResult assigned to the Result property must not be null."); + } + await Result.ExecuteAsync(httpContext); } @@ -449,6 +479,11 @@ public async Task ExecuteAsync(HttpContext httpContext) { ArgumentNullException.ThrowIfNull(httpContext, nameof(httpContext)); + if (Result is null) + { + throw new InvalidOperationException("The IResult assigned to the Result property must not be null."); + } + await Result.ExecuteAsync(httpContext); } @@ -546,6 +581,11 @@ public async Task ExecuteAsync(HttpContext httpContext) { ArgumentNullException.ThrowIfNull(httpContext, nameof(httpContext)); + if (Result is null) + { + throw new InvalidOperationException("The IResult assigned to the Result property must not be null."); + } + await Result.ExecuteAsync(httpContext); } @@ -651,6 +691,11 @@ public async Task ExecuteAsync(HttpContext httpContext) { ArgumentNullException.ThrowIfNull(httpContext, nameof(httpContext)); + if (Result is null) + { + throw new InvalidOperationException("The IResult assigned to the Result property must not be null."); + } + await Result.ExecuteAsync(httpContext); } @@ -764,6 +809,11 @@ public async Task ExecuteAsync(HttpContext httpContext) { ArgumentNullException.ThrowIfNull(httpContext, nameof(httpContext)); + if (Result is null) + { + throw new InvalidOperationException("The IResult assigned to the Result property must not be null."); + } + await Result.ExecuteAsync(httpContext); } @@ -885,6 +935,11 @@ public async Task ExecuteAsync(HttpContext httpContext) { ArgumentNullException.ThrowIfNull(httpContext, nameof(httpContext)); + if (Result is null) + { + throw new InvalidOperationException("The IResult assigned to the Result property must not be null."); + } + await Result.ExecuteAsync(httpContext); } @@ -1014,6 +1069,11 @@ public async Task ExecuteAsync(HttpContext httpContext) { ArgumentNullException.ThrowIfNull(httpContext, nameof(httpContext)); + if (Result is null) + { + throw new InvalidOperationException("The IResult assigned to the Result property must not be null."); + } + await Result.ExecuteAsync(httpContext); } @@ -1151,6 +1211,11 @@ public async Task ExecuteAsync(HttpContext httpContext) { ArgumentNullException.ThrowIfNull(httpContext, nameof(httpContext)); + if (Result is null) + { + throw new InvalidOperationException("The IResult assigned to the Result property must not be null."); + } + await Result.ExecuteAsync(httpContext); } @@ -1296,6 +1361,11 @@ public async Task ExecuteAsync(HttpContext httpContext) { ArgumentNullException.ThrowIfNull(httpContext, nameof(httpContext)); + if (Result is null) + { + throw new InvalidOperationException("The IResult assigned to the Result property must not be null."); + } + await Result.ExecuteAsync(httpContext); } @@ -1449,6 +1519,11 @@ public async Task ExecuteAsync(HttpContext httpContext) { ArgumentNullException.ThrowIfNull(httpContext, nameof(httpContext)); + if (Result is null) + { + throw new InvalidOperationException("The IResult assigned to the Result property must not be null."); + } + await Result.ExecuteAsync(httpContext); } diff --git a/src/Http/Http.Results/test/ResultsOfTTests.cs b/src/Http/Http.Results/test/ResultsOfTTests.cs new file mode 100644 index 000000000000..588785e0e892 --- /dev/null +++ b/src/Http/Http.Results/test/ResultsOfTTests.cs @@ -0,0 +1,111 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +namespace Microsoft.AspNetCore.Http.Result; + +using System.Threading.Tasks; +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Logging; +using Microsoft.Extensions.Logging.Abstractions; + +public class ResultsOfTTests +{ + [Theory] + [InlineData(0, typeof(OkObjectHttpResult))] + [InlineData(1, typeof(NoContentHttpResult))] + public void ResultsOfT_Result_IsAssignedResult(int input, Type expectedResult) + { + // Arrange + Results MyApi(int id) + { + return id switch + { + 0 => (OkObjectHttpResult)Results.Ok(), + _ => (NoContentHttpResult)Results.NoContent() + }; + } + + // Act + var result = MyApi(input); + + // Assert + Assert.IsType(expectedResult, result.Result); + } + + [Theory] + [InlineData(100, 100)] + [InlineData(200, null)] + public async Task ResultsOfT_ExecuteResult_ExecutesAssignedResult(int input, object expected) + { + // Arrange + Results MyApi(int checksum) + { + return checksum switch + { + 100 => new CustomResult(checksum), + _ => (NoContentHttpResult)Results.NoContent() + }; + } + var httpContext = GetHttpContext(); + + // Act + var result = MyApi(input); + await result.ExecuteAsync(httpContext); + + // Assert + Assert.Equal(expected, httpContext.Items[result.Result]); + } + + [Fact] + public void ResultsOfT_Throws_InvalidOperationException_WhenResultIsNull() + { + // Arrange + Results MyApi() + { + return (CustomResult)null; + } + var httpContext = GetHttpContext(); + + // Act & Assert + var result = MyApi(); + + Assert.ThrowsAsync(async () => + { + await result.ExecuteAsync(httpContext); + }); + } + + class CustomResult : IResult + { + public CustomResult(int checksum) + { + Checksum = checksum; + } + + public int Checksum { get; } + + public Task ExecuteAsync(HttpContext httpContext) + { + httpContext.Items[this] = Checksum; + return Task.CompletedTask; + } + } + + private static IServiceCollection CreateServices() + { + var services = new ServiceCollection(); + services.AddSingleton(NullLoggerFactory.Instance); + services.AddSingleton(typeof(ILogger<>), typeof(NullLogger<>)); + return services; + } + + private static HttpContext GetHttpContext() + { + var services = CreateServices(); + + var httpContext = new DefaultHttpContext(); + httpContext.RequestServices = services.BuildServiceProvider(); + + return httpContext; + } +} diff --git a/src/Http/Http.Results/tools/ResultsOfTGenerator/Program.cs b/src/Http/Http.Results/tools/ResultsOfTGenerator/Program.cs index fcc19dc03bab..6103a0a11e28 100644 --- a/src/Http/Http.Results/tools/ResultsOfTGenerator/Program.cs +++ b/src/Http/Http.Results/tools/ResultsOfTGenerator/Program.cs @@ -95,6 +95,11 @@ writer.WriteLine(" {"); writer.WriteLine(" ArgumentNullException.ThrowIfNull(httpContext, nameof(httpContext));"); writer.WriteLine(); + writer.WriteLine(" if (Result is null)"); + writer.WriteLine(" {"); + writer.WriteLine(" throw new InvalidOperationException(\"The IResult assigned to the Result property must not be null.\");"); + writer.WriteLine(" }"); + writer.WriteLine(); writer.WriteLine(" await Result.ExecuteAsync(httpContext);"); writer.WriteLine(" }"); writer.WriteLine(); diff --git a/src/Http/samples/MinimalSample/Program.cs b/src/Http/samples/MinimalSample/Program.cs index a68f558d2b43..6961e5bac6a4 100644 --- a/src/Http/samples/MinimalSample/Program.cs +++ b/src/Http/samples/MinimalSample/Program.cs @@ -19,6 +19,8 @@ string SayHello(string name) => $"Hello, {name}!"; app.MapGet("/hello/{name}", SayHello); +app.MapGet("/null-result", () => (IResult)null); + app.MapGet("/todo/{id}", Results (int id) => { return id switch From 5d7d545320c7747002dd307ebf6a1039d7903d9e Mon Sep 17 00:00:00 2001 From: Damian Edwards Date: Thu, 31 Mar 2022 17:10:10 -0700 Subject: [PATCH 10/19] Code gen Results tests --- .../test/ResultsOfTTests.Generated.cs | 1219 +++++++++++++++++ src/Http/Http.Results/test/ResultsOfTTests.cs | 83 +- .../tools/ResultsOfTGenerator/Program.cs | 676 ++++++--- 3 files changed, 1688 insertions(+), 290 deletions(-) create mode 100644 src/Http/Http.Results/test/ResultsOfTTests.Generated.cs diff --git a/src/Http/Http.Results/test/ResultsOfTTests.Generated.cs b/src/Http/Http.Results/test/ResultsOfTTests.Generated.cs new file mode 100644 index 000000000000..8205f47d03a2 --- /dev/null +++ b/src/Http/Http.Results/test/ResultsOfTTests.Generated.cs @@ -0,0 +1,1219 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +// This file is generated by a tool. See: src/Http/Http.Results/tools/ResultsOfTGenerator +namespace Microsoft.AspNetCore.Http.Result; + +using System.Threading.Tasks; +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Logging; +using Microsoft.Extensions.Logging.Abstractions; + +public partial class ResultsOfTTests +{ + [Theory] + [InlineData(1, typeof(ChecksumResult1))] + [InlineData(2, typeof(ChecksumResult2))] + public void ResultsOfTResult1TResult2_Result_IsAssignedResult(int input, Type expectedResult) + { + // Arrange + Results MyApi(int id) + { + return id switch + { + 1 => new ChecksumResult1(), + _ => new ChecksumResult2() + }; + } + + // Act + var result = MyApi(input); + + // Assert + Assert.IsType(expectedResult, result.Result); + } + + [Theory] + [InlineData(1)] + [InlineData(2)] + public async Task ResultsOfTResult1TResult2_ExecuteResult_ExecutesAssignedResult(int input) + { + // Arrange + Results MyApi(int checksum) + { + return checksum switch + { + 1 => new ChecksumResult1(checksum), + _ => new ChecksumResult2(checksum) + }; + } + var httpContext = GetHttpContext(); + + // Act + var result = MyApi(input); + await result.ExecuteAsync(httpContext); + + // Assert + Assert.Equal(input, httpContext.Items[result.Result]); + } + + [Theory] + [InlineData(1, typeof(ChecksumResult1))] + [InlineData(2, typeof(ChecksumResult2))] + [InlineData(3, typeof(ChecksumResult3))] + public void ResultsOfTResult1TResult2TResult3_Result_IsAssignedResult(int input, Type expectedResult) + { + // Arrange + Results MyApi(int id) + { + return id switch + { + 1 => new ChecksumResult1(), + 2 => new ChecksumResult2(), + _ => new ChecksumResult3() + }; + } + + // Act + var result = MyApi(input); + + // Assert + Assert.IsType(expectedResult, result.Result); + } + + [Theory] + [InlineData(1)] + [InlineData(2)] + [InlineData(3)] + public async Task ResultsOfTResult1TResult2TResult3_ExecuteResult_ExecutesAssignedResult(int input) + { + // Arrange + Results MyApi(int checksum) + { + return checksum switch + { + 1 => new ChecksumResult1(checksum), + 2 => new ChecksumResult2(checksum), + _ => new ChecksumResult3(checksum) + }; + } + var httpContext = GetHttpContext(); + + // Act + var result = MyApi(input); + await result.ExecuteAsync(httpContext); + + // Assert + Assert.Equal(input, httpContext.Items[result.Result]); + } + + [Theory] + [InlineData(1, typeof(ChecksumResult1))] + [InlineData(2, typeof(ChecksumResult2))] + [InlineData(3, typeof(ChecksumResult3))] + [InlineData(4, typeof(ChecksumResult4))] + public void ResultsOfTResult1TResult2TResult3TResult4_Result_IsAssignedResult(int input, Type expectedResult) + { + // Arrange + Results MyApi(int id) + { + return id switch + { + 1 => new ChecksumResult1(), + 2 => new ChecksumResult2(), + 3 => new ChecksumResult3(), + _ => new ChecksumResult4() + }; + } + + // Act + var result = MyApi(input); + + // Assert + Assert.IsType(expectedResult, result.Result); + } + + [Theory] + [InlineData(1)] + [InlineData(2)] + [InlineData(3)] + [InlineData(4)] + public async Task ResultsOfTResult1TResult2TResult3TResult4_ExecuteResult_ExecutesAssignedResult(int input) + { + // Arrange + Results MyApi(int checksum) + { + return checksum switch + { + 1 => new ChecksumResult1(checksum), + 2 => new ChecksumResult2(checksum), + 3 => new ChecksumResult3(checksum), + _ => new ChecksumResult4(checksum) + }; + } + var httpContext = GetHttpContext(); + + // Act + var result = MyApi(input); + await result.ExecuteAsync(httpContext); + + // Assert + Assert.Equal(input, httpContext.Items[result.Result]); + } + + [Theory] + [InlineData(1, typeof(ChecksumResult1))] + [InlineData(2, typeof(ChecksumResult2))] + [InlineData(3, typeof(ChecksumResult3))] + [InlineData(4, typeof(ChecksumResult4))] + [InlineData(5, typeof(ChecksumResult5))] + public void ResultsOfTResult1TResult2TResult3TResult4TResult5_Result_IsAssignedResult(int input, Type expectedResult) + { + // Arrange + Results MyApi(int id) + { + return id switch + { + 1 => new ChecksumResult1(), + 2 => new ChecksumResult2(), + 3 => new ChecksumResult3(), + 4 => new ChecksumResult4(), + _ => new ChecksumResult5() + }; + } + + // Act + var result = MyApi(input); + + // Assert + Assert.IsType(expectedResult, result.Result); + } + + [Theory] + [InlineData(1)] + [InlineData(2)] + [InlineData(3)] + [InlineData(4)] + [InlineData(5)] + public async Task ResultsOfTResult1TResult2TResult3TResult4TResult5_ExecuteResult_ExecutesAssignedResult(int input) + { + // Arrange + Results MyApi(int checksum) + { + return checksum switch + { + 1 => new ChecksumResult1(checksum), + 2 => new ChecksumResult2(checksum), + 3 => new ChecksumResult3(checksum), + 4 => new ChecksumResult4(checksum), + _ => new ChecksumResult5(checksum) + }; + } + var httpContext = GetHttpContext(); + + // Act + var result = MyApi(input); + await result.ExecuteAsync(httpContext); + + // Assert + Assert.Equal(input, httpContext.Items[result.Result]); + } + + [Theory] + [InlineData(1, typeof(ChecksumResult1))] + [InlineData(2, typeof(ChecksumResult2))] + [InlineData(3, typeof(ChecksumResult3))] + [InlineData(4, typeof(ChecksumResult4))] + [InlineData(5, typeof(ChecksumResult5))] + [InlineData(6, typeof(ChecksumResult6))] + public void ResultsOfTResult1TResult2TResult3TResult4TResult5TResult6_Result_IsAssignedResult(int input, Type expectedResult) + { + // Arrange + Results MyApi(int id) + { + return id switch + { + 1 => new ChecksumResult1(), + 2 => new ChecksumResult2(), + 3 => new ChecksumResult3(), + 4 => new ChecksumResult4(), + 5 => new ChecksumResult5(), + _ => new ChecksumResult6() + }; + } + + // Act + var result = MyApi(input); + + // Assert + Assert.IsType(expectedResult, result.Result); + } + + [Theory] + [InlineData(1)] + [InlineData(2)] + [InlineData(3)] + [InlineData(4)] + [InlineData(5)] + [InlineData(6)] + public async Task ResultsOfTResult1TResult2TResult3TResult4TResult5TResult6_ExecuteResult_ExecutesAssignedResult(int input) + { + // Arrange + Results MyApi(int checksum) + { + return checksum switch + { + 1 => new ChecksumResult1(checksum), + 2 => new ChecksumResult2(checksum), + 3 => new ChecksumResult3(checksum), + 4 => new ChecksumResult4(checksum), + 5 => new ChecksumResult5(checksum), + _ => new ChecksumResult6(checksum) + }; + } + var httpContext = GetHttpContext(); + + // Act + var result = MyApi(input); + await result.ExecuteAsync(httpContext); + + // Assert + Assert.Equal(input, httpContext.Items[result.Result]); + } + + [Theory] + [InlineData(1, typeof(ChecksumResult1))] + [InlineData(2, typeof(ChecksumResult2))] + [InlineData(3, typeof(ChecksumResult3))] + [InlineData(4, typeof(ChecksumResult4))] + [InlineData(5, typeof(ChecksumResult5))] + [InlineData(6, typeof(ChecksumResult6))] + [InlineData(7, typeof(ChecksumResult7))] + public void ResultsOfTResult1TResult2TResult3TResult4TResult5TResult6TResult7_Result_IsAssignedResult(int input, Type expectedResult) + { + // Arrange + Results MyApi(int id) + { + return id switch + { + 1 => new ChecksumResult1(), + 2 => new ChecksumResult2(), + 3 => new ChecksumResult3(), + 4 => new ChecksumResult4(), + 5 => new ChecksumResult5(), + 6 => new ChecksumResult6(), + _ => new ChecksumResult7() + }; + } + + // Act + var result = MyApi(input); + + // Assert + Assert.IsType(expectedResult, result.Result); + } + + [Theory] + [InlineData(1)] + [InlineData(2)] + [InlineData(3)] + [InlineData(4)] + [InlineData(5)] + [InlineData(6)] + [InlineData(7)] + public async Task ResultsOfTResult1TResult2TResult3TResult4TResult5TResult6TResult7_ExecuteResult_ExecutesAssignedResult(int input) + { + // Arrange + Results MyApi(int checksum) + { + return checksum switch + { + 1 => new ChecksumResult1(checksum), + 2 => new ChecksumResult2(checksum), + 3 => new ChecksumResult3(checksum), + 4 => new ChecksumResult4(checksum), + 5 => new ChecksumResult5(checksum), + 6 => new ChecksumResult6(checksum), + _ => new ChecksumResult7(checksum) + }; + } + var httpContext = GetHttpContext(); + + // Act + var result = MyApi(input); + await result.ExecuteAsync(httpContext); + + // Assert + Assert.Equal(input, httpContext.Items[result.Result]); + } + + [Theory] + [InlineData(1, typeof(ChecksumResult1))] + [InlineData(2, typeof(ChecksumResult2))] + [InlineData(3, typeof(ChecksumResult3))] + [InlineData(4, typeof(ChecksumResult4))] + [InlineData(5, typeof(ChecksumResult5))] + [InlineData(6, typeof(ChecksumResult6))] + [InlineData(7, typeof(ChecksumResult7))] + [InlineData(8, typeof(ChecksumResult8))] + public void ResultsOfTResult1TResult2TResult3TResult4TResult5TResult6TResult7TResult8_Result_IsAssignedResult(int input, Type expectedResult) + { + // Arrange + Results MyApi(int id) + { + return id switch + { + 1 => new ChecksumResult1(), + 2 => new ChecksumResult2(), + 3 => new ChecksumResult3(), + 4 => new ChecksumResult4(), + 5 => new ChecksumResult5(), + 6 => new ChecksumResult6(), + 7 => new ChecksumResult7(), + _ => new ChecksumResult8() + }; + } + + // Act + var result = MyApi(input); + + // Assert + Assert.IsType(expectedResult, result.Result); + } + + [Theory] + [InlineData(1)] + [InlineData(2)] + [InlineData(3)] + [InlineData(4)] + [InlineData(5)] + [InlineData(6)] + [InlineData(7)] + [InlineData(8)] + public async Task ResultsOfTResult1TResult2TResult3TResult4TResult5TResult6TResult7TResult8_ExecuteResult_ExecutesAssignedResult(int input) + { + // Arrange + Results MyApi(int checksum) + { + return checksum switch + { + 1 => new ChecksumResult1(checksum), + 2 => new ChecksumResult2(checksum), + 3 => new ChecksumResult3(checksum), + 4 => new ChecksumResult4(checksum), + 5 => new ChecksumResult5(checksum), + 6 => new ChecksumResult6(checksum), + 7 => new ChecksumResult7(checksum), + _ => new ChecksumResult8(checksum) + }; + } + var httpContext = GetHttpContext(); + + // Act + var result = MyApi(input); + await result.ExecuteAsync(httpContext); + + // Assert + Assert.Equal(input, httpContext.Items[result.Result]); + } + + [Theory] + [InlineData(1, typeof(ChecksumResult1))] + [InlineData(2, typeof(ChecksumResult2))] + [InlineData(3, typeof(ChecksumResult3))] + [InlineData(4, typeof(ChecksumResult4))] + [InlineData(5, typeof(ChecksumResult5))] + [InlineData(6, typeof(ChecksumResult6))] + [InlineData(7, typeof(ChecksumResult7))] + [InlineData(8, typeof(ChecksumResult8))] + [InlineData(9, typeof(ChecksumResult9))] + public void ResultsOfTResult1TResult2TResult3TResult4TResult5TResult6TResult7TResult8TResult9_Result_IsAssignedResult(int input, Type expectedResult) + { + // Arrange + Results MyApi(int id) + { + return id switch + { + 1 => new ChecksumResult1(), + 2 => new ChecksumResult2(), + 3 => new ChecksumResult3(), + 4 => new ChecksumResult4(), + 5 => new ChecksumResult5(), + 6 => new ChecksumResult6(), + 7 => new ChecksumResult7(), + 8 => new ChecksumResult8(), + _ => new ChecksumResult9() + }; + } + + // Act + var result = MyApi(input); + + // Assert + Assert.IsType(expectedResult, result.Result); + } + + [Theory] + [InlineData(1)] + [InlineData(2)] + [InlineData(3)] + [InlineData(4)] + [InlineData(5)] + [InlineData(6)] + [InlineData(7)] + [InlineData(8)] + [InlineData(9)] + public async Task ResultsOfTResult1TResult2TResult3TResult4TResult5TResult6TResult7TResult8TResult9_ExecuteResult_ExecutesAssignedResult(int input) + { + // Arrange + Results MyApi(int checksum) + { + return checksum switch + { + 1 => new ChecksumResult1(checksum), + 2 => new ChecksumResult2(checksum), + 3 => new ChecksumResult3(checksum), + 4 => new ChecksumResult4(checksum), + 5 => new ChecksumResult5(checksum), + 6 => new ChecksumResult6(checksum), + 7 => new ChecksumResult7(checksum), + 8 => new ChecksumResult8(checksum), + _ => new ChecksumResult9(checksum) + }; + } + var httpContext = GetHttpContext(); + + // Act + var result = MyApi(input); + await result.ExecuteAsync(httpContext); + + // Assert + Assert.Equal(input, httpContext.Items[result.Result]); + } + + [Theory] + [InlineData(1, typeof(ChecksumResult1))] + [InlineData(2, typeof(ChecksumResult2))] + [InlineData(3, typeof(ChecksumResult3))] + [InlineData(4, typeof(ChecksumResult4))] + [InlineData(5, typeof(ChecksumResult5))] + [InlineData(6, typeof(ChecksumResult6))] + [InlineData(7, typeof(ChecksumResult7))] + [InlineData(8, typeof(ChecksumResult8))] + [InlineData(9, typeof(ChecksumResult9))] + [InlineData(10, typeof(ChecksumResult10))] + public void ResultsOfTResult1TResult2TResult3TResult4TResult5TResult6TResult7TResult8TResult9TResult10_Result_IsAssignedResult(int input, Type expectedResult) + { + // Arrange + Results MyApi(int id) + { + return id switch + { + 1 => new ChecksumResult1(), + 2 => new ChecksumResult2(), + 3 => new ChecksumResult3(), + 4 => new ChecksumResult4(), + 5 => new ChecksumResult5(), + 6 => new ChecksumResult6(), + 7 => new ChecksumResult7(), + 8 => new ChecksumResult8(), + 9 => new ChecksumResult9(), + _ => new ChecksumResult10() + }; + } + + // Act + var result = MyApi(input); + + // Assert + Assert.IsType(expectedResult, result.Result); + } + + [Theory] + [InlineData(1)] + [InlineData(2)] + [InlineData(3)] + [InlineData(4)] + [InlineData(5)] + [InlineData(6)] + [InlineData(7)] + [InlineData(8)] + [InlineData(9)] + [InlineData(10)] + public async Task ResultsOfTResult1TResult2TResult3TResult4TResult5TResult6TResult7TResult8TResult9TResult10_ExecuteResult_ExecutesAssignedResult(int input) + { + // Arrange + Results MyApi(int checksum) + { + return checksum switch + { + 1 => new ChecksumResult1(checksum), + 2 => new ChecksumResult2(checksum), + 3 => new ChecksumResult3(checksum), + 4 => new ChecksumResult4(checksum), + 5 => new ChecksumResult5(checksum), + 6 => new ChecksumResult6(checksum), + 7 => new ChecksumResult7(checksum), + 8 => new ChecksumResult8(checksum), + 9 => new ChecksumResult9(checksum), + _ => new ChecksumResult10(checksum) + }; + } + var httpContext = GetHttpContext(); + + // Act + var result = MyApi(input); + await result.ExecuteAsync(httpContext); + + // Assert + Assert.Equal(input, httpContext.Items[result.Result]); + } + + [Theory] + [InlineData(1, typeof(ChecksumResult1))] + [InlineData(2, typeof(ChecksumResult2))] + [InlineData(3, typeof(ChecksumResult3))] + [InlineData(4, typeof(ChecksumResult4))] + [InlineData(5, typeof(ChecksumResult5))] + [InlineData(6, typeof(ChecksumResult6))] + [InlineData(7, typeof(ChecksumResult7))] + [InlineData(8, typeof(ChecksumResult8))] + [InlineData(9, typeof(ChecksumResult9))] + [InlineData(10, typeof(ChecksumResult10))] + [InlineData(11, typeof(ChecksumResult11))] + public void ResultsOfTResult1TResult2TResult3TResult4TResult5TResult6TResult7TResult8TResult9TResult10TResult11_Result_IsAssignedResult(int input, Type expectedResult) + { + // Arrange + Results MyApi(int id) + { + return id switch + { + 1 => new ChecksumResult1(), + 2 => new ChecksumResult2(), + 3 => new ChecksumResult3(), + 4 => new ChecksumResult4(), + 5 => new ChecksumResult5(), + 6 => new ChecksumResult6(), + 7 => new ChecksumResult7(), + 8 => new ChecksumResult8(), + 9 => new ChecksumResult9(), + 10 => new ChecksumResult10(), + _ => new ChecksumResult11() + }; + } + + // Act + var result = MyApi(input); + + // Assert + Assert.IsType(expectedResult, result.Result); + } + + [Theory] + [InlineData(1)] + [InlineData(2)] + [InlineData(3)] + [InlineData(4)] + [InlineData(5)] + [InlineData(6)] + [InlineData(7)] + [InlineData(8)] + [InlineData(9)] + [InlineData(10)] + [InlineData(11)] + public async Task ResultsOfTResult1TResult2TResult3TResult4TResult5TResult6TResult7TResult8TResult9TResult10TResult11_ExecuteResult_ExecutesAssignedResult(int input) + { + // Arrange + Results MyApi(int checksum) + { + return checksum switch + { + 1 => new ChecksumResult1(checksum), + 2 => new ChecksumResult2(checksum), + 3 => new ChecksumResult3(checksum), + 4 => new ChecksumResult4(checksum), + 5 => new ChecksumResult5(checksum), + 6 => new ChecksumResult6(checksum), + 7 => new ChecksumResult7(checksum), + 8 => new ChecksumResult8(checksum), + 9 => new ChecksumResult9(checksum), + 10 => new ChecksumResult10(checksum), + _ => new ChecksumResult11(checksum) + }; + } + var httpContext = GetHttpContext(); + + // Act + var result = MyApi(input); + await result.ExecuteAsync(httpContext); + + // Assert + Assert.Equal(input, httpContext.Items[result.Result]); + } + + [Theory] + [InlineData(1, typeof(ChecksumResult1))] + [InlineData(2, typeof(ChecksumResult2))] + [InlineData(3, typeof(ChecksumResult3))] + [InlineData(4, typeof(ChecksumResult4))] + [InlineData(5, typeof(ChecksumResult5))] + [InlineData(6, typeof(ChecksumResult6))] + [InlineData(7, typeof(ChecksumResult7))] + [InlineData(8, typeof(ChecksumResult8))] + [InlineData(9, typeof(ChecksumResult9))] + [InlineData(10, typeof(ChecksumResult10))] + [InlineData(11, typeof(ChecksumResult11))] + [InlineData(12, typeof(ChecksumResult12))] + public void ResultsOfTResult1TResult2TResult3TResult4TResult5TResult6TResult7TResult8TResult9TResult10TResult11TResult12_Result_IsAssignedResult(int input, Type expectedResult) + { + // Arrange + Results MyApi(int id) + { + return id switch + { + 1 => new ChecksumResult1(), + 2 => new ChecksumResult2(), + 3 => new ChecksumResult3(), + 4 => new ChecksumResult4(), + 5 => new ChecksumResult5(), + 6 => new ChecksumResult6(), + 7 => new ChecksumResult7(), + 8 => new ChecksumResult8(), + 9 => new ChecksumResult9(), + 10 => new ChecksumResult10(), + 11 => new ChecksumResult11(), + _ => new ChecksumResult12() + }; + } + + // Act + var result = MyApi(input); + + // Assert + Assert.IsType(expectedResult, result.Result); + } + + [Theory] + [InlineData(1)] + [InlineData(2)] + [InlineData(3)] + [InlineData(4)] + [InlineData(5)] + [InlineData(6)] + [InlineData(7)] + [InlineData(8)] + [InlineData(9)] + [InlineData(10)] + [InlineData(11)] + [InlineData(12)] + public async Task ResultsOfTResult1TResult2TResult3TResult4TResult5TResult6TResult7TResult8TResult9TResult10TResult11TResult12_ExecuteResult_ExecutesAssignedResult(int input) + { + // Arrange + Results MyApi(int checksum) + { + return checksum switch + { + 1 => new ChecksumResult1(checksum), + 2 => new ChecksumResult2(checksum), + 3 => new ChecksumResult3(checksum), + 4 => new ChecksumResult4(checksum), + 5 => new ChecksumResult5(checksum), + 6 => new ChecksumResult6(checksum), + 7 => new ChecksumResult7(checksum), + 8 => new ChecksumResult8(checksum), + 9 => new ChecksumResult9(checksum), + 10 => new ChecksumResult10(checksum), + 11 => new ChecksumResult11(checksum), + _ => new ChecksumResult12(checksum) + }; + } + var httpContext = GetHttpContext(); + + // Act + var result = MyApi(input); + await result.ExecuteAsync(httpContext); + + // Assert + Assert.Equal(input, httpContext.Items[result.Result]); + } + + [Theory] + [InlineData(1, typeof(ChecksumResult1))] + [InlineData(2, typeof(ChecksumResult2))] + [InlineData(3, typeof(ChecksumResult3))] + [InlineData(4, typeof(ChecksumResult4))] + [InlineData(5, typeof(ChecksumResult5))] + [InlineData(6, typeof(ChecksumResult6))] + [InlineData(7, typeof(ChecksumResult7))] + [InlineData(8, typeof(ChecksumResult8))] + [InlineData(9, typeof(ChecksumResult9))] + [InlineData(10, typeof(ChecksumResult10))] + [InlineData(11, typeof(ChecksumResult11))] + [InlineData(12, typeof(ChecksumResult12))] + [InlineData(13, typeof(ChecksumResult13))] + public void ResultsOfTResult1TResult2TResult3TResult4TResult5TResult6TResult7TResult8TResult9TResult10TResult11TResult12TResult13_Result_IsAssignedResult(int input, Type expectedResult) + { + // Arrange + Results MyApi(int id) + { + return id switch + { + 1 => new ChecksumResult1(), + 2 => new ChecksumResult2(), + 3 => new ChecksumResult3(), + 4 => new ChecksumResult4(), + 5 => new ChecksumResult5(), + 6 => new ChecksumResult6(), + 7 => new ChecksumResult7(), + 8 => new ChecksumResult8(), + 9 => new ChecksumResult9(), + 10 => new ChecksumResult10(), + 11 => new ChecksumResult11(), + 12 => new ChecksumResult12(), + _ => new ChecksumResult13() + }; + } + + // Act + var result = MyApi(input); + + // Assert + Assert.IsType(expectedResult, result.Result); + } + + [Theory] + [InlineData(1)] + [InlineData(2)] + [InlineData(3)] + [InlineData(4)] + [InlineData(5)] + [InlineData(6)] + [InlineData(7)] + [InlineData(8)] + [InlineData(9)] + [InlineData(10)] + [InlineData(11)] + [InlineData(12)] + [InlineData(13)] + public async Task ResultsOfTResult1TResult2TResult3TResult4TResult5TResult6TResult7TResult8TResult9TResult10TResult11TResult12TResult13_ExecuteResult_ExecutesAssignedResult(int input) + { + // Arrange + Results MyApi(int checksum) + { + return checksum switch + { + 1 => new ChecksumResult1(checksum), + 2 => new ChecksumResult2(checksum), + 3 => new ChecksumResult3(checksum), + 4 => new ChecksumResult4(checksum), + 5 => new ChecksumResult5(checksum), + 6 => new ChecksumResult6(checksum), + 7 => new ChecksumResult7(checksum), + 8 => new ChecksumResult8(checksum), + 9 => new ChecksumResult9(checksum), + 10 => new ChecksumResult10(checksum), + 11 => new ChecksumResult11(checksum), + 12 => new ChecksumResult12(checksum), + _ => new ChecksumResult13(checksum) + }; + } + var httpContext = GetHttpContext(); + + // Act + var result = MyApi(input); + await result.ExecuteAsync(httpContext); + + // Assert + Assert.Equal(input, httpContext.Items[result.Result]); + } + + [Theory] + [InlineData(1, typeof(ChecksumResult1))] + [InlineData(2, typeof(ChecksumResult2))] + [InlineData(3, typeof(ChecksumResult3))] + [InlineData(4, typeof(ChecksumResult4))] + [InlineData(5, typeof(ChecksumResult5))] + [InlineData(6, typeof(ChecksumResult6))] + [InlineData(7, typeof(ChecksumResult7))] + [InlineData(8, typeof(ChecksumResult8))] + [InlineData(9, typeof(ChecksumResult9))] + [InlineData(10, typeof(ChecksumResult10))] + [InlineData(11, typeof(ChecksumResult11))] + [InlineData(12, typeof(ChecksumResult12))] + [InlineData(13, typeof(ChecksumResult13))] + [InlineData(14, typeof(ChecksumResult14))] + public void ResultsOfTResult1TResult2TResult3TResult4TResult5TResult6TResult7TResult8TResult9TResult10TResult11TResult12TResult13TResult14_Result_IsAssignedResult(int input, Type expectedResult) + { + // Arrange + Results MyApi(int id) + { + return id switch + { + 1 => new ChecksumResult1(), + 2 => new ChecksumResult2(), + 3 => new ChecksumResult3(), + 4 => new ChecksumResult4(), + 5 => new ChecksumResult5(), + 6 => new ChecksumResult6(), + 7 => new ChecksumResult7(), + 8 => new ChecksumResult8(), + 9 => new ChecksumResult9(), + 10 => new ChecksumResult10(), + 11 => new ChecksumResult11(), + 12 => new ChecksumResult12(), + 13 => new ChecksumResult13(), + _ => new ChecksumResult14() + }; + } + + // Act + var result = MyApi(input); + + // Assert + Assert.IsType(expectedResult, result.Result); + } + + [Theory] + [InlineData(1)] + [InlineData(2)] + [InlineData(3)] + [InlineData(4)] + [InlineData(5)] + [InlineData(6)] + [InlineData(7)] + [InlineData(8)] + [InlineData(9)] + [InlineData(10)] + [InlineData(11)] + [InlineData(12)] + [InlineData(13)] + [InlineData(14)] + public async Task ResultsOfTResult1TResult2TResult3TResult4TResult5TResult6TResult7TResult8TResult9TResult10TResult11TResult12TResult13TResult14_ExecuteResult_ExecutesAssignedResult(int input) + { + // Arrange + Results MyApi(int checksum) + { + return checksum switch + { + 1 => new ChecksumResult1(checksum), + 2 => new ChecksumResult2(checksum), + 3 => new ChecksumResult3(checksum), + 4 => new ChecksumResult4(checksum), + 5 => new ChecksumResult5(checksum), + 6 => new ChecksumResult6(checksum), + 7 => new ChecksumResult7(checksum), + 8 => new ChecksumResult8(checksum), + 9 => new ChecksumResult9(checksum), + 10 => new ChecksumResult10(checksum), + 11 => new ChecksumResult11(checksum), + 12 => new ChecksumResult12(checksum), + 13 => new ChecksumResult13(checksum), + _ => new ChecksumResult14(checksum) + }; + } + var httpContext = GetHttpContext(); + + // Act + var result = MyApi(input); + await result.ExecuteAsync(httpContext); + + // Assert + Assert.Equal(input, httpContext.Items[result.Result]); + } + + [Theory] + [InlineData(1, typeof(ChecksumResult1))] + [InlineData(2, typeof(ChecksumResult2))] + [InlineData(3, typeof(ChecksumResult3))] + [InlineData(4, typeof(ChecksumResult4))] + [InlineData(5, typeof(ChecksumResult5))] + [InlineData(6, typeof(ChecksumResult6))] + [InlineData(7, typeof(ChecksumResult7))] + [InlineData(8, typeof(ChecksumResult8))] + [InlineData(9, typeof(ChecksumResult9))] + [InlineData(10, typeof(ChecksumResult10))] + [InlineData(11, typeof(ChecksumResult11))] + [InlineData(12, typeof(ChecksumResult12))] + [InlineData(13, typeof(ChecksumResult13))] + [InlineData(14, typeof(ChecksumResult14))] + [InlineData(15, typeof(ChecksumResult15))] + public void ResultsOfTResult1TResult2TResult3TResult4TResult5TResult6TResult7TResult8TResult9TResult10TResult11TResult12TResult13TResult14TResult15_Result_IsAssignedResult(int input, Type expectedResult) + { + // Arrange + Results MyApi(int id) + { + return id switch + { + 1 => new ChecksumResult1(), + 2 => new ChecksumResult2(), + 3 => new ChecksumResult3(), + 4 => new ChecksumResult4(), + 5 => new ChecksumResult5(), + 6 => new ChecksumResult6(), + 7 => new ChecksumResult7(), + 8 => new ChecksumResult8(), + 9 => new ChecksumResult9(), + 10 => new ChecksumResult10(), + 11 => new ChecksumResult11(), + 12 => new ChecksumResult12(), + 13 => new ChecksumResult13(), + 14 => new ChecksumResult14(), + _ => new ChecksumResult15() + }; + } + + // Act + var result = MyApi(input); + + // Assert + Assert.IsType(expectedResult, result.Result); + } + + [Theory] + [InlineData(1)] + [InlineData(2)] + [InlineData(3)] + [InlineData(4)] + [InlineData(5)] + [InlineData(6)] + [InlineData(7)] + [InlineData(8)] + [InlineData(9)] + [InlineData(10)] + [InlineData(11)] + [InlineData(12)] + [InlineData(13)] + [InlineData(14)] + [InlineData(15)] + public async Task ResultsOfTResult1TResult2TResult3TResult4TResult5TResult6TResult7TResult8TResult9TResult10TResult11TResult12TResult13TResult14TResult15_ExecuteResult_ExecutesAssignedResult(int input) + { + // Arrange + Results MyApi(int checksum) + { + return checksum switch + { + 1 => new ChecksumResult1(checksum), + 2 => new ChecksumResult2(checksum), + 3 => new ChecksumResult3(checksum), + 4 => new ChecksumResult4(checksum), + 5 => new ChecksumResult5(checksum), + 6 => new ChecksumResult6(checksum), + 7 => new ChecksumResult7(checksum), + 8 => new ChecksumResult8(checksum), + 9 => new ChecksumResult9(checksum), + 10 => new ChecksumResult10(checksum), + 11 => new ChecksumResult11(checksum), + 12 => new ChecksumResult12(checksum), + 13 => new ChecksumResult13(checksum), + 14 => new ChecksumResult14(checksum), + _ => new ChecksumResult15(checksum) + }; + } + var httpContext = GetHttpContext(); + + // Act + var result = MyApi(input); + await result.ExecuteAsync(httpContext); + + // Assert + Assert.Equal(input, httpContext.Items[result.Result]); + } + + [Theory] + [InlineData(1, typeof(ChecksumResult1))] + [InlineData(2, typeof(ChecksumResult2))] + [InlineData(3, typeof(ChecksumResult3))] + [InlineData(4, typeof(ChecksumResult4))] + [InlineData(5, typeof(ChecksumResult5))] + [InlineData(6, typeof(ChecksumResult6))] + [InlineData(7, typeof(ChecksumResult7))] + [InlineData(8, typeof(ChecksumResult8))] + [InlineData(9, typeof(ChecksumResult9))] + [InlineData(10, typeof(ChecksumResult10))] + [InlineData(11, typeof(ChecksumResult11))] + [InlineData(12, typeof(ChecksumResult12))] + [InlineData(13, typeof(ChecksumResult13))] + [InlineData(14, typeof(ChecksumResult14))] + [InlineData(15, typeof(ChecksumResult15))] + [InlineData(16, typeof(ChecksumResult16))] + public void ResultsOfTResult1TResult2TResult3TResult4TResult5TResult6TResult7TResult8TResult9TResult10TResult11TResult12TResult13TResult14TResult15TResult16_Result_IsAssignedResult(int input, Type expectedResult) + { + // Arrange + Results MyApi(int id) + { + return id switch + { + 1 => new ChecksumResult1(), + 2 => new ChecksumResult2(), + 3 => new ChecksumResult3(), + 4 => new ChecksumResult4(), + 5 => new ChecksumResult5(), + 6 => new ChecksumResult6(), + 7 => new ChecksumResult7(), + 8 => new ChecksumResult8(), + 9 => new ChecksumResult9(), + 10 => new ChecksumResult10(), + 11 => new ChecksumResult11(), + 12 => new ChecksumResult12(), + 13 => new ChecksumResult13(), + 14 => new ChecksumResult14(), + 15 => new ChecksumResult15(), + _ => new ChecksumResult16() + }; + } + + // Act + var result = MyApi(input); + + // Assert + Assert.IsType(expectedResult, result.Result); + } + + [Theory] + [InlineData(1)] + [InlineData(2)] + [InlineData(3)] + [InlineData(4)] + [InlineData(5)] + [InlineData(6)] + [InlineData(7)] + [InlineData(8)] + [InlineData(9)] + [InlineData(10)] + [InlineData(11)] + [InlineData(12)] + [InlineData(13)] + [InlineData(14)] + [InlineData(15)] + [InlineData(16)] + public async Task ResultsOfTResult1TResult2TResult3TResult4TResult5TResult6TResult7TResult8TResult9TResult10TResult11TResult12TResult13TResult14TResult15TResult16_ExecuteResult_ExecutesAssignedResult(int input) + { + // Arrange + Results MyApi(int checksum) + { + return checksum switch + { + 1 => new ChecksumResult1(checksum), + 2 => new ChecksumResult2(checksum), + 3 => new ChecksumResult3(checksum), + 4 => new ChecksumResult4(checksum), + 5 => new ChecksumResult5(checksum), + 6 => new ChecksumResult6(checksum), + 7 => new ChecksumResult7(checksum), + 8 => new ChecksumResult8(checksum), + 9 => new ChecksumResult9(checksum), + 10 => new ChecksumResult10(checksum), + 11 => new ChecksumResult11(checksum), + 12 => new ChecksumResult12(checksum), + 13 => new ChecksumResult13(checksum), + 14 => new ChecksumResult14(checksum), + 15 => new ChecksumResult15(checksum), + _ => new ChecksumResult16(checksum) + }; + } + var httpContext = GetHttpContext(); + + // Act + var result = MyApi(input); + await result.ExecuteAsync(httpContext); + + // Assert + Assert.Equal(input, httpContext.Items[result.Result]); + } + + class ChecksumResult : IResult + { + public ChecksumResult(int checksum = 0) + { + Checksum = checksum; + } + + public int Checksum { get; } + + public Task ExecuteAsync(HttpContext httpContext) + { + httpContext.Items[this] = Checksum; + return Task.CompletedTask; + } + } + + class ChecksumResult1 : ChecksumResult + { + public ChecksumResult1(int checksum = 0) : base(checksum) { } + } + + class ChecksumResult2 : ChecksumResult + { + public ChecksumResult2(int checksum = 0) : base(checksum) { } + } + + class ChecksumResult3 : ChecksumResult + { + public ChecksumResult3(int checksum = 0) : base(checksum) { } + } + + class ChecksumResult4 : ChecksumResult + { + public ChecksumResult4(int checksum = 0) : base(checksum) { } + } + + class ChecksumResult5 : ChecksumResult + { + public ChecksumResult5(int checksum = 0) : base(checksum) { } + } + + class ChecksumResult6 : ChecksumResult + { + public ChecksumResult6(int checksum = 0) : base(checksum) { } + } + + class ChecksumResult7 : ChecksumResult + { + public ChecksumResult7(int checksum = 0) : base(checksum) { } + } + + class ChecksumResult8 : ChecksumResult + { + public ChecksumResult8(int checksum = 0) : base(checksum) { } + } + + class ChecksumResult9 : ChecksumResult + { + public ChecksumResult9(int checksum = 0) : base(checksum) { } + } + + class ChecksumResult10 : ChecksumResult + { + public ChecksumResult10(int checksum = 0) : base(checksum) { } + } + + class ChecksumResult11 : ChecksumResult + { + public ChecksumResult11(int checksum = 0) : base(checksum) { } + } + + class ChecksumResult12 : ChecksumResult + { + public ChecksumResult12(int checksum = 0) : base(checksum) { } + } + + class ChecksumResult13 : ChecksumResult + { + public ChecksumResult13(int checksum = 0) : base(checksum) { } + } + + class ChecksumResult14 : ChecksumResult + { + public ChecksumResult14(int checksum = 0) : base(checksum) { } + } + + class ChecksumResult15 : ChecksumResult + { + public ChecksumResult15(int checksum = 0) : base(checksum) { } + } + + class ChecksumResult16 : ChecksumResult + { + public ChecksumResult16(int checksum = 0) : base(checksum) { } + } +} diff --git a/src/Http/Http.Results/test/ResultsOfTTests.cs b/src/Http/Http.Results/test/ResultsOfTTests.cs index 588785e0e892..f5e1fb65aa2d 100644 --- a/src/Http/Http.Results/test/ResultsOfTTests.cs +++ b/src/Http/Http.Results/test/ResultsOfTTests.cs @@ -8,89 +8,8 @@ namespace Microsoft.AspNetCore.Http.Result; using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging.Abstractions; -public class ResultsOfTTests +public partial class ResultsOfTTests { - [Theory] - [InlineData(0, typeof(OkObjectHttpResult))] - [InlineData(1, typeof(NoContentHttpResult))] - public void ResultsOfT_Result_IsAssignedResult(int input, Type expectedResult) - { - // Arrange - Results MyApi(int id) - { - return id switch - { - 0 => (OkObjectHttpResult)Results.Ok(), - _ => (NoContentHttpResult)Results.NoContent() - }; - } - - // Act - var result = MyApi(input); - - // Assert - Assert.IsType(expectedResult, result.Result); - } - - [Theory] - [InlineData(100, 100)] - [InlineData(200, null)] - public async Task ResultsOfT_ExecuteResult_ExecutesAssignedResult(int input, object expected) - { - // Arrange - Results MyApi(int checksum) - { - return checksum switch - { - 100 => new CustomResult(checksum), - _ => (NoContentHttpResult)Results.NoContent() - }; - } - var httpContext = GetHttpContext(); - - // Act - var result = MyApi(input); - await result.ExecuteAsync(httpContext); - - // Assert - Assert.Equal(expected, httpContext.Items[result.Result]); - } - - [Fact] - public void ResultsOfT_Throws_InvalidOperationException_WhenResultIsNull() - { - // Arrange - Results MyApi() - { - return (CustomResult)null; - } - var httpContext = GetHttpContext(); - - // Act & Assert - var result = MyApi(); - - Assert.ThrowsAsync(async () => - { - await result.ExecuteAsync(httpContext); - }); - } - - class CustomResult : IResult - { - public CustomResult(int checksum) - { - Checksum = checksum; - } - - public int Checksum { get; } - - public Task ExecuteAsync(HttpContext httpContext) - { - httpContext.Items[this] = Checksum; - return Task.CompletedTask; - } - } - private static IServiceCollection CreateServices() { var services = new ServiceCollection(); diff --git a/src/Http/Http.Results/tools/ResultsOfTGenerator/Program.cs b/src/Http/Http.Results/tools/ResultsOfTGenerator/Program.cs index 6103a0a11e28..5940cdf414da 100644 --- a/src/Http/Http.Results/tools/ResultsOfTGenerator/Program.cs +++ b/src/Http/Http.Results/tools/ResultsOfTGenerator/Program.cs @@ -6,151 +6,520 @@ var className = "Results"; var typeArgCount = 16; var typeArgName = "TResult"; -var filePath = Path.Join(Directory.GetCurrentDirectory(), $"{className}OfT.cs"); +var pwd = Directory.GetCurrentDirectory(); -Console.WriteLine($"Will generate file at {filePath}"); -Console.WriteLine("Press any key to continue or Ctrl-C to cancel"); -Console.ReadKey(); +GenerateClassFile(Path.Join(pwd, $"{className}OfT.cs")); -using var writer = new StreamWriter(filePath, append: false); - -// File header -writer.WriteLine("// Licensed to the .NET Foundation under one or more agreements."); -writer.WriteLine("// The .NET Foundation licenses this file to you under the MIT license."); -writer.WriteLine(); -writer.WriteLine("// This file is generated by a tool. See: src/Http/Http.Results/tools/ResultsOfTGenerator"); +Console.WriteLine(); -// Namespace -writer.WriteLine("namespace Microsoft.AspNetCore.Http;"); -writer.WriteLine(); +GenerateTestFiles(Path.Join(pwd, $"..{Path.DirectorySeparatorChar}test", $"{className}OfTTests.Generated.cs")); -for (int i = 1; i <= typeArgCount; i++) +void GenerateClassFile(string classFilePath) { - if (i == 1) continue; - - // Class summary doc - writer.WriteLine("/// "); - writer.WriteLine($"/// An that could be one of {i.ToWords()} different types. On execution will"); - writer.WriteLine("/// execute the underlying instance that was actually returned by the HTTP endpoint."); - writer.WriteLine("/// "); - - // Class remarks doc - writer.WriteLine("/// "); - writer.WriteLine("/// An instance of this type cannot be created explicitly. Use the implicit cast operators to create an instance"); - writer.WriteLine("/// from an instance of one of the declared type arguments, e.g."); - writer.WriteLine("/// Results<OkObjectHttpResult, ProblemHttpResult> result = Results.Ok();"); - writer.WriteLine("/// "); - - // Type params docs - for (int j = 1; j <= i; j++) + Console.WriteLine($"Will generate class file at {classFilePath}"); + Console.WriteLine("Press any key to continue or Ctrl-C to cancel"); + Console.ReadKey(); + + using var writer = new StreamWriter(classFilePath, append: false); + + // File header + writer.WriteLine("// Licensed to the .NET Foundation under one or more agreements."); + writer.WriteLine("// The .NET Foundation licenses this file to you under the MIT license."); + writer.WriteLine(); + writer.WriteLine("// This file is generated by a tool. See: src/Http/Http.Results/tools/ResultsOfTGenerator"); + + // Namespace + writer.WriteLine("namespace Microsoft.AspNetCore.Http;"); + writer.WriteLine(); + + for (int i = 1; i <= typeArgCount; i++) { - writer.WriteLine(@$"/// The {j.ToOrdinalWords()} result type."); + // Skip first as we don't have a Results class + if (i == 1) continue; + + // Class summary doc + writer.WriteLine("/// "); + writer.WriteLine($"/// An that could be one of {i.ToWords()} different types. On execution will"); + writer.WriteLine("/// execute the underlying instance that was actually returned by the HTTP endpoint."); + writer.WriteLine("/// "); + + // Class remarks doc + writer.WriteLine("/// "); + writer.WriteLine("/// An instance of this type cannot be created explicitly. Use the implicit cast operators to create an instance"); + writer.WriteLine("/// from an instance of one of the declared type arguments, e.g."); + writer.WriteLine("/// Results<OkObjectHttpResult, ProblemHttpResult> result = Results.Ok();"); + writer.WriteLine("/// "); + + // Type params docs + for (int j = 1; j <= i; j++) + { + writer.WriteLine(@$"/// The {j.ToOrdinalWords()} result type."); + } + + // Class declaration + writer.Write($"public sealed class {className}<"); + + // Type args + for (int j = 1; j <= i; j++) + { + writer.Write($"{typeArgName}{j}"); + if (j != i) + { + writer.Write(", "); + } + } + + writer.WriteLine("> : IResult"); + + // Type arg contraints + for (int j = 1; j <= i; j++) + { + writer.Write($" where {typeArgName}{j} : IResult"); + if (j != i) + { + writer.Write(Environment.NewLine); + } + } + writer.WriteLine(); + writer.WriteLine("{"); + + // Ctor + writer.WriteLine(" // Use implicit cast operators to create an instance"); + writer.WriteLine($" private {className}(IResult activeResult)"); + writer.WriteLine(" {"); + writer.WriteLine(" Result = activeResult;"); + writer.WriteLine(" }"); + writer.WriteLine(); + + // Result property + writer.WriteLine(" /// "); + writer.WriteLine($" /// Gets the actual returned by the route handler delegate."); + writer.WriteLine(" /// "); + writer.WriteLine(" public IResult Result { get; }"); + writer.WriteLine(); + + // ExecuteAsync method + writer.WriteLine(" /// "); + writer.WriteLine(" public async Task ExecuteAsync(HttpContext httpContext)"); + writer.WriteLine(" {"); + writer.WriteLine(" ArgumentNullException.ThrowIfNull(httpContext, nameof(httpContext));"); + writer.WriteLine(); + writer.WriteLine(" if (Result is null)"); + writer.WriteLine(" {"); + writer.WriteLine(" throw new InvalidOperationException(\"The IResult assigned to the Result property must not be null.\");"); + writer.WriteLine(" }"); + writer.WriteLine(); + writer.WriteLine(" await Result.ExecuteAsync(httpContext);"); + writer.WriteLine(" }"); + writer.WriteLine(); + + // Implicit converter operators + var sb = new StringBuilder(); + for (int j = 1; j <= i; j++) + { + sb.Append($"{typeArgName}{j}"); + if (j != i) + { + sb.Append(", "); + } + } + var typeArgsList = sb.ToString(); + + for (int j = 1; j <= i; j++) + { + writer.WriteLine(" /// "); + writer.WriteLine($" /// Converts the to a ."); + writer.WriteLine(" /// "); + writer.WriteLine(" /// The result."); + writer.WriteLine($" public static implicit operator {className}<{typeArgsList}>({typeArgName}{j} result) => new(result);"); + + if (i != j) + { + writer.WriteLine(); + } + } + + // Class end + writer.WriteLine("}"); + + if (i != typeArgCount) + { + writer.WriteLine(); + } } + writer.Flush(); + writer.Close(); + + var file = new FileInfo(classFilePath); + + if (!file.Exists) throw new FileNotFoundException(classFilePath); + + Console.WriteLine(); + Console.WriteLine($"{file.Length:N0} bytes written to {file.FullName} successfully!"); +} + +void GenerateTestFiles(string testFilePath) +{ + Console.WriteLine($"Will generate tests file at {testFilePath}"); + Console.WriteLine("Press any key to continue or Ctrl-C to cancel"); + Console.ReadKey(); + + using var writer = new StreamWriter(testFilePath, append: false); + + // File header + writer.WriteLine("// Licensed to the .NET Foundation under one or more agreements."); + writer.WriteLine("// The .NET Foundation licenses this file to you under the MIT license."); + writer.WriteLine(); + writer.WriteLine("// This file is generated by a tool. See: src/Http/Http.Results/tools/ResultsOfTGenerator"); + + // Namespace + writer.WriteLine("namespace Microsoft.AspNetCore.Http.Result;"); + writer.WriteLine(); + + // Using statements + writer.WriteLine("using System.Threading.Tasks;"); + writer.WriteLine("using Microsoft.Extensions.DependencyInjection;"); + writer.WriteLine("using Microsoft.Extensions.Logging;"); + writer.WriteLine("using Microsoft.Extensions.Logging.Abstractions;"); + writer.WriteLine(); + // Class declaration - writer.Write($"public sealed class {className}<"); + writer.WriteLine($"public partial class {className}OfTTests"); + writer.WriteLine("{"); - // Type args - for (int j = 1; j <= i; j++) + for (int i = 1; i <= typeArgCount; i++) { - writer.Write($"{typeArgName}{j}"); - if (j != i) + // Skip first as we don't have a Results class + if (i == 1) continue; + + GenerateTest_Result_IsAssignedResult(writer, i); + GenerateTest_ExecuteResult_ExecutesAssignedResult(writer, i); + GenerateTest_Throws_ArgumentNullException_WhenHttpContextIsNull(writer, i); + GenerateTest_Throws_InvalidOperationException_WhenResultIsNull(writer, i); + } + + Generate_ChecksumResultClass(writer); + + // CustomResult classes + writer.WriteLine(); + for (int i = 1; i <= typeArgCount; i++) + { + Generate_ChecksumResultClass(writer, i); + + if (i != typeArgCount) { - writer.Write(", "); + writer.WriteLine(); } } - writer.WriteLine("> : IResult"); + // End test class + writer.WriteLine("}"); + + writer.Flush(); + writer.Close(); + + var file = new FileInfo(testFilePath); + + if (!file.Exists) throw new FileNotFoundException(testFilePath); + + Console.WriteLine(); + Console.WriteLine($"{file.Length:N0} bytes written to {file.FullName} successfully!"); +} + +void GenerateTest_Result_IsAssignedResult(StreamWriter writer, int typeArgNumber) +{ + //[Theory] + //[InlineData(1, typeof(ChecksumResult1))] + //[InlineData(2, typeof(ChecksumResult2))] + //public void ResultsOfTResult1TResult2_Result_IsAssignedResult(int input, Type expectedResult) + //{ + // // Arrange + // Results MyApi(int id) + // { + // return id switch + // { + // 1 => new CustomResult1(), + // _ => new CustomResult2() + // }; + // } + + // // Act + // var result = MyApi(input); + + // // Assert + // Assert.IsType(expectedResult, result.Result); + //} + + // Attributes + writer.WriteIndentedLine("[Theory]"); + + // InlineData + for (int j = 1; j <= typeArgNumber; j++) + { + writer.WriteIndentedLine($"[InlineData({j}, typeof(ChecksumResult{j}))]"); + } + + // Method + // public void ResultsOfTResult1TResult2_Result_IsAssignedResult(int input, Type expectedResult) + writer.WriteIndent(1, "public void ResultsOf"); + for (int j = 1; j <= typeArgNumber; j++) + { + writer.Write($"TResult{j}"); + } + writer.WriteLine("_Result_IsAssignedResult(int input, Type expectedResult)"); + writer.WriteIndentedLine("{"); - // Type arg contraints - for (int j = 1; j <= i; j++) + // Arrange + writer.WriteIndentedLine(2, "// Arrange"); + writer.WriteIndent(2, "Results<"); + for (int j = 1; j <= typeArgNumber; j++) + { + writer.Write($"ChecksumResult{j}"); + if (typeArgNumber != j) + { + writer.Write(", "); + } + } + writer.WriteLine("> MyApi(int id)"); + writer.WriteIndentedLine(2, "{"); + writer.WriteIndentedLine(3, "return id switch"); + writer.WriteIndentedLine(3, "{"); + for (int j = 1; j <= typeArgNumber; j++) { - writer.Write($" where {typeArgName}{j} : IResult"); - if (j != i) + if (j != typeArgNumber) + { + writer.WriteIndentedLine(4, $"{j} => new ChecksumResult{j}(),"); + } + else { - writer.Write(Environment.NewLine); + writer.WriteIndentedLine(4, $"_ => new ChecksumResult{j}()"); } } + writer.WriteIndentedLine(3, "};"); + writer.WriteIndentedLine(2, "}"); writer.WriteLine(); - writer.WriteLine("{"); - // Ctor - writer.WriteLine(" // Use implicit cast operators to create an instance"); - writer.WriteLine($" private {className}(IResult activeResult)"); - writer.WriteLine(" {"); - writer.WriteLine(" Result = activeResult;"); - writer.WriteLine(" }"); + // Act + writer.WriteIndentedLine(2, "// Act"); + writer.WriteIndentedLine(2, "var result = MyApi(input);"); writer.WriteLine(); - // Result property - writer.WriteLine(" /// "); - writer.WriteLine($" /// Gets the actual returned by the route handler delegate."); - writer.WriteLine(" /// "); - writer.WriteLine(" public IResult Result { get; }"); - writer.WriteLine(); + // Assert + writer.WriteIndentedLine(2, "// Assert"); + writer.WriteIndentedLine(2, "Assert.IsType(expectedResult, result.Result);"); - // ExecuteAsync method - writer.WriteLine(" /// "); - writer.WriteLine(" public async Task ExecuteAsync(HttpContext httpContext)"); - writer.WriteLine(" {"); - writer.WriteLine(" ArgumentNullException.ThrowIfNull(httpContext, nameof(httpContext));"); - writer.WriteLine(); - writer.WriteLine(" if (Result is null)"); - writer.WriteLine(" {"); - writer.WriteLine(" throw new InvalidOperationException(\"The IResult assigned to the Result property must not be null.\");"); - writer.WriteLine(" }"); - writer.WriteLine(); - writer.WriteLine(" await Result.ExecuteAsync(httpContext);"); - writer.WriteLine(" }"); + // End of method + writer.WriteIndentedLine("}"); writer.WriteLine(); +} - // Implicit converter operators - var sb = new StringBuilder(); - for (int j = 1; j <= i; j++) +void GenerateTest_ExecuteResult_ExecutesAssignedResult(StreamWriter writer, int typeArgNumber) +{ + //[Theory] + //[InlineData(1, 1)] + //[InlineData(2, 2)] + //[InlineData(-1, null)] + //public async Task ResultsOfTResult1TResult2_ExecuteResult_ExecutesAssignedResult(int input, object expected) + //{ + // // Arrange + // Results MyApi(int checksum) + // { + // return checksum switch + // { + // 1 => new ChecksumResult1(checksum), + // 2 => new ChecksumResult2(checksum), + // _ => (NoContentHttpResult)Results.NoContent() + // }; + // } + // var httpContext = GetHttpContext(); + + // // Act + // var result = MyApi(input); + // await result.ExecuteAsync(httpContext); + + // // Assert + // Assert.Equal(expected, httpContext.Items[result.Result]); + //} + + // Attributes + writer.WriteIndentedLine("[Theory]"); + + // InlineData + for (int j = 1; j <= typeArgNumber; j++) { - sb.Append($"{typeArgName}{j}"); - if (j != i) - { - sb.Append(", "); - } + writer.WriteIndentedLine($"[InlineData({j})]"); } - var typeArgsList = sb.ToString(); + //writer.WriteIndentedLine("[InlineData(-1, null)]"); - for (int j = 1; j <= i; j++) + // Method + // public void ResultsOfTResult1TResult2_ExecuteResult_ExecutesAssignedResult(int input, object expected) + writer.WriteIndent(1, "public async Task ResultsOf"); + for (int j = 1; j <= typeArgNumber; j++) { - writer.WriteLine(" /// "); - writer.WriteLine($" /// Converts the to a ."); - writer.WriteLine(" /// "); - writer.WriteLine(" /// The result."); - writer.WriteLine($" public static implicit operator {className}<{typeArgsList}>({typeArgName}{j} result) => new(result);"); + writer.Write($"TResult{j}"); + } + writer.WriteLine("_ExecuteResult_ExecutesAssignedResult(int input)"); + writer.WriteIndentedLine("{"); - if (i != j) + // Arrange + writer.WriteIndentedLine(2, "// Arrange"); + writer.WriteIndent(2, "Results<"); + for (int j = 1; j <= typeArgNumber; j++) + { + writer.Write($"ChecksumResult{j}"); + if (typeArgNumber != j) { - writer.WriteLine(); + writer.Write(", "); + } + } + writer.WriteLine("> MyApi(int checksum)"); + writer.WriteIndentedLine(2, "{"); + writer.WriteIndentedLine(3, "return checksum switch"); + writer.WriteIndentedLine(3, "{"); + for (int j = 1; j <= typeArgNumber; j++) + { + if (j < typeArgNumber) + { + writer.WriteIndentedLine(4, $"{j} => new ChecksumResult{j}(checksum),"); + } + else + { + writer.WriteIndentedLine(4, $"_ => new ChecksumResult{j}(checksum)"); } } + //writer.WriteIndentedLine(4, $"_ => (NoContentHttpResult)Results.NoContent()"); + writer.WriteIndentedLine(3, "};"); + writer.WriteIndentedLine(2, "}"); + writer.WriteIndentedLine(2, "var httpContext = GetHttpContext();"); + writer.WriteLine(); - // Class end - writer.WriteLine("}"); + // Act + writer.WriteIndentedLine(2, "// Act"); + writer.WriteIndentedLine(2, "var result = MyApi(input);"); + writer.WriteIndentedLine(2, "await result.ExecuteAsync(httpContext);"); + writer.WriteLine(); + + // Assert + writer.WriteIndentedLine(2, "// Assert"); + writer.WriteIndentedLine(2, "Assert.Equal(input, httpContext.Items[result.Result]);"); - if (i != typeArgCount) + // End of method + writer.WriteIndentedLine("}"); + writer.WriteLine(); +} + +void GenerateTest_Throws_ArgumentNullException_WhenHttpContextIsNull(StreamWriter writer, int typeArgNumber) +{ + //[Fact] + //public void ResultsOfTResult1TResult2_Throws_ArgumentNullException_WhenHttpContextIsNull() + //{ + // // Arrange + // Results MyApi() + // { + // return new ChecksumResult(1); + // } + // HttpContext httpContext = null; + + // // Act & Assert + // var result = MyApi(); + + // Assert.ThrowsAsync(async () => + // { + // await result.ExecuteAsync(httpContext); + // }); + //} + +} + +void GenerateTest_Throws_InvalidOperationException_WhenResultIsNull(StreamWriter writer, int typeArgNumber) +{ + //[Fact] + //public void ResultsOfTResult1TResult2_Throws_InvalidOperationException_WhenResultIsNull() + //{ + // // Arrange + // Results MyApi() + // { + // return (ChecksumResult)null; + // } + // var httpContext = GetHttpContext(); + + // // Act & Assert + // var result = MyApi(); + + // Assert.ThrowsAsync(async () => + // { + // await result.ExecuteAsync(httpContext); + // }); + //} + +} + +void Generate_ChecksumResultClass(StreamWriter writer, int typeArgNumber = -1) +{ + if (typeArgNumber <= 0) { + writer.WriteIndentedLine(1, "class ChecksumResult : IResult"); + writer.WriteIndentedLine(1, "{"); + writer.WriteIndentedLine(2, "public ChecksumResult(int checksum = 0)"); + writer.WriteIndentedLine(2, "{"); + writer.WriteIndentedLine(3, "Checksum = checksum;"); + writer.WriteIndentedLine(2, "}"); + writer.WriteLine(); + writer.WriteIndentedLine(2, "public int Checksum { get; }"); writer.WriteLine(); + writer.WriteIndentedLine(2, "public Task ExecuteAsync(HttpContext httpContext)"); + writer.WriteIndentedLine(2, "{"); + writer.WriteIndentedLine(3, "httpContext.Items[this] = Checksum;"); + writer.WriteIndentedLine(3, "return Task.CompletedTask;"); + writer.WriteIndentedLine(2, "}"); + writer.WriteIndentedLine(1, "}"); + } + else + { + // ChecksumResult class + //class ChecksumResult1 : ChecksumResult + //{ + // public ChecksumResult1(int checksum = 0) : base(checksum) { } + //} + writer.WriteIndentedLine(1, $"class ChecksumResult{typeArgNumber} : ChecksumResult"); + writer.WriteIndentedLine(1, "{"); + writer.WriteIndentedLine(2, $"public ChecksumResult{typeArgNumber}(int checksum = 0) : base(checksum) {{ }}"); + writer.WriteIndentedLine(1, "}"); } } -writer.Flush(); -writer.Close(); +static class StringExtensions +{ + public static void WriteIndent(this StreamWriter writer, string? value = null) + { + WriteIndent(writer, 1, value); + } -var file = new FileInfo(filePath); + public static void WriteIndent(this StreamWriter writer, int count, string? value = null) + { + for (int i = 1; i <= count; i++) + { + writer.Write(" "); + } -if (!file.Exists) throw new FileNotFoundException(filePath); + if (value != null) + { + writer.Write(value); + } + } -Console.WriteLine(); -Console.WriteLine($"{file.Length:N0} bytes written to {file.FullName} successfully!"); + public static void WriteIndentedLine(this StreamWriter writer, string? value = null) + { + WriteIndentedLine(writer, 1, value); + } + + public static void WriteIndentedLine(this StreamWriter writer, int count, string? value = null) + { + WriteIndent(writer, count, value); + writer.WriteLine(); + } -static class StringExtensions -{ public static string ToWords(this int number) => number switch { 1 => "one", @@ -201,112 +570,3 @@ static class StringExtensions _ => throw new NotImplementedException("Add more numbers") }; } - -/* TEMPLATE -/// -/// Represents the result of an route handler delegate that can return ten different types. -/// -/// The first result type. -/// The second result type. -/// The third result type. -/// The fourth result type. -/// The fifth result type. -/// The sixth result type. -/// The seventh result type. -/// The eighth result type. -/// The ninth result type. -/// The tenth result type. -public sealed class Results : IResult - where TResult1 : IResult - where TResult2 : IResult - where TResult3 : IResult - where TResult4 : IResult - where TResult5 : IResult - where TResult6 : IResult - where TResult7 : IResult - where TResult8 : IResult - where TResult9 : IResult - where TResult10 : IResult -{ - private Results(IResult activeResult) - { - Result = activeResult; - } - - /// - /// Gets the actual returned by the route handler delegate. - /// - public IResult Result { get; } - - /// - /// Writes an HTTP response reflecting the result. - /// - /// The for the current request. - /// A that represents the asynchronous execute operation. - public async Task ExecuteAsync(HttpContext httpContext) - { - ArgumentNullException.ThrowIfNull(httpContext, nameof(httpContext)); - - await Result.ExecuteAsync(httpContext); - } - - /// - /// Converts the to a . - /// - /// The result. - public static implicit operator Results(TResult1 result) => new(result); - - /// - /// Converts the to a . - /// - /// The result. - public static implicit operator Results(TResult2 result) => new(result); - - /// - /// Converts the to a . - /// - /// The result. - public static implicit operator Results(TResult3 result) => new(result); - - /// - /// Converts the to a . - /// - /// The result. - public static implicit operator Results(TResult4 result) => new(result); - - /// - /// Converts the to a . - /// - /// The result. - public static implicit operator Results(TResult5 result) => new(result); - - /// - /// Converts the to a . - /// - /// The result. - public static implicit operator Results(TResult6 result) => new(result); - - /// - /// Converts the to a . - /// - /// The result. - public static implicit operator Results(TResult7 result) => new(result); - - /// - /// Converts the to a . - /// - /// The result. - public static implicit operator Results(TResult8 result) => new(result); - - /// - /// Converts the to a . - /// - /// The result. - public static implicit operator Results(TResult9 result) => new(result); - - /// - /// Converts the to a . - /// - /// The result. - public static implicit operator Results(TResult10 result) => new(result); - */ From 0eda77bf602c6aff8ba011bd93a71e43842577c7 Mon Sep 17 00:00:00 2001 From: Damian Edwards Date: Thu, 31 Mar 2022 17:35:23 -0700 Subject: [PATCH 11/19] More Results tests --- .../test/ResultsOfTTests.Generated.cs | 570 ++++++++++++++++++ .../tools/ResultsOfTGenerator/Program.cs | 77 ++- 2 files changed, 642 insertions(+), 5 deletions(-) diff --git a/src/Http/Http.Results/test/ResultsOfTTests.Generated.cs b/src/Http/Http.Results/test/ResultsOfTTests.Generated.cs index 8205f47d03a2..07e141345f24 100644 --- a/src/Http/Http.Results/test/ResultsOfTTests.Generated.cs +++ b/src/Http/Http.Results/test/ResultsOfTTests.Generated.cs @@ -57,6 +57,44 @@ Results MyApi(int checksum) Assert.Equal(input, httpContext.Items[result.Result]); } + [Fact] + public void ResultsOfTResult1TResult2_Throws_ArgumentNullException_WhenHttpContextIsNull() + { + // Arrange + Results MyApi() + { + return new ChecksumResult1(1); + } + HttpContext httpContext = null; + + // Act & Assert + var result = MyApi(); + + Assert.ThrowsAsync(async () => + { + await result.ExecuteAsync(httpContext); + }); + } + + [Fact] + public void ResultsOfTResult1TResult2_Throws_InvalidOperationException_WhenResultIsNull() + { + // Arrange + Results MyApi() + { + return new ChecksumResult1(1); + } + var httpContext = GetHttpContext(); + + // Act & Assert + var result = MyApi(); + + Assert.ThrowsAsync(async () => + { + await result.ExecuteAsync(httpContext); + }); + } + [Theory] [InlineData(1, typeof(ChecksumResult1))] [InlineData(2, typeof(ChecksumResult2))] @@ -107,6 +145,44 @@ Results MyApi(int checksum) Assert.Equal(input, httpContext.Items[result.Result]); } + [Fact] + public void ResultsOfTResult1TResult2TResult3_Throws_ArgumentNullException_WhenHttpContextIsNull() + { + // Arrange + Results MyApi() + { + return new ChecksumResult1(1); + } + HttpContext httpContext = null; + + // Act & Assert + var result = MyApi(); + + Assert.ThrowsAsync(async () => + { + await result.ExecuteAsync(httpContext); + }); + } + + [Fact] + public void ResultsOfTResult1TResult2TResult3_Throws_InvalidOperationException_WhenResultIsNull() + { + // Arrange + Results MyApi() + { + return new ChecksumResult1(1); + } + var httpContext = GetHttpContext(); + + // Act & Assert + var result = MyApi(); + + Assert.ThrowsAsync(async () => + { + await result.ExecuteAsync(httpContext); + }); + } + [Theory] [InlineData(1, typeof(ChecksumResult1))] [InlineData(2, typeof(ChecksumResult2))] @@ -161,6 +237,44 @@ Results MyAp Assert.Equal(input, httpContext.Items[result.Result]); } + [Fact] + public void ResultsOfTResult1TResult2TResult3TResult4_Throws_ArgumentNullException_WhenHttpContextIsNull() + { + // Arrange + Results MyApi() + { + return new ChecksumResult1(1); + } + HttpContext httpContext = null; + + // Act & Assert + var result = MyApi(); + + Assert.ThrowsAsync(async () => + { + await result.ExecuteAsync(httpContext); + }); + } + + [Fact] + public void ResultsOfTResult1TResult2TResult3TResult4_Throws_InvalidOperationException_WhenResultIsNull() + { + // Arrange + Results MyApi() + { + return new ChecksumResult1(1); + } + var httpContext = GetHttpContext(); + + // Act & Assert + var result = MyApi(); + + Assert.ThrowsAsync(async () => + { + await result.ExecuteAsync(httpContext); + }); + } + [Theory] [InlineData(1, typeof(ChecksumResult1))] [InlineData(2, typeof(ChecksumResult2))] @@ -219,6 +333,44 @@ Results MyApi() + { + return new ChecksumResult1(1); + } + HttpContext httpContext = null; + + // Act & Assert + var result = MyApi(); + + Assert.ThrowsAsync(async () => + { + await result.ExecuteAsync(httpContext); + }); + } + + [Fact] + public void ResultsOfTResult1TResult2TResult3TResult4TResult5_Throws_InvalidOperationException_WhenResultIsNull() + { + // Arrange + Results MyApi() + { + return new ChecksumResult1(1); + } + var httpContext = GetHttpContext(); + + // Act & Assert + var result = MyApi(); + + Assert.ThrowsAsync(async () => + { + await result.ExecuteAsync(httpContext); + }); + } + [Theory] [InlineData(1, typeof(ChecksumResult1))] [InlineData(2, typeof(ChecksumResult2))] @@ -281,6 +433,44 @@ Results MyApi() + { + return new ChecksumResult1(1); + } + HttpContext httpContext = null; + + // Act & Assert + var result = MyApi(); + + Assert.ThrowsAsync(async () => + { + await result.ExecuteAsync(httpContext); + }); + } + + [Fact] + public void ResultsOfTResult1TResult2TResult3TResult4TResult5TResult6_Throws_InvalidOperationException_WhenResultIsNull() + { + // Arrange + Results MyApi() + { + return new ChecksumResult1(1); + } + var httpContext = GetHttpContext(); + + // Act & Assert + var result = MyApi(); + + Assert.ThrowsAsync(async () => + { + await result.ExecuteAsync(httpContext); + }); + } + [Theory] [InlineData(1, typeof(ChecksumResult1))] [InlineData(2, typeof(ChecksumResult2))] @@ -347,6 +537,44 @@ Results MyApi() + { + return new ChecksumResult1(1); + } + HttpContext httpContext = null; + + // Act & Assert + var result = MyApi(); + + Assert.ThrowsAsync(async () => + { + await result.ExecuteAsync(httpContext); + }); + } + + [Fact] + public void ResultsOfTResult1TResult2TResult3TResult4TResult5TResult6TResult7_Throws_InvalidOperationException_WhenResultIsNull() + { + // Arrange + Results MyApi() + { + return new ChecksumResult1(1); + } + var httpContext = GetHttpContext(); + + // Act & Assert + var result = MyApi(); + + Assert.ThrowsAsync(async () => + { + await result.ExecuteAsync(httpContext); + }); + } + [Theory] [InlineData(1, typeof(ChecksumResult1))] [InlineData(2, typeof(ChecksumResult2))] @@ -417,6 +645,44 @@ Results MyApi() + { + return new ChecksumResult1(1); + } + HttpContext httpContext = null; + + // Act & Assert + var result = MyApi(); + + Assert.ThrowsAsync(async () => + { + await result.ExecuteAsync(httpContext); + }); + } + + [Fact] + public void ResultsOfTResult1TResult2TResult3TResult4TResult5TResult6TResult7TResult8_Throws_InvalidOperationException_WhenResultIsNull() + { + // Arrange + Results MyApi() + { + return new ChecksumResult1(1); + } + var httpContext = GetHttpContext(); + + // Act & Assert + var result = MyApi(); + + Assert.ThrowsAsync(async () => + { + await result.ExecuteAsync(httpContext); + }); + } + [Theory] [InlineData(1, typeof(ChecksumResult1))] [InlineData(2, typeof(ChecksumResult2))] @@ -491,6 +757,44 @@ Results MyApi() + { + return new ChecksumResult1(1); + } + HttpContext httpContext = null; + + // Act & Assert + var result = MyApi(); + + Assert.ThrowsAsync(async () => + { + await result.ExecuteAsync(httpContext); + }); + } + + [Fact] + public void ResultsOfTResult1TResult2TResult3TResult4TResult5TResult6TResult7TResult8TResult9_Throws_InvalidOperationException_WhenResultIsNull() + { + // Arrange + Results MyApi() + { + return new ChecksumResult1(1); + } + var httpContext = GetHttpContext(); + + // Act & Assert + var result = MyApi(); + + Assert.ThrowsAsync(async () => + { + await result.ExecuteAsync(httpContext); + }); + } + [Theory] [InlineData(1, typeof(ChecksumResult1))] [InlineData(2, typeof(ChecksumResult2))] @@ -569,6 +873,44 @@ Results MyApi() + { + return new ChecksumResult1(1); + } + HttpContext httpContext = null; + + // Act & Assert + var result = MyApi(); + + Assert.ThrowsAsync(async () => + { + await result.ExecuteAsync(httpContext); + }); + } + + [Fact] + public void ResultsOfTResult1TResult2TResult3TResult4TResult5TResult6TResult7TResult8TResult9TResult10_Throws_InvalidOperationException_WhenResultIsNull() + { + // Arrange + Results MyApi() + { + return new ChecksumResult1(1); + } + var httpContext = GetHttpContext(); + + // Act & Assert + var result = MyApi(); + + Assert.ThrowsAsync(async () => + { + await result.ExecuteAsync(httpContext); + }); + } + [Theory] [InlineData(1, typeof(ChecksumResult1))] [InlineData(2, typeof(ChecksumResult2))] @@ -651,6 +993,44 @@ Results MyApi() + { + return new ChecksumResult1(1); + } + HttpContext httpContext = null; + + // Act & Assert + var result = MyApi(); + + Assert.ThrowsAsync(async () => + { + await result.ExecuteAsync(httpContext); + }); + } + + [Fact] + public void ResultsOfTResult1TResult2TResult3TResult4TResult5TResult6TResult7TResult8TResult9TResult10TResult11_Throws_InvalidOperationException_WhenResultIsNull() + { + // Arrange + Results MyApi() + { + return new ChecksumResult1(1); + } + var httpContext = GetHttpContext(); + + // Act & Assert + var result = MyApi(); + + Assert.ThrowsAsync(async () => + { + await result.ExecuteAsync(httpContext); + }); + } + [Theory] [InlineData(1, typeof(ChecksumResult1))] [InlineData(2, typeof(ChecksumResult2))] @@ -737,6 +1117,44 @@ Results MyApi() + { + return new ChecksumResult1(1); + } + HttpContext httpContext = null; + + // Act & Assert + var result = MyApi(); + + Assert.ThrowsAsync(async () => + { + await result.ExecuteAsync(httpContext); + }); + } + + [Fact] + public void ResultsOfTResult1TResult2TResult3TResult4TResult5TResult6TResult7TResult8TResult9TResult10TResult11TResult12_Throws_InvalidOperationException_WhenResultIsNull() + { + // Arrange + Results MyApi() + { + return new ChecksumResult1(1); + } + var httpContext = GetHttpContext(); + + // Act & Assert + var result = MyApi(); + + Assert.ThrowsAsync(async () => + { + await result.ExecuteAsync(httpContext); + }); + } + [Theory] [InlineData(1, typeof(ChecksumResult1))] [InlineData(2, typeof(ChecksumResult2))] @@ -827,6 +1245,44 @@ Results MyApi() + { + return new ChecksumResult1(1); + } + HttpContext httpContext = null; + + // Act & Assert + var result = MyApi(); + + Assert.ThrowsAsync(async () => + { + await result.ExecuteAsync(httpContext); + }); + } + + [Fact] + public void ResultsOfTResult1TResult2TResult3TResult4TResult5TResult6TResult7TResult8TResult9TResult10TResult11TResult12TResult13_Throws_InvalidOperationException_WhenResultIsNull() + { + // Arrange + Results MyApi() + { + return new ChecksumResult1(1); + } + var httpContext = GetHttpContext(); + + // Act & Assert + var result = MyApi(); + + Assert.ThrowsAsync(async () => + { + await result.ExecuteAsync(httpContext); + }); + } + [Theory] [InlineData(1, typeof(ChecksumResult1))] [InlineData(2, typeof(ChecksumResult2))] @@ -921,6 +1377,44 @@ Results MyApi() + { + return new ChecksumResult1(1); + } + HttpContext httpContext = null; + + // Act & Assert + var result = MyApi(); + + Assert.ThrowsAsync(async () => + { + await result.ExecuteAsync(httpContext); + }); + } + + [Fact] + public void ResultsOfTResult1TResult2TResult3TResult4TResult5TResult6TResult7TResult8TResult9TResult10TResult11TResult12TResult13TResult14_Throws_InvalidOperationException_WhenResultIsNull() + { + // Arrange + Results MyApi() + { + return new ChecksumResult1(1); + } + var httpContext = GetHttpContext(); + + // Act & Assert + var result = MyApi(); + + Assert.ThrowsAsync(async () => + { + await result.ExecuteAsync(httpContext); + }); + } + [Theory] [InlineData(1, typeof(ChecksumResult1))] [InlineData(2, typeof(ChecksumResult2))] @@ -1019,6 +1513,44 @@ Results MyApi() + { + return new ChecksumResult1(1); + } + HttpContext httpContext = null; + + // Act & Assert + var result = MyApi(); + + Assert.ThrowsAsync(async () => + { + await result.ExecuteAsync(httpContext); + }); + } + + [Fact] + public void ResultsOfTResult1TResult2TResult3TResult4TResult5TResult6TResult7TResult8TResult9TResult10TResult11TResult12TResult13TResult14TResult15_Throws_InvalidOperationException_WhenResultIsNull() + { + // Arrange + Results MyApi() + { + return new ChecksumResult1(1); + } + var httpContext = GetHttpContext(); + + // Act & Assert + var result = MyApi(); + + Assert.ThrowsAsync(async () => + { + await result.ExecuteAsync(httpContext); + }); + } + [Theory] [InlineData(1, typeof(ChecksumResult1))] [InlineData(2, typeof(ChecksumResult2))] @@ -1121,6 +1653,44 @@ Results MyApi() + { + return new ChecksumResult1(1); + } + HttpContext httpContext = null; + + // Act & Assert + var result = MyApi(); + + Assert.ThrowsAsync(async () => + { + await result.ExecuteAsync(httpContext); + }); + } + + [Fact] + public void ResultsOfTResult1TResult2TResult3TResult4TResult5TResult6TResult7TResult8TResult9TResult10TResult11TResult12TResult13TResult14TResult15TResult16_Throws_InvalidOperationException_WhenResultIsNull() + { + // Arrange + Results MyApi() + { + return new ChecksumResult1(1); + } + var httpContext = GetHttpContext(); + + // Act & Assert + var result = MyApi(); + + Assert.ThrowsAsync(async () => + { + await result.ExecuteAsync(httpContext); + }); + } + class ChecksumResult : IResult { public ChecksumResult(int checksum = 0) diff --git a/src/Http/Http.Results/tools/ResultsOfTGenerator/Program.cs b/src/Http/Http.Results/tools/ResultsOfTGenerator/Program.cs index 5940cdf414da..7cbdc2559648 100644 --- a/src/Http/Http.Results/tools/ResultsOfTGenerator/Program.cs +++ b/src/Http/Http.Results/tools/ResultsOfTGenerator/Program.cs @@ -388,7 +388,6 @@ void GenerateTest_ExecuteResult_ExecutesAssignedResult(StreamWriter writer, int writer.WriteIndentedLine(4, $"_ => new ChecksumResult{j}(checksum)"); } } - //writer.WriteIndentedLine(4, $"_ => (NoContentHttpResult)Results.NoContent()"); writer.WriteIndentedLine(3, "};"); writer.WriteIndentedLine(2, "}"); writer.WriteIndentedLine(2, "var httpContext = GetHttpContext();"); @@ -415,9 +414,9 @@ void GenerateTest_Throws_ArgumentNullException_WhenHttpContextIsNull(StreamWrite //public void ResultsOfTResult1TResult2_Throws_ArgumentNullException_WhenHttpContextIsNull() //{ // // Arrange - // Results MyApi() + // Results MyApi() // { - // return new ChecksumResult(1); + // return new ChecksumResult1(1); // } // HttpContext httpContext = null; @@ -430,6 +429,40 @@ void GenerateTest_Throws_ArgumentNullException_WhenHttpContextIsNull(StreamWrite // }); //} + // Attributes + writer.WriteIndentedLine("[Fact]"); + + // Start method + writer.WriteIndent(1, "public void ResultsOf"); + for (int j = 1; j <= typeArgNumber; j++) + { + writer.Write($"TResult{j}"); + } + writer.WriteLine("_Throws_ArgumentNullException_WhenHttpContextIsNull()"); + writer.WriteIndentedLine("{"); + + // Arrange + writer.WriteIndentedLine(2, "// Arrange"); + writer.WriteIndentedLine(2, "Results MyApi()"); + writer.WriteIndentedLine(2, "{"); + writer.WriteIndentedLine(3, "return new ChecksumResult1(1);"); + writer.WriteIndentedLine(2, "}"); + writer.WriteIndentedLine(2, "HttpContext httpContext = null;"); + writer.WriteIndentedLine(2); + + // Act & Assert + writer.WriteIndentedLine(2, "// Act & Assert"); + writer.WriteIndentedLine(2, "var result = MyApi();"); + writer.WriteIndentedLine(2); + + writer.WriteIndentedLine(2, "Assert.ThrowsAsync(async () =>"); + writer.WriteIndentedLine(2, "{"); + writer.WriteIndentedLine(3, "await result.ExecuteAsync(httpContext);"); + writer.WriteIndentedLine(2, "});"); + + // Close method + writer.WriteIndentedLine(1, "}"); + writer.WriteIndentedLine(); } void GenerateTest_Throws_InvalidOperationException_WhenResultIsNull(StreamWriter writer, int typeArgNumber) @@ -438,9 +471,9 @@ void GenerateTest_Throws_InvalidOperationException_WhenResultIsNull(StreamWriter //public void ResultsOfTResult1TResult2_Throws_InvalidOperationException_WhenResultIsNull() //{ // // Arrange - // Results MyApi() + // Results MyApi() // { - // return (ChecksumResult)null; + // return (ChecksumResult1)null; // } // var httpContext = GetHttpContext(); @@ -453,6 +486,40 @@ void GenerateTest_Throws_InvalidOperationException_WhenResultIsNull(StreamWriter // }); //} + // Attributes + writer.WriteIndentedLine("[Fact]"); + + // Start method + writer.WriteIndent(1, "public void ResultsOf"); + for (int j = 1; j <= typeArgNumber; j++) + { + writer.Write($"TResult{j}"); + } + writer.WriteLine("_Throws_InvalidOperationException_WhenResultIsNull()"); + writer.WriteIndentedLine("{"); + + // Arrange + writer.WriteIndentedLine(2, "// Arrange"); + writer.WriteIndentedLine(2, "Results MyApi()"); + writer.WriteIndentedLine(2, "{"); + writer.WriteIndentedLine(3, "return new ChecksumResult1(1);"); + writer.WriteIndentedLine(2, "}"); + writer.WriteIndentedLine(2, "var httpContext = GetHttpContext();"); + writer.WriteIndentedLine(2); + + // Act & Assert + writer.WriteIndentedLine(2, "// Act & Assert"); + writer.WriteIndentedLine(2, "var result = MyApi();"); + writer.WriteIndentedLine(2); + + writer.WriteIndentedLine(2, "Assert.ThrowsAsync(async () =>"); + writer.WriteIndentedLine(2, "{"); + writer.WriteIndentedLine(3, "await result.ExecuteAsync(httpContext);"); + writer.WriteIndentedLine(2, "});"); + + // Close method + writer.WriteIndentedLine(1, "}"); + writer.WriteIndentedLine(); } void Generate_ChecksumResultClass(StreamWriter writer, int typeArgNumber = -1) From 6a0eae7ff9536415389f765f6dfa4312597aab2e Mon Sep 17 00:00:00 2001 From: Damian Edwards Date: Thu, 31 Mar 2022 17:41:38 -0700 Subject: [PATCH 12/19] Result code gen tweaks --- src/Http/Http.Results/src/ResultsOfT.cs | 270 +++++++++--------- .../tools/ResultsOfTGenerator/Program.cs | 54 ++-- 2 files changed, 162 insertions(+), 162 deletions(-) diff --git a/src/Http/Http.Results/src/ResultsOfT.cs b/src/Http/Http.Results/src/ResultsOfT.cs index 9cde02f6ff67..45382eccb07e 100644 --- a/src/Http/Http.Results/src/ResultsOfT.cs +++ b/src/Http/Http.Results/src/ResultsOfT.cs @@ -16,8 +16,8 @@ namespace Microsoft.AspNetCore.Http; /// The first result type. /// The second result type. public sealed class Results : IResult - where TResult1 : IResult - where TResult2 : IResult + where TResult1 : IResult + where TResult2 : IResult { // Use implicit cast operators to create an instance private Results(IResult activeResult) @@ -69,9 +69,9 @@ public async Task ExecuteAsync(HttpContext httpContext) /// The second result type. /// The third result type. public sealed class Results : IResult - where TResult1 : IResult - where TResult2 : IResult - where TResult3 : IResult + where TResult1 : IResult + where TResult2 : IResult + where TResult3 : IResult { // Use implicit cast operators to create an instance private Results(IResult activeResult) @@ -130,10 +130,10 @@ public async Task ExecuteAsync(HttpContext httpContext) /// The third result type. /// The fourth result type. public sealed class Results : IResult - where TResult1 : IResult - where TResult2 : IResult - where TResult3 : IResult - where TResult4 : IResult + where TResult1 : IResult + where TResult2 : IResult + where TResult3 : IResult + where TResult4 : IResult { // Use implicit cast operators to create an instance private Results(IResult activeResult) @@ -199,11 +199,11 @@ public async Task ExecuteAsync(HttpContext httpContext) /// The fourth result type. /// The fifth result type. public sealed class Results : IResult - where TResult1 : IResult - where TResult2 : IResult - where TResult3 : IResult - where TResult4 : IResult - where TResult5 : IResult + where TResult1 : IResult + where TResult2 : IResult + where TResult3 : IResult + where TResult4 : IResult + where TResult5 : IResult { // Use implicit cast operators to create an instance private Results(IResult activeResult) @@ -276,12 +276,12 @@ public async Task ExecuteAsync(HttpContext httpContext) /// The fifth result type. /// The sixth result type. public sealed class Results : IResult - where TResult1 : IResult - where TResult2 : IResult - where TResult3 : IResult - where TResult4 : IResult - where TResult5 : IResult - where TResult6 : IResult + where TResult1 : IResult + where TResult2 : IResult + where TResult3 : IResult + where TResult4 : IResult + where TResult5 : IResult + where TResult6 : IResult { // Use implicit cast operators to create an instance private Results(IResult activeResult) @@ -361,13 +361,13 @@ public async Task ExecuteAsync(HttpContext httpContext) /// The sixth result type. /// The seventh result type. public sealed class Results : IResult - where TResult1 : IResult - where TResult2 : IResult - where TResult3 : IResult - where TResult4 : IResult - where TResult5 : IResult - where TResult6 : IResult - where TResult7 : IResult + where TResult1 : IResult + where TResult2 : IResult + where TResult3 : IResult + where TResult4 : IResult + where TResult5 : IResult + where TResult6 : IResult + where TResult7 : IResult { // Use implicit cast operators to create an instance private Results(IResult activeResult) @@ -454,14 +454,14 @@ public async Task ExecuteAsync(HttpContext httpContext) /// The seventh result type. /// The eighth result type. public sealed class Results : IResult - where TResult1 : IResult - where TResult2 : IResult - where TResult3 : IResult - where TResult4 : IResult - where TResult5 : IResult - where TResult6 : IResult - where TResult7 : IResult - where TResult8 : IResult + where TResult1 : IResult + where TResult2 : IResult + where TResult3 : IResult + where TResult4 : IResult + where TResult5 : IResult + where TResult6 : IResult + where TResult7 : IResult + where TResult8 : IResult { // Use implicit cast operators to create an instance private Results(IResult activeResult) @@ -555,15 +555,15 @@ public async Task ExecuteAsync(HttpContext httpContext) /// The eighth result type. /// The ninth result type. public sealed class Results : IResult - where TResult1 : IResult - where TResult2 : IResult - where TResult3 : IResult - where TResult4 : IResult - where TResult5 : IResult - where TResult6 : IResult - where TResult7 : IResult - where TResult8 : IResult - where TResult9 : IResult + where TResult1 : IResult + where TResult2 : IResult + where TResult3 : IResult + where TResult4 : IResult + where TResult5 : IResult + where TResult6 : IResult + where TResult7 : IResult + where TResult8 : IResult + where TResult9 : IResult { // Use implicit cast operators to create an instance private Results(IResult activeResult) @@ -664,16 +664,16 @@ public async Task ExecuteAsync(HttpContext httpContext) /// The ninth result type. /// The tenth result type. public sealed class Results : IResult - where TResult1 : IResult - where TResult2 : IResult - where TResult3 : IResult - where TResult4 : IResult - where TResult5 : IResult - where TResult6 : IResult - where TResult7 : IResult - where TResult8 : IResult - where TResult9 : IResult - where TResult10 : IResult + where TResult1 : IResult + where TResult2 : IResult + where TResult3 : IResult + where TResult4 : IResult + where TResult5 : IResult + where TResult6 : IResult + where TResult7 : IResult + where TResult8 : IResult + where TResult9 : IResult + where TResult10 : IResult { // Use implicit cast operators to create an instance private Results(IResult activeResult) @@ -781,17 +781,17 @@ public async Task ExecuteAsync(HttpContext httpContext) /// The tenth result type. /// The eleventh result type. public sealed class Results : IResult - where TResult1 : IResult - where TResult2 : IResult - where TResult3 : IResult - where TResult4 : IResult - where TResult5 : IResult - where TResult6 : IResult - where TResult7 : IResult - where TResult8 : IResult - where TResult9 : IResult - where TResult10 : IResult - where TResult11 : IResult + where TResult1 : IResult + where TResult2 : IResult + where TResult3 : IResult + where TResult4 : IResult + where TResult5 : IResult + where TResult6 : IResult + where TResult7 : IResult + where TResult8 : IResult + where TResult9 : IResult + where TResult10 : IResult + where TResult11 : IResult { // Use implicit cast operators to create an instance private Results(IResult activeResult) @@ -906,18 +906,18 @@ public async Task ExecuteAsync(HttpContext httpContext) /// The eleventh result type. /// The twelfth result type. public sealed class Results : IResult - where TResult1 : IResult - where TResult2 : IResult - where TResult3 : IResult - where TResult4 : IResult - where TResult5 : IResult - where TResult6 : IResult - where TResult7 : IResult - where TResult8 : IResult - where TResult9 : IResult - where TResult10 : IResult - where TResult11 : IResult - where TResult12 : IResult + where TResult1 : IResult + where TResult2 : IResult + where TResult3 : IResult + where TResult4 : IResult + where TResult5 : IResult + where TResult6 : IResult + where TResult7 : IResult + where TResult8 : IResult + where TResult9 : IResult + where TResult10 : IResult + where TResult11 : IResult + where TResult12 : IResult { // Use implicit cast operators to create an instance private Results(IResult activeResult) @@ -1039,19 +1039,19 @@ public async Task ExecuteAsync(HttpContext httpContext) /// The twelfth result type. /// The thirteenth result type. public sealed class Results : IResult - where TResult1 : IResult - where TResult2 : IResult - where TResult3 : IResult - where TResult4 : IResult - where TResult5 : IResult - where TResult6 : IResult - where TResult7 : IResult - where TResult8 : IResult - where TResult9 : IResult - where TResult10 : IResult - where TResult11 : IResult - where TResult12 : IResult - where TResult13 : IResult + where TResult1 : IResult + where TResult2 : IResult + where TResult3 : IResult + where TResult4 : IResult + where TResult5 : IResult + where TResult6 : IResult + where TResult7 : IResult + where TResult8 : IResult + where TResult9 : IResult + where TResult10 : IResult + where TResult11 : IResult + where TResult12 : IResult + where TResult13 : IResult { // Use implicit cast operators to create an instance private Results(IResult activeResult) @@ -1180,20 +1180,20 @@ public async Task ExecuteAsync(HttpContext httpContext) /// The thirteenth result type. /// The fourteenth result type. public sealed class Results : IResult - where TResult1 : IResult - where TResult2 : IResult - where TResult3 : IResult - where TResult4 : IResult - where TResult5 : IResult - where TResult6 : IResult - where TResult7 : IResult - where TResult8 : IResult - where TResult9 : IResult - where TResult10 : IResult - where TResult11 : IResult - where TResult12 : IResult - where TResult13 : IResult - where TResult14 : IResult + where TResult1 : IResult + where TResult2 : IResult + where TResult3 : IResult + where TResult4 : IResult + where TResult5 : IResult + where TResult6 : IResult + where TResult7 : IResult + where TResult8 : IResult + where TResult9 : IResult + where TResult10 : IResult + where TResult11 : IResult + where TResult12 : IResult + where TResult13 : IResult + where TResult14 : IResult { // Use implicit cast operators to create an instance private Results(IResult activeResult) @@ -1329,21 +1329,21 @@ public async Task ExecuteAsync(HttpContext httpContext) /// The fourteenth result type. /// The fifteenth result type. public sealed class Results : IResult - where TResult1 : IResult - where TResult2 : IResult - where TResult3 : IResult - where TResult4 : IResult - where TResult5 : IResult - where TResult6 : IResult - where TResult7 : IResult - where TResult8 : IResult - where TResult9 : IResult - where TResult10 : IResult - where TResult11 : IResult - where TResult12 : IResult - where TResult13 : IResult - where TResult14 : IResult - where TResult15 : IResult + where TResult1 : IResult + where TResult2 : IResult + where TResult3 : IResult + where TResult4 : IResult + where TResult5 : IResult + where TResult6 : IResult + where TResult7 : IResult + where TResult8 : IResult + where TResult9 : IResult + where TResult10 : IResult + where TResult11 : IResult + where TResult12 : IResult + where TResult13 : IResult + where TResult14 : IResult + where TResult15 : IResult { // Use implicit cast operators to create an instance private Results(IResult activeResult) @@ -1486,22 +1486,22 @@ public async Task ExecuteAsync(HttpContext httpContext) /// The fifteenth result type. /// The sixteenth result type. public sealed class Results : IResult - where TResult1 : IResult - where TResult2 : IResult - where TResult3 : IResult - where TResult4 : IResult - where TResult5 : IResult - where TResult6 : IResult - where TResult7 : IResult - where TResult8 : IResult - where TResult9 : IResult - where TResult10 : IResult - where TResult11 : IResult - where TResult12 : IResult - where TResult13 : IResult - where TResult14 : IResult - where TResult15 : IResult - where TResult16 : IResult + where TResult1 : IResult + where TResult2 : IResult + where TResult3 : IResult + where TResult4 : IResult + where TResult5 : IResult + where TResult6 : IResult + where TResult7 : IResult + where TResult8 : IResult + where TResult9 : IResult + where TResult10 : IResult + where TResult11 : IResult + where TResult12 : IResult + where TResult13 : IResult + where TResult14 : IResult + where TResult15 : IResult + where TResult16 : IResult { // Use implicit cast operators to create an instance private Results(IResult activeResult) diff --git a/src/Http/Http.Results/tools/ResultsOfTGenerator/Program.cs b/src/Http/Http.Results/tools/ResultsOfTGenerator/Program.cs index 7cbdc2559648..9bd9ad0efdd5 100644 --- a/src/Http/Http.Results/tools/ResultsOfTGenerator/Program.cs +++ b/src/Http/Http.Results/tools/ResultsOfTGenerator/Program.cs @@ -74,43 +74,43 @@ void GenerateClassFile(string classFilePath) // Type arg contraints for (int j = 1; j <= i; j++) { - writer.Write($" where {typeArgName}{j} : IResult"); + writer.WriteIndent($"where {typeArgName}{j} : IResult"); if (j != i) { - writer.Write(Environment.NewLine); + writer.WriteLine(); } } writer.WriteLine(); writer.WriteLine("{"); // Ctor - writer.WriteLine(" // Use implicit cast operators to create an instance"); - writer.WriteLine($" private {className}(IResult activeResult)"); - writer.WriteLine(" {"); - writer.WriteLine(" Result = activeResult;"); - writer.WriteLine(" }"); + writer.WriteIndentedLine("// Use implicit cast operators to create an instance"); + writer.WriteIndentedLine($"private {className}(IResult activeResult)"); + writer.WriteIndentedLine("{"); + writer.WriteIndentedLine(2, "Result = activeResult;"); + writer.WriteIndentedLine("}"); writer.WriteLine(); // Result property - writer.WriteLine(" /// "); - writer.WriteLine($" /// Gets the actual returned by the route handler delegate."); - writer.WriteLine(" /// "); - writer.WriteLine(" public IResult Result { get; }"); + writer.WriteIndentedLine("/// "); + writer.WriteIndentedLine($"/// Gets the actual returned by the route handler delegate."); + writer.WriteIndentedLine("/// "); + writer.WriteIndentedLine("public IResult Result { get; }"); writer.WriteLine(); // ExecuteAsync method - writer.WriteLine(" /// "); - writer.WriteLine(" public async Task ExecuteAsync(HttpContext httpContext)"); - writer.WriteLine(" {"); - writer.WriteLine(" ArgumentNullException.ThrowIfNull(httpContext, nameof(httpContext));"); + writer.WriteIndentedLine("/// "); + writer.WriteIndentedLine("public async Task ExecuteAsync(HttpContext httpContext)"); + writer.WriteIndentedLine("{"); + writer.WriteIndentedLine(2, "ArgumentNullException.ThrowIfNull(httpContext, nameof(httpContext));"); writer.WriteLine(); - writer.WriteLine(" if (Result is null)"); - writer.WriteLine(" {"); - writer.WriteLine(" throw new InvalidOperationException(\"The IResult assigned to the Result property must not be null.\");"); - writer.WriteLine(" }"); + writer.WriteIndentedLine(2, "if (Result is null)"); + writer.WriteIndentedLine(2, "{"); + writer.WriteIndentedLine(3, "throw new InvalidOperationException(\"The IResult assigned to the Result property must not be null.\");"); + writer.WriteIndentedLine(2, "}"); writer.WriteLine(); - writer.WriteLine(" await Result.ExecuteAsync(httpContext);"); - writer.WriteLine(" }"); + writer.WriteIndentedLine(2, "await Result.ExecuteAsync(httpContext);"); + writer.WriteIndentedLine("}"); writer.WriteLine(); // Implicit converter operators @@ -127,11 +127,11 @@ void GenerateClassFile(string classFilePath) for (int j = 1; j <= i; j++) { - writer.WriteLine(" /// "); - writer.WriteLine($" /// Converts the to a ."); - writer.WriteLine(" /// "); - writer.WriteLine(" /// The result."); - writer.WriteLine($" public static implicit operator {className}<{typeArgsList}>({typeArgName}{j} result) => new(result);"); + writer.WriteIndentedLine("/// "); + writer.WriteIndentedLine($"/// Converts the to a ."); + writer.WriteIndentedLine("/// "); + writer.WriteIndentedLine("/// The result."); + writer.WriteIndentedLine($"public static implicit operator {className}<{typeArgsList}>({typeArgName}{j} result) => new(result);"); if (i != j) { @@ -565,7 +565,7 @@ public static void WriteIndent(this StreamWriter writer, string? value = null) public static void WriteIndent(this StreamWriter writer, int count, string? value = null) { - for (int i = 1; i <= count; i++) + for (var i = 1; i <= count; i++) { writer.Write(" "); } From e457a0b41528c8c4f6514d81395ad5ab5afeba6c Mon Sep 17 00:00:00 2001 From: Damian Edwards Date: Thu, 31 Mar 2022 18:13:39 -0700 Subject: [PATCH 13/19] Fix build error --- .../tools/ResultsOfTGenerator/Program.cs | 23 +++++++++++++++---- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/src/Http/Http.Results/tools/ResultsOfTGenerator/Program.cs b/src/Http/Http.Results/tools/ResultsOfTGenerator/Program.cs index 9bd9ad0efdd5..9d3b988e8497 100644 --- a/src/Http/Http.Results/tools/ResultsOfTGenerator/Program.cs +++ b/src/Http/Http.Results/tools/ResultsOfTGenerator/Program.cs @@ -1,6 +1,7 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. +using System.Globalization; using System.Text; var className = "Results"; @@ -35,7 +36,10 @@ void GenerateClassFile(string classFilePath) for (int i = 1; i <= typeArgCount; i++) { // Skip first as we don't have a Results class - if (i == 1) continue; + if (i == 1) + { + continue; + } // Class summary doc writer.WriteLine("/// "); @@ -117,7 +121,7 @@ void GenerateClassFile(string classFilePath) var sb = new StringBuilder(); for (int j = 1; j <= i; j++) { - sb.Append($"{typeArgName}{j}"); + sb.AppendFormat(CultureInfo.InvariantCulture, "{0}{1}", typeArgName, j); if (j != i) { sb.Append(", "); @@ -153,7 +157,10 @@ void GenerateClassFile(string classFilePath) var file = new FileInfo(classFilePath); - if (!file.Exists) throw new FileNotFoundException(classFilePath); + if (!file.Exists) + { + throw new FileNotFoundException(classFilePath); + } Console.WriteLine(); Console.WriteLine($"{file.Length:N0} bytes written to {file.FullName} successfully!"); @@ -191,7 +198,10 @@ void GenerateTestFiles(string testFilePath) for (int i = 1; i <= typeArgCount; i++) { // Skip first as we don't have a Results class - if (i == 1) continue; + if (i == 1) + { + continue; + } GenerateTest_Result_IsAssignedResult(writer, i); GenerateTest_ExecuteResult_ExecutesAssignedResult(writer, i); @@ -221,7 +231,10 @@ void GenerateTestFiles(string testFilePath) var file = new FileInfo(testFilePath); - if (!file.Exists) throw new FileNotFoundException(testFilePath); + if (!file.Exists) + { + throw new FileNotFoundException(testFilePath); + } Console.WriteLine(); Console.WriteLine($"{file.Length:N0} bytes written to {file.FullName} successfully!"); From b19bf91418f5032ea2a4730c3f943c91c2fd8d2d Mon Sep 17 00:00:00 2001 From: Damian Edwards Date: Fri, 1 Apr 2022 10:03:12 -0700 Subject: [PATCH 14/19] PR feedback --- src/Http/samples/MinimalSample/Program.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Http/samples/MinimalSample/Program.cs b/src/Http/samples/MinimalSample/Program.cs index 6961e5bac6a4..1b9b249a1d57 100644 --- a/src/Http/samples/MinimalSample/Program.cs +++ b/src/Http/samples/MinimalSample/Program.cs @@ -19,7 +19,7 @@ string SayHello(string name) => $"Hello, {name}!"; app.MapGet("/hello/{name}", SayHello); -app.MapGet("/null-result", () => (IResult)null); +app.MapGet("/null-result", IResult () => null); app.MapGet("/todo/{id}", Results (int id) => { From ccbc5358ba822853d68d3ad24ef43c4b34d09568 Mon Sep 17 00:00:00 2001 From: Damian Edwards Date: Wed, 6 Apr 2022 14:22:21 -0700 Subject: [PATCH 15/19] Implement API review feedback + more tests --- src/Http/Http.Results/src/ResultsOfT.cs | 1280 ------------ .../test/ResultsOfTTests.Generated.cs | 1707 ++++++++--------- .../tools/ResultsOfTGenerator/Program.cs | 247 ++- 3 files changed, 1076 insertions(+), 2158 deletions(-) diff --git a/src/Http/Http.Results/src/ResultsOfT.cs b/src/Http/Http.Results/src/ResultsOfT.cs index 45382eccb07e..75488be1c701 100644 --- a/src/Http/Http.Results/src/ResultsOfT.cs +++ b/src/Http/Http.Results/src/ResultsOfT.cs @@ -343,1283 +343,3 @@ public async Task ExecuteAsync(HttpContext httpContext) /// The result. public static implicit operator Results(TResult6 result) => new(result); } - -/// -/// An that could be one of seven different types. On execution will -/// execute the underlying instance that was actually returned by the HTTP endpoint. -/// -/// -/// An instance of this type cannot be created explicitly. Use the implicit cast operators to create an instance -/// from an instance of one of the declared type arguments, e.g. -/// Results<OkObjectHttpResult, ProblemHttpResult> result = Results.Ok(); -/// -/// The first result type. -/// The second result type. -/// The third result type. -/// The fourth result type. -/// The fifth result type. -/// The sixth result type. -/// The seventh result type. -public sealed class Results : IResult - where TResult1 : IResult - where TResult2 : IResult - where TResult3 : IResult - where TResult4 : IResult - where TResult5 : IResult - where TResult6 : IResult - where TResult7 : IResult -{ - // Use implicit cast operators to create an instance - private Results(IResult activeResult) - { - Result = activeResult; - } - - /// - /// Gets the actual returned by the route handler delegate. - /// - public IResult Result { get; } - - /// - public async Task ExecuteAsync(HttpContext httpContext) - { - ArgumentNullException.ThrowIfNull(httpContext, nameof(httpContext)); - - if (Result is null) - { - throw new InvalidOperationException("The IResult assigned to the Result property must not be null."); - } - - await Result.ExecuteAsync(httpContext); - } - - /// - /// Converts the to a . - /// - /// The result. - public static implicit operator Results(TResult1 result) => new(result); - - /// - /// Converts the to a . - /// - /// The result. - public static implicit operator Results(TResult2 result) => new(result); - - /// - /// Converts the to a . - /// - /// The result. - public static implicit operator Results(TResult3 result) => new(result); - - /// - /// Converts the to a . - /// - /// The result. - public static implicit operator Results(TResult4 result) => new(result); - - /// - /// Converts the to a . - /// - /// The result. - public static implicit operator Results(TResult5 result) => new(result); - - /// - /// Converts the to a . - /// - /// The result. - public static implicit operator Results(TResult6 result) => new(result); - - /// - /// Converts the to a . - /// - /// The result. - public static implicit operator Results(TResult7 result) => new(result); -} - -/// -/// An that could be one of eight different types. On execution will -/// execute the underlying instance that was actually returned by the HTTP endpoint. -/// -/// -/// An instance of this type cannot be created explicitly. Use the implicit cast operators to create an instance -/// from an instance of one of the declared type arguments, e.g. -/// Results<OkObjectHttpResult, ProblemHttpResult> result = Results.Ok(); -/// -/// The first result type. -/// The second result type. -/// The third result type. -/// The fourth result type. -/// The fifth result type. -/// The sixth result type. -/// The seventh result type. -/// The eighth result type. -public sealed class Results : IResult - where TResult1 : IResult - where TResult2 : IResult - where TResult3 : IResult - where TResult4 : IResult - where TResult5 : IResult - where TResult6 : IResult - where TResult7 : IResult - where TResult8 : IResult -{ - // Use implicit cast operators to create an instance - private Results(IResult activeResult) - { - Result = activeResult; - } - - /// - /// Gets the actual returned by the route handler delegate. - /// - public IResult Result { get; } - - /// - public async Task ExecuteAsync(HttpContext httpContext) - { - ArgumentNullException.ThrowIfNull(httpContext, nameof(httpContext)); - - if (Result is null) - { - throw new InvalidOperationException("The IResult assigned to the Result property must not be null."); - } - - await Result.ExecuteAsync(httpContext); - } - - /// - /// Converts the to a . - /// - /// The result. - public static implicit operator Results(TResult1 result) => new(result); - - /// - /// Converts the to a . - /// - /// The result. - public static implicit operator Results(TResult2 result) => new(result); - - /// - /// Converts the to a . - /// - /// The result. - public static implicit operator Results(TResult3 result) => new(result); - - /// - /// Converts the to a . - /// - /// The result. - public static implicit operator Results(TResult4 result) => new(result); - - /// - /// Converts the to a . - /// - /// The result. - public static implicit operator Results(TResult5 result) => new(result); - - /// - /// Converts the to a . - /// - /// The result. - public static implicit operator Results(TResult6 result) => new(result); - - /// - /// Converts the to a . - /// - /// The result. - public static implicit operator Results(TResult7 result) => new(result); - - /// - /// Converts the to a . - /// - /// The result. - public static implicit operator Results(TResult8 result) => new(result); -} - -/// -/// An that could be one of nine different types. On execution will -/// execute the underlying instance that was actually returned by the HTTP endpoint. -/// -/// -/// An instance of this type cannot be created explicitly. Use the implicit cast operators to create an instance -/// from an instance of one of the declared type arguments, e.g. -/// Results<OkObjectHttpResult, ProblemHttpResult> result = Results.Ok(); -/// -/// The first result type. -/// The second result type. -/// The third result type. -/// The fourth result type. -/// The fifth result type. -/// The sixth result type. -/// The seventh result type. -/// The eighth result type. -/// The ninth result type. -public sealed class Results : IResult - where TResult1 : IResult - where TResult2 : IResult - where TResult3 : IResult - where TResult4 : IResult - where TResult5 : IResult - where TResult6 : IResult - where TResult7 : IResult - where TResult8 : IResult - where TResult9 : IResult -{ - // Use implicit cast operators to create an instance - private Results(IResult activeResult) - { - Result = activeResult; - } - - /// - /// Gets the actual returned by the route handler delegate. - /// - public IResult Result { get; } - - /// - public async Task ExecuteAsync(HttpContext httpContext) - { - ArgumentNullException.ThrowIfNull(httpContext, nameof(httpContext)); - - if (Result is null) - { - throw new InvalidOperationException("The IResult assigned to the Result property must not be null."); - } - - await Result.ExecuteAsync(httpContext); - } - - /// - /// Converts the to a . - /// - /// The result. - public static implicit operator Results(TResult1 result) => new(result); - - /// - /// Converts the to a . - /// - /// The result. - public static implicit operator Results(TResult2 result) => new(result); - - /// - /// Converts the to a . - /// - /// The result. - public static implicit operator Results(TResult3 result) => new(result); - - /// - /// Converts the to a . - /// - /// The result. - public static implicit operator Results(TResult4 result) => new(result); - - /// - /// Converts the to a . - /// - /// The result. - public static implicit operator Results(TResult5 result) => new(result); - - /// - /// Converts the to a . - /// - /// The result. - public static implicit operator Results(TResult6 result) => new(result); - - /// - /// Converts the to a . - /// - /// The result. - public static implicit operator Results(TResult7 result) => new(result); - - /// - /// Converts the to a . - /// - /// The result. - public static implicit operator Results(TResult8 result) => new(result); - - /// - /// Converts the to a . - /// - /// The result. - public static implicit operator Results(TResult9 result) => new(result); -} - -/// -/// An that could be one of ten different types. On execution will -/// execute the underlying instance that was actually returned by the HTTP endpoint. -/// -/// -/// An instance of this type cannot be created explicitly. Use the implicit cast operators to create an instance -/// from an instance of one of the declared type arguments, e.g. -/// Results<OkObjectHttpResult, ProblemHttpResult> result = Results.Ok(); -/// -/// The first result type. -/// The second result type. -/// The third result type. -/// The fourth result type. -/// The fifth result type. -/// The sixth result type. -/// The seventh result type. -/// The eighth result type. -/// The ninth result type. -/// The tenth result type. -public sealed class Results : IResult - where TResult1 : IResult - where TResult2 : IResult - where TResult3 : IResult - where TResult4 : IResult - where TResult5 : IResult - where TResult6 : IResult - where TResult7 : IResult - where TResult8 : IResult - where TResult9 : IResult - where TResult10 : IResult -{ - // Use implicit cast operators to create an instance - private Results(IResult activeResult) - { - Result = activeResult; - } - - /// - /// Gets the actual returned by the route handler delegate. - /// - public IResult Result { get; } - - /// - public async Task ExecuteAsync(HttpContext httpContext) - { - ArgumentNullException.ThrowIfNull(httpContext, nameof(httpContext)); - - if (Result is null) - { - throw new InvalidOperationException("The IResult assigned to the Result property must not be null."); - } - - await Result.ExecuteAsync(httpContext); - } - - /// - /// Converts the to a . - /// - /// The result. - public static implicit operator Results(TResult1 result) => new(result); - - /// - /// Converts the to a . - /// - /// The result. - public static implicit operator Results(TResult2 result) => new(result); - - /// - /// Converts the to a . - /// - /// The result. - public static implicit operator Results(TResult3 result) => new(result); - - /// - /// Converts the to a . - /// - /// The result. - public static implicit operator Results(TResult4 result) => new(result); - - /// - /// Converts the to a . - /// - /// The result. - public static implicit operator Results(TResult5 result) => new(result); - - /// - /// Converts the to a . - /// - /// The result. - public static implicit operator Results(TResult6 result) => new(result); - - /// - /// Converts the to a . - /// - /// The result. - public static implicit operator Results(TResult7 result) => new(result); - - /// - /// Converts the to a . - /// - /// The result. - public static implicit operator Results(TResult8 result) => new(result); - - /// - /// Converts the to a . - /// - /// The result. - public static implicit operator Results(TResult9 result) => new(result); - - /// - /// Converts the to a . - /// - /// The result. - public static implicit operator Results(TResult10 result) => new(result); -} - -/// -/// An that could be one of eleven different types. On execution will -/// execute the underlying instance that was actually returned by the HTTP endpoint. -/// -/// -/// An instance of this type cannot be created explicitly. Use the implicit cast operators to create an instance -/// from an instance of one of the declared type arguments, e.g. -/// Results<OkObjectHttpResult, ProblemHttpResult> result = Results.Ok(); -/// -/// The first result type. -/// The second result type. -/// The third result type. -/// The fourth result type. -/// The fifth result type. -/// The sixth result type. -/// The seventh result type. -/// The eighth result type. -/// The ninth result type. -/// The tenth result type. -/// The eleventh result type. -public sealed class Results : IResult - where TResult1 : IResult - where TResult2 : IResult - where TResult3 : IResult - where TResult4 : IResult - where TResult5 : IResult - where TResult6 : IResult - where TResult7 : IResult - where TResult8 : IResult - where TResult9 : IResult - where TResult10 : IResult - where TResult11 : IResult -{ - // Use implicit cast operators to create an instance - private Results(IResult activeResult) - { - Result = activeResult; - } - - /// - /// Gets the actual returned by the route handler delegate. - /// - public IResult Result { get; } - - /// - public async Task ExecuteAsync(HttpContext httpContext) - { - ArgumentNullException.ThrowIfNull(httpContext, nameof(httpContext)); - - if (Result is null) - { - throw new InvalidOperationException("The IResult assigned to the Result property must not be null."); - } - - await Result.ExecuteAsync(httpContext); - } - - /// - /// Converts the to a . - /// - /// The result. - public static implicit operator Results(TResult1 result) => new(result); - - /// - /// Converts the to a . - /// - /// The result. - public static implicit operator Results(TResult2 result) => new(result); - - /// - /// Converts the to a . - /// - /// The result. - public static implicit operator Results(TResult3 result) => new(result); - - /// - /// Converts the to a . - /// - /// The result. - public static implicit operator Results(TResult4 result) => new(result); - - /// - /// Converts the to a . - /// - /// The result. - public static implicit operator Results(TResult5 result) => new(result); - - /// - /// Converts the to a . - /// - /// The result. - public static implicit operator Results(TResult6 result) => new(result); - - /// - /// Converts the to a . - /// - /// The result. - public static implicit operator Results(TResult7 result) => new(result); - - /// - /// Converts the to a . - /// - /// The result. - public static implicit operator Results(TResult8 result) => new(result); - - /// - /// Converts the to a . - /// - /// The result. - public static implicit operator Results(TResult9 result) => new(result); - - /// - /// Converts the to a . - /// - /// The result. - public static implicit operator Results(TResult10 result) => new(result); - - /// - /// Converts the to a . - /// - /// The result. - public static implicit operator Results(TResult11 result) => new(result); -} - -/// -/// An that could be one of twelve different types. On execution will -/// execute the underlying instance that was actually returned by the HTTP endpoint. -/// -/// -/// An instance of this type cannot be created explicitly. Use the implicit cast operators to create an instance -/// from an instance of one of the declared type arguments, e.g. -/// Results<OkObjectHttpResult, ProblemHttpResult> result = Results.Ok(); -/// -/// The first result type. -/// The second result type. -/// The third result type. -/// The fourth result type. -/// The fifth result type. -/// The sixth result type. -/// The seventh result type. -/// The eighth result type. -/// The ninth result type. -/// The tenth result type. -/// The eleventh result type. -/// The twelfth result type. -public sealed class Results : IResult - where TResult1 : IResult - where TResult2 : IResult - where TResult3 : IResult - where TResult4 : IResult - where TResult5 : IResult - where TResult6 : IResult - where TResult7 : IResult - where TResult8 : IResult - where TResult9 : IResult - where TResult10 : IResult - where TResult11 : IResult - where TResult12 : IResult -{ - // Use implicit cast operators to create an instance - private Results(IResult activeResult) - { - Result = activeResult; - } - - /// - /// Gets the actual returned by the route handler delegate. - /// - public IResult Result { get; } - - /// - public async Task ExecuteAsync(HttpContext httpContext) - { - ArgumentNullException.ThrowIfNull(httpContext, nameof(httpContext)); - - if (Result is null) - { - throw new InvalidOperationException("The IResult assigned to the Result property must not be null."); - } - - await Result.ExecuteAsync(httpContext); - } - - /// - /// Converts the to a . - /// - /// The result. - public static implicit operator Results(TResult1 result) => new(result); - - /// - /// Converts the to a . - /// - /// The result. - public static implicit operator Results(TResult2 result) => new(result); - - /// - /// Converts the to a . - /// - /// The result. - public static implicit operator Results(TResult3 result) => new(result); - - /// - /// Converts the to a . - /// - /// The result. - public static implicit operator Results(TResult4 result) => new(result); - - /// - /// Converts the to a . - /// - /// The result. - public static implicit operator Results(TResult5 result) => new(result); - - /// - /// Converts the to a . - /// - /// The result. - public static implicit operator Results(TResult6 result) => new(result); - - /// - /// Converts the to a . - /// - /// The result. - public static implicit operator Results(TResult7 result) => new(result); - - /// - /// Converts the to a . - /// - /// The result. - public static implicit operator Results(TResult8 result) => new(result); - - /// - /// Converts the to a . - /// - /// The result. - public static implicit operator Results(TResult9 result) => new(result); - - /// - /// Converts the to a . - /// - /// The result. - public static implicit operator Results(TResult10 result) => new(result); - - /// - /// Converts the to a . - /// - /// The result. - public static implicit operator Results(TResult11 result) => new(result); - - /// - /// Converts the to a . - /// - /// The result. - public static implicit operator Results(TResult12 result) => new(result); -} - -/// -/// An that could be one of thirteen different types. On execution will -/// execute the underlying instance that was actually returned by the HTTP endpoint. -/// -/// -/// An instance of this type cannot be created explicitly. Use the implicit cast operators to create an instance -/// from an instance of one of the declared type arguments, e.g. -/// Results<OkObjectHttpResult, ProblemHttpResult> result = Results.Ok(); -/// -/// The first result type. -/// The second result type. -/// The third result type. -/// The fourth result type. -/// The fifth result type. -/// The sixth result type. -/// The seventh result type. -/// The eighth result type. -/// The ninth result type. -/// The tenth result type. -/// The eleventh result type. -/// The twelfth result type. -/// The thirteenth result type. -public sealed class Results : IResult - where TResult1 : IResult - where TResult2 : IResult - where TResult3 : IResult - where TResult4 : IResult - where TResult5 : IResult - where TResult6 : IResult - where TResult7 : IResult - where TResult8 : IResult - where TResult9 : IResult - where TResult10 : IResult - where TResult11 : IResult - where TResult12 : IResult - where TResult13 : IResult -{ - // Use implicit cast operators to create an instance - private Results(IResult activeResult) - { - Result = activeResult; - } - - /// - /// Gets the actual returned by the route handler delegate. - /// - public IResult Result { get; } - - /// - public async Task ExecuteAsync(HttpContext httpContext) - { - ArgumentNullException.ThrowIfNull(httpContext, nameof(httpContext)); - - if (Result is null) - { - throw new InvalidOperationException("The IResult assigned to the Result property must not be null."); - } - - await Result.ExecuteAsync(httpContext); - } - - /// - /// Converts the to a . - /// - /// The result. - public static implicit operator Results(TResult1 result) => new(result); - - /// - /// Converts the to a . - /// - /// The result. - public static implicit operator Results(TResult2 result) => new(result); - - /// - /// Converts the to a . - /// - /// The result. - public static implicit operator Results(TResult3 result) => new(result); - - /// - /// Converts the to a . - /// - /// The result. - public static implicit operator Results(TResult4 result) => new(result); - - /// - /// Converts the to a . - /// - /// The result. - public static implicit operator Results(TResult5 result) => new(result); - - /// - /// Converts the to a . - /// - /// The result. - public static implicit operator Results(TResult6 result) => new(result); - - /// - /// Converts the to a . - /// - /// The result. - public static implicit operator Results(TResult7 result) => new(result); - - /// - /// Converts the to a . - /// - /// The result. - public static implicit operator Results(TResult8 result) => new(result); - - /// - /// Converts the to a . - /// - /// The result. - public static implicit operator Results(TResult9 result) => new(result); - - /// - /// Converts the to a . - /// - /// The result. - public static implicit operator Results(TResult10 result) => new(result); - - /// - /// Converts the to a . - /// - /// The result. - public static implicit operator Results(TResult11 result) => new(result); - - /// - /// Converts the to a . - /// - /// The result. - public static implicit operator Results(TResult12 result) => new(result); - - /// - /// Converts the to a . - /// - /// The result. - public static implicit operator Results(TResult13 result) => new(result); -} - -/// -/// An that could be one of fourteen different types. On execution will -/// execute the underlying instance that was actually returned by the HTTP endpoint. -/// -/// -/// An instance of this type cannot be created explicitly. Use the implicit cast operators to create an instance -/// from an instance of one of the declared type arguments, e.g. -/// Results<OkObjectHttpResult, ProblemHttpResult> result = Results.Ok(); -/// -/// The first result type. -/// The second result type. -/// The third result type. -/// The fourth result type. -/// The fifth result type. -/// The sixth result type. -/// The seventh result type. -/// The eighth result type. -/// The ninth result type. -/// The tenth result type. -/// The eleventh result type. -/// The twelfth result type. -/// The thirteenth result type. -/// The fourteenth result type. -public sealed class Results : IResult - where TResult1 : IResult - where TResult2 : IResult - where TResult3 : IResult - where TResult4 : IResult - where TResult5 : IResult - where TResult6 : IResult - where TResult7 : IResult - where TResult8 : IResult - where TResult9 : IResult - where TResult10 : IResult - where TResult11 : IResult - where TResult12 : IResult - where TResult13 : IResult - where TResult14 : IResult -{ - // Use implicit cast operators to create an instance - private Results(IResult activeResult) - { - Result = activeResult; - } - - /// - /// Gets the actual returned by the route handler delegate. - /// - public IResult Result { get; } - - /// - public async Task ExecuteAsync(HttpContext httpContext) - { - ArgumentNullException.ThrowIfNull(httpContext, nameof(httpContext)); - - if (Result is null) - { - throw new InvalidOperationException("The IResult assigned to the Result property must not be null."); - } - - await Result.ExecuteAsync(httpContext); - } - - /// - /// Converts the to a . - /// - /// The result. - public static implicit operator Results(TResult1 result) => new(result); - - /// - /// Converts the to a . - /// - /// The result. - public static implicit operator Results(TResult2 result) => new(result); - - /// - /// Converts the to a . - /// - /// The result. - public static implicit operator Results(TResult3 result) => new(result); - - /// - /// Converts the to a . - /// - /// The result. - public static implicit operator Results(TResult4 result) => new(result); - - /// - /// Converts the to a . - /// - /// The result. - public static implicit operator Results(TResult5 result) => new(result); - - /// - /// Converts the to a . - /// - /// The result. - public static implicit operator Results(TResult6 result) => new(result); - - /// - /// Converts the to a . - /// - /// The result. - public static implicit operator Results(TResult7 result) => new(result); - - /// - /// Converts the to a . - /// - /// The result. - public static implicit operator Results(TResult8 result) => new(result); - - /// - /// Converts the to a . - /// - /// The result. - public static implicit operator Results(TResult9 result) => new(result); - - /// - /// Converts the to a . - /// - /// The result. - public static implicit operator Results(TResult10 result) => new(result); - - /// - /// Converts the to a . - /// - /// The result. - public static implicit operator Results(TResult11 result) => new(result); - - /// - /// Converts the to a . - /// - /// The result. - public static implicit operator Results(TResult12 result) => new(result); - - /// - /// Converts the to a . - /// - /// The result. - public static implicit operator Results(TResult13 result) => new(result); - - /// - /// Converts the to a . - /// - /// The result. - public static implicit operator Results(TResult14 result) => new(result); -} - -/// -/// An that could be one of fifteen different types. On execution will -/// execute the underlying instance that was actually returned by the HTTP endpoint. -/// -/// -/// An instance of this type cannot be created explicitly. Use the implicit cast operators to create an instance -/// from an instance of one of the declared type arguments, e.g. -/// Results<OkObjectHttpResult, ProblemHttpResult> result = Results.Ok(); -/// -/// The first result type. -/// The second result type. -/// The third result type. -/// The fourth result type. -/// The fifth result type. -/// The sixth result type. -/// The seventh result type. -/// The eighth result type. -/// The ninth result type. -/// The tenth result type. -/// The eleventh result type. -/// The twelfth result type. -/// The thirteenth result type. -/// The fourteenth result type. -/// The fifteenth result type. -public sealed class Results : IResult - where TResult1 : IResult - where TResult2 : IResult - where TResult3 : IResult - where TResult4 : IResult - where TResult5 : IResult - where TResult6 : IResult - where TResult7 : IResult - where TResult8 : IResult - where TResult9 : IResult - where TResult10 : IResult - where TResult11 : IResult - where TResult12 : IResult - where TResult13 : IResult - where TResult14 : IResult - where TResult15 : IResult -{ - // Use implicit cast operators to create an instance - private Results(IResult activeResult) - { - Result = activeResult; - } - - /// - /// Gets the actual returned by the route handler delegate. - /// - public IResult Result { get; } - - /// - public async Task ExecuteAsync(HttpContext httpContext) - { - ArgumentNullException.ThrowIfNull(httpContext, nameof(httpContext)); - - if (Result is null) - { - throw new InvalidOperationException("The IResult assigned to the Result property must not be null."); - } - - await Result.ExecuteAsync(httpContext); - } - - /// - /// Converts the to a . - /// - /// The result. - public static implicit operator Results(TResult1 result) => new(result); - - /// - /// Converts the to a . - /// - /// The result. - public static implicit operator Results(TResult2 result) => new(result); - - /// - /// Converts the to a . - /// - /// The result. - public static implicit operator Results(TResult3 result) => new(result); - - /// - /// Converts the to a . - /// - /// The result. - public static implicit operator Results(TResult4 result) => new(result); - - /// - /// Converts the to a . - /// - /// The result. - public static implicit operator Results(TResult5 result) => new(result); - - /// - /// Converts the to a . - /// - /// The result. - public static implicit operator Results(TResult6 result) => new(result); - - /// - /// Converts the to a . - /// - /// The result. - public static implicit operator Results(TResult7 result) => new(result); - - /// - /// Converts the to a . - /// - /// The result. - public static implicit operator Results(TResult8 result) => new(result); - - /// - /// Converts the to a . - /// - /// The result. - public static implicit operator Results(TResult9 result) => new(result); - - /// - /// Converts the to a . - /// - /// The result. - public static implicit operator Results(TResult10 result) => new(result); - - /// - /// Converts the to a . - /// - /// The result. - public static implicit operator Results(TResult11 result) => new(result); - - /// - /// Converts the to a . - /// - /// The result. - public static implicit operator Results(TResult12 result) => new(result); - - /// - /// Converts the to a . - /// - /// The result. - public static implicit operator Results(TResult13 result) => new(result); - - /// - /// Converts the to a . - /// - /// The result. - public static implicit operator Results(TResult14 result) => new(result); - - /// - /// Converts the to a . - /// - /// The result. - public static implicit operator Results(TResult15 result) => new(result); -} - -/// -/// An that could be one of sixteen different types. On execution will -/// execute the underlying instance that was actually returned by the HTTP endpoint. -/// -/// -/// An instance of this type cannot be created explicitly. Use the implicit cast operators to create an instance -/// from an instance of one of the declared type arguments, e.g. -/// Results<OkObjectHttpResult, ProblemHttpResult> result = Results.Ok(); -/// -/// The first result type. -/// The second result type. -/// The third result type. -/// The fourth result type. -/// The fifth result type. -/// The sixth result type. -/// The seventh result type. -/// The eighth result type. -/// The ninth result type. -/// The tenth result type. -/// The eleventh result type. -/// The twelfth result type. -/// The thirteenth result type. -/// The fourteenth result type. -/// The fifteenth result type. -/// The sixteenth result type. -public sealed class Results : IResult - where TResult1 : IResult - where TResult2 : IResult - where TResult3 : IResult - where TResult4 : IResult - where TResult5 : IResult - where TResult6 : IResult - where TResult7 : IResult - where TResult8 : IResult - where TResult9 : IResult - where TResult10 : IResult - where TResult11 : IResult - where TResult12 : IResult - where TResult13 : IResult - where TResult14 : IResult - where TResult15 : IResult - where TResult16 : IResult -{ - // Use implicit cast operators to create an instance - private Results(IResult activeResult) - { - Result = activeResult; - } - - /// - /// Gets the actual returned by the route handler delegate. - /// - public IResult Result { get; } - - /// - public async Task ExecuteAsync(HttpContext httpContext) - { - ArgumentNullException.ThrowIfNull(httpContext, nameof(httpContext)); - - if (Result is null) - { - throw new InvalidOperationException("The IResult assigned to the Result property must not be null."); - } - - await Result.ExecuteAsync(httpContext); - } - - /// - /// Converts the to a . - /// - /// The result. - public static implicit operator Results(TResult1 result) => new(result); - - /// - /// Converts the to a . - /// - /// The result. - public static implicit operator Results(TResult2 result) => new(result); - - /// - /// Converts the to a . - /// - /// The result. - public static implicit operator Results(TResult3 result) => new(result); - - /// - /// Converts the to a . - /// - /// The result. - public static implicit operator Results(TResult4 result) => new(result); - - /// - /// Converts the to a . - /// - /// The result. - public static implicit operator Results(TResult5 result) => new(result); - - /// - /// Converts the to a . - /// - /// The result. - public static implicit operator Results(TResult6 result) => new(result); - - /// - /// Converts the to a . - /// - /// The result. - public static implicit operator Results(TResult7 result) => new(result); - - /// - /// Converts the to a . - /// - /// The result. - public static implicit operator Results(TResult8 result) => new(result); - - /// - /// Converts the to a . - /// - /// The result. - public static implicit operator Results(TResult9 result) => new(result); - - /// - /// Converts the to a . - /// - /// The result. - public static implicit operator Results(TResult10 result) => new(result); - - /// - /// Converts the to a . - /// - /// The result. - public static implicit operator Results(TResult11 result) => new(result); - - /// - /// Converts the to a . - /// - /// The result. - public static implicit operator Results(TResult12 result) => new(result); - - /// - /// Converts the to a . - /// - /// The result. - public static implicit operator Results(TResult13 result) => new(result); - - /// - /// Converts the to a . - /// - /// The result. - public static implicit operator Results(TResult14 result) => new(result); - - /// - /// Converts the to a . - /// - /// The result. - public static implicit operator Results(TResult15 result) => new(result); - - /// - /// Converts the to a . - /// - /// The result. - public static implicit operator Results(TResult16 result) => new(result); -} diff --git a/src/Http/Http.Results/test/ResultsOfTTests.Generated.cs b/src/Http/Http.Results/test/ResultsOfTTests.Generated.cs index 07e141345f24..8347260cc355 100644 --- a/src/Http/Http.Results/test/ResultsOfTTests.Generated.cs +++ b/src/Http/Http.Results/test/ResultsOfTTests.Generated.cs @@ -14,7 +14,7 @@ public partial class ResultsOfTTests [Theory] [InlineData(1, typeof(ChecksumResult1))] [InlineData(2, typeof(ChecksumResult2))] - public void ResultsOfTResult1TResult2_Result_IsAssignedResult(int input, Type expectedResult) + public void ResultsOfTResult1TResult2_Result_IsAssignedResult(int input, Type expectedResultType) { // Arrange Results MyApi(int id) @@ -30,7 +30,7 @@ Results MyApi(int id) var result = MyApi(input); // Assert - Assert.IsType(expectedResult, result.Result); + Assert.IsType(expectedResultType, result.Result); } [Theory] @@ -54,7 +54,7 @@ Results MyApi(int checksum) await result.ExecuteAsync(httpContext); // Assert - Assert.Equal(input, httpContext.Items[result.Result]); + Assert.Equal(input, httpContext.Items[nameof(ChecksumResult.Checksum)]); } [Fact] @@ -98,41 +98,40 @@ Results MyApi() [Theory] [InlineData(1, typeof(ChecksumResult1))] [InlineData(2, typeof(ChecksumResult2))] - [InlineData(3, typeof(ChecksumResult3))] - public void ResultsOfTResult1TResult2TResult3_Result_IsAssignedResult(int input, Type expectedResult) + public async Task ResultsOfTResult1TResult2_AcceptsIResult_AsFirstTypeArg(int input, Type expectedResultType) { // Arrange - Results MyApi(int id) + Results MyApi(int id) { return id switch { - 1 => new ChecksumResult1(), - 2 => new ChecksumResult2(), - _ => new ChecksumResult3() + 1 => new ChecksumResult1(1), + _ => new ChecksumResult2(2) }; } + var httpContext = GetHttpContext(); // Act var result = MyApi(input); - + await result.ExecuteAsync(httpContext); + // Assert - Assert.IsType(expectedResult, result.Result); + Assert.IsType(expectedResultType, result.Result); + Assert.Equal(input, httpContext.Items[nameof(ChecksumResult.Checksum)]); } - + [Theory] - [InlineData(1)] - [InlineData(2)] - [InlineData(3)] - public async Task ResultsOfTResult1TResult2TResult3_ExecuteResult_ExecutesAssignedResult(int input) + [InlineData(1, typeof(ChecksumResult1))] + [InlineData(2, typeof(ChecksumResult2))] + public async Task ResultsOfTResult1TResult2_AcceptsIResult_AsSecondTypeArg(int input, Type expectedResultType) { // Arrange - Results MyApi(int checksum) + Results MyApi(int id) { - return checksum switch + return id switch { - 1 => new ChecksumResult1(checksum), - 2 => new ChecksumResult2(checksum), - _ => new ChecksumResult3(checksum) + 1 => new ChecksumResult1(1), + _ => new ChecksumResult2(2) }; } var httpContext = GetHttpContext(); @@ -140,65 +139,80 @@ Results MyApi(int checksum) // Act var result = MyApi(input); await result.ExecuteAsync(httpContext); - + // Assert - Assert.Equal(input, httpContext.Items[result.Result]); + Assert.IsType(expectedResultType, result.Result); + Assert.Equal(input, httpContext.Items[nameof(ChecksumResult.Checksum)]); } - - [Fact] - public void ResultsOfTResult1TResult2TResult3_Throws_ArgumentNullException_WhenHttpContextIsNull() + + [Theory] + [InlineData(1, typeof(Results))] + [InlineData(2, typeof(Results))] + [InlineData(3, typeof(ChecksumResult3))] + public async Task ResultsOfTResult1TResult2_AcceptsNestedResultsOfT_AsFirstTypeArg(int input, Type expectedResultType) { // Arrange - Results MyApi() + Results, ChecksumResult3> MyApi(int id) { - return new ChecksumResult1(1); + return id switch + { + 1 => (Results)new ChecksumResult1(1), + 2 => (Results)new ChecksumResult2(2), + _ => new ChecksumResult3(3) + }; } - HttpContext httpContext = null; - - // Act & Assert - var result = MyApi(); + var httpContext = GetHttpContext(); + + // Act + var result = MyApi(input); + await result.ExecuteAsync(httpContext); - Assert.ThrowsAsync(async () => - { - await result.ExecuteAsync(httpContext); - }); + // Assert + Assert.IsType(expectedResultType, result.Result); + Assert.Equal(input, httpContext.Items[nameof(ChecksumResult.Checksum)]); } - [Fact] - public void ResultsOfTResult1TResult2TResult3_Throws_InvalidOperationException_WhenResultIsNull() + [Theory] + [InlineData(1, typeof(Results))] + [InlineData(2, typeof(Results))] + [InlineData(3, typeof(ChecksumResult3))] + public async Task ResultsOfTResult1TResult2_AcceptsNestedResultsOfT_AsSecondTypeArg(int input, Type expectedResultType) { // Arrange - Results MyApi() + Results, ChecksumResult3> MyApi(int id) { - return new ChecksumResult1(1); + return id switch + { + 1 => (Results)new ChecksumResult1(1), + 2 => (Results)new ChecksumResult2(2), + _ => new ChecksumResult3(3) + }; } var httpContext = GetHttpContext(); + + // Act + var result = MyApi(input); + await result.ExecuteAsync(httpContext); - // Act & Assert - var result = MyApi(); - - Assert.ThrowsAsync(async () => - { - await result.ExecuteAsync(httpContext); - }); + // Assert + Assert.IsType(expectedResultType, result.Result); + Assert.Equal(input, httpContext.Items[nameof(ChecksumResult.Checksum)]); } [Theory] [InlineData(1, typeof(ChecksumResult1))] [InlineData(2, typeof(ChecksumResult2))] [InlineData(3, typeof(ChecksumResult3))] - [InlineData(4, typeof(ChecksumResult4))] - public void ResultsOfTResult1TResult2TResult3TResult4_Result_IsAssignedResult(int input, Type expectedResult) + public void ResultsOfTResult1TResult2TResult3_Result_IsAssignedResult(int input, Type expectedResultType) { // Arrange - Results MyApi(int id) + Results MyApi(int id) { return id switch { 1 => new ChecksumResult1(), 2 => new ChecksumResult2(), - 3 => new ChecksumResult3(), - _ => new ChecksumResult4() + _ => new ChecksumResult3() }; } @@ -206,25 +220,23 @@ Results MyAp var result = MyApi(input); // Assert - Assert.IsType(expectedResult, result.Result); + Assert.IsType(expectedResultType, result.Result); } [Theory] [InlineData(1)] [InlineData(2)] [InlineData(3)] - [InlineData(4)] - public async Task ResultsOfTResult1TResult2TResult3TResult4_ExecuteResult_ExecutesAssignedResult(int input) + public async Task ResultsOfTResult1TResult2TResult3_ExecuteResult_ExecutesAssignedResult(int input) { // Arrange - Results MyApi(int checksum) + Results MyApi(int checksum) { return checksum switch { 1 => new ChecksumResult1(checksum), 2 => new ChecksumResult2(checksum), - 3 => new ChecksumResult3(checksum), - _ => new ChecksumResult4(checksum) + _ => new ChecksumResult3(checksum) }; } var httpContext = GetHttpContext(); @@ -234,11 +246,11 @@ Results MyAp await result.ExecuteAsync(httpContext); // Assert - Assert.Equal(input, httpContext.Items[result.Result]); + Assert.Equal(input, httpContext.Items[nameof(ChecksumResult.Checksum)]); } [Fact] - public void ResultsOfTResult1TResult2TResult3TResult4_Throws_ArgumentNullException_WhenHttpContextIsNull() + public void ResultsOfTResult1TResult2TResult3_Throws_ArgumentNullException_WhenHttpContextIsNull() { // Arrange Results MyApi() @@ -257,7 +269,7 @@ Results MyApi() } [Fact] - public void ResultsOfTResult1TResult2TResult3TResult4_Throws_InvalidOperationException_WhenResultIsNull() + public void ResultsOfTResult1TResult2TResult3_Throws_InvalidOperationException_WhenResultIsNull() { // Arrange Results MyApi() @@ -279,48 +291,43 @@ Results MyApi() [InlineData(1, typeof(ChecksumResult1))] [InlineData(2, typeof(ChecksumResult2))] [InlineData(3, typeof(ChecksumResult3))] - [InlineData(4, typeof(ChecksumResult4))] - [InlineData(5, typeof(ChecksumResult5))] - public void ResultsOfTResult1TResult2TResult3TResult4TResult5_Result_IsAssignedResult(int input, Type expectedResult) + public async Task ResultsOfTResult1TResult2TResult3_AcceptsIResult_AsFirstTypeArg(int input, Type expectedResultType) { // Arrange - Results MyApi(int id) + Results MyApi(int id) { return id switch { - 1 => new ChecksumResult1(), - 2 => new ChecksumResult2(), - 3 => new ChecksumResult3(), - 4 => new ChecksumResult4(), - _ => new ChecksumResult5() + 1 => new ChecksumResult1(1), + 2 => new ChecksumResult2(2), + _ => new ChecksumResult3(3) }; } + var httpContext = GetHttpContext(); // Act var result = MyApi(input); - + await result.ExecuteAsync(httpContext); + // Assert - Assert.IsType(expectedResult, result.Result); + Assert.IsType(expectedResultType, result.Result); + Assert.Equal(input, httpContext.Items[nameof(ChecksumResult.Checksum)]); } - + [Theory] - [InlineData(1)] - [InlineData(2)] - [InlineData(3)] - [InlineData(4)] - [InlineData(5)] - public async Task ResultsOfTResult1TResult2TResult3TResult4TResult5_ExecuteResult_ExecutesAssignedResult(int input) + [InlineData(1, typeof(ChecksumResult1))] + [InlineData(2, typeof(ChecksumResult2))] + [InlineData(3, typeof(ChecksumResult3))] + public async Task ResultsOfTResult1TResult2TResult3_AcceptsIResult_AsSecondTypeArg(int input, Type expectedResultType) { // Arrange - Results MyApi(int checksum) + Results MyApi(int id) { - return checksum switch + return id switch { - 1 => new ChecksumResult1(checksum), - 2 => new ChecksumResult2(checksum), - 3 => new ChecksumResult3(checksum), - 4 => new ChecksumResult4(checksum), - _ => new ChecksumResult5(checksum) + 1 => new ChecksumResult1(1), + 2 => new ChecksumResult2(2), + _ => new ChecksumResult3(3) }; } var httpContext = GetHttpContext(); @@ -328,47 +335,124 @@ Results MyApi() + Results MyApi(int id) { - return new ChecksumResult1(1); + return id switch + { + 1 => new ChecksumResult1(1), + 2 => new ChecksumResult2(2), + _ => new ChecksumResult3(3) + }; } - HttpContext httpContext = null; - - // Act & Assert - var result = MyApi(); + var httpContext = GetHttpContext(); + + // Act + var result = MyApi(input); + await result.ExecuteAsync(httpContext); - Assert.ThrowsAsync(async () => - { - await result.ExecuteAsync(httpContext); - }); + // Assert + Assert.IsType(expectedResultType, result.Result); + Assert.Equal(input, httpContext.Items[nameof(ChecksumResult.Checksum)]); } - [Fact] - public void ResultsOfTResult1TResult2TResult3TResult4TResult5_Throws_InvalidOperationException_WhenResultIsNull() + [Theory] + [InlineData(1, typeof(Results))] + [InlineData(2, typeof(Results))] + [InlineData(3, typeof(Results))] + [InlineData(4, typeof(ChecksumResult4))] + public async Task ResultsOfTResult1TResult2TResult3_AcceptsNestedResultsOfT_AsFirstTypeArg(int input, Type expectedResultType) { // Arrange - Results MyApi() + Results, ChecksumResult4> MyApi(int id) { - return new ChecksumResult1(1); + return id switch + { + 1 => (Results)new ChecksumResult1(1), + 2 => (Results)new ChecksumResult2(2), + 3 => (Results)new ChecksumResult3(3), + _ => new ChecksumResult4(4) + }; } var httpContext = GetHttpContext(); + + // Act + var result = MyApi(input); + await result.ExecuteAsync(httpContext); - // Act & Assert - var result = MyApi(); + // Assert + Assert.IsType(expectedResultType, result.Result); + Assert.Equal(input, httpContext.Items[nameof(ChecksumResult.Checksum)]); + } + + [Theory] + [InlineData(1, typeof(Results))] + [InlineData(2, typeof(Results))] + [InlineData(3, typeof(Results))] + [InlineData(4, typeof(ChecksumResult4))] + public async Task ResultsOfTResult1TResult2TResult3_AcceptsNestedResultsOfT_AsSecondTypeArg(int input, Type expectedResultType) + { + // Arrange + Results, ChecksumResult4> MyApi(int id) + { + return id switch + { + 1 => (Results)new ChecksumResult1(1), + 2 => (Results)new ChecksumResult2(2), + 3 => (Results)new ChecksumResult3(3), + _ => new ChecksumResult4(4) + }; + } + var httpContext = GetHttpContext(); + + // Act + var result = MyApi(input); + await result.ExecuteAsync(httpContext); - Assert.ThrowsAsync(async () => + // Assert + Assert.IsType(expectedResultType, result.Result); + Assert.Equal(input, httpContext.Items[nameof(ChecksumResult.Checksum)]); + } + + [Theory] + [InlineData(1, typeof(Results))] + [InlineData(2, typeof(Results))] + [InlineData(3, typeof(Results))] + [InlineData(4, typeof(ChecksumResult4))] + public async Task ResultsOfTResult1TResult2TResult3_AcceptsNestedResultsOfT_AsThirdTypeArg(int input, Type expectedResultType) + { + // Arrange + Results, ChecksumResult4> MyApi(int id) { - await result.ExecuteAsync(httpContext); - }); + return id switch + { + 1 => (Results)new ChecksumResult1(1), + 2 => (Results)new ChecksumResult2(2), + 3 => (Results)new ChecksumResult3(3), + _ => new ChecksumResult4(4) + }; + } + var httpContext = GetHttpContext(); + + // Act + var result = MyApi(input); + await result.ExecuteAsync(httpContext); + + // Assert + Assert.IsType(expectedResultType, result.Result); + Assert.Equal(input, httpContext.Items[nameof(ChecksumResult.Checksum)]); } [Theory] @@ -376,21 +460,17 @@ Results MyApi() [InlineData(2, typeof(ChecksumResult2))] [InlineData(3, typeof(ChecksumResult3))] [InlineData(4, typeof(ChecksumResult4))] - [InlineData(5, typeof(ChecksumResult5))] - [InlineData(6, typeof(ChecksumResult6))] - public void ResultsOfTResult1TResult2TResult3TResult4TResult5TResult6_Result_IsAssignedResult(int input, Type expectedResult) + public void ResultsOfTResult1TResult2TResult3TResult4_Result_IsAssignedResult(int input, Type expectedResultType) { // Arrange - Results MyApi(int id) + Results MyApi(int id) { return id switch { 1 => new ChecksumResult1(), 2 => new ChecksumResult2(), 3 => new ChecksumResult3(), - 4 => new ChecksumResult4(), - 5 => new ChecksumResult5(), - _ => new ChecksumResult6() + _ => new ChecksumResult4() }; } @@ -398,7 +478,7 @@ Results MyApi(int checksum) + Results MyApi(int checksum) { return checksum switch { 1 => new ChecksumResult1(checksum), 2 => new ChecksumResult2(checksum), 3 => new ChecksumResult3(checksum), - 4 => new ChecksumResult4(checksum), - 5 => new ChecksumResult5(checksum), - _ => new ChecksumResult6(checksum) + _ => new ChecksumResult4(checksum) }; } var httpContext = GetHttpContext(); @@ -430,11 +506,11 @@ Results MyApi() @@ -453,7 +529,7 @@ Results MyApi() } [Fact] - public void ResultsOfTResult1TResult2TResult3TResult4TResult5TResult6_Throws_InvalidOperationException_WhenResultIsNull() + public void ResultsOfTResult1TResult2TResult3TResult4_Throws_InvalidOperationException_WhenResultIsNull() { // Arrange Results MyApi() @@ -476,55 +552,46 @@ Results MyApi() [InlineData(2, typeof(ChecksumResult2))] [InlineData(3, typeof(ChecksumResult3))] [InlineData(4, typeof(ChecksumResult4))] - [InlineData(5, typeof(ChecksumResult5))] - [InlineData(6, typeof(ChecksumResult6))] - [InlineData(7, typeof(ChecksumResult7))] - public void ResultsOfTResult1TResult2TResult3TResult4TResult5TResult6TResult7_Result_IsAssignedResult(int input, Type expectedResult) + public async Task ResultsOfTResult1TResult2TResult3TResult4_AcceptsIResult_AsFirstTypeArg(int input, Type expectedResultType) { // Arrange - Results MyApi(int id) + Results MyApi(int id) { return id switch { - 1 => new ChecksumResult1(), - 2 => new ChecksumResult2(), - 3 => new ChecksumResult3(), - 4 => new ChecksumResult4(), - 5 => new ChecksumResult5(), - 6 => new ChecksumResult6(), - _ => new ChecksumResult7() + 1 => new ChecksumResult1(1), + 2 => new ChecksumResult2(2), + 3 => new ChecksumResult3(3), + _ => new ChecksumResult4(4) }; } + var httpContext = GetHttpContext(); // Act var result = MyApi(input); - + await result.ExecuteAsync(httpContext); + // Assert - Assert.IsType(expectedResult, result.Result); + Assert.IsType(expectedResultType, result.Result); + Assert.Equal(input, httpContext.Items[nameof(ChecksumResult.Checksum)]); } - + [Theory] - [InlineData(1)] - [InlineData(2)] - [InlineData(3)] - [InlineData(4)] - [InlineData(5)] - [InlineData(6)] - [InlineData(7)] - public async Task ResultsOfTResult1TResult2TResult3TResult4TResult5TResult6TResult7_ExecuteResult_ExecutesAssignedResult(int input) + [InlineData(1, typeof(ChecksumResult1))] + [InlineData(2, typeof(ChecksumResult2))] + [InlineData(3, typeof(ChecksumResult3))] + [InlineData(4, typeof(ChecksumResult4))] + public async Task ResultsOfTResult1TResult2TResult3TResult4_AcceptsIResult_AsSecondTypeArg(int input, Type expectedResultType) { // Arrange - Results MyApi(int checksum) + Results MyApi(int id) { - return checksum switch + return id switch { - 1 => new ChecksumResult1(checksum), - 2 => new ChecksumResult2(checksum), - 3 => new ChecksumResult3(checksum), - 4 => new ChecksumResult4(checksum), - 5 => new ChecksumResult5(checksum), - 6 => new ChecksumResult6(checksum), - _ => new ChecksumResult7(checksum) + 1 => new ChecksumResult1(1), + 2 => new ChecksumResult2(2), + 3 => new ChecksumResult3(3), + _ => new ChecksumResult4(4) }; } var httpContext = GetHttpContext(); @@ -532,107 +599,119 @@ Results MyApi() + Results MyApi(int id) { - return new ChecksumResult1(1); + return id switch + { + 1 => new ChecksumResult1(1), + 2 => new ChecksumResult2(2), + 3 => new ChecksumResult3(3), + _ => new ChecksumResult4(4) + }; } - HttpContext httpContext = null; - - // Act & Assert - var result = MyApi(); + var httpContext = GetHttpContext(); + + // Act + var result = MyApi(input); + await result.ExecuteAsync(httpContext); - Assert.ThrowsAsync(async () => - { - await result.ExecuteAsync(httpContext); - }); + // Assert + Assert.IsType(expectedResultType, result.Result); + Assert.Equal(input, httpContext.Items[nameof(ChecksumResult.Checksum)]); } - [Fact] - public void ResultsOfTResult1TResult2TResult3TResult4TResult5TResult6TResult7_Throws_InvalidOperationException_WhenResultIsNull() + [Theory] + [InlineData(1, typeof(ChecksumResult1))] + [InlineData(2, typeof(ChecksumResult2))] + [InlineData(3, typeof(ChecksumResult3))] + [InlineData(4, typeof(ChecksumResult4))] + public async Task ResultsOfTResult1TResult2TResult3TResult4_AcceptsIResult_AsFourthTypeArg(int input, Type expectedResultType) { // Arrange - Results MyApi() + Results MyApi(int id) { - return new ChecksumResult1(1); + return id switch + { + 1 => new ChecksumResult1(1), + 2 => new ChecksumResult2(2), + 3 => new ChecksumResult3(3), + _ => new ChecksumResult4(4) + }; } var httpContext = GetHttpContext(); + + // Act + var result = MyApi(input); + await result.ExecuteAsync(httpContext); - // Act & Assert - var result = MyApi(); - - Assert.ThrowsAsync(async () => - { - await result.ExecuteAsync(httpContext); - }); + // Assert + Assert.IsType(expectedResultType, result.Result); + Assert.Equal(input, httpContext.Items[nameof(ChecksumResult.Checksum)]); } [Theory] - [InlineData(1, typeof(ChecksumResult1))] - [InlineData(2, typeof(ChecksumResult2))] - [InlineData(3, typeof(ChecksumResult3))] - [InlineData(4, typeof(ChecksumResult4))] + [InlineData(1, typeof(Results))] + [InlineData(2, typeof(Results))] + [InlineData(3, typeof(Results))] + [InlineData(4, typeof(Results))] [InlineData(5, typeof(ChecksumResult5))] - [InlineData(6, typeof(ChecksumResult6))] - [InlineData(7, typeof(ChecksumResult7))] - [InlineData(8, typeof(ChecksumResult8))] - public void ResultsOfTResult1TResult2TResult3TResult4TResult5TResult6TResult7TResult8_Result_IsAssignedResult(int input, Type expectedResult) + public async Task ResultsOfTResult1TResult2TResult3TResult4_AcceptsNestedResultsOfT_AsFirstTypeArg(int input, Type expectedResultType) { // Arrange - Results MyApi(int id) + Results, ChecksumResult5> MyApi(int id) { return id switch { - 1 => new ChecksumResult1(), - 2 => new ChecksumResult2(), - 3 => new ChecksumResult3(), - 4 => new ChecksumResult4(), - 5 => new ChecksumResult5(), - 6 => new ChecksumResult6(), - 7 => new ChecksumResult7(), - _ => new ChecksumResult8() + 1 => (Results)new ChecksumResult1(1), + 2 => (Results)new ChecksumResult2(2), + 3 => (Results)new ChecksumResult3(3), + 4 => (Results)new ChecksumResult4(4), + _ => new ChecksumResult5(5) }; } + var httpContext = GetHttpContext(); // Act var result = MyApi(input); - + await result.ExecuteAsync(httpContext); + // Assert - Assert.IsType(expectedResult, result.Result); + Assert.IsType(expectedResultType, result.Result); + Assert.Equal(input, httpContext.Items[nameof(ChecksumResult.Checksum)]); } - + [Theory] - [InlineData(1)] - [InlineData(2)] - [InlineData(3)] - [InlineData(4)] - [InlineData(5)] - [InlineData(6)] - [InlineData(7)] - [InlineData(8)] - public async Task ResultsOfTResult1TResult2TResult3TResult4TResult5TResult6TResult7TResult8_ExecuteResult_ExecutesAssignedResult(int input) + [InlineData(1, typeof(Results))] + [InlineData(2, typeof(Results))] + [InlineData(3, typeof(Results))] + [InlineData(4, typeof(Results))] + [InlineData(5, typeof(ChecksumResult5))] + public async Task ResultsOfTResult1TResult2TResult3TResult4_AcceptsNestedResultsOfT_AsSecondTypeArg(int input, Type expectedResultType) { // Arrange - Results MyApi(int checksum) + Results, ChecksumResult5> MyApi(int id) { - return checksum switch + return id switch { - 1 => new ChecksumResult1(checksum), - 2 => new ChecksumResult2(checksum), - 3 => new ChecksumResult3(checksum), - 4 => new ChecksumResult4(checksum), - 5 => new ChecksumResult5(checksum), - 6 => new ChecksumResult6(checksum), - 7 => new ChecksumResult7(checksum), - _ => new ChecksumResult8(checksum) + 1 => (Results)new ChecksumResult1(1), + 2 => (Results)new ChecksumResult2(2), + 3 => (Results)new ChecksumResult3(3), + 4 => (Results)new ChecksumResult4(4), + _ => new ChecksumResult5(5) }; } var httpContext = GetHttpContext(); @@ -640,47 +719,72 @@ Results))] + [InlineData(2, typeof(Results))] + [InlineData(3, typeof(Results))] + [InlineData(4, typeof(Results))] + [InlineData(5, typeof(ChecksumResult5))] + public async Task ResultsOfTResult1TResult2TResult3TResult4_AcceptsNestedResultsOfT_AsThirdTypeArg(int input, Type expectedResultType) { // Arrange - Results MyApi() + Results, ChecksumResult5> MyApi(int id) { - return new ChecksumResult1(1); + return id switch + { + 1 => (Results)new ChecksumResult1(1), + 2 => (Results)new ChecksumResult2(2), + 3 => (Results)new ChecksumResult3(3), + 4 => (Results)new ChecksumResult4(4), + _ => new ChecksumResult5(5) + }; } - HttpContext httpContext = null; - - // Act & Assert - var result = MyApi(); + var httpContext = GetHttpContext(); + + // Act + var result = MyApi(input); + await result.ExecuteAsync(httpContext); - Assert.ThrowsAsync(async () => - { - await result.ExecuteAsync(httpContext); - }); + // Assert + Assert.IsType(expectedResultType, result.Result); + Assert.Equal(input, httpContext.Items[nameof(ChecksumResult.Checksum)]); } - [Fact] - public void ResultsOfTResult1TResult2TResult3TResult4TResult5TResult6TResult7TResult8_Throws_InvalidOperationException_WhenResultIsNull() + [Theory] + [InlineData(1, typeof(Results))] + [InlineData(2, typeof(Results))] + [InlineData(3, typeof(Results))] + [InlineData(4, typeof(Results))] + [InlineData(5, typeof(ChecksumResult5))] + public async Task ResultsOfTResult1TResult2TResult3TResult4_AcceptsNestedResultsOfT_AsFourthTypeArg(int input, Type expectedResultType) { // Arrange - Results MyApi() + Results, ChecksumResult5> MyApi(int id) { - return new ChecksumResult1(1); + return id switch + { + 1 => (Results)new ChecksumResult1(1), + 2 => (Results)new ChecksumResult2(2), + 3 => (Results)new ChecksumResult3(3), + 4 => (Results)new ChecksumResult4(4), + _ => new ChecksumResult5(5) + }; } var httpContext = GetHttpContext(); + + // Act + var result = MyApi(input); + await result.ExecuteAsync(httpContext); - // Act & Assert - var result = MyApi(); - - Assert.ThrowsAsync(async () => - { - await result.ExecuteAsync(httpContext); - }); + // Assert + Assert.IsType(expectedResultType, result.Result); + Assert.Equal(input, httpContext.Items[nameof(ChecksumResult.Checksum)]); } [Theory] @@ -689,14 +793,10 @@ Results MyApi() [InlineData(3, typeof(ChecksumResult3))] [InlineData(4, typeof(ChecksumResult4))] [InlineData(5, typeof(ChecksumResult5))] - [InlineData(6, typeof(ChecksumResult6))] - [InlineData(7, typeof(ChecksumResult7))] - [InlineData(8, typeof(ChecksumResult8))] - [InlineData(9, typeof(ChecksumResult9))] - public void ResultsOfTResult1TResult2TResult3TResult4TResult5TResult6TResult7TResult8TResult9_Result_IsAssignedResult(int input, Type expectedResult) + public void ResultsOfTResult1TResult2TResult3TResult4TResult5_Result_IsAssignedResult(int input, Type expectedResultType) { // Arrange - Results MyApi(int id) + Results MyApi(int id) { return id switch { @@ -704,11 +804,7 @@ Results new ChecksumResult2(), 3 => new ChecksumResult3(), 4 => new ChecksumResult4(), - 5 => new ChecksumResult5(), - 6 => new ChecksumResult6(), - 7 => new ChecksumResult7(), - 8 => new ChecksumResult8(), - _ => new ChecksumResult9() + _ => new ChecksumResult5() }; } @@ -716,7 +812,7 @@ Results MyApi(int checksum) + Results MyApi(int checksum) { return checksum switch { @@ -740,11 +832,7 @@ Results new ChecksumResult2(checksum), 3 => new ChecksumResult3(checksum), 4 => new ChecksumResult4(checksum), - 5 => new ChecksumResult5(checksum), - 6 => new ChecksumResult6(checksum), - 7 => new ChecksumResult7(checksum), - 8 => new ChecksumResult8(checksum), - _ => new ChecksumResult9(checksum) + _ => new ChecksumResult5(checksum) }; } var httpContext = GetHttpContext(); @@ -754,11 +842,11 @@ Results MyApi() @@ -777,7 +865,7 @@ Results MyApi() } [Fact] - public void ResultsOfTResult1TResult2TResult3TResult4TResult5TResult6TResult7TResult8TResult9_Throws_InvalidOperationException_WhenResultIsNull() + public void ResultsOfTResult1TResult2TResult3TResult4TResult5_Throws_InvalidOperationException_WhenResultIsNull() { // Arrange Results MyApi() @@ -801,66 +889,49 @@ Results MyApi() [InlineData(3, typeof(ChecksumResult3))] [InlineData(4, typeof(ChecksumResult4))] [InlineData(5, typeof(ChecksumResult5))] - [InlineData(6, typeof(ChecksumResult6))] - [InlineData(7, typeof(ChecksumResult7))] - [InlineData(8, typeof(ChecksumResult8))] - [InlineData(9, typeof(ChecksumResult9))] - [InlineData(10, typeof(ChecksumResult10))] - public void ResultsOfTResult1TResult2TResult3TResult4TResult5TResult6TResult7TResult8TResult9TResult10_Result_IsAssignedResult(int input, Type expectedResult) + public async Task ResultsOfTResult1TResult2TResult3TResult4TResult5_AcceptsIResult_AsFirstTypeArg(int input, Type expectedResultType) { // Arrange - Results MyApi(int id) + Results MyApi(int id) { return id switch { - 1 => new ChecksumResult1(), - 2 => new ChecksumResult2(), - 3 => new ChecksumResult3(), - 4 => new ChecksumResult4(), - 5 => new ChecksumResult5(), - 6 => new ChecksumResult6(), - 7 => new ChecksumResult7(), - 8 => new ChecksumResult8(), - 9 => new ChecksumResult9(), - _ => new ChecksumResult10() + 1 => new ChecksumResult1(1), + 2 => new ChecksumResult2(2), + 3 => new ChecksumResult3(3), + 4 => new ChecksumResult4(4), + _ => new ChecksumResult5(5) }; } + var httpContext = GetHttpContext(); // Act var result = MyApi(input); - + await result.ExecuteAsync(httpContext); + // Assert - Assert.IsType(expectedResult, result.Result); + Assert.IsType(expectedResultType, result.Result); + Assert.Equal(input, httpContext.Items[nameof(ChecksumResult.Checksum)]); } - + [Theory] - [InlineData(1)] - [InlineData(2)] - [InlineData(3)] - [InlineData(4)] - [InlineData(5)] - [InlineData(6)] - [InlineData(7)] - [InlineData(8)] - [InlineData(9)] - [InlineData(10)] - public async Task ResultsOfTResult1TResult2TResult3TResult4TResult5TResult6TResult7TResult8TResult9TResult10_ExecuteResult_ExecutesAssignedResult(int input) + [InlineData(1, typeof(ChecksumResult1))] + [InlineData(2, typeof(ChecksumResult2))] + [InlineData(3, typeof(ChecksumResult3))] + [InlineData(4, typeof(ChecksumResult4))] + [InlineData(5, typeof(ChecksumResult5))] + public async Task ResultsOfTResult1TResult2TResult3TResult4TResult5_AcceptsIResult_AsSecondTypeArg(int input, Type expectedResultType) { // Arrange - Results MyApi(int checksum) + Results MyApi(int id) { - return checksum switch + return id switch { - 1 => new ChecksumResult1(checksum), - 2 => new ChecksumResult2(checksum), - 3 => new ChecksumResult3(checksum), - 4 => new ChecksumResult4(checksum), - 5 => new ChecksumResult5(checksum), - 6 => new ChecksumResult6(checksum), - 7 => new ChecksumResult7(checksum), - 8 => new ChecksumResult8(checksum), - 9 => new ChecksumResult9(checksum), - _ => new ChecksumResult10(checksum) + 1 => new ChecksumResult1(1), + 2 => new ChecksumResult2(2), + 3 => new ChecksumResult3(3), + 4 => new ChecksumResult4(4), + _ => new ChecksumResult5(5) }; } var httpContext = GetHttpContext(); @@ -868,47 +939,72 @@ Results MyApi() + Results MyApi(int id) { - return new ChecksumResult1(1); + return id switch + { + 1 => new ChecksumResult1(1), + 2 => new ChecksumResult2(2), + 3 => new ChecksumResult3(3), + 4 => new ChecksumResult4(4), + _ => new ChecksumResult5(5) + }; } - HttpContext httpContext = null; - - // Act & Assert - var result = MyApi(); + var httpContext = GetHttpContext(); + + // Act + var result = MyApi(input); + await result.ExecuteAsync(httpContext); - Assert.ThrowsAsync(async () => - { - await result.ExecuteAsync(httpContext); - }); + // Assert + Assert.IsType(expectedResultType, result.Result); + Assert.Equal(input, httpContext.Items[nameof(ChecksumResult.Checksum)]); } - [Fact] - public void ResultsOfTResult1TResult2TResult3TResult4TResult5TResult6TResult7TResult8TResult9TResult10_Throws_InvalidOperationException_WhenResultIsNull() + [Theory] + [InlineData(1, typeof(ChecksumResult1))] + [InlineData(2, typeof(ChecksumResult2))] + [InlineData(3, typeof(ChecksumResult3))] + [InlineData(4, typeof(ChecksumResult4))] + [InlineData(5, typeof(ChecksumResult5))] + public async Task ResultsOfTResult1TResult2TResult3TResult4TResult5_AcceptsIResult_AsFourthTypeArg(int input, Type expectedResultType) { // Arrange - Results MyApi() + Results MyApi(int id) { - return new ChecksumResult1(1); + return id switch + { + 1 => new ChecksumResult1(1), + 2 => new ChecksumResult2(2), + 3 => new ChecksumResult3(3), + 4 => new ChecksumResult4(4), + _ => new ChecksumResult5(5) + }; } var httpContext = GetHttpContext(); + + // Act + var result = MyApi(input); + await result.ExecuteAsync(httpContext); - // Act & Assert - var result = MyApi(); - - Assert.ThrowsAsync(async () => - { - await result.ExecuteAsync(httpContext); - }); + // Assert + Assert.IsType(expectedResultType, result.Result); + Assert.Equal(input, httpContext.Items[nameof(ChecksumResult.Checksum)]); } [Theory] @@ -917,70 +1013,51 @@ Results MyApi() [InlineData(3, typeof(ChecksumResult3))] [InlineData(4, typeof(ChecksumResult4))] [InlineData(5, typeof(ChecksumResult5))] - [InlineData(6, typeof(ChecksumResult6))] - [InlineData(7, typeof(ChecksumResult7))] - [InlineData(8, typeof(ChecksumResult8))] - [InlineData(9, typeof(ChecksumResult9))] - [InlineData(10, typeof(ChecksumResult10))] - [InlineData(11, typeof(ChecksumResult11))] - public void ResultsOfTResult1TResult2TResult3TResult4TResult5TResult6TResult7TResult8TResult9TResult10TResult11_Result_IsAssignedResult(int input, Type expectedResult) + public async Task ResultsOfTResult1TResult2TResult3TResult4TResult5_AcceptsIResult_AsFifthTypeArg(int input, Type expectedResultType) { // Arrange - Results MyApi(int id) + Results MyApi(int id) { return id switch { - 1 => new ChecksumResult1(), - 2 => new ChecksumResult2(), - 3 => new ChecksumResult3(), - 4 => new ChecksumResult4(), - 5 => new ChecksumResult5(), - 6 => new ChecksumResult6(), - 7 => new ChecksumResult7(), - 8 => new ChecksumResult8(), - 9 => new ChecksumResult9(), - 10 => new ChecksumResult10(), - _ => new ChecksumResult11() + 1 => new ChecksumResult1(1), + 2 => new ChecksumResult2(2), + 3 => new ChecksumResult3(3), + 4 => new ChecksumResult4(4), + _ => new ChecksumResult5(5) }; } + var httpContext = GetHttpContext(); // Act var result = MyApi(input); - + await result.ExecuteAsync(httpContext); + // Assert - Assert.IsType(expectedResult, result.Result); + Assert.IsType(expectedResultType, result.Result); + Assert.Equal(input, httpContext.Items[nameof(ChecksumResult.Checksum)]); } - + [Theory] - [InlineData(1)] - [InlineData(2)] - [InlineData(3)] - [InlineData(4)] - [InlineData(5)] - [InlineData(6)] - [InlineData(7)] - [InlineData(8)] - [InlineData(9)] - [InlineData(10)] - [InlineData(11)] - public async Task ResultsOfTResult1TResult2TResult3TResult4TResult5TResult6TResult7TResult8TResult9TResult10TResult11_ExecuteResult_ExecutesAssignedResult(int input) + [InlineData(1, typeof(Results))] + [InlineData(2, typeof(Results))] + [InlineData(3, typeof(Results))] + [InlineData(4, typeof(Results))] + [InlineData(5, typeof(Results))] + [InlineData(6, typeof(ChecksumResult6))] + public async Task ResultsOfTResult1TResult2TResult3TResult4TResult5_AcceptsNestedResultsOfT_AsFirstTypeArg(int input, Type expectedResultType) { // Arrange - Results MyApi(int checksum) + Results, ChecksumResult6> MyApi(int id) { - return checksum switch + return id switch { - 1 => new ChecksumResult1(checksum), - 2 => new ChecksumResult2(checksum), - 3 => new ChecksumResult3(checksum), - 4 => new ChecksumResult4(checksum), - 5 => new ChecksumResult5(checksum), - 6 => new ChecksumResult6(checksum), - 7 => new ChecksumResult7(checksum), - 8 => new ChecksumResult8(checksum), - 9 => new ChecksumResult9(checksum), - 10 => new ChecksumResult10(checksum), - _ => new ChecksumResult11(checksum) + 1 => (Results)new ChecksumResult1(1), + 2 => (Results)new ChecksumResult2(2), + 3 => (Results)new ChecksumResult3(3), + 4 => (Results)new ChecksumResult4(4), + 5 => (Results)new ChecksumResult5(5), + _ => new ChecksumResult6(6) }; } var httpContext = GetHttpContext(); @@ -988,123 +1065,98 @@ Results MyApi() - { - return new ChecksumResult1(1); - } - HttpContext httpContext = null; - - // Act & Assert - var result = MyApi(); - - Assert.ThrowsAsync(async () => - { - await result.ExecuteAsync(httpContext); - }); + Assert.IsType(expectedResultType, result.Result); + Assert.Equal(input, httpContext.Items[nameof(ChecksumResult.Checksum)]); } - [Fact] - public void ResultsOfTResult1TResult2TResult3TResult4TResult5TResult6TResult7TResult8TResult9TResult10TResult11_Throws_InvalidOperationException_WhenResultIsNull() + [Theory] + [InlineData(1, typeof(Results))] + [InlineData(2, typeof(Results))] + [InlineData(3, typeof(Results))] + [InlineData(4, typeof(Results))] + [InlineData(5, typeof(Results))] + [InlineData(6, typeof(ChecksumResult6))] + public async Task ResultsOfTResult1TResult2TResult3TResult4TResult5_AcceptsNestedResultsOfT_AsSecondTypeArg(int input, Type expectedResultType) { // Arrange - Results MyApi() + Results, ChecksumResult6> MyApi(int id) { - return new ChecksumResult1(1); + return id switch + { + 1 => (Results)new ChecksumResult1(1), + 2 => (Results)new ChecksumResult2(2), + 3 => (Results)new ChecksumResult3(3), + 4 => (Results)new ChecksumResult4(4), + 5 => (Results)new ChecksumResult5(5), + _ => new ChecksumResult6(6) + }; } var httpContext = GetHttpContext(); + + // Act + var result = MyApi(input); + await result.ExecuteAsync(httpContext); - // Act & Assert - var result = MyApi(); - - Assert.ThrowsAsync(async () => - { - await result.ExecuteAsync(httpContext); - }); + // Assert + Assert.IsType(expectedResultType, result.Result); + Assert.Equal(input, httpContext.Items[nameof(ChecksumResult.Checksum)]); } [Theory] - [InlineData(1, typeof(ChecksumResult1))] - [InlineData(2, typeof(ChecksumResult2))] - [InlineData(3, typeof(ChecksumResult3))] - [InlineData(4, typeof(ChecksumResult4))] - [InlineData(5, typeof(ChecksumResult5))] + [InlineData(1, typeof(Results))] + [InlineData(2, typeof(Results))] + [InlineData(3, typeof(Results))] + [InlineData(4, typeof(Results))] + [InlineData(5, typeof(Results))] [InlineData(6, typeof(ChecksumResult6))] - [InlineData(7, typeof(ChecksumResult7))] - [InlineData(8, typeof(ChecksumResult8))] - [InlineData(9, typeof(ChecksumResult9))] - [InlineData(10, typeof(ChecksumResult10))] - [InlineData(11, typeof(ChecksumResult11))] - [InlineData(12, typeof(ChecksumResult12))] - public void ResultsOfTResult1TResult2TResult3TResult4TResult5TResult6TResult7TResult8TResult9TResult10TResult11TResult12_Result_IsAssignedResult(int input, Type expectedResult) + public async Task ResultsOfTResult1TResult2TResult3TResult4TResult5_AcceptsNestedResultsOfT_AsThirdTypeArg(int input, Type expectedResultType) { // Arrange - Results MyApi(int id) + Results, ChecksumResult6> MyApi(int id) { return id switch { - 1 => new ChecksumResult1(), - 2 => new ChecksumResult2(), - 3 => new ChecksumResult3(), - 4 => new ChecksumResult4(), - 5 => new ChecksumResult5(), - 6 => new ChecksumResult6(), - 7 => new ChecksumResult7(), - 8 => new ChecksumResult8(), - 9 => new ChecksumResult9(), - 10 => new ChecksumResult10(), - 11 => new ChecksumResult11(), - _ => new ChecksumResult12() + 1 => (Results)new ChecksumResult1(1), + 2 => (Results)new ChecksumResult2(2), + 3 => (Results)new ChecksumResult3(3), + 4 => (Results)new ChecksumResult4(4), + 5 => (Results)new ChecksumResult5(5), + _ => new ChecksumResult6(6) }; } + var httpContext = GetHttpContext(); // Act var result = MyApi(input); - + await result.ExecuteAsync(httpContext); + // Assert - Assert.IsType(expectedResult, result.Result); + Assert.IsType(expectedResultType, result.Result); + Assert.Equal(input, httpContext.Items[nameof(ChecksumResult.Checksum)]); } - + [Theory] - [InlineData(1)] - [InlineData(2)] - [InlineData(3)] - [InlineData(4)] - [InlineData(5)] - [InlineData(6)] - [InlineData(7)] - [InlineData(8)] - [InlineData(9)] - [InlineData(10)] - [InlineData(11)] - [InlineData(12)] - public async Task ResultsOfTResult1TResult2TResult3TResult4TResult5TResult6TResult7TResult8TResult9TResult10TResult11TResult12_ExecuteResult_ExecutesAssignedResult(int input) + [InlineData(1, typeof(Results))] + [InlineData(2, typeof(Results))] + [InlineData(3, typeof(Results))] + [InlineData(4, typeof(Results))] + [InlineData(5, typeof(Results))] + [InlineData(6, typeof(ChecksumResult6))] + public async Task ResultsOfTResult1TResult2TResult3TResult4TResult5_AcceptsNestedResultsOfT_AsFourthTypeArg(int input, Type expectedResultType) { // Arrange - Results MyApi(int checksum) + Results, ChecksumResult6> MyApi(int id) { - return checksum switch + return id switch { - 1 => new ChecksumResult1(checksum), - 2 => new ChecksumResult2(checksum), - 3 => new ChecksumResult3(checksum), - 4 => new ChecksumResult4(checksum), - 5 => new ChecksumResult5(checksum), - 6 => new ChecksumResult6(checksum), - 7 => new ChecksumResult7(checksum), - 8 => new ChecksumResult8(checksum), - 9 => new ChecksumResult9(checksum), - 10 => new ChecksumResult10(checksum), - 11 => new ChecksumResult11(checksum), - _ => new ChecksumResult12(checksum) + 1 => (Results)new ChecksumResult1(1), + 2 => (Results)new ChecksumResult2(2), + 3 => (Results)new ChecksumResult3(3), + 4 => (Results)new ChecksumResult4(4), + 5 => (Results)new ChecksumResult5(5), + _ => new ChecksumResult6(6) }; } var httpContext = GetHttpContext(); @@ -1112,47 +1164,43 @@ Results MyApi() - { - return new ChecksumResult1(1); - } - HttpContext httpContext = null; - - // Act & Assert - var result = MyApi(); - Assert.ThrowsAsync(async () => - { - await result.ExecuteAsync(httpContext); - }); + // Assert + Assert.IsType(expectedResultType, result.Result); + Assert.Equal(input, httpContext.Items[nameof(ChecksumResult.Checksum)]); } - [Fact] - public void ResultsOfTResult1TResult2TResult3TResult4TResult5TResult6TResult7TResult8TResult9TResult10TResult11TResult12_Throws_InvalidOperationException_WhenResultIsNull() + [Theory] + [InlineData(1, typeof(Results))] + [InlineData(2, typeof(Results))] + [InlineData(3, typeof(Results))] + [InlineData(4, typeof(Results))] + [InlineData(5, typeof(Results))] + [InlineData(6, typeof(ChecksumResult6))] + public async Task ResultsOfTResult1TResult2TResult3TResult4TResult5_AcceptsNestedResultsOfT_AsFifthTypeArg(int input, Type expectedResultType) { // Arrange - Results MyApi() + Results, ChecksumResult6> MyApi(int id) { - return new ChecksumResult1(1); + return id switch + { + 1 => (Results)new ChecksumResult1(1), + 2 => (Results)new ChecksumResult2(2), + 3 => (Results)new ChecksumResult3(3), + 4 => (Results)new ChecksumResult4(4), + 5 => (Results)new ChecksumResult5(5), + _ => new ChecksumResult6(6) + }; } var httpContext = GetHttpContext(); + + // Act + var result = MyApi(input); + await result.ExecuteAsync(httpContext); - // Act & Assert - var result = MyApi(); - - Assert.ThrowsAsync(async () => - { - await result.ExecuteAsync(httpContext); - }); + // Assert + Assert.IsType(expectedResultType, result.Result); + Assert.Equal(input, httpContext.Items[nameof(ChecksumResult.Checksum)]); } [Theory] @@ -1162,17 +1210,10 @@ Results MyApi() [InlineData(4, typeof(ChecksumResult4))] [InlineData(5, typeof(ChecksumResult5))] [InlineData(6, typeof(ChecksumResult6))] - [InlineData(7, typeof(ChecksumResult7))] - [InlineData(8, typeof(ChecksumResult8))] - [InlineData(9, typeof(ChecksumResult9))] - [InlineData(10, typeof(ChecksumResult10))] - [InlineData(11, typeof(ChecksumResult11))] - [InlineData(12, typeof(ChecksumResult12))] - [InlineData(13, typeof(ChecksumResult13))] - public void ResultsOfTResult1TResult2TResult3TResult4TResult5TResult6TResult7TResult8TResult9TResult10TResult11TResult12TResult13_Result_IsAssignedResult(int input, Type expectedResult) + public void ResultsOfTResult1TResult2TResult3TResult4TResult5TResult6_Result_IsAssignedResult(int input, Type expectedResultType) { // Arrange - Results MyApi(int id) + Results MyApi(int id) { return id switch { @@ -1181,14 +1222,7 @@ Results new ChecksumResult3(), 4 => new ChecksumResult4(), 5 => new ChecksumResult5(), - 6 => new ChecksumResult6(), - 7 => new ChecksumResult7(), - 8 => new ChecksumResult8(), - 9 => new ChecksumResult9(), - 10 => new ChecksumResult10(), - 11 => new ChecksumResult11(), - 12 => new ChecksumResult12(), - _ => new ChecksumResult13() + _ => new ChecksumResult6() }; } @@ -1196,7 +1230,7 @@ Results MyApi(int checksum) + Results MyApi(int checksum) { return checksum switch { @@ -1225,14 +1252,7 @@ Results new ChecksumResult3(checksum), 4 => new ChecksumResult4(checksum), 5 => new ChecksumResult5(checksum), - 6 => new ChecksumResult6(checksum), - 7 => new ChecksumResult7(checksum), - 8 => new ChecksumResult8(checksum), - 9 => new ChecksumResult9(checksum), - 10 => new ChecksumResult10(checksum), - 11 => new ChecksumResult11(checksum), - 12 => new ChecksumResult12(checksum), - _ => new ChecksumResult13(checksum) + _ => new ChecksumResult6(checksum) }; } var httpContext = GetHttpContext(); @@ -1242,11 +1262,11 @@ Results MyApi() @@ -1265,7 +1285,7 @@ Results MyApi() } [Fact] - public void ResultsOfTResult1TResult2TResult3TResult4TResult5TResult6TResult7TResult8TResult9TResult10TResult11TResult12TResult13_Throws_InvalidOperationException_WhenResultIsNull() + public void ResultsOfTResult1TResult2TResult3TResult4TResult5TResult6_Throws_InvalidOperationException_WhenResultIsNull() { // Arrange Results MyApi() @@ -1290,81 +1310,52 @@ Results MyApi() [InlineData(4, typeof(ChecksumResult4))] [InlineData(5, typeof(ChecksumResult5))] [InlineData(6, typeof(ChecksumResult6))] - [InlineData(7, typeof(ChecksumResult7))] - [InlineData(8, typeof(ChecksumResult8))] - [InlineData(9, typeof(ChecksumResult9))] - [InlineData(10, typeof(ChecksumResult10))] - [InlineData(11, typeof(ChecksumResult11))] - [InlineData(12, typeof(ChecksumResult12))] - [InlineData(13, typeof(ChecksumResult13))] - [InlineData(14, typeof(ChecksumResult14))] - public void ResultsOfTResult1TResult2TResult3TResult4TResult5TResult6TResult7TResult8TResult9TResult10TResult11TResult12TResult13TResult14_Result_IsAssignedResult(int input, Type expectedResult) + public async Task ResultsOfTResult1TResult2TResult3TResult4TResult5TResult6_AcceptsIResult_AsFirstTypeArg(int input, Type expectedResultType) { // Arrange - Results MyApi(int id) + Results MyApi(int id) { return id switch { - 1 => new ChecksumResult1(), - 2 => new ChecksumResult2(), - 3 => new ChecksumResult3(), - 4 => new ChecksumResult4(), - 5 => new ChecksumResult5(), - 6 => new ChecksumResult6(), - 7 => new ChecksumResult7(), - 8 => new ChecksumResult8(), - 9 => new ChecksumResult9(), - 10 => new ChecksumResult10(), - 11 => new ChecksumResult11(), - 12 => new ChecksumResult12(), - 13 => new ChecksumResult13(), - _ => new ChecksumResult14() + 1 => new ChecksumResult1(1), + 2 => new ChecksumResult2(2), + 3 => new ChecksumResult3(3), + 4 => new ChecksumResult4(4), + 5 => new ChecksumResult5(5), + _ => new ChecksumResult6(6) }; } + var httpContext = GetHttpContext(); // Act var result = MyApi(input); - + await result.ExecuteAsync(httpContext); + // Assert - Assert.IsType(expectedResult, result.Result); + Assert.IsType(expectedResultType, result.Result); + Assert.Equal(input, httpContext.Items[nameof(ChecksumResult.Checksum)]); } - + [Theory] - [InlineData(1)] - [InlineData(2)] - [InlineData(3)] - [InlineData(4)] - [InlineData(5)] - [InlineData(6)] - [InlineData(7)] - [InlineData(8)] - [InlineData(9)] - [InlineData(10)] - [InlineData(11)] - [InlineData(12)] - [InlineData(13)] - [InlineData(14)] - public async Task ResultsOfTResult1TResult2TResult3TResult4TResult5TResult6TResult7TResult8TResult9TResult10TResult11TResult12TResult13TResult14_ExecuteResult_ExecutesAssignedResult(int input) + [InlineData(1, typeof(ChecksumResult1))] + [InlineData(2, typeof(ChecksumResult2))] + [InlineData(3, typeof(ChecksumResult3))] + [InlineData(4, typeof(ChecksumResult4))] + [InlineData(5, typeof(ChecksumResult5))] + [InlineData(6, typeof(ChecksumResult6))] + public async Task ResultsOfTResult1TResult2TResult3TResult4TResult5TResult6_AcceptsIResult_AsSecondTypeArg(int input, Type expectedResultType) { // Arrange - Results MyApi(int checksum) + Results MyApi(int id) { - return checksum switch + return id switch { - 1 => new ChecksumResult1(checksum), - 2 => new ChecksumResult2(checksum), - 3 => new ChecksumResult3(checksum), - 4 => new ChecksumResult4(checksum), - 5 => new ChecksumResult5(checksum), - 6 => new ChecksumResult6(checksum), - 7 => new ChecksumResult7(checksum), - 8 => new ChecksumResult8(checksum), - 9 => new ChecksumResult9(checksum), - 10 => new ChecksumResult10(checksum), - 11 => new ChecksumResult11(checksum), - 12 => new ChecksumResult12(checksum), - 13 => new ChecksumResult13(checksum), - _ => new ChecksumResult14(checksum) + 1 => new ChecksumResult1(1), + 2 => new ChecksumResult2(2), + 3 => new ChecksumResult3(3), + 4 => new ChecksumResult4(4), + 5 => new ChecksumResult5(5), + _ => new ChecksumResult6(6) }; } var httpContext = GetHttpContext(); @@ -1372,47 +1363,76 @@ Results MyApi() + Results MyApi(int id) { - return new ChecksumResult1(1); + return id switch + { + 1 => new ChecksumResult1(1), + 2 => new ChecksumResult2(2), + 3 => new ChecksumResult3(3), + 4 => new ChecksumResult4(4), + 5 => new ChecksumResult5(5), + _ => new ChecksumResult6(6) + }; } - HttpContext httpContext = null; - - // Act & Assert - var result = MyApi(); + var httpContext = GetHttpContext(); + + // Act + var result = MyApi(input); + await result.ExecuteAsync(httpContext); - Assert.ThrowsAsync(async () => - { - await result.ExecuteAsync(httpContext); - }); + // Assert + Assert.IsType(expectedResultType, result.Result); + Assert.Equal(input, httpContext.Items[nameof(ChecksumResult.Checksum)]); } - [Fact] - public void ResultsOfTResult1TResult2TResult3TResult4TResult5TResult6TResult7TResult8TResult9TResult10TResult11TResult12TResult13TResult14_Throws_InvalidOperationException_WhenResultIsNull() + [Theory] + [InlineData(1, typeof(ChecksumResult1))] + [InlineData(2, typeof(ChecksumResult2))] + [InlineData(3, typeof(ChecksumResult3))] + [InlineData(4, typeof(ChecksumResult4))] + [InlineData(5, typeof(ChecksumResult5))] + [InlineData(6, typeof(ChecksumResult6))] + public async Task ResultsOfTResult1TResult2TResult3TResult4TResult5TResult6_AcceptsIResult_AsFourthTypeArg(int input, Type expectedResultType) { // Arrange - Results MyApi() + Results MyApi(int id) { - return new ChecksumResult1(1); + return id switch + { + 1 => new ChecksumResult1(1), + 2 => new ChecksumResult2(2), + 3 => new ChecksumResult3(3), + 4 => new ChecksumResult4(4), + 5 => new ChecksumResult5(5), + _ => new ChecksumResult6(6) + }; } var httpContext = GetHttpContext(); + + // Act + var result = MyApi(input); + await result.ExecuteAsync(httpContext); - // Act & Assert - var result = MyApi(); - - Assert.ThrowsAsync(async () => - { - await result.ExecuteAsync(httpContext); - }); + // Assert + Assert.IsType(expectedResultType, result.Result); + Assert.Equal(input, httpContext.Items[nameof(ChecksumResult.Checksum)]); } [Theory] @@ -1422,85 +1442,52 @@ Results MyApi() [InlineData(4, typeof(ChecksumResult4))] [InlineData(5, typeof(ChecksumResult5))] [InlineData(6, typeof(ChecksumResult6))] - [InlineData(7, typeof(ChecksumResult7))] - [InlineData(8, typeof(ChecksumResult8))] - [InlineData(9, typeof(ChecksumResult9))] - [InlineData(10, typeof(ChecksumResult10))] - [InlineData(11, typeof(ChecksumResult11))] - [InlineData(12, typeof(ChecksumResult12))] - [InlineData(13, typeof(ChecksumResult13))] - [InlineData(14, typeof(ChecksumResult14))] - [InlineData(15, typeof(ChecksumResult15))] - public void ResultsOfTResult1TResult2TResult3TResult4TResult5TResult6TResult7TResult8TResult9TResult10TResult11TResult12TResult13TResult14TResult15_Result_IsAssignedResult(int input, Type expectedResult) + public async Task ResultsOfTResult1TResult2TResult3TResult4TResult5TResult6_AcceptsIResult_AsFifthTypeArg(int input, Type expectedResultType) { // Arrange - Results MyApi(int id) + Results MyApi(int id) { return id switch { - 1 => new ChecksumResult1(), - 2 => new ChecksumResult2(), - 3 => new ChecksumResult3(), - 4 => new ChecksumResult4(), - 5 => new ChecksumResult5(), - 6 => new ChecksumResult6(), - 7 => new ChecksumResult7(), - 8 => new ChecksumResult8(), - 9 => new ChecksumResult9(), - 10 => new ChecksumResult10(), - 11 => new ChecksumResult11(), - 12 => new ChecksumResult12(), - 13 => new ChecksumResult13(), - 14 => new ChecksumResult14(), - _ => new ChecksumResult15() + 1 => new ChecksumResult1(1), + 2 => new ChecksumResult2(2), + 3 => new ChecksumResult3(3), + 4 => new ChecksumResult4(4), + 5 => new ChecksumResult5(5), + _ => new ChecksumResult6(6) }; } + var httpContext = GetHttpContext(); // Act var result = MyApi(input); - + await result.ExecuteAsync(httpContext); + // Assert - Assert.IsType(expectedResult, result.Result); + Assert.IsType(expectedResultType, result.Result); + Assert.Equal(input, httpContext.Items[nameof(ChecksumResult.Checksum)]); } - + [Theory] - [InlineData(1)] - [InlineData(2)] - [InlineData(3)] - [InlineData(4)] - [InlineData(5)] - [InlineData(6)] - [InlineData(7)] - [InlineData(8)] - [InlineData(9)] - [InlineData(10)] - [InlineData(11)] - [InlineData(12)] - [InlineData(13)] - [InlineData(14)] - [InlineData(15)] - public async Task ResultsOfTResult1TResult2TResult3TResult4TResult5TResult6TResult7TResult8TResult9TResult10TResult11TResult12TResult13TResult14TResult15_ExecuteResult_ExecutesAssignedResult(int input) + [InlineData(1, typeof(ChecksumResult1))] + [InlineData(2, typeof(ChecksumResult2))] + [InlineData(3, typeof(ChecksumResult3))] + [InlineData(4, typeof(ChecksumResult4))] + [InlineData(5, typeof(ChecksumResult5))] + [InlineData(6, typeof(ChecksumResult6))] + public async Task ResultsOfTResult1TResult2TResult3TResult4TResult5TResult6_AcceptsIResult_AsSixthTypeArg(int input, Type expectedResultType) { // Arrange - Results MyApi(int checksum) + Results MyApi(int id) { - return checksum switch + return id switch { - 1 => new ChecksumResult1(checksum), - 2 => new ChecksumResult2(checksum), - 3 => new ChecksumResult3(checksum), - 4 => new ChecksumResult4(checksum), - 5 => new ChecksumResult5(checksum), - 6 => new ChecksumResult6(checksum), - 7 => new ChecksumResult7(checksum), - 8 => new ChecksumResult8(checksum), - 9 => new ChecksumResult9(checksum), - 10 => new ChecksumResult10(checksum), - 11 => new ChecksumResult11(checksum), - 12 => new ChecksumResult12(checksum), - 13 => new ChecksumResult13(checksum), - 14 => new ChecksumResult14(checksum), - _ => new ChecksumResult15(checksum) + 1 => new ChecksumResult1(1), + 2 => new ChecksumResult2(2), + 3 => new ChecksumResult3(3), + 4 => new ChecksumResult4(4), + 5 => new ChecksumResult5(5), + _ => new ChecksumResult6(6) }; } var httpContext = GetHttpContext(); @@ -1508,139 +1495,139 @@ Results))] + [InlineData(2, typeof(Results))] + [InlineData(3, typeof(Results))] + [InlineData(4, typeof(Results))] + [InlineData(5, typeof(Results))] + [InlineData(6, typeof(Results))] + [InlineData(7, typeof(ChecksumResult7))] + public async Task ResultsOfTResult1TResult2TResult3TResult4TResult5TResult6_AcceptsNestedResultsOfT_AsFirstTypeArg(int input, Type expectedResultType) { // Arrange - Results MyApi() + Results, ChecksumResult7> MyApi(int id) { - return new ChecksumResult1(1); + return id switch + { + 1 => (Results)new ChecksumResult1(1), + 2 => (Results)new ChecksumResult2(2), + 3 => (Results)new ChecksumResult3(3), + 4 => (Results)new ChecksumResult4(4), + 5 => (Results)new ChecksumResult5(5), + 6 => (Results)new ChecksumResult6(6), + _ => new ChecksumResult7(7) + }; } - HttpContext httpContext = null; - - // Act & Assert - var result = MyApi(); + var httpContext = GetHttpContext(); + + // Act + var result = MyApi(input); + await result.ExecuteAsync(httpContext); - Assert.ThrowsAsync(async () => - { - await result.ExecuteAsync(httpContext); - }); + // Assert + Assert.IsType(expectedResultType, result.Result); + Assert.Equal(input, httpContext.Items[nameof(ChecksumResult.Checksum)]); } - [Fact] - public void ResultsOfTResult1TResult2TResult3TResult4TResult5TResult6TResult7TResult8TResult9TResult10TResult11TResult12TResult13TResult14TResult15_Throws_InvalidOperationException_WhenResultIsNull() + [Theory] + [InlineData(1, typeof(Results))] + [InlineData(2, typeof(Results))] + [InlineData(3, typeof(Results))] + [InlineData(4, typeof(Results))] + [InlineData(5, typeof(Results))] + [InlineData(6, typeof(Results))] + [InlineData(7, typeof(ChecksumResult7))] + public async Task ResultsOfTResult1TResult2TResult3TResult4TResult5TResult6_AcceptsNestedResultsOfT_AsSecondTypeArg(int input, Type expectedResultType) { // Arrange - Results MyApi() + Results, ChecksumResult7> MyApi(int id) { - return new ChecksumResult1(1); + return id switch + { + 1 => (Results)new ChecksumResult1(1), + 2 => (Results)new ChecksumResult2(2), + 3 => (Results)new ChecksumResult3(3), + 4 => (Results)new ChecksumResult4(4), + 5 => (Results)new ChecksumResult5(5), + 6 => (Results)new ChecksumResult6(6), + _ => new ChecksumResult7(7) + }; } var httpContext = GetHttpContext(); + + // Act + var result = MyApi(input); + await result.ExecuteAsync(httpContext); - // Act & Assert - var result = MyApi(); - - Assert.ThrowsAsync(async () => - { - await result.ExecuteAsync(httpContext); - }); + // Assert + Assert.IsType(expectedResultType, result.Result); + Assert.Equal(input, httpContext.Items[nameof(ChecksumResult.Checksum)]); } [Theory] - [InlineData(1, typeof(ChecksumResult1))] - [InlineData(2, typeof(ChecksumResult2))] - [InlineData(3, typeof(ChecksumResult3))] - [InlineData(4, typeof(ChecksumResult4))] - [InlineData(5, typeof(ChecksumResult5))] - [InlineData(6, typeof(ChecksumResult6))] + [InlineData(1, typeof(Results))] + [InlineData(2, typeof(Results))] + [InlineData(3, typeof(Results))] + [InlineData(4, typeof(Results))] + [InlineData(5, typeof(Results))] + [InlineData(6, typeof(Results))] [InlineData(7, typeof(ChecksumResult7))] - [InlineData(8, typeof(ChecksumResult8))] - [InlineData(9, typeof(ChecksumResult9))] - [InlineData(10, typeof(ChecksumResult10))] - [InlineData(11, typeof(ChecksumResult11))] - [InlineData(12, typeof(ChecksumResult12))] - [InlineData(13, typeof(ChecksumResult13))] - [InlineData(14, typeof(ChecksumResult14))] - [InlineData(15, typeof(ChecksumResult15))] - [InlineData(16, typeof(ChecksumResult16))] - public void ResultsOfTResult1TResult2TResult3TResult4TResult5TResult6TResult7TResult8TResult9TResult10TResult11TResult12TResult13TResult14TResult15TResult16_Result_IsAssignedResult(int input, Type expectedResult) + public async Task ResultsOfTResult1TResult2TResult3TResult4TResult5TResult6_AcceptsNestedResultsOfT_AsThirdTypeArg(int input, Type expectedResultType) { // Arrange - Results MyApi(int id) + Results, ChecksumResult7> MyApi(int id) { return id switch { - 1 => new ChecksumResult1(), - 2 => new ChecksumResult2(), - 3 => new ChecksumResult3(), - 4 => new ChecksumResult4(), - 5 => new ChecksumResult5(), - 6 => new ChecksumResult6(), - 7 => new ChecksumResult7(), - 8 => new ChecksumResult8(), - 9 => new ChecksumResult9(), - 10 => new ChecksumResult10(), - 11 => new ChecksumResult11(), - 12 => new ChecksumResult12(), - 13 => new ChecksumResult13(), - 14 => new ChecksumResult14(), - 15 => new ChecksumResult15(), - _ => new ChecksumResult16() + 1 => (Results)new ChecksumResult1(1), + 2 => (Results)new ChecksumResult2(2), + 3 => (Results)new ChecksumResult3(3), + 4 => (Results)new ChecksumResult4(4), + 5 => (Results)new ChecksumResult5(5), + 6 => (Results)new ChecksumResult6(6), + _ => new ChecksumResult7(7) }; } + var httpContext = GetHttpContext(); // Act var result = MyApi(input); - + await result.ExecuteAsync(httpContext); + // Assert - Assert.IsType(expectedResult, result.Result); + Assert.IsType(expectedResultType, result.Result); + Assert.Equal(input, httpContext.Items[nameof(ChecksumResult.Checksum)]); } - + [Theory] - [InlineData(1)] - [InlineData(2)] - [InlineData(3)] - [InlineData(4)] - [InlineData(5)] - [InlineData(6)] - [InlineData(7)] - [InlineData(8)] - [InlineData(9)] - [InlineData(10)] - [InlineData(11)] - [InlineData(12)] - [InlineData(13)] - [InlineData(14)] - [InlineData(15)] - [InlineData(16)] - public async Task ResultsOfTResult1TResult2TResult3TResult4TResult5TResult6TResult7TResult8TResult9TResult10TResult11TResult12TResult13TResult14TResult15TResult16_ExecuteResult_ExecutesAssignedResult(int input) + [InlineData(1, typeof(Results))] + [InlineData(2, typeof(Results))] + [InlineData(3, typeof(Results))] + [InlineData(4, typeof(Results))] + [InlineData(5, typeof(Results))] + [InlineData(6, typeof(Results))] + [InlineData(7, typeof(ChecksumResult7))] + public async Task ResultsOfTResult1TResult2TResult3TResult4TResult5TResult6_AcceptsNestedResultsOfT_AsFourthTypeArg(int input, Type expectedResultType) { // Arrange - Results MyApi(int checksum) + Results, ChecksumResult7> MyApi(int id) { - return checksum switch + return id switch { - 1 => new ChecksumResult1(checksum), - 2 => new ChecksumResult2(checksum), - 3 => new ChecksumResult3(checksum), - 4 => new ChecksumResult4(checksum), - 5 => new ChecksumResult5(checksum), - 6 => new ChecksumResult6(checksum), - 7 => new ChecksumResult7(checksum), - 8 => new ChecksumResult8(checksum), - 9 => new ChecksumResult9(checksum), - 10 => new ChecksumResult10(checksum), - 11 => new ChecksumResult11(checksum), - 12 => new ChecksumResult12(checksum), - 13 => new ChecksumResult13(checksum), - 14 => new ChecksumResult14(checksum), - 15 => new ChecksumResult15(checksum), - _ => new ChecksumResult16(checksum) + 1 => (Results)new ChecksumResult1(1), + 2 => (Results)new ChecksumResult2(2), + 3 => (Results)new ChecksumResult3(3), + 4 => (Results)new ChecksumResult4(4), + 5 => (Results)new ChecksumResult5(5), + 6 => (Results)new ChecksumResult6(6), + _ => new ChecksumResult7(7) }; } var httpContext = GetHttpContext(); @@ -1648,50 +1635,83 @@ Results))] + [InlineData(2, typeof(Results))] + [InlineData(3, typeof(Results))] + [InlineData(4, typeof(Results))] + [InlineData(5, typeof(Results))] + [InlineData(6, typeof(Results))] + [InlineData(7, typeof(ChecksumResult7))] + public async Task ResultsOfTResult1TResult2TResult3TResult4TResult5TResult6_AcceptsNestedResultsOfT_AsFifthTypeArg(int input, Type expectedResultType) { // Arrange - Results MyApi() + Results, ChecksumResult7> MyApi(int id) { - return new ChecksumResult1(1); + return id switch + { + 1 => (Results)new ChecksumResult1(1), + 2 => (Results)new ChecksumResult2(2), + 3 => (Results)new ChecksumResult3(3), + 4 => (Results)new ChecksumResult4(4), + 5 => (Results)new ChecksumResult5(5), + 6 => (Results)new ChecksumResult6(6), + _ => new ChecksumResult7(7) + }; } - HttpContext httpContext = null; - - // Act & Assert - var result = MyApi(); + var httpContext = GetHttpContext(); + + // Act + var result = MyApi(input); + await result.ExecuteAsync(httpContext); - Assert.ThrowsAsync(async () => - { - await result.ExecuteAsync(httpContext); - }); + // Assert + Assert.IsType(expectedResultType, result.Result); + Assert.Equal(input, httpContext.Items[nameof(ChecksumResult.Checksum)]); } - [Fact] - public void ResultsOfTResult1TResult2TResult3TResult4TResult5TResult6TResult7TResult8TResult9TResult10TResult11TResult12TResult13TResult14TResult15TResult16_Throws_InvalidOperationException_WhenResultIsNull() + [Theory] + [InlineData(1, typeof(Results))] + [InlineData(2, typeof(Results))] + [InlineData(3, typeof(Results))] + [InlineData(4, typeof(Results))] + [InlineData(5, typeof(Results))] + [InlineData(6, typeof(Results))] + [InlineData(7, typeof(ChecksumResult7))] + public async Task ResultsOfTResult1TResult2TResult3TResult4TResult5TResult6_AcceptsNestedResultsOfT_AsSixthTypeArg(int input, Type expectedResultType) { // Arrange - Results MyApi() + Results, ChecksumResult7> MyApi(int id) { - return new ChecksumResult1(1); + return id switch + { + 1 => (Results)new ChecksumResult1(1), + 2 => (Results)new ChecksumResult2(2), + 3 => (Results)new ChecksumResult3(3), + 4 => (Results)new ChecksumResult4(4), + 5 => (Results)new ChecksumResult5(5), + 6 => (Results)new ChecksumResult6(6), + _ => new ChecksumResult7(7) + }; } var httpContext = GetHttpContext(); + + // Act + var result = MyApi(input); + await result.ExecuteAsync(httpContext); - // Act & Assert - var result = MyApi(); - - Assert.ThrowsAsync(async () => - { - await result.ExecuteAsync(httpContext); - }); + // Assert + Assert.IsType(expectedResultType, result.Result); + Assert.Equal(input, httpContext.Items[nameof(ChecksumResult.Checksum)]); } - class ChecksumResult : IResult + abstract class ChecksumResult : IResult { public ChecksumResult(int checksum = 0) { @@ -1702,7 +1722,7 @@ public ChecksumResult(int checksum = 0) public Task ExecuteAsync(HttpContext httpContext) { - httpContext.Items[this] = Checksum; + httpContext.Items[nameof(ChecksumResult.Checksum)] = Checksum; return Task.CompletedTask; } } @@ -1736,54 +1756,9 @@ class ChecksumResult6 : ChecksumResult { public ChecksumResult6(int checksum = 0) : base(checksum) { } } - class ChecksumResult7 : ChecksumResult { public ChecksumResult7(int checksum = 0) : base(checksum) { } } - class ChecksumResult8 : ChecksumResult - { - public ChecksumResult8(int checksum = 0) : base(checksum) { } - } - - class ChecksumResult9 : ChecksumResult - { - public ChecksumResult9(int checksum = 0) : base(checksum) { } - } - - class ChecksumResult10 : ChecksumResult - { - public ChecksumResult10(int checksum = 0) : base(checksum) { } - } - - class ChecksumResult11 : ChecksumResult - { - public ChecksumResult11(int checksum = 0) : base(checksum) { } - } - - class ChecksumResult12 : ChecksumResult - { - public ChecksumResult12(int checksum = 0) : base(checksum) { } - } - - class ChecksumResult13 : ChecksumResult - { - public ChecksumResult13(int checksum = 0) : base(checksum) { } - } - - class ChecksumResult14 : ChecksumResult - { - public ChecksumResult14(int checksum = 0) : base(checksum) { } - } - - class ChecksumResult15 : ChecksumResult - { - public ChecksumResult15(int checksum = 0) : base(checksum) { } - } - - class ChecksumResult16 : ChecksumResult - { - public ChecksumResult16(int checksum = 0) : base(checksum) { } - } } diff --git a/src/Http/Http.Results/tools/ResultsOfTGenerator/Program.cs b/src/Http/Http.Results/tools/ResultsOfTGenerator/Program.cs index 9d3b988e8497..53a8216df51c 100644 --- a/src/Http/Http.Results/tools/ResultsOfTGenerator/Program.cs +++ b/src/Http/Http.Results/tools/ResultsOfTGenerator/Program.cs @@ -5,7 +5,7 @@ using System.Text; var className = "Results"; -var typeArgCount = 16; +var typeArgCount = 6; var typeArgName = "TResult"; var pwd = Directory.GetCurrentDirectory(); @@ -207,13 +207,15 @@ void GenerateTestFiles(string testFilePath) GenerateTest_ExecuteResult_ExecutesAssignedResult(writer, i); GenerateTest_Throws_ArgumentNullException_WhenHttpContextIsNull(writer, i); GenerateTest_Throws_InvalidOperationException_WhenResultIsNull(writer, i); + Generate_AcceptsIResult_AsAnyTypeArg(writer, i); + Generate_AcceptsNestedResultsOfT_AsAnyTypeArg(writer, i); } Generate_ChecksumResultClass(writer); // CustomResult classes writer.WriteLine(); - for (int i = 1; i <= typeArgCount; i++) + for (int i = 1; i <= typeArgCount + 1; i++) { Generate_ChecksumResultClass(writer, i); @@ -245,7 +247,7 @@ void GenerateTest_Result_IsAssignedResult(StreamWriter writer, int typeArgNumber //[Theory] //[InlineData(1, typeof(ChecksumResult1))] //[InlineData(2, typeof(ChecksumResult2))] - //public void ResultsOfTResult1TResult2_Result_IsAssignedResult(int input, Type expectedResult) + //public void ResultsOfTResult1TResult2_Result_IsAssignedResult(int input, Type expectedResultType) //{ // // Arrange // Results MyApi(int id) @@ -261,7 +263,7 @@ void GenerateTest_Result_IsAssignedResult(StreamWriter writer, int typeArgNumber // var result = MyApi(input); // // Assert - // Assert.IsType(expectedResult, result.Result); + // Assert.IsType(expectedResultType, result.Result); //} // Attributes @@ -274,13 +276,12 @@ void GenerateTest_Result_IsAssignedResult(StreamWriter writer, int typeArgNumber } // Method - // public void ResultsOfTResult1TResult2_Result_IsAssignedResult(int input, Type expectedResult) writer.WriteIndent(1, "public void ResultsOf"); for (int j = 1; j <= typeArgNumber; j++) { writer.Write($"TResult{j}"); } - writer.WriteLine("_Result_IsAssignedResult(int input, Type expectedResult)"); + writer.WriteLine("_Result_IsAssignedResult(int input, Type expectedResultType)"); writer.WriteIndentedLine("{"); // Arrange @@ -320,7 +321,7 @@ void GenerateTest_Result_IsAssignedResult(StreamWriter writer, int typeArgNumber // Assert writer.WriteIndentedLine(2, "// Assert"); - writer.WriteIndentedLine(2, "Assert.IsType(expectedResult, result.Result);"); + writer.WriteIndentedLine(2, "Assert.IsType(expectedResultType, result.Result);"); // End of method writer.WriteIndentedLine("}"); @@ -352,7 +353,7 @@ void GenerateTest_ExecuteResult_ExecutesAssignedResult(StreamWriter writer, int // await result.ExecuteAsync(httpContext); // // Assert - // Assert.Equal(expected, httpContext.Items[result.Result]); + // Assert.Equal(expected, httpContext.Items[nameof(ChecksumResult.Checksum)]); //} // Attributes @@ -363,7 +364,6 @@ void GenerateTest_ExecuteResult_ExecutesAssignedResult(StreamWriter writer, int { writer.WriteIndentedLine($"[InlineData({j})]"); } - //writer.WriteIndentedLine("[InlineData(-1, null)]"); // Method // public void ResultsOfTResult1TResult2_ExecuteResult_ExecutesAssignedResult(int input, object expected) @@ -414,7 +414,7 @@ void GenerateTest_ExecuteResult_ExecutesAssignedResult(StreamWriter writer, int // Assert writer.WriteIndentedLine(2, "// Assert"); - writer.WriteIndentedLine(2, "Assert.Equal(input, httpContext.Items[result.Result]);"); + writer.WriteIndentedLine(2, "Assert.Equal(input, httpContext.Items[nameof(ChecksumResult.Checksum)]);"); // End of method writer.WriteIndentedLine("}"); @@ -535,11 +535,227 @@ void GenerateTest_Throws_InvalidOperationException_WhenResultIsNull(StreamWriter writer.WriteIndentedLine(); } +void Generate_AcceptsIResult_AsAnyTypeArg(StreamWriter writer, int typeArgCount) +{ + for (int i = 1; i <= typeArgCount; i++) + { + Generate_AcceptsIResult_AsNthTypeArg(writer, typeArgCount, i); + } +} + +void Generate_AcceptsIResult_AsNthTypeArg(StreamWriter writer, int typeArgCount, int typeArgNumber) +{ + //[Theory] + //[InlineData(1, typeof(ChecksumResult1))] + //[InlineData(2, typeof(ChecksumResult2))] + //public async Task ResultsOfTResult1TResult2_AcceptsIResult_AsFirstTypeArg(int input, Type expectedResultType) + //{ + // // Arrange + // Results MyApi(int id) + // { + // return id switch + // { + // 1 => new ChecksumResult1(1), + // _ => new ChecksumResult2(2) + // }; + // } + // var httpContext = GetHttpContext(); + + // // Act + // var result = MyApi(input); + // await result.ExecuteAsync(httpContext); + + // // Assert + // Assert.IsType(expectedResultType, result.Result); + // Assert.Equal(input, httpContext.Items[nameof(ChecksumResult.Checksum)]); + //} + + // Attributes + writer.WriteIndentedLine("[Theory]"); + + // InlineData + for (int j = 1; j <= typeArgCount; j++) + { + writer.WriteIndentedLine($"[InlineData({j}, typeof(ChecksumResult{j}))]"); + } + + // Start method + writer.WriteIndent(1, "public async Task ResultsOf"); + for (int j = 1; j <= typeArgCount; j++) + { + writer.Write($"TResult{j}"); + } + writer.WriteLine($"_AcceptsIResult_As{typeArgNumber.ToOrdinalWords().TitleCase()}TypeArg(int input, Type expectedResultType)"); + writer.WriteIndentedLine("{"); + + // Arrange + writer.WriteIndentedLine(2, "// Arrange"); + writer.WriteIndent(2, "Results<"); + for (int j = 1; j <= typeArgCount; j++) + { + if (j == typeArgNumber) + { + writer.Write("IResult"); + } + else + { + writer.Write($"ChecksumResult{j}"); + } + + if (j < typeArgCount) + { + writer.Write(", "); + } + } + writer.WriteLine("> MyApi(int id)"); + writer.WriteIndentedLine(2, "{"); + writer.WriteIndentedLine(3, "return id switch"); + writer.WriteIndentedLine(3, "{"); + for (int j = 1; j <= typeArgCount; j++) + { + if (j < typeArgCount) + { + writer.WriteIndentedLine(4, $"{j} => new ChecksumResult{j}({j}),"); + } + else + { + writer.WriteIndentedLine(4, $"_ => new ChecksumResult{j}({j})"); + } + } + writer.WriteIndentedLine(3, "};"); + writer.WriteIndentedLine(2, "}"); + writer.WriteIndentedLine(2, "var httpContext = GetHttpContext();"); + writer.WriteLine(); + + // Act + writer.WriteIndentedLine(2, "// Act"); + writer.WriteIndentedLine(2, "var result = MyApi(input);"); + writer.WriteIndentedLine(2, "await result.ExecuteAsync(httpContext);"); + writer.WriteIndentedLine(2); + + // Assert + writer.WriteIndentedLine(2, "// Assert"); + writer.WriteIndentedLine(2, "Assert.IsType(expectedResultType, result.Result);"); + writer.WriteIndentedLine(2, "Assert.Equal(input, httpContext.Items[nameof(ChecksumResult.Checksum)]);"); + + // Close method + writer.WriteIndentedLine(1, "}"); + writer.WriteIndentedLine(); +} + +void Generate_AcceptsNestedResultsOfT_AsAnyTypeArg(StreamWriter writer, int typeArgCount) +{ + for (int i = 1; i <= typeArgCount; i++) + { + Generate_AcceptsNestedResultsOfT_AsNthTypeArg(writer, typeArgCount, i); + } +} + +void Generate_AcceptsNestedResultsOfT_AsNthTypeArg(StreamWriter writer, int typeArgCount, int typeArgNumber) +{ + //[Theory] + //[InlineData(1, typeof(Results))] + //[InlineData(2, typeof(Results))] + //[InlineData(3, typeof(ChecksumResult3))] + //public async Task ResultsOfTResult1TResult2_AcceptsNestedResultsOfT_AsFirstTypeArg(int input, Type expectedResultType) + //{ + // // Arrange + // Results, ChecksumResult3> MyApi(int id) + // { + // return id switch + // { + // 1 => (Results)new ChecksumResult1(1), + // 2 => (Results)new ChecksumResult2(2), + // _ => new ChecksumResult3(3) + // }; + // } + // var httpContext = GetHttpContext(); + + // // Act + // var result = MyApi(input); + // await result.ExecuteAsync(httpContext); + + // // Assert + // Assert.IsType(expectedResultType, result.Result); + // Assert.Equal(input, httpContext.Items[nameof(ChecksumResult.Checksum)]); + //} + + var sb = new StringBuilder("Results<"); + for (int j = 1; j <= typeArgCount; j++) + { + sb.Append($"ChecksumResult{j}"); + + if (j < typeArgCount) + { + sb.Append(", "); + } + } + sb.Append(">"); + var nestedResultTypeName = sb.ToString(); + + // Attributes + writer.WriteIndentedLine("[Theory]"); + + // InlineData + for (int j = 1; j <= typeArgCount + 1; j++) + { + if (j <= typeArgCount) + { + writer.WriteIndentedLine($"[InlineData({j}, typeof({nestedResultTypeName}))]"); + } + else + { + writer.WriteIndentedLine($"[InlineData({j}, typeof(ChecksumResult{j}))]"); + } + } + + // Start method + writer.WriteIndent(1, "public async Task ResultsOf"); + for (int j = 1; j <= typeArgCount; j++) + { + writer.Write($"TResult{j}"); + } + writer.WriteLine($"_AcceptsNestedResultsOfT_As{typeArgNumber.ToOrdinalWords().TitleCase()}TypeArg(int input, Type expectedResultType)"); + writer.WriteIndentedLine("{"); + + // Arrange + writer.WriteIndentedLine(2, "// Arrange"); + writer.WriteIndent(2, "Results<"); + writer.WriteLine($"{nestedResultTypeName}, ChecksumResult{typeArgCount + 1}> MyApi(int id)"); + writer.WriteIndentedLine(2, "{"); + writer.WriteIndentedLine(3, "return id switch"); + writer.WriteIndentedLine(3, "{"); + for (int j = 1; j <= typeArgCount; j++) + { + writer.WriteIndentedLine(4, $"{j} => ({nestedResultTypeName})new ChecksumResult{j}({j}),"); + } + writer.WriteIndentedLine(4, $"_ => new ChecksumResult{typeArgCount + 1}({typeArgCount + 1})"); + writer.WriteIndentedLine(3, "};"); + writer.WriteIndentedLine(2, "}"); + writer.WriteIndentedLine(2, "var httpContext = GetHttpContext();"); + writer.WriteLine(); + + // Act + writer.WriteIndentedLine(2, "// Act"); + writer.WriteIndentedLine(2, "var result = MyApi(input);"); + writer.WriteIndentedLine(2, "await result.ExecuteAsync(httpContext);"); + writer.WriteIndentedLine(2); + + // Assert + writer.WriteIndentedLine(2, "// Assert"); + writer.WriteIndentedLine(2, "Assert.IsType(expectedResultType, result.Result);"); + writer.WriteIndentedLine(2, "Assert.Equal(input, httpContext.Items[nameof(ChecksumResult.Checksum)]);"); + + // Close method + writer.WriteIndentedLine(1, "}"); + writer.WriteIndentedLine(); +} + void Generate_ChecksumResultClass(StreamWriter writer, int typeArgNumber = -1) { if (typeArgNumber <= 0) { - writer.WriteIndentedLine(1, "class ChecksumResult : IResult"); + writer.WriteIndentedLine(1, "abstract class ChecksumResult : IResult"); writer.WriteIndentedLine(1, "{"); writer.WriteIndentedLine(2, "public ChecksumResult(int checksum = 0)"); writer.WriteIndentedLine(2, "{"); @@ -550,7 +766,7 @@ void Generate_ChecksumResultClass(StreamWriter writer, int typeArgNumber = -1) writer.WriteLine(); writer.WriteIndentedLine(2, "public Task ExecuteAsync(HttpContext httpContext)"); writer.WriteIndentedLine(2, "{"); - writer.WriteIndentedLine(3, "httpContext.Items[this] = Checksum;"); + writer.WriteIndentedLine(3, "httpContext.Items[nameof(ChecksumResult.Checksum)] = Checksum;"); writer.WriteIndentedLine(3, "return Task.CompletedTask;"); writer.WriteIndentedLine(2, "}"); writer.WriteIndentedLine(1, "}"); @@ -649,4 +865,11 @@ public static void WriteIndentedLine(this StreamWriter writer, int count, string 20 => "twentieth", _ => throw new NotImplementedException("Add more numbers") }; + + public static string TitleCase(this string value) => String.Create(value.Length, value, (c, s) => + { + var origValueSpan = s.AsSpan(); + c[0] = char.ToUpper(origValueSpan[0], CultureInfo.InvariantCulture); + origValueSpan.Slice(1).TryCopyTo(c.Slice(1)); + }); } From aacfa5ac26341294d362402f0dc6b7a7aa59b715 Mon Sep 17 00:00:00 2001 From: Damian Edwards Date: Wed, 6 Apr 2022 14:32:15 -0700 Subject: [PATCH 16/19] Fix build errors/warnings --- .../Http.Results/src/PublicAPI.Unshipped.txt | 115 ------------------ src/Http/Http.Results/test/ResultsOfTTests.cs | 7 +- .../tools/ResultsOfTGenerator/Program.cs | 8 +- 3 files changed, 8 insertions(+), 122 deletions(-) diff --git a/src/Http/Http.Results/src/PublicAPI.Unshipped.txt b/src/Http/Http.Results/src/PublicAPI.Unshipped.txt index cf3faed7c709..66e7993893eb 100644 --- a/src/Http/Http.Results/src/PublicAPI.Unshipped.txt +++ b/src/Http/Http.Results/src/PublicAPI.Unshipped.txt @@ -192,121 +192,6 @@ static Microsoft.AspNetCore.Http.Results.Bytes(System.ReadOnlyMemory conte static Microsoft.AspNetCore.Http.Results.Empty.get -> Microsoft.AspNetCore.Http.IResult! static Microsoft.AspNetCore.Http.Results.Stream(System.Func! streamWriterCallback, string? contentType = null, string? fileDownloadName = null, System.DateTimeOffset? lastModified = null, Microsoft.Net.Http.Headers.EntityTagHeaderValue? entityTag = null) -> Microsoft.AspNetCore.Http.IResult! static Microsoft.AspNetCore.Http.Results.Stream(System.IO.Pipelines.PipeReader! pipeReader, string? contentType = null, string? fileDownloadName = null, System.DateTimeOffset? lastModified = null, Microsoft.Net.Http.Headers.EntityTagHeaderValue? entityTag = null, bool enableRangeProcessing = false) -> Microsoft.AspNetCore.Http.IResult! -static Microsoft.AspNetCore.Http.Results.implicit operator Microsoft.AspNetCore.Http.Results!(TResult1 result) -> Microsoft.AspNetCore.Http.Results! -static Microsoft.AspNetCore.Http.Results.implicit operator Microsoft.AspNetCore.Http.Results!(TResult10 result) -> Microsoft.AspNetCore.Http.Results! -static Microsoft.AspNetCore.Http.Results.implicit operator Microsoft.AspNetCore.Http.Results!(TResult11 result) -> Microsoft.AspNetCore.Http.Results! -static Microsoft.AspNetCore.Http.Results.implicit operator Microsoft.AspNetCore.Http.Results!(TResult12 result) -> Microsoft.AspNetCore.Http.Results! -static Microsoft.AspNetCore.Http.Results.implicit operator Microsoft.AspNetCore.Http.Results!(TResult13 result) -> Microsoft.AspNetCore.Http.Results! -static Microsoft.AspNetCore.Http.Results.implicit operator Microsoft.AspNetCore.Http.Results!(TResult14 result) -> Microsoft.AspNetCore.Http.Results! -static Microsoft.AspNetCore.Http.Results.implicit operator Microsoft.AspNetCore.Http.Results!(TResult15 result) -> Microsoft.AspNetCore.Http.Results! -static Microsoft.AspNetCore.Http.Results.implicit operator Microsoft.AspNetCore.Http.Results!(TResult16 result) -> Microsoft.AspNetCore.Http.Results! -static Microsoft.AspNetCore.Http.Results.implicit operator Microsoft.AspNetCore.Http.Results!(TResult2 result) -> Microsoft.AspNetCore.Http.Results! -static Microsoft.AspNetCore.Http.Results.implicit operator Microsoft.AspNetCore.Http.Results!(TResult3 result) -> Microsoft.AspNetCore.Http.Results! -static Microsoft.AspNetCore.Http.Results.implicit operator Microsoft.AspNetCore.Http.Results!(TResult4 result) -> Microsoft.AspNetCore.Http.Results! -static Microsoft.AspNetCore.Http.Results.implicit operator Microsoft.AspNetCore.Http.Results!(TResult5 result) -> Microsoft.AspNetCore.Http.Results! -static Microsoft.AspNetCore.Http.Results.implicit operator Microsoft.AspNetCore.Http.Results!(TResult6 result) -> Microsoft.AspNetCore.Http.Results! -static Microsoft.AspNetCore.Http.Results.implicit operator Microsoft.AspNetCore.Http.Results!(TResult7 result) -> Microsoft.AspNetCore.Http.Results! -static Microsoft.AspNetCore.Http.Results.implicit operator Microsoft.AspNetCore.Http.Results!(TResult8 result) -> Microsoft.AspNetCore.Http.Results! -static Microsoft.AspNetCore.Http.Results.implicit operator Microsoft.AspNetCore.Http.Results!(TResult9 result) -> Microsoft.AspNetCore.Http.Results! -static Microsoft.AspNetCore.Http.Results.implicit operator Microsoft.AspNetCore.Http.Results!(TResult1 result) -> Microsoft.AspNetCore.Http.Results! -static Microsoft.AspNetCore.Http.Results.implicit operator Microsoft.AspNetCore.Http.Results!(TResult10 result) -> Microsoft.AspNetCore.Http.Results! -static Microsoft.AspNetCore.Http.Results.implicit operator Microsoft.AspNetCore.Http.Results!(TResult11 result) -> Microsoft.AspNetCore.Http.Results! -static Microsoft.AspNetCore.Http.Results.implicit operator Microsoft.AspNetCore.Http.Results!(TResult12 result) -> Microsoft.AspNetCore.Http.Results! -static Microsoft.AspNetCore.Http.Results.implicit operator Microsoft.AspNetCore.Http.Results!(TResult13 result) -> Microsoft.AspNetCore.Http.Results! -static Microsoft.AspNetCore.Http.Results.implicit operator Microsoft.AspNetCore.Http.Results!(TResult14 result) -> Microsoft.AspNetCore.Http.Results! -static Microsoft.AspNetCore.Http.Results.implicit operator Microsoft.AspNetCore.Http.Results!(TResult15 result) -> Microsoft.AspNetCore.Http.Results! -static Microsoft.AspNetCore.Http.Results.implicit operator Microsoft.AspNetCore.Http.Results!(TResult2 result) -> Microsoft.AspNetCore.Http.Results! -static Microsoft.AspNetCore.Http.Results.implicit operator Microsoft.AspNetCore.Http.Results!(TResult3 result) -> Microsoft.AspNetCore.Http.Results! -static Microsoft.AspNetCore.Http.Results.implicit operator Microsoft.AspNetCore.Http.Results!(TResult4 result) -> Microsoft.AspNetCore.Http.Results! -static Microsoft.AspNetCore.Http.Results.implicit operator Microsoft.AspNetCore.Http.Results!(TResult5 result) -> Microsoft.AspNetCore.Http.Results! -static Microsoft.AspNetCore.Http.Results.implicit operator Microsoft.AspNetCore.Http.Results!(TResult6 result) -> Microsoft.AspNetCore.Http.Results! -static Microsoft.AspNetCore.Http.Results.implicit operator Microsoft.AspNetCore.Http.Results!(TResult7 result) -> Microsoft.AspNetCore.Http.Results! -static Microsoft.AspNetCore.Http.Results.implicit operator Microsoft.AspNetCore.Http.Results!(TResult8 result) -> Microsoft.AspNetCore.Http.Results! -static Microsoft.AspNetCore.Http.Results.implicit operator Microsoft.AspNetCore.Http.Results!(TResult9 result) -> Microsoft.AspNetCore.Http.Results! -static Microsoft.AspNetCore.Http.Results.implicit operator Microsoft.AspNetCore.Http.Results!(TResult1 result) -> Microsoft.AspNetCore.Http.Results! -static Microsoft.AspNetCore.Http.Results.implicit operator Microsoft.AspNetCore.Http.Results!(TResult10 result) -> Microsoft.AspNetCore.Http.Results! -static Microsoft.AspNetCore.Http.Results.implicit operator Microsoft.AspNetCore.Http.Results!(TResult11 result) -> Microsoft.AspNetCore.Http.Results! -static Microsoft.AspNetCore.Http.Results.implicit operator Microsoft.AspNetCore.Http.Results!(TResult12 result) -> Microsoft.AspNetCore.Http.Results! -static Microsoft.AspNetCore.Http.Results.implicit operator Microsoft.AspNetCore.Http.Results!(TResult13 result) -> Microsoft.AspNetCore.Http.Results! -static Microsoft.AspNetCore.Http.Results.implicit operator Microsoft.AspNetCore.Http.Results!(TResult14 result) -> Microsoft.AspNetCore.Http.Results! -static Microsoft.AspNetCore.Http.Results.implicit operator Microsoft.AspNetCore.Http.Results!(TResult2 result) -> Microsoft.AspNetCore.Http.Results! -static Microsoft.AspNetCore.Http.Results.implicit operator Microsoft.AspNetCore.Http.Results!(TResult3 result) -> Microsoft.AspNetCore.Http.Results! -static Microsoft.AspNetCore.Http.Results.implicit operator Microsoft.AspNetCore.Http.Results!(TResult4 result) -> Microsoft.AspNetCore.Http.Results! -static Microsoft.AspNetCore.Http.Results.implicit operator Microsoft.AspNetCore.Http.Results!(TResult5 result) -> Microsoft.AspNetCore.Http.Results! -static Microsoft.AspNetCore.Http.Results.implicit operator Microsoft.AspNetCore.Http.Results!(TResult6 result) -> Microsoft.AspNetCore.Http.Results! -static Microsoft.AspNetCore.Http.Results.implicit operator Microsoft.AspNetCore.Http.Results!(TResult7 result) -> Microsoft.AspNetCore.Http.Results! -static Microsoft.AspNetCore.Http.Results.implicit operator Microsoft.AspNetCore.Http.Results!(TResult8 result) -> Microsoft.AspNetCore.Http.Results! -static Microsoft.AspNetCore.Http.Results.implicit operator Microsoft.AspNetCore.Http.Results!(TResult9 result) -> Microsoft.AspNetCore.Http.Results! -static Microsoft.AspNetCore.Http.Results.implicit operator Microsoft.AspNetCore.Http.Results!(TResult1 result) -> Microsoft.AspNetCore.Http.Results! -static Microsoft.AspNetCore.Http.Results.implicit operator Microsoft.AspNetCore.Http.Results!(TResult10 result) -> Microsoft.AspNetCore.Http.Results! -static Microsoft.AspNetCore.Http.Results.implicit operator Microsoft.AspNetCore.Http.Results!(TResult11 result) -> Microsoft.AspNetCore.Http.Results! -static Microsoft.AspNetCore.Http.Results.implicit operator Microsoft.AspNetCore.Http.Results!(TResult12 result) -> Microsoft.AspNetCore.Http.Results! -static Microsoft.AspNetCore.Http.Results.implicit operator Microsoft.AspNetCore.Http.Results!(TResult13 result) -> Microsoft.AspNetCore.Http.Results! -static Microsoft.AspNetCore.Http.Results.implicit operator Microsoft.AspNetCore.Http.Results!(TResult2 result) -> Microsoft.AspNetCore.Http.Results! -static Microsoft.AspNetCore.Http.Results.implicit operator Microsoft.AspNetCore.Http.Results!(TResult3 result) -> Microsoft.AspNetCore.Http.Results! -static Microsoft.AspNetCore.Http.Results.implicit operator Microsoft.AspNetCore.Http.Results!(TResult4 result) -> Microsoft.AspNetCore.Http.Results! -static Microsoft.AspNetCore.Http.Results.implicit operator Microsoft.AspNetCore.Http.Results!(TResult5 result) -> Microsoft.AspNetCore.Http.Results! -static Microsoft.AspNetCore.Http.Results.implicit operator Microsoft.AspNetCore.Http.Results!(TResult6 result) -> Microsoft.AspNetCore.Http.Results! -static Microsoft.AspNetCore.Http.Results.implicit operator Microsoft.AspNetCore.Http.Results!(TResult7 result) -> Microsoft.AspNetCore.Http.Results! -static Microsoft.AspNetCore.Http.Results.implicit operator Microsoft.AspNetCore.Http.Results!(TResult8 result) -> Microsoft.AspNetCore.Http.Results! -static Microsoft.AspNetCore.Http.Results.implicit operator Microsoft.AspNetCore.Http.Results!(TResult9 result) -> Microsoft.AspNetCore.Http.Results! -static Microsoft.AspNetCore.Http.Results.implicit operator Microsoft.AspNetCore.Http.Results!(TResult1 result) -> Microsoft.AspNetCore.Http.Results! -static Microsoft.AspNetCore.Http.Results.implicit operator Microsoft.AspNetCore.Http.Results!(TResult10 result) -> Microsoft.AspNetCore.Http.Results! -static Microsoft.AspNetCore.Http.Results.implicit operator Microsoft.AspNetCore.Http.Results!(TResult11 result) -> Microsoft.AspNetCore.Http.Results! -static Microsoft.AspNetCore.Http.Results.implicit operator Microsoft.AspNetCore.Http.Results!(TResult12 result) -> Microsoft.AspNetCore.Http.Results! -static Microsoft.AspNetCore.Http.Results.implicit operator Microsoft.AspNetCore.Http.Results!(TResult2 result) -> Microsoft.AspNetCore.Http.Results! -static Microsoft.AspNetCore.Http.Results.implicit operator Microsoft.AspNetCore.Http.Results!(TResult3 result) -> Microsoft.AspNetCore.Http.Results! -static Microsoft.AspNetCore.Http.Results.implicit operator Microsoft.AspNetCore.Http.Results!(TResult4 result) -> Microsoft.AspNetCore.Http.Results! -static Microsoft.AspNetCore.Http.Results.implicit operator Microsoft.AspNetCore.Http.Results!(TResult5 result) -> Microsoft.AspNetCore.Http.Results! -static Microsoft.AspNetCore.Http.Results.implicit operator Microsoft.AspNetCore.Http.Results!(TResult6 result) -> Microsoft.AspNetCore.Http.Results! -static Microsoft.AspNetCore.Http.Results.implicit operator Microsoft.AspNetCore.Http.Results!(TResult7 result) -> Microsoft.AspNetCore.Http.Results! -static Microsoft.AspNetCore.Http.Results.implicit operator Microsoft.AspNetCore.Http.Results!(TResult8 result) -> Microsoft.AspNetCore.Http.Results! -static Microsoft.AspNetCore.Http.Results.implicit operator Microsoft.AspNetCore.Http.Results!(TResult9 result) -> Microsoft.AspNetCore.Http.Results! -static Microsoft.AspNetCore.Http.Results.implicit operator Microsoft.AspNetCore.Http.Results!(TResult1 result) -> Microsoft.AspNetCore.Http.Results! -static Microsoft.AspNetCore.Http.Results.implicit operator Microsoft.AspNetCore.Http.Results!(TResult10 result) -> Microsoft.AspNetCore.Http.Results! -static Microsoft.AspNetCore.Http.Results.implicit operator Microsoft.AspNetCore.Http.Results!(TResult11 result) -> Microsoft.AspNetCore.Http.Results! -static Microsoft.AspNetCore.Http.Results.implicit operator Microsoft.AspNetCore.Http.Results!(TResult2 result) -> Microsoft.AspNetCore.Http.Results! -static Microsoft.AspNetCore.Http.Results.implicit operator Microsoft.AspNetCore.Http.Results!(TResult3 result) -> Microsoft.AspNetCore.Http.Results! -static Microsoft.AspNetCore.Http.Results.implicit operator Microsoft.AspNetCore.Http.Results!(TResult4 result) -> Microsoft.AspNetCore.Http.Results! -static Microsoft.AspNetCore.Http.Results.implicit operator Microsoft.AspNetCore.Http.Results!(TResult5 result) -> Microsoft.AspNetCore.Http.Results! -static Microsoft.AspNetCore.Http.Results.implicit operator Microsoft.AspNetCore.Http.Results!(TResult6 result) -> Microsoft.AspNetCore.Http.Results! -static Microsoft.AspNetCore.Http.Results.implicit operator Microsoft.AspNetCore.Http.Results!(TResult7 result) -> Microsoft.AspNetCore.Http.Results! -static Microsoft.AspNetCore.Http.Results.implicit operator Microsoft.AspNetCore.Http.Results!(TResult8 result) -> Microsoft.AspNetCore.Http.Results! -static Microsoft.AspNetCore.Http.Results.implicit operator Microsoft.AspNetCore.Http.Results!(TResult9 result) -> Microsoft.AspNetCore.Http.Results! -static Microsoft.AspNetCore.Http.Results.implicit operator Microsoft.AspNetCore.Http.Results!(TResult1 result) -> Microsoft.AspNetCore.Http.Results! -static Microsoft.AspNetCore.Http.Results.implicit operator Microsoft.AspNetCore.Http.Results!(TResult10 result) -> Microsoft.AspNetCore.Http.Results! -static Microsoft.AspNetCore.Http.Results.implicit operator Microsoft.AspNetCore.Http.Results!(TResult2 result) -> Microsoft.AspNetCore.Http.Results! -static Microsoft.AspNetCore.Http.Results.implicit operator Microsoft.AspNetCore.Http.Results!(TResult3 result) -> Microsoft.AspNetCore.Http.Results! -static Microsoft.AspNetCore.Http.Results.implicit operator Microsoft.AspNetCore.Http.Results!(TResult4 result) -> Microsoft.AspNetCore.Http.Results! -static Microsoft.AspNetCore.Http.Results.implicit operator Microsoft.AspNetCore.Http.Results!(TResult5 result) -> Microsoft.AspNetCore.Http.Results! -static Microsoft.AspNetCore.Http.Results.implicit operator Microsoft.AspNetCore.Http.Results!(TResult6 result) -> Microsoft.AspNetCore.Http.Results! -static Microsoft.AspNetCore.Http.Results.implicit operator Microsoft.AspNetCore.Http.Results!(TResult7 result) -> Microsoft.AspNetCore.Http.Results! -static Microsoft.AspNetCore.Http.Results.implicit operator Microsoft.AspNetCore.Http.Results!(TResult8 result) -> Microsoft.AspNetCore.Http.Results! -static Microsoft.AspNetCore.Http.Results.implicit operator Microsoft.AspNetCore.Http.Results!(TResult9 result) -> Microsoft.AspNetCore.Http.Results! -static Microsoft.AspNetCore.Http.Results.implicit operator Microsoft.AspNetCore.Http.Results!(TResult1 result) -> Microsoft.AspNetCore.Http.Results! -static Microsoft.AspNetCore.Http.Results.implicit operator Microsoft.AspNetCore.Http.Results!(TResult2 result) -> Microsoft.AspNetCore.Http.Results! -static Microsoft.AspNetCore.Http.Results.implicit operator Microsoft.AspNetCore.Http.Results!(TResult3 result) -> Microsoft.AspNetCore.Http.Results! -static Microsoft.AspNetCore.Http.Results.implicit operator Microsoft.AspNetCore.Http.Results!(TResult4 result) -> Microsoft.AspNetCore.Http.Results! -static Microsoft.AspNetCore.Http.Results.implicit operator Microsoft.AspNetCore.Http.Results!(TResult5 result) -> Microsoft.AspNetCore.Http.Results! -static Microsoft.AspNetCore.Http.Results.implicit operator Microsoft.AspNetCore.Http.Results!(TResult6 result) -> Microsoft.AspNetCore.Http.Results! -static Microsoft.AspNetCore.Http.Results.implicit operator Microsoft.AspNetCore.Http.Results!(TResult7 result) -> Microsoft.AspNetCore.Http.Results! -static Microsoft.AspNetCore.Http.Results.implicit operator Microsoft.AspNetCore.Http.Results!(TResult8 result) -> Microsoft.AspNetCore.Http.Results! -static Microsoft.AspNetCore.Http.Results.implicit operator Microsoft.AspNetCore.Http.Results!(TResult9 result) -> Microsoft.AspNetCore.Http.Results! -static Microsoft.AspNetCore.Http.Results.implicit operator Microsoft.AspNetCore.Http.Results!(TResult1 result) -> Microsoft.AspNetCore.Http.Results! -static Microsoft.AspNetCore.Http.Results.implicit operator Microsoft.AspNetCore.Http.Results!(TResult2 result) -> Microsoft.AspNetCore.Http.Results! -static Microsoft.AspNetCore.Http.Results.implicit operator Microsoft.AspNetCore.Http.Results!(TResult3 result) -> Microsoft.AspNetCore.Http.Results! -static Microsoft.AspNetCore.Http.Results.implicit operator Microsoft.AspNetCore.Http.Results!(TResult4 result) -> Microsoft.AspNetCore.Http.Results! -static Microsoft.AspNetCore.Http.Results.implicit operator Microsoft.AspNetCore.Http.Results!(TResult5 result) -> Microsoft.AspNetCore.Http.Results! -static Microsoft.AspNetCore.Http.Results.implicit operator Microsoft.AspNetCore.Http.Results!(TResult6 result) -> Microsoft.AspNetCore.Http.Results! -static Microsoft.AspNetCore.Http.Results.implicit operator Microsoft.AspNetCore.Http.Results!(TResult7 result) -> Microsoft.AspNetCore.Http.Results! -static Microsoft.AspNetCore.Http.Results.implicit operator Microsoft.AspNetCore.Http.Results!(TResult8 result) -> Microsoft.AspNetCore.Http.Results! -static Microsoft.AspNetCore.Http.Results.implicit operator Microsoft.AspNetCore.Http.Results!(TResult1 result) -> Microsoft.AspNetCore.Http.Results! -static Microsoft.AspNetCore.Http.Results.implicit operator Microsoft.AspNetCore.Http.Results!(TResult2 result) -> Microsoft.AspNetCore.Http.Results! -static Microsoft.AspNetCore.Http.Results.implicit operator Microsoft.AspNetCore.Http.Results!(TResult3 result) -> Microsoft.AspNetCore.Http.Results! -static Microsoft.AspNetCore.Http.Results.implicit operator Microsoft.AspNetCore.Http.Results!(TResult4 result) -> Microsoft.AspNetCore.Http.Results! -static Microsoft.AspNetCore.Http.Results.implicit operator Microsoft.AspNetCore.Http.Results!(TResult5 result) -> Microsoft.AspNetCore.Http.Results! -static Microsoft.AspNetCore.Http.Results.implicit operator Microsoft.AspNetCore.Http.Results!(TResult6 result) -> Microsoft.AspNetCore.Http.Results! -static Microsoft.AspNetCore.Http.Results.implicit operator Microsoft.AspNetCore.Http.Results!(TResult7 result) -> Microsoft.AspNetCore.Http.Results! static Microsoft.AspNetCore.Http.Results.implicit operator Microsoft.AspNetCore.Http.Results!(TResult1 result) -> Microsoft.AspNetCore.Http.Results! static Microsoft.AspNetCore.Http.Results.implicit operator Microsoft.AspNetCore.Http.Results!(TResult2 result) -> Microsoft.AspNetCore.Http.Results! static Microsoft.AspNetCore.Http.Results.implicit operator Microsoft.AspNetCore.Http.Results!(TResult3 result) -> Microsoft.AspNetCore.Http.Results! diff --git a/src/Http/Http.Results/test/ResultsOfTTests.cs b/src/Http/Http.Results/test/ResultsOfTTests.cs index f5e1fb65aa2d..cc619db9b362 100644 --- a/src/Http/Http.Results/test/ResultsOfTTests.cs +++ b/src/Http/Http.Results/test/ResultsOfTTests.cs @@ -3,7 +3,6 @@ namespace Microsoft.AspNetCore.Http.Result; -using System.Threading.Tasks; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging.Abstractions; @@ -22,8 +21,10 @@ private static HttpContext GetHttpContext() { var services = CreateServices(); - var httpContext = new DefaultHttpContext(); - httpContext.RequestServices = services.BuildServiceProvider(); + var httpContext = new DefaultHttpContext + { + RequestServices = services.BuildServiceProvider() + }; return httpContext; } diff --git a/src/Http/Http.Results/tools/ResultsOfTGenerator/Program.cs b/src/Http/Http.Results/tools/ResultsOfTGenerator/Program.cs index 53a8216df51c..9a0325d81073 100644 --- a/src/Http/Http.Results/tools/ResultsOfTGenerator/Program.cs +++ b/src/Http/Http.Results/tools/ResultsOfTGenerator/Program.cs @@ -683,14 +683,14 @@ void Generate_AcceptsNestedResultsOfT_AsNthTypeArg(StreamWriter writer, int type var sb = new StringBuilder("Results<"); for (int j = 1; j <= typeArgCount; j++) { - sb.Append($"ChecksumResult{j}"); + sb.Append(CultureInfo.InvariantCulture, $"ChecksumResult{j}"); if (j < typeArgCount) { sb.Append(", "); } } - sb.Append(">"); + sb.Append('>'); var nestedResultTypeName = sb.ToString(); // Attributes @@ -866,10 +866,10 @@ public static void WriteIndentedLine(this StreamWriter writer, int count, string _ => throw new NotImplementedException("Add more numbers") }; - public static string TitleCase(this string value) => String.Create(value.Length, value, (c, s) => + public static string TitleCase(this string value) => string.Create(value.Length, value, (c, s) => { var origValueSpan = s.AsSpan(); c[0] = char.ToUpper(origValueSpan[0], CultureInfo.InvariantCulture); - origValueSpan.Slice(1).TryCopyTo(c.Slice(1)); + origValueSpan[1..].TryCopyTo(c[1..]); }); } From 437537b1a9c6bbf596c41fa763f9a647d5b05659 Mon Sep 17 00:00:00 2001 From: Damian Edwards Date: Wed, 6 Apr 2022 14:35:18 -0700 Subject: [PATCH 17/19] Fix PublicAPI.Unshipped.txt --- .../Http.Results/src/PublicAPI.Unshipped.txt | 70 ++++++------------- 1 file changed, 20 insertions(+), 50 deletions(-) diff --git a/src/Http/Http.Results/src/PublicAPI.Unshipped.txt b/src/Http/Http.Results/src/PublicAPI.Unshipped.txt index 66e7993893eb..162a8ca3601f 100644 --- a/src/Http/Http.Results/src/PublicAPI.Unshipped.txt +++ b/src/Http/Http.Results/src/PublicAPI.Unshipped.txt @@ -114,36 +114,6 @@ Microsoft.AspNetCore.Http.RedirectToRouteHttpResult.Permanent.get -> bool Microsoft.AspNetCore.Http.RedirectToRouteHttpResult.PreserveMethod.get -> bool Microsoft.AspNetCore.Http.RedirectToRouteHttpResult.RouteName.get -> string? Microsoft.AspNetCore.Http.RedirectToRouteHttpResult.RouteValues.get -> Microsoft.AspNetCore.Routing.RouteValueDictionary? -Microsoft.AspNetCore.Http.Results -Microsoft.AspNetCore.Http.Results.ExecuteAsync(Microsoft.AspNetCore.Http.HttpContext! httpContext) -> System.Threading.Tasks.Task! -Microsoft.AspNetCore.Http.Results.Result.get -> Microsoft.AspNetCore.Http.IResult! -Microsoft.AspNetCore.Http.Results -Microsoft.AspNetCore.Http.Results.ExecuteAsync(Microsoft.AspNetCore.Http.HttpContext! httpContext) -> System.Threading.Tasks.Task! -Microsoft.AspNetCore.Http.Results.Result.get -> Microsoft.AspNetCore.Http.IResult! -Microsoft.AspNetCore.Http.Results -Microsoft.AspNetCore.Http.Results.ExecuteAsync(Microsoft.AspNetCore.Http.HttpContext! httpContext) -> System.Threading.Tasks.Task! -Microsoft.AspNetCore.Http.Results.Result.get -> Microsoft.AspNetCore.Http.IResult! -Microsoft.AspNetCore.Http.Results -Microsoft.AspNetCore.Http.Results.ExecuteAsync(Microsoft.AspNetCore.Http.HttpContext! httpContext) -> System.Threading.Tasks.Task! -Microsoft.AspNetCore.Http.Results.Result.get -> Microsoft.AspNetCore.Http.IResult! -Microsoft.AspNetCore.Http.Results -Microsoft.AspNetCore.Http.Results.ExecuteAsync(Microsoft.AspNetCore.Http.HttpContext! httpContext) -> System.Threading.Tasks.Task! -Microsoft.AspNetCore.Http.Results.Result.get -> Microsoft.AspNetCore.Http.IResult! -Microsoft.AspNetCore.Http.Results -Microsoft.AspNetCore.Http.Results.ExecuteAsync(Microsoft.AspNetCore.Http.HttpContext! httpContext) -> System.Threading.Tasks.Task! -Microsoft.AspNetCore.Http.Results.Result.get -> Microsoft.AspNetCore.Http.IResult! -Microsoft.AspNetCore.Http.Results -Microsoft.AspNetCore.Http.Results.ExecuteAsync(Microsoft.AspNetCore.Http.HttpContext! httpContext) -> System.Threading.Tasks.Task! -Microsoft.AspNetCore.Http.Results.Result.get -> Microsoft.AspNetCore.Http.IResult! -Microsoft.AspNetCore.Http.Results -Microsoft.AspNetCore.Http.Results.ExecuteAsync(Microsoft.AspNetCore.Http.HttpContext! httpContext) -> System.Threading.Tasks.Task! -Microsoft.AspNetCore.Http.Results.Result.get -> Microsoft.AspNetCore.Http.IResult! -Microsoft.AspNetCore.Http.Results -Microsoft.AspNetCore.Http.Results.ExecuteAsync(Microsoft.AspNetCore.Http.HttpContext! httpContext) -> System.Threading.Tasks.Task! -Microsoft.AspNetCore.Http.Results.Result.get -> Microsoft.AspNetCore.Http.IResult! -Microsoft.AspNetCore.Http.Results -Microsoft.AspNetCore.Http.Results.ExecuteAsync(Microsoft.AspNetCore.Http.HttpContext! httpContext) -> System.Threading.Tasks.Task! -Microsoft.AspNetCore.Http.Results.Result.get -> Microsoft.AspNetCore.Http.IResult! Microsoft.AspNetCore.Http.Results Microsoft.AspNetCore.Http.Results.ExecuteAsync(Microsoft.AspNetCore.Http.HttpContext! httpContext) -> System.Threading.Tasks.Task! Microsoft.AspNetCore.Http.Results.Result.get -> Microsoft.AspNetCore.Http.IResult! @@ -159,6 +129,26 @@ Microsoft.AspNetCore.Http.Results.Result.get -> Mi Microsoft.AspNetCore.Http.Results Microsoft.AspNetCore.Http.Results.ExecuteAsync(Microsoft.AspNetCore.Http.HttpContext! httpContext) -> System.Threading.Tasks.Task! Microsoft.AspNetCore.Http.Results.Result.get -> Microsoft.AspNetCore.Http.IResult! +static Microsoft.AspNetCore.Http.Results.implicit operator Microsoft.AspNetCore.Http.Results!(TResult1 result) -> Microsoft.AspNetCore.Http.Results! +static Microsoft.AspNetCore.Http.Results.implicit operator Microsoft.AspNetCore.Http.Results!(TResult2 result) -> Microsoft.AspNetCore.Http.Results! +static Microsoft.AspNetCore.Http.Results.implicit operator Microsoft.AspNetCore.Http.Results!(TResult3 result) -> Microsoft.AspNetCore.Http.Results! +static Microsoft.AspNetCore.Http.Results.implicit operator Microsoft.AspNetCore.Http.Results!(TResult4 result) -> Microsoft.AspNetCore.Http.Results! +static Microsoft.AspNetCore.Http.Results.implicit operator Microsoft.AspNetCore.Http.Results!(TResult5 result) -> Microsoft.AspNetCore.Http.Results! +static Microsoft.AspNetCore.Http.Results.implicit operator Microsoft.AspNetCore.Http.Results!(TResult6 result) -> Microsoft.AspNetCore.Http.Results! +static Microsoft.AspNetCore.Http.Results.implicit operator Microsoft.AspNetCore.Http.Results!(TResult1 result) -> Microsoft.AspNetCore.Http.Results! +static Microsoft.AspNetCore.Http.Results.implicit operator Microsoft.AspNetCore.Http.Results!(TResult2 result) -> Microsoft.AspNetCore.Http.Results! +static Microsoft.AspNetCore.Http.Results.implicit operator Microsoft.AspNetCore.Http.Results!(TResult3 result) -> Microsoft.AspNetCore.Http.Results! +static Microsoft.AspNetCore.Http.Results.implicit operator Microsoft.AspNetCore.Http.Results!(TResult4 result) -> Microsoft.AspNetCore.Http.Results! +static Microsoft.AspNetCore.Http.Results.implicit operator Microsoft.AspNetCore.Http.Results!(TResult5 result) -> Microsoft.AspNetCore.Http.Results! +static Microsoft.AspNetCore.Http.Results.implicit operator Microsoft.AspNetCore.Http.Results!(TResult1 result) -> Microsoft.AspNetCore.Http.Results! +static Microsoft.AspNetCore.Http.Results.implicit operator Microsoft.AspNetCore.Http.Results!(TResult2 result) -> Microsoft.AspNetCore.Http.Results! +static Microsoft.AspNetCore.Http.Results.implicit operator Microsoft.AspNetCore.Http.Results!(TResult3 result) -> Microsoft.AspNetCore.Http.Results! +static Microsoft.AspNetCore.Http.Results.implicit operator Microsoft.AspNetCore.Http.Results!(TResult4 result) -> Microsoft.AspNetCore.Http.Results! +static Microsoft.AspNetCore.Http.Results.implicit operator Microsoft.AspNetCore.Http.Results!(TResult1 result) -> Microsoft.AspNetCore.Http.Results! +static Microsoft.AspNetCore.Http.Results.implicit operator Microsoft.AspNetCore.Http.Results!(TResult2 result) -> Microsoft.AspNetCore.Http.Results! +static Microsoft.AspNetCore.Http.Results.implicit operator Microsoft.AspNetCore.Http.Results!(TResult3 result) -> Microsoft.AspNetCore.Http.Results! +static Microsoft.AspNetCore.Http.Results.implicit operator Microsoft.AspNetCore.Http.Results!(TResult1 result) -> Microsoft.AspNetCore.Http.Results! +static Microsoft.AspNetCore.Http.Results.implicit operator Microsoft.AspNetCore.Http.Results!(TResult2 result) -> Microsoft.AspNetCore.Http.Results! Microsoft.AspNetCore.Http.SignInHttpResult Microsoft.AspNetCore.Http.SignInHttpResult.AuthenticationScheme.get -> string? Microsoft.AspNetCore.Http.SignInHttpResult.ExecuteAsync(Microsoft.AspNetCore.Http.HttpContext! httpContext) -> System.Threading.Tasks.Task! @@ -192,23 +182,3 @@ static Microsoft.AspNetCore.Http.Results.Bytes(System.ReadOnlyMemory conte static Microsoft.AspNetCore.Http.Results.Empty.get -> Microsoft.AspNetCore.Http.IResult! static Microsoft.AspNetCore.Http.Results.Stream(System.Func! streamWriterCallback, string? contentType = null, string? fileDownloadName = null, System.DateTimeOffset? lastModified = null, Microsoft.Net.Http.Headers.EntityTagHeaderValue? entityTag = null) -> Microsoft.AspNetCore.Http.IResult! static Microsoft.AspNetCore.Http.Results.Stream(System.IO.Pipelines.PipeReader! pipeReader, string? contentType = null, string? fileDownloadName = null, System.DateTimeOffset? lastModified = null, Microsoft.Net.Http.Headers.EntityTagHeaderValue? entityTag = null, bool enableRangeProcessing = false) -> Microsoft.AspNetCore.Http.IResult! -static Microsoft.AspNetCore.Http.Results.implicit operator Microsoft.AspNetCore.Http.Results!(TResult1 result) -> Microsoft.AspNetCore.Http.Results! -static Microsoft.AspNetCore.Http.Results.implicit operator Microsoft.AspNetCore.Http.Results!(TResult2 result) -> Microsoft.AspNetCore.Http.Results! -static Microsoft.AspNetCore.Http.Results.implicit operator Microsoft.AspNetCore.Http.Results!(TResult3 result) -> Microsoft.AspNetCore.Http.Results! -static Microsoft.AspNetCore.Http.Results.implicit operator Microsoft.AspNetCore.Http.Results!(TResult4 result) -> Microsoft.AspNetCore.Http.Results! -static Microsoft.AspNetCore.Http.Results.implicit operator Microsoft.AspNetCore.Http.Results!(TResult5 result) -> Microsoft.AspNetCore.Http.Results! -static Microsoft.AspNetCore.Http.Results.implicit operator Microsoft.AspNetCore.Http.Results!(TResult6 result) -> Microsoft.AspNetCore.Http.Results! -static Microsoft.AspNetCore.Http.Results.implicit operator Microsoft.AspNetCore.Http.Results!(TResult1 result) -> Microsoft.AspNetCore.Http.Results! -static Microsoft.AspNetCore.Http.Results.implicit operator Microsoft.AspNetCore.Http.Results!(TResult2 result) -> Microsoft.AspNetCore.Http.Results! -static Microsoft.AspNetCore.Http.Results.implicit operator Microsoft.AspNetCore.Http.Results!(TResult3 result) -> Microsoft.AspNetCore.Http.Results! -static Microsoft.AspNetCore.Http.Results.implicit operator Microsoft.AspNetCore.Http.Results!(TResult4 result) -> Microsoft.AspNetCore.Http.Results! -static Microsoft.AspNetCore.Http.Results.implicit operator Microsoft.AspNetCore.Http.Results!(TResult5 result) -> Microsoft.AspNetCore.Http.Results! -static Microsoft.AspNetCore.Http.Results.implicit operator Microsoft.AspNetCore.Http.Results!(TResult1 result) -> Microsoft.AspNetCore.Http.Results! -static Microsoft.AspNetCore.Http.Results.implicit operator Microsoft.AspNetCore.Http.Results!(TResult2 result) -> Microsoft.AspNetCore.Http.Results! -static Microsoft.AspNetCore.Http.Results.implicit operator Microsoft.AspNetCore.Http.Results!(TResult3 result) -> Microsoft.AspNetCore.Http.Results! -static Microsoft.AspNetCore.Http.Results.implicit operator Microsoft.AspNetCore.Http.Results!(TResult4 result) -> Microsoft.AspNetCore.Http.Results! -static Microsoft.AspNetCore.Http.Results.implicit operator Microsoft.AspNetCore.Http.Results!(TResult1 result) -> Microsoft.AspNetCore.Http.Results! -static Microsoft.AspNetCore.Http.Results.implicit operator Microsoft.AspNetCore.Http.Results!(TResult2 result) -> Microsoft.AspNetCore.Http.Results! -static Microsoft.AspNetCore.Http.Results.implicit operator Microsoft.AspNetCore.Http.Results!(TResult3 result) -> Microsoft.AspNetCore.Http.Results! -static Microsoft.AspNetCore.Http.Results.implicit operator Microsoft.AspNetCore.Http.Results!(TResult1 result) -> Microsoft.AspNetCore.Http.Results! -static Microsoft.AspNetCore.Http.Results.implicit operator Microsoft.AspNetCore.Http.Results!(TResult2 result) -> Microsoft.AspNetCore.Http.Results! From 768b5ee09534b9825580dbcfa21d57abf056cb20 Mon Sep 17 00:00:00 2001 From: Damian Edwards Date: Wed, 6 Apr 2022 17:44:47 -0700 Subject: [PATCH 18/19] Address PR feedback --- src/Http/Http.Results/src/ResultsOfT.cs | 20 +- ...osoft.AspNetCore.Http.Results.Tests.csproj | 7 +- src/Http/Http.Results/test/ResultsOfTTests.cs | 55 + .../tools/ResultsOfTGenerator/Program.cs | 1354 +++++++++-------- 4 files changed, 765 insertions(+), 671 deletions(-) diff --git a/src/Http/Http.Results/src/ResultsOfT.cs b/src/Http/Http.Results/src/ResultsOfT.cs index 75488be1c701..029d0aeed5f0 100644 --- a/src/Http/Http.Results/src/ResultsOfT.cs +++ b/src/Http/Http.Results/src/ResultsOfT.cs @@ -31,7 +31,7 @@ private Results(IResult activeResult) public IResult Result { get; } /// - public async Task ExecuteAsync(HttpContext httpContext) + public Task ExecuteAsync(HttpContext httpContext) { ArgumentNullException.ThrowIfNull(httpContext, nameof(httpContext)); @@ -40,7 +40,7 @@ public async Task ExecuteAsync(HttpContext httpContext) throw new InvalidOperationException("The IResult assigned to the Result property must not be null."); } - await Result.ExecuteAsync(httpContext); + return Result.ExecuteAsync(httpContext); } /// @@ -85,7 +85,7 @@ private Results(IResult activeResult) public IResult Result { get; } /// - public async Task ExecuteAsync(HttpContext httpContext) + public Task ExecuteAsync(HttpContext httpContext) { ArgumentNullException.ThrowIfNull(httpContext, nameof(httpContext)); @@ -94,7 +94,7 @@ public async Task ExecuteAsync(HttpContext httpContext) throw new InvalidOperationException("The IResult assigned to the Result property must not be null."); } - await Result.ExecuteAsync(httpContext); + return Result.ExecuteAsync(httpContext); } /// @@ -147,7 +147,7 @@ private Results(IResult activeResult) public IResult Result { get; } /// - public async Task ExecuteAsync(HttpContext httpContext) + public Task ExecuteAsync(HttpContext httpContext) { ArgumentNullException.ThrowIfNull(httpContext, nameof(httpContext)); @@ -156,7 +156,7 @@ public async Task ExecuteAsync(HttpContext httpContext) throw new InvalidOperationException("The IResult assigned to the Result property must not be null."); } - await Result.ExecuteAsync(httpContext); + return Result.ExecuteAsync(httpContext); } /// @@ -217,7 +217,7 @@ private Results(IResult activeResult) public IResult Result { get; } /// - public async Task ExecuteAsync(HttpContext httpContext) + public Task ExecuteAsync(HttpContext httpContext) { ArgumentNullException.ThrowIfNull(httpContext, nameof(httpContext)); @@ -226,7 +226,7 @@ public async Task ExecuteAsync(HttpContext httpContext) throw new InvalidOperationException("The IResult assigned to the Result property must not be null."); } - await Result.ExecuteAsync(httpContext); + return Result.ExecuteAsync(httpContext); } /// @@ -295,7 +295,7 @@ private Results(IResult activeResult) public IResult Result { get; } /// - public async Task ExecuteAsync(HttpContext httpContext) + public Task ExecuteAsync(HttpContext httpContext) { ArgumentNullException.ThrowIfNull(httpContext, nameof(httpContext)); @@ -304,7 +304,7 @@ public async Task ExecuteAsync(HttpContext httpContext) throw new InvalidOperationException("The IResult assigned to the Result property must not be null."); } - await Result.ExecuteAsync(httpContext); + return Result.ExecuteAsync(httpContext); } /// diff --git a/src/Http/Http.Results/test/Microsoft.AspNetCore.Http.Results.Tests.csproj b/src/Http/Http.Results/test/Microsoft.AspNetCore.Http.Results.Tests.csproj index 270acfe04ebb..f59c42ded08a 100644 --- a/src/Http/Http.Results/test/Microsoft.AspNetCore.Http.Results.Tests.csproj +++ b/src/Http/Http.Results/test/Microsoft.AspNetCore.Http.Results.Tests.csproj @@ -1,4 +1,4 @@ - + $(DefaultNetCoreTargetFramework) @@ -9,7 +9,12 @@ + + + + + diff --git a/src/Http/Http.Results/test/ResultsOfTTests.cs b/src/Http/Http.Results/test/ResultsOfTTests.cs index cc619db9b362..c96a0dc6adce 100644 --- a/src/Http/Http.Results/test/ResultsOfTTests.cs +++ b/src/Http/Http.Results/test/ResultsOfTTests.cs @@ -6,9 +6,47 @@ namespace Microsoft.AspNetCore.Http.Result; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging.Abstractions; +using Xunit.Abstractions; public partial class ResultsOfTTests { + private readonly ITestOutputHelper _output; + + public ResultsOfTTests(ITestOutputHelper output) + { + _output = output; + } + + [Fact] + public void GeneratedCodeIsUpToDate() + { + // This assumes the output is in the repo artifacts directory + var resultsOfTGeneratedPath = Path.Combine(AppContext.BaseDirectory, "Shared", "GeneratedContent", "ResultsOfT.cs"); + var testsGeneratedPath = Path.Combine(AppContext.BaseDirectory, "Shared", "GeneratedContent", "ResultsOfTTests.Generated.cs"); + + var testResultsOfTGeneratedPath = Path.GetTempFileName(); + var testTestsGeneratedPath = Path.GetTempFileName(); + + try + { + var currentResultsOfTGenerated = File.ReadAllText(resultsOfTGeneratedPath); + var currentTestsGenerated = File.ReadAllText(testsGeneratedPath); + + ResultsOfTGenerator.Program.Run(testResultsOfTGeneratedPath, testTestsGeneratedPath); + + var testResultsOfTGenerated = File.ReadAllText(testResultsOfTGeneratedPath); + var testTestsGenerated = File.ReadAllText(testTestsGeneratedPath); + + AssertFileContentEqual(currentResultsOfTGenerated, testResultsOfTGenerated, "ResultsOfT.cs"); + AssertFileContentEqual(currentTestsGenerated, testTestsGenerated, "ResultsOfTTests.Generated.cs"); + } + finally + { + File.Delete(testResultsOfTGeneratedPath); + File.Delete(testTestsGeneratedPath); + } + } + private static IServiceCollection CreateServices() { var services = new ServiceCollection(); @@ -28,4 +66,21 @@ private static HttpContext GetHttpContext() return httpContext; } + + private void AssertFileContentEqual(string expected, string actual, string type) + { + try + { + Assert.Equal(expected.Trim(), actual.Trim(), ignoreLineEndingDifferences: true); + } + catch (Exception) + { + _output.WriteLine($"Error when comparing {type}."); + _output.WriteLine("Expected:"); + _output.WriteLine(expected); + _output.WriteLine("Actual:"); + _output.WriteLine(actual); + throw; + } + } } diff --git a/src/Http/Http.Results/tools/ResultsOfTGenerator/Program.cs b/src/Http/Http.Results/tools/ResultsOfTGenerator/Program.cs index 9a0325d81073..502313ea07e0 100644 --- a/src/Http/Http.Results/tools/ResultsOfTGenerator/Program.cs +++ b/src/Http/Http.Results/tools/ResultsOfTGenerator/Program.cs @@ -4,788 +4,822 @@ using System.Globalization; using System.Text; -var className = "Results"; -var typeArgCount = 6; -var typeArgName = "TResult"; -var pwd = Directory.GetCurrentDirectory(); +namespace ResultsOfTGenerator; -GenerateClassFile(Path.Join(pwd, $"{className}OfT.cs")); +public class Program +{ + private const int TYPE_ARG_COUNT = 6; -Console.WriteLine(); + public static void Main(string[] args) + { + // By default we assume we're being run in the context of the /src/Http/Http.Results/src + var pwd = Directory.GetCurrentDirectory(); + var classTargetFilePath = Path.Combine(pwd, "ResultsOfT.cs"); + var testsTargetFilePath = Path.Combine(pwd, "..", "test", "ResultsOfTTests.Generated.cs"); -GenerateTestFiles(Path.Join(pwd, $"..{Path.DirectorySeparatorChar}test", $"{className}OfTTests.Generated.cs")); + if (args.Length > 0) + { + if (args.Length != 2) + { + throw new ArgumentException("Invalid number of args specified. Must specify both class file path and test file path if args are passed."); + } -void GenerateClassFile(string classFilePath) -{ - Console.WriteLine($"Will generate class file at {classFilePath}"); - Console.WriteLine("Press any key to continue or Ctrl-C to cancel"); - Console.ReadKey(); + classTargetFilePath = args[0]; + testsTargetFilePath = args[1]; + } - using var writer = new StreamWriter(classFilePath, append: false); + GenerateClassFile(classTargetFilePath, TYPE_ARG_COUNT, args.Length == 0); + + GenerateTestFiles(testsTargetFilePath, TYPE_ARG_COUNT, args.Length == 0); + } - // File header - writer.WriteLine("// Licensed to the .NET Foundation under one or more agreements."); - writer.WriteLine("// The .NET Foundation licenses this file to you under the MIT license."); - writer.WriteLine(); - writer.WriteLine("// This file is generated by a tool. See: src/Http/Http.Results/tools/ResultsOfTGenerator"); + public static void Run(string classFilePath, string testsFilePath) + { + GenerateClassFile(classFilePath, TYPE_ARG_COUNT, false); - // Namespace - writer.WriteLine("namespace Microsoft.AspNetCore.Http;"); - writer.WriteLine(); + GenerateTestFiles(testsFilePath, TYPE_ARG_COUNT, false); + } - for (int i = 1; i <= typeArgCount; i++) + static void GenerateClassFile(string classFilePath, int typeArgCount, bool interactive = true) { - // Skip first as we don't have a Results class - if (i == 1) + Console.WriteLine($"Will generate class file at {classFilePath}"); + + if (interactive) { - continue; + Console.WriteLine("Press any key to continue or Ctrl-C to cancel"); + Console.ReadKey(); } - // Class summary doc - writer.WriteLine("/// "); - writer.WriteLine($"/// An that could be one of {i.ToWords()} different types. On execution will"); - writer.WriteLine("/// execute the underlying instance that was actually returned by the HTTP endpoint."); - writer.WriteLine("/// "); + using var writer = new StreamWriter(classFilePath, append: false); - // Class remarks doc - writer.WriteLine("/// "); - writer.WriteLine("/// An instance of this type cannot be created explicitly. Use the implicit cast operators to create an instance"); - writer.WriteLine("/// from an instance of one of the declared type arguments, e.g."); - writer.WriteLine("/// Results<OkObjectHttpResult, ProblemHttpResult> result = Results.Ok();"); - writer.WriteLine("/// "); + // File header + writer.WriteLine("// Licensed to the .NET Foundation under one or more agreements."); + writer.WriteLine("// The .NET Foundation licenses this file to you under the MIT license."); + writer.WriteLine(); + writer.WriteLine("// This file is generated by a tool. See: src/Http/Http.Results/tools/ResultsOfTGenerator"); - // Type params docs - for (int j = 1; j <= i; j++) + // Namespace + writer.WriteLine("namespace Microsoft.AspNetCore.Http;"); + writer.WriteLine(); + + for (int i = 1; i <= typeArgCount; i++) { - writer.WriteLine(@$"/// The {j.ToOrdinalWords()} result type."); - } + // Skip first as we don't have a Results class + if (i == 1) + { + continue; + } - // Class declaration - writer.Write($"public sealed class {className}<"); + // Class summary doc + writer.WriteLine("/// "); + writer.WriteLine($"/// An that could be one of {i.ToWords()} different types. On execution will"); + writer.WriteLine("/// execute the underlying instance that was actually returned by the HTTP endpoint."); + writer.WriteLine("/// "); + + // Class remarks doc + writer.WriteLine("/// "); + writer.WriteLine("/// An instance of this type cannot be created explicitly. Use the implicit cast operators to create an instance"); + writer.WriteLine("/// from an instance of one of the declared type arguments, e.g."); + writer.WriteLine("/// Results<OkObjectHttpResult, ProblemHttpResult> result = Results.Ok();"); + writer.WriteLine("/// "); + + // Type params docs + for (int j = 1; j <= i; j++) + { + writer.WriteLine(@$"/// The {j.ToOrdinalWords()} result type."); + } - // Type args - for (int j = 1; j <= i; j++) - { - writer.Write($"{typeArgName}{j}"); - if (j != i) + // Class declaration + writer.Write($"public sealed class Results<"); + + // Type args + for (int j = 1; j <= i; j++) { - writer.Write(", "); + writer.Write($"TResult{j}"); + if (j != i) + { + writer.Write(", "); + } } - } - writer.WriteLine("> : IResult"); + writer.WriteLine("> : IResult"); - // Type arg contraints - for (int j = 1; j <= i; j++) - { - writer.WriteIndent($"where {typeArgName}{j} : IResult"); - if (j != i) + // Type arg contraints + for (int j = 1; j <= i; j++) + { + writer.WriteIndent($"where TResult{j} : IResult"); + if (j != i) + { + writer.WriteLine(); + } + } + writer.WriteLine(); + writer.WriteLine("{"); + + // Ctor + writer.WriteIndentedLine("// Use implicit cast operators to create an instance"); + writer.WriteIndentedLine($"private Results(IResult activeResult)"); + writer.WriteIndentedLine("{"); + writer.WriteIndentedLine(2, "Result = activeResult;"); + writer.WriteIndentedLine("}"); + writer.WriteLine(); + + // Result property + writer.WriteIndentedLine("/// "); + writer.WriteIndentedLine($"/// Gets the actual returned by the route handler delegate."); + writer.WriteIndentedLine("/// "); + writer.WriteIndentedLine("public IResult Result { get; }"); + writer.WriteLine(); + + // ExecuteAsync method + writer.WriteIndentedLine("/// "); + writer.WriteIndentedLine("public Task ExecuteAsync(HttpContext httpContext)"); + writer.WriteIndentedLine("{"); + writer.WriteIndentedLine(2, "ArgumentNullException.ThrowIfNull(httpContext, nameof(httpContext));"); + writer.WriteLine(); + writer.WriteIndentedLine(2, "if (Result is null)"); + writer.WriteIndentedLine(2, "{"); + writer.WriteIndentedLine(3, "throw new InvalidOperationException(\"The IResult assigned to the Result property must not be null.\");"); + writer.WriteIndentedLine(2, "}"); + writer.WriteLine(); + writer.WriteIndentedLine(2, "return Result.ExecuteAsync(httpContext);"); + writer.WriteIndentedLine("}"); + writer.WriteLine(); + + // Implicit converter operators + var sb = new StringBuilder(); + for (int j = 1; j <= i; j++) + { + sb.AppendFormat(CultureInfo.InvariantCulture, "TResult{0}", j); + if (j != i) + { + sb.Append(", "); + } + } + var typeArgsList = sb.ToString(); + + for (int j = 1; j <= i; j++) + { + writer.WriteIndentedLine("/// "); + writer.WriteIndentedLine($"/// Converts the to a ."); + writer.WriteIndentedLine("/// "); + writer.WriteIndentedLine("/// The result."); + writer.WriteIndentedLine($"public static implicit operator Results<{typeArgsList}>(TResult{j} result) => new(result);"); + + if (i != j) + { + writer.WriteLine(); + } + } + + // Class end + writer.WriteLine("}"); + + if (i != typeArgCount) { writer.WriteLine(); } } - writer.WriteLine(); - writer.WriteLine("{"); - // Ctor - writer.WriteIndentedLine("// Use implicit cast operators to create an instance"); - writer.WriteIndentedLine($"private {className}(IResult activeResult)"); - writer.WriteIndentedLine("{"); - writer.WriteIndentedLine(2, "Result = activeResult;"); - writer.WriteIndentedLine("}"); - writer.WriteLine(); + writer.Flush(); + writer.Close(); - // Result property - writer.WriteIndentedLine("/// "); - writer.WriteIndentedLine($"/// Gets the actual returned by the route handler delegate."); - writer.WriteIndentedLine("/// "); - writer.WriteIndentedLine("public IResult Result { get; }"); - writer.WriteLine(); + var file = new FileInfo(classFilePath); - // ExecuteAsync method - writer.WriteIndentedLine("/// "); - writer.WriteIndentedLine("public async Task ExecuteAsync(HttpContext httpContext)"); - writer.WriteIndentedLine("{"); - writer.WriteIndentedLine(2, "ArgumentNullException.ThrowIfNull(httpContext, nameof(httpContext));"); + if (!file.Exists) + { + throw new FileNotFoundException(classFilePath); + } + + Console.WriteLine(); + Console.WriteLine($"{file.Length:N0} bytes written to {file.FullName} successfully!"); + Console.WriteLine(); + } + + static void GenerateTestFiles(string testFilePath, int typeArgCount, bool interactive = true) + { + Console.WriteLine($"Will generate tests file at {testFilePath}"); + + if (interactive) + { + Console.WriteLine("Press any key to continue or Ctrl-C to cancel"); + Console.ReadKey(); + } + + using var writer = new StreamWriter(testFilePath, append: false); + + // File header + writer.WriteLine("// Licensed to the .NET Foundation under one or more agreements."); + writer.WriteLine("// The .NET Foundation licenses this file to you under the MIT license."); writer.WriteLine(); - writer.WriteIndentedLine(2, "if (Result is null)"); - writer.WriteIndentedLine(2, "{"); - writer.WriteIndentedLine(3, "throw new InvalidOperationException(\"The IResult assigned to the Result property must not be null.\");"); - writer.WriteIndentedLine(2, "}"); + writer.WriteLine("// This file is generated by a tool. See: src/Http/Http.Results/tools/ResultsOfTGenerator"); + + // Namespace + writer.WriteLine("namespace Microsoft.AspNetCore.Http.Result;"); writer.WriteLine(); - writer.WriteIndentedLine(2, "await Result.ExecuteAsync(httpContext);"); - writer.WriteIndentedLine("}"); + + // Using statements + writer.WriteLine("using System.Threading.Tasks;"); + writer.WriteLine("using Microsoft.Extensions.DependencyInjection;"); + writer.WriteLine("using Microsoft.Extensions.Logging;"); + writer.WriteLine("using Microsoft.Extensions.Logging.Abstractions;"); writer.WriteLine(); - // Implicit converter operators - var sb = new StringBuilder(); - for (int j = 1; j <= i; j++) + // Class declaration + writer.WriteLine($"public partial class ResultsOfTTests"); + writer.WriteLine("{"); + + for (int i = 1; i <= typeArgCount; i++) { - sb.AppendFormat(CultureInfo.InvariantCulture, "{0}{1}", typeArgName, j); - if (j != i) + // Skip first as we don't have a Results class + if (i == 1) { - sb.Append(", "); + continue; } + + GenerateTest_Result_IsAssignedResult(writer, i); + GenerateTest_ExecuteResult_ExecutesAssignedResult(writer, i); + GenerateTest_Throws_ArgumentNullException_WhenHttpContextIsNull(writer, i); + GenerateTest_Throws_InvalidOperationException_WhenResultIsNull(writer, i); + Generate_AcceptsIResult_AsAnyTypeArg(writer, i); + Generate_AcceptsNestedResultsOfT_AsAnyTypeArg(writer, i); } - var typeArgsList = sb.ToString(); - for (int j = 1; j <= i; j++) + Generate_ChecksumResultClass(writer); + + // CustomResult classes + writer.WriteLine(); + for (int i = 1; i <= typeArgCount + 1; i++) { - writer.WriteIndentedLine("/// "); - writer.WriteIndentedLine($"/// Converts the to a ."); - writer.WriteIndentedLine("/// "); - writer.WriteIndentedLine("/// The result."); - writer.WriteIndentedLine($"public static implicit operator {className}<{typeArgsList}>({typeArgName}{j} result) => new(result);"); + Generate_ChecksumResultClass(writer, i); - if (i != j) + if (i != typeArgCount) { writer.WriteLine(); } } - // Class end + // End test class writer.WriteLine("}"); - if (i != typeArgCount) + writer.Flush(); + writer.Close(); + + var file = new FileInfo(testFilePath); + + if (!file.Exists) { - writer.WriteLine(); + throw new FileNotFoundException(testFilePath); } - } - - writer.Flush(); - writer.Close(); - var file = new FileInfo(classFilePath); + Console.WriteLine(); + Console.WriteLine($"{file.Length:N0} bytes written to {file.FullName} successfully!"); + } - if (!file.Exists) + static void GenerateTest_Result_IsAssignedResult(StreamWriter writer, int typeArgNumber) { - throw new FileNotFoundException(classFilePath); - } + //[Theory] + //[InlineData(1, typeof(ChecksumResult1))] + //[InlineData(2, typeof(ChecksumResult2))] + //public void ResultsOfTResult1TResult2_Result_IsAssignedResult(int input, Type expectedResultType) + //{ + // // Arrange + // Results MyApi(int id) + // { + // return id switch + // { + // 1 => new CustomResult1(), + // _ => new CustomResult2() + // }; + // } + + // // Act + // var result = MyApi(input); + + // // Assert + // Assert.IsType(expectedResultType, result.Result); + //} - Console.WriteLine(); - Console.WriteLine($"{file.Length:N0} bytes written to {file.FullName} successfully!"); -} + // Attributes + writer.WriteIndentedLine("[Theory]"); -void GenerateTestFiles(string testFilePath) -{ - Console.WriteLine($"Will generate tests file at {testFilePath}"); - Console.WriteLine("Press any key to continue or Ctrl-C to cancel"); - Console.ReadKey(); - - using var writer = new StreamWriter(testFilePath, append: false); - - // File header - writer.WriteLine("// Licensed to the .NET Foundation under one or more agreements."); - writer.WriteLine("// The .NET Foundation licenses this file to you under the MIT license."); - writer.WriteLine(); - writer.WriteLine("// This file is generated by a tool. See: src/Http/Http.Results/tools/ResultsOfTGenerator"); - - // Namespace - writer.WriteLine("namespace Microsoft.AspNetCore.Http.Result;"); - writer.WriteLine(); - - // Using statements - writer.WriteLine("using System.Threading.Tasks;"); - writer.WriteLine("using Microsoft.Extensions.DependencyInjection;"); - writer.WriteLine("using Microsoft.Extensions.Logging;"); - writer.WriteLine("using Microsoft.Extensions.Logging.Abstractions;"); - writer.WriteLine(); - - // Class declaration - writer.WriteLine($"public partial class {className}OfTTests"); - writer.WriteLine("{"); - - for (int i = 1; i <= typeArgCount; i++) - { - // Skip first as we don't have a Results class - if (i == 1) + // InlineData + for (int j = 1; j <= typeArgNumber; j++) { - continue; + writer.WriteIndentedLine($"[InlineData({j}, typeof(ChecksumResult{j}))]"); } - GenerateTest_Result_IsAssignedResult(writer, i); - GenerateTest_ExecuteResult_ExecutesAssignedResult(writer, i); - GenerateTest_Throws_ArgumentNullException_WhenHttpContextIsNull(writer, i); - GenerateTest_Throws_InvalidOperationException_WhenResultIsNull(writer, i); - Generate_AcceptsIResult_AsAnyTypeArg(writer, i); - Generate_AcceptsNestedResultsOfT_AsAnyTypeArg(writer, i); - } - - Generate_ChecksumResultClass(writer); - - // CustomResult classes - writer.WriteLine(); - for (int i = 1; i <= typeArgCount + 1; i++) - { - Generate_ChecksumResultClass(writer, i); - - if (i != typeArgCount) + // Method + writer.WriteIndent(1, "public void ResultsOf"); + for (int j = 1; j <= typeArgNumber; j++) { - writer.WriteLine(); + writer.Write($"TResult{j}"); } - } + writer.WriteLine("_Result_IsAssignedResult(int input, Type expectedResultType)"); + writer.WriteIndentedLine("{"); - // End test class - writer.WriteLine("}"); + // Arrange + writer.WriteIndentedLine(2, "// Arrange"); + writer.WriteIndent(2, "Results<"); + for (int j = 1; j <= typeArgNumber; j++) + { + writer.Write($"ChecksumResult{j}"); + if (typeArgNumber != j) + { + writer.Write(", "); + } + } + writer.WriteLine("> MyApi(int id)"); + writer.WriteIndentedLine(2, "{"); + writer.WriteIndentedLine(3, "return id switch"); + writer.WriteIndentedLine(3, "{"); + for (int j = 1; j <= typeArgNumber; j++) + { + if (j != typeArgNumber) + { + writer.WriteIndentedLine(4, $"{j} => new ChecksumResult{j}(),"); + } + else + { + writer.WriteIndentedLine(4, $"_ => new ChecksumResult{j}()"); + } + } + writer.WriteIndentedLine(3, "};"); + writer.WriteIndentedLine(2, "}"); + writer.WriteLine(); - writer.Flush(); - writer.Close(); + // Act + writer.WriteIndentedLine(2, "// Act"); + writer.WriteIndentedLine(2, "var result = MyApi(input);"); + writer.WriteLine(); - var file = new FileInfo(testFilePath); + // Assert + writer.WriteIndentedLine(2, "// Assert"); + writer.WriteIndentedLine(2, "Assert.IsType(expectedResultType, result.Result);"); - if (!file.Exists) - { - throw new FileNotFoundException(testFilePath); + // End of method + writer.WriteIndentedLine("}"); + writer.WriteLine(); } - Console.WriteLine(); - Console.WriteLine($"{file.Length:N0} bytes written to {file.FullName} successfully!"); -} - -void GenerateTest_Result_IsAssignedResult(StreamWriter writer, int typeArgNumber) -{ - //[Theory] - //[InlineData(1, typeof(ChecksumResult1))] - //[InlineData(2, typeof(ChecksumResult2))] - //public void ResultsOfTResult1TResult2_Result_IsAssignedResult(int input, Type expectedResultType) - //{ - // // Arrange - // Results MyApi(int id) - // { - // return id switch - // { - // 1 => new CustomResult1(), - // _ => new CustomResult2() - // }; - // } - - // // Act - // var result = MyApi(input); - - // // Assert - // Assert.IsType(expectedResultType, result.Result); - //} - - // Attributes - writer.WriteIndentedLine("[Theory]"); - - // InlineData - for (int j = 1; j <= typeArgNumber; j++) + static void GenerateTest_ExecuteResult_ExecutesAssignedResult(StreamWriter writer, int typeArgNumber) { - writer.WriteIndentedLine($"[InlineData({j}, typeof(ChecksumResult{j}))]"); - } + //[Theory] + //[InlineData(1, 1)] + //[InlineData(2, 2)] + //[InlineData(-1, null)] + //public async Task ResultsOfTResult1TResult2_ExecuteResult_ExecutesAssignedResult(int input, object expected) + //{ + // // Arrange + // Results MyApi(int checksum) + // { + // return checksum switch + // { + // 1 => new ChecksumResult1(checksum), + // 2 => new ChecksumResult2(checksum), + // _ => (NoContentHttpResult)Results.NoContent() + // }; + // } + // var httpContext = GetHttpContext(); + + // // Act + // var result = MyApi(input); + // await result.ExecuteAsync(httpContext); + + // // Assert + // Assert.Equal(expected, httpContext.Items[nameof(ChecksumResult.Checksum)]); + //} - // Method - writer.WriteIndent(1, "public void ResultsOf"); - for (int j = 1; j <= typeArgNumber; j++) - { - writer.Write($"TResult{j}"); - } - writer.WriteLine("_Result_IsAssignedResult(int input, Type expectedResultType)"); - writer.WriteIndentedLine("{"); + // Attributes + writer.WriteIndentedLine("[Theory]"); - // Arrange - writer.WriteIndentedLine(2, "// Arrange"); - writer.WriteIndent(2, "Results<"); - for (int j = 1; j <= typeArgNumber; j++) - { - writer.Write($"ChecksumResult{j}"); - if (typeArgNumber != j) + // InlineData + for (int j = 1; j <= typeArgNumber; j++) { - writer.Write(", "); + writer.WriteIndentedLine($"[InlineData({j})]"); } - } - writer.WriteLine("> MyApi(int id)"); - writer.WriteIndentedLine(2, "{"); - writer.WriteIndentedLine(3, "return id switch"); - writer.WriteIndentedLine(3, "{"); - for (int j = 1; j <= typeArgNumber; j++) - { - if (j != typeArgNumber) + + // Method + // public void ResultsOfTResult1TResult2_ExecuteResult_ExecutesAssignedResult(int input, object expected) + writer.WriteIndent(1, "public async Task ResultsOf"); + for (int j = 1; j <= typeArgNumber; j++) { - writer.WriteIndentedLine(4, $"{j} => new ChecksumResult{j}(),"); + writer.Write($"TResult{j}"); } - else + writer.WriteLine("_ExecuteResult_ExecutesAssignedResult(int input)"); + writer.WriteIndentedLine("{"); + + // Arrange + writer.WriteIndentedLine(2, "// Arrange"); + writer.WriteIndent(2, "Results<"); + for (int j = 1; j <= typeArgNumber; j++) { - writer.WriteIndentedLine(4, $"_ => new ChecksumResult{j}()"); + writer.Write($"ChecksumResult{j}"); + if (typeArgNumber != j) + { + writer.Write(", "); + } } - } - writer.WriteIndentedLine(3, "};"); - writer.WriteIndentedLine(2, "}"); - writer.WriteLine(); - - // Act - writer.WriteIndentedLine(2, "// Act"); - writer.WriteIndentedLine(2, "var result = MyApi(input);"); - writer.WriteLine(); - - // Assert - writer.WriteIndentedLine(2, "// Assert"); - writer.WriteIndentedLine(2, "Assert.IsType(expectedResultType, result.Result);"); - - // End of method - writer.WriteIndentedLine("}"); - writer.WriteLine(); -} + writer.WriteLine("> MyApi(int checksum)"); + writer.WriteIndentedLine(2, "{"); + writer.WriteIndentedLine(3, "return checksum switch"); + writer.WriteIndentedLine(3, "{"); + for (int j = 1; j <= typeArgNumber; j++) + { + if (j < typeArgNumber) + { + writer.WriteIndentedLine(4, $"{j} => new ChecksumResult{j}(checksum),"); + } + else + { + writer.WriteIndentedLine(4, $"_ => new ChecksumResult{j}(checksum)"); + } + } + writer.WriteIndentedLine(3, "};"); + writer.WriteIndentedLine(2, "}"); + writer.WriteIndentedLine(2, "var httpContext = GetHttpContext();"); + writer.WriteLine(); -void GenerateTest_ExecuteResult_ExecutesAssignedResult(StreamWriter writer, int typeArgNumber) -{ - //[Theory] - //[InlineData(1, 1)] - //[InlineData(2, 2)] - //[InlineData(-1, null)] - //public async Task ResultsOfTResult1TResult2_ExecuteResult_ExecutesAssignedResult(int input, object expected) - //{ - // // Arrange - // Results MyApi(int checksum) - // { - // return checksum switch - // { - // 1 => new ChecksumResult1(checksum), - // 2 => new ChecksumResult2(checksum), - // _ => (NoContentHttpResult)Results.NoContent() - // }; - // } - // var httpContext = GetHttpContext(); - - // // Act - // var result = MyApi(input); - // await result.ExecuteAsync(httpContext); - - // // Assert - // Assert.Equal(expected, httpContext.Items[nameof(ChecksumResult.Checksum)]); - //} - - // Attributes - writer.WriteIndentedLine("[Theory]"); - - // InlineData - for (int j = 1; j <= typeArgNumber; j++) - { - writer.WriteIndentedLine($"[InlineData({j})]"); - } + // Act + writer.WriteIndentedLine(2, "// Act"); + writer.WriteIndentedLine(2, "var result = MyApi(input);"); + writer.WriteIndentedLine(2, "await result.ExecuteAsync(httpContext);"); + writer.WriteLine(); - // Method - // public void ResultsOfTResult1TResult2_ExecuteResult_ExecutesAssignedResult(int input, object expected) - writer.WriteIndent(1, "public async Task ResultsOf"); - for (int j = 1; j <= typeArgNumber; j++) - { - writer.Write($"TResult{j}"); + // Assert + writer.WriteIndentedLine(2, "// Assert"); + writer.WriteIndentedLine(2, "Assert.Equal(input, httpContext.Items[nameof(ChecksumResult.Checksum)]);"); + + // End of method + writer.WriteIndentedLine("}"); + writer.WriteLine(); } - writer.WriteLine("_ExecuteResult_ExecutesAssignedResult(int input)"); - writer.WriteIndentedLine("{"); - // Arrange - writer.WriteIndentedLine(2, "// Arrange"); - writer.WriteIndent(2, "Results<"); - for (int j = 1; j <= typeArgNumber; j++) + static void GenerateTest_Throws_ArgumentNullException_WhenHttpContextIsNull(StreamWriter writer, int typeArgNumber) { - writer.Write($"ChecksumResult{j}"); - if (typeArgNumber != j) + //[Fact] + //public void ResultsOfTResult1TResult2_Throws_ArgumentNullException_WhenHttpContextIsNull() + //{ + // // Arrange + // Results MyApi() + // { + // return new ChecksumResult1(1); + // } + // HttpContext httpContext = null; + + // // Act & Assert + // var result = MyApi(); + + // Assert.ThrowsAsync(async () => + // { + // await result.ExecuteAsync(httpContext); + // }); + //} + + // Attributes + writer.WriteIndentedLine("[Fact]"); + + // Start method + writer.WriteIndent(1, "public void ResultsOf"); + for (int j = 1; j <= typeArgNumber; j++) { - writer.Write(", "); + writer.Write($"TResult{j}"); } + writer.WriteLine("_Throws_ArgumentNullException_WhenHttpContextIsNull()"); + writer.WriteIndentedLine("{"); + + // Arrange + writer.WriteIndentedLine(2, "// Arrange"); + writer.WriteIndentedLine(2, "Results MyApi()"); + writer.WriteIndentedLine(2, "{"); + writer.WriteIndentedLine(3, "return new ChecksumResult1(1);"); + writer.WriteIndentedLine(2, "}"); + writer.WriteIndentedLine(2, "HttpContext httpContext = null;"); + writer.WriteIndentedLine(2); + + // Act & Assert + writer.WriteIndentedLine(2, "// Act & Assert"); + writer.WriteIndentedLine(2, "var result = MyApi();"); + writer.WriteIndentedLine(2); + + writer.WriteIndentedLine(2, "Assert.ThrowsAsync(async () =>"); + writer.WriteIndentedLine(2, "{"); + writer.WriteIndentedLine(3, "await result.ExecuteAsync(httpContext);"); + writer.WriteIndentedLine(2, "});"); + + // Close method + writer.WriteIndentedLine(1, "}"); + writer.WriteIndentedLine(); } - writer.WriteLine("> MyApi(int checksum)"); - writer.WriteIndentedLine(2, "{"); - writer.WriteIndentedLine(3, "return checksum switch"); - writer.WriteIndentedLine(3, "{"); - for (int j = 1; j <= typeArgNumber; j++) + + static void GenerateTest_Throws_InvalidOperationException_WhenResultIsNull(StreamWriter writer, int typeArgNumber) { - if (j < typeArgNumber) - { - writer.WriteIndentedLine(4, $"{j} => new ChecksumResult{j}(checksum),"); - } - else + //[Fact] + //public void ResultsOfTResult1TResult2_Throws_InvalidOperationException_WhenResultIsNull() + //{ + // // Arrange + // Results MyApi() + // { + // return (ChecksumResult1)null; + // } + // var httpContext = GetHttpContext(); + + // // Act & Assert + // var result = MyApi(); + + // Assert.ThrowsAsync(async () => + // { + // await result.ExecuteAsync(httpContext); + // }); + //} + + // Attributes + writer.WriteIndentedLine("[Fact]"); + + // Start method + writer.WriteIndent(1, "public void ResultsOf"); + for (int j = 1; j <= typeArgNumber; j++) { - writer.WriteIndentedLine(4, $"_ => new ChecksumResult{j}(checksum)"); + writer.Write($"TResult{j}"); } - } - writer.WriteIndentedLine(3, "};"); - writer.WriteIndentedLine(2, "}"); - writer.WriteIndentedLine(2, "var httpContext = GetHttpContext();"); - writer.WriteLine(); - - // Act - writer.WriteIndentedLine(2, "// Act"); - writer.WriteIndentedLine(2, "var result = MyApi(input);"); - writer.WriteIndentedLine(2, "await result.ExecuteAsync(httpContext);"); - writer.WriteLine(); - - // Assert - writer.WriteIndentedLine(2, "// Assert"); - writer.WriteIndentedLine(2, "Assert.Equal(input, httpContext.Items[nameof(ChecksumResult.Checksum)]);"); - - // End of method - writer.WriteIndentedLine("}"); - writer.WriteLine(); -} + writer.WriteLine("_Throws_InvalidOperationException_WhenResultIsNull()"); + writer.WriteIndentedLine("{"); -void GenerateTest_Throws_ArgumentNullException_WhenHttpContextIsNull(StreamWriter writer, int typeArgNumber) -{ - //[Fact] - //public void ResultsOfTResult1TResult2_Throws_ArgumentNullException_WhenHttpContextIsNull() - //{ - // // Arrange - // Results MyApi() - // { - // return new ChecksumResult1(1); - // } - // HttpContext httpContext = null; - - // // Act & Assert - // var result = MyApi(); - - // Assert.ThrowsAsync(async () => - // { - // await result.ExecuteAsync(httpContext); - // }); - //} - - // Attributes - writer.WriteIndentedLine("[Fact]"); - - // Start method - writer.WriteIndent(1, "public void ResultsOf"); - for (int j = 1; j <= typeArgNumber; j++) - { - writer.Write($"TResult{j}"); - } - writer.WriteLine("_Throws_ArgumentNullException_WhenHttpContextIsNull()"); - writer.WriteIndentedLine("{"); - - // Arrange - writer.WriteIndentedLine(2, "// Arrange"); - writer.WriteIndentedLine(2, "Results MyApi()"); - writer.WriteIndentedLine(2, "{"); - writer.WriteIndentedLine(3, "return new ChecksumResult1(1);"); - writer.WriteIndentedLine(2, "}"); - writer.WriteIndentedLine(2, "HttpContext httpContext = null;"); - writer.WriteIndentedLine(2); - - // Act & Assert - writer.WriteIndentedLine(2, "// Act & Assert"); - writer.WriteIndentedLine(2, "var result = MyApi();"); - writer.WriteIndentedLine(2); - - writer.WriteIndentedLine(2, "Assert.ThrowsAsync(async () =>"); - writer.WriteIndentedLine(2, "{"); - writer.WriteIndentedLine(3, "await result.ExecuteAsync(httpContext);"); - writer.WriteIndentedLine(2, "});"); - - // Close method - writer.WriteIndentedLine(1, "}"); - writer.WriteIndentedLine(); -} + // Arrange + writer.WriteIndentedLine(2, "// Arrange"); + writer.WriteIndentedLine(2, "Results MyApi()"); + writer.WriteIndentedLine(2, "{"); + writer.WriteIndentedLine(3, "return new ChecksumResult1(1);"); + writer.WriteIndentedLine(2, "}"); + writer.WriteIndentedLine(2, "var httpContext = GetHttpContext();"); + writer.WriteIndentedLine(2); -void GenerateTest_Throws_InvalidOperationException_WhenResultIsNull(StreamWriter writer, int typeArgNumber) -{ - //[Fact] - //public void ResultsOfTResult1TResult2_Throws_InvalidOperationException_WhenResultIsNull() - //{ - // // Arrange - // Results MyApi() - // { - // return (ChecksumResult1)null; - // } - // var httpContext = GetHttpContext(); - - // // Act & Assert - // var result = MyApi(); - - // Assert.ThrowsAsync(async () => - // { - // await result.ExecuteAsync(httpContext); - // }); - //} - - // Attributes - writer.WriteIndentedLine("[Fact]"); - - // Start method - writer.WriteIndent(1, "public void ResultsOf"); - for (int j = 1; j <= typeArgNumber; j++) - { - writer.Write($"TResult{j}"); - } - writer.WriteLine("_Throws_InvalidOperationException_WhenResultIsNull()"); - writer.WriteIndentedLine("{"); - - // Arrange - writer.WriteIndentedLine(2, "// Arrange"); - writer.WriteIndentedLine(2, "Results MyApi()"); - writer.WriteIndentedLine(2, "{"); - writer.WriteIndentedLine(3, "return new ChecksumResult1(1);"); - writer.WriteIndentedLine(2, "}"); - writer.WriteIndentedLine(2, "var httpContext = GetHttpContext();"); - writer.WriteIndentedLine(2); - - // Act & Assert - writer.WriteIndentedLine(2, "// Act & Assert"); - writer.WriteIndentedLine(2, "var result = MyApi();"); - writer.WriteIndentedLine(2); - - writer.WriteIndentedLine(2, "Assert.ThrowsAsync(async () =>"); - writer.WriteIndentedLine(2, "{"); - writer.WriteIndentedLine(3, "await result.ExecuteAsync(httpContext);"); - writer.WriteIndentedLine(2, "});"); - - // Close method - writer.WriteIndentedLine(1, "}"); - writer.WriteIndentedLine(); -} + // Act & Assert + writer.WriteIndentedLine(2, "// Act & Assert"); + writer.WriteIndentedLine(2, "var result = MyApi();"); + writer.WriteIndentedLine(2); -void Generate_AcceptsIResult_AsAnyTypeArg(StreamWriter writer, int typeArgCount) -{ - for (int i = 1; i <= typeArgCount; i++) - { - Generate_AcceptsIResult_AsNthTypeArg(writer, typeArgCount, i); - } -} + writer.WriteIndentedLine(2, "Assert.ThrowsAsync(async () =>"); + writer.WriteIndentedLine(2, "{"); + writer.WriteIndentedLine(3, "await result.ExecuteAsync(httpContext);"); + writer.WriteIndentedLine(2, "});"); -void Generate_AcceptsIResult_AsNthTypeArg(StreamWriter writer, int typeArgCount, int typeArgNumber) -{ - //[Theory] - //[InlineData(1, typeof(ChecksumResult1))] - //[InlineData(2, typeof(ChecksumResult2))] - //public async Task ResultsOfTResult1TResult2_AcceptsIResult_AsFirstTypeArg(int input, Type expectedResultType) - //{ - // // Arrange - // Results MyApi(int id) - // { - // return id switch - // { - // 1 => new ChecksumResult1(1), - // _ => new ChecksumResult2(2) - // }; - // } - // var httpContext = GetHttpContext(); - - // // Act - // var result = MyApi(input); - // await result.ExecuteAsync(httpContext); - - // // Assert - // Assert.IsType(expectedResultType, result.Result); - // Assert.Equal(input, httpContext.Items[nameof(ChecksumResult.Checksum)]); - //} - - // Attributes - writer.WriteIndentedLine("[Theory]"); - - // InlineData - for (int j = 1; j <= typeArgCount; j++) - { - writer.WriteIndentedLine($"[InlineData({j}, typeof(ChecksumResult{j}))]"); + // Close method + writer.WriteIndentedLine(1, "}"); + writer.WriteIndentedLine(); } - // Start method - writer.WriteIndent(1, "public async Task ResultsOf"); - for (int j = 1; j <= typeArgCount; j++) + static void Generate_AcceptsIResult_AsAnyTypeArg(StreamWriter writer, int typeArgCount) { - writer.Write($"TResult{j}"); + for (int i = 1; i <= typeArgCount; i++) + { + Generate_AcceptsIResult_AsNthTypeArg(writer, typeArgCount, i); + } } - writer.WriteLine($"_AcceptsIResult_As{typeArgNumber.ToOrdinalWords().TitleCase()}TypeArg(int input, Type expectedResultType)"); - writer.WriteIndentedLine("{"); - // Arrange - writer.WriteIndentedLine(2, "// Arrange"); - writer.WriteIndent(2, "Results<"); - for (int j = 1; j <= typeArgCount; j++) + static void Generate_AcceptsIResult_AsNthTypeArg(StreamWriter writer, int typeArgCount, int typeArgNumber) { - if (j == typeArgNumber) - { - writer.Write("IResult"); - } - else + //[Theory] + //[InlineData(1, typeof(ChecksumResult1))] + //[InlineData(2, typeof(ChecksumResult2))] + //public async Task ResultsOfTResult1TResult2_AcceptsIResult_AsFirstTypeArg(int input, Type expectedResultType) + //{ + // // Arrange + // Results MyApi(int id) + // { + // return id switch + // { + // 1 => new ChecksumResult1(1), + // _ => new ChecksumResult2(2) + // }; + // } + // var httpContext = GetHttpContext(); + + // // Act + // var result = MyApi(input); + // await result.ExecuteAsync(httpContext); + + // // Assert + // Assert.IsType(expectedResultType, result.Result); + // Assert.Equal(input, httpContext.Items[nameof(ChecksumResult.Checksum)]); + //} + + // Attributes + writer.WriteIndentedLine("[Theory]"); + + // InlineData + for (int j = 1; j <= typeArgCount; j++) { - writer.Write($"ChecksumResult{j}"); + writer.WriteIndentedLine($"[InlineData({j}, typeof(ChecksumResult{j}))]"); } - if (j < typeArgCount) + // Start method + writer.WriteIndent(1, "public async Task ResultsOf"); + for (int j = 1; j <= typeArgCount; j++) { - writer.Write(", "); + writer.Write($"TResult{j}"); } - } - writer.WriteLine("> MyApi(int id)"); - writer.WriteIndentedLine(2, "{"); - writer.WriteIndentedLine(3, "return id switch"); - writer.WriteIndentedLine(3, "{"); - for (int j = 1; j <= typeArgCount; j++) - { - if (j < typeArgCount) + writer.WriteLine($"_AcceptsIResult_As{typeArgNumber.ToOrdinalWords().TitleCase()}TypeArg(int input, Type expectedResultType)"); + writer.WriteIndentedLine("{"); + + // Arrange + writer.WriteIndentedLine(2, "// Arrange"); + writer.WriteIndent(2, "Results<"); + for (int j = 1; j <= typeArgCount; j++) { - writer.WriteIndentedLine(4, $"{j} => new ChecksumResult{j}({j}),"); + if (j == typeArgNumber) + { + writer.Write("IResult"); + } + else + { + writer.Write($"ChecksumResult{j}"); + } + + if (j < typeArgCount) + { + writer.Write(", "); + } } - else + writer.WriteLine("> MyApi(int id)"); + writer.WriteIndentedLine(2, "{"); + writer.WriteIndentedLine(3, "return id switch"); + writer.WriteIndentedLine(3, "{"); + for (int j = 1; j <= typeArgCount; j++) { - writer.WriteIndentedLine(4, $"_ => new ChecksumResult{j}({j})"); + if (j < typeArgCount) + { + writer.WriteIndentedLine(4, $"{j} => new ChecksumResult{j}({j}),"); + } + else + { + writer.WriteIndentedLine(4, $"_ => new ChecksumResult{j}({j})"); + } } + writer.WriteIndentedLine(3, "};"); + writer.WriteIndentedLine(2, "}"); + writer.WriteIndentedLine(2, "var httpContext = GetHttpContext();"); + writer.WriteLine(); + + // Act + writer.WriteIndentedLine(2, "// Act"); + writer.WriteIndentedLine(2, "var result = MyApi(input);"); + writer.WriteIndentedLine(2, "await result.ExecuteAsync(httpContext);"); + writer.WriteIndentedLine(2); + + // Assert + writer.WriteIndentedLine(2, "// Assert"); + writer.WriteIndentedLine(2, "Assert.IsType(expectedResultType, result.Result);"); + writer.WriteIndentedLine(2, "Assert.Equal(input, httpContext.Items[nameof(ChecksumResult.Checksum)]);"); + + // Close method + writer.WriteIndentedLine(1, "}"); + writer.WriteIndentedLine(); } - writer.WriteIndentedLine(3, "};"); - writer.WriteIndentedLine(2, "}"); - writer.WriteIndentedLine(2, "var httpContext = GetHttpContext();"); - writer.WriteLine(); - - // Act - writer.WriteIndentedLine(2, "// Act"); - writer.WriteIndentedLine(2, "var result = MyApi(input);"); - writer.WriteIndentedLine(2, "await result.ExecuteAsync(httpContext);"); - writer.WriteIndentedLine(2); - - // Assert - writer.WriteIndentedLine(2, "// Assert"); - writer.WriteIndentedLine(2, "Assert.IsType(expectedResultType, result.Result);"); - writer.WriteIndentedLine(2, "Assert.Equal(input, httpContext.Items[nameof(ChecksumResult.Checksum)]);"); - - // Close method - writer.WriteIndentedLine(1, "}"); - writer.WriteIndentedLine(); -} -void Generate_AcceptsNestedResultsOfT_AsAnyTypeArg(StreamWriter writer, int typeArgCount) -{ - for (int i = 1; i <= typeArgCount; i++) + static void Generate_AcceptsNestedResultsOfT_AsAnyTypeArg(StreamWriter writer, int typeArgCount) { - Generate_AcceptsNestedResultsOfT_AsNthTypeArg(writer, typeArgCount, i); + for (int i = 1; i <= typeArgCount; i++) + { + Generate_AcceptsNestedResultsOfT_AsNthTypeArg(writer, typeArgCount, i); + } } -} -void Generate_AcceptsNestedResultsOfT_AsNthTypeArg(StreamWriter writer, int typeArgCount, int typeArgNumber) -{ - //[Theory] - //[InlineData(1, typeof(Results))] - //[InlineData(2, typeof(Results))] - //[InlineData(3, typeof(ChecksumResult3))] - //public async Task ResultsOfTResult1TResult2_AcceptsNestedResultsOfT_AsFirstTypeArg(int input, Type expectedResultType) - //{ - // // Arrange - // Results, ChecksumResult3> MyApi(int id) - // { - // return id switch - // { - // 1 => (Results)new ChecksumResult1(1), - // 2 => (Results)new ChecksumResult2(2), - // _ => new ChecksumResult3(3) - // }; - // } - // var httpContext = GetHttpContext(); - - // // Act - // var result = MyApi(input); - // await result.ExecuteAsync(httpContext); - - // // Assert - // Assert.IsType(expectedResultType, result.Result); - // Assert.Equal(input, httpContext.Items[nameof(ChecksumResult.Checksum)]); - //} - - var sb = new StringBuilder("Results<"); - for (int j = 1; j <= typeArgCount; j++) + static void Generate_AcceptsNestedResultsOfT_AsNthTypeArg(StreamWriter writer, int typeArgCount, int typeArgNumber) { - sb.Append(CultureInfo.InvariantCulture, $"ChecksumResult{j}"); + //[Theory] + //[InlineData(1, typeof(Results))] + //[InlineData(2, typeof(Results))] + //[InlineData(3, typeof(ChecksumResult3))] + //public async Task ResultsOfTResult1TResult2_AcceptsNestedResultsOfT_AsFirstTypeArg(int input, Type expectedResultType) + //{ + // // Arrange + // Results, ChecksumResult3> MyApi(int id) + // { + // return id switch + // { + // 1 => (Results)new ChecksumResult1(1), + // 2 => (Results)new ChecksumResult2(2), + // _ => new ChecksumResult3(3) + // }; + // } + // var httpContext = GetHttpContext(); + + // // Act + // var result = MyApi(input); + // await result.ExecuteAsync(httpContext); + + // // Assert + // Assert.IsType(expectedResultType, result.Result); + // Assert.Equal(input, httpContext.Items[nameof(ChecksumResult.Checksum)]); + //} - if (j < typeArgCount) + var sb = new StringBuilder("Results<"); + for (int j = 1; j <= typeArgCount; j++) { - sb.Append(", "); + sb.Append(CultureInfo.InvariantCulture, $"ChecksumResult{j}"); + + if (j < typeArgCount) + { + sb.Append(", "); + } } - } - sb.Append('>'); - var nestedResultTypeName = sb.ToString(); + sb.Append('>'); + var nestedResultTypeName = sb.ToString(); - // Attributes - writer.WriteIndentedLine("[Theory]"); + // Attributes + writer.WriteIndentedLine("[Theory]"); - // InlineData - for (int j = 1; j <= typeArgCount + 1; j++) - { - if (j <= typeArgCount) + // InlineData + for (int j = 1; j <= typeArgCount + 1; j++) { - writer.WriteIndentedLine($"[InlineData({j}, typeof({nestedResultTypeName}))]"); + if (j <= typeArgCount) + { + writer.WriteIndentedLine($"[InlineData({j}, typeof({nestedResultTypeName}))]"); + } + else + { + writer.WriteIndentedLine($"[InlineData({j}, typeof(ChecksumResult{j}))]"); + } } - else + + // Start method + writer.WriteIndent(1, "public async Task ResultsOf"); + for (int j = 1; j <= typeArgCount; j++) { - writer.WriteIndentedLine($"[InlineData({j}, typeof(ChecksumResult{j}))]"); + writer.Write($"TResult{j}"); } - } - - // Start method - writer.WriteIndent(1, "public async Task ResultsOf"); - for (int j = 1; j <= typeArgCount; j++) - { - writer.Write($"TResult{j}"); - } - writer.WriteLine($"_AcceptsNestedResultsOfT_As{typeArgNumber.ToOrdinalWords().TitleCase()}TypeArg(int input, Type expectedResultType)"); - writer.WriteIndentedLine("{"); - - // Arrange - writer.WriteIndentedLine(2, "// Arrange"); - writer.WriteIndent(2, "Results<"); - writer.WriteLine($"{nestedResultTypeName}, ChecksumResult{typeArgCount + 1}> MyApi(int id)"); - writer.WriteIndentedLine(2, "{"); - writer.WriteIndentedLine(3, "return id switch"); - writer.WriteIndentedLine(3, "{"); - for (int j = 1; j <= typeArgCount; j++) - { - writer.WriteIndentedLine(4, $"{j} => ({nestedResultTypeName})new ChecksumResult{j}({j}),"); - } - writer.WriteIndentedLine(4, $"_ => new ChecksumResult{typeArgCount + 1}({typeArgCount + 1})"); - writer.WriteIndentedLine(3, "};"); - writer.WriteIndentedLine(2, "}"); - writer.WriteIndentedLine(2, "var httpContext = GetHttpContext();"); - writer.WriteLine(); - - // Act - writer.WriteIndentedLine(2, "// Act"); - writer.WriteIndentedLine(2, "var result = MyApi(input);"); - writer.WriteIndentedLine(2, "await result.ExecuteAsync(httpContext);"); - writer.WriteIndentedLine(2); - - // Assert - writer.WriteIndentedLine(2, "// Assert"); - writer.WriteIndentedLine(2, "Assert.IsType(expectedResultType, result.Result);"); - writer.WriteIndentedLine(2, "Assert.Equal(input, httpContext.Items[nameof(ChecksumResult.Checksum)]);"); - - // Close method - writer.WriteIndentedLine(1, "}"); - writer.WriteIndentedLine(); -} + writer.WriteLine($"_AcceptsNestedResultsOfT_As{typeArgNumber.ToOrdinalWords().TitleCase()}TypeArg(int input, Type expectedResultType)"); + writer.WriteIndentedLine("{"); -void Generate_ChecksumResultClass(StreamWriter writer, int typeArgNumber = -1) -{ - if (typeArgNumber <= 0) - { - writer.WriteIndentedLine(1, "abstract class ChecksumResult : IResult"); - writer.WriteIndentedLine(1, "{"); - writer.WriteIndentedLine(2, "public ChecksumResult(int checksum = 0)"); + // Arrange + writer.WriteIndentedLine(2, "// Arrange"); + writer.WriteIndent(2, "Results<"); + writer.WriteLine($"{nestedResultTypeName}, ChecksumResult{typeArgCount + 1}> MyApi(int id)"); writer.WriteIndentedLine(2, "{"); - writer.WriteIndentedLine(3, "Checksum = checksum;"); + writer.WriteIndentedLine(3, "return id switch"); + writer.WriteIndentedLine(3, "{"); + for (int j = 1; j <= typeArgCount; j++) + { + writer.WriteIndentedLine(4, $"{j} => ({nestedResultTypeName})new ChecksumResult{j}({j}),"); + } + writer.WriteIndentedLine(4, $"_ => new ChecksumResult{typeArgCount + 1}({typeArgCount + 1})"); + writer.WriteIndentedLine(3, "};"); writer.WriteIndentedLine(2, "}"); + writer.WriteIndentedLine(2, "var httpContext = GetHttpContext();"); writer.WriteLine(); - writer.WriteIndentedLine(2, "public int Checksum { get; }"); - writer.WriteLine(); - writer.WriteIndentedLine(2, "public Task ExecuteAsync(HttpContext httpContext)"); - writer.WriteIndentedLine(2, "{"); - writer.WriteIndentedLine(3, "httpContext.Items[nameof(ChecksumResult.Checksum)] = Checksum;"); - writer.WriteIndentedLine(3, "return Task.CompletedTask;"); - writer.WriteIndentedLine(2, "}"); + + // Act + writer.WriteIndentedLine(2, "// Act"); + writer.WriteIndentedLine(2, "var result = MyApi(input);"); + writer.WriteIndentedLine(2, "await result.ExecuteAsync(httpContext);"); + writer.WriteIndentedLine(2); + + // Assert + writer.WriteIndentedLine(2, "// Assert"); + writer.WriteIndentedLine(2, "Assert.IsType(expectedResultType, result.Result);"); + writer.WriteIndentedLine(2, "Assert.Equal(input, httpContext.Items[nameof(ChecksumResult.Checksum)]);"); + + // Close method writer.WriteIndentedLine(1, "}"); + writer.WriteIndentedLine(); } - else + + static void Generate_ChecksumResultClass(StreamWriter writer, int typeArgNumber = -1) { - // ChecksumResult class - //class ChecksumResult1 : ChecksumResult - //{ - // public ChecksumResult1(int checksum = 0) : base(checksum) { } - //} - writer.WriteIndentedLine(1, $"class ChecksumResult{typeArgNumber} : ChecksumResult"); - writer.WriteIndentedLine(1, "{"); - writer.WriteIndentedLine(2, $"public ChecksumResult{typeArgNumber}(int checksum = 0) : base(checksum) {{ }}"); - writer.WriteIndentedLine(1, "}"); + if (typeArgNumber <= 0) + { + writer.WriteIndentedLine(1, "abstract class ChecksumResult : IResult"); + writer.WriteIndentedLine(1, "{"); + writer.WriteIndentedLine(2, "public ChecksumResult(int checksum = 0)"); + writer.WriteIndentedLine(2, "{"); + writer.WriteIndentedLine(3, "Checksum = checksum;"); + writer.WriteIndentedLine(2, "}"); + writer.WriteLine(); + writer.WriteIndentedLine(2, "public int Checksum { get; }"); + writer.WriteLine(); + writer.WriteIndentedLine(2, "public Task ExecuteAsync(HttpContext httpContext)"); + writer.WriteIndentedLine(2, "{"); + writer.WriteIndentedLine(3, "httpContext.Items[nameof(ChecksumResult.Checksum)] = Checksum;"); + writer.WriteIndentedLine(3, "return Task.CompletedTask;"); + writer.WriteIndentedLine(2, "}"); + writer.WriteIndentedLine(1, "}"); + } + else + { + // ChecksumResult class + //class ChecksumResult1 : ChecksumResult + //{ + // public ChecksumResult1(int checksum = 0) : base(checksum) { } + //} + writer.WriteIndentedLine(1, $"class ChecksumResult{typeArgNumber} : ChecksumResult"); + writer.WriteIndentedLine(1, "{"); + writer.WriteIndentedLine(2, $"public ChecksumResult{typeArgNumber}(int checksum = 0) : base(checksum) {{ }}"); + writer.WriteIndentedLine(1, "}"); + } } } - -static class StringExtensions +public static class StringExtensions { public static void WriteIndent(this StreamWriter writer, string? value = null) { @@ -867,9 +901,9 @@ public static void WriteIndentedLine(this StreamWriter writer, int count, string }; public static string TitleCase(this string value) => string.Create(value.Length, value, (c, s) => - { - var origValueSpan = s.AsSpan(); - c[0] = char.ToUpper(origValueSpan[0], CultureInfo.InvariantCulture); - origValueSpan[1..].TryCopyTo(c[1..]); - }); + { + var origValueSpan = s.AsSpan(); + c[0] = char.ToUpper(origValueSpan[0], CultureInfo.InvariantCulture); + origValueSpan[1..].TryCopyTo(c[1..]); + }); } From ebe56709ffee91c9c5e9b860faedd6822ff45648 Mon Sep 17 00:00:00 2001 From: Damian Edwards Date: Thu, 7 Apr 2022 13:55:31 -0700 Subject: [PATCH 19/19] nit fix --- .../Http.Results/tools/ResultsOfTGenerator/Program.cs | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/src/Http/Http.Results/tools/ResultsOfTGenerator/Program.cs b/src/Http/Http.Results/tools/ResultsOfTGenerator/Program.cs index 502313ea07e0..27d5ad49f040 100644 --- a/src/Http/Http.Results/tools/ResultsOfTGenerator/Program.cs +++ b/src/Http/Http.Results/tools/ResultsOfTGenerator/Program.cs @@ -62,14 +62,9 @@ static void GenerateClassFile(string classFilePath, int typeArgCount, bool inter writer.WriteLine("namespace Microsoft.AspNetCore.Http;"); writer.WriteLine(); - for (int i = 1; i <= typeArgCount; i++) + // Skip 1 as we don't have a Results class + for (int i = 2; i <= typeArgCount; i++) { - // Skip first as we don't have a Results class - if (i == 1) - { - continue; - } - // Class summary doc writer.WriteLine("/// "); writer.WriteLine($"/// An that could be one of {i.ToWords()} different types. On execution will");