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 the writing derived type constraint validation #1358

Merged
merged 4 commits into from
Dec 18, 2018

Conversation

xuzhg
Copy link
Member

@xuzhg xuzhg commented Dec 11, 2018

Issues

*This pull request continues on Union type feature.

Description

Enable writing derived type constraint validation on:

  1. Resource
  2. Nested resource info
  3. Edm.PrimitiveType property

Checklist (Uncheck if it is not completed)

  • Test cases added
  • Build and test with one-click build and test script passed

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.

@xuzhg xuzhg added the Ready for review Use this label if a pull request is ready to be reviewed label Dec 11, 2018
@xuzhg xuzhg added this to the 7.6 milestone Dec 11, 2018
@@ -13,7 +14,11 @@ namespace Microsoft.OData
/// </summary>
internal class PropertyMetadataTypeInfo
{
public PropertyMetadataTypeInfo(string name, IEdmStructuredType owningType)
private bool loadDerivedTypeConstraints;
Copy link
Member

@mikepizzo mikepizzo Dec 12, 2018

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

Copy link
Member Author

@xuzhg xuzhg Dec 13, 2018

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,
Copy link
Member

@mikepizzo mikepizzo Dec 12, 2018

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

Copy link
Member Author

@xuzhg xuzhg Dec 18, 2018

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)
Copy link
Member

@mikepizzo mikepizzo Dec 12, 2018

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

Copy link
Member Author

@xuzhg xuzhg Dec 13, 2018

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");
Copy link
Member

@mikepizzo mikepizzo Dec 12, 2018

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

Copy link
Member Author

@xuzhg xuzhg Dec 13, 2018

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

Copy link
Member

@mikepizzo mikepizzo Dec 13, 2018

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

Copy link
Member

@mikepizzo mikepizzo left a comment

Choose a reason for hiding this comment

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

🕐

@mikepizzo mikepizzo removed the Ready for review Use this label if a pull request is ready to be reviewed label Dec 12, 2018
@xuzhg xuzhg added the Ready for review Use this label if a pull request is ready to be reviewed label Dec 13, 2018
/// </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,
Copy link
Member

@mikepizzo mikepizzo Dec 17, 2018

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

Copy link
Member Author

@xuzhg xuzhg Dec 18, 2018

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>
Copy link
Member

@mikepizzo mikepizzo Dec 17, 2018

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

Copy link
Member

@mikepizzo mikepizzo left a comment

Choose a reason for hiding this comment

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

:shipit:

@xuzhg xuzhg merged commit a69ab2f into OData:master Dec 18, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Ready for review Use this label if a pull request is ready to be reviewed
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants