forked from Azure/azure-sdk-for-net
-
Notifications
You must be signed in to change notification settings - Fork 0
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
TestV2 for patch model purpose #7
Draft
pshao25
wants to merge
5
commits into
annelo-msft:core-mergepatch-proto2
Choose a base branch
from
pshao25:mergepatch-testv2
base: core-mergepatch-proto2
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
34 changes: 34 additions & 0 deletions
34
sdk/loadtestservice/Azure.Developer.LoadTesting/src/Models/RoundTripModel.Serialization.cs
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,34 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. | ||
|
||
using System.Text.Json; | ||
using System.Xml.Linq; | ||
using Azure.Core; | ||
using Azure.Core.Json; | ||
|
||
namespace Azure.Developer.LoadTesting.Models | ||
{ | ||
public partial class RoundTripModel : IUtf8JsonSerializable | ||
{ | ||
void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) | ||
{ | ||
_element.WriteTo(writer, 'P'); // TO-DO: we need another option not calling 'P' but its logic is the same as 'P' | ||
} | ||
|
||
/// <summary> Deserializes the model from a raw response. </summary> | ||
/// <param name="response"> The response to deserialize the model from. </param> | ||
internal static RoundTripModel FromResponse(Response response) | ||
{ | ||
MutableJsonDocument jsonDocument = MutableJsonDocument.Parse(response.Content); | ||
return new RoundTripModel(jsonDocument.RootElement); | ||
} | ||
|
||
/// <summary> Convert into a Utf8JsonRequestContent. </summary> | ||
internal RequestContent ToRequestContent() | ||
{ | ||
var content = new Utf8JsonRequestContent(); | ||
content.JsonWriter.WriteObjectValue(this); | ||
return content; | ||
} | ||
} | ||
} |
142 changes: 142 additions & 0 deletions
142
sdk/loadtestservice/Azure.Developer.LoadTesting/src/Models/RoundTripModel.cs
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,142 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. | ||
|
||
using System; | ||
using System.Collections.Generic; | ||
using System.IO; | ||
using System.Text.Json; | ||
using System.Xml.Linq; | ||
using Azure.Core; | ||
using Azure.Core.Json; | ||
|
||
namespace Azure.Developer.LoadTesting.Models | ||
{ | ||
/// <summary> | ||
/// model RoundTripModel { | ||
/// requiredString: string; | ||
/// requiredNullableInt: int32 | null; | ||
/// requiredNullableString: string | null; | ||
/// nonRequiredNullableInt?: int32 | null; | ||
/// nonRequiredNullableString?: string | null; | ||
/// } | ||
/// </summary> | ||
public partial class RoundTripModel | ||
{ | ||
private MutableJsonElement _element; | ||
|
||
/// <summary> | ||
/// Initializes a new instance of the <see cref="RoundTripModel"/> class. | ||
/// </summary> | ||
public RoundTripModel(string requiredString, int? requiredNullableInt, string requiredNullableString) | ||
{ | ||
Argument.AssertNotNull(requiredString, nameof(requiredString)); | ||
|
||
BinaryData utf8Json; | ||
using (MemoryStream stream = new()) | ||
{ | ||
using Utf8JsonWriter writer = new Utf8JsonWriter(stream); | ||
writer.WriteStartObject(); | ||
writer.WritePropertyName("requiredString"); | ||
writer.WriteStringValue(requiredString); | ||
if (requiredNullableInt != null) | ||
{ | ||
writer.WritePropertyName("requiredNullableInt"); | ||
writer.WriteNumberValue(requiredNullableInt.Value); | ||
} | ||
else | ||
{ | ||
writer.WriteNull("requiredNullableInt"); | ||
} | ||
if (requiredNullableString != null) | ||
{ | ||
writer.WritePropertyName("requiredNullableString"); | ||
writer.WriteStringValue(requiredNullableString); | ||
} | ||
else | ||
{ | ||
writer.WriteNull("requiredNullableString"); | ||
} | ||
writer.WriteEndObject(); | ||
writer.Flush(); | ||
stream.Position = 0; | ||
utf8Json = BinaryData.FromStream(stream); | ||
} | ||
_element = MutableJsonDocument.Parse(utf8Json).RootElement; | ||
} | ||
|
||
internal RoundTripModel(MutableJsonElement element) | ||
{ | ||
_element = element; | ||
} | ||
|
||
/// <summary> Required string, illustrating a reference type property. </summary> | ||
public string RequiredString | ||
{ | ||
get | ||
{ | ||
if (_element.TryGetProperty("requiredString", out MutableJsonElement value)) | ||
{ | ||
return value.GetString(); | ||
} | ||
return default; | ||
} | ||
set => _element.SetProperty("requiredString", value); | ||
} | ||
|
||
/// <summary> Required nullable int. </summary> | ||
public int? RequiredNullableInt | ||
{ | ||
get | ||
{ | ||
if (_element.TryGetProperty("requiredNullableInt", out MutableJsonElement value)) | ||
{ | ||
return value.GetInt32(); | ||
} | ||
return default; | ||
} | ||
set => _element.SetProperty("requiredNullableInt", value); | ||
} | ||
|
||
/// <summary> Required nullable string. </summary> | ||
public string RequiredNullableString | ||
{ | ||
get | ||
{ | ||
if (_element.TryGetProperty("requiredNullableString", out MutableJsonElement value)) | ||
{ | ||
return value.GetString(); | ||
} | ||
return default; | ||
} | ||
set => _element.SetProperty("requiredNullableString", value); | ||
} | ||
|
||
/// <summary> Optional nullable int. </summary> | ||
public int? NonRequiredNullableInt | ||
{ | ||
get | ||
{ | ||
if (_element.TryGetProperty("nonRequiredNullableInt", out MutableJsonElement value)) | ||
{ | ||
return value.GetInt32(); | ||
} | ||
return null; | ||
} | ||
set => _element.SetProperty("nonRequiredNullableInt", value); | ||
} | ||
|
||
/// <summary> Optional nullable string. </summary> | ||
public string NonRequiredNullableString | ||
{ | ||
get | ||
{ | ||
if (_element.TryGetProperty("nonRequiredNullableString", out MutableJsonElement value)) | ||
{ | ||
return value.GetString(); | ||
} | ||
return null; | ||
} | ||
set => _element.SetProperty("nonRequiredNullableString", value); | ||
} | ||
} | ||
} |
64 changes: 64 additions & 0 deletions
64
sdk/loadtestservice/Azure.Developer.LoadTesting/src/Models/TestV2.Serialization.cs
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,64 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. | ||
|
||
#nullable disable | ||
|
||
using Azure.Core.Serialization; | ||
using Azure.Core; | ||
using Azure.Core.Json; | ||
using System.Text.Json; | ||
using System; | ||
|
||
namespace Azure.Developer.LoadTesting.Models | ||
{ | ||
public partial class TestV2 : IUtf8JsonSerializable, IJsonModelSerializable | ||
{ | ||
void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) | ||
{ | ||
writer.WriteStartObject(); | ||
writer.WritePropertyName("key"u8); | ||
writer.WriteStringValue(Key); | ||
writer.WritePropertyName("requiredProperty"u8); | ||
writer.WriteNumberValue(RequiredProperty); | ||
if (Optional.IsDefined(OptionalProperty)) | ||
{ | ||
writer.WritePropertyName("optionalProperty"u8); | ||
writer.WriteStringValue(OptionalProperty); | ||
} | ||
writer.WriteEndObject(); | ||
} | ||
|
||
void IJsonModelSerializable.Serialize(Utf8JsonWriter writer, ModelSerializerOptions options) | ||
{ | ||
((IUtf8JsonSerializable)this).Write(writer); | ||
} | ||
|
||
object IJsonModelSerializable.Deserialize(ref Utf8JsonReader reader, ModelSerializerOptions options) | ||
{ | ||
JsonDocument doc = JsonDocument.ParseValue(ref reader); | ||
MutableJsonDocument mdoc = new MutableJsonDocument(doc, new JsonSerializerOptions()); | ||
return new TestV2(mdoc.RootElement); | ||
} | ||
|
||
object IModelSerializable.Deserialize(BinaryData data, ModelSerializerOptions options) | ||
{ | ||
MutableJsonDocument jsonDocument = MutableJsonDocument.Parse(data); | ||
return new TestV2(jsonDocument.RootElement); | ||
} | ||
|
||
BinaryData IModelSerializable.Serialize(ModelSerializerOptions options) => ModelSerializerHelper.SerializeToBinaryData(writer => ((IJsonModelSerializable)this).Serialize(writer, options)); | ||
|
||
internal virtual RequestContent ToRequestContent() | ||
{ | ||
var content = new Utf8JsonRequestContent(); | ||
content.JsonWriter.WriteObjectValue(this); | ||
return content; | ||
} | ||
|
||
internal static TestV2 FromResponse(Response response) | ||
{ | ||
MutableJsonDocument jsonDocument = MutableJsonDocument.Parse(response.Content); | ||
return new TestV2(jsonDocument.RootElement); | ||
} | ||
} | ||
} |
109 changes: 109 additions & 0 deletions
109
sdk/loadtestservice/Azure.Developer.LoadTesting/src/Models/TestV2.cs
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,109 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. | ||
|
||
#nullable disable | ||
using System.IO; | ||
using System.Text.Json; | ||
using System; | ||
using Azure.Core.Json; | ||
using Azure.Core; | ||
using System.Collections.Generic; | ||
|
||
namespace Azure.Developer.LoadTesting.Models | ||
{ | ||
/// <summary> | ||
/// model TestV2 { | ||
/// @key | ||
/// key: string; // Because it has @key so there will be a @path implictly added to it. | ||
/// | ||
/// @visibility("read") | ||
/// readOnlyProperty: string; // Add this propery to differentiate request from response. | ||
/// optionalProperty?: string; | ||
/// requiredProperty: int32; | ||
/// } | ||
/// </summary> | ||
public partial class TestV2 | ||
{ | ||
private MutableJsonElement _element; | ||
|
||
/// <summary> </summary> | ||
public TestV2(string key, int required) | ||
{ | ||
BinaryData utf8Json; | ||
using (MemoryStream stream = new()) | ||
{ | ||
using Utf8JsonWriter writer = new Utf8JsonWriter(stream); | ||
writer.WriteStartObject(); | ||
writer.WritePropertyName("key"); | ||
writer.WriteStringValue(key.AsSpan()); | ||
writer.WritePropertyName("requiredProperty"); | ||
writer.WriteNumberValue(required); | ||
writer.WriteEndObject(); | ||
writer.Flush(); | ||
stream.Position = 0; | ||
utf8Json = BinaryData.FromStream(stream); | ||
} | ||
_element = MutableJsonDocument.Parse(utf8Json).RootElement; | ||
} | ||
|
||
internal TestV2(MutableJsonElement element) | ||
{ | ||
_element = element; | ||
} | ||
|
||
/// <summary></summary> | ||
public string Key | ||
{ | ||
get | ||
{ | ||
if (_element.TryGetProperty("key", out MutableJsonElement value)) | ||
{ | ||
return value.GetString(); | ||
} | ||
return default; | ||
} | ||
set => _element.SetProperty("key", value); | ||
} | ||
|
||
/// <summary> </summary> | ||
public int RequiredProperty | ||
{ | ||
get | ||
{ | ||
if (_element.TryGetProperty("requiredProperty", out MutableJsonElement value)) | ||
{ | ||
return value.GetInt32(); | ||
} | ||
return default; | ||
} | ||
set => _element.SetProperty("requiredProperty", value); | ||
} | ||
|
||
/// <summary> </summary> | ||
public string OptionalProperty | ||
{ | ||
get | ||
{ | ||
if (_element.TryGetProperty("optionalProperty", out MutableJsonElement value)) | ||
{ | ||
return value.GetString(); | ||
} | ||
return default; | ||
} | ||
set => _element.SetProperty("optionalProperty", value); | ||
} | ||
|
||
/// <summary> </summary> | ||
public string ReadOnlyProperty | ||
{ | ||
get | ||
{ | ||
if (_element.TryGetProperty("readOnlyProperty", out MutableJsonElement value)) | ||
{ | ||
return value.GetString(); | ||
} | ||
return default; | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should understand why this property is required for GET and PUT but not for PATCH. I don't think we have a good foundation for this question yet.