Skip to content

Commit

Permalink
address comments
Browse files Browse the repository at this point in the history
  • Loading branch information
ms-rkolesnikov committed Sep 6, 2023
1 parent 5bbd4f4 commit b307092
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ internal sealed class ODataMultipartMixedBatchReader : ODataBatchReader

/// <summary>
/// Require Content-Id header in changesets
/// If turned off allows to read OData 2.0 requests without Content-Id header present.
/// If turned off, it allows to reading OData 2.0 requests without Content-Id header present.
/// </summary>
private bool requireContentId = true;

Expand All @@ -46,6 +46,7 @@ internal sealed class ODataMultipartMixedBatchReader : ODataBatchReader
/// <param name="batchBoundary">The boundary string for the batch structure itself.</param>
/// <param name="batchEncoding">The encoding to use to read from the batch stream.</param>
/// <param name="synchronous">true if the reader is created for synchronous operation; false for asynchronous.</param>
/// <param name="requireContentId">If turned off, it allows to reading OData 2.0 requests without Content-Id header present.</param>
internal ODataMultipartMixedBatchReader(ODataMultipartMixedBatchInputContext inputContext, string batchBoundary, Encoding batchEncoding, bool synchronous, bool requireContentId)
: base(inputContext, synchronous)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -210,9 +210,34 @@ public void ReadMultipartMixedBatchRequest()
public void ReadMultipartMixedBatchRequestWthoutContentId()
{
var payload = Regex.Replace(batchRequestPayload, "Content-ID: .", "");
Assert.NotEqual(payload, batchRequestPayload);
Assert.DoesNotContain("Content-ID", payload);

var verifyResourceStack = new Stack<Action<ODataResource>>();
verifyResourceStack.Push((resource) =>
{
Assert.NotNull(resource);
Assert.Equal("NS.Order", resource.TypeName);
var properties = resource.Properties.ToArray();
Assert.Equal(2, properties.Length);
Assert.Equal("Id", properties[0].Name);
Assert.Equal(1, properties[0].Value);
Assert.Equal("Amount", properties[1].Name);
Assert.Equal(13M, properties[1].Value);
});
verifyResourceStack.Push((resource) =>
{
Assert.NotNull(resource);
Assert.Equal("NS.Customer", resource.TypeName);
var properties = resource.Properties.ToArray();
Assert.Equal(2, properties.Length);
Assert.Equal("Id", properties[0].Name);
Assert.Equal(1, properties[0].Value);
Assert.Equal("Name", properties[1].Name);
Assert.Equal("Sue", properties[1].Value);
});

SetupMultipartMixedBatchReaderAndRunTest(
batchRequestPayload,
payload,
(multipartMixedBatchReader) =>
{
var operationCount = 0;
Expand All @@ -223,6 +248,7 @@ public void ReadMultipartMixedBatchRequestWthoutContentId()
{
case ODataBatchReaderState.Operation:
var operationRequestMessage = multipartMixedBatchReader.CreateOperationRequestMessage();
operationCount++;
using (var messageReader = new ODataMessageReader(operationRequestMessage, new ODataMessageReaderSettings(), this.model))
{
if (operationCount == 3)
Expand All @@ -232,7 +258,17 @@ public void ReadMultipartMixedBatchRequestWthoutContentId()
else
{
var jsonLightResourceReader = messageReader.CreateODataResourceReader();
while (jsonLightResourceReader.Read()) {}
while (jsonLightResourceReader.Read())
{
switch (jsonLightResourceReader.State)
{
case ODataReaderState.ResourceEnd:
Assert.NotEmpty(verifyResourceStack);
var innerVerifyResourceStack = verifyResourceStack.Pop();
innerVerifyResourceStack(jsonLightResourceReader.Item as ODataResource);
break;
}
}
}
}
break;
Expand Down

0 comments on commit b307092

Please sign in to comment.