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

exposing DataServiceActionQuery<T> properties for testing purposes #2842

Open
wants to merge 3 commits into
base: release-7.x
Choose a base branch
from
Open
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
41 changes: 33 additions & 8 deletions src/Microsoft.OData.Client/DataServiceActionQueryOfT.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@ public sealed class DataServiceActionQuery<T>
/// <summary>
/// Context associated with this query.
/// </summary>
private readonly DataServiceContext Context;
private readonly DataServiceContext context;

/// <summary>
/// Parameters of this action.
/// </summary>
private readonly BodyOperationParameter[] Parameters;
private readonly BodyOperationParameter[] parameters;

/// <summary>
/// Object of an action which returns a collection.
Expand All @@ -35,9 +35,34 @@ public sealed class DataServiceActionQuery<T>
/// <param name="parameters">Parameters of this action.</param>
public DataServiceActionQuery(DataServiceContext context, string requestUriString, params BodyOperationParameter[] parameters)
{
this.Context = context;
this.context = context;
this.RequestUri = new Uri(requestUriString);
this.Parameters = parameters;
this.parameters = parameters;
}

/// <summary>
/// Gets the <see cref="DataServiceContext"/> that will be used to execute the action query
/// </summary>
public DataServiceContext Context
{
get
{
return this.context;
}
}

/// <summary>
/// Gets the <see cref="BodyOperationParameter"/>s that will be provided to the action when the query is executed
/// </summary>
public IEnumerable<BodyOperationParameter> Parameters
{
get
{
foreach (var element in this.parameters)
{
yield return element;
}
}
Comment on lines +59 to +65
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I assume this is done so that the user does not modify the array. But it seems excessive to me, especially given that we do not seem modify the list internally. I think by the time they're casting it back into array to try and modify it, they're already assuming any risks that come with that. But if we really want to prevent that, then maybe it's better to hand them a ReadOnlyCollection that's computed once so we don't have to generate the enumerable each time the property is accessed.

}

/// <summary>
Expand All @@ -52,7 +77,7 @@ public DataServiceActionQuery(DataServiceContext context, string requestUriStrin
/// <exception cref="InvalidOperationException">Problem materializing result of query into object.</exception>
public IEnumerable<T> Execute()
{
return Context.Execute<T>(this.RequestUri, XmlConstants.HttpMethodPost, false, Parameters);
return context.Execute<T>(this.RequestUri, XmlConstants.HttpMethodPost, false, parameters);
}

/// <summary>Asynchronously sends a request to the data service to execute a specific URI.</summary>
Expand All @@ -62,7 +87,7 @@ public IEnumerable<T> Execute()
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1004:GenericMethodsShouldProvideTypeParameter", Justification = "Type is used to infer result")]
public IAsyncResult BeginExecute(AsyncCallback callback, object state)
{
return Context.BeginExecute<T>(this.RequestUri, callback, state, XmlConstants.HttpMethodPost, false, Parameters);
return context.BeginExecute<T>(this.RequestUri, callback, state, XmlConstants.HttpMethodPost, false, parameters);
}

/// <summary>Asynchronously sends the request so that this call does not block processing while waiting for the results from the service.</summary>
Expand All @@ -77,7 +102,7 @@ public Task<IEnumerable<T>> ExecuteAsync()
/// <param name="cancellationToken">The token to monitor for cancellation requests.</param>
public Task<IEnumerable<T>> ExecuteAsync(CancellationToken cancellationToken)
{
return Context.ExecuteAsync<T>(this.RequestUri, XmlConstants.HttpMethodPost, false, cancellationToken, Parameters);
return context.ExecuteAsync<T>(this.RequestUri, XmlConstants.HttpMethodPost, false, cancellationToken, parameters);
}

/// <summary>Called to complete the <see cref="Microsoft.OData.Client.DataServiceActionQuery.BeginExecute(System.AsyncCallback,System.Object)" />.</summary>
Expand All @@ -92,7 +117,7 @@ public Task<IEnumerable<T>> ExecuteAsync(CancellationToken cancellationToken)
public IEnumerable<T> EndExecute(IAsyncResult asyncResult)
{
Util.CheckArgumentNull(asyncResult, "asyncResult");
return Context.EndExecute<T>(asyncResult);
return context.EndExecute<T>(asyncResult);
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Microsoft.OData.Client.DataServiceActionQuery<T>.Context.get -> Microsoft.OData.Client.DataServiceContext
Microsoft.OData.Client.DataServiceActionQuery<T>.Parameters.get -> System.Collections.Generic.IEnumerable<Microsoft.OData.Client.BodyOperationParameter>
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Microsoft.OData.Client.DataServiceActionQuery<T>.Context.get -> Microsoft.OData.Client.DataServiceContext
Microsoft.OData.Client.DataServiceActionQuery<T>.Parameters.get -> System.Collections.Generic.IEnumerable<Microsoft.OData.Client.BodyOperationParameter>
Original file line number Diff line number Diff line change
Expand Up @@ -8647,6 +8647,8 @@ public sealed class Microsoft.OData.Client.ContainerPropertyAttribute : System.A
public sealed class Microsoft.OData.Client.DataServiceActionQuery`1 {
public DataServiceActionQuery`1 (Microsoft.OData.Client.DataServiceContext context, string requestUriString, Microsoft.OData.Client.BodyOperationParameter[] parameters)

Microsoft.OData.Client.DataServiceContext Context { public get; }
System.Collections.Generic.IEnumerable`1[[Microsoft.OData.Client.BodyOperationParameter]] Parameters { public get; }
System.Uri RequestUri { public get; }

public System.IAsyncResult BeginExecute (System.AsyncCallback callback, object state)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8647,6 +8647,8 @@ public sealed class Microsoft.OData.Client.ContainerPropertyAttribute : System.A
public sealed class Microsoft.OData.Client.DataServiceActionQuery`1 {
public DataServiceActionQuery`1 (Microsoft.OData.Client.DataServiceContext context, string requestUriString, Microsoft.OData.Client.BodyOperationParameter[] parameters)

Microsoft.OData.Client.DataServiceContext Context { public get; }
System.Collections.Generic.IEnumerable`1[[Microsoft.OData.Client.BodyOperationParameter]] Parameters { public get; }
System.Uri RequestUri { public get; }

public System.IAsyncResult BeginExecute (System.AsyncCallback callback, object state)
Expand Down
Loading