-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
21 changed files
with
668 additions
and
225 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation"> | ||
<s:Boolean x:Key="/Default/CodeEditing/SuppressUninitializedWarningFix/Enabled/@EntryValue">False</s:Boolean> | ||
<s:Boolean x:Key="/Default/UserDictionary/Words/=Deps/@EntryIndexedValue">True</s:Boolean></wpf:ResourceDictionary> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
|
||
namespace OpenApiLINQPadDriver.Extensions; | ||
internal static class EnumerableExtensions | ||
{ | ||
public static IEnumerable<T> AppendIf<T>(this IEnumerable<T> enumerable, bool shouldAppend, T element) | ||
=> shouldAppend ? enumerable.Append(element) : enumerable; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
namespace OpenApiLINQPadDriverTests; | ||
public class AuthTests : BaseDriverApiTest | ||
{ | ||
[Theory] //todo test both global and local setter | ||
[MemberData(nameof(EnumInlineData.Data), MemberType = typeof(EnumInlineData))] | ||
public async Task Setting_Headers_In_PrepareRequestFunction_For_MultipleClientsFromFirstTagAndOperationName(JsonLibrary jsonLibrary, ClassStyle classStyle) | ||
{ | ||
MapGet("Header", "/replay", "Replay", static (HttpContext context) => context.Request.Headers); | ||
StartApi(); | ||
|
||
await ExecuteScriptAsync( | ||
""" | ||
var tokenValue = "fakeBearer"; | ||
this.PrepareRequestFunction = (a, requestMessage, c) => | ||
{ | ||
requestMessage.Headers.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("Bearer", tokenValue); | ||
}; | ||
|
||
var replayedHeaders = await this.HeaderClient.ReplayAsync(); | ||
|
||
replayedHeaders.Should() | ||
.Contain(h => h.Key == "Authorization" && h.Value.Any(v => v == $"Bearer {tokenValue}")); | ||
// return 1; | ||
""", EndpointGrouping.MultipleClientsFromFirstTagAndOperationName, jsonLibrary, classStyle); | ||
} | ||
|
||
[Theory] //todo test both global and local setter | ||
[MemberData(nameof(EnumInlineData.Data), MemberType = typeof(EnumInlineData))] | ||
public async Task Setting_Headers_In_PrepareRequestFunction_For_SingleClientFromOperationIdOperationName(JsonLibrary jsonLibrary, ClassStyle classStyle) | ||
{ | ||
MapGet("Header", "/replay", "Replay", static (HttpContext context) => context.Request.Headers); | ||
StartApi(); | ||
|
||
await ExecuteScriptAsync( | ||
""" | ||
var tokenValue = "fakeBearer"; | ||
this.PrepareRequestFunction = (a, requestMessage, c) => | ||
{ | ||
requestMessage.Headers.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("Bearer", tokenValue); | ||
}; | ||
|
||
var replayedHeaders = await this.ReplayAsync(); | ||
|
||
replayedHeaders.Should() | ||
.Contain(h => h.Key == "Authorization" && h.Value.Any(v => v == $"Bearer {tokenValue}")); | ||
|
||
//replayedHeaders.Dump(); | ||
return replayedHeaders; | ||
""", EndpointGrouping.SingleClientFromOperationIdOperationName, jsonLibrary, classStyle); | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
namespace OpenApiLINQPadDriverTests; | ||
public class CustomResponseBody : BaseDriverApiTest | ||
{ | ||
[Theory] | ||
[MemberData(nameof(EnumInlineData.Data), MemberType = typeof(EnumInlineData))] | ||
public async Task MultipleClientsFromFirstTagAndOperationName(JsonLibrary jsonLibrary, ClassStyle classStyle) | ||
{ | ||
MapGet("CustomResponseAndRequest", "/First", "first", static ([FromBody] CustomRequest request) => new CustomResponse(request.Foo, request.Bar)); | ||
StartApi(); | ||
|
||
var requestConstructor = GetRequestCtor(classStyle); | ||
var responseConstructor = GetResponseCtor(classStyle); | ||
|
||
await ExecuteScriptAsync( | ||
$""" | ||
{nameof(CustomRequest)} request = {requestConstructor}; | ||
|
||
var response = await this.CustomResponseAndRequestClient.FirstAsync(request); | ||
response.Should().BeEquivalentTo({responseConstructor}); | ||
|
||
""", EndpointGrouping.MultipleClientsFromFirstTagAndOperationName, jsonLibrary, classStyle); | ||
} | ||
|
||
[Theory] | ||
[MemberData(nameof(EnumInlineData.Data), MemberType = typeof(EnumInlineData))] | ||
public async Task SingleClientFromOperationIdOperationName(JsonLibrary jsonLibrary, ClassStyle classStyle) | ||
{ | ||
MapGet("CustomResponseAndRequest", "/First", "first", static ([FromBody] CustomRequest request) => new CustomResponse(request.Foo, request.Bar)); | ||
StartApi(); | ||
|
||
var requestConstructor = GetRequestCtor(classStyle); | ||
var responseConstructor = GetResponseCtor(classStyle); | ||
|
||
await ExecuteScriptAsync( | ||
$""" | ||
{nameof(CustomRequest)} request = {requestConstructor}; | ||
|
||
var response = await this.FirstAsync(request); | ||
response.Should().BeEquivalentTo({responseConstructor}); | ||
|
||
""", EndpointGrouping.SingleClientFromOperationIdOperationName, jsonLibrary, classStyle); | ||
} | ||
|
||
private record CustomResponse(string Foo, int Bar); | ||
private record CustomRequest(string Foo, int Bar); | ||
|
||
private static string GetResponseCtor(ClassStyle classStyle) => classStyle switch | ||
{ | ||
ClassStyle.Poco or ClassStyle.Inpc or ClassStyle.Prism => | ||
""" | ||
new CustomResponse() | ||
{ | ||
Foo = "string", | ||
Bar = 1 | ||
} | ||
""", | ||
ClassStyle.Record => "new CustomResponse(1, \"string\")", | ||
_ => throw new InvalidOperationException() | ||
}; | ||
|
||
private static string GetRequestCtor(ClassStyle classStyle) => classStyle switch | ||
{ | ||
ClassStyle.Poco or ClassStyle.Inpc or ClassStyle.Prism => | ||
""" | ||
new CustomRequest() | ||
{ | ||
Foo = "string", | ||
Bar = 1 | ||
} | ||
""", | ||
ClassStyle.Record => "new CustomRequest(1, \"string\")", | ||
_ => throw new InvalidOperationException() | ||
}; | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.