Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[csharp-netore][generichost] Renamed ToModel to AsModel #15662

Merged
merged 2 commits into from
May 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -110,9 +110,9 @@ namespace {{packageName}}.{{clientPackage}}
/// <summary>
/// Deserializes the server's response
/// </summary>
public T{{nrt?}} ToModel(System.Text.Json.JsonSerializerOptions{{nrt?}} options = null)
public T{{nrt?}} AsModel(System.Text.Json.JsonSerializerOptions{{nrt?}} options = null)
{
{{>ToModel}}
{{>AsModel}}
}

/// <summary>
Expand All @@ -122,7 +122,7 @@ namespace {{packageName}}.{{clientPackage}}
{
try
{
model = ToModel(options);
model = AsModel(options);
return model != null;
}
catch
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// This logic may be modified with the ToModel.mustache template
// This logic may be modified with the AsModel.mustache template
return IsSuccessStatusCode
? System.Text.Json.JsonSerializer.Deserialize<T>(RawContent, options ?? _jsonSerializerOptions)
: default(T);
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ namespace YourProject
{{#operation}}
{{#-first}}
ApiResponse<{{#returnType}}{{{.}}}{{/returnType}}{{^returnType}}object{{/returnType}}> response = await api.{{operationId}}Async("todo");
{{#returnType}}{{{.}}}{{/returnType}}{{^returnType}}object{{/returnType}} model = response.ToModel();
{{#returnType}}{{{.}}}{{/returnType}}{{^returnType}}object{{/returnType}} model = response.AsModel();
{{/-first}}
{{/operation}}
{{/-first}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ namespace {{packageName}}.Test.{{apiPackage}}
{{/allParams}}
{{#returnType}}
var response = await _instance.{{operationId}}Async({{#allParams}}{{paramName}}{{^-last}}, {{/-last}}{{/allParams}});
var model = response.ToModel();
var model = response.AsModel();
Assert.IsType<{{{.}}}>(model);
{{/returnType}}
{{^returnType}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public async Task Call123TestSpecialTagsAsyncTest()
{
ModelClient modelClient = default;
var response = await _instance.Call123TestSpecialTagsAsync(modelClient);
var model = response.ToModel();
var model = response.AsModel();
Assert.IsType<ModelClient>(model);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public DefaultApiTests(): base(Array.Empty<string>())
public async Task FooGetAsyncTest()
{
var response = await _instance.FooGetAsync();
var model = response.ToModel();
var model = response.AsModel();
Assert.IsType<FooGetDefaultResponse>(model);
}

Expand All @@ -79,7 +79,7 @@ public async Task GetCountryAsyncTest()
public async Task HelloAsyncTest()
{
var response = await _instance.HelloAsync();
var model = response.ToModel();
var model = response.AsModel();
Assert.IsType<List<Guid>>(model);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public FakeApiTests(): base(Array.Empty<string>())
public async Task FakeHealthGetAsyncTest()
{
var response = await _instance.FakeHealthGetAsync();
var model = response.ToModel();
var model = response.AsModel();
Assert.IsType<HealthCheckResult>(model);
}

Expand All @@ -70,7 +70,7 @@ public async Task FakeOuterBooleanSerializeAsyncTest()
{
bool? body = default;
var response = await _instance.FakeOuterBooleanSerializeAsync(body);
var model = response.ToModel();
var model = response.AsModel();
Assert.IsType<bool>(model);
}

Expand All @@ -82,7 +82,7 @@ public async Task FakeOuterCompositeSerializeAsyncTest()
{
OuterComposite? outerComposite = default;
var response = await _instance.FakeOuterCompositeSerializeAsync(outerComposite);
var model = response.ToModel();
var model = response.AsModel();
Assert.IsType<OuterComposite>(model);
}

Expand All @@ -94,7 +94,7 @@ public async Task FakeOuterNumberSerializeAsyncTest()
{
decimal? body = default;
var response = await _instance.FakeOuterNumberSerializeAsync(body);
var model = response.ToModel();
var model = response.AsModel();
Assert.IsType<decimal>(model);
}

Expand All @@ -107,7 +107,7 @@ public async Task FakeOuterStringSerializeAsyncTest()
Guid requiredStringUuid = default;
string? body = default;
var response = await _instance.FakeOuterStringSerializeAsync(requiredStringUuid, body);
var model = response.ToModel();
var model = response.AsModel();
Assert.IsType<string>(model);
}

Expand All @@ -118,7 +118,7 @@ public async Task FakeOuterStringSerializeAsyncTest()
public async Task GetArrayOfEnumsAsyncTest()
{
var response = await _instance.GetArrayOfEnumsAsync();
var model = response.ToModel();
var model = response.AsModel();
Assert.IsType<List<OuterEnum>>(model);
}

Expand Down Expand Up @@ -151,7 +151,7 @@ public async Task TestClientModelAsyncTest()
{
ModelClient modelClient = default;
var response = await _instance.TestClientModelAsync(modelClient);
var model = response.ToModel();
var model = response.AsModel();
Assert.IsType<ModelClient>(model);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public async Task TestClassnameAsyncTest()
{
ModelClient modelClient = default;
var response = await _instance.TestClassnameAsync(modelClient);
var model = response.ToModel();
var model = response.AsModel();
Assert.IsType<ModelClient>(model);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ public async Task FindPetsByStatusAsyncTest()
{
List<string> status = default;
var response = await _instance.FindPetsByStatusAsync(status);
var model = response.ToModel();
var model = response.AsModel();
Assert.IsType<List<Pet>>(model);
}

Expand All @@ -92,7 +92,7 @@ public async Task FindPetsByTagsAsyncTest()
{
List<string> tags = default;
var response = await _instance.FindPetsByTagsAsync(tags);
var model = response.ToModel();
var model = response.AsModel();
Assert.IsType<List<Pet>>(model);
}

Expand All @@ -104,7 +104,7 @@ public async Task GetPetByIdAsyncTest()
{
long petId = default;
var response = await _instance.GetPetByIdAsync(petId);
var model = response.ToModel();
var model = response.AsModel();
Assert.IsType<Pet>(model);
}

Expand Down Expand Up @@ -140,7 +140,7 @@ public async Task UploadFileAsyncTest()
System.IO.Stream? file = default;
string? additionalMetadata = default;
var response = await _instance.UploadFileAsync(petId, file, additionalMetadata);
var model = response.ToModel();
var model = response.AsModel();
Assert.IsType<ApiResponse>(model);
}

Expand All @@ -154,7 +154,7 @@ public async Task UploadFileWithRequiredFileAsyncTest()
long petId = default;
string? additionalMetadata = default;
var response = await _instance.UploadFileWithRequiredFileAsync(requiredFile, petId, additionalMetadata);
var model = response.ToModel();
var model = response.AsModel();
Assert.IsType<ApiResponse>(model);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public async Task DeleteOrderAsyncTest()
public async Task GetInventoryAsyncTest()
{
var response = await _instance.GetInventoryAsync();
var model = response.ToModel();
var model = response.AsModel();
Assert.IsType<Dictionary<string, int>>(model);
}

Expand All @@ -80,7 +80,7 @@ public async Task GetOrderByIdAsyncTest()
{
long orderId = default;
var response = await _instance.GetOrderByIdAsync(orderId);
var model = response.ToModel();
var model = response.AsModel();
Assert.IsType<Order>(model);
}

Expand All @@ -92,7 +92,7 @@ public async Task PlaceOrderAsyncTest()
{
Order order = default;
var response = await _instance.PlaceOrderAsync(order);
var model = response.ToModel();
var model = response.AsModel();
Assert.IsType<Order>(model);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ public async Task GetUserByNameAsyncTest()
{
string username = default;
var response = await _instance.GetUserByNameAsync(username);
var model = response.ToModel();
var model = response.AsModel();
Assert.IsType<User>(model);
}

Expand All @@ -112,7 +112,7 @@ public async Task LoginUserAsyncTest()
string username = default;
string password = default;
var response = await _instance.LoginUserAsync(username, password);
var model = response.ToModel();
var model = response.AsModel();
Assert.IsType<string>(model);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,9 +116,9 @@ public ApiResponse(System.Net.Http.HttpRequestMessage httpRequestMessage, System
/// <summary>
/// Deserializes the server's response
/// </summary>
public T? ToModel(System.Text.Json.JsonSerializerOptions? options = null)
public T? AsModel(System.Text.Json.JsonSerializerOptions? options = null)
{
// This logic may be modified with the ToModel.mustache template
// This logic may be modified with the AsModel.mustache template
return IsSuccessStatusCode
? System.Text.Json.JsonSerializer.Deserialize<T>(RawContent, options ?? _jsonSerializerOptions)
: default(T);
Expand All @@ -131,7 +131,7 @@ public bool TryToModel([NotNullWhen(true)] out T? model, System.Text.Json.JsonSe
{
try
{
model = ToModel(options);
model = AsModel(options);
return model != null;
}
catch
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ namespace YourProject
var host = CreateHostBuilder(args).Build();
var api = host.Services.GetRequiredService<IAnotherFakeApi>();
ApiResponse<ModelClient> response = await api.Call123TestSpecialTagsAsync("todo");
ModelClient model = response.ToModel();
ModelClient model = response.AsModel();
}

public static IHostBuilder CreateHostBuilder(string[] args) => Host.CreateDefaultBuilder(args)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public async Task Call123TestSpecialTagsAsyncTest()
{
ModelClient modelClient = default;
var response = await _instance.Call123TestSpecialTagsAsync(modelClient);
var model = response.ToModel();
var model = response.AsModel();
Assert.IsType<ModelClient>(model);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public DefaultApiTests(): base(Array.Empty<string>())
public async Task FooGetAsyncTest()
{
var response = await _instance.FooGetAsync();
var model = response.ToModel();
var model = response.AsModel();
Assert.IsType<FooGetDefaultResponse>(model);
}

Expand All @@ -79,7 +79,7 @@ public async Task GetCountryAsyncTest()
public async Task HelloAsyncTest()
{
var response = await _instance.HelloAsync();
var model = response.ToModel();
var model = response.AsModel();
Assert.IsType<List<Guid>>(model);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public FakeApiTests(): base(Array.Empty<string>())
public async Task FakeHealthGetAsyncTest()
{
var response = await _instance.FakeHealthGetAsync();
var model = response.ToModel();
var model = response.AsModel();
Assert.IsType<HealthCheckResult>(model);
}

Expand All @@ -70,7 +70,7 @@ public async Task FakeOuterBooleanSerializeAsyncTest()
{
bool? body = default;
var response = await _instance.FakeOuterBooleanSerializeAsync(body);
var model = response.ToModel();
var model = response.AsModel();
Assert.IsType<bool>(model);
}

Expand All @@ -82,7 +82,7 @@ public async Task FakeOuterCompositeSerializeAsyncTest()
{
OuterComposite outerComposite = default;
var response = await _instance.FakeOuterCompositeSerializeAsync(outerComposite);
var model = response.ToModel();
var model = response.AsModel();
Assert.IsType<OuterComposite>(model);
}

Expand All @@ -94,7 +94,7 @@ public async Task FakeOuterNumberSerializeAsyncTest()
{
decimal? body = default;
var response = await _instance.FakeOuterNumberSerializeAsync(body);
var model = response.ToModel();
var model = response.AsModel();
Assert.IsType<decimal>(model);
}

Expand All @@ -107,7 +107,7 @@ public async Task FakeOuterStringSerializeAsyncTest()
Guid requiredStringUuid = default;
string body = default;
var response = await _instance.FakeOuterStringSerializeAsync(requiredStringUuid, body);
var model = response.ToModel();
var model = response.AsModel();
Assert.IsType<string>(model);
}

Expand All @@ -118,7 +118,7 @@ public async Task FakeOuterStringSerializeAsyncTest()
public async Task GetArrayOfEnumsAsyncTest()
{
var response = await _instance.GetArrayOfEnumsAsync();
var model = response.ToModel();
var model = response.AsModel();
Assert.IsType<List<OuterEnum>>(model);
}

Expand Down Expand Up @@ -151,7 +151,7 @@ public async Task TestClientModelAsyncTest()
{
ModelClient modelClient = default;
var response = await _instance.TestClientModelAsync(modelClient);
var model = response.ToModel();
var model = response.AsModel();
Assert.IsType<ModelClient>(model);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public async Task TestClassnameAsyncTest()
{
ModelClient modelClient = default;
var response = await _instance.TestClassnameAsync(modelClient);
var model = response.ToModel();
var model = response.AsModel();
Assert.IsType<ModelClient>(model);
}
}
Expand Down
Loading