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

Add HasExplicitODataId to ODataResourceBase #2620

Open
wants to merge 2 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
Original file line number Diff line number Diff line change
Expand Up @@ -861,6 +861,7 @@ internal void ApplyEntryInstanceAnnotation(IODataJsonLightReaderResourceState re
else
{
resource.Id = (Uri)annotationValue;
resource.HasExplicitODataId = true;
}

break;
Expand Down
8 changes: 8 additions & 0 deletions src/Microsoft.OData.Core/ODataResource.cs
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,14 @@ public ICollection<ODataInstanceAnnotation> InstanceAnnotations
set { this.SetInstanceAnnotations(value); }
}

/// <summary>Gets or sets the value that shows if the resource has @odata.id or @id.</summary>
/// <returns>true if the resource has @odata.id or @id, false otherwise.</returns>
public bool HasExplicitODataId
Copy link
Member

Choose a reason for hiding this comment

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

internal set? or totally as internal property?

Change "Gets or sets" for Internal set

Copy link
Member

Choose a reason for hiding this comment

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

HasExplicitODataId

how does this relate to NonComputedId?

{
get;
internal set;
}

/// <summary>
/// The metadata builder for this OData resource.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Microsoft.OData.ODataResourceBase.HasExplicitODataId.get -> bool
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Microsoft.OData.ODataResourceBase.HasExplicitODataId.get -> bool
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Microsoft.OData.ODataResourceBase.HasExplicitODataId.get -> bool
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Microsoft.OData.ODataResourceBase.HasExplicitODataId.get -> bool
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,44 @@ await SetupJsonLightResourceSerializerAndRunReadResourceContextTestAsync(
});
}

[Fact]
public async Task ReadResourceContentWithODataId()
{
var payload = "{\"@odata.context\":\"http://tempuri.org/$metadata#Categories/$entity\"," +
"\"@odata.id\":\"http://tempuri.org/Categories(1)\"," +
"\"Name\":\"Food\"}";

await SetupJsonLightResourceSerializerAndRunReadResourceContextTestAsync(
payload,
this.categoriesEntitySet,
this.categoryEntityType,
(resourceState) =>
{
var resource = resourceState.Resource;
Assert.Equal(new Uri("http://tempuri.org/Categories(1)"), resource.Id);
Assert.True(resource.HasExplicitODataId);
});
}

[Fact]
public async Task ReadResourceContentWithIdProperty()
{
var payload = "{\"@odata.context\":\"http://tempuri.org/$metadata#Categories/$entity\"," +
"\"Id\":1," +
"\"Name\":\"Food\"}";

await SetupJsonLightResourceSerializerAndRunReadResourceContextTestAsync(
payload,
this.categoriesEntitySet,
this.categoryEntityType,
(resourceState) =>
{
var resource = resourceState.Resource;
Assert.Null(resource.Id); // Null since Id is computed at ODataReaderState.ResourceEnd
Assert.False(resource.HasExplicitODataId);
});
}

[Fact]
public async Task ReadResourceContentWithODataAnnotationsAsync()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,11 @@ public void ReadBasicSingletonTest()
Assert.Equal(2, entry.Properties.Count());
Assert.Equal(10, entry.Properties.Single(p => p.Name == "WebId").Value);
Assert.Equal("SingletonWeb", entry.Properties.Single(p => p.Name == "Name").Value);
Assert.False(entry.HasExplicitODataId);
}

[Fact]
public void ReadSingletonWithIdSpecifiedTest()
public void ReadSingletonWithODataIdSpecifiedTest()
Copy link
Contributor

@ElizabethOkerio ElizabethOkerio Feb 22, 2023

Choose a reason for hiding this comment

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

There is no @id here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Check line 81

{
const string payload = "{" +
"\"@odata.context\":\"http://odata.org/test/$metadata#MySingleton\"," +
Expand All @@ -86,6 +87,7 @@ public void ReadSingletonWithIdSpecifiedTest()
Assert.Equal(new Uri("http://odata.org/test/Bla"), entry.Id);
Assert.Equal(new Uri("http://odata.org/test/BlaBla"), entry.EditLink);
Assert.Equal(new Uri("http://odata.org/test/BlaBlaBla"), entry.ReadLink);
Assert.True(entry.HasExplicitODataId);
}

[Fact]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4810,6 +4810,7 @@ public abstract class Microsoft.OData.ODataResourceBase : Microsoft.OData.ODataI
System.Uri EditLink { public get; public set; }
string ETag { public get; public set; }
System.Collections.Generic.IEnumerable`1[[Microsoft.OData.ODataFunction]] Functions { public get; }
bool HasExplicitODataId { public get; }
System.Uri Id { public get; public set; }
System.Collections.Generic.ICollection`1[[Microsoft.OData.ODataInstanceAnnotation]] InstanceAnnotations { public get; public set; }
bool IsTransient { public get; public set; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4810,6 +4810,7 @@ public abstract class Microsoft.OData.ODataResourceBase : Microsoft.OData.ODataI
System.Uri EditLink { public get; public set; }
string ETag { public get; public set; }
System.Collections.Generic.IEnumerable`1[[Microsoft.OData.ODataFunction]] Functions { public get; }
bool HasExplicitODataId { public get; }
System.Uri Id { public get; public set; }
System.Collections.Generic.ICollection`1[[Microsoft.OData.ODataInstanceAnnotation]] InstanceAnnotations { public get; public set; }
bool IsTransient { public get; public set; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4810,6 +4810,7 @@ public abstract class Microsoft.OData.ODataResourceBase : Microsoft.OData.ODataI
System.Uri EditLink { public get; public set; }
string ETag { public get; public set; }
System.Collections.Generic.IEnumerable`1[[Microsoft.OData.ODataFunction]] Functions { public get; }
bool HasExplicitODataId { public get; }
System.Uri Id { public get; public set; }
System.Collections.Generic.ICollection`1[[Microsoft.OData.ODataInstanceAnnotation]] InstanceAnnotations { public get; public set; }
bool IsTransient { public get; public set; }
Expand Down