Skip to content

Conversation

@caitlinrussell
Copy link

This allows them to get deserialized down the line, typically by the default Serializer class into AdditionalData["responseHeaders"] and AdditionalData["statusCode".

BaseRequest.cs - add headers to the response content. If the content stream is null, do not add headers, because the serializer is expecting a null object back. Because these will get picked up by the individual models later in the deserialization process, we need to temporarily re-serialize the headers and append them to the content stream to "trick" the serializer into deserializing them back into the object as additional data.

MockSerializer - Added SerializeObject method to MockSerializer for both .NET and .NET Core tests (required for MockBehavior.Strict, also used in the BaseRequestTest.cs)

BaseRequestTests - Similar behavior to SendAsync test, but with content and headers set. Content must be set in order for headers to be attached.

OneDriveTests and PlannerTests - Updated test credentials to verify functional tests pass with response header updates.

@mlafleur
Copy link

I love the elegence of this implimentation. It might however be a good idea to include an example of using both HeaderOption and QueryOption objects in the documentation. It isn't imeediatly clear that the prototype is .Request(IEnumerable<Option>) or that you can pass both Header and Query options in the same collection.

docs/headers.md Outdated

Custom headers can be added by creating a new header option collection and adding it to the request object:

```chsarp
Copy link
Collaborator

Choose a reason for hiding this comment

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

Language tag typo this one and below

docs/headers.md Outdated
Custom headers can be added by creating a new header option collection and adding it to the request object:

```chsarp
List<HeaderOption> options = new List<HeaderOption>();
Copy link
Collaborator

Choose a reason for hiding this comment

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

Above
"Custom headers can be added by creating a new header option collection"

change to:

"Custom headers can be added by creating a new option collection"

Below
Let's change this to List<Option> options = new List<Option>(); so that we can add QueryOption to the collection.

if (response.Content != null)
{
var responseString = await response.Content.ReadAsStringAsync().ConfigureAwait(false);
responseString = AddHeadersToResponse(response, responseString);
Copy link
Collaborator

@MIchaelMainer MIchaelMainer Apr 24, 2018

Choose a reason for hiding this comment

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

Instead of passing the responseString, and the httpResponseMessage (which has the response content as well) to AddHeadersToResponse ,I suggest that we change this call from AddHeadersToResponse to string GetResponseString(HttpResponseMessage hrm). GetResponseString will call AddHeadersToResponse with the results of response.Content.ReadAsStringAsync() and then return the results it receives from AddHeadersToResponse. The goal being that we don't pass the same data twice to the function.

Copy link
Author

Choose a reason for hiding this comment

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

That makes a lot more sense

docs/headers.md Outdated
```


*Currently, requests that have a return type of `void` do not return response headers and cannot be inspected.*
Copy link
Collaborator

@MIchaelMainer MIchaelMainer Apr 24, 2018

Choose a reason for hiding this comment

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

Stream return types won't work either. We should add an item to our breaking changes backlog for this.

Copy link
Collaborator

@MIchaelMainer MIchaelMainer left a comment

Choose a reason for hiding this comment

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

I don't think I did the review correctly as GH is saying I have 1 thing to review.

var responseItem = await baseRequest.SendAsync<DerivedTypeClass>("string", CancellationToken.None);
Assert.IsNotNull(responseItem.AdditionalData["responseHeaders"], "No response headers available");
Assert.AreEqual(expectedResponseItem.AdditionalData["responseHeaders"], responseItem.AdditionalData["responseHeaders"], "Unexpected response headers");
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

Looks good as far as I see. Can you walk me through this so that I can understand how the mock library works.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants