Skip to content

Commit

Permalink
Issue#400 Support Dynamic/Additional properties of a non-open type
Browse files Browse the repository at this point in the history
  • Loading branch information
VikingsFan authored and LianwMS committed Jan 15, 2016
1 parent 70f8a36 commit 27ded6a
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 51 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -186,11 +186,8 @@ private void WriteProperty(
this.InstanceAnnotationWriter.WriteInstanceAnnotations(property.InstanceAnnotations, propertyName);
}
}

IEdmProperty edmProperty = WriterValidationUtils.ValidatePropertyDefined(
propertyName,
owningType,
!this.bypassValidation);
IEdmProperty edmProperty = WriterValidationUtils.ValidatePropertyDefined(propertyName, owningType,
!(this.bypassValidation || this.WritingResponse));
IEdmTypeReference propertyTypeReference = edmProperty == null ? null : edmProperty.Type;

ODataValue value = property.ODataValue;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -347,11 +347,11 @@ public void WritingFeedExpandWithNonCollectionContainedElement()
{
ODataItem[] itemsToWrite = new ODataItem[]
{
new ODataFeed(),
new ODataFeed(),
this.entryWithOnlyData1,
this.containedNavLink,
this.entryWithOnlyData2,
this.containedNavLink,
this.containedNavLink,
this.entryWithOnlyData3
};

Expand Down Expand Up @@ -386,9 +386,9 @@ public void WritingEntryExpandWithMixedCollectionAndNonCollectionContainedElemen
{
this.entryWithOnlyData1,
this.containedCollectionNavLink,
new ODataFeed(),
new ODataFeed(),
this.entryWithOnlyData2,
this.containedNavLink,
this.containedNavLink,
this.entryWithOnlyData3,
};

Expand Down Expand Up @@ -422,9 +422,9 @@ public void WritingEntryExpandWithExpandCollectionNavPropAndNonCollectionContain
{
this.entryWithOnlyData1,
this.expandedCollectionNavLink,
new ODataFeed(),
new ODataFeed(),
this.entryWithOnlyData2,
this.containedNavLink,
this.containedNavLink,
this.entryWithOnlyData3
};

Expand Down Expand Up @@ -458,8 +458,8 @@ public void WritingEntryExpandWithCollectionContainedElementAndExpandNavProp()
ODataItem[] itemsToWrite = new ODataItem[]
{
this.entryWithOnlyData1,
this.containedCollectionNavLink,
new ODataFeed(),
this.containedCollectionNavLink,
new ODataFeed(),
this.entryWithOnlyData2,
this.expandedNavLink,
this.entryWithOnlyData3
Expand Down Expand Up @@ -537,11 +537,11 @@ public void WritingFeedExpandWithNonCollectionContainedElementWithTypeCast()
{
ODataItem[] itemsToWrite = new ODataItem[]
{
new ODataFeed(),
new ODataFeed(),
this.entryWithOnlyData1,
this.containedNavLink,
this.entryWithOnlyData2,
this.containedNavLink,
this.containedNavLink,
this.entryWithOnlyData3
};

Expand Down Expand Up @@ -576,9 +576,9 @@ public void WritingEntryExpandWithMixedCollectionAndNonCollectionContainedElemen
{
this.entryWithOnlyData1,
this.containedCollectionNavLink,
new ODataFeed(),
new ODataFeed(),
this.entryWithOnlyData2,
this.containedNavLink,
this.containedNavLink,
this.entryWithOnlyData3,
};

Expand Down Expand Up @@ -662,10 +662,10 @@ public void WritingEntryExpandWithMixedCollectionAndNonCollectionContainedElemen
this.entryWithOnlyData2,
new ODataNavigationLinkEnd(),
this.containedCollectionNavLink,
new ODataFeed(),
new ODataFeed(),
this.entryWithOnlyData2,
new ODataNavigationLinkEnd(),
this.containedNavLink,
new ODataNavigationLinkEnd(),
this.containedNavLink,
this.entryWithOnlyData3,
};

Expand Down Expand Up @@ -780,7 +780,7 @@ public void WritingTopLevelInlinecountTest()

ODataItem[] itemsToWrite = new ODataItem[]
{
feed,
feed,
this.entryWithOnlyData1,
};

Expand All @@ -806,7 +806,7 @@ public void WritingNestedInlinecountTest()

ODataItem[] itemsToWrite = new ODataItem[]
{
new ODataFeed(),
new ODataFeed(),
this.entryWithOnlyData1,
this.containedCollectionNavLink,
feed
Expand Down Expand Up @@ -907,7 +907,7 @@ public void ReadingNestedInlinecountTest()
#endregion Inlinecount Tests

[Fact]
public void ShouldWriteAdditionalPropertyWhenFullValidationDisabled()
public void ShouldAlwaysWriteAdditionalPropertyWhenWriteResponse()
{
var entry = new ODataEntry
{
Expand All @@ -921,30 +921,30 @@ public void ShouldWriteAdditionalPropertyWhenFullValidationDisabled()

ODataItem[] itemsToWrite = { entry };

Action action = () => this.GetWriterOutputForContentTypeAndKnobValue(
string expectedPayload =
"{\"" +
"@odata.context\":\"http://example.org/odata.svc/$metadata#EntitySet/$entity\"," +
"\"ID\":102,\"Name\":\"Bob\",\"Prop1\":\"Var1\"" +
"}";

string result = this.GetWriterOutputForContentTypeAndKnobValue(
"application/json;odata.metadata=minimal",
true,
itemsToWrite,
Model,
EntitySet,
EntityType,
enableFullValidation: true);
action.ShouldThrow<ODataException>().WithMessage(
Strings.ValidationUtils_PropertyDoesNotExistOnType("Prop1", "Namespace.EntityType"));
result.Should().Be(expectedPayload);

string result = this.GetWriterOutputForContentTypeAndKnobValue(
result = this.GetWriterOutputForContentTypeAndKnobValue(
"application/json;odata.metadata=minimal",
true,
itemsToWrite,
Model,
EntitySet,
EntityType,
enableFullValidation: false);
string expectedPayload =
"{\"" +
"@odata.context\":\"http://example.org/odata.svc/$metadata#EntitySet/$entity\"," +
"\"ID\":102,\"Name\":\"Bob\",\"Prop1\":\"Var1\"" +
"}";
result.Should().Be(expectedPayload);
}

Expand All @@ -964,8 +964,8 @@ public void ShouldWriteNestedContextUrlIfCanNotBeInferred()
ODataItem[] itemsToWrite = new ODataItem[]
{
this.entryWithOnlyData1,
this.containedCollectionNavLink,
new ODataFeed(),
this.containedCollectionNavLink,
new ODataFeed(),
entryWithOnlyData2WithSerializationInfo,
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2129,23 +2129,6 @@ private IEnumerable<PayloadWriterTestDescriptor<ODataPayloadElement>> GenerateCo
)
));
}

var propertyInComplexValue2 = duplicateProperty.Value.Properties.First();
propertyInComplexValue2.Name = String.Format(CultureInfo.InvariantCulture, "{0}{1}", propertyInComplexValue2.Name, Guid.NewGuid().ToString().Substring(0, 5));

testCases.Add(new PayloadWriterTestDescriptor<ODataPayloadElement>(
this.Settings,
duplicateProperty,
new PayloadWriterTestDescriptor.WriterTestExpectedResultCallback(
(config) =>
{
return new WriterTestExpectedResults(this.Settings.ExpectedResultSettings)
{
ExpectedException2 = ODataExpectedExceptions.ODataException("ValidationUtils_PropertyDoesNotExistOnType", propertyInComplexValue2.Name, duplicateProperty.Value.FullTypeName),
};
}
)
));
}
}
return testCases;
Expand Down

0 comments on commit 27ded6a

Please sign in to comment.