diff --git a/src/Microsoft.OData.Client/AtomMaterializerLog.cs b/src/Microsoft.OData.Client/AtomMaterializerLog.cs index 5f39833c57..d3d7510845 100644 --- a/src/Microsoft.OData.Client/AtomMaterializerLog.cs +++ b/src/Microsoft.OData.Client/AtomMaterializerLog.cs @@ -49,7 +49,7 @@ internal class AtomMaterializerLog /// /// The materializer context. /// - private IODataMaterializerContext materializerContext; + private readonly IODataMaterializerContext materializerContext; #endregion Private fields @@ -69,6 +69,7 @@ internal AtomMaterializerLog(MergeOption mergeOption, ClientEdmModel model, Enti { Debug.Assert(model != null, "model != null"); Debug.Assert(entityTracker != null, "entityTracker != null"); + Debug.Assert(materializerContext != null, "materializerContext != null"); this.appendOnlyEntries = new Dictionary(EqualityComparer.Default); this.mergeOption = mergeOption; diff --git a/src/Microsoft.OData.Client/BaseAsyncResult.cs b/src/Microsoft.OData.Client/BaseAsyncResult.cs index 6d9140043b..10502e8aad 100644 --- a/src/Microsoft.OData.Client/BaseAsyncResult.cs +++ b/src/Microsoft.OData.Client/BaseAsyncResult.cs @@ -27,11 +27,6 @@ internal abstract class BaseAsyncResult : IAsyncResult /// wrapped request protected PerRequest perRequest; - /// - /// Cache used to store temporary metadata used for materialization of OData items. - /// - protected MaterializerCache materializerCache = new MaterializerCache(); - /// /// The int equivalent for true. /// @@ -94,6 +89,11 @@ internal BaseAsyncResult(object source, string method, AsyncCallback callback, o this.userState = state; } + /// + /// Cache used to store temporary metadata used for materialization of OData items. + /// + protected MaterializerCache MaterializerCache { get; } = new MaterializerCache(); + /// /// This delegate exists to workaround limitations in the WP7 runtime. /// When limitations on the number of parameters to Func<> are resolved, this can be subsumed by the following: diff --git a/src/Microsoft.OData.Client/BatchSaveResult.cs b/src/Microsoft.OData.Client/BatchSaveResult.cs index cd3a240a3c..054c4308ba 100644 --- a/src/Microsoft.OData.Client/BatchSaveResult.cs +++ b/src/Microsoft.OData.Client/BatchSaveResult.cs @@ -254,7 +254,7 @@ protected override MaterializeAtom GetMaterializer(EntityDescriptor entityDescri /*projectionPlan*/ null, this.currentOperationResponse.CreateResponseMessage(), ODataPayloadKind.Resource, - this.materializerCache); + base.MaterializerCache); } /// @@ -690,7 +690,7 @@ private IEnumerable HandleBatchResponse(ODataBatchReader batc this.currentOperationResponse.Headers.GetHeader(XmlConstants.HttpContentType), this.currentOperationResponse.CreateResponseMessage(), query.PayloadKind, - this.materializerCache); + base.MaterializerCache); qresponse = QueryOperationResponse.GetInstance(query.ElementType, this.currentOperationResponse.Headers, query, materializer); } } diff --git a/src/Microsoft.OData.Client/GroupByProjectionPlanCompiler.cs b/src/Microsoft.OData.Client/GroupByProjectionPlanCompiler.cs index e2363aa0c5..6cf8b12253 100644 --- a/src/Microsoft.OData.Client/GroupByProjectionPlanCompiler.cs +++ b/src/Microsoft.OData.Client/GroupByProjectionPlanCompiler.cs @@ -364,7 +364,12 @@ private Expression CallValueForPath(Expression entry, Expression entryType, Proj Debug.Assert(entry != null, "entry != null"); Debug.Assert(path != null, "path != null"); - Expression result = CallMaterializer("ProjectionValueForPath", this.materializerExpression, entry, entryType, Expression.Constant(path, typeof(object))); + Expression result = CallMaterializer( + nameof(ODataEntityMaterializerInvoker.ProjectionValueForPath), + this.materializerExpression, + entry, + entryType, + Expression.Constant(path, typeof(object))); this.annotations.Add(result, new ExpressionAnnotation() { Segment = path[path.Count - 1] }); return result; } @@ -523,7 +528,7 @@ private Expression RebindMethodCallForAggregationMethod(MethodCallExpression met annotation.Segment.StartPath.Add(memberSegment); Expression value = CallMaterializer( - "ProjectionDynamicValueForPath", + nameof(ODataEntityMaterializerInvoker.ProjectionDynamicValueForPath), this.materializerExpression, annotation.Segment.StartPath.RootEntry, Expression.Constant(targetType, typeof(Type)), diff --git a/src/Microsoft.OData.Client/ProjectionPlanCompiler.cs b/src/Microsoft.OData.Client/ProjectionPlanCompiler.cs index 9051246250..72d90127fa 100644 --- a/src/Microsoft.OData.Client/ProjectionPlanCompiler.cs +++ b/src/Microsoft.OData.Client/ProjectionPlanCompiler.cs @@ -67,6 +67,8 @@ internal class ProjectionPlanCompiler : ALinqExpressionVisitor /// The materializer context. private ProjectionPlanCompiler(Dictionary normalizerRewrites, IODataMaterializerContext materializerContext) { + Debug.Assert(materializerContext != null, "materializerContext != null"); + this.annotations = new Dictionary(ReferenceEqualityComparer.Instance); this.materializerExpression = Expression.Parameter(typeof(object), "mat"); this.normalizerRewrites = normalizerRewrites; @@ -504,7 +506,12 @@ private static Expression RebindConstructor(ConstructorInfo info, params Express /// A new expression with the call instance. private Expression CallCheckValueForPathIsNull(Expression entry, Expression entryType, ProjectionPath path) { - Expression result = CallMaterializer("ProjectionCheckValueForPathIsNull", entry, entryType, Expression.Constant(path, typeof(object))); + Expression result = CallMaterializer( + nameof(ODataEntityMaterializerInvoker.ProjectionCheckValueForPathIsNull), + entry, + entryType, + Expression.Constant(path, typeof(object)), + Expression.Constant(this.materializerContext)); this.annotations.Add(result, new ExpressionAnnotation() { Segment = path[path.Count - 1] }); return result; } @@ -519,7 +526,12 @@ private Expression CallValueForPath(Expression entry, Expression entryType, Proj Debug.Assert(entry != null, "entry != null"); Debug.Assert(path != null, "path != null"); - Expression result = CallMaterializer("ProjectionValueForPath", this.materializerExpression, entry, entryType, Expression.Constant(path, typeof(object))); + Expression result = CallMaterializer( + nameof(ODataEntityMaterializerInvoker.ProjectionValueForPath), + this.materializerExpression, + entry, + entryType, + Expression.Constant(path, typeof(object))); this.annotations.Add(result, new ExpressionAnnotation() { Segment = path[path.Count - 1] }); return result; } @@ -671,7 +683,7 @@ private Expression RebindEntityMemberInit(MemberInitExpression init) assignment.Expression.NodeType == ExpressionType.MemberInit)) { Expression nestedEntry = CallMaterializer( - "ProjectionGetEntry", + nameof(ODataEntityMaterializerInvoker.ProjectionGetEntry), entryParameterAtMemberInit, Expression.Constant(assignment.Member.Name, typeof(string)), Expression.Constant(this.materializerContext)); @@ -771,7 +783,7 @@ private Expression RebindEntityMemberInit(MemberInitExpression init) } Expression reboundExpression = CallMaterializer( - "ProjectionInitializeEntity", + nameof(ODataEntityMaterializerInvoker.ProjectionInitializeEntity), this.materializerExpression, entryToInitValue, expectedParamValue, @@ -797,7 +809,7 @@ private Expression GetDeepestEntry(Expression[] path) do { result = CallMaterializer( - "ProjectionGetEntry", + nameof(ODataEntityMaterializerInvoker.ProjectionGetEntry), result ?? this.pathBuilder.ParameterEntryInScope, Expression.Constant(((MemberExpression)path[pathIndex]).Member.Name, typeof(string))); pathIndex++; @@ -1051,7 +1063,7 @@ private Expression RebindMethodCallForMemberSelect(MethodCallExpression call) // helpers, eg to preserve paging information. Type returnElementType = call.Method.ReturnType.GetGenericArguments()[0]; result = CallMaterializer( - "ProjectionSelect", + nameof(ODataEntityMaterializerInvoker.ProjectionSelect), this.materializerExpression, this.pathBuilder.ParameterEntryInScope, this.pathBuilder.ExpectedParamTypeInScope, @@ -1060,7 +1072,7 @@ private Expression RebindMethodCallForMemberSelect(MethodCallExpression call) selectorExpression); this.annotations.Add(result, annotation); result = CallMaterializerWithType( - "EnumerateAsElementType", + nameof(ODataEntityMaterializerInvoker.EnumerateAsElementType), new Type[] { returnElementType }, result); this.annotations.Add(result, annotation); @@ -1150,7 +1162,7 @@ private Expression RebindMethodCallForNewSequence(MethodCallExpression call) // {(mat, entry1, type1) => Convert(ProjectionValueForPath(mat, entry1, type1, p->*.FirstName))} Type returnElementType = call.Method.ReturnType.GetGenericArguments()[0]; result = CallMaterializer( - "ProjectionSelect", + nameof(ODataEntityMaterializerInvoker.ProjectionSelect), this.materializerExpression, this.pathBuilder.ParameterEntryInScope, this.pathBuilder.ExpectedParamTypeInScope, @@ -1159,7 +1171,7 @@ private Expression RebindMethodCallForNewSequence(MethodCallExpression call) selectorExpression); this.annotations.Add(result, annotation); result = CallMaterializerWithType( - "EnumerateAsElementType", + nameof(ODataEntityMaterializerInvoker.EnumerateAsElementType), new Type[] { returnElementType }, result); this.annotations.Add(result, annotation); @@ -1209,7 +1221,7 @@ private Expression TypedEnumerableToList(Expression source, Type targetType) // Return the annotated expression. Expression result = CallMaterializerWithType( - "ListAsElementType", + nameof(ODataEntityMaterializer.ListAsElementType), new Type[] { enumeratedType, listElementType }, this.materializerExpression, source); diff --git a/src/Microsoft.OData.Client/QueryResult.cs b/src/Microsoft.OData.Client/QueryResult.cs index eb0d6a7ed0..156376832f 100644 --- a/src/Microsoft.OData.Client/QueryResult.cs +++ b/src/Microsoft.OData.Client/QueryResult.cs @@ -708,7 +708,7 @@ private MaterializeAtom CreateMaterializer(ProjectionPlan plan, ODataPayloadKind this.ContentType, responseMessageWrapper, payloadKind, - this.materializerCache); + base.MaterializerCache); } } } diff --git a/src/Microsoft.OData.Client/SaveResult.cs b/src/Microsoft.OData.Client/SaveResult.cs index a3c14f7165..89eceb6dde 100644 --- a/src/Microsoft.OData.Client/SaveResult.cs +++ b/src/Microsoft.OData.Client/SaveResult.cs @@ -360,7 +360,7 @@ protected override MaterializeAtom GetMaterializer(EntityDescriptor entityDescri { Debug.Assert(this.cachedResponse.Exception == null && this.cachedResponse.MaterializerEntry != null, "this.cachedResponse.Exception == null && this.cachedResponse.Entry != null"); ODataResource entry = this.cachedResponse.MaterializerEntry == null ? null : this.cachedResponse.MaterializerEntry.Entry; - return new MaterializeAtom(responseInfo, new[] { entry }, entityDescriptor.Entity.GetType(), this.cachedResponse.MaterializerEntry.Format, this.materializerCache); + return new MaterializeAtom(responseInfo, new[] { entry }, entityDescriptor.Entity.GetType(), this.cachedResponse.MaterializerEntry.Format, base.MaterializerCache); } /// @@ -865,7 +865,7 @@ private void HandleOperationResponseData(IODataResponseMessage responseMsg, Stre responseMsg.StatusCode, () => responseStream); - ODataMaterializerContext materializerContext = new ODataMaterializerContext(responseInfo, this.materializerCache); + ODataMaterializerContext materializerContext = new ODataMaterializerContext(responseInfo, base.MaterializerCache); entry = ODataReaderEntityMaterializer.ParseSingleEntityPayload(responseMessageWrapper, responseInfo, entityDescriptor.Entity.GetType(), materializerContext); entityDescriptor.TransientEntityDescriptor = entry.EntityDescriptor; } diff --git a/test/EndToEndTests/Tests/Client/AsynchronousTests/AsynchronousQueryTests.cs b/test/EndToEndTests/Tests/Client/AsynchronousTests/AsynchronousQueryTests.cs index b241d5bc2a..7bff3e1619 100644 --- a/test/EndToEndTests/Tests/Client/AsynchronousTests/AsynchronousQueryTests.cs +++ b/test/EndToEndTests/Tests/Client/AsynchronousTests/AsynchronousQueryTests.cs @@ -11,6 +11,7 @@ namespace Microsoft.Test.OData.Tests.Client.AsynchronousTests using System.Linq; using System.Net; using System.Reflection; + using System.Threading.Tasks; using Microsoft.OData.Client; using Microsoft.Test.OData.Services.TestServices; using Microsoft.Test.OData.Services.TestServices.AstoriaDefaultServiceReference; @@ -788,6 +789,24 @@ public void Linq_ProjectPropertiesFromEntityandExpandedEntity() this.EnqueueTestComplete(); } + [Fact] + public async Task Linq_ProjectPropertiesFromEntityWithConditionalNullCheckOnExpandedEntity() + { + var context = this.CreateWrappedContext().Context; + var query = context.Computer.Where(c => c.ComputerId == -10) + .Select(c => new Computer + { + ComputerId = c.ComputerId, + ComputerDetail = c.ComputerDetail == null ? null : c.ComputerDetail, + }) as DataServiceQuery; + + var result = await query.ExecuteAsync(); + + var computer = result.First(); + Assert.Equal(-10, computer.ComputerId); + Assert.Equal(-10, computer.ComputerDetail.ComputerDetailId); + } + /// /// LINQ query Project Name Stream Property /// diff --git a/test/FunctionalTests/Tests/DataServices/UnitTests/Client.TDD.Tests/Tests/Materialization/CollectionValueMaterializationPolicyTests.cs b/test/FunctionalTests/Tests/DataServices/UnitTests/Client.TDD.Tests/Tests/Materialization/CollectionValueMaterializationPolicyTests.cs index 03539d18cc..ec244d9fad 100644 --- a/test/FunctionalTests/Tests/DataServices/UnitTests/Client.TDD.Tests/Tests/Materialization/CollectionValueMaterializationPolicyTests.cs +++ b/test/FunctionalTests/Tests/DataServices/UnitTests/Client.TDD.Tests/Tests/Materialization/CollectionValueMaterializationPolicyTests.cs @@ -130,7 +130,7 @@ public void AddingCollectionToComplexCollectionShouldFail() [Fact] public void DataServicCollectionOfTAsCollectionTypeShouldFailForPrimitiveOrComplexCollections() { - var testContext = new TestMaterializerContext(new MaterializerCache()); + var testContext = new TestMaterializerContext(); var edmType = testContext.Model.GetOrCreateEdmType(typeof(MyInfo)); var clientTypeAnnotation = new ClientTypeAnnotation(edmType, typeof(MyInfo), "MyInfo", testContext.Model); @@ -141,7 +141,7 @@ public void DataServicCollectionOfTAsCollectionTypeShouldFailForPrimitiveOrCompl [Fact] public void CreateCollectionInstanceShouldFailOnTypeWithNoParametersLessConstructors() { - var testContext = new TestMaterializerContext(new MaterializerCache()); + var testContext = new TestMaterializerContext(); var edmType = testContext.Model.GetOrCreateEdmType(typeof(ListWithNoEmptyConstructors)); var clientTypeAnnotation = new ClientTypeAnnotation(edmType, typeof(ListWithNoEmptyConstructors), "Points", testContext.Model); @@ -153,7 +153,7 @@ public void CreateCollectionInstanceShouldFailOnTypeWithNoParametersLessConstruc public void CreateCollectionPropertyInstanceShouldFailOnTypeWithNoParametersLessConstructors() { var odataProperty = new ODataProperty() { Name = "foo", Value = new ODataCollectionValue() { TypeName = "Points" } }; - var testContext = new TestMaterializerContext(new MaterializerCache()); + var testContext = new TestMaterializerContext(); testContext.ResolveTypeForMaterializationOverrideFunc = (Type type, string name) => { var edmType = testContext.Model.GetOrCreateEdmType(typeof(ListWithNoEmptyConstructors)); @@ -167,7 +167,7 @@ public void CreateCollectionPropertyInstanceShouldFailOnTypeWithNoParametersLess [Fact] public void NonMissingMethodExceptionOnCreateInstanceShouldNotBeCaught() { - var testContext = new TestMaterializerContext(new MaterializerCache()); + var testContext = new TestMaterializerContext(); var edmType = testContext.Model.GetOrCreateEdmType(typeof(ListWithNoEmptyConstructors)); var clientTypeAnnotation = new ClientTypeAnnotation(edmType, typeof(ErrorThrowingList), "Points", testContext.Model); @@ -181,7 +181,7 @@ public void NonMissingMethodExceptionOnCreateInstanceShouldNotBeCaught() internal CollectionValueMaterializationPolicy CreateCollectionValueMaterializationPolicy() { - return CreateCollectionValueMaterializationPolicy(new TestMaterializerContext(new MaterializerCache())); + return CreateCollectionValueMaterializationPolicy(new TestMaterializerContext()); } internal CollectionValueMaterializationPolicy CreateCollectionValueMaterializationPolicy(IODataMaterializerContext materializerContext) diff --git a/test/FunctionalTests/Tests/DataServices/UnitTests/Client.TDD.Tests/Tests/Materialization/EntryMaterializationPolicyForComplexResourceTests.cs b/test/FunctionalTests/Tests/DataServices/UnitTests/Client.TDD.Tests/Tests/Materialization/EntryMaterializationPolicyForComplexResourceTests.cs index c8a45c571b..7ff46e48d2 100644 --- a/test/FunctionalTests/Tests/DataServices/UnitTests/Client.TDD.Tests/Tests/Materialization/EntryMaterializationPolicyForComplexResourceTests.cs +++ b/test/FunctionalTests/Tests/DataServices/UnitTests/Client.TDD.Tests/Tests/Materialization/EntryMaterializationPolicyForComplexResourceTests.cs @@ -50,7 +50,7 @@ public void ComplexWithPrimitiveValueShouldMaterialize() [Fact] public void ApplyNonExistantPropertyWithIgnoreMissingPropertiesShouldNotError() { - TestMaterializerContext materializerContext = new TestMaterializerContext(new MaterializerCache()) { UndeclaredPropertyBehavior = DSClient.UndeclaredPropertyBehavior.Support }; + TestMaterializerContext materializerContext = new TestMaterializerContext() { UndeclaredPropertyBehavior = DSClient.UndeclaredPropertyBehavior.Support }; CollectionValueMaterializationPolicyTests.Point point = new CollectionValueMaterializationPolicyTests.Point(); ODataProperty property = new ODataProperty() { Name = "Z", Value = 10 }; this.CreateEntryMaterializationPolicy(materializerContext) @@ -60,7 +60,7 @@ public void ApplyNonExistantPropertyWithIgnoreMissingPropertiesShouldNotError() [Fact] public void ApplyNullOnCollectionPropertyShouldError() { - TestMaterializerContext materializerContext = new TestMaterializerContext(new MaterializerCache()); + TestMaterializerContext materializerContext = new TestMaterializerContext(); ComplexTypeWithPrimitiveCollection complexInstance = new ComplexTypeWithPrimitiveCollection(); ODataProperty property = new ODataProperty() { Name = "Strings", Value = null }; @@ -71,7 +71,7 @@ public void ApplyNullOnCollectionPropertyShouldError() [Fact] public void ApplyStringValueForCollectionPropertyShouldError() { - TestMaterializerContext materializerContext = new TestMaterializerContext(new MaterializerCache()); + TestMaterializerContext materializerContext = new TestMaterializerContext(); ComplexTypeWithPrimitiveCollection complexInstance = new ComplexTypeWithPrimitiveCollection(); ODataProperty property = new ODataProperty() { Name = "Strings", Value = "foo" }; @@ -82,8 +82,7 @@ public void ApplyStringValueForCollectionPropertyShouldError() [Fact] public void MaterializeDerivedComplexForBaseComplexTypeProperty() { - var materializerCache = new MaterializerCache(); - TestMaterializerContext materializerContext = new TestMaterializerContext(materializerCache); + TestMaterializerContext materializerContext = new TestMaterializerContext(); //In a true client, a TypeResolver will be used to resolve derived property type. materializerContext.ResolveTypeForMaterializationOverrideFunc = (Type type, string name) => @@ -110,7 +109,7 @@ public void MaterializeDerivedComplexForBaseComplexTypeProperty() [Fact] public void ApplyDerivedComplexForBaseComplexTypeProperty() { - TestMaterializerContext materializerContext = new TestMaterializerContext(new MaterializerCache()); + TestMaterializerContext materializerContext = new TestMaterializerContext(); materializerContext.ResolveTypeForMaterializationOverrideFunc = (Type type, string name) => { @@ -141,7 +140,7 @@ public void ApplyDerivedComplexForBaseComplexTypeProperty() [Fact] public void ApplyODataCollectionValueToNonNullExistingCollectionProperty() { - TestMaterializerContext materializerContext = new TestMaterializerContext(new MaterializerCache()); + TestMaterializerContext materializerContext = new TestMaterializerContext(); ComplexTypeWithPrimitiveCollection complexInstance = new ComplexTypeWithPrimitiveCollection(); complexInstance.Strings.Add("ShouldBeCleared"); @@ -157,7 +156,7 @@ public void ApplyODataCollectionValueToNonNullExistingCollectionProperty() [Fact] public void ApplyODataCollectionValueToNullCollectionProperty() { - TestMaterializerContext materializerContext = new TestMaterializerContext(new MaterializerCache()); + TestMaterializerContext materializerContext = new TestMaterializerContext(); ComplexTypeWithPrimitiveCollection complexInstance = new ComplexTypeWithPrimitiveCollection(); complexInstance.Strings = null; ODataProperty property = new ODataProperty() { Name = "Strings", Value = new ODataCollectionValue() { Items = new string[] { "foo" }, TypeName = typeof(ComplexTypeWithPrimitiveCollection).FullName } }; @@ -172,7 +171,7 @@ public void ValueShouldBeAppliedRegardlessIfPropertyStartsNullOrNot() { foreach (var startingPropertyState in new ChildComplexType[] { null, new ChildComplexType() }) { - TestMaterializerContext materializerContext = new TestMaterializerContext(new MaterializerCache()); + TestMaterializerContext materializerContext = new TestMaterializerContext(); ComplexTypeWithChildComplexType complexInstance = new ComplexTypeWithChildComplexType(); complexInstance.InnerComplexProperty = startingPropertyState; var innerEntry = new ODataResource() { Properties = new ODataProperty[] { new ODataProperty() { Name = "Prop", Value = 1 } } }; @@ -184,7 +183,7 @@ public void ValueShouldBeAppliedRegardlessIfPropertyStartsNullOrNot() [Fact] public void NullValueShouldBeAppliedToSubComplexValueProperty() { - TestMaterializerContext materializerContext = new TestMaterializerContext(new MaterializerCache()); + TestMaterializerContext materializerContext = new TestMaterializerContext(); ComplexTypeWithChildComplexType complexInstance = new ComplexTypeWithChildComplexType(); complexInstance.InnerComplexProperty = new ChildComplexType(); @@ -194,7 +193,7 @@ public void NullValueShouldBeAppliedToSubComplexValueProperty() private void ApplyInnerProperty(ODataResource innerResource, ComplexTypeWithChildComplexType parentInstance, TestMaterializerContext materializerContext = null) { - materializerContext = materializerContext ?? new TestMaterializerContext(new MaterializerCache()); + materializerContext = materializerContext ?? new TestMaterializerContext(); var resource = new ODataResource() { TypeName = "ComplexTypeWithChildComplexType", Properties = new ODataProperty[0] }; var clientEdmModel = new ClientEdmModel(ODataProtocolVersion.V4); @@ -224,7 +223,7 @@ internal EntryValueMaterializationPolicy CreateEntryMaterializationPolicy(TestMa { var clientEdmModel = new ClientEdmModel(ODataProtocolVersion.V4); var context = new DataServiceContext(); - materializerContext = materializerContext ?? new TestMaterializerContext(new MaterializerCache()) { Model = clientEdmModel, Context = context }; + materializerContext = materializerContext ?? new TestMaterializerContext() { Model = clientEdmModel, Context = context }; var adapter = new EntityTrackingAdapter(new TestEntityTracker(), MergeOption.OverwriteChanges, clientEdmModel, context, materializerContext); var lazyPrimitivePropertyConverter = new DSClient.SimpleLazy(() => new PrimitivePropertyConverter()); var primitiveValueMaterializerPolicy = new PrimitiveValueMaterializationPolicy(materializerContext, lazyPrimitivePropertyConverter); @@ -274,7 +273,7 @@ public void ShouldMaterializeConcreteComplexCollectionDeclaredAsAbstract() new ODataResource(){Properties = new ODataProperty[]{ new ODataProperty(){Name="Points", Value = 0}, new ODataProperty(){Name="Diameter", Value = 18} }}, }); - var testContext = new TestMaterializerContext(new MaterializerCache()); + var testContext = new TestMaterializerContext(); testContext.ResolveTypeForMaterializationOverrideFunc = (Type type, string name) => { var edmType = testContext.Model.GetOrCreateEdmType(typeof(CollectionValueMaterializationPolicyTests.Circle)); @@ -328,7 +327,7 @@ internal ODataEntriesEntityMaterializer CreateODataEntriesEntityMaterializer( { var clientEdmModel = new ClientEdmModel(ODataProtocolVersion.V4); var context = new DataServiceContext(); - materializerContext = materializerContext ?? new TestMaterializerContext(new MaterializerCache()) { Model = clientEdmModel, Context = context }; + materializerContext = materializerContext ?? new TestMaterializerContext() { Model = clientEdmModel, Context = context }; var resourceSet = new ODataResourceSet(); MaterializerFeed.CreateFeed(resourceSet, resources, materializerContext); diff --git a/test/FunctionalTests/Tests/DataServices/UnitTests/Client.TDD.Tests/Tests/Materialization/EntryValueMaterializationPolicyUnitTests.cs b/test/FunctionalTests/Tests/DataServices/UnitTests/Client.TDD.Tests/Tests/Materialization/EntryValueMaterializationPolicyUnitTests.cs index d8e7ed2303..7e1b53f3c8 100644 --- a/test/FunctionalTests/Tests/DataServices/UnitTests/Client.TDD.Tests/Tests/Materialization/EntryValueMaterializationPolicyUnitTests.cs +++ b/test/FunctionalTests/Tests/DataServices/UnitTests/Client.TDD.Tests/Tests/Materialization/EntryValueMaterializationPolicyUnitTests.cs @@ -41,7 +41,7 @@ public EntryValueMaterializationPolicyUnitTests() this.clientEdmModel = new ClientEdmModel(ODataProtocolVersion.V4); this.clientEdmModel.GetOrCreateEdmType(typeof(TestCustomer)); this.clientEdmModel.GetOrCreateEdmType(typeof(TestOrder)); - this.materializerContext = new TestMaterializerContext(new MaterializerCache()) { Model = this.clientEdmModel }; + this.materializerContext = new TestMaterializerContext() { Model = this.clientEdmModel }; this.ordersProperty = this.clientEdmModel.GetClientTypeAnnotation(typeof(TestCustomer)).GetProperty("Orders", UndeclaredPropertyBehavior.ThrowException); } diff --git a/test/FunctionalTests/Tests/DataServices/UnitTests/Client.TDD.Tests/Tests/Materialization/FeedAndEntryMaterializerAdapterUnitTests.cs b/test/FunctionalTests/Tests/DataServices/UnitTests/Client.TDD.Tests/Tests/Materialization/FeedAndEntryMaterializerAdapterUnitTests.cs index e9805920b9..5915f84c8b 100644 --- a/test/FunctionalTests/Tests/DataServices/UnitTests/Client.TDD.Tests/Tests/Materialization/FeedAndEntryMaterializerAdapterUnitTests.cs +++ b/test/FunctionalTests/Tests/DataServices/UnitTests/Client.TDD.Tests/Tests/Materialization/FeedAndEntryMaterializerAdapterUnitTests.cs @@ -52,7 +52,7 @@ public void ValidateShortIntegrationFeedReading() var responsePipeline = new DataServiceClientResponsePipelineConfiguration(new DataServiceContext()); var odataReaderWrapper = ODataReaderWrapper.CreateForTest(testODataReader, responsePipeline); - var materializerContext = new TestMaterializerContext(new MaterializerCache()); + var materializerContext = new TestMaterializerContext(); FeedAndEntryMaterializerAdapter reader = new FeedAndEntryMaterializerAdapter(ODataFormat.Json, odataReaderWrapper, clientEdmModel, MergeOption.OverwriteChanges, materializerContext); int readCounter = 0; diff --git a/test/FunctionalTests/Tests/DataServices/UnitTests/Client.TDD.Tests/Tests/Materialization/MaterializerEntryTests.cs b/test/FunctionalTests/Tests/DataServices/UnitTests/Client.TDD.Tests/Tests/Materialization/MaterializerEntryTests.cs index ab815f798b..38106d18e6 100644 --- a/test/FunctionalTests/Tests/DataServices/UnitTests/Client.TDD.Tests/Tests/Materialization/MaterializerEntryTests.cs +++ b/test/FunctionalTests/Tests/DataServices/UnitTests/Client.TDD.Tests/Tests/Materialization/MaterializerEntryTests.cs @@ -64,7 +64,7 @@ private MaterializerEntry CreateMaterializerEntry(ODataFormat format, Action(() => new PrimitivePropertyConverter())); + return new PrimitiveValueMaterializationPolicy(new TestMaterializerContext(), new SimpleLazy(() => new PrimitivePropertyConverter())); } public class UnknownPoint diff --git a/test/FunctionalTests/Tests/DataServices/UnitTests/Client.TDD.Tests/Tests/Materialization/TestMaterializerContext.cs b/test/FunctionalTests/Tests/DataServices/UnitTests/Client.TDD.Tests/Tests/Materialization/TestMaterializerContext.cs index 246919b7c8..5d9b3abd58 100644 --- a/test/FunctionalTests/Tests/DataServices/UnitTests/Client.TDD.Tests/Tests/Materialization/TestMaterializerContext.cs +++ b/test/FunctionalTests/Tests/DataServices/UnitTests/Client.TDD.Tests/Tests/Materialization/TestMaterializerContext.cs @@ -17,13 +17,13 @@ namespace AstoriaUnitTests.Tests /// internal class TestMaterializerContext : IODataMaterializerContext { - public TestMaterializerContext(MaterializerCache materializerCache) + public TestMaterializerContext() { this.UndeclaredPropertyBehavior = UndeclaredPropertyBehavior.ThrowException; this.ResponsePipeline = new DataServiceClientResponsePipelineConfiguration(this); this.Model = new ClientEdmModel(ODataProtocolVersion.V4); this.Context = new DataServiceContext(); - this.MaterializerCache = materializerCache; + this.MaterializerCache = new MaterializerCache(); } public Func ResolveTypeForMaterializationOverrideFunc { get; set; } diff --git a/test/FunctionalTests/Tests/DataServices/UnitTests/Client.TDD.Tests/Tests/T4/ODataT4CamelCaseTests.cs b/test/FunctionalTests/Tests/DataServices/UnitTests/Client.TDD.Tests/Tests/T4/ODataT4CamelCaseTests.cs index e24036be19..0fb2cf0a0d 100644 --- a/test/FunctionalTests/Tests/DataServices/UnitTests/Client.TDD.Tests/Tests/T4/ODataT4CamelCaseTests.cs +++ b/test/FunctionalTests/Tests/DataServices/UnitTests/Client.TDD.Tests/Tests/T4/ODataT4CamelCaseTests.cs @@ -322,7 +322,7 @@ public void MaterializeEntityShouldWork() var clientEdmModel = new ClientEdmModel(ODataProtocolVersion.V4); var context = new DataServiceContext(); - var materializerContext = new TestMaterializerContext(new MaterializerCache()) { Model = clientEdmModel, Context = context }; + var materializerContext = new TestMaterializerContext() { Model = clientEdmModel, Context = context }; var materializerEntry = MaterializerEntry.CreateEntry(odataEntry, OData.ODataFormat.Json, true, clientEdmModel, materializerContext); MaterializerNavigationLink.CreateLink(complexP, MaterializerEntry.CreateEntry(complexResource, OData.ODataFormat.Json, true, clientEdmModel, materializerContext), materializerContext); @@ -382,7 +382,7 @@ public void MaterializeComplexTypeShouldWork() } }; - var materializerContext = new TestMaterializerContext(new MaterializerCache()); + var materializerContext = new TestMaterializerContext(); var materializerEntry = MaterializerEntry.CreateEntry(complexValue, OData.ODataFormat.Json, false, new ClientEdmModel(ODataProtocolVersion.V4), materializerContext); this.CreateEntryMaterializationPolicy().Materialize(materializerEntry, typeof(ComplexType), false); var complex = materializerEntry.ResolvedObject as ComplexType; @@ -398,7 +398,7 @@ public void MaterializeEnumTypeShouldWork() { OData.ODataEnumValue enumValue = new OData.ODataEnumValue("blue"); OData.ODataProperty property = new OData.ODataProperty { Name = "enumProperty", Value = enumValue }; - var materializerContext = new TestMaterializerContext(new MaterializerCache()); + var materializerContext = new TestMaterializerContext(); var enumPolicy = new EnumValueMaterializationPolicy(materializerContext); var result = enumPolicy.MaterializeEnumTypeProperty(typeof(Color), property); property.GetMaterializedValue(materializerContext).Should().Be(Color.Blue); @@ -473,7 +473,7 @@ internal EntryValueMaterializationPolicy CreateEntryMaterializationPolicy(TestMa { var clientEdmModel = new ClientEdmModel(ODataProtocolVersion.V4); var context = new DataServiceContext().ReConfigureForNetworkLoadingTests(); - materializerContext = materializerContext ?? new TestMaterializerContext(new MaterializerCache()) { Model = clientEdmModel, Context = context }; + materializerContext = materializerContext ?? new TestMaterializerContext() { Model = clientEdmModel, Context = context }; var adapter = new EntityTrackingAdapter(new TestEntityTracker(), MergeOption.OverwriteChanges, clientEdmModel, context, materializerContext); var lazyPrimitivePropertyConverter = new Microsoft.OData.Client.SimpleLazy(() => new PrimitivePropertyConverter()); var primitiveValueMaterializerPolicy = new PrimitiveValueMaterializationPolicy(materializerContext, lazyPrimitivePropertyConverter);