-
Notifications
You must be signed in to change notification settings - Fork 5.1k
Feature/model reader writer #39421
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
Merged
Merged
Feature/model reader writer #39421
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
fb618f6
Revert "update api"
m-nash d62f58d
Revert "remove serialization"
m-nash 36b225e
Merge remote-tracking branch 'origin/main' into feature/modelSerializer
ArcturusZhang c291226
fix after merge
ArcturusZhang a0142ed
Merge branch 'feature/modelSerializer' of https://github.com/Azure/az…
m-nash 6bed41d
merge in feature/core-experiment
m-nash d3fb51b
update after merge
m-nash f1741f0
Merge branch 'feature/core-experiment' of https://github.com/Azure/az…
m-nash 0dffe78
Merge branch 'feature/core-experiment' of https://github.com/Azure/az…
m-nash 776891b
initial checkin for the model reader writer into new System.Net.Clien…
m-nash 71b8485
update api
m-nash 87dd212
Merge branch 'feature/core-experiment' of https://github.com/Azure/az…
m-nash 04a5b80
update test class name reference
m-nash c7a4bb8
update request content api
m-nash 3b329da
update api
m-nash 8ba8af9
removing artifacts from test projects
m-nash 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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
67 changes: 67 additions & 0 deletions
67
sdk/core/Azure.Core/tests/ModelReaderWriter/ModelReaderWriterRequestContentTests.cs
This file contains hidden or 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,67 @@ | ||
| // Copyright (c) Microsoft Corporation. All rights reserved. | ||
| // Licensed under the MIT License. | ||
|
|
||
| using System; | ||
| using System.Net.ClientModel; | ||
| using System.Net.ClientModel.Core; | ||
| using System.Reflection; | ||
| using Azure.Core.Tests.ModelReaderWriterTests.Models; | ||
| using NUnit.Framework; | ||
|
|
||
| namespace Azure.Core.Tests.ModelReaderWriterTests | ||
| { | ||
| public class ModelReaderWriterRequestContentTests | ||
| { | ||
| private const string json = "{\"kind\":\"X\",\"name\":\"Name\",\"xProperty\":100}"; | ||
| private ModelX _modelX; | ||
|
|
||
| [OneTimeSetUp] | ||
| public void OneTimeSetUp() | ||
| { | ||
| _modelX = ModelReaderWriter.Read<ModelX>(BinaryData.FromString(json)); | ||
| } | ||
|
|
||
| [Test] | ||
| public void CanCalculateLength() | ||
| { | ||
| //use IModelSerializable | ||
| var content = RequestContent.Create((IModel<ModelX>)_modelX); | ||
| AssertContentType(content, "ModelWriterContent"); | ||
| content.TryComputeLength(out long lengthNonJson); | ||
| Assert.Greater(lengthNonJson, 0); | ||
|
|
||
| //use IModelJsonSerializable | ||
| var jsonContent = RequestContent.Create((IJsonModel<ModelX>)_modelX); | ||
| AssertContentType(jsonContent, "JsonModelWriterContent"); | ||
| content.TryComputeLength(out long lengthJson); | ||
| Assert.Greater(lengthJson, 0); | ||
|
|
||
| Assert.AreEqual(lengthNonJson, lengthJson); | ||
|
|
||
| //use default | ||
| jsonContent = RequestContent.Create(_modelX); | ||
| AssertContentType(jsonContent, "JsonModelWriterContent"); | ||
| content.TryComputeLength(out lengthJson); | ||
| Assert.Greater(lengthJson, 0); | ||
|
|
||
| Assert.AreEqual(lengthNonJson, lengthJson); | ||
| } | ||
|
|
||
| private static void AssertContentType(RequestContent content, string expectedContent) | ||
| { | ||
| Assert.AreEqual("PipelineContentContent", content.GetType().Name); | ||
| var field = content.GetType().GetField("_content", BindingFlags.NonPublic | BindingFlags.Instance); | ||
| Assert.IsNotNull(field); | ||
| Assert.AreEqual(expectedContent, field.GetValue(content).GetType().Name); | ||
| } | ||
|
|
||
| [Test] | ||
| public void ValidatePrivateClassType() | ||
| { | ||
| IModel<ModelX> modelX = _modelX; | ||
|
|
||
| RequestContent content = RequestContent.Create(modelX); | ||
| AssertContentType(content, "ModelWriterContent"); | ||
| } | ||
| } | ||
| } |
This file contains hidden or 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.
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.
👍