-
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
Add the writing derived type constraint validation #1358
Conversation
69077b9
to
5dcb07d
Compare
@@ -13,7 +14,11 @@ namespace Microsoft.OData | |||
/// </summary> | |||
internal class PropertyMetadataTypeInfo | |||
{ | |||
public PropertyMetadataTypeInfo(string name, IEdmStructuredType owningType) | |||
private bool loadDerivedTypeConstraints; |
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.
loadDerivedTypeConstraints [](start = 21, length = 26)
loadDerivedTypeConstraints [](start = 21, length = 26)
nit: sounds like directive (to load or not to load) rather than state. perhaps rename to something like "derivedTypeConstraintsLoaded" #Closed
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.
#resolved. #Closed
/// </summary> | ||
/// <param name="propertySerializationInfo">The property serialization info.</param> | ||
/// <remarks>This does NOT validate the value of the property, just the type of property.</remarks> | ||
internal static void ValidateCollectionPropertyDerivedTypeConstraint(ODataCollectionValue collectionValue, |
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.
collectionValue [](start = 98, length = 15)
collectionValue [](start = 98, length = 15)
Is collectionValue used anywhere? this looks like the same logic as above, which takes only PropertySerializationInfo. #Resolved
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.
Sorry, forgot to clean the collection. #Resolved. #Resolved
/// <param name="metadataType">The type from metadata.</param> | ||
/// <param name="navigationSource">The navigation source.</param> | ||
/// <param name="derivedTypeConstraints">The derived type constraints on the nested resource.</param> | ||
internal static void ValidateDerivedTypeConstraintOnNavigationSource(IEdmStructuredType resourceType, IEdmStructuredType metadataType, IEdmNavigationSource navigationSource, IEnumerable<string> derivedTypeConstraints) |
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.
ValidateDerivedTypeConstraintOnNavigationSource [](start = 29, length = 47)
ValidateDerivedTypeConstraintOnNavigationSource [](start = 29, length = 47)
ValidateDerivedTypeConstraintOnNavigationSource and ValidateDerivedTypeConstraintOnNestedResourceInfo have the same logic, except that one uses the name of the navigation source in the exception and the other uses the name from the nestedresourceinfo. Instead of two overloads, unless you think you'll need the navigationsource (or additional information out of the nestedResourceInfo) in the future, how about just having a single overload that takes a string property "navigationSourceName", and pass the appropriate string from the caller? #Resolved
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.
#resolved. #Resolved
Assert.Contains("/$metadata#Me\",\"Id\":7}", customerActual); | ||
|
||
// Singleton has the derived type constraint. | ||
SetDerivedTypeAnnotation(this.edmModel, this.edmMe, "NS.VipCustomer"); |
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.
SetDerivedTypeAnnotation [](start = 12, length = 24)
does a new instance of edmModel get created with each test case run, or is the derived type constraint set for all subsequent tests? #Closed
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.
@mikepizzo For every single test, xUnit.net creates a new instance of the test class, so, in each test method, the "this.edmModel" is the basic edm model created in the constructor.
Below is the description from xUnit document at: https://xunit.github.io/docs/shared-context
xUnit.net creates a new instance of the test class for every test that is run, so any code which is placed into the constructor of the test class will be run for every single test. This makes the constructor a convenient place to put reusable context setup code where you want to share the code without sharing object instances (meaning, you get a clean copy of the context object(s) for every test that is run).
#Closed
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.
👍 Thanks for the research @xuzhg! #Closed
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.
🕐
resource and Edm primitive type property
5dcb07d
to
d024f82
Compare
/// </summary> | ||
/// <param name="propertySerializationInfo">The property serialization info.</param> | ||
/// <remarks>This does NOT validate the value of the property, just the type of property.</remarks> | ||
internal static void ValidateCollectionPropertyDerivedTypeConstraint(ODataCollectionValue collectionValue, |
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.
ValidateCollectionPropertyDerivedTypeConstraint [](start = 29, length = 47)
Can this be combined with ValidatePropertyDerivedTypeConstraint? It looks like the logic is exactly the same, and that the ODataCollectionValue is not used. #Resolved
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.
#Resolved. That's old codes to verify the collection(Edm.PrimitiveType). Not, it's not valid. And I removed. Thanks. #Resolved
/// <summary> | ||
/// Validates the value type of a property meets the derived type constraints. | ||
/// </summary> | ||
/// <param name="propertySerializationInfo">The property serialization info.</param> |
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.
param name [](start = 13, length = 10)
parameters in comments don't match parameters in function signature (ODataCollectionValue is missing). If we do need this overload to take an ODataCollectionValue, then we need to add that parameter to the comments. #Resolved
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.
Issues
*This pull request continues on Union type feature.
Description
Enable writing derived type constraint validation on:
Checklist (Uncheck if it is not completed)
Additional work necessary
If documentation update is needed, please add "Docs Needed" label to the issue and provide details about the required document change in the issue.