-
Notifications
You must be signed in to change notification settings - Fork 359
Port Primitive Types Tests #3160
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
Changes from 5 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
347a76a
port duration tests
WanjohiSammy 5511e67
Add more tests
WanjohiSammy 22cee18
Port PrimitiveValueFormatTest
WanjohiSammy e1450e1
Port PrimitiveKeysValuesTests
WanjohiSammy ee15ca2
Resolve failed errors
WanjohiSammy 53545d9
Added DecimalTests
WanjohiSammy 35671d4
Use TheoryDataSet instead of loop through test cases
WanjohiSammy 9280c7a
Refactor tests
WanjohiSammy ea8b413
Ensure both DataServiceUrlKeyDelimiter.Parentheses and DataServiceUrl…
WanjohiSammy eab0343
Added controller actions to handle keys in parenthesis
WanjohiSammy 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
235 changes: 235 additions & 0 deletions
235
...sts/Common/Microsoft.OData.Client.E2E.TestCommon/Helpers/ODataMessageReaderTestsHelper.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,235 @@ | ||
//--------------------------------------------------------------------- | ||
// <copyright file="ODataMessageReaderTestsHelper.cs" company="Microsoft"> | ||
// Copyright (C) Microsoft Corporation. All rights reserved. See License.txt in the project root for license information. | ||
// </copyright> | ||
//--------------------------------------------------------------------- | ||
|
||
using Microsoft.OData.Client.E2E.TestCommon.Common; | ||
using Microsoft.OData.Edm; | ||
using Xunit; | ||
|
||
namespace Microsoft.OData.Client.E2E.TestCommon.Helpers; | ||
|
||
public class ODataMessageReaderTestsHelper | ||
{ | ||
private readonly Uri BaseUri; | ||
private readonly IEdmModel Model; | ||
private readonly HttpClient Client; | ||
private const string IncludeAnnotation = "odata.include-annotations"; | ||
|
||
public ODataMessageReaderTestsHelper(Uri baseUri, IEdmModel model, HttpClient client) | ||
{ | ||
this.BaseUri = baseUri; | ||
this.Model = model; | ||
this.Client = client; | ||
} | ||
|
||
/// <summary> | ||
/// Queries resource entries asynchronously based on the provided query text and MIME type. | ||
/// </summary> | ||
/// <param name="queryText">The query text to append to the base URI.</param> | ||
/// <param name="mimeType">The MIME type to set in the request header.</param> | ||
/// <returns>A task that represents the asynchronous operation. The task result contains a list of <see cref="ODataResource"/>.</returns> | ||
public async Task<List<ODataResource>> QueryResourceEntriesAsync(string queryText, string mimeType) | ||
|
||
{ | ||
ODataMessageReaderSettings readerSettings = new() { BaseUri = BaseUri }; | ||
var requestUrl = new Uri(BaseUri.AbsoluteUri + queryText, UriKind.Absolute); | ||
|
||
var requestMessage = new TestHttpClientRequestMessage(requestUrl, Client); | ||
requestMessage.SetHeader("Accept", mimeType); | ||
requestMessage.SetHeader("Prefer", string.Format("{0}={1}", IncludeAnnotation, "*")); | ||
|
||
var responseMessage = await requestMessage.GetResponseAsync(); | ||
|
||
Assert.Equal(200, responseMessage.StatusCode); | ||
|
||
var entries = new List<ODataResource>(); | ||
if (!mimeType.Contains(MimeTypes.ODataParameterNoMetadata)) | ||
{ | ||
using (var messageReader = new ODataMessageReader(responseMessage, readerSettings, Model)) | ||
{ | ||
var reader = await messageReader.CreateODataResourceReaderAsync(); | ||
while (await reader.ReadAsync()) | ||
{ | ||
if (reader.State == ODataReaderState.ResourceEnd && reader.Item is ODataResource odataResource) | ||
{ | ||
entries.Add(odataResource); | ||
} | ||
} | ||
Assert.Equal(ODataReaderState.Completed, reader.State); | ||
} | ||
} | ||
|
||
return entries; | ||
} | ||
|
||
/// <summary> | ||
/// Queries resource sets asynchronously based on the provided query text and MIME type. | ||
/// </summary> | ||
/// <param name="queryText">The query text to append to the base URI.</param> | ||
/// <param name="mimeType">The MIME type to set in the request header.</param> | ||
/// <returns>A task that represents the asynchronous operation. The task result contains a list of <see cref="ODataResource"/>.</returns> | ||
public async Task<List<ODataResource>> QueryResourceSetsAsync(string queryText, string mimeType) | ||
|
||
{ | ||
ODataMessageReaderSettings readerSettings = new() { BaseUri = BaseUri }; | ||
var requestUrl = new Uri(BaseUri.AbsoluteUri + queryText, UriKind.Absolute); | ||
|
||
var requestMessage = new TestHttpClientRequestMessage(requestUrl, Client); | ||
requestMessage.SetHeader("Accept", mimeType); | ||
|
||
var responseMessage = await requestMessage.GetResponseAsync(); | ||
|
||
Assert.Equal(200, responseMessage.StatusCode); | ||
|
||
var entries = new List<ODataResource>(); | ||
if (!mimeType.Contains(MimeTypes.ODataParameterNoMetadata)) | ||
{ | ||
using (var messageReader = new ODataMessageReader(responseMessage, readerSettings, Model)) | ||
{ | ||
var reader = await messageReader.CreateODataResourceSetReaderAsync(); | ||
while (await reader.ReadAsync()) | ||
{ | ||
if (reader.State == ODataReaderState.ResourceEnd) | ||
{ | ||
if (reader.Item is ODataResource odataResource) | ||
{ | ||
entries.Add(odataResource); | ||
} | ||
} | ||
} | ||
Assert.Equal(ODataReaderState.Completed, reader.State); | ||
} | ||
|
||
} | ||
|
||
return entries; | ||
} | ||
|
||
public async Task<(List<ODataResource>, List<ODataResourceSet>)> QueryResourceAndResourceSetsAsync(string queryText, string mimeType) | ||
|
||
{ | ||
ODataMessageReaderSettings readerSettings = new() { BaseUri = BaseUri }; | ||
var requestUrl = new Uri(BaseUri.AbsoluteUri + queryText, UriKind.Absolute); | ||
|
||
var requestMessage = new TestHttpClientRequestMessage(requestUrl, Client); | ||
requestMessage.SetHeader("Accept", mimeType); | ||
|
||
var responseMessage = await requestMessage.GetResponseAsync(); | ||
|
||
Assert.Equal(200, responseMessage.StatusCode); | ||
|
||
var resourceEntries = new List<ODataResource>(); | ||
var resourceSetEntries = new List<ODataResourceSet>(); | ||
if (!mimeType.Contains(MimeTypes.ODataParameterNoMetadata)) | ||
{ | ||
using (var messageReader = new ODataMessageReader(responseMessage, readerSettings, Model)) | ||
{ | ||
var reader = await messageReader.CreateODataResourceSetReaderAsync(); | ||
while (await reader.ReadAsync()) | ||
{ | ||
if (reader.State == ODataReaderState.ResourceEnd && reader.Item is ODataResource odataResource) | ||
{ | ||
resourceEntries.Add(odataResource); | ||
} | ||
else if(reader.State == ODataReaderState.ResourceSetEnd && reader.Item is ODataResourceSet odataResourceSet) | ||
{ | ||
resourceSetEntries.Add(odataResourceSet); | ||
} | ||
} | ||
Assert.Equal(ODataReaderState.Completed, reader.State); | ||
} | ||
|
||
} | ||
|
||
return (resourceEntries, resourceSetEntries); | ||
} | ||
|
||
/// <summary> | ||
/// Queries an OData resource set asynchronously based on the provided query text and MIME type. | ||
/// </summary> | ||
/// <param name="queryText">The query text to append to the base URI.</param> | ||
/// <param name="mimeType">The MIME type to set in the request header.</param> | ||
/// <returns>A task that represents the asynchronous operation. The task result contains an <see cref="ODataResourceSet"/> if found; otherwise, null.</returns> | ||
public async Task<ODataResourceSet?> QueryODataResourceSetAsync(string queryText, string mimeType) | ||
{ | ||
ODataMessageReaderSettings readerSettings = new() { BaseUri = BaseUri }; | ||
var requestUrl = new Uri(BaseUri.AbsoluteUri + queryText, UriKind.Absolute); | ||
|
||
var requestMessage = new TestHttpClientRequestMessage(requestUrl, Client); | ||
requestMessage.SetHeader("Accept", mimeType); | ||
|
||
var responseMessage = await requestMessage.GetResponseAsync(); | ||
|
||
Assert.Equal(200, responseMessage.StatusCode); | ||
|
||
if (!mimeType.Contains(MimeTypes.ODataParameterNoMetadata)) | ||
{ | ||
using (var messageReader = new ODataMessageReader(responseMessage, readerSettings, Model)) | ||
{ | ||
var reader = await messageReader.CreateODataResourceReaderAsync(); | ||
while (await reader.ReadAsync()) | ||
{ | ||
if (reader.State == ODataReaderState.ResourceSetEnd && reader.Item is ODataResourceSet oDataResourceSet) | ||
{ | ||
return oDataResourceSet; | ||
} | ||
} | ||
} | ||
} | ||
|
||
return null; | ||
} | ||
|
||
/// <summary> | ||
/// Queries a property asynchronously based on the provided request URI and MIME type. | ||
/// </summary> | ||
/// <param name="requestUri">The request URI to append to the base URI.</param> | ||
/// <param name="mimeType">The MIME type to set in the request header.</param> | ||
/// <returns>A task that represents the asynchronous operation. The task result contains an <see cref="ODataProperty"/> if found; otherwise, null.</returns> | ||
public async Task<ODataProperty?> QueryPropertyAsync(string requestUri, string mimeType) | ||
{ | ||
var readerSettings = new ODataMessageReaderSettings() { BaseUri = BaseUri }; | ||
|
||
var uri = new Uri(BaseUri.AbsoluteUri + requestUri, UriKind.Absolute); | ||
var requestMessage = new TestHttpClientRequestMessage(uri, Client); | ||
|
||
requestMessage.SetHeader("Accept", mimeType); | ||
|
||
var responseMessage = await requestMessage.GetResponseAsync(); | ||
|
||
Assert.Equal(200, responseMessage.StatusCode); | ||
|
||
ODataProperty? property = null; | ||
|
||
if (!mimeType.Contains(MimeTypes.ODataParameterNoMetadata)) | ||
{ | ||
using (var messageReader = new ODataMessageReader(responseMessage, readerSettings, Model)) | ||
{ | ||
property = messageReader.ReadProperty(); | ||
} | ||
} | ||
|
||
return property; | ||
} | ||
|
||
public async Task<object?> QueryPropertyValueInStringAsync(string requestUri) | ||
{ | ||
var readerSettings = new ODataMessageReaderSettings() { BaseUri = BaseUri }; | ||
|
||
var uri = new Uri(BaseUri.AbsoluteUri + requestUri, UriKind.Absolute); | ||
var requestMessage = new TestHttpClientRequestMessage(uri, Client); | ||
|
||
requestMessage.SetHeader("Accept", "*/*"); | ||
|
||
var responseMessage = await requestMessage.GetResponseAsync(); | ||
|
||
Assert.Equal(200, responseMessage.StatusCode); | ||
|
||
using (var messageReader = new ODataMessageReader(responseMessage, readerSettings, Model)) | ||
{ | ||
return messageReader.ReadValue(EdmCoreModel.Instance.GetString(false)); | ||
} | ||
} | ||
} |
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.
Uh oh!
There was an error while loading. Please reload this page.