forked from OData/odata.net
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Undeclared properties should be allowed on Open Types
Added support to ClientEdmModel to consult IEdmEntityType's IsOpen property when instantiating EdmEntityTypeWithDelayLoadedProperties and EdmComplexTypeWithDelayLoadedProperties. ClientEdmModel was always setting isOpen to false for these instances. This fixes an issue where sending arbitrary/undeclared ODataProperty instances up would throw in WriterValidationUtil.ValidatePropertyDefined(). This addresses OData#143
- Loading branch information
1 parent
0223a9f
commit fefc1a7
Showing
4 changed files
with
98 additions
and
3 deletions.
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
70 changes: 70 additions & 0 deletions
70
test/EndToEndTests/Tests/Client/Build.Desktop/ClientTests/ClientOpenTypeUpdateTests.cs
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 |
---|---|---|
@@ -0,0 +1,70 @@ | ||
//--------------------------------------------------------------------- | ||
// <copyright file="ClientUpdateTests.cs" company="Microsoft"> | ||
// Copyright (C) Microsoft Corporation. All rights reserved. See License.txt in the project root for license information. | ||
// </copyright> | ||
//--------------------------------------------------------------------- | ||
|
||
namespace Microsoft.Test.OData.Tests.Client | ||
{ | ||
using Microsoft.OData.Client; | ||
using System.Linq; | ||
using Microsoft.Test.OData.Framework; | ||
using Microsoft.Test.OData.Framework.Client; | ||
using Microsoft.Test.OData.Services.TestServices; | ||
using Microsoft.Test.OData.Services.TestServices.OpenTypesServiceReference; | ||
using Microsoft.VisualStudio.TestTools.UnitTesting; | ||
using System.Collections.Generic; | ||
using Microsoft.OData.Core; | ||
using System; | ||
|
||
/// <summary> | ||
/// Generic client update test cases. | ||
/// </summary> | ||
[TestClass] | ||
public class ClientOpenTypeUpdateTests : EndToEndTestBase | ||
{ | ||
private DataServiceContextWrapper<DefaultContainer> contextWrapper; | ||
|
||
public ClientOpenTypeUpdateTests() | ||
: base(ServiceDescriptors.OpenTypesService) | ||
{ | ||
} | ||
|
||
[TestMethod] | ||
public void UpdateOpenTypeWithUndeclaredProperties() | ||
{ | ||
SetContextWrapper(); | ||
contextWrapper.MergeOption = MergeOption.PreserveChanges; | ||
contextWrapper.Configurations.RequestPipeline.OnEntryStarting(ea => EntryStarting(ea)); | ||
var row = contextWrapper.Context.Row.Where(r => r.Id == Guid.Parse("814d505b-6b6a-45a0-9de0-153b16149d56")).First(); | ||
|
||
// In practice, transient property data would be mutated here in the partial companion to the client proxy. | ||
|
||
contextWrapper.UpdateObject(row); | ||
contextWrapper.SaveChanges(); | ||
} | ||
|
||
private void EntryStarting(WritingEntryArgs ea) | ||
{ | ||
var odataProps = ea.Entry.Properties as List<ODataProperty>; | ||
var entityState = contextWrapper.Context.Entities.First(e => e.Entity == ea.Entity).State; | ||
|
||
// Send up an undeclared property on an Open Type. | ||
if (entityState == EntityStates.Modified || entityState == EntityStates.Added) | ||
{ | ||
if (ea.Entity.GetType() == typeof(Row)) | ||
{ | ||
// In practice, the data from this undeclared property would probably be stored in a transient property of the partial companion class to the client proxy. | ||
var undeclaredOdataProperty = new ODataProperty() { Name = "dynamicPropertyKey", Value = "dynamicPropertyValue" }; | ||
odataProps.Add(undeclaredOdataProperty); | ||
} | ||
} | ||
|
||
ea.Entry.Properties = odataProps; | ||
} | ||
private void SetContextWrapper() | ||
{ | ||
contextWrapper = this.CreateWrappedContext<DefaultContainer>(); | ||
} | ||
} | ||
} |
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