Skip to content

Commit

Permalink
Add test
Browse files Browse the repository at this point in the history
  • Loading branch information
KenitoInc committed Sep 22, 2021
1 parent 0849892 commit ea6f7f8
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/Microsoft.OData.Core/ODataNestedResourceInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public sealed class ODataNestedResourceInfo : ODataItem
private bool hasAssociationUrl;

/// <summary>The number of items in the resource set.</summary>
private long count;
private long? count;

/// <summary>Gets or sets a value that indicates whether the nested resource info represents a collection or a resource.</summary>
/// <returns>true if the nested resource info represents a collection; false if the navigation represents a resource.</returns>
Expand Down Expand Up @@ -113,7 +113,7 @@ public long? Count
throw new ODataException(Strings.ODataWriterCore_QueryCountInODataNestedResourceInfo);
}

this.count = (long)value;
this.count = value;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -583,6 +583,26 @@ public void WriteAnnotationAndCountAtStartExpandedFeedShouldPassInJsonLight()

this.WriteAnnotationsAndValidatePayload(action, EntitySet, ODataFormat.Json, expectedPayload, request: false, createFeedWriter: false);
}

[Fact]
public void WriteCountOnExpandedEntryShouldFail()
{
Action<ODataWriter> action = (odataWriter) =>
{
var entryToWrite = new ODataResource { Properties = new[] { new ODataProperty { Name = "ID", Value = 1 } } };
odataWriter.WriteStart(entryToWrite);

ODataNestedResourceInfo navLink = new ODataNestedResourceInfo { Name = "ResourceNavigationProperty", IsCollection = false };
navLink.Count = 10;

odataWriter.WriteStart(navLink);
odataWriter.WriteEnd();
odataWriter.WriteEnd();
};

Action testResponse = () => this.WriteAnnotationsAndValidatePayload(action, EntitySet, ODataFormat.Json, null, request: false, createFeedWriter: false);
testResponse.Throws<ODataException>(Strings.ODataWriterCore_QueryCountInODataNestedResourceInfo);
}
#endregion Writing instance annotations on expanded feeds

#region Write Delta Feed
Expand Down

0 comments on commit ea6f7f8

Please sign in to comment.