Skip to content

Commit

Permalink
Add validation and Refractor tests
Browse files Browse the repository at this point in the history
  • Loading branch information
KenitoInc committed Sep 22, 2021
1 parent e8b4546 commit 0849892
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 9 deletions.
1 change: 1 addition & 0 deletions src/Microsoft.OData.Core/Microsoft.OData.Core.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ internal sealed class TextRes {
internal const string ODataWriterCore_StreamNotDisposed = "ODataWriterCore_StreamNotDisposed";
internal const string ODataWriterCore_DeltaResourceWithoutIdOrKeyProperties = "ODataWriterCore_DeltaResourceWithoutIdOrKeyProperties";
internal const string ODataWriterCore_QueryCountInRequest = "ODataWriterCore_QueryCountInRequest";
internal const string ODataWriterCore_QueryCountInODataNestedResourceInfo = "ODataWriterCore_QueryCountInODataNestedResourceInfo";
internal const string ODataWriterCore_QueryNextLinkInRequest = "ODataWriterCore_QueryNextLinkInRequest";
internal const string ODataWriterCore_QueryDeltaLinkInRequest = "ODataWriterCore_QueryDeltaLinkInRequest";
internal const string ODataWriterCore_CannotWriteDeltaWithResourceSetWriter = "ODataWriterCore_CannotWriteDeltaWithResourceSetWriter";
Expand Down
1 change: 1 addition & 0 deletions src/Microsoft.OData.Core/Microsoft.OData.Core.txt
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ ODataWriterCore_StreamNotDisposed=ODataWriter.Write or ODataWriter.WriteEnd was

ODataWriterCore_DeltaResourceWithoutIdOrKeyProperties=No Id or key properties were found. A resource in a delta payload requires an ID or key properties be specified.
ODataWriterCore_QueryCountInRequest=The ODataResourceSet.Count must be null for request payloads. Query counts are only supported in responses.
ODataWriterCore_QueryCountInODataNestedResourceInfo=The ODataNestedResourceInfo.Count must be null when ODataNestedResourceInfo.IsCollection is false.
ODataWriterCore_QueryNextLinkInRequest=The NextPageLink must be null for request payloads. Next page links are only supported in responses.
ODataWriterCore_QueryDeltaLinkInRequest=The DeltaLink must be null for request payloads. Delta links are only supported in responses.
ODataWriterCore_CannotWriteDeltaWithResourceSetWriter=Cannot write a deleted resource, link, deleted link, or nested delta resource set to a non-delta payload. Please use a delta resource set writer, or a request resource writer.
Expand Down
19 changes: 17 additions & 2 deletions src/Microsoft.OData.Core/ODataNestedResourceInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ public sealed class ODataNestedResourceInfo : ODataItem
/// <summary>true if the association link has been set by the user or seen on the wire or computed by the metadata builder, false otherwise.</summary>
private bool hasAssociationUrl;

/// <summary>The number of items in the resource set.</summary>
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>
public bool? IsCollection
Expand Down Expand Up @@ -98,8 +101,20 @@ public Uri AssociationLinkUrl
/// <returns>The number of items in the resource set.</returns>
public long? Count
{
get;
set;
get
{
return this.count;
}

set
{
if (IsCollection != null && (bool)IsCollection == false)
{
throw new ODataException(Strings.ODataWriterCore_QueryCountInODataNestedResourceInfo);
}

this.count = (long)value;
}
}

/// <summary>
Expand Down
11 changes: 11 additions & 0 deletions src/Microsoft.OData.Core/Parameterized.Microsoft.OData.Core.cs
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,17 @@ internal static string ODataWriterCore_QueryCountInRequest
}
}

/// <summary>
/// A string like "The ODataNestedResourceInfo.Count must be null when ODataNestedResourceInfo.IsCollection is false."
/// </summary>
internal static string ODataWriterCore_QueryCountInODataNestedResourceInfo
{
get
{
return Microsoft.OData.TextRes.GetString(Microsoft.OData.TextRes.ODataWriterCore_QueryCountInODataNestedResourceInfo);
}
}

/// <summary>
/// A string like "The NextPageLink must be null for request payloads. Next page links are only supported in responses."
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -567,11 +567,6 @@ public void WriteAnnotationAndCountAtStartExpandedFeedShouldPassInJsonLight()
"\"[email protected]\":123" +
"}";

this.WriteAnnotationAndCountAtStartExpandedFeedShouldPass(ODataFormat.Json, expectedPayload, EntitySet);
}

private void WriteAnnotationAndCountAtStartExpandedFeedShouldPass(ODataFormat format, string expectedPayload, IEdmNavigationSource navigationSource)
{
Action<ODataWriter> action = (odataWriter) =>
{
var entryToWrite = new ODataResource { Properties = new[] { new ODataProperty { Name = "ID", Value = 1 } } };
Expand All @@ -586,9 +581,8 @@ private void WriteAnnotationAndCountAtStartExpandedFeedShouldPass(ODataFormat fo
odataWriter.WriteEnd();
};

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

#endregion Writing instance annotations on expanded feeds

#region Write Delta Feed
Expand Down

0 comments on commit 0849892

Please sign in to comment.