-
Notifications
You must be signed in to change notification settings - Fork 352
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
Default to using entityType for incomplete serializationInfo. #2279
Merged
Merged
Changes from 1 commit
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
47fd7e6
Default to using entityType for incomplete serializationInfo.
mikepizzo a00e0a8
Consolidate validation logic
mikepizzo db2940e
Merge branch 'master' of https://github.com/odata/odata.net
mikepizzo 1aa37b1
Address Code Review Comments.
mikepizzo File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -512,6 +512,146 @@ static AutoComputePayloadMetadataInJsonIntegrationTests() | |
Model.AddElement(function4); | ||
} | ||
|
||
public enum SerializationType | ||
{ | ||
NoSerializationInfo, | ||
ResourceSerializationInfo, | ||
ResourceAndPropertySerializationInfo | ||
} | ||
|
||
[Theory] | ||
[InlineData(SerializationType.NoSerializationInfo, /*fullMetadata*/ false)] | ||
[InlineData(SerializationType.ResourceAndPropertySerializationInfo, /*fullMetadata*/ false)] | ||
[InlineData(SerializationType.ResourceSerializationInfo, /*fullMetadata*/ false)] | ||
[InlineData(SerializationType.NoSerializationInfo, /*fullMetadata*/ true)] | ||
[InlineData(SerializationType.ResourceAndPropertySerializationInfo, /*fullMetadata*/ true)] | ||
[InlineData(SerializationType.ResourceSerializationInfo, /*fullMetadata*/ true)] | ||
public void WritingNestedResourceInfoWithVariousSerializationInfoSucceeds(SerializationType serializationType, bool fullMetadata) | ||
{ | ||
// setup model | ||
var model = new EdmModel(); | ||
var entityType = new EdmEntityType("NS", "entityType"); | ||
entityType.AddKeys( | ||
entityType.AddStructuralProperty("keyProperty", EdmPrimitiveTypeKind.Int64)); | ||
|
||
var nestedEntityType = new EdmEntityType("NS", "nestedEntityType"); | ||
nestedEntityType.AddKeys( | ||
nestedEntityType.AddStructuralProperty("keyProperty", EdmPrimitiveTypeKind.Int64)); | ||
|
||
entityType.AddUnidirectionalNavigation(new EdmNavigationPropertyInfo { | ||
Name = "nestedEntities", | ||
Target = nestedEntityType, | ||
TargetMultiplicity = EdmMultiplicity.Many, | ||
ContainsTarget = true | ||
}); | ||
|
||
var container = new EdmEntityContainer("NS", "Container"); | ||
var entitySet = container.AddEntitySet("EntitySet", entityType); | ||
|
||
model.AddElements(new IEdmSchemaElement[] { entityType, nestedEntityType, container }); | ||
|
||
// setup writer | ||
var stream = new MemoryStream(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
var message = new InMemoryMessage { Stream = stream }; | ||
message.SetHeader("Content-Type", fullMetadata ? "application/json;odata.metadata=full" : "application/json"); | ||
var settings = new ODataMessageWriterSettings | ||
{ | ||
ODataUri = new ODataUri | ||
{ | ||
ServiceRoot = new Uri("http://svc/"), | ||
Path = new ODataUriParser(model, new Uri("EntitySet",UriKind.Relative)).ParsePath() | ||
}, | ||
}; | ||
var writer = new ODataMessageWriter((IODataResponseMessage)message, settings, model); | ||
|
||
// write payload | ||
var entitySetWriter = writer.CreateODataResourceSetWriter(entitySet, entitySet.EntityType()); | ||
entitySetWriter.WriteStart(new ODataResourceSet()); | ||
var resource = new ODataResource | ||
{ | ||
Properties = new[] | ||
{ | ||
new ODataProperty { | ||
Name = "keyProperty", | ||
Value = 1L, | ||
SerializationInfo = serializationType == SerializationType.ResourceAndPropertySerializationInfo ? | ||
new ODataPropertySerializationInfo { | ||
PropertyKind = ODataPropertyKind.Key | ||
} : null | ||
} | ||
}, | ||
TypeName = serializationType == SerializationType.NoSerializationInfo ? null : entityType.FullName | ||
}; | ||
|
||
if (serializationType != SerializationType.NoSerializationInfo) | ||
{ | ||
resource.SerializationInfo = new ODataResourceSerializationInfo | ||
{ | ||
NavigationSourceName = "EntitySet", | ||
NavigationSourceKind = EdmNavigationSourceKind.EntitySet, | ||
NavigationSourceEntityTypeName = entityType.FullName, | ||
ExpectedTypeName = entityType.FullName, | ||
IsFromCollection = true | ||
}; | ||
} | ||
|
||
entitySetWriter.WriteStart( resource ); | ||
entitySetWriter.WriteStart( | ||
new ODataNestedResourceInfo | ||
{ | ||
Name = "nestedEntities", | ||
} | ||
); | ||
entitySetWriter.WriteStart(new ODataResourceSet()); | ||
var entityValue = new ODataResource | ||
{ | ||
TypeName = "NS.nestedEntityType", | ||
Properties = new[] | ||
{ | ||
new ODataProperty { Name = "keyProperty", Value = 1L } | ||
} | ||
}; | ||
entitySetWriter.WriteStart(entityValue); | ||
entitySetWriter.WriteEnd(); // nestedEntity | ||
entitySetWriter.WriteEnd(); // nested resourceSet | ||
entitySetWriter.WriteEnd(); // nestedInfo | ||
entitySetWriter.WriteEnd(); // entity | ||
entitySetWriter.WriteEnd(); // resourceSet | ||
var str = Encoding.UTF8.GetString(stream.ToArray()); | ||
|
||
var typeAnnotation = | ||
serializationType == SerializationType.NoSerializationInfo ? "" : | ||
"\"@odata.type\":\"#NS.entityType\","; | ||
|
||
var expected = fullMetadata ? | ||
"{\"@odata.context\":\"http://svc/$metadata#EntitySet\"," + | ||
"\"value\":[{" + | ||
typeAnnotation + | ||
"\"@odata.id\":\"EntitySet(1)\"," + | ||
"\"@odata.editLink\":\"EntitySet(1)\"," + | ||
"\"[email protected]\":\"#Int64\"," + | ||
"\"keyProperty\":1," + | ||
"\"[email protected]\":\"http://svc/EntitySet(1)/nestedEntities/$ref\"," + | ||
"\"[email protected]\":\"http://svc/EntitySet(1)/nestedEntities\"," + | ||
"\"nestedEntities\":[{" + | ||
"\"@odata.type\":\"#NS.nestedEntityType\"," + | ||
"\"@odata.id\":\"EntitySet(1)/nestedEntities(1)\"," + | ||
"\"@odata.editLink\":\"EntitySet(1)/nestedEntities(1)\"," + | ||
"\"[email protected]\":\"#Int64\"," + | ||
"\"keyProperty\":1" + | ||
"}]" + | ||
"}]}" : | ||
"{\"@odata.context\":\"http://svc/$metadata#EntitySet\"," + | ||
"\"value\":[{" + | ||
"\"keyProperty\":1," + | ||
"\"nestedEntities\":[{" + | ||
"\"keyProperty\":1" + | ||
"}]" + | ||
"}]}"; | ||
|
||
Assert.Equal(expected, str); | ||
} | ||
|
||
[Fact] | ||
public void WritingDynamicComplexPropertyWithModelSpecifiedInFullMetadataMode() | ||
{ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
GetKeyProperties
seems to make the assumption thatresource
isn'tnull
. I know that this isn't really related to your change, but not validating thatcurrentEntityType
is actually aIEdmEntityType
means we could get aNullReferenceException
here. #ResolvedThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is our code and should never be called with a null resource. I added an assert to GetKeyProperties.