From 90ba262b9588238920e731da2b32ff71c51a750d Mon Sep 17 00:00:00 2001 From: Clement Habinshuti Date: Thu, 16 Jan 2020 17:49:48 +0300 Subject: [PATCH 01/24] Make generated c# class and methods internal --- .../Templates/ODataT4CodeGenerator.ttinclude | 86 ++++++++++++------- 1 file changed, 55 insertions(+), 31 deletions(-) diff --git a/ODataConnectedService/src/Templates/ODataT4CodeGenerator.ttinclude b/ODataConnectedService/src/Templates/ODataT4CodeGenerator.ttinclude index a5c23bf..89761d0 100644 --- a/ODataConnectedService/src/Templates/ODataT4CodeGenerator.ttinclude +++ b/ODataConnectedService/src/Templates/ODataT4CodeGenerator.ttinclude @@ -47,7 +47,8 @@ THE SOFTWARE IS PROVIDED *AS IS*, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI UseDataServiceCollection = this.UseDataServiceCollection, TargetLanguage = this.TargetLanguage, EnableNamingAlias = this.EnableNamingAlias, - IgnoreUnexpectedElementsAndAttributes = this.IgnoreUnexpectedElementsAndAttributes + IgnoreUnexpectedElementsAndAttributes = this.IgnoreUnexpectedElementsAndAttributes, + MakeClassesInternal = true }; } else @@ -63,7 +64,8 @@ THE SOFTWARE IS PROVIDED *AS IS*, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI UseDataServiceCollection = this.UseDataServiceCollection, TargetLanguage = this.TargetLanguage, EnableNamingAlias = this.EnableNamingAlias, - IgnoreUnexpectedElementsAndAttributes = this.IgnoreUnexpectedElementsAndAttributes + IgnoreUnexpectedElementsAndAttributes = this.IgnoreUnexpectedElementsAndAttributes, + MakeClassesInternal = true }; } @@ -672,6 +674,16 @@ public class CodeGenerationContext get; set; } + + /// + /// true to use internal access modifier for generated classes, otherwise they will be made public. + /// This is useful if you don't want the generated classes to be visible outside the assembly + /// + public bool MakeClassesInternal + { + get; + set; + } /// /// Specifies which specific .Net Framework language the generated code will target. @@ -932,6 +944,8 @@ public abstract class ODataClientTemplate : TemplateBase internal abstract string GlobalPrefix { get; } internal abstract string SystemTypeTypeName { get; } internal abstract string AbstractModifier { get; } + internal abstract string PublicAccessModifier { get; } + internal abstract string InternalAccessModifier { get; } internal abstract string DataServiceActionQueryTypeName { get; } internal abstract string DataServiceActionQuerySingleOfTStructureTemplate { get; } internal abstract string DataServiceActionQueryOfTStructureTemplate { get; } @@ -1077,6 +1091,12 @@ public abstract class ODataClientTemplate : TemplateBase } } private HashSet clrReferenceTypes; + internal string ClassAccessModifier { + get { + return this.context.MakeClassesInternal ? this.InternalAccessModifier : this.PublicAccessModifier; + } + } + /// /// Generates code for the OData client. /// @@ -3016,6 +3036,8 @@ public sealed class ODataClientCSharpTemplate : ODataClientTemplate internal override string GlobalPrefix { get {return "global::"; } } internal override string SystemTypeTypeName { get { return "global::System.Type"; } } internal override string AbstractModifier { get { return " abstract"; } } + internal override string PublicAccessModifier { get { return "public"; } } + internal override string InternalAccessModifier { get { return "internal"; } } internal override string DataServiceActionQueryTypeName { get { return "global::Microsoft.OData.Client.DataServiceActionQuery"; } } internal override string DataServiceActionQuerySingleOfTStructureTemplate { get { return "global::Microsoft.OData.Client.DataServiceActionQuerySingle<{0}>"; } } internal override string DataServiceActionQueryOfTStructureTemplate { get { return "global::Microsoft.OData.Client.DataServiceActionQuery<{0}>"; } } @@ -3137,7 +3159,7 @@ namespace <#= fullNamespace #> <#+ } #> - public partial class <#= fixedContainerName #> : global::Microsoft.OData.Client.DataServiceContext + <#= ClassAccessModifier #> partial class <#= fixedContainerName #> : global::Microsoft.OData.Client.DataServiceContext { <#+ } @@ -3149,7 +3171,7 @@ namespace <#= fullNamespace #> /// Initialize a new <#= containerName #> object. /// [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "<#=T4Version#>")] - public <#= fixedContainerName #>(global::System.Uri serviceRoot) : + <#= ClassAccessModifier #> <#= fixedContainerName #>(global::System.Uri serviceRoot) : base(serviceRoot, global::Microsoft.OData.Client.ODataProtocolVersion.V4) { <#+ @@ -3289,19 +3311,19 @@ namespace <#= fullNamespace #> /// /// Initialize a new <#= singleTypeName #> object. /// - public <#= singleTypeName #>(global::Microsoft.OData.Client.DataServiceContext context, string path) + <#= ClassAccessModifier #> <#= singleTypeName #>(global::Microsoft.OData.Client.DataServiceContext context, string path) : base(context, path) {} /// /// Initialize a new <#= singleTypeName #> object. /// - public <#= singleTypeName #>(global::Microsoft.OData.Client.DataServiceContext context, string path, bool isComposable) + <#= ClassAccessModifier #> <#= singleTypeName #>(global::Microsoft.OData.Client.DataServiceContext context, string path, bool isComposable) : base(context, path, isComposable) {} /// /// Initialize a new <#= singleTypeName #> object. /// - public <#= singleTypeName #>(<#= baseTypeName #> query) + <#= ClassAccessModifier #> <#= singleTypeName #>(<#= baseTypeName #> query) : base(query) {} <#+ @@ -3322,7 +3344,7 @@ namespace <#= fullNamespace #> <#+ } #> - public global::Microsoft.OData.Client.DataServiceQuery<<#= entitySetElementTypeName #>> <#= entitySetFixedName #> + <#= ClassAccessModifier #> global::Microsoft.OData.Client.DataServiceQuery<<#= entitySetElementTypeName #>> <#= entitySetFixedName #> { get { @@ -3364,7 +3386,7 @@ namespace <#= fullNamespace #> <#+ } #> - public <#= singletonElementTypeName #> <#= singletonFixedName #> + <#= ClassAccessModifier #> <#= singletonElementTypeName #> <#= singletonFixedName #> { get { @@ -3398,7 +3420,7 @@ namespace <#= fullNamespace #> /// There are no comments for <#= entitySetName #> in the schema. /// [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "<#=T4Version#>")] - public void AddTo<#= entitySetName #>(<#= typeName #> <#= parameterName #>) + <#= ClassAccessModifier #> void AddTo<#= entitySetName #>(<#= typeName #> <#= parameterName #>) { base.AddObject("<#= originalEntitySetName #>", <#= parameterName #>); } @@ -3435,7 +3457,7 @@ namespace <#= fullNamespace #> [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "<#=T4Version#>")] private const string Edmx = @"<#= escapedEdmxString #>"; [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "<#=T4Version#>")] - public static global::Microsoft.OData.Edm.IEdmModel GetInstance() + <#= ClassAccessModifier #> static global::Microsoft.OData.Edm.IEdmModel GetInstance() { return ParsedModel; } @@ -3560,7 +3582,7 @@ namespace <#= fullNamespace #> <#+ } #> - public<#= abstractModifier #> partial class <#= typeName #><#= baseTypeName #> + <#= ClassAccessModifier #><#= abstractModifier #> partial class <#= typeName #><#= baseTypeName #> { <#+ } @@ -3585,7 +3607,7 @@ namespace <#= fullNamespace #> { #> [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "<#=T4Version#>")] - public static <#= fixedTypeName #> Create<#= typeName #>(<#+ + <#= ClassAccessModifier #> static <#= fixedTypeName #> Create<#= typeName #>(<#+ } internal override void WriteParameterForStaticCreateMethod(string parameterTypeName, string parameterName, string parameterSeparater) @@ -3641,7 +3663,7 @@ namespace <#= fullNamespace #> <#+ } #> - public <#= propertyType #> <#= fixedPropertyName #> + <#= ClassAccessModifier #> <#= propertyType #> <#= fixedPropertyName #> { get { @@ -3676,7 +3698,7 @@ namespace <#= fullNamespace #> /// This event is raised when the value of the property is changed /// [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "<#=T4Version#>")] - public event global::System.ComponentModel.PropertyChangedEventHandler PropertyChanged; + <#= ClassAccessModifier #> event global::System.ComponentModel.PropertyChangedEventHandler PropertyChanged; /// /// The value of the property is changed /// @@ -3724,7 +3746,7 @@ namespace <#= fullNamespace #> <#+ } #> - public enum <#= enumName #><#= underlyingType #> + <#= ClassAccessModifier #> enum <#= enumName #><#= underlyingType #> { <#+ } @@ -3763,7 +3785,7 @@ namespace <#= fullNamespace #> <#+ } #> - public global::Microsoft.OData.Client.DataServiceQuery<<#= returnTypeName #>> <#= functionName #>(<#= parameters #><#= useEntityReference ? ", bool useEntityReference = false" : string.Empty #>) + <#= ClassAccessModifier #> global::Microsoft.OData.Client.DataServiceQuery<<#= returnTypeName #>> <#= functionName #>(<#= parameters #><#= useEntityReference ? ", bool useEntityReference = false" : string.Empty #>) { return this.CreateFunctionQuery<<#= returnTypeName #>>("", "<#= originalFunctionName #>", <#= isComposable.ToString().ToLower(CultureInfo.InvariantCulture) #><#= string.IsNullOrEmpty(parameterValues) ? string.Empty : ", " + parameterValues #>); } @@ -3784,7 +3806,7 @@ namespace <#= fullNamespace #> <#+ } #> - public <#= isReturnEntity ? returnTypeName + this.singleSuffix : string.Format(CultureInfo.InvariantCulture, this.DataServiceQuerySingleStructureTemplate, returnTypeName) #> <#= functionName #>(<#= parameters #><#= useEntityReference ? ", bool useEntityReference = false" : string.Empty #>) + <#= ClassAccessModifier #> <#= isReturnEntity ? returnTypeName + this.singleSuffix : string.Format(CultureInfo.InvariantCulture, this.DataServiceQuerySingleStructureTemplate, returnTypeName) #> <#= functionName #>(<#= parameters #><#= useEntityReference ? ", bool useEntityReference = false" : string.Empty #>) { return <#= isReturnEntity ? "new " + returnTypeName + this.singleSuffix + "(" : string.Empty #>this.CreateFunctionQuerySingle<<#= returnTypeName #>>("", "<#= originalFunctionName #>", <#= isComposable.ToString().ToLower(CultureInfo.InvariantCulture) #><#= string.IsNullOrEmpty(parameterValues) ? string.Empty : ", " + parameterValues #>)<#= isReturnEntity ? ")" : string.Empty #>; } @@ -3805,7 +3827,7 @@ namespace <#= fullNamespace #> <#+ } #> - public <#= hideBaseMethod ? this.OverloadsModifier : string.Empty #>global::Microsoft.OData.Client.DataServiceQuery<<#= returnTypeName #>> <#= functionName #>(<#= parameters #><#= useEntityReference ? ", bool useEntityReference = false" : string.Empty #>) + <#= ClassAccessModifier #> <#= hideBaseMethod ? this.OverloadsModifier : string.Empty #>global::Microsoft.OData.Client.DataServiceQuery<<#= returnTypeName #>> <#= functionName #>(<#= parameters #><#= useEntityReference ? ", bool useEntityReference = false" : string.Empty #>) { global::System.Uri requestUri; Context.TryGetUri(this, out requestUri); @@ -3828,7 +3850,7 @@ namespace <#= fullNamespace #> <#+ } #> - public <#= hideBaseMethod ? this.OverloadsModifier : string.Empty #> <#= isReturnEntity ? returnTypeName + this.singleSuffix : string.Format(CultureInfo.InvariantCulture, this.DataServiceQuerySingleStructureTemplate, returnTypeName) #> <#= functionName #>(<#= parameters #><#= useEntityReference ? ", bool useEntityReference = false" : string.Empty #>) + <#= ClassAccessModifier #> <#= hideBaseMethod ? this.OverloadsModifier : string.Empty #> <#= isReturnEntity ? returnTypeName + this.singleSuffix : string.Format(CultureInfo.InvariantCulture, this.DataServiceQuerySingleStructureTemplate, returnTypeName) #> <#= functionName #>(<#= parameters #><#= useEntityReference ? ", bool useEntityReference = false" : string.Empty #>) { global::System.Uri requestUri; Context.TryGetUri(this, out requestUri); @@ -3852,7 +3874,7 @@ namespace <#= fullNamespace #> <#+ } #> - public <#= returnTypeName #> <#= actionName #>(<#= parameters #>) + <#= ClassAccessModifier #> <#= returnTypeName #> <#= actionName #>(<#= parameters #>) { return new <#= returnTypeName #>(this, this.BaseUri.OriginalString.Trim('/') + "/<#= originalActionName #>"<#= string.IsNullOrEmpty(parameterValues) ? string.Empty : ", " + parameterValues #>); } @@ -3873,7 +3895,7 @@ namespace <#= fullNamespace #> <#+ } #> - public <#= hideBaseMethod ? this.OverloadsModifier : string.Empty #><#= returnTypeName #> <#= actionName #>(<#= parameters #>) + <#= ClassAccessModifier #> <#= hideBaseMethod ? this.OverloadsModifier : string.Empty #><#= returnTypeName #> <#= actionName #>(<#= parameters #>) { global::Microsoft.OData.Client.EntityDescriptor resource = Context.EntityTracker.TryGetEntityDescriptor(this); if (resource == null) @@ -3892,7 +3914,7 @@ namespace <#= fullNamespace #> /// /// Class containing all extension methods /// - public static class ExtensionMethods + <#= ClassAccessModifier #> static class ExtensionMethods { <#+ } @@ -3912,7 +3934,7 @@ namespace <#= fullNamespace #> /// /// source entity set /// dictionary with the names and values of keys - public static <#= returnTypeName #> ByKey(this global::Microsoft.OData.Client.DataServiceQuery<<#= entityTypeName #>> source, global::System.Collections.Generic.Dictionary keys) + <#= ClassAccessModifier #> static <#= returnTypeName #> ByKey(this global::Microsoft.OData.Client.DataServiceQuery<<#= entityTypeName #>> source, global::System.Collections.Generic.Dictionary keys) { return new <#= returnTypeName #>(source.Context, source.GetKeyPath(global::Microsoft.OData.Client.Serializer.GetKeyString(source.Context, keys))); } @@ -3928,7 +3950,7 @@ namespace <#= fullNamespace #> <#+ } #> - public static <#= returnTypeName #> ByKey(this global::Microsoft.OData.Client.DataServiceQuery<<#= entityTypeName #>> source, + <#= ClassAccessModifier #> static <#= returnTypeName #> ByKey(this global::Microsoft.OData.Client.DataServiceQuery<<#= entityTypeName #>> source, <#= keyParameters #>) { global::System.Collections.Generic.Dictionary keys = new global::System.Collections.Generic.Dictionary @@ -3947,7 +3969,7 @@ namespace <#= fullNamespace #> /// Cast an entity of type <#= baseTypeName #> to its derived type <#= derivedTypeFullName #> /// /// source entity - public static <#= returnTypeName #> CastTo<#= derivedTypeName #>(this global::Microsoft.OData.Client.DataServiceQuerySingle<<#= baseTypeName #>> source) + <#= ClassAccessModifier #> static <#= returnTypeName #> CastTo<#= derivedTypeName #>(this global::Microsoft.OData.Client.DataServiceQuerySingle<<#= baseTypeName #>> source) { global::Microsoft.OData.Client.DataServiceQuerySingle<<#= derivedTypeFullName #>> query = source.CastTo<<#= derivedTypeFullName #>>(); return new <#= returnTypeName #>(source.Context, query.GetPath(null)); @@ -3969,7 +3991,7 @@ namespace <#= fullNamespace #> <#+ } #> - public static <#= isReturnEntity ? returnTypeName + this.singleSuffix : string.Format(CultureInfo.InvariantCulture, this.DataServiceQuerySingleStructureTemplate, returnTypeName) #> <#= functionName #>(this <#= boundTypeName #> source<#= string.IsNullOrEmpty(parameters) ? string.Empty : ", " + parameters #><#= useEntityReference ? ", bool useEntityReference = false" : string.Empty #>) + <#= ClassAccessModifier #> static <#= isReturnEntity ? returnTypeName + this.singleSuffix : string.Format(CultureInfo.InvariantCulture, this.DataServiceQuerySingleStructureTemplate, returnTypeName) #> <#= functionName #>(this <#= boundTypeName #> source<#= string.IsNullOrEmpty(parameters) ? string.Empty : ", " + parameters #><#= useEntityReference ? ", bool useEntityReference = false" : string.Empty #>) { if (!source.IsComposable) { @@ -3995,7 +4017,7 @@ namespace <#= fullNamespace #> <#+ } #> - public static global::Microsoft.OData.Client.DataServiceQuery<<#= returnTypeName #>> <#= functionName #>(this <#= boundTypeName #> source<#= string.IsNullOrEmpty(parameters) ? string.Empty : ", " + parameters #><#= useEntityReference ? ", bool useEntityReference = true" : string.Empty #>) + <#= ClassAccessModifier #> static global::Microsoft.OData.Client.DataServiceQuery<<#= returnTypeName #>> <#= functionName #>(this <#= boundTypeName #> source<#= string.IsNullOrEmpty(parameters) ? string.Empty : ", " + parameters #><#= useEntityReference ? ", bool useEntityReference = true" : string.Empty #>) { if (!source.IsComposable) { @@ -4021,7 +4043,7 @@ namespace <#= fullNamespace #> <#+ } #> - public static <#= returnTypeName #> <#= actionName #>(this <#= boundSourceType #> source<#= string.IsNullOrEmpty(parameters) ? string.Empty : ", " + parameters #>) + <#= ClassAccessModifier #> static <#= returnTypeName #> <#= actionName #>(this <#= boundSourceType #> source<#= string.IsNullOrEmpty(parameters) ? string.Empty : ", " + parameters #>) { if (!source.IsComposable) { @@ -4055,6 +4077,8 @@ public sealed class ODataClientVBTemplate : ODataClientTemplate internal override string GlobalPrefix { get { return string.Empty; } } internal override string SystemTypeTypeName { get { return "Global.System.Type"; } } internal override string AbstractModifier { get { return " MustInherit"; } } + internal override string PublicAccessModifier { get { return "Public"; } } + internal override string InternalAccessModifier { get { return "Friend"; } } internal override string DataServiceActionQueryTypeName { get { return "Global.Microsoft.OData.Client.DataServiceActionQuery"; } } internal override string DataServiceActionQuerySingleOfTStructureTemplate { get { return "Global.Microsoft.OData.Client.DataServiceActionQuerySingle(Of {0})"; } } internal override string DataServiceActionQueryOfTStructureTemplate { get { return "Global.Microsoft.OData.Client.DataServiceActionQuery(Of {0})"; } } @@ -4188,7 +4212,7 @@ Namespace <#= fullNamespace #> <#+ } #> - Partial Public Class <#= fixedContainerName #> + Partial <#= ClassAccessModifier #> Class <#= fixedContainerName #> Inherits Global.Microsoft.OData.Client.DataServiceContext <#+ } @@ -4602,7 +4626,7 @@ Namespace <#= fullNamespace #> <#+ } #> - Partial Public<#= abstractModifier #> Class <#= typeName #><#= baseTypeName #> + Partial <#= ClassAccessModifier #><#= abstractModifier #> Class <#= typeName #><#= baseTypeName #> <#+ } From 642304e6e13a81b9f8678d93981bf93c9535d5f2 Mon Sep 17 00:00:00 2001 From: Clement Habinshuti Date: Thu, 16 Jan 2020 18:03:57 +0300 Subject: [PATCH 02/24] Remove internal modifier from generated methods and properties --- .../Templates/ODataT4CodeGenerator.ttinclude | 46 +++++++++---------- 1 file changed, 23 insertions(+), 23 deletions(-) diff --git a/ODataConnectedService/src/Templates/ODataT4CodeGenerator.ttinclude b/ODataConnectedService/src/Templates/ODataT4CodeGenerator.ttinclude index 89761d0..d7a498c 100644 --- a/ODataConnectedService/src/Templates/ODataT4CodeGenerator.ttinclude +++ b/ODataConnectedService/src/Templates/ODataT4CodeGenerator.ttinclude @@ -3171,7 +3171,7 @@ namespace <#= fullNamespace #> /// Initialize a new <#= containerName #> object. /// [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "<#=T4Version#>")] - <#= ClassAccessModifier #> <#= fixedContainerName #>(global::System.Uri serviceRoot) : + public <#= fixedContainerName #>(global::System.Uri serviceRoot) : base(serviceRoot, global::Microsoft.OData.Client.ODataProtocolVersion.V4) { <#+ @@ -3311,19 +3311,19 @@ namespace <#= fullNamespace #> /// /// Initialize a new <#= singleTypeName #> object. /// - <#= ClassAccessModifier #> <#= singleTypeName #>(global::Microsoft.OData.Client.DataServiceContext context, string path) + public <#= singleTypeName #>(global::Microsoft.OData.Client.DataServiceContext context, string path) : base(context, path) {} /// /// Initialize a new <#= singleTypeName #> object. /// - <#= ClassAccessModifier #> <#= singleTypeName #>(global::Microsoft.OData.Client.DataServiceContext context, string path, bool isComposable) + public <#= singleTypeName #>(global::Microsoft.OData.Client.DataServiceContext context, string path, bool isComposable) : base(context, path, isComposable) {} /// /// Initialize a new <#= singleTypeName #> object. /// - <#= ClassAccessModifier #> <#= singleTypeName #>(<#= baseTypeName #> query) + public <#= singleTypeName #>(<#= baseTypeName #> query) : base(query) {} <#+ @@ -3344,7 +3344,7 @@ namespace <#= fullNamespace #> <#+ } #> - <#= ClassAccessModifier #> global::Microsoft.OData.Client.DataServiceQuery<<#= entitySetElementTypeName #>> <#= entitySetFixedName #> + public global::Microsoft.OData.Client.DataServiceQuery<<#= entitySetElementTypeName #>> <#= entitySetFixedName #> { get { @@ -3386,7 +3386,7 @@ namespace <#= fullNamespace #> <#+ } #> - <#= ClassAccessModifier #> <#= singletonElementTypeName #> <#= singletonFixedName #> + public <#= singletonElementTypeName #> <#= singletonFixedName #> { get { @@ -3420,7 +3420,7 @@ namespace <#= fullNamespace #> /// There are no comments for <#= entitySetName #> in the schema. /// [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "<#=T4Version#>")] - <#= ClassAccessModifier #> void AddTo<#= entitySetName #>(<#= typeName #> <#= parameterName #>) + public void AddTo<#= entitySetName #>(<#= typeName #> <#= parameterName #>) { base.AddObject("<#= originalEntitySetName #>", <#= parameterName #>); } @@ -3457,7 +3457,7 @@ namespace <#= fullNamespace #> [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "<#=T4Version#>")] private const string Edmx = @"<#= escapedEdmxString #>"; [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "<#=T4Version#>")] - <#= ClassAccessModifier #> static global::Microsoft.OData.Edm.IEdmModel GetInstance() + public static global::Microsoft.OData.Edm.IEdmModel GetInstance() { return ParsedModel; } @@ -3607,7 +3607,7 @@ namespace <#= fullNamespace #> { #> [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "<#=T4Version#>")] - <#= ClassAccessModifier #> static <#= fixedTypeName #> Create<#= typeName #>(<#+ + public static <#= fixedTypeName #> Create<#= typeName #>(<#+ } internal override void WriteParameterForStaticCreateMethod(string parameterTypeName, string parameterName, string parameterSeparater) @@ -3663,7 +3663,7 @@ namespace <#= fullNamespace #> <#+ } #> - <#= ClassAccessModifier #> <#= propertyType #> <#= fixedPropertyName #> + public <#= propertyType #> <#= fixedPropertyName #> { get { @@ -3698,7 +3698,7 @@ namespace <#= fullNamespace #> /// This event is raised when the value of the property is changed /// [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "<#=T4Version#>")] - <#= ClassAccessModifier #> event global::System.ComponentModel.PropertyChangedEventHandler PropertyChanged; + public event global::System.ComponentModel.PropertyChangedEventHandler PropertyChanged; /// /// The value of the property is changed /// @@ -3785,7 +3785,7 @@ namespace <#= fullNamespace #> <#+ } #> - <#= ClassAccessModifier #> global::Microsoft.OData.Client.DataServiceQuery<<#= returnTypeName #>> <#= functionName #>(<#= parameters #><#= useEntityReference ? ", bool useEntityReference = false" : string.Empty #>) + public global::Microsoft.OData.Client.DataServiceQuery<<#= returnTypeName #>> <#= functionName #>(<#= parameters #><#= useEntityReference ? ", bool useEntityReference = false" : string.Empty #>) { return this.CreateFunctionQuery<<#= returnTypeName #>>("", "<#= originalFunctionName #>", <#= isComposable.ToString().ToLower(CultureInfo.InvariantCulture) #><#= string.IsNullOrEmpty(parameterValues) ? string.Empty : ", " + parameterValues #>); } @@ -3806,7 +3806,7 @@ namespace <#= fullNamespace #> <#+ } #> - <#= ClassAccessModifier #> <#= isReturnEntity ? returnTypeName + this.singleSuffix : string.Format(CultureInfo.InvariantCulture, this.DataServiceQuerySingleStructureTemplate, returnTypeName) #> <#= functionName #>(<#= parameters #><#= useEntityReference ? ", bool useEntityReference = false" : string.Empty #>) + public <#= isReturnEntity ? returnTypeName + this.singleSuffix : string.Format(CultureInfo.InvariantCulture, this.DataServiceQuerySingleStructureTemplate, returnTypeName) #> <#= functionName #>(<#= parameters #><#= useEntityReference ? ", bool useEntityReference = false" : string.Empty #>) { return <#= isReturnEntity ? "new " + returnTypeName + this.singleSuffix + "(" : string.Empty #>this.CreateFunctionQuerySingle<<#= returnTypeName #>>("", "<#= originalFunctionName #>", <#= isComposable.ToString().ToLower(CultureInfo.InvariantCulture) #><#= string.IsNullOrEmpty(parameterValues) ? string.Empty : ", " + parameterValues #>)<#= isReturnEntity ? ")" : string.Empty #>; } @@ -3827,7 +3827,7 @@ namespace <#= fullNamespace #> <#+ } #> - <#= ClassAccessModifier #> <#= hideBaseMethod ? this.OverloadsModifier : string.Empty #>global::Microsoft.OData.Client.DataServiceQuery<<#= returnTypeName #>> <#= functionName #>(<#= parameters #><#= useEntityReference ? ", bool useEntityReference = false" : string.Empty #>) + public <#= hideBaseMethod ? this.OverloadsModifier : string.Empty #>global::Microsoft.OData.Client.DataServiceQuery<<#= returnTypeName #>> <#= functionName #>(<#= parameters #><#= useEntityReference ? ", bool useEntityReference = false" : string.Empty #>) { global::System.Uri requestUri; Context.TryGetUri(this, out requestUri); @@ -3850,7 +3850,7 @@ namespace <#= fullNamespace #> <#+ } #> - <#= ClassAccessModifier #> <#= hideBaseMethod ? this.OverloadsModifier : string.Empty #> <#= isReturnEntity ? returnTypeName + this.singleSuffix : string.Format(CultureInfo.InvariantCulture, this.DataServiceQuerySingleStructureTemplate, returnTypeName) #> <#= functionName #>(<#= parameters #><#= useEntityReference ? ", bool useEntityReference = false" : string.Empty #>) + public <#= hideBaseMethod ? this.OverloadsModifier : string.Empty #> <#= isReturnEntity ? returnTypeName + this.singleSuffix : string.Format(CultureInfo.InvariantCulture, this.DataServiceQuerySingleStructureTemplate, returnTypeName) #> <#= functionName #>(<#= parameters #><#= useEntityReference ? ", bool useEntityReference = false" : string.Empty #>) { global::System.Uri requestUri; Context.TryGetUri(this, out requestUri); @@ -3874,7 +3874,7 @@ namespace <#= fullNamespace #> <#+ } #> - <#= ClassAccessModifier #> <#= returnTypeName #> <#= actionName #>(<#= parameters #>) + public <#= returnTypeName #> <#= actionName #>(<#= parameters #>) { return new <#= returnTypeName #>(this, this.BaseUri.OriginalString.Trim('/') + "/<#= originalActionName #>"<#= string.IsNullOrEmpty(parameterValues) ? string.Empty : ", " + parameterValues #>); } @@ -3895,7 +3895,7 @@ namespace <#= fullNamespace #> <#+ } #> - <#= ClassAccessModifier #> <#= hideBaseMethod ? this.OverloadsModifier : string.Empty #><#= returnTypeName #> <#= actionName #>(<#= parameters #>) + public <#= hideBaseMethod ? this.OverloadsModifier : string.Empty #><#= returnTypeName #> <#= actionName #>(<#= parameters #>) { global::Microsoft.OData.Client.EntityDescriptor resource = Context.EntityTracker.TryGetEntityDescriptor(this); if (resource == null) @@ -3934,7 +3934,7 @@ namespace <#= fullNamespace #> /// /// source entity set /// dictionary with the names and values of keys - <#= ClassAccessModifier #> static <#= returnTypeName #> ByKey(this global::Microsoft.OData.Client.DataServiceQuery<<#= entityTypeName #>> source, global::System.Collections.Generic.Dictionary keys) + public static <#= returnTypeName #> ByKey(this global::Microsoft.OData.Client.DataServiceQuery<<#= entityTypeName #>> source, global::System.Collections.Generic.Dictionary keys) { return new <#= returnTypeName #>(source.Context, source.GetKeyPath(global::Microsoft.OData.Client.Serializer.GetKeyString(source.Context, keys))); } @@ -3950,7 +3950,7 @@ namespace <#= fullNamespace #> <#+ } #> - <#= ClassAccessModifier #> static <#= returnTypeName #> ByKey(this global::Microsoft.OData.Client.DataServiceQuery<<#= entityTypeName #>> source, + public static <#= returnTypeName #> ByKey(this global::Microsoft.OData.Client.DataServiceQuery<<#= entityTypeName #>> source, <#= keyParameters #>) { global::System.Collections.Generic.Dictionary keys = new global::System.Collections.Generic.Dictionary @@ -3969,7 +3969,7 @@ namespace <#= fullNamespace #> /// Cast an entity of type <#= baseTypeName #> to its derived type <#= derivedTypeFullName #> /// /// source entity - <#= ClassAccessModifier #> static <#= returnTypeName #> CastTo<#= derivedTypeName #>(this global::Microsoft.OData.Client.DataServiceQuerySingle<<#= baseTypeName #>> source) + public static <#= returnTypeName #> CastTo<#= derivedTypeName #>(this global::Microsoft.OData.Client.DataServiceQuerySingle<<#= baseTypeName #>> source) { global::Microsoft.OData.Client.DataServiceQuerySingle<<#= derivedTypeFullName #>> query = source.CastTo<<#= derivedTypeFullName #>>(); return new <#= returnTypeName #>(source.Context, query.GetPath(null)); @@ -3991,7 +3991,7 @@ namespace <#= fullNamespace #> <#+ } #> - <#= ClassAccessModifier #> static <#= isReturnEntity ? returnTypeName + this.singleSuffix : string.Format(CultureInfo.InvariantCulture, this.DataServiceQuerySingleStructureTemplate, returnTypeName) #> <#= functionName #>(this <#= boundTypeName #> source<#= string.IsNullOrEmpty(parameters) ? string.Empty : ", " + parameters #><#= useEntityReference ? ", bool useEntityReference = false" : string.Empty #>) + public static <#= isReturnEntity ? returnTypeName + this.singleSuffix : string.Format(CultureInfo.InvariantCulture, this.DataServiceQuerySingleStructureTemplate, returnTypeName) #> <#= functionName #>(this <#= boundTypeName #> source<#= string.IsNullOrEmpty(parameters) ? string.Empty : ", " + parameters #><#= useEntityReference ? ", bool useEntityReference = false" : string.Empty #>) { if (!source.IsComposable) { @@ -4017,7 +4017,7 @@ namespace <#= fullNamespace #> <#+ } #> - <#= ClassAccessModifier #> static global::Microsoft.OData.Client.DataServiceQuery<<#= returnTypeName #>> <#= functionName #>(this <#= boundTypeName #> source<#= string.IsNullOrEmpty(parameters) ? string.Empty : ", " + parameters #><#= useEntityReference ? ", bool useEntityReference = true" : string.Empty #>) + public static global::Microsoft.OData.Client.DataServiceQuery<<#= returnTypeName #>> <#= functionName #>(this <#= boundTypeName #> source<#= string.IsNullOrEmpty(parameters) ? string.Empty : ", " + parameters #><#= useEntityReference ? ", bool useEntityReference = true" : string.Empty #>) { if (!source.IsComposable) { @@ -4043,7 +4043,7 @@ namespace <#= fullNamespace #> <#+ } #> - <#= ClassAccessModifier #> static <#= returnTypeName #> <#= actionName #>(this <#= boundSourceType #> source<#= string.IsNullOrEmpty(parameters) ? string.Empty : ", " + parameters #>) + public static <#= returnTypeName #> <#= actionName #>(this <#= boundSourceType #> source<#= string.IsNullOrEmpty(parameters) ? string.Empty : ", " + parameters #>) { if (!source.IsComposable) { From e1ee353e90cc52a76b6b38ead2e91871a3487a22 Mon Sep 17 00:00:00 2001 From: Clement Habinshuti Date: Thu, 16 Jan 2020 18:09:42 +0300 Subject: [PATCH 03/24] Use class access modifier on VB enums and extension classes --- .../src/Templates/ODataT4CodeGenerator.ttinclude | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ODataConnectedService/src/Templates/ODataT4CodeGenerator.ttinclude b/ODataConnectedService/src/Templates/ODataT4CodeGenerator.ttinclude index d7a498c..6f96dcb 100644 --- a/ODataConnectedService/src/Templates/ODataT4CodeGenerator.ttinclude +++ b/ODataConnectedService/src/Templates/ODataT4CodeGenerator.ttinclude @@ -4792,7 +4792,7 @@ Namespace <#= fullNamespace #> <#+ } #> - Public Enum <#= enumName #><#= underlyingType #> + <#= ClassAccessModifier #> Enum <#= enumName #><#= underlyingType #> <#+ } @@ -4951,7 +4951,7 @@ Namespace <#= fullNamespace #> ''' ''' Class containing all extension methods ''' - Public Module ExtensionMethods + <#= ClassAccessModifier #> Module ExtensionMethods <#+ } From cabbddee087a8befd4f3b0d1d2df372e9dec373f Mon Sep 17 00:00:00 2001 From: Clement Habinshuti Date: Fri, 17 Jan 2020 09:44:06 +0300 Subject: [PATCH 04/24] Add UI option to enable generating types as internal --- .../src/CodeGeneration/V4CodeGenDescriptor.cs | 3 +- .../src/Models/ServiceConfiguration.cs | 1 + .../src/ODataConnectedServiceWizard.cs | 2 + .../src/Templates/ODataT4CodeGenerator.cs | 123 +++++++++++++++--- .../src/Templates/ODataT4CodeGenerator.tt | 4 + .../Templates/ODataT4CodeGenerator.ttinclude | 45 ++++++- .../ViewModels/AdvancedSettingsViewModel.cs | 2 + .../src/Views/AdvancedSettings.xaml | 4 + 8 files changed, 164 insertions(+), 20 deletions(-) diff --git a/ODataConnectedService/src/CodeGeneration/V4CodeGenDescriptor.cs b/ODataConnectedService/src/CodeGeneration/V4CodeGenDescriptor.cs index c42814c..0bf8471 100644 --- a/ODataConnectedService/src/CodeGeneration/V4CodeGenDescriptor.cs +++ b/ODataConnectedService/src/CodeGeneration/V4CodeGenDescriptor.cs @@ -66,7 +66,7 @@ private async Task AddT4File() text = Regex.Replace(text, "(public const string TargetLanguage = )\"OutputLanguage\";", "$1\"CSharp\";"); text = Regex.Replace(text, "(public const bool EnableNamingAlias = )true;", "$1" + this.ServiceConfiguration.EnableNamingAlias.ToString().ToLower(CultureInfo.InvariantCulture) + ";"); text = Regex.Replace(text, "(public const bool IgnoreUnexpectedElementsAndAttributes = )true;", "$1" + this.ServiceConfiguration.IgnoreUnexpectedElementsAndAttributes.ToString().ToLower(CultureInfo.InvariantCulture) + ";"); - + text = Regex.Replace(text, "(public const bool MakeTypesInternal = )false;", "$1" + ServiceConfiguration.MakeTypesInternal.ToString().ToLower(CultureInfo.InvariantCulture) + ";"); await writer.WriteAsync(text); await writer.FlushAsync(); } @@ -85,6 +85,7 @@ private async Task AddGeneratedCSharpCode() t4CodeGenerator.IgnoreUnexpectedElementsAndAttributes = this.ServiceConfiguration.IgnoreUnexpectedElementsAndAttributes; t4CodeGenerator.EnableNamingAlias = this.ServiceConfiguration.EnableNamingAlias; t4CodeGenerator.NamespacePrefix = this.ServiceConfiguration.NamespacePrefix; + t4CodeGenerator.MakeTypesInternal = ServiceConfiguration.MakeTypesInternal; string tempFile = Path.GetTempFileName(); diff --git a/ODataConnectedService/src/Models/ServiceConfiguration.cs b/ODataConnectedService/src/Models/ServiceConfiguration.cs index 56bcc7c..b9a6a2b 100644 --- a/ODataConnectedService/src/Models/ServiceConfiguration.cs +++ b/ODataConnectedService/src/Models/ServiceConfiguration.cs @@ -14,6 +14,7 @@ internal class ServiceConfiguration public bool UseNameSpacePrefix { get; set; } public string NamespacePrefix { get; set; } public bool UseDataServiceCollection { get; set; } + public bool MakeTypesInternal { get; set; } } internal class ServiceConfigurationV4 : ServiceConfiguration diff --git a/ODataConnectedService/src/ODataConnectedServiceWizard.cs b/ODataConnectedService/src/ODataConnectedServiceWizard.cs index dfff4c0..185ddcd 100644 --- a/ODataConnectedService/src/ODataConnectedServiceWizard.cs +++ b/ODataConnectedService/src/ODataConnectedServiceWizard.cs @@ -77,6 +77,7 @@ public ODataConnectedServiceWizard(ConnectedServiceProviderContext context) advancedSettingsViewModel.UseNamespacePrefix = serviceConfig.UseNameSpacePrefix; advancedSettingsViewModel.NamespacePrefix = serviceConfig.NamespacePrefix; advancedSettingsViewModel.UseDataServiceCollection = serviceConfig.UseDataServiceCollection; + advancedSettingsViewModel.MakeTypesInternal = serviceConfig.MakeTypesInternal; if (serviceConfig.EdmxVersion == Common.Constants.EdmxVersion4) { @@ -132,6 +133,7 @@ private ServiceConfiguration CreateServiceConfiguration() serviceConfiguration.UseDataServiceCollection = AdvancedSettingsViewModel.UseDataServiceCollection; serviceConfiguration.GeneratedFileNamePrefix = AdvancedSettingsViewModel.GeneratedFileName; serviceConfiguration.UseNameSpacePrefix = AdvancedSettingsViewModel.UseNamespacePrefix; + serviceConfiguration.MakeTypesInternal = AdvancedSettingsViewModel.MakeTypesInternal; if (AdvancedSettingsViewModel.UseNamespacePrefix && !string.IsNullOrEmpty(AdvancedSettingsViewModel.NamespacePrefix)) { serviceConfiguration.NamespacePrefix = AdvancedSettingsViewModel.NamespacePrefix; diff --git a/ODataConnectedService/src/Templates/ODataT4CodeGenerator.cs b/ODataConnectedService/src/Templates/ODataT4CodeGenerator.cs index 554bb28..acae83d 100644 --- a/ODataConnectedService/src/Templates/ODataT4CodeGenerator.cs +++ b/ODataConnectedService/src/Templates/ODataT4CodeGenerator.cs @@ -61,7 +61,8 @@ The above copyright notice and this permission notice shall be included in all c UseDataServiceCollection = this.UseDataServiceCollection, TargetLanguage = this.TargetLanguage, EnableNamingAlias = this.EnableNamingAlias, - IgnoreUnexpectedElementsAndAttributes = this.IgnoreUnexpectedElementsAndAttributes + IgnoreUnexpectedElementsAndAttributes = this.IgnoreUnexpectedElementsAndAttributes, + MakeTypesInternal = this.MakeTypesInternal }; } else @@ -77,7 +78,8 @@ The above copyright notice and this permission notice shall be included in all c UseDataServiceCollection = this.UseDataServiceCollection, TargetLanguage = this.TargetLanguage, EnableNamingAlias = this.EnableNamingAlias, - IgnoreUnexpectedElementsAndAttributes = this.IgnoreUnexpectedElementsAndAttributes + IgnoreUnexpectedElementsAndAttributes = this.IgnoreUnexpectedElementsAndAttributes, + MakeTypesInternal = this.MakeTypesInternal }; } @@ -150,6 +152,10 @@ public static class Configuration // This flag indicates whether to ignore unexpected elements and attributes in the metadata document and generate // the client code if any. The value must be set to true or false. public const bool IgnoreUnexpectedElementsAndAttributes = true; + + // If set to true, generated types will have an "internal" class modifier ("Friend" in VB) instead of "public" + // thereby making them invisible outside the assembly + public const bool MakeTypesInternal = false; } public static class Customization @@ -237,7 +243,7 @@ public string MetadataDocumentUri { value = uri.Scheme + "://" + uri.Authority + uri.AbsolutePath; value = value.TrimEnd('/'); - if (!value.EndsWith("$metadata", StringComparison.CurrentCulture)) + if (!value.EndsWith("$metadata")) { value += "/$metadata"; } @@ -321,6 +327,16 @@ public bool IgnoreUnexpectedElementsAndAttributes set; } +/// +/// true to use the "internal" access modifier ("Friend" in VB) on generated types, +/// otherwise "public" is used +/// +public bool MakeTypesInternal +{ + get; + set; +} + /// /// Generate code targeting a specific .Net Framework language. /// @@ -413,6 +429,26 @@ public void ValidateAndSetIgnoreUnexpectedElementsAndAttributesFromString(string this.IgnoreUnexpectedElementsAndAttributes = boolValue; } +/// +/// Set the MakeTypesInternal property with the given value. +/// +/// The value to set. +public void ValidateAndSetMakeTypesInternalFromString(string stringValue) +{ + bool boolValue; + if (!bool.TryParse(stringValue, out boolValue)) + { + // ******************************************************************************************************** + // To fix this error, if the current text transformation is run by the TextTemplatingFileGenerator + // custom tool inside Visual Studio, update the .odata.config file in the project with a valid parameter + // value then hit Ctrl-S to save the .tt file to refresh the code generation. + // ******************************************************************************************************** + throw new ArgumentException(string.Format(CultureInfo.InvariantCulture, "The value \"{0}\" cannot be assigned to the MakeTypesInternal parameter because it is not a valid boolean value.", stringValue)); + } + + this.MakeTypesInternal = boolValue; +} + /// /// Reads the parameter values from the Configuration class and applies them. /// @@ -424,6 +460,7 @@ private void ApplyParametersFromConfigurationClass() this.ValidateAndSetTargetLanguageFromString(Configuration.TargetLanguage); this.EnableNamingAlias = Configuration.EnableNamingAlias; this.IgnoreUnexpectedElementsAndAttributes = Configuration.IgnoreUnexpectedElementsAndAttributes; + this.MakeTypesInternal = Configuration.MakeTypesInternal; } /// @@ -471,6 +508,12 @@ private void ApplyParametersFromCommandLine() { this.ValidateAndSetIgnoreUnexpectedElementsAndAttributesFromString(ignoreUnexpectedElementsAndAttributes); } + + string makeTypesInternal = this.Host.ResolveParameterValue("notempty", "notempty", "MakeTypesInternal"); + if (!string.IsNullOrEmpty(makeTypesInternal)) + { + this.ValidateAndSetMakeTypesInternalFromString(makeTypesInternal); + } } /// @@ -780,6 +823,16 @@ public bool UseDataServiceCollection get; set; } + + /// + /// true to use internal access modifier for generated classes, otherwise they will be made public. + /// This is useful if you don't want the generated classes to be visible outside the assembly + /// + public bool MakeTypesInternal + { + get; + set; + } /// /// Specifies which specific .Net Framework language the generated code will target. @@ -1040,6 +1093,8 @@ public ODataClientTemplate(CodeGenerationContext context) internal abstract string GlobalPrefix { get; } internal abstract string SystemTypeTypeName { get; } internal abstract string AbstractModifier { get; } + internal abstract string PublicAccessModifier { get; } + internal abstract string InternalAccessModifier { get; } internal abstract string DataServiceActionQueryTypeName { get; } internal abstract string DataServiceActionQuerySingleOfTStructureTemplate { get; } internal abstract string DataServiceActionQueryOfTStructureTemplate { get; } @@ -1185,6 +1240,12 @@ internal HashSet ClrReferenceTypes { get { } } private HashSet clrReferenceTypes; + internal string ClassAccessModifier { + get { + return this.context.MakeTypesInternal ? this.InternalAccessModifier : this.PublicAccessModifier; + } + } + /// /// Generates code for the OData client. /// @@ -2455,14 +2516,14 @@ public void WriteLine(string textToAppend) /// public void Write(string format, params object[] args) { - this.Write(string.Format(global::System.Globalization.CultureInfo.CurrentCulture, format, args)); + this.Write(string.Format(CultureInfo.InvariantCulture, format, args)); } /// /// Write formatted text directly into the generated output /// public void WriteLine(string format, params object[] args) { - this.WriteLine(string.Format(global::System.Globalization.CultureInfo.CurrentCulture, format, args)); + this.WriteLine(string.Format(CultureInfo.InvariantCulture, format, args)); } /// /// Raise an error @@ -3124,6 +3185,8 @@ public ODataClientCSharpTemplate(CodeGenerationContext context) internal override string GlobalPrefix { get {return "global::"; } } internal override string SystemTypeTypeName { get { return "global::System.Type"; } } internal override string AbstractModifier { get { return " abstract"; } } + internal override string PublicAccessModifier { get { return "public"; } } + internal override string InternalAccessModifier { get { return "internal"; } } internal override string DataServiceActionQueryTypeName { get { return "global::Microsoft.OData.Client.DataServiceActionQuery"; } } internal override string DataServiceActionQuerySingleOfTStructureTemplate { get { return "global::Microsoft.OData.Client.DataServiceActionQuerySingle<{0}>"; } } internal override string DataServiceActionQueryOfTStructureTemplate { get { return "global::Microsoft.OData.Client.DataServiceActionQuery<{0}>"; } } @@ -3262,7 +3325,11 @@ internal override void WriteClassStartForEntityContainer(string originalContaine } -this.Write(" public partial class "); +this.Write(" "); + +this.Write(this.ToStringHelper.ToStringWithCulture(ClassAccessModifier)); + +this.Write(" partial class "); this.Write(this.ToStringHelper.ToStringWithCulture(fixedContainerName)); @@ -3955,7 +4022,9 @@ internal override void WriteClassStartForStructuredType(string abstractModifier, } -this.Write(" public"); +this.Write(" "); + +this.Write(this.ToStringHelper.ToStringWithCulture(ClassAccessModifier)); this.Write(this.ToStringHelper.ToStringWithCulture(abstractModifier)); @@ -4274,7 +4343,11 @@ internal override void WriteEnumDeclaration(string enumName, string originalEnum } -this.Write(" public enum "); +this.Write(" "); + +this.Write(this.ToStringHelper.ToStringWithCulture(ClassAccessModifier)); + +this.Write(" enum "); this.Write(this.ToStringHelper.ToStringWithCulture(enumName)); @@ -4699,7 +4772,11 @@ internal override void WriteExtensionMethodsStart() { this.Write(" /// \r\n /// Class containing all extension methods\r\n /// \r\n public static class ExtensionMethods\r\n {\r\n"); + "ary>\r\n "); + +this.Write(this.ToStringHelper.ToStringWithCulture(ClassAccessModifier)); + +this.Write(" static class ExtensionMethods\r\n {\r\n"); } @@ -5060,6 +5137,8 @@ public ODataClientVBTemplate(CodeGenerationContext context) internal override string GlobalPrefix { get { return string.Empty; } } internal override string SystemTypeTypeName { get { return "Global.System.Type"; } } internal override string AbstractModifier { get { return " MustInherit"; } } + internal override string PublicAccessModifier { get { return "Public"; } } + internal override string InternalAccessModifier { get { return "Friend"; } } internal override string DataServiceActionQueryTypeName { get { return "Global.Microsoft.OData.Client.DataServiceActionQuery"; } } internal override string DataServiceActionQuerySingleOfTStructureTemplate { get { return "Global.Microsoft.OData.Client.DataServiceActionQuerySingle(Of {0})"; } } internal override string DataServiceActionQueryOfTStructureTemplate { get { return "Global.Microsoft.OData.Client.DataServiceActionQuery(Of {0})"; } } @@ -5215,7 +5294,11 @@ internal override void WriteClassStartForEntityContainer(string originalContaine } -this.Write(" Partial Public Class "); +this.Write(" Partial "); + +this.Write(this.ToStringHelper.ToStringWithCulture(ClassAccessModifier)); + +this.Write(" Class "); this.Write(this.ToStringHelper.ToStringWithCulture(fixedContainerName)); @@ -5943,7 +6026,9 @@ internal override void WriteClassStartForStructuredType(string abstractModifier, } -this.Write(" Partial Public"); +this.Write(" Partial "); + +this.Write(this.ToStringHelper.ToStringWithCulture(ClassAccessModifier)); this.Write(this.ToStringHelper.ToStringWithCulture(abstractModifier)); @@ -6272,7 +6357,11 @@ internal override void WriteEnumDeclaration(string enumName, string originalEnum } -this.Write(" Public Enum "); +this.Write(" "); + +this.Write(this.ToStringHelper.ToStringWithCulture(ClassAccessModifier)); + +this.Write(" Enum "); this.Write(this.ToStringHelper.ToStringWithCulture(enumName)); @@ -6695,7 +6784,11 @@ internal override void WriteExtensionMethodsStart() { this.Write(" \'\'\' \r\n \'\'\' Class containing all extension methods\r\n \'\'\' \r\n Public Module ExtensionMethods\r\n"); + "ary>\r\n "); + +this.Write(this.ToStringHelper.ToStringWithCulture(ClassAccessModifier)); + +this.Write(" Module ExtensionMethods\r\n"); } @@ -6808,8 +6901,8 @@ internal override void WriteCastToMethods(string baseTypeName, string derivedTyp this.Write(this.ToStringHelper.ToStringWithCulture(derivedTypeFullName)); this.Write("\r\n \'\'\' \r\n \'\'\' source entity\r" + - "\n \r\n Public " + - "Function CastTo"); + "\n \r\n Public Fu" + + "nction CastTo"); this.Write(this.ToStringHelper.ToStringWithCulture(derivedTypeName)); diff --git a/ODataConnectedService/src/Templates/ODataT4CodeGenerator.tt b/ODataConnectedService/src/Templates/ODataT4CodeGenerator.tt index adde141..960fa16 100644 --- a/ODataConnectedService/src/Templates/ODataT4CodeGenerator.tt +++ b/ODataConnectedService/src/Templates/ODataT4CodeGenerator.tt @@ -24,6 +24,10 @@ public static class Configuration // This flag indicates whether to ignore unexpected elements and attributes in the metadata document and generate // the client code if any. The value must be set to true or false. public const bool IgnoreUnexpectedElementsAndAttributes = true; + + // If set to true, generated types will have an "internal" class modifier ("Friend" in VB) instead of "public" + // thereby making them invisible outside the assembly + public const bool MakeTypesInternal = false; } public static class Customization diff --git a/ODataConnectedService/src/Templates/ODataT4CodeGenerator.ttinclude b/ODataConnectedService/src/Templates/ODataT4CodeGenerator.ttinclude index 6f96dcb..1d53c0c 100644 --- a/ODataConnectedService/src/Templates/ODataT4CodeGenerator.ttinclude +++ b/ODataConnectedService/src/Templates/ODataT4CodeGenerator.ttinclude @@ -48,7 +48,7 @@ THE SOFTWARE IS PROVIDED *AS IS*, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI TargetLanguage = this.TargetLanguage, EnableNamingAlias = this.EnableNamingAlias, IgnoreUnexpectedElementsAndAttributes = this.IgnoreUnexpectedElementsAndAttributes, - MakeClassesInternal = true + MakeTypesInternal = this.MakeTypesInternal }; } else @@ -65,7 +65,7 @@ THE SOFTWARE IS PROVIDED *AS IS*, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI TargetLanguage = this.TargetLanguage, EnableNamingAlias = this.EnableNamingAlias, IgnoreUnexpectedElementsAndAttributes = this.IgnoreUnexpectedElementsAndAttributes, - MakeClassesInternal = true + MakeTypesInternal = this.MakeTypesInternal }; } @@ -215,6 +215,16 @@ public bool IgnoreUnexpectedElementsAndAttributes set; } +/// +/// true to use the "internal" access modifier ("Friend" in VB) on generated types, +/// otherwise "public" is used +/// +public bool MakeTypesInternal +{ + get; + set; +} + /// /// Generate code targeting a specific .Net Framework language. /// @@ -307,6 +317,26 @@ public void ValidateAndSetIgnoreUnexpectedElementsAndAttributesFromString(string this.IgnoreUnexpectedElementsAndAttributes = boolValue; } +/// +/// Set the MakeTypesInternal property with the given value. +/// +/// The value to set. +public void ValidateAndSetMakeTypesInternalFromString(string stringValue) +{ + bool boolValue; + if (!bool.TryParse(stringValue, out boolValue)) + { + // ******************************************************************************************************** + // To fix this error, if the current text transformation is run by the TextTemplatingFileGenerator + // custom tool inside Visual Studio, update the .odata.config file in the project with a valid parameter + // value then hit Ctrl-S to save the .tt file to refresh the code generation. + // ******************************************************************************************************** + throw new ArgumentException(string.Format(CultureInfo.InvariantCulture, "The value \"{0}\" cannot be assigned to the MakeTypesInternal parameter because it is not a valid boolean value.", stringValue)); + } + + this.MakeTypesInternal = boolValue; +} + /// /// Reads the parameter values from the Configuration class and applies them. /// @@ -318,6 +348,7 @@ private void ApplyParametersFromConfigurationClass() this.ValidateAndSetTargetLanguageFromString(Configuration.TargetLanguage); this.EnableNamingAlias = Configuration.EnableNamingAlias; this.IgnoreUnexpectedElementsAndAttributes = Configuration.IgnoreUnexpectedElementsAndAttributes; + this.MakeTypesInternal = Configuration.MakeTypesInternal; } /// @@ -365,6 +396,12 @@ private void ApplyParametersFromCommandLine() { this.ValidateAndSetIgnoreUnexpectedElementsAndAttributesFromString(ignoreUnexpectedElementsAndAttributes); } + + string makeTypesInternal = this.Host.ResolveParameterValue("notempty", "notempty", "MakeTypesInternal"); + if (!string.IsNullOrEmpty(makeTypesInternal)) + { + this.ValidateAndSetMakeTypesInternalFromString(makeTypesInternal); + } } /// @@ -679,7 +716,7 @@ public class CodeGenerationContext /// true to use internal access modifier for generated classes, otherwise they will be made public. /// This is useful if you don't want the generated classes to be visible outside the assembly /// - public bool MakeClassesInternal + public bool MakeTypesInternal { get; set; @@ -1093,7 +1130,7 @@ public abstract class ODataClientTemplate : TemplateBase internal string ClassAccessModifier { get { - return this.context.MakeClassesInternal ? this.InternalAccessModifier : this.PublicAccessModifier; + return this.context.MakeTypesInternal ? this.InternalAccessModifier : this.PublicAccessModifier; } } diff --git a/ODataConnectedService/src/ViewModels/AdvancedSettingsViewModel.cs b/ODataConnectedService/src/ViewModels/AdvancedSettingsViewModel.cs index d193f87..c7732be 100644 --- a/ODataConnectedService/src/ViewModels/AdvancedSettingsViewModel.cs +++ b/ODataConnectedService/src/ViewModels/AdvancedSettingsViewModel.cs @@ -17,6 +17,7 @@ internal class AdvancedSettingsViewModel : ConnectedServiceWizardPage public bool IgnoreUnexpectedElementsAndAttributes { get; set; } public string GeneratedFileName { get; set; } public bool IncludeT4File { get; set; } + public bool MakeTypesInternal { get; set; } public AdvancedSettingsViewModel() : base() { @@ -55,6 +56,7 @@ private void ResetDataContext() this.EnableNamingAlias = false; this.GeneratedFileName = Common.Constants.DefaultReferenceFileName; this.IncludeT4File = false; + MakeTypesInternal = false; } } } diff --git a/ODataConnectedService/src/Views/AdvancedSettings.xaml b/ODataConnectedService/src/Views/AdvancedSettings.xaml index cc40528..0530d49 100644 --- a/ODataConnectedService/src/Views/AdvancedSettings.xaml +++ b/ODataConnectedService/src/Views/AdvancedSettings.xaml @@ -36,6 +36,10 @@ HorizontalAlignment="Left" TextWrapping="Wrap" VerticalAlignment="Center" Width="250" Margin="20, 0, 0, 5"/> + + Make generated types internal (Enable this if you don't want to expose the generated types outside of your assembly.) + Date: Fri, 17 Jan 2020 10:38:59 +0300 Subject: [PATCH 05/24] Add ODataConnectedService support for VS 2019 --- .../src/ODataConnectedService.csproj | 9 ++-- .../src/ODataConnectedServiceProvider.cs | 14 +++--- .../src/Views/AdvancedSettings.xaml | 2 +- ODataConnectedService/src/app.config | 12 ++--- .../src/source.extension.vsixmanifest | 46 ++++++++++--------- 5 files changed, 43 insertions(+), 40 deletions(-) diff --git a/ODataConnectedService/src/ODataConnectedService.csproj b/ODataConnectedService/src/ODataConnectedService.csproj index 54a0c2a..2697bf1 100644 --- a/ODataConnectedService/src/ODataConnectedService.csproj +++ b/ODataConnectedService/src/ODataConnectedService.csproj @@ -22,6 +22,7 @@ false true 14.0 + @@ -36,14 +37,14 @@ Properties Microsoft.OData.ConnectedService Microsoft.OData.ConnectedService - v4.5 + v4.7.2 512 false Program - C:\Program Files (x86)\Microsoft Visual Studio $(VisualStudioVersion)\Common7\IDE\devenv.exe + $(DevEnvDir)devenv.exe /rootSuffix exp - true - true + false + false $(DFRootPath)\tools\35MSSharedLib1024.snk diff --git a/ODataConnectedService/src/ODataConnectedServiceProvider.cs b/ODataConnectedService/src/ODataConnectedServiceProvider.cs index b4c47b1..e44591e 100644 --- a/ODataConnectedService/src/ODataConnectedServiceProvider.cs +++ b/ODataConnectedService/src/ODataConnectedServiceProvider.cs @@ -15,13 +15,13 @@ internal class ODataConnectedServiceProvider : ConnectedServiceProvider { public ODataConnectedServiceProvider() { - this.Name = "OData Connected Service"; - this.Category = "OData"; - this.Description = "OData Connected Service for V1-V4"; - this.Icon = new BitmapImage(new Uri("pack://application:,,/" + this.GetType().Assembly.ToString() + ";component/Resources/Icon.png")); - this.CreatedBy = "OData"; - this.Version = new Version(0, 2, 0); - this.MoreInfoUri = new Uri("https://github.com/odata/lab"); + Name = "OData Connected Service"; + Category = "OData"; + Description = "OData Connected Service for V1-V4"; + Icon = new BitmapImage(new Uri("pack://application:,,/" + this.GetType().Assembly.ToString() + ";component/Resources/Icon.png")); + CreatedBy = "OData"; + Version = new Version(0, 4, 0); + MoreInfoUri = new Uri("https://github.com/odata/lab"); } public override Task CreateConfiguratorAsync(ConnectedServiceProviderContext context) diff --git a/ODataConnectedService/src/Views/AdvancedSettings.xaml b/ODataConnectedService/src/Views/AdvancedSettings.xaml index 0530d49..e0029cd 100644 --- a/ODataConnectedService/src/Views/AdvancedSettings.xaml +++ b/ODataConnectedService/src/Views/AdvancedSettings.xaml @@ -49,7 +49,7 @@ Ignore unknown elements (Whether to ignore unexpected elements and attributes in the metadata document and generate the client code if any.) + HorizontalAlignment="Left" VerticalAlignment="Top" Margin="0, 15" FontWeight="Medium"/> diff --git a/ODataConnectedService/src/app.config b/ODataConnectedService/src/app.config index faa26ba..bc76694 100644 --- a/ODataConnectedService/src/app.config +++ b/ODataConnectedService/src/app.config @@ -1,15 +1,15 @@ - + - - + + - - + + - + diff --git a/ODataConnectedService/src/source.extension.vsixmanifest b/ODataConnectedService/src/source.extension.vsixmanifest index 3357965..cace2d2 100644 --- a/ODataConnectedService/src/source.extension.vsixmanifest +++ b/ODataConnectedService/src/source.extension.vsixmanifest @@ -1,25 +1,27 @@ - - - Microsoft - OData Connected Service - OData Connected Service for V1-V4 - https://github.com/odata/lab - License.txt - Resources\ExtensionIcon.png - OData Connected Service - - - - - - - - - - - - - + + + Microsoft + OData Connected Service + OData Connected Service for V1-V4 + https://github.com/odata/lab + License.txt + Resources\ExtensionIcon.png + OData Connected Service + + + + + + + + + + + + + + + From 589caf12c43bb47226add98b42332b026ccb0609 Mon Sep 17 00:00:00 2001 From: Clement Habinshuti Date: Fri, 17 Jan 2020 10:48:15 +0300 Subject: [PATCH 06/24] Re-enable signing --- ODataConnectedService/src/ODataConnectedService.csproj | 4 ++-- README.md | 2 ++ 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/ODataConnectedService/src/ODataConnectedService.csproj b/ODataConnectedService/src/ODataConnectedService.csproj index 2697bf1..5948c9d 100644 --- a/ODataConnectedService/src/ODataConnectedService.csproj +++ b/ODataConnectedService/src/ODataConnectedService.csproj @@ -43,8 +43,8 @@ Program $(DevEnvDir)devenv.exe /rootSuffix exp - false - false + true + true $(DFRootPath)\tools\35MSSharedLib1024.snk diff --git a/README.md b/README.md index 88074a9..ffe14d9 100644 --- a/README.md +++ b/README.md @@ -14,6 +14,8 @@ This repository is for exploring new ideas and developing early prototypes of va * [Source](https://github.com/OData/lab/tree/master/ODataConnectedService) * [Visual Studio Extension](https://visualstudiogallery.msdn.microsoft.com/b343d0eb-6493-44c2-b558-13a0408d013f) * FAQ + **Question**: The extension module is not loaded when debugging in the Visual Studio experimental instance, or it is not listed as part of the "Add Connected Service" options + **Workaround**: Disable signing by going to the Project Properties > Signing and disabling both "Sign the assembly" and "Delay sign only" options. **Question**: In Visual Studio 2017, upon configuring the service endpoint in the OData Connected Services extension and clicking "Finish", I get an error message that says "Value cannot be null.\r\nParameter name: path1". **Workaround**: Download the [Microsoft WCF ToolKit](https://download.microsoft.com/download/1/C/A/1CAA41C7-88B9-42D6-9E11-3C655656DAB1/WcfDataServices.exe) and install it. Then go to the registry and find the following key: `[HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\Microsoft\Microsoft WCF Data Services]`. Create a duplicate of "VS 2010 Tooling" (if this doesn't exist, use "5.6" instead) named "VS 2014 Tooling". Then try again. (Special thanks to [mohsenno1](https://github.com/mohsenno1) for pointing this out.) From 691c839d6f81d4a5b28b7f469093f6f93f913571 Mon Sep 17 00:00:00 2001 From: Clement Habinshuti Date: Fri, 17 Jan 2020 11:13:16 +0300 Subject: [PATCH 07/24] Fix inconsistent indentation --- .../src/Templates/ODataT4CodeGenerator.cs | 44 +++++++++---------- .../Templates/ODataT4CodeGenerator.ttinclude | 38 ++++++++-------- 2 files changed, 41 insertions(+), 41 deletions(-) diff --git a/ODataConnectedService/src/Templates/ODataT4CodeGenerator.cs b/ODataConnectedService/src/Templates/ODataT4CodeGenerator.cs index acae83d..6348065 100644 --- a/ODataConnectedService/src/Templates/ODataT4CodeGenerator.cs +++ b/ODataConnectedService/src/Templates/ODataT4CodeGenerator.cs @@ -1,7 +1,7 @@ // ------------------------------------------------------------------------------ // // This code was generated by a tool. -// Runtime Version: 15.0.0.0 +// Runtime Version: 16.0.0.0 // // Changes to this file may cause incorrect behavior and will be lost if // the code is regenerated. @@ -31,7 +31,7 @@ namespace Microsoft.OData.ConnectedService.Templates /// /// Class to produce the template output /// - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.TextTemplating", "15.0.0.0")] + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.TextTemplating", "16.0.0.0")] internal partial class ODataT4CodeGenerator : ODataT4CodeGeneratorBase { /// @@ -62,7 +62,7 @@ The above copyright notice and this permission notice shall be included in all c TargetLanguage = this.TargetLanguage, EnableNamingAlias = this.EnableNamingAlias, IgnoreUnexpectedElementsAndAttributes = this.IgnoreUnexpectedElementsAndAttributes, - MakeTypesInternal = this.MakeTypesInternal + MakeTypesInternal = this.MakeTypesInternal }; } else @@ -79,7 +79,7 @@ The above copyright notice and this permission notice shall be included in all c TargetLanguage = this.TargetLanguage, EnableNamingAlias = this.EnableNamingAlias, IgnoreUnexpectedElementsAndAttributes = this.IgnoreUnexpectedElementsAndAttributes, - MakeTypesInternal = this.MakeTypesInternal + MakeTypesInternal = this.MakeTypesInternal }; } @@ -460,7 +460,7 @@ private void ApplyParametersFromConfigurationClass() this.ValidateAndSetTargetLanguageFromString(Configuration.TargetLanguage); this.EnableNamingAlias = Configuration.EnableNamingAlias; this.IgnoreUnexpectedElementsAndAttributes = Configuration.IgnoreUnexpectedElementsAndAttributes; - this.MakeTypesInternal = Configuration.MakeTypesInternal; + this.MakeTypesInternal = Configuration.MakeTypesInternal; } /// @@ -509,11 +509,11 @@ private void ApplyParametersFromCommandLine() this.ValidateAndSetIgnoreUnexpectedElementsAndAttributesFromString(ignoreUnexpectedElementsAndAttributes); } - string makeTypesInternal = this.Host.ResolveParameterValue("notempty", "notempty", "MakeTypesInternal"); - if (!string.IsNullOrEmpty(makeTypesInternal)) - { - this.ValidateAndSetMakeTypesInternalFromString(makeTypesInternal); - } + string makeTypesInternal = this.Host.ResolveParameterValue("notempty", "notempty", "MakeTypesInternal"); + if (!string.IsNullOrEmpty(makeTypesInternal)) + { + this.ValidateAndSetMakeTypesInternalFromString(makeTypesInternal); + } } /// @@ -1093,8 +1093,8 @@ public ODataClientTemplate(CodeGenerationContext context) internal abstract string GlobalPrefix { get; } internal abstract string SystemTypeTypeName { get; } internal abstract string AbstractModifier { get; } - internal abstract string PublicAccessModifier { get; } - internal abstract string InternalAccessModifier { get; } + internal abstract string PublicAccessModifier { get; } + internal abstract string InternalAccessModifier { get; } internal abstract string DataServiceActionQueryTypeName { get; } internal abstract string DataServiceActionQuerySingleOfTStructureTemplate { get; } internal abstract string DataServiceActionQueryOfTStructureTemplate { get; } @@ -1240,11 +1240,11 @@ internal HashSet ClrReferenceTypes { get { } } private HashSet clrReferenceTypes; - internal string ClassAccessModifier { - get { - return this.context.MakeTypesInternal ? this.InternalAccessModifier : this.PublicAccessModifier; - } - } + internal string ClassAccessModifier { + get { + return this.context.MakeTypesInternal ? this.InternalAccessModifier : this.PublicAccessModifier; + } + } /// /// Generates code for the OData client. @@ -3185,8 +3185,8 @@ public ODataClientCSharpTemplate(CodeGenerationContext context) internal override string GlobalPrefix { get {return "global::"; } } internal override string SystemTypeTypeName { get { return "global::System.Type"; } } internal override string AbstractModifier { get { return " abstract"; } } - internal override string PublicAccessModifier { get { return "public"; } } - internal override string InternalAccessModifier { get { return "internal"; } } + internal override string PublicAccessModifier { get { return "public"; } } + internal override string InternalAccessModifier { get { return "internal"; } } internal override string DataServiceActionQueryTypeName { get { return "global::Microsoft.OData.Client.DataServiceActionQuery"; } } internal override string DataServiceActionQuerySingleOfTStructureTemplate { get { return "global::Microsoft.OData.Client.DataServiceActionQuerySingle<{0}>"; } } internal override string DataServiceActionQueryOfTStructureTemplate { get { return "global::Microsoft.OData.Client.DataServiceActionQuery<{0}>"; } } @@ -5137,8 +5137,8 @@ public ODataClientVBTemplate(CodeGenerationContext context) internal override string GlobalPrefix { get { return string.Empty; } } internal override string SystemTypeTypeName { get { return "Global.System.Type"; } } internal override string AbstractModifier { get { return " MustInherit"; } } - internal override string PublicAccessModifier { get { return "Public"; } } - internal override string InternalAccessModifier { get { return "Friend"; } } + internal override string PublicAccessModifier { get { return "Public"; } } + internal override string InternalAccessModifier { get { return "Friend"; } } internal override string DataServiceActionQueryTypeName { get { return "Global.Microsoft.OData.Client.DataServiceActionQuery"; } } internal override string DataServiceActionQuerySingleOfTStructureTemplate { get { return "Global.Microsoft.OData.Client.DataServiceActionQuerySingle(Of {0})"; } } internal override string DataServiceActionQueryOfTStructureTemplate { get { return "Global.Microsoft.OData.Client.DataServiceActionQuery(Of {0})"; } } @@ -7142,7 +7142,7 @@ internal override void WriteNamespaceEnd() /// /// Base class for this transformation /// - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.TextTemplating", "15.0.0.0")] + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.TextTemplating", "16.0.0.0")] internal class ODataT4CodeGeneratorBase { #region Fields diff --git a/ODataConnectedService/src/Templates/ODataT4CodeGenerator.ttinclude b/ODataConnectedService/src/Templates/ODataT4CodeGenerator.ttinclude index 1d53c0c..a1b8edb 100644 --- a/ODataConnectedService/src/Templates/ODataT4CodeGenerator.ttinclude +++ b/ODataConnectedService/src/Templates/ODataT4CodeGenerator.ttinclude @@ -48,7 +48,7 @@ THE SOFTWARE IS PROVIDED *AS IS*, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI TargetLanguage = this.TargetLanguage, EnableNamingAlias = this.EnableNamingAlias, IgnoreUnexpectedElementsAndAttributes = this.IgnoreUnexpectedElementsAndAttributes, - MakeTypesInternal = this.MakeTypesInternal + MakeTypesInternal = this.MakeTypesInternal }; } else @@ -65,7 +65,7 @@ THE SOFTWARE IS PROVIDED *AS IS*, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI TargetLanguage = this.TargetLanguage, EnableNamingAlias = this.EnableNamingAlias, IgnoreUnexpectedElementsAndAttributes = this.IgnoreUnexpectedElementsAndAttributes, - MakeTypesInternal = this.MakeTypesInternal + MakeTypesInternal = this.MakeTypesInternal }; } @@ -348,7 +348,7 @@ private void ApplyParametersFromConfigurationClass() this.ValidateAndSetTargetLanguageFromString(Configuration.TargetLanguage); this.EnableNamingAlias = Configuration.EnableNamingAlias; this.IgnoreUnexpectedElementsAndAttributes = Configuration.IgnoreUnexpectedElementsAndAttributes; - this.MakeTypesInternal = Configuration.MakeTypesInternal; + this.MakeTypesInternal = Configuration.MakeTypesInternal; } /// @@ -397,11 +397,11 @@ private void ApplyParametersFromCommandLine() this.ValidateAndSetIgnoreUnexpectedElementsAndAttributesFromString(ignoreUnexpectedElementsAndAttributes); } - string makeTypesInternal = this.Host.ResolveParameterValue("notempty", "notempty", "MakeTypesInternal"); - if (!string.IsNullOrEmpty(makeTypesInternal)) - { - this.ValidateAndSetMakeTypesInternalFromString(makeTypesInternal); - } + string makeTypesInternal = this.Host.ResolveParameterValue("notempty", "notempty", "MakeTypesInternal"); + if (!string.IsNullOrEmpty(makeTypesInternal)) + { + this.ValidateAndSetMakeTypesInternalFromString(makeTypesInternal); + } } /// @@ -981,8 +981,8 @@ public abstract class ODataClientTemplate : TemplateBase internal abstract string GlobalPrefix { get; } internal abstract string SystemTypeTypeName { get; } internal abstract string AbstractModifier { get; } - internal abstract string PublicAccessModifier { get; } - internal abstract string InternalAccessModifier { get; } + internal abstract string PublicAccessModifier { get; } + internal abstract string InternalAccessModifier { get; } internal abstract string DataServiceActionQueryTypeName { get; } internal abstract string DataServiceActionQuerySingleOfTStructureTemplate { get; } internal abstract string DataServiceActionQueryOfTStructureTemplate { get; } @@ -1128,11 +1128,11 @@ public abstract class ODataClientTemplate : TemplateBase } } private HashSet clrReferenceTypes; - internal string ClassAccessModifier { - get { - return this.context.MakeTypesInternal ? this.InternalAccessModifier : this.PublicAccessModifier; - } - } + internal string ClassAccessModifier { + get { + return this.context.MakeTypesInternal ? this.InternalAccessModifier : this.PublicAccessModifier; + } + } /// /// Generates code for the OData client. @@ -3073,8 +3073,8 @@ public sealed class ODataClientCSharpTemplate : ODataClientTemplate internal override string GlobalPrefix { get {return "global::"; } } internal override string SystemTypeTypeName { get { return "global::System.Type"; } } internal override string AbstractModifier { get { return " abstract"; } } - internal override string PublicAccessModifier { get { return "public"; } } - internal override string InternalAccessModifier { get { return "internal"; } } + internal override string PublicAccessModifier { get { return "public"; } } + internal override string InternalAccessModifier { get { return "internal"; } } internal override string DataServiceActionQueryTypeName { get { return "global::Microsoft.OData.Client.DataServiceActionQuery"; } } internal override string DataServiceActionQuerySingleOfTStructureTemplate { get { return "global::Microsoft.OData.Client.DataServiceActionQuerySingle<{0}>"; } } internal override string DataServiceActionQueryOfTStructureTemplate { get { return "global::Microsoft.OData.Client.DataServiceActionQuery<{0}>"; } } @@ -4114,8 +4114,8 @@ public sealed class ODataClientVBTemplate : ODataClientTemplate internal override string GlobalPrefix { get { return string.Empty; } } internal override string SystemTypeTypeName { get { return "Global.System.Type"; } } internal override string AbstractModifier { get { return " MustInherit"; } } - internal override string PublicAccessModifier { get { return "Public"; } } - internal override string InternalAccessModifier { get { return "Friend"; } } + internal override string PublicAccessModifier { get { return "Public"; } } + internal override string InternalAccessModifier { get { return "Friend"; } } internal override string DataServiceActionQueryTypeName { get { return "Global.Microsoft.OData.Client.DataServiceActionQuery"; } } internal override string DataServiceActionQuerySingleOfTStructureTemplate { get { return "Global.Microsoft.OData.Client.DataServiceActionQuerySingle(Of {0})"; } } internal override string DataServiceActionQueryOfTStructureTemplate { get { return "Global.Microsoft.OData.Client.DataServiceActionQuery(Of {0})"; } } From 244cc87b1c5e3538d22838a2fb1a97a8be002412 Mon Sep 17 00:00:00 2001 From: Clement Habinshuti Date: Tue, 21 Jan 2020 11:58:39 +0300 Subject: [PATCH 08/24] Create test solution for ODataConnectedService --- .../ODataConnectedService.Tests.sln | 31 + .../src/ODataConnectedService.csproj | 2 +- .../src/Properties/AssemblyInfo.cs | 3 + .../EntitiesEnumsFunctions.cs | 1298 +++++++++++++++ .../EntitiesEnumsFunctions.xml | 81 + .../EntitiesEnumsFunctionsDSC.cs | 1423 +++++++++++++++++ ...itiesEnumsFunctionsDSCWithInternalTypes.cs | 1423 +++++++++++++++++ ...EntitiesEnumsFunctionsWithInternalTypes.cs | 1298 +++++++++++++++ .../ODataConnectedService.Tests.csproj | 72 + .../Properties/AssemblyInfo.cs | 20 + .../Templates/ODataT4CodeGeneratorTest.cs | 110 ++ 11 files changed, 5760 insertions(+), 1 deletion(-) create mode 100644 ODataConnectedService/ODataConnectedService.Tests.sln create mode 100644 ODataConnectedService/test/ODataConnectedService.Tests/CodeGenReferences/EntitiesEnumsFunctions.cs create mode 100644 ODataConnectedService/test/ODataConnectedService.Tests/CodeGenReferences/EntitiesEnumsFunctions.xml create mode 100644 ODataConnectedService/test/ODataConnectedService.Tests/CodeGenReferences/EntitiesEnumsFunctionsDSC.cs create mode 100644 ODataConnectedService/test/ODataConnectedService.Tests/CodeGenReferences/EntitiesEnumsFunctionsDSCWithInternalTypes.cs create mode 100644 ODataConnectedService/test/ODataConnectedService.Tests/CodeGenReferences/EntitiesEnumsFunctionsWithInternalTypes.cs create mode 100644 ODataConnectedService/test/ODataConnectedService.Tests/ODataConnectedService.Tests.csproj create mode 100644 ODataConnectedService/test/ODataConnectedService.Tests/Properties/AssemblyInfo.cs create mode 100644 ODataConnectedService/test/ODataConnectedService.Tests/Templates/ODataT4CodeGeneratorTest.cs diff --git a/ODataConnectedService/ODataConnectedService.Tests.sln b/ODataConnectedService/ODataConnectedService.Tests.sln new file mode 100644 index 0000000..0943779 --- /dev/null +++ b/ODataConnectedService/ODataConnectedService.Tests.sln @@ -0,0 +1,31 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 16 +VisualStudioVersion = 16.0.29613.14 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ODataConnectedService", "src\ODataConnectedService.csproj", "{A8BC5B8E-9AB7-4257-B8F1-E7C62169F9B5}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ODataConnectedService.Tests", "test\ODataConnectedService.Tests\ODataConnectedService.Tests.csproj", "{903B31D0-BE14-4D9E-BA76-186FA82B3A37}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {A8BC5B8E-9AB7-4257-B8F1-E7C62169F9B5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {A8BC5B8E-9AB7-4257-B8F1-E7C62169F9B5}.Debug|Any CPU.Build.0 = Debug|Any CPU + {A8BC5B8E-9AB7-4257-B8F1-E7C62169F9B5}.Release|Any CPU.ActiveCfg = Release|Any CPU + {A8BC5B8E-9AB7-4257-B8F1-E7C62169F9B5}.Release|Any CPU.Build.0 = Release|Any CPU + {903B31D0-BE14-4D9E-BA76-186FA82B3A37}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {903B31D0-BE14-4D9E-BA76-186FA82B3A37}.Debug|Any CPU.Build.0 = Debug|Any CPU + {903B31D0-BE14-4D9E-BA76-186FA82B3A37}.Release|Any CPU.ActiveCfg = Release|Any CPU + {903B31D0-BE14-4D9E-BA76-186FA82B3A37}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {FD696714-8F52-4A00-93F4-43C843F184DB} + EndGlobalSection +EndGlobal diff --git a/ODataConnectedService/src/ODataConnectedService.csproj b/ODataConnectedService/src/ODataConnectedService.csproj index 5948c9d..11b437f 100644 --- a/ODataConnectedService/src/ODataConnectedService.csproj +++ b/ODataConnectedService/src/ODataConnectedService.csproj @@ -43,7 +43,7 @@ Program $(DevEnvDir)devenv.exe /rootSuffix exp - true + false true $(DFRootPath)\tools\35MSSharedLib1024.snk diff --git a/ODataConnectedService/src/Properties/AssemblyInfo.cs b/ODataConnectedService/src/Properties/AssemblyInfo.cs index 4a87d33..9fe57b2 100644 --- a/ODataConnectedService/src/Properties/AssemblyInfo.cs +++ b/ODataConnectedService/src/Properties/AssemblyInfo.cs @@ -4,6 +4,7 @@ using System; using System.Reflection; using System.Resources; +using System.Runtime.CompilerServices; using System.Runtime.InteropServices; // General Information about an assembly is controlled through the following @@ -37,3 +38,5 @@ [assembly: AssemblyVersion("0.3.0.0")] [assembly: AssemblyFileVersion("0.3.0.0")] [assembly: NeutralResourcesLanguageAttribute("en")] + +[assembly: InternalsVisibleTo("ODataConnectedService.Tests")] diff --git a/ODataConnectedService/test/ODataConnectedService.Tests/CodeGenReferences/EntitiesEnumsFunctions.cs b/ODataConnectedService/test/ODataConnectedService.Tests/CodeGenReferences/EntitiesEnumsFunctions.cs new file mode 100644 index 0000000..44ada8d --- /dev/null +++ b/ODataConnectedService/test/ODataConnectedService.Tests/CodeGenReferences/EntitiesEnumsFunctions.cs @@ -0,0 +1,1298 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by a tool. +// Runtime Version:4.0.30319.42000 +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +// Generation date: 1/21/2020 11:02:50 AM +namespace Microsoft.OData.Service.Sample.TrippinInMemory.Models +{ + /// + /// There are no comments for Container in the schema. + /// + public partial class Container : global::Microsoft.OData.Client.DataServiceContext + { + /// + /// Initialize a new Container object. + /// + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + public Container(global::System.Uri serviceRoot) : + base(serviceRoot, global::Microsoft.OData.Client.ODataProtocolVersion.V4) + { + this.ResolveName = new global::System.Func(this.ResolveNameFromType); + this.OnContextCreated(); + this.Format.LoadServiceModel = GeneratedEdmModel.GetInstance; + this.Format.UseJson(); + } + partial void OnContextCreated(); + /// + /// Since the namespace configured for this service reference + /// in Visual Studio is different from the one indicated in the + /// server schema, use type-mappers to map between the two. + /// + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + protected string ResolveNameFromType(global::System.Type clientType) + { + return clientType.FullName; + } + /// + /// There are no comments for People in the schema. + /// + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + public global::Microsoft.OData.Client.DataServiceQuery People + { + get + { + if ((this._People == null)) + { + this._People = base.CreateQuery("People"); + } + return this._People; + } + } + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + private global::Microsoft.OData.Client.DataServiceQuery _People; + /// + /// There are no comments for Airlines in the schema. + /// + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + public global::Microsoft.OData.Client.DataServiceQuery Airlines + { + get + { + if ((this._Airlines == null)) + { + this._Airlines = base.CreateQuery("Airlines"); + } + return this._Airlines; + } + } + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + private global::Microsoft.OData.Client.DataServiceQuery _Airlines; + /// + /// There are no comments for Airports in the schema. + /// + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + public global::Microsoft.OData.Client.DataServiceQuery Airports + { + get + { + if ((this._Airports == null)) + { + this._Airports = base.CreateQuery("Airports"); + } + return this._Airports; + } + } + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + private global::Microsoft.OData.Client.DataServiceQuery _Airports; + /// + /// There are no comments for People in the schema. + /// + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + public void AddToPeople(Person person) + { + base.AddObject("People", person); + } + /// + /// There are no comments for Airlines in the schema. + /// + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + public void AddToAirlines(Airline airline) + { + base.AddObject("Airlines", airline); + } + /// + /// There are no comments for Airports in the schema. + /// + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + public void AddToAirports(Airport airport) + { + base.AddObject("Airports", airport); + } + /// + /// There are no comments for Me in the schema. + /// + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + public PersonSingle Me + { + get + { + if ((this._Me == null)) + { + this._Me = new PersonSingle(this, "Me"); + } + return this._Me; + } + } + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + private PersonSingle _Me; + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + private abstract class GeneratedEdmModel + { + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + private static global::Microsoft.OData.Edm.IEdmModel ParsedModel = LoadModelFromString(); + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + private const string Edmx = @" + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +"; + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + public static global::Microsoft.OData.Edm.IEdmModel GetInstance() + { + return ParsedModel; + } + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + private static global::Microsoft.OData.Edm.IEdmModel LoadModelFromString() + { + global::System.Xml.XmlReader reader = CreateXmlReader(Edmx); + try + { + return global::Microsoft.OData.Edm.Csdl.CsdlReader.Parse(reader); + } + finally + { + ((global::System.IDisposable)(reader)).Dispose(); + } + } + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + private static global::System.Xml.XmlReader CreateXmlReader(string edmxToParse) + { + return global::System.Xml.XmlReader.Create(new global::System.IO.StringReader(edmxToParse)); + } + } + /// + /// There are no comments for GetPersonWithMostFriends in the schema. + /// + public global::Microsoft.OData.Service.Sample.TrippinInMemory.Models.PersonSingle GetPersonWithMostFriends() + { + return new global::Microsoft.OData.Service.Sample.TrippinInMemory.Models.PersonSingle(this.CreateFunctionQuerySingle("", "GetPersonWithMostFriends", false)); + } + /// + /// There are no comments for GetNearestAirport in the schema. + /// + public global::Microsoft.OData.Service.Sample.TrippinInMemory.Models.AirportSingle GetNearestAirport(double lat, double lon) + { + return new global::Microsoft.OData.Service.Sample.TrippinInMemory.Models.AirportSingle(this.CreateFunctionQuerySingle("", "GetNearestAirport", false, new global::Microsoft.OData.Client.UriOperationParameter("lat", lat), + new global::Microsoft.OData.Client.UriOperationParameter("lon", lon))); + } + /// + /// There are no comments for ResetDataSource in the schema. + /// + public global::Microsoft.OData.Client.DataServiceActionQuery ResetDataSource() + { + return new global::Microsoft.OData.Client.DataServiceActionQuery(this, this.BaseUri.OriginalString.Trim('/') + "/ResetDataSource"); + } + } + /// + /// There are no comments for PersonSingle in the schema. + /// + public partial class PersonSingle : global::Microsoft.OData.Client.DataServiceQuerySingle + { + /// + /// Initialize a new PersonSingle object. + /// + public PersonSingle(global::Microsoft.OData.Client.DataServiceContext context, string path) + : base(context, path) { } + + /// + /// Initialize a new PersonSingle object. + /// + public PersonSingle(global::Microsoft.OData.Client.DataServiceContext context, string path, bool isComposable) + : base(context, path, isComposable) { } + + /// + /// Initialize a new PersonSingle object. + /// + public PersonSingle(global::Microsoft.OData.Client.DataServiceQuerySingle query) + : base(query) { } + + /// + /// There are no comments for Friends in the schema. + /// + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + public global::Microsoft.OData.Client.DataServiceQuery Friends + { + get + { + if (!this.IsComposable) + { + throw new global::System.NotSupportedException("The previous function is not composable."); + } + if ((this._Friends == null)) + { + this._Friends = Context.CreateQuery(GetPath("Friends")); + } + return this._Friends; + } + } + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + private global::Microsoft.OData.Client.DataServiceQuery _Friends; + /// + /// There are no comments for Trips in the schema. + /// + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + public global::Microsoft.OData.Client.DataServiceQuery Trips + { + get + { + if (!this.IsComposable) + { + throw new global::System.NotSupportedException("The previous function is not composable."); + } + if ((this._Trips == null)) + { + this._Trips = Context.CreateQuery(GetPath("Trips")); + } + return this._Trips; + } + } + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + private global::Microsoft.OData.Client.DataServiceQuery _Trips; + } + /// + /// There are no comments for Person in the schema. + /// + /// + /// UserName + /// + [global::Microsoft.OData.Client.Key("UserName")] + public partial class Person : global::Microsoft.OData.Client.BaseEntityType + { + /// + /// Create a new Person object. + /// + /// Initial value of UserName. + /// Initial value of Gender. + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + public static Person CreatePerson(string userName, global::Microsoft.OData.Service.Sample.TrippinInMemory.Models.PersonGender gender) + { + Person person = new Person(); + person.UserName = userName; + person.Gender = gender; + return person; + } + /// + /// There are no comments for Property UserName in the schema. + /// + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + public string UserName + { + get + { + return this._UserName; + } + set + { + this.OnUserNameChanging(value); + this._UserName = value; + this.OnUserNameChanged(); + } + } + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + private string _UserName; + partial void OnUserNameChanging(string value); + partial void OnUserNameChanged(); + /// + /// There are no comments for Property Gender in the schema. + /// + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + public global::Microsoft.OData.Service.Sample.TrippinInMemory.Models.PersonGender Gender + { + get + { + return this._Gender; + } + set + { + this.OnGenderChanging(value); + this._Gender = value; + this.OnGenderChanged(); + } + } + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + private global::Microsoft.OData.Service.Sample.TrippinInMemory.Models.PersonGender _Gender; + partial void OnGenderChanging(global::Microsoft.OData.Service.Sample.TrippinInMemory.Models.PersonGender value); + partial void OnGenderChanged(); + /// + /// There are no comments for Property Age in the schema. + /// + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + public global::System.Nullable Age + { + get + { + return this._Age; + } + set + { + this.OnAgeChanging(value); + this._Age = value; + this.OnAgeChanged(); + } + } + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + private global::System.Nullable _Age; + partial void OnAgeChanging(global::System.Nullable value); + partial void OnAgeChanged(); + /// + /// There are no comments for Property HomeAddress in the schema. + /// + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + public global::Microsoft.OData.Service.Sample.TrippinInMemory.Models.Location HomeAddress + { + get + { + return this._HomeAddress; + } + set + { + this.OnHomeAddressChanging(value); + this._HomeAddress = value; + this.OnHomeAddressChanged(); + } + } + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + private global::Microsoft.OData.Service.Sample.TrippinInMemory.Models.Location _HomeAddress; + partial void OnHomeAddressChanging(global::Microsoft.OData.Service.Sample.TrippinInMemory.Models.Location value); + partial void OnHomeAddressChanged(); + /// + /// There are no comments for Property Friends in the schema. + /// + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + public global::System.Collections.ObjectModel.Collection Friends + { + get + { + return this._Friends; + } + set + { + this.OnFriendsChanging(value); + this._Friends = value; + this.OnFriendsChanged(); + } + } + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + private global::System.Collections.ObjectModel.Collection _Friends = new global::System.Collections.ObjectModel.Collection(); + partial void OnFriendsChanging(global::System.Collections.ObjectModel.Collection value); + partial void OnFriendsChanged(); + /// + /// There are no comments for Property Trips in the schema. + /// + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + public global::System.Collections.ObjectModel.Collection Trips + { + get + { + return this._Trips; + } + set + { + this.OnTripsChanging(value); + this._Trips = value; + this.OnTripsChanged(); + } + } + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + private global::System.Collections.ObjectModel.Collection _Trips = new global::System.Collections.ObjectModel.Collection(); + partial void OnTripsChanging(global::System.Collections.ObjectModel.Collection value); + partial void OnTripsChanged(); + } + /// + /// There are no comments for AirlineSingle in the schema. + /// + public partial class AirlineSingle : global::Microsoft.OData.Client.DataServiceQuerySingle + { + /// + /// Initialize a new AirlineSingle object. + /// + public AirlineSingle(global::Microsoft.OData.Client.DataServiceContext context, string path) + : base(context, path) { } + + /// + /// Initialize a new AirlineSingle object. + /// + public AirlineSingle(global::Microsoft.OData.Client.DataServiceContext context, string path, bool isComposable) + : base(context, path, isComposable) { } + + /// + /// Initialize a new AirlineSingle object. + /// + public AirlineSingle(global::Microsoft.OData.Client.DataServiceQuerySingle query) + : base(query) { } + + } + /// + /// There are no comments for Airline in the schema. + /// + /// + /// AirlineCode + /// + [global::Microsoft.OData.Client.Key("AirlineCode")] + public partial class Airline : global::Microsoft.OData.Client.BaseEntityType + { + /// + /// Create a new Airline object. + /// + /// Initial value of AirlineCode. + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + public static Airline CreateAirline(string airlineCode) + { + Airline airline = new Airline(); + airline.AirlineCode = airlineCode; + return airline; + } + /// + /// There are no comments for Property AirlineCode in the schema. + /// + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + public string AirlineCode + { + get + { + return this._AirlineCode; + } + set + { + this.OnAirlineCodeChanging(value); + this._AirlineCode = value; + this.OnAirlineCodeChanged(); + } + } + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + private string _AirlineCode; + partial void OnAirlineCodeChanging(string value); + partial void OnAirlineCodeChanged(); + /// + /// There are no comments for Property Name in the schema. + /// + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + public string Name + { + get + { + return this._Name; + } + set + { + this.OnNameChanging(value); + this._Name = value; + this.OnNameChanged(); + } + } + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + private string _Name; + partial void OnNameChanging(string value); + partial void OnNameChanged(); + } + /// + /// There are no comments for AirportSingle in the schema. + /// + public partial class AirportSingle : global::Microsoft.OData.Client.DataServiceQuerySingle + { + /// + /// Initialize a new AirportSingle object. + /// + public AirportSingle(global::Microsoft.OData.Client.DataServiceContext context, string path) + : base(context, path) { } + + /// + /// Initialize a new AirportSingle object. + /// + public AirportSingle(global::Microsoft.OData.Client.DataServiceContext context, string path, bool isComposable) + : base(context, path, isComposable) { } + + /// + /// Initialize a new AirportSingle object. + /// + public AirportSingle(global::Microsoft.OData.Client.DataServiceQuerySingle query) + : base(query) { } + + } + /// + /// There are no comments for Airport in the schema. + /// + /// + /// IcaoCode + /// + [global::Microsoft.OData.Client.Key("IcaoCode")] + public partial class Airport : global::Microsoft.OData.Client.BaseEntityType + { + /// + /// Create a new Airport object. + /// + /// Initial value of IcaoCode. + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + public static Airport CreateAirport(string icaoCode) + { + Airport airport = new Airport(); + airport.IcaoCode = icaoCode; + return airport; + } + /// + /// There are no comments for Property Name in the schema. + /// + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + public string Name + { + get + { + return this._Name; + } + set + { + this.OnNameChanging(value); + this._Name = value; + this.OnNameChanged(); + } + } + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + private string _Name; + partial void OnNameChanging(string value); + partial void OnNameChanged(); + /// + /// There are no comments for Property IcaoCode in the schema. + /// + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + public string IcaoCode + { + get + { + return this._IcaoCode; + } + set + { + this.OnIcaoCodeChanging(value); + this._IcaoCode = value; + this.OnIcaoCodeChanged(); + } + } + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + private string _IcaoCode; + partial void OnIcaoCodeChanging(string value); + partial void OnIcaoCodeChanged(); + } + /// + /// There are no comments for Location in the schema. + /// + public partial class Location + { + /// + /// There are no comments for Property Address in the schema. + /// + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + public string Address + { + get + { + return this._Address; + } + set + { + this.OnAddressChanging(value); + this._Address = value; + this.OnAddressChanged(); + } + } + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + private string _Address; + partial void OnAddressChanging(string value); + partial void OnAddressChanged(); + /// + /// There are no comments for Property City in the schema. + /// + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + public global::Microsoft.OData.Service.Sample.TrippinInMemory.Models.City City + { + get + { + return this._City; + } + set + { + this.OnCityChanging(value); + this._City = value; + this.OnCityChanged(); + } + } + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + private global::Microsoft.OData.Service.Sample.TrippinInMemory.Models.City _City; + partial void OnCityChanging(global::Microsoft.OData.Service.Sample.TrippinInMemory.Models.City value); + partial void OnCityChanged(); + } + /// + /// There are no comments for City in the schema. + /// + public partial class City + { + /// + /// There are no comments for Property Name in the schema. + /// + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + public string Name + { + get + { + return this._Name; + } + set + { + this.OnNameChanging(value); + this._Name = value; + this.OnNameChanged(); + } + } + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + private string _Name; + partial void OnNameChanging(string value); + partial void OnNameChanged(); + } + /// + /// There are no comments for TripSingle in the schema. + /// + public partial class TripSingle : global::Microsoft.OData.Client.DataServiceQuerySingle + { + /// + /// Initialize a new TripSingle object. + /// + public TripSingle(global::Microsoft.OData.Client.DataServiceContext context, string path) + : base(context, path) { } + + /// + /// Initialize a new TripSingle object. + /// + public TripSingle(global::Microsoft.OData.Client.DataServiceContext context, string path, bool isComposable) + : base(context, path, isComposable) { } + + /// + /// Initialize a new TripSingle object. + /// + public TripSingle(global::Microsoft.OData.Client.DataServiceQuerySingle query) + : base(query) { } + + } + /// + /// There are no comments for Trip in the schema. + /// + /// + /// TripId + /// + [global::Microsoft.OData.Client.Key("TripId")] + public partial class Trip : global::Microsoft.OData.Client.BaseEntityType + { + /// + /// Create a new Trip object. + /// + /// Initial value of TripId. + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + public static Trip CreateTrip(int tripId) + { + Trip trip = new Trip(); + trip.TripId = tripId; + return trip; + } + /// + /// There are no comments for Property TripId in the schema. + /// + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + public int TripId + { + get + { + return this._TripId; + } + set + { + this.OnTripIdChanging(value); + this._TripId = value; + this.OnTripIdChanged(); + } + } + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + private int _TripId; + partial void OnTripIdChanging(int value); + partial void OnTripIdChanged(); + /// + /// There are no comments for Property Name in the schema. + /// + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + public string Name + { + get + { + return this._Name; + } + set + { + this.OnNameChanging(value); + this._Name = value; + this.OnNameChanged(); + } + } + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + private string _Name; + partial void OnNameChanging(string value); + partial void OnNameChanged(); + } + /// + /// There are no comments for FlightSingle in the schema. + /// + public partial class FlightSingle : global::Microsoft.OData.Client.DataServiceQuerySingle + { + /// + /// Initialize a new FlightSingle object. + /// + public FlightSingle(global::Microsoft.OData.Client.DataServiceContext context, string path) + : base(context, path) { } + + /// + /// Initialize a new FlightSingle object. + /// + public FlightSingle(global::Microsoft.OData.Client.DataServiceContext context, string path, bool isComposable) + : base(context, path, isComposable) { } + + /// + /// Initialize a new FlightSingle object. + /// + public FlightSingle(global::Microsoft.OData.Client.DataServiceQuerySingle query) + : base(query) { } + + /// + /// There are no comments for Airline in the schema. + /// + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + public global::Microsoft.OData.Service.Sample.TrippinInMemory.Models.AirlineSingle Airline + { + get + { + if (!this.IsComposable) + { + throw new global::System.NotSupportedException("The previous function is not composable."); + } + if ((this._Airline == null)) + { + this._Airline = new global::Microsoft.OData.Service.Sample.TrippinInMemory.Models.AirlineSingle(this.Context, GetPath("Airline")); + } + return this._Airline; + } + } + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + private global::Microsoft.OData.Service.Sample.TrippinInMemory.Models.AirlineSingle _Airline; + /// + /// There are no comments for From in the schema. + /// + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + public global::Microsoft.OData.Service.Sample.TrippinInMemory.Models.AirportSingle From + { + get + { + if (!this.IsComposable) + { + throw new global::System.NotSupportedException("The previous function is not composable."); + } + if ((this._From == null)) + { + this._From = new global::Microsoft.OData.Service.Sample.TrippinInMemory.Models.AirportSingle(this.Context, GetPath("From")); + } + return this._From; + } + } + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + private global::Microsoft.OData.Service.Sample.TrippinInMemory.Models.AirportSingle _From; + /// + /// There are no comments for To in the schema. + /// + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + public global::Microsoft.OData.Service.Sample.TrippinInMemory.Models.AirportSingle To + { + get + { + if (!this.IsComposable) + { + throw new global::System.NotSupportedException("The previous function is not composable."); + } + if ((this._To == null)) + { + this._To = new global::Microsoft.OData.Service.Sample.TrippinInMemory.Models.AirportSingle(this.Context, GetPath("To")); + } + return this._To; + } + } + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + private global::Microsoft.OData.Service.Sample.TrippinInMemory.Models.AirportSingle _To; + } + /// + /// There are no comments for Flight in the schema. + /// + [global::Microsoft.OData.Client.EntityType()] + public partial class Flight : PublicTransportation + { + /// + /// There are no comments for Property FlightNumber in the schema. + /// + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + public string FlightNumber + { + get + { + return this._FlightNumber; + } + set + { + this.OnFlightNumberChanging(value); + this._FlightNumber = value; + this.OnFlightNumberChanged(); + } + } + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + private string _FlightNumber; + partial void OnFlightNumberChanging(string value); + partial void OnFlightNumberChanged(); + /// + /// There are no comments for Property Airline in the schema. + /// + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + public global::Microsoft.OData.Service.Sample.TrippinInMemory.Models.Airline Airline + { + get + { + return this._Airline; + } + set + { + this.OnAirlineChanging(value); + this._Airline = value; + this.OnAirlineChanged(); + } + } + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + private global::Microsoft.OData.Service.Sample.TrippinInMemory.Models.Airline _Airline; + partial void OnAirlineChanging(global::Microsoft.OData.Service.Sample.TrippinInMemory.Models.Airline value); + partial void OnAirlineChanged(); + /// + /// There are no comments for Property From in the schema. + /// + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + public global::Microsoft.OData.Service.Sample.TrippinInMemory.Models.Airport From + { + get + { + return this._From; + } + set + { + this.OnFromChanging(value); + this._From = value; + this.OnFromChanged(); + } + } + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + private global::Microsoft.OData.Service.Sample.TrippinInMemory.Models.Airport _From; + partial void OnFromChanging(global::Microsoft.OData.Service.Sample.TrippinInMemory.Models.Airport value); + partial void OnFromChanged(); + /// + /// There are no comments for Property To in the schema. + /// + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + public global::Microsoft.OData.Service.Sample.TrippinInMemory.Models.Airport To + { + get + { + return this._To; + } + set + { + this.OnToChanging(value); + this._To = value; + this.OnToChanged(); + } + } + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + private global::Microsoft.OData.Service.Sample.TrippinInMemory.Models.Airport _To; + partial void OnToChanging(global::Microsoft.OData.Service.Sample.TrippinInMemory.Models.Airport value); + partial void OnToChanged(); + } + /// + /// There are no comments for EmployeeSingle in the schema. + /// + public partial class EmployeeSingle : global::Microsoft.OData.Client.DataServiceQuerySingle + { + /// + /// Initialize a new EmployeeSingle object. + /// + public EmployeeSingle(global::Microsoft.OData.Client.DataServiceContext context, string path) + : base(context, path) { } + + /// + /// Initialize a new EmployeeSingle object. + /// + public EmployeeSingle(global::Microsoft.OData.Client.DataServiceContext context, string path, bool isComposable) + : base(context, path, isComposable) { } + + /// + /// Initialize a new EmployeeSingle object. + /// + public EmployeeSingle(global::Microsoft.OData.Client.DataServiceQuerySingle query) + : base(query) { } + + /// + /// There are no comments for Peers in the schema. + /// + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + public global::Microsoft.OData.Client.DataServiceQuery Peers + { + get + { + if (!this.IsComposable) + { + throw new global::System.NotSupportedException("The previous function is not composable."); + } + if ((this._Peers == null)) + { + this._Peers = Context.CreateQuery(GetPath("Peers")); + } + return this._Peers; + } + } + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + private global::Microsoft.OData.Client.DataServiceQuery _Peers; + /// + /// There are no comments for Friends in the schema. + /// + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + public global::Microsoft.OData.Client.DataServiceQuery Friends + { + get + { + if (!this.IsComposable) + { + throw new global::System.NotSupportedException("The previous function is not composable."); + } + if ((this._Friends == null)) + { + this._Friends = Context.CreateQuery(GetPath("Friends")); + } + return this._Friends; + } + } + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + private global::Microsoft.OData.Client.DataServiceQuery _Friends; + /// + /// There are no comments for Trips in the schema. + /// + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + public global::Microsoft.OData.Client.DataServiceQuery Trips + { + get + { + if (!this.IsComposable) + { + throw new global::System.NotSupportedException("The previous function is not composable."); + } + if ((this._Trips == null)) + { + this._Trips = Context.CreateQuery(GetPath("Trips")); + } + return this._Trips; + } + } + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + private global::Microsoft.OData.Client.DataServiceQuery _Trips; + } + /// + /// There are no comments for Employee in the schema. + /// + /// + /// UserName + /// + [global::Microsoft.OData.Client.Key("UserName")] + public partial class Employee : Person + { + /// + /// Create a new Employee object. + /// + /// Initial value of UserName. + /// Initial value of Gender. + /// Initial value of Cost. + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + public static Employee CreateEmployee(string userName, global::Microsoft.OData.Service.Sample.TrippinInMemory.Models.PersonGender gender, long cost) + { + Employee employee = new Employee(); + employee.UserName = userName; + employee.Gender = gender; + employee.Cost = cost; + return employee; + } + /// + /// There are no comments for Property Cost in the schema. + /// + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + public long Cost + { + get + { + return this._Cost; + } + set + { + this.OnCostChanging(value); + this._Cost = value; + this.OnCostChanged(); + } + } + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + private long _Cost; + partial void OnCostChanging(long value); + partial void OnCostChanged(); + /// + /// There are no comments for Property Peers in the schema. + /// + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + public global::System.Collections.ObjectModel.Collection Peers + { + get + { + return this._Peers; + } + set + { + this.OnPeersChanging(value); + this._Peers = value; + this.OnPeersChanged(); + } + } + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + private global::System.Collections.ObjectModel.Collection _Peers = new global::System.Collections.ObjectModel.Collection(); + partial void OnPeersChanging(global::System.Collections.ObjectModel.Collection value); + partial void OnPeersChanged(); + } + /// + /// There are no comments for PersonGender in the schema. + /// + public enum PersonGender + { + Male = 0, + Female = 1, + Unknow = 2 + } + /// + /// Class containing all extension methods + /// + public static class ExtensionMethods + { + /// + /// Get an entity of type global::Microsoft.OData.Service.Sample.TrippinInMemory.Models.Person as global::Microsoft.OData.Service.Sample.TrippinInMemory.Models.PersonSingle specified by key from an entity set + /// + /// source entity set + /// dictionary with the names and values of keys + public static global::Microsoft.OData.Service.Sample.TrippinInMemory.Models.PersonSingle ByKey(this global::Microsoft.OData.Client.DataServiceQuery source, global::System.Collections.Generic.Dictionary keys) + { + return new global::Microsoft.OData.Service.Sample.TrippinInMemory.Models.PersonSingle(source.Context, source.GetKeyPath(global::Microsoft.OData.Client.Serializer.GetKeyString(source.Context, keys))); + } + /// + /// Get an entity of type global::Microsoft.OData.Service.Sample.TrippinInMemory.Models.Person as global::Microsoft.OData.Service.Sample.TrippinInMemory.Models.PersonSingle specified by key from an entity set + /// + /// source entity set + /// The value of userName + public static global::Microsoft.OData.Service.Sample.TrippinInMemory.Models.PersonSingle ByKey(this global::Microsoft.OData.Client.DataServiceQuery source, + string userName) + { + global::System.Collections.Generic.Dictionary keys = new global::System.Collections.Generic.Dictionary + { + { "UserName", userName } + }; + return new global::Microsoft.OData.Service.Sample.TrippinInMemory.Models.PersonSingle(source.Context, source.GetKeyPath(global::Microsoft.OData.Client.Serializer.GetKeyString(source.Context, keys))); + } + /// + /// Get an entity of type global::Microsoft.OData.Service.Sample.TrippinInMemory.Models.Airline as global::Microsoft.OData.Service.Sample.TrippinInMemory.Models.AirlineSingle specified by key from an entity set + /// + /// source entity set + /// dictionary with the names and values of keys + public static global::Microsoft.OData.Service.Sample.TrippinInMemory.Models.AirlineSingle ByKey(this global::Microsoft.OData.Client.DataServiceQuery source, global::System.Collections.Generic.Dictionary keys) + { + return new global::Microsoft.OData.Service.Sample.TrippinInMemory.Models.AirlineSingle(source.Context, source.GetKeyPath(global::Microsoft.OData.Client.Serializer.GetKeyString(source.Context, keys))); + } + /// + /// Get an entity of type global::Microsoft.OData.Service.Sample.TrippinInMemory.Models.Airline as global::Microsoft.OData.Service.Sample.TrippinInMemory.Models.AirlineSingle specified by key from an entity set + /// + /// source entity set + /// The value of airlineCode + public static global::Microsoft.OData.Service.Sample.TrippinInMemory.Models.AirlineSingle ByKey(this global::Microsoft.OData.Client.DataServiceQuery source, + string airlineCode) + { + global::System.Collections.Generic.Dictionary keys = new global::System.Collections.Generic.Dictionary + { + { "AirlineCode", airlineCode } + }; + return new global::Microsoft.OData.Service.Sample.TrippinInMemory.Models.AirlineSingle(source.Context, source.GetKeyPath(global::Microsoft.OData.Client.Serializer.GetKeyString(source.Context, keys))); + } + /// + /// Get an entity of type global::Microsoft.OData.Service.Sample.TrippinInMemory.Models.Airport as global::Microsoft.OData.Service.Sample.TrippinInMemory.Models.AirportSingle specified by key from an entity set + /// + /// source entity set + /// dictionary with the names and values of keys + public static global::Microsoft.OData.Service.Sample.TrippinInMemory.Models.AirportSingle ByKey(this global::Microsoft.OData.Client.DataServiceQuery source, global::System.Collections.Generic.Dictionary keys) + { + return new global::Microsoft.OData.Service.Sample.TrippinInMemory.Models.AirportSingle(source.Context, source.GetKeyPath(global::Microsoft.OData.Client.Serializer.GetKeyString(source.Context, keys))); + } + /// + /// Get an entity of type global::Microsoft.OData.Service.Sample.TrippinInMemory.Models.Airport as global::Microsoft.OData.Service.Sample.TrippinInMemory.Models.AirportSingle specified by key from an entity set + /// + /// source entity set + /// The value of icaoCode + public static global::Microsoft.OData.Service.Sample.TrippinInMemory.Models.AirportSingle ByKey(this global::Microsoft.OData.Client.DataServiceQuery source, + string icaoCode) + { + global::System.Collections.Generic.Dictionary keys = new global::System.Collections.Generic.Dictionary + { + { "IcaoCode", icaoCode } + }; + return new global::Microsoft.OData.Service.Sample.TrippinInMemory.Models.AirportSingle(source.Context, source.GetKeyPath(global::Microsoft.OData.Client.Serializer.GetKeyString(source.Context, keys))); + } + /// + /// Get an entity of type global::Microsoft.OData.Service.Sample.TrippinInMemory.Models.Trip as global::Microsoft.OData.Service.Sample.TrippinInMemory.Models.TripSingle specified by key from an entity set + /// + /// source entity set + /// dictionary with the names and values of keys + public static global::Microsoft.OData.Service.Sample.TrippinInMemory.Models.TripSingle ByKey(this global::Microsoft.OData.Client.DataServiceQuery source, global::System.Collections.Generic.Dictionary keys) + { + return new global::Microsoft.OData.Service.Sample.TrippinInMemory.Models.TripSingle(source.Context, source.GetKeyPath(global::Microsoft.OData.Client.Serializer.GetKeyString(source.Context, keys))); + } + /// + /// Get an entity of type global::Microsoft.OData.Service.Sample.TrippinInMemory.Models.Trip as global::Microsoft.OData.Service.Sample.TrippinInMemory.Models.TripSingle specified by key from an entity set + /// + /// source entity set + /// The value of tripId + public static global::Microsoft.OData.Service.Sample.TrippinInMemory.Models.TripSingle ByKey(this global::Microsoft.OData.Client.DataServiceQuery source, + int tripId) + { + global::System.Collections.Generic.Dictionary keys = new global::System.Collections.Generic.Dictionary + { + { "TripId", tripId } + }; + return new global::Microsoft.OData.Service.Sample.TrippinInMemory.Models.TripSingle(source.Context, source.GetKeyPath(global::Microsoft.OData.Client.Serializer.GetKeyString(source.Context, keys))); + } + /// + /// Cast an entity of type global::Microsoft.OData.Service.Sample.TrippinInMemory.Models.PublicTransportation to its derived type global::Microsoft.OData.Service.Sample.TrippinInMemory.Models.Flight + /// + /// source entity + public static global::Microsoft.OData.Service.Sample.TrippinInMemory.Models.FlightSingle CastToFlight(this global::Microsoft.OData.Client.DataServiceQuerySingle source) + { + global::Microsoft.OData.Client.DataServiceQuerySingle query = source.CastTo(); + return new global::Microsoft.OData.Service.Sample.TrippinInMemory.Models.FlightSingle(source.Context, query.GetPath(null)); + } + /// + /// Get an entity of type global::Microsoft.OData.Service.Sample.TrippinInMemory.Models.Employee as global::Microsoft.OData.Service.Sample.TrippinInMemory.Models.EmployeeSingle specified by key from an entity set + /// + /// source entity set + /// dictionary with the names and values of keys + public static global::Microsoft.OData.Service.Sample.TrippinInMemory.Models.EmployeeSingle ByKey(this global::Microsoft.OData.Client.DataServiceQuery source, global::System.Collections.Generic.Dictionary keys) + { + return new global::Microsoft.OData.Service.Sample.TrippinInMemory.Models.EmployeeSingle(source.Context, source.GetKeyPath(global::Microsoft.OData.Client.Serializer.GetKeyString(source.Context, keys))); + } + /// + /// Get an entity of type global::Microsoft.OData.Service.Sample.TrippinInMemory.Models.Employee as global::Microsoft.OData.Service.Sample.TrippinInMemory.Models.EmployeeSingle specified by key from an entity set + /// + /// source entity set + /// The value of userName + public static global::Microsoft.OData.Service.Sample.TrippinInMemory.Models.EmployeeSingle ByKey(this global::Microsoft.OData.Client.DataServiceQuery source, + string userName) + { + global::System.Collections.Generic.Dictionary keys = new global::System.Collections.Generic.Dictionary + { + { "UserName", userName } + }; + return new global::Microsoft.OData.Service.Sample.TrippinInMemory.Models.EmployeeSingle(source.Context, source.GetKeyPath(global::Microsoft.OData.Client.Serializer.GetKeyString(source.Context, keys))); + } + /// + /// Cast an entity of type global::Microsoft.OData.Service.Sample.TrippinInMemory.Models.Person to its derived type global::Microsoft.OData.Service.Sample.TrippinInMemory.Models.Employee + /// + /// source entity + public static global::Microsoft.OData.Service.Sample.TrippinInMemory.Models.EmployeeSingle CastToEmployee(this global::Microsoft.OData.Client.DataServiceQuerySingle source) + { + global::Microsoft.OData.Client.DataServiceQuerySingle query = source.CastTo(); + return new global::Microsoft.OData.Service.Sample.TrippinInMemory.Models.EmployeeSingle(source.Context, query.GetPath(null)); + } + } +} diff --git a/ODataConnectedService/test/ODataConnectedService.Tests/CodeGenReferences/EntitiesEnumsFunctions.xml b/ODataConnectedService/test/ODataConnectedService.Tests/CodeGenReferences/EntitiesEnumsFunctions.xml new file mode 100644 index 0000000..92af564 --- /dev/null +++ b/ODataConnectedService/test/ODataConnectedService.Tests/CodeGenReferences/EntitiesEnumsFunctions.xml @@ -0,0 +1,81 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/ODataConnectedService/test/ODataConnectedService.Tests/CodeGenReferences/EntitiesEnumsFunctionsDSC.cs b/ODataConnectedService/test/ODataConnectedService.Tests/CodeGenReferences/EntitiesEnumsFunctionsDSC.cs new file mode 100644 index 0000000..7a3c074 --- /dev/null +++ b/ODataConnectedService/test/ODataConnectedService.Tests/CodeGenReferences/EntitiesEnumsFunctionsDSC.cs @@ -0,0 +1,1423 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by a tool. +// Runtime Version:4.0.30319.42000 +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +// Generation date: 1/21/2020 11:33:16 AM +namespace Microsoft.OData.Service.Sample.TrippinInMemory.Models +{ + /// + /// There are no comments for Container in the schema. + /// + public partial class Container : global::Microsoft.OData.Client.DataServiceContext + { + /// + /// Initialize a new Container object. + /// + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + public Container(global::System.Uri serviceRoot) : + base(serviceRoot, global::Microsoft.OData.Client.ODataProtocolVersion.V4) + { + this.ResolveName = new global::System.Func(this.ResolveNameFromType); + this.OnContextCreated(); + this.Format.LoadServiceModel = GeneratedEdmModel.GetInstance; + this.Format.UseJson(); + } + partial void OnContextCreated(); + /// + /// Since the namespace configured for this service reference + /// in Visual Studio is different from the one indicated in the + /// server schema, use type-mappers to map between the two. + /// + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + protected string ResolveNameFromType(global::System.Type clientType) + { + return clientType.FullName; + } + /// + /// There are no comments for People in the schema. + /// + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + public global::Microsoft.OData.Client.DataServiceQuery People + { + get + { + if ((this._People == null)) + { + this._People = base.CreateQuery("People"); + } + return this._People; + } + } + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + private global::Microsoft.OData.Client.DataServiceQuery _People; + /// + /// There are no comments for Airlines in the schema. + /// + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + public global::Microsoft.OData.Client.DataServiceQuery Airlines + { + get + { + if ((this._Airlines == null)) + { + this._Airlines = base.CreateQuery("Airlines"); + } + return this._Airlines; + } + } + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + private global::Microsoft.OData.Client.DataServiceQuery _Airlines; + /// + /// There are no comments for Airports in the schema. + /// + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + public global::Microsoft.OData.Client.DataServiceQuery Airports + { + get + { + if ((this._Airports == null)) + { + this._Airports = base.CreateQuery("Airports"); + } + return this._Airports; + } + } + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + private global::Microsoft.OData.Client.DataServiceQuery _Airports; + /// + /// There are no comments for People in the schema. + /// + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + public void AddToPeople(Person person) + { + base.AddObject("People", person); + } + /// + /// There are no comments for Airlines in the schema. + /// + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + public void AddToAirlines(Airline airline) + { + base.AddObject("Airlines", airline); + } + /// + /// There are no comments for Airports in the schema. + /// + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + public void AddToAirports(Airport airport) + { + base.AddObject("Airports", airport); + } + /// + /// There are no comments for Me in the schema. + /// + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + public PersonSingle Me + { + get + { + if ((this._Me == null)) + { + this._Me = new PersonSingle(this, "Me"); + } + return this._Me; + } + } + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + private PersonSingle _Me; + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + private abstract class GeneratedEdmModel + { + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + private static global::Microsoft.OData.Edm.IEdmModel ParsedModel = LoadModelFromString(); + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + private const string Edmx = @" + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +"; + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + public static global::Microsoft.OData.Edm.IEdmModel GetInstance() + { + return ParsedModel; + } + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + private static global::Microsoft.OData.Edm.IEdmModel LoadModelFromString() + { + global::System.Xml.XmlReader reader = CreateXmlReader(Edmx); + try + { + return global::Microsoft.OData.Edm.Csdl.CsdlReader.Parse(reader); + } + finally + { + ((global::System.IDisposable)(reader)).Dispose(); + } + } + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + private static global::System.Xml.XmlReader CreateXmlReader(string edmxToParse) + { + return global::System.Xml.XmlReader.Create(new global::System.IO.StringReader(edmxToParse)); + } + } + /// + /// There are no comments for GetPersonWithMostFriends in the schema. + /// + public global::Microsoft.OData.Service.Sample.TrippinInMemory.Models.PersonSingle GetPersonWithMostFriends() + { + return new global::Microsoft.OData.Service.Sample.TrippinInMemory.Models.PersonSingle(this.CreateFunctionQuerySingle("", "GetPersonWithMostFriends", false)); + } + /// + /// There are no comments for GetNearestAirport in the schema. + /// + public global::Microsoft.OData.Service.Sample.TrippinInMemory.Models.AirportSingle GetNearestAirport(double lat, double lon) + { + return new global::Microsoft.OData.Service.Sample.TrippinInMemory.Models.AirportSingle(this.CreateFunctionQuerySingle("", "GetNearestAirport", false, new global::Microsoft.OData.Client.UriOperationParameter("lat", lat), + new global::Microsoft.OData.Client.UriOperationParameter("lon", lon))); + } + /// + /// There are no comments for ResetDataSource in the schema. + /// + public global::Microsoft.OData.Client.DataServiceActionQuery ResetDataSource() + { + return new global::Microsoft.OData.Client.DataServiceActionQuery(this, this.BaseUri.OriginalString.Trim('/') + "/ResetDataSource"); + } + } + /// + /// There are no comments for PersonSingle in the schema. + /// + public partial class PersonSingle : global::Microsoft.OData.Client.DataServiceQuerySingle + { + /// + /// Initialize a new PersonSingle object. + /// + public PersonSingle(global::Microsoft.OData.Client.DataServiceContext context, string path) + : base(context, path) { } + + /// + /// Initialize a new PersonSingle object. + /// + public PersonSingle(global::Microsoft.OData.Client.DataServiceContext context, string path, bool isComposable) + : base(context, path, isComposable) { } + + /// + /// Initialize a new PersonSingle object. + /// + public PersonSingle(global::Microsoft.OData.Client.DataServiceQuerySingle query) + : base(query) { } + + /// + /// There are no comments for Friends in the schema. + /// + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + public global::Microsoft.OData.Client.DataServiceQuery Friends + { + get + { + if (!this.IsComposable) + { + throw new global::System.NotSupportedException("The previous function is not composable."); + } + if ((this._Friends == null)) + { + this._Friends = Context.CreateQuery(GetPath("Friends")); + } + return this._Friends; + } + } + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + private global::Microsoft.OData.Client.DataServiceQuery _Friends; + /// + /// There are no comments for Trips in the schema. + /// + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + public global::Microsoft.OData.Client.DataServiceQuery Trips + { + get + { + if (!this.IsComposable) + { + throw new global::System.NotSupportedException("The previous function is not composable."); + } + if ((this._Trips == null)) + { + this._Trips = Context.CreateQuery(GetPath("Trips")); + } + return this._Trips; + } + } + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + private global::Microsoft.OData.Client.DataServiceQuery _Trips; + } + /// + /// There are no comments for Person in the schema. + /// + /// + /// UserName + /// + [global::Microsoft.OData.Client.Key("UserName")] + public partial class Person : global::Microsoft.OData.Client.BaseEntityType, global::System.ComponentModel.INotifyPropertyChanged + { + /// + /// Create a new Person object. + /// + /// Initial value of UserName. + /// Initial value of Gender. + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + public static Person CreatePerson(string userName, global::Microsoft.OData.Service.Sample.TrippinInMemory.Models.PersonGender gender) + { + Person person = new Person(); + person.UserName = userName; + person.Gender = gender; + return person; + } + /// + /// There are no comments for Property UserName in the schema. + /// + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + public string UserName + { + get + { + return this._UserName; + } + set + { + this.OnUserNameChanging(value); + this._UserName = value; + this.OnUserNameChanged(); + this.OnPropertyChanged("UserName"); + } + } + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + private string _UserName; + partial void OnUserNameChanging(string value); + partial void OnUserNameChanged(); + /// + /// There are no comments for Property Gender in the schema. + /// + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + public global::Microsoft.OData.Service.Sample.TrippinInMemory.Models.PersonGender Gender + { + get + { + return this._Gender; + } + set + { + this.OnGenderChanging(value); + this._Gender = value; + this.OnGenderChanged(); + this.OnPropertyChanged("Gender"); + } + } + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + private global::Microsoft.OData.Service.Sample.TrippinInMemory.Models.PersonGender _Gender; + partial void OnGenderChanging(global::Microsoft.OData.Service.Sample.TrippinInMemory.Models.PersonGender value); + partial void OnGenderChanged(); + /// + /// There are no comments for Property Age in the schema. + /// + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + public global::System.Nullable Age + { + get + { + return this._Age; + } + set + { + this.OnAgeChanging(value); + this._Age = value; + this.OnAgeChanged(); + this.OnPropertyChanged("Age"); + } + } + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + private global::System.Nullable _Age; + partial void OnAgeChanging(global::System.Nullable value); + partial void OnAgeChanged(); + /// + /// There are no comments for Property HomeAddress in the schema. + /// + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + public global::Microsoft.OData.Service.Sample.TrippinInMemory.Models.Location HomeAddress + { + get + { + return this._HomeAddress; + } + set + { + this.OnHomeAddressChanging(value); + this._HomeAddress = value; + this.OnHomeAddressChanged(); + this.OnPropertyChanged("HomeAddress"); + } + } + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + private global::Microsoft.OData.Service.Sample.TrippinInMemory.Models.Location _HomeAddress; + partial void OnHomeAddressChanging(global::Microsoft.OData.Service.Sample.TrippinInMemory.Models.Location value); + partial void OnHomeAddressChanged(); + /// + /// There are no comments for Property Friends in the schema. + /// + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + public global::Microsoft.OData.Client.DataServiceCollection Friends + { + get + { + return this._Friends; + } + set + { + this.OnFriendsChanging(value); + this._Friends = value; + this.OnFriendsChanged(); + this.OnPropertyChanged("Friends"); + } + } + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + private global::Microsoft.OData.Client.DataServiceCollection _Friends = new global::Microsoft.OData.Client.DataServiceCollection(null, global::Microsoft.OData.Client.TrackingMode.None); + partial void OnFriendsChanging(global::Microsoft.OData.Client.DataServiceCollection value); + partial void OnFriendsChanged(); + /// + /// There are no comments for Property Trips in the schema. + /// + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + public global::Microsoft.OData.Client.DataServiceCollection Trips + { + get + { + return this._Trips; + } + set + { + this.OnTripsChanging(value); + this._Trips = value; + this.OnTripsChanged(); + this.OnPropertyChanged("Trips"); + } + } + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + private global::Microsoft.OData.Client.DataServiceCollection _Trips = new global::Microsoft.OData.Client.DataServiceCollection(null, global::Microsoft.OData.Client.TrackingMode.None); + partial void OnTripsChanging(global::Microsoft.OData.Client.DataServiceCollection value); + partial void OnTripsChanged(); + /// + /// This event is raised when the value of the property is changed + /// + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + public event global::System.ComponentModel.PropertyChangedEventHandler PropertyChanged; + /// + /// The value of the property is changed + /// + /// property name + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + protected virtual void OnPropertyChanged(string property) + { + if ((this.PropertyChanged != null)) + { + this.PropertyChanged(this, new global::System.ComponentModel.PropertyChangedEventArgs(property)); + } + } + } + /// + /// There are no comments for AirlineSingle in the schema. + /// + public partial class AirlineSingle : global::Microsoft.OData.Client.DataServiceQuerySingle + { + /// + /// Initialize a new AirlineSingle object. + /// + public AirlineSingle(global::Microsoft.OData.Client.DataServiceContext context, string path) + : base(context, path) { } + + /// + /// Initialize a new AirlineSingle object. + /// + public AirlineSingle(global::Microsoft.OData.Client.DataServiceContext context, string path, bool isComposable) + : base(context, path, isComposable) { } + + /// + /// Initialize a new AirlineSingle object. + /// + public AirlineSingle(global::Microsoft.OData.Client.DataServiceQuerySingle query) + : base(query) { } + + } + /// + /// There are no comments for Airline in the schema. + /// + /// + /// AirlineCode + /// + [global::Microsoft.OData.Client.Key("AirlineCode")] + [global::Microsoft.OData.Client.EntitySet("Airlines")] + public partial class Airline : global::Microsoft.OData.Client.BaseEntityType, global::System.ComponentModel.INotifyPropertyChanged + { + /// + /// Create a new Airline object. + /// + /// Initial value of AirlineCode. + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + public static Airline CreateAirline(string airlineCode) + { + Airline airline = new Airline(); + airline.AirlineCode = airlineCode; + return airline; + } + /// + /// There are no comments for Property AirlineCode in the schema. + /// + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + public string AirlineCode + { + get + { + return this._AirlineCode; + } + set + { + this.OnAirlineCodeChanging(value); + this._AirlineCode = value; + this.OnAirlineCodeChanged(); + this.OnPropertyChanged("AirlineCode"); + } + } + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + private string _AirlineCode; + partial void OnAirlineCodeChanging(string value); + partial void OnAirlineCodeChanged(); + /// + /// There are no comments for Property Name in the schema. + /// + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + public string Name + { + get + { + return this._Name; + } + set + { + this.OnNameChanging(value); + this._Name = value; + this.OnNameChanged(); + this.OnPropertyChanged("Name"); + } + } + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + private string _Name; + partial void OnNameChanging(string value); + partial void OnNameChanged(); + /// + /// This event is raised when the value of the property is changed + /// + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + public event global::System.ComponentModel.PropertyChangedEventHandler PropertyChanged; + /// + /// The value of the property is changed + /// + /// property name + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + protected virtual void OnPropertyChanged(string property) + { + if ((this.PropertyChanged != null)) + { + this.PropertyChanged(this, new global::System.ComponentModel.PropertyChangedEventArgs(property)); + } + } + } + /// + /// There are no comments for AirportSingle in the schema. + /// + public partial class AirportSingle : global::Microsoft.OData.Client.DataServiceQuerySingle + { + /// + /// Initialize a new AirportSingle object. + /// + public AirportSingle(global::Microsoft.OData.Client.DataServiceContext context, string path) + : base(context, path) { } + + /// + /// Initialize a new AirportSingle object. + /// + public AirportSingle(global::Microsoft.OData.Client.DataServiceContext context, string path, bool isComposable) + : base(context, path, isComposable) { } + + /// + /// Initialize a new AirportSingle object. + /// + public AirportSingle(global::Microsoft.OData.Client.DataServiceQuerySingle query) + : base(query) { } + + } + /// + /// There are no comments for Airport in the schema. + /// + /// + /// IcaoCode + /// + [global::Microsoft.OData.Client.Key("IcaoCode")] + [global::Microsoft.OData.Client.EntitySet("Airports")] + public partial class Airport : global::Microsoft.OData.Client.BaseEntityType, global::System.ComponentModel.INotifyPropertyChanged + { + /// + /// Create a new Airport object. + /// + /// Initial value of IcaoCode. + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + public static Airport CreateAirport(string icaoCode) + { + Airport airport = new Airport(); + airport.IcaoCode = icaoCode; + return airport; + } + /// + /// There are no comments for Property Name in the schema. + /// + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + public string Name + { + get + { + return this._Name; + } + set + { + this.OnNameChanging(value); + this._Name = value; + this.OnNameChanged(); + this.OnPropertyChanged("Name"); + } + } + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + private string _Name; + partial void OnNameChanging(string value); + partial void OnNameChanged(); + /// + /// There are no comments for Property IcaoCode in the schema. + /// + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + public string IcaoCode + { + get + { + return this._IcaoCode; + } + set + { + this.OnIcaoCodeChanging(value); + this._IcaoCode = value; + this.OnIcaoCodeChanged(); + this.OnPropertyChanged("IcaoCode"); + } + } + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + private string _IcaoCode; + partial void OnIcaoCodeChanging(string value); + partial void OnIcaoCodeChanged(); + /// + /// This event is raised when the value of the property is changed + /// + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + public event global::System.ComponentModel.PropertyChangedEventHandler PropertyChanged; + /// + /// The value of the property is changed + /// + /// property name + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + protected virtual void OnPropertyChanged(string property) + { + if ((this.PropertyChanged != null)) + { + this.PropertyChanged(this, new global::System.ComponentModel.PropertyChangedEventArgs(property)); + } + } + } + /// + /// There are no comments for Location in the schema. + /// + public partial class Location : global::System.ComponentModel.INotifyPropertyChanged + { + /// + /// There are no comments for Property Address in the schema. + /// + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + public string Address + { + get + { + return this._Address; + } + set + { + this.OnAddressChanging(value); + this._Address = value; + this.OnAddressChanged(); + this.OnPropertyChanged("Address"); + } + } + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + private string _Address; + partial void OnAddressChanging(string value); + partial void OnAddressChanged(); + /// + /// There are no comments for Property City in the schema. + /// + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + public global::Microsoft.OData.Service.Sample.TrippinInMemory.Models.City City + { + get + { + return this._City; + } + set + { + this.OnCityChanging(value); + this._City = value; + this.OnCityChanged(); + this.OnPropertyChanged("City"); + } + } + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + private global::Microsoft.OData.Service.Sample.TrippinInMemory.Models.City _City; + partial void OnCityChanging(global::Microsoft.OData.Service.Sample.TrippinInMemory.Models.City value); + partial void OnCityChanged(); + /// + /// This event is raised when the value of the property is changed + /// + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + public event global::System.ComponentModel.PropertyChangedEventHandler PropertyChanged; + /// + /// The value of the property is changed + /// + /// property name + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + protected virtual void OnPropertyChanged(string property) + { + if ((this.PropertyChanged != null)) + { + this.PropertyChanged(this, new global::System.ComponentModel.PropertyChangedEventArgs(property)); + } + } + } + /// + /// There are no comments for City in the schema. + /// + public partial class City : global::System.ComponentModel.INotifyPropertyChanged + { + /// + /// There are no comments for Property Name in the schema. + /// + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + public string Name + { + get + { + return this._Name; + } + set + { + this.OnNameChanging(value); + this._Name = value; + this.OnNameChanged(); + this.OnPropertyChanged("Name"); + } + } + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + private string _Name; + partial void OnNameChanging(string value); + partial void OnNameChanged(); + /// + /// This event is raised when the value of the property is changed + /// + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + public event global::System.ComponentModel.PropertyChangedEventHandler PropertyChanged; + /// + /// The value of the property is changed + /// + /// property name + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + protected virtual void OnPropertyChanged(string property) + { + if ((this.PropertyChanged != null)) + { + this.PropertyChanged(this, new global::System.ComponentModel.PropertyChangedEventArgs(property)); + } + } + } + /// + /// There are no comments for TripSingle in the schema. + /// + public partial class TripSingle : global::Microsoft.OData.Client.DataServiceQuerySingle + { + /// + /// Initialize a new TripSingle object. + /// + public TripSingle(global::Microsoft.OData.Client.DataServiceContext context, string path) + : base(context, path) { } + + /// + /// Initialize a new TripSingle object. + /// + public TripSingle(global::Microsoft.OData.Client.DataServiceContext context, string path, bool isComposable) + : base(context, path, isComposable) { } + + /// + /// Initialize a new TripSingle object. + /// + public TripSingle(global::Microsoft.OData.Client.DataServiceQuerySingle query) + : base(query) { } + + } + /// + /// There are no comments for Trip in the schema. + /// + /// + /// TripId + /// + [global::Microsoft.OData.Client.Key("TripId")] + public partial class Trip : global::Microsoft.OData.Client.BaseEntityType, global::System.ComponentModel.INotifyPropertyChanged + { + /// + /// Create a new Trip object. + /// + /// Initial value of TripId. + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + public static Trip CreateTrip(int tripId) + { + Trip trip = new Trip(); + trip.TripId = tripId; + return trip; + } + /// + /// There are no comments for Property TripId in the schema. + /// + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + public int TripId + { + get + { + return this._TripId; + } + set + { + this.OnTripIdChanging(value); + this._TripId = value; + this.OnTripIdChanged(); + this.OnPropertyChanged("TripId"); + } + } + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + private int _TripId; + partial void OnTripIdChanging(int value); + partial void OnTripIdChanged(); + /// + /// There are no comments for Property Name in the schema. + /// + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + public string Name + { + get + { + return this._Name; + } + set + { + this.OnNameChanging(value); + this._Name = value; + this.OnNameChanged(); + this.OnPropertyChanged("Name"); + } + } + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + private string _Name; + partial void OnNameChanging(string value); + partial void OnNameChanged(); + /// + /// This event is raised when the value of the property is changed + /// + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + public event global::System.ComponentModel.PropertyChangedEventHandler PropertyChanged; + /// + /// The value of the property is changed + /// + /// property name + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + protected virtual void OnPropertyChanged(string property) + { + if ((this.PropertyChanged != null)) + { + this.PropertyChanged(this, new global::System.ComponentModel.PropertyChangedEventArgs(property)); + } + } + } + /// + /// There are no comments for FlightSingle in the schema. + /// + public partial class FlightSingle : global::Microsoft.OData.Client.DataServiceQuerySingle + { + /// + /// Initialize a new FlightSingle object. + /// + public FlightSingle(global::Microsoft.OData.Client.DataServiceContext context, string path) + : base(context, path) { } + + /// + /// Initialize a new FlightSingle object. + /// + public FlightSingle(global::Microsoft.OData.Client.DataServiceContext context, string path, bool isComposable) + : base(context, path, isComposable) { } + + /// + /// Initialize a new FlightSingle object. + /// + public FlightSingle(global::Microsoft.OData.Client.DataServiceQuerySingle query) + : base(query) { } + + /// + /// There are no comments for Airline in the schema. + /// + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + public global::Microsoft.OData.Service.Sample.TrippinInMemory.Models.AirlineSingle Airline + { + get + { + if (!this.IsComposable) + { + throw new global::System.NotSupportedException("The previous function is not composable."); + } + if ((this._Airline == null)) + { + this._Airline = new global::Microsoft.OData.Service.Sample.TrippinInMemory.Models.AirlineSingle(this.Context, GetPath("Airline")); + } + return this._Airline; + } + } + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + private global::Microsoft.OData.Service.Sample.TrippinInMemory.Models.AirlineSingle _Airline; + /// + /// There are no comments for From in the schema. + /// + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + public global::Microsoft.OData.Service.Sample.TrippinInMemory.Models.AirportSingle From + { + get + { + if (!this.IsComposable) + { + throw new global::System.NotSupportedException("The previous function is not composable."); + } + if ((this._From == null)) + { + this._From = new global::Microsoft.OData.Service.Sample.TrippinInMemory.Models.AirportSingle(this.Context, GetPath("From")); + } + return this._From; + } + } + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + private global::Microsoft.OData.Service.Sample.TrippinInMemory.Models.AirportSingle _From; + /// + /// There are no comments for To in the schema. + /// + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + public global::Microsoft.OData.Service.Sample.TrippinInMemory.Models.AirportSingle To + { + get + { + if (!this.IsComposable) + { + throw new global::System.NotSupportedException("The previous function is not composable."); + } + if ((this._To == null)) + { + this._To = new global::Microsoft.OData.Service.Sample.TrippinInMemory.Models.AirportSingle(this.Context, GetPath("To")); + } + return this._To; + } + } + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + private global::Microsoft.OData.Service.Sample.TrippinInMemory.Models.AirportSingle _To; + } + /// + /// There are no comments for Flight in the schema. + /// + [global::Microsoft.OData.Client.EntityType()] + public partial class Flight : PublicTransportation + { + /// + /// There are no comments for Property FlightNumber in the schema. + /// + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + public string FlightNumber + { + get + { + return this._FlightNumber; + } + set + { + this.OnFlightNumberChanging(value); + this._FlightNumber = value; + this.OnFlightNumberChanged(); + this.OnPropertyChanged("FlightNumber"); + } + } + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + private string _FlightNumber; + partial void OnFlightNumberChanging(string value); + partial void OnFlightNumberChanged(); + /// + /// There are no comments for Property Airline in the schema. + /// + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + public global::Microsoft.OData.Service.Sample.TrippinInMemory.Models.Airline Airline + { + get + { + return this._Airline; + } + set + { + this.OnAirlineChanging(value); + this._Airline = value; + this.OnAirlineChanged(); + this.OnPropertyChanged("Airline"); + } + } + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + private global::Microsoft.OData.Service.Sample.TrippinInMemory.Models.Airline _Airline; + partial void OnAirlineChanging(global::Microsoft.OData.Service.Sample.TrippinInMemory.Models.Airline value); + partial void OnAirlineChanged(); + /// + /// There are no comments for Property From in the schema. + /// + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + public global::Microsoft.OData.Service.Sample.TrippinInMemory.Models.Airport From + { + get + { + return this._From; + } + set + { + this.OnFromChanging(value); + this._From = value; + this.OnFromChanged(); + this.OnPropertyChanged("From"); + } + } + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + private global::Microsoft.OData.Service.Sample.TrippinInMemory.Models.Airport _From; + partial void OnFromChanging(global::Microsoft.OData.Service.Sample.TrippinInMemory.Models.Airport value); + partial void OnFromChanged(); + /// + /// There are no comments for Property To in the schema. + /// + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + public global::Microsoft.OData.Service.Sample.TrippinInMemory.Models.Airport To + { + get + { + return this._To; + } + set + { + this.OnToChanging(value); + this._To = value; + this.OnToChanged(); + this.OnPropertyChanged("To"); + } + } + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + private global::Microsoft.OData.Service.Sample.TrippinInMemory.Models.Airport _To; + partial void OnToChanging(global::Microsoft.OData.Service.Sample.TrippinInMemory.Models.Airport value); + partial void OnToChanged(); + } + /// + /// There are no comments for EmployeeSingle in the schema. + /// + public partial class EmployeeSingle : global::Microsoft.OData.Client.DataServiceQuerySingle + { + /// + /// Initialize a new EmployeeSingle object. + /// + public EmployeeSingle(global::Microsoft.OData.Client.DataServiceContext context, string path) + : base(context, path) { } + + /// + /// Initialize a new EmployeeSingle object. + /// + public EmployeeSingle(global::Microsoft.OData.Client.DataServiceContext context, string path, bool isComposable) + : base(context, path, isComposable) { } + + /// + /// Initialize a new EmployeeSingle object. + /// + public EmployeeSingle(global::Microsoft.OData.Client.DataServiceQuerySingle query) + : base(query) { } + + /// + /// There are no comments for Peers in the schema. + /// + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + public global::Microsoft.OData.Client.DataServiceQuery Peers + { + get + { + if (!this.IsComposable) + { + throw new global::System.NotSupportedException("The previous function is not composable."); + } + if ((this._Peers == null)) + { + this._Peers = Context.CreateQuery(GetPath("Peers")); + } + return this._Peers; + } + } + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + private global::Microsoft.OData.Client.DataServiceQuery _Peers; + /// + /// There are no comments for Friends in the schema. + /// + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + public global::Microsoft.OData.Client.DataServiceQuery Friends + { + get + { + if (!this.IsComposable) + { + throw new global::System.NotSupportedException("The previous function is not composable."); + } + if ((this._Friends == null)) + { + this._Friends = Context.CreateQuery(GetPath("Friends")); + } + return this._Friends; + } + } + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + private global::Microsoft.OData.Client.DataServiceQuery _Friends; + /// + /// There are no comments for Trips in the schema. + /// + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + public global::Microsoft.OData.Client.DataServiceQuery Trips + { + get + { + if (!this.IsComposable) + { + throw new global::System.NotSupportedException("The previous function is not composable."); + } + if ((this._Trips == null)) + { + this._Trips = Context.CreateQuery(GetPath("Trips")); + } + return this._Trips; + } + } + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + private global::Microsoft.OData.Client.DataServiceQuery _Trips; + } + /// + /// There are no comments for Employee in the schema. + /// + /// + /// UserName + /// + [global::Microsoft.OData.Client.Key("UserName")] + public partial class Employee : Person + { + /// + /// Create a new Employee object. + /// + /// Initial value of UserName. + /// Initial value of Gender. + /// Initial value of Cost. + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + public static Employee CreateEmployee(string userName, global::Microsoft.OData.Service.Sample.TrippinInMemory.Models.PersonGender gender, long cost) + { + Employee employee = new Employee(); + employee.UserName = userName; + employee.Gender = gender; + employee.Cost = cost; + return employee; + } + /// + /// There are no comments for Property Cost in the schema. + /// + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + public long Cost + { + get + { + return this._Cost; + } + set + { + this.OnCostChanging(value); + this._Cost = value; + this.OnCostChanged(); + this.OnPropertyChanged("Cost"); + } + } + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + private long _Cost; + partial void OnCostChanging(long value); + partial void OnCostChanged(); + /// + /// There are no comments for Property Peers in the schema. + /// + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + public global::Microsoft.OData.Client.DataServiceCollection Peers + { + get + { + return this._Peers; + } + set + { + this.OnPeersChanging(value); + this._Peers = value; + this.OnPeersChanged(); + this.OnPropertyChanged("Peers"); + } + } + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + private global::Microsoft.OData.Client.DataServiceCollection _Peers = new global::Microsoft.OData.Client.DataServiceCollection(null, global::Microsoft.OData.Client.TrackingMode.None); + partial void OnPeersChanging(global::Microsoft.OData.Client.DataServiceCollection value); + partial void OnPeersChanged(); + } + /// + /// There are no comments for PersonGender in the schema. + /// + public enum PersonGender + { + Male = 0, + Female = 1, + Unknow = 2 + } + /// + /// Class containing all extension methods + /// + public static class ExtensionMethods + { + /// + /// Get an entity of type global::Microsoft.OData.Service.Sample.TrippinInMemory.Models.Person as global::Microsoft.OData.Service.Sample.TrippinInMemory.Models.PersonSingle specified by key from an entity set + /// + /// source entity set + /// dictionary with the names and values of keys + public static global::Microsoft.OData.Service.Sample.TrippinInMemory.Models.PersonSingle ByKey(this global::Microsoft.OData.Client.DataServiceQuery source, global::System.Collections.Generic.Dictionary keys) + { + return new global::Microsoft.OData.Service.Sample.TrippinInMemory.Models.PersonSingle(source.Context, source.GetKeyPath(global::Microsoft.OData.Client.Serializer.GetKeyString(source.Context, keys))); + } + /// + /// Get an entity of type global::Microsoft.OData.Service.Sample.TrippinInMemory.Models.Person as global::Microsoft.OData.Service.Sample.TrippinInMemory.Models.PersonSingle specified by key from an entity set + /// + /// source entity set + /// The value of userName + public static global::Microsoft.OData.Service.Sample.TrippinInMemory.Models.PersonSingle ByKey(this global::Microsoft.OData.Client.DataServiceQuery source, + string userName) + { + global::System.Collections.Generic.Dictionary keys = new global::System.Collections.Generic.Dictionary + { + { "UserName", userName } + }; + return new global::Microsoft.OData.Service.Sample.TrippinInMemory.Models.PersonSingle(source.Context, source.GetKeyPath(global::Microsoft.OData.Client.Serializer.GetKeyString(source.Context, keys))); + } + /// + /// Get an entity of type global::Microsoft.OData.Service.Sample.TrippinInMemory.Models.Airline as global::Microsoft.OData.Service.Sample.TrippinInMemory.Models.AirlineSingle specified by key from an entity set + /// + /// source entity set + /// dictionary with the names and values of keys + public static global::Microsoft.OData.Service.Sample.TrippinInMemory.Models.AirlineSingle ByKey(this global::Microsoft.OData.Client.DataServiceQuery source, global::System.Collections.Generic.Dictionary keys) + { + return new global::Microsoft.OData.Service.Sample.TrippinInMemory.Models.AirlineSingle(source.Context, source.GetKeyPath(global::Microsoft.OData.Client.Serializer.GetKeyString(source.Context, keys))); + } + /// + /// Get an entity of type global::Microsoft.OData.Service.Sample.TrippinInMemory.Models.Airline as global::Microsoft.OData.Service.Sample.TrippinInMemory.Models.AirlineSingle specified by key from an entity set + /// + /// source entity set + /// The value of airlineCode + public static global::Microsoft.OData.Service.Sample.TrippinInMemory.Models.AirlineSingle ByKey(this global::Microsoft.OData.Client.DataServiceQuery source, + string airlineCode) + { + global::System.Collections.Generic.Dictionary keys = new global::System.Collections.Generic.Dictionary + { + { "AirlineCode", airlineCode } + }; + return new global::Microsoft.OData.Service.Sample.TrippinInMemory.Models.AirlineSingle(source.Context, source.GetKeyPath(global::Microsoft.OData.Client.Serializer.GetKeyString(source.Context, keys))); + } + /// + /// Get an entity of type global::Microsoft.OData.Service.Sample.TrippinInMemory.Models.Airport as global::Microsoft.OData.Service.Sample.TrippinInMemory.Models.AirportSingle specified by key from an entity set + /// + /// source entity set + /// dictionary with the names and values of keys + public static global::Microsoft.OData.Service.Sample.TrippinInMemory.Models.AirportSingle ByKey(this global::Microsoft.OData.Client.DataServiceQuery source, global::System.Collections.Generic.Dictionary keys) + { + return new global::Microsoft.OData.Service.Sample.TrippinInMemory.Models.AirportSingle(source.Context, source.GetKeyPath(global::Microsoft.OData.Client.Serializer.GetKeyString(source.Context, keys))); + } + /// + /// Get an entity of type global::Microsoft.OData.Service.Sample.TrippinInMemory.Models.Airport as global::Microsoft.OData.Service.Sample.TrippinInMemory.Models.AirportSingle specified by key from an entity set + /// + /// source entity set + /// The value of icaoCode + public static global::Microsoft.OData.Service.Sample.TrippinInMemory.Models.AirportSingle ByKey(this global::Microsoft.OData.Client.DataServiceQuery source, + string icaoCode) + { + global::System.Collections.Generic.Dictionary keys = new global::System.Collections.Generic.Dictionary + { + { "IcaoCode", icaoCode } + }; + return new global::Microsoft.OData.Service.Sample.TrippinInMemory.Models.AirportSingle(source.Context, source.GetKeyPath(global::Microsoft.OData.Client.Serializer.GetKeyString(source.Context, keys))); + } + /// + /// Get an entity of type global::Microsoft.OData.Service.Sample.TrippinInMemory.Models.Trip as global::Microsoft.OData.Service.Sample.TrippinInMemory.Models.TripSingle specified by key from an entity set + /// + /// source entity set + /// dictionary with the names and values of keys + public static global::Microsoft.OData.Service.Sample.TrippinInMemory.Models.TripSingle ByKey(this global::Microsoft.OData.Client.DataServiceQuery source, global::System.Collections.Generic.Dictionary keys) + { + return new global::Microsoft.OData.Service.Sample.TrippinInMemory.Models.TripSingle(source.Context, source.GetKeyPath(global::Microsoft.OData.Client.Serializer.GetKeyString(source.Context, keys))); + } + /// + /// Get an entity of type global::Microsoft.OData.Service.Sample.TrippinInMemory.Models.Trip as global::Microsoft.OData.Service.Sample.TrippinInMemory.Models.TripSingle specified by key from an entity set + /// + /// source entity set + /// The value of tripId + public static global::Microsoft.OData.Service.Sample.TrippinInMemory.Models.TripSingle ByKey(this global::Microsoft.OData.Client.DataServiceQuery source, + int tripId) + { + global::System.Collections.Generic.Dictionary keys = new global::System.Collections.Generic.Dictionary + { + { "TripId", tripId } + }; + return new global::Microsoft.OData.Service.Sample.TrippinInMemory.Models.TripSingle(source.Context, source.GetKeyPath(global::Microsoft.OData.Client.Serializer.GetKeyString(source.Context, keys))); + } + /// + /// Cast an entity of type global::Microsoft.OData.Service.Sample.TrippinInMemory.Models.PublicTransportation to its derived type global::Microsoft.OData.Service.Sample.TrippinInMemory.Models.Flight + /// + /// source entity + public static global::Microsoft.OData.Service.Sample.TrippinInMemory.Models.FlightSingle CastToFlight(this global::Microsoft.OData.Client.DataServiceQuerySingle source) + { + global::Microsoft.OData.Client.DataServiceQuerySingle query = source.CastTo(); + return new global::Microsoft.OData.Service.Sample.TrippinInMemory.Models.FlightSingle(source.Context, query.GetPath(null)); + } + /// + /// Get an entity of type global::Microsoft.OData.Service.Sample.TrippinInMemory.Models.Employee as global::Microsoft.OData.Service.Sample.TrippinInMemory.Models.EmployeeSingle specified by key from an entity set + /// + /// source entity set + /// dictionary with the names and values of keys + public static global::Microsoft.OData.Service.Sample.TrippinInMemory.Models.EmployeeSingle ByKey(this global::Microsoft.OData.Client.DataServiceQuery source, global::System.Collections.Generic.Dictionary keys) + { + return new global::Microsoft.OData.Service.Sample.TrippinInMemory.Models.EmployeeSingle(source.Context, source.GetKeyPath(global::Microsoft.OData.Client.Serializer.GetKeyString(source.Context, keys))); + } + /// + /// Get an entity of type global::Microsoft.OData.Service.Sample.TrippinInMemory.Models.Employee as global::Microsoft.OData.Service.Sample.TrippinInMemory.Models.EmployeeSingle specified by key from an entity set + /// + /// source entity set + /// The value of userName + public static global::Microsoft.OData.Service.Sample.TrippinInMemory.Models.EmployeeSingle ByKey(this global::Microsoft.OData.Client.DataServiceQuery source, + string userName) + { + global::System.Collections.Generic.Dictionary keys = new global::System.Collections.Generic.Dictionary + { + { "UserName", userName } + }; + return new global::Microsoft.OData.Service.Sample.TrippinInMemory.Models.EmployeeSingle(source.Context, source.GetKeyPath(global::Microsoft.OData.Client.Serializer.GetKeyString(source.Context, keys))); + } + /// + /// Cast an entity of type global::Microsoft.OData.Service.Sample.TrippinInMemory.Models.Person to its derived type global::Microsoft.OData.Service.Sample.TrippinInMemory.Models.Employee + /// + /// source entity + public static global::Microsoft.OData.Service.Sample.TrippinInMemory.Models.EmployeeSingle CastToEmployee(this global::Microsoft.OData.Client.DataServiceQuerySingle source) + { + global::Microsoft.OData.Client.DataServiceQuerySingle query = source.CastTo(); + return new global::Microsoft.OData.Service.Sample.TrippinInMemory.Models.EmployeeSingle(source.Context, query.GetPath(null)); + } + } +} diff --git a/ODataConnectedService/test/ODataConnectedService.Tests/CodeGenReferences/EntitiesEnumsFunctionsDSCWithInternalTypes.cs b/ODataConnectedService/test/ODataConnectedService.Tests/CodeGenReferences/EntitiesEnumsFunctionsDSCWithInternalTypes.cs new file mode 100644 index 0000000..d4ad726 --- /dev/null +++ b/ODataConnectedService/test/ODataConnectedService.Tests/CodeGenReferences/EntitiesEnumsFunctionsDSCWithInternalTypes.cs @@ -0,0 +1,1423 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by a tool. +// Runtime Version:4.0.30319.42000 +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +// Generation date: 1/21/2020 11:33:16 AM +namespace Microsoft.OData.Service.Sample.TrippinInMemory.Models +{ + /// + /// There are no comments for Container in the schema. + /// + internal partial class Container : global::Microsoft.OData.Client.DataServiceContext + { + /// + /// Initialize a new Container object. + /// + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + public Container(global::System.Uri serviceRoot) : + base(serviceRoot, global::Microsoft.OData.Client.ODataProtocolVersion.V4) + { + this.ResolveName = new global::System.Func(this.ResolveNameFromType); + this.OnContextCreated(); + this.Format.LoadServiceModel = GeneratedEdmModel.GetInstance; + this.Format.UseJson(); + } + partial void OnContextCreated(); + /// + /// Since the namespace configured for this service reference + /// in Visual Studio is different from the one indicated in the + /// server schema, use type-mappers to map between the two. + /// + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + protected string ResolveNameFromType(global::System.Type clientType) + { + return clientType.FullName; + } + /// + /// There are no comments for People in the schema. + /// + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + public global::Microsoft.OData.Client.DataServiceQuery People + { + get + { + if ((this._People == null)) + { + this._People = base.CreateQuery("People"); + } + return this._People; + } + } + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + private global::Microsoft.OData.Client.DataServiceQuery _People; + /// + /// There are no comments for Airlines in the schema. + /// + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + public global::Microsoft.OData.Client.DataServiceQuery Airlines + { + get + { + if ((this._Airlines == null)) + { + this._Airlines = base.CreateQuery("Airlines"); + } + return this._Airlines; + } + } + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + private global::Microsoft.OData.Client.DataServiceQuery _Airlines; + /// + /// There are no comments for Airports in the schema. + /// + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + public global::Microsoft.OData.Client.DataServiceQuery Airports + { + get + { + if ((this._Airports == null)) + { + this._Airports = base.CreateQuery("Airports"); + } + return this._Airports; + } + } + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + private global::Microsoft.OData.Client.DataServiceQuery _Airports; + /// + /// There are no comments for People in the schema. + /// + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + public void AddToPeople(Person person) + { + base.AddObject("People", person); + } + /// + /// There are no comments for Airlines in the schema. + /// + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + public void AddToAirlines(Airline airline) + { + base.AddObject("Airlines", airline); + } + /// + /// There are no comments for Airports in the schema. + /// + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + public void AddToAirports(Airport airport) + { + base.AddObject("Airports", airport); + } + /// + /// There are no comments for Me in the schema. + /// + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + public PersonSingle Me + { + get + { + if ((this._Me == null)) + { + this._Me = new PersonSingle(this, "Me"); + } + return this._Me; + } + } + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + private PersonSingle _Me; + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + private abstract class GeneratedEdmModel + { + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + private static global::Microsoft.OData.Edm.IEdmModel ParsedModel = LoadModelFromString(); + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + private const string Edmx = @" + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +"; + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + public static global::Microsoft.OData.Edm.IEdmModel GetInstance() + { + return ParsedModel; + } + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + private static global::Microsoft.OData.Edm.IEdmModel LoadModelFromString() + { + global::System.Xml.XmlReader reader = CreateXmlReader(Edmx); + try + { + return global::Microsoft.OData.Edm.Csdl.CsdlReader.Parse(reader); + } + finally + { + ((global::System.IDisposable)(reader)).Dispose(); + } + } + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + private static global::System.Xml.XmlReader CreateXmlReader(string edmxToParse) + { + return global::System.Xml.XmlReader.Create(new global::System.IO.StringReader(edmxToParse)); + } + } + /// + /// There are no comments for GetPersonWithMostFriends in the schema. + /// + public global::Microsoft.OData.Service.Sample.TrippinInMemory.Models.PersonSingle GetPersonWithMostFriends() + { + return new global::Microsoft.OData.Service.Sample.TrippinInMemory.Models.PersonSingle(this.CreateFunctionQuerySingle("", "GetPersonWithMostFriends", false)); + } + /// + /// There are no comments for GetNearestAirport in the schema. + /// + public global::Microsoft.OData.Service.Sample.TrippinInMemory.Models.AirportSingle GetNearestAirport(double lat, double lon) + { + return new global::Microsoft.OData.Service.Sample.TrippinInMemory.Models.AirportSingle(this.CreateFunctionQuerySingle("", "GetNearestAirport", false, new global::Microsoft.OData.Client.UriOperationParameter("lat", lat), + new global::Microsoft.OData.Client.UriOperationParameter("lon", lon))); + } + /// + /// There are no comments for ResetDataSource in the schema. + /// + public global::Microsoft.OData.Client.DataServiceActionQuery ResetDataSource() + { + return new global::Microsoft.OData.Client.DataServiceActionQuery(this, this.BaseUri.OriginalString.Trim('/') + "/ResetDataSource"); + } + } + /// + /// There are no comments for PersonSingle in the schema. + /// + internal partial class PersonSingle : global::Microsoft.OData.Client.DataServiceQuerySingle + { + /// + /// Initialize a new PersonSingle object. + /// + public PersonSingle(global::Microsoft.OData.Client.DataServiceContext context, string path) + : base(context, path) { } + + /// + /// Initialize a new PersonSingle object. + /// + public PersonSingle(global::Microsoft.OData.Client.DataServiceContext context, string path, bool isComposable) + : base(context, path, isComposable) { } + + /// + /// Initialize a new PersonSingle object. + /// + public PersonSingle(global::Microsoft.OData.Client.DataServiceQuerySingle query) + : base(query) { } + + /// + /// There are no comments for Friends in the schema. + /// + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + public global::Microsoft.OData.Client.DataServiceQuery Friends + { + get + { + if (!this.IsComposable) + { + throw new global::System.NotSupportedException("The previous function is not composable."); + } + if ((this._Friends == null)) + { + this._Friends = Context.CreateQuery(GetPath("Friends")); + } + return this._Friends; + } + } + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + private global::Microsoft.OData.Client.DataServiceQuery _Friends; + /// + /// There are no comments for Trips in the schema. + /// + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + public global::Microsoft.OData.Client.DataServiceQuery Trips + { + get + { + if (!this.IsComposable) + { + throw new global::System.NotSupportedException("The previous function is not composable."); + } + if ((this._Trips == null)) + { + this._Trips = Context.CreateQuery(GetPath("Trips")); + } + return this._Trips; + } + } + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + private global::Microsoft.OData.Client.DataServiceQuery _Trips; + } + /// + /// There are no comments for Person in the schema. + /// + /// + /// UserName + /// + [global::Microsoft.OData.Client.Key("UserName")] + internal partial class Person : global::Microsoft.OData.Client.BaseEntityType, global::System.ComponentModel.INotifyPropertyChanged + { + /// + /// Create a new Person object. + /// + /// Initial value of UserName. + /// Initial value of Gender. + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + public static Person CreatePerson(string userName, global::Microsoft.OData.Service.Sample.TrippinInMemory.Models.PersonGender gender) + { + Person person = new Person(); + person.UserName = userName; + person.Gender = gender; + return person; + } + /// + /// There are no comments for Property UserName in the schema. + /// + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + public string UserName + { + get + { + return this._UserName; + } + set + { + this.OnUserNameChanging(value); + this._UserName = value; + this.OnUserNameChanged(); + this.OnPropertyChanged("UserName"); + } + } + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + private string _UserName; + partial void OnUserNameChanging(string value); + partial void OnUserNameChanged(); + /// + /// There are no comments for Property Gender in the schema. + /// + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + public global::Microsoft.OData.Service.Sample.TrippinInMemory.Models.PersonGender Gender + { + get + { + return this._Gender; + } + set + { + this.OnGenderChanging(value); + this._Gender = value; + this.OnGenderChanged(); + this.OnPropertyChanged("Gender"); + } + } + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + private global::Microsoft.OData.Service.Sample.TrippinInMemory.Models.PersonGender _Gender; + partial void OnGenderChanging(global::Microsoft.OData.Service.Sample.TrippinInMemory.Models.PersonGender value); + partial void OnGenderChanged(); + /// + /// There are no comments for Property Age in the schema. + /// + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + public global::System.Nullable Age + { + get + { + return this._Age; + } + set + { + this.OnAgeChanging(value); + this._Age = value; + this.OnAgeChanged(); + this.OnPropertyChanged("Age"); + } + } + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + private global::System.Nullable _Age; + partial void OnAgeChanging(global::System.Nullable value); + partial void OnAgeChanged(); + /// + /// There are no comments for Property HomeAddress in the schema. + /// + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + public global::Microsoft.OData.Service.Sample.TrippinInMemory.Models.Location HomeAddress + { + get + { + return this._HomeAddress; + } + set + { + this.OnHomeAddressChanging(value); + this._HomeAddress = value; + this.OnHomeAddressChanged(); + this.OnPropertyChanged("HomeAddress"); + } + } + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + private global::Microsoft.OData.Service.Sample.TrippinInMemory.Models.Location _HomeAddress; + partial void OnHomeAddressChanging(global::Microsoft.OData.Service.Sample.TrippinInMemory.Models.Location value); + partial void OnHomeAddressChanged(); + /// + /// There are no comments for Property Friends in the schema. + /// + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + public global::Microsoft.OData.Client.DataServiceCollection Friends + { + get + { + return this._Friends; + } + set + { + this.OnFriendsChanging(value); + this._Friends = value; + this.OnFriendsChanged(); + this.OnPropertyChanged("Friends"); + } + } + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + private global::Microsoft.OData.Client.DataServiceCollection _Friends = new global::Microsoft.OData.Client.DataServiceCollection(null, global::Microsoft.OData.Client.TrackingMode.None); + partial void OnFriendsChanging(global::Microsoft.OData.Client.DataServiceCollection value); + partial void OnFriendsChanged(); + /// + /// There are no comments for Property Trips in the schema. + /// + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + public global::Microsoft.OData.Client.DataServiceCollection Trips + { + get + { + return this._Trips; + } + set + { + this.OnTripsChanging(value); + this._Trips = value; + this.OnTripsChanged(); + this.OnPropertyChanged("Trips"); + } + } + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + private global::Microsoft.OData.Client.DataServiceCollection _Trips = new global::Microsoft.OData.Client.DataServiceCollection(null, global::Microsoft.OData.Client.TrackingMode.None); + partial void OnTripsChanging(global::Microsoft.OData.Client.DataServiceCollection value); + partial void OnTripsChanged(); + /// + /// This event is raised when the value of the property is changed + /// + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + public event global::System.ComponentModel.PropertyChangedEventHandler PropertyChanged; + /// + /// The value of the property is changed + /// + /// property name + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + protected virtual void OnPropertyChanged(string property) + { + if ((this.PropertyChanged != null)) + { + this.PropertyChanged(this, new global::System.ComponentModel.PropertyChangedEventArgs(property)); + } + } + } + /// + /// There are no comments for AirlineSingle in the schema. + /// + internal partial class AirlineSingle : global::Microsoft.OData.Client.DataServiceQuerySingle + { + /// + /// Initialize a new AirlineSingle object. + /// + public AirlineSingle(global::Microsoft.OData.Client.DataServiceContext context, string path) + : base(context, path) { } + + /// + /// Initialize a new AirlineSingle object. + /// + public AirlineSingle(global::Microsoft.OData.Client.DataServiceContext context, string path, bool isComposable) + : base(context, path, isComposable) { } + + /// + /// Initialize a new AirlineSingle object. + /// + public AirlineSingle(global::Microsoft.OData.Client.DataServiceQuerySingle query) + : base(query) { } + + } + /// + /// There are no comments for Airline in the schema. + /// + /// + /// AirlineCode + /// + [global::Microsoft.OData.Client.Key("AirlineCode")] + [global::Microsoft.OData.Client.EntitySet("Airlines")] + internal partial class Airline : global::Microsoft.OData.Client.BaseEntityType, global::System.ComponentModel.INotifyPropertyChanged + { + /// + /// Create a new Airline object. + /// + /// Initial value of AirlineCode. + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + public static Airline CreateAirline(string airlineCode) + { + Airline airline = new Airline(); + airline.AirlineCode = airlineCode; + return airline; + } + /// + /// There are no comments for Property AirlineCode in the schema. + /// + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + public string AirlineCode + { + get + { + return this._AirlineCode; + } + set + { + this.OnAirlineCodeChanging(value); + this._AirlineCode = value; + this.OnAirlineCodeChanged(); + this.OnPropertyChanged("AirlineCode"); + } + } + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + private string _AirlineCode; + partial void OnAirlineCodeChanging(string value); + partial void OnAirlineCodeChanged(); + /// + /// There are no comments for Property Name in the schema. + /// + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + public string Name + { + get + { + return this._Name; + } + set + { + this.OnNameChanging(value); + this._Name = value; + this.OnNameChanged(); + this.OnPropertyChanged("Name"); + } + } + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + private string _Name; + partial void OnNameChanging(string value); + partial void OnNameChanged(); + /// + /// This event is raised when the value of the property is changed + /// + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + public event global::System.ComponentModel.PropertyChangedEventHandler PropertyChanged; + /// + /// The value of the property is changed + /// + /// property name + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + protected virtual void OnPropertyChanged(string property) + { + if ((this.PropertyChanged != null)) + { + this.PropertyChanged(this, new global::System.ComponentModel.PropertyChangedEventArgs(property)); + } + } + } + /// + /// There are no comments for AirportSingle in the schema. + /// + internal partial class AirportSingle : global::Microsoft.OData.Client.DataServiceQuerySingle + { + /// + /// Initialize a new AirportSingle object. + /// + public AirportSingle(global::Microsoft.OData.Client.DataServiceContext context, string path) + : base(context, path) { } + + /// + /// Initialize a new AirportSingle object. + /// + public AirportSingle(global::Microsoft.OData.Client.DataServiceContext context, string path, bool isComposable) + : base(context, path, isComposable) { } + + /// + /// Initialize a new AirportSingle object. + /// + public AirportSingle(global::Microsoft.OData.Client.DataServiceQuerySingle query) + : base(query) { } + + } + /// + /// There are no comments for Airport in the schema. + /// + /// + /// IcaoCode + /// + [global::Microsoft.OData.Client.Key("IcaoCode")] + [global::Microsoft.OData.Client.EntitySet("Airports")] + internal partial class Airport : global::Microsoft.OData.Client.BaseEntityType, global::System.ComponentModel.INotifyPropertyChanged + { + /// + /// Create a new Airport object. + /// + /// Initial value of IcaoCode. + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + public static Airport CreateAirport(string icaoCode) + { + Airport airport = new Airport(); + airport.IcaoCode = icaoCode; + return airport; + } + /// + /// There are no comments for Property Name in the schema. + /// + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + public string Name + { + get + { + return this._Name; + } + set + { + this.OnNameChanging(value); + this._Name = value; + this.OnNameChanged(); + this.OnPropertyChanged("Name"); + } + } + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + private string _Name; + partial void OnNameChanging(string value); + partial void OnNameChanged(); + /// + /// There are no comments for Property IcaoCode in the schema. + /// + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + public string IcaoCode + { + get + { + return this._IcaoCode; + } + set + { + this.OnIcaoCodeChanging(value); + this._IcaoCode = value; + this.OnIcaoCodeChanged(); + this.OnPropertyChanged("IcaoCode"); + } + } + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + private string _IcaoCode; + partial void OnIcaoCodeChanging(string value); + partial void OnIcaoCodeChanged(); + /// + /// This event is raised when the value of the property is changed + /// + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + public event global::System.ComponentModel.PropertyChangedEventHandler PropertyChanged; + /// + /// The value of the property is changed + /// + /// property name + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + protected virtual void OnPropertyChanged(string property) + { + if ((this.PropertyChanged != null)) + { + this.PropertyChanged(this, new global::System.ComponentModel.PropertyChangedEventArgs(property)); + } + } + } + /// + /// There are no comments for Location in the schema. + /// + internal partial class Location : global::System.ComponentModel.INotifyPropertyChanged + { + /// + /// There are no comments for Property Address in the schema. + /// + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + public string Address + { + get + { + return this._Address; + } + set + { + this.OnAddressChanging(value); + this._Address = value; + this.OnAddressChanged(); + this.OnPropertyChanged("Address"); + } + } + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + private string _Address; + partial void OnAddressChanging(string value); + partial void OnAddressChanged(); + /// + /// There are no comments for Property City in the schema. + /// + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + public global::Microsoft.OData.Service.Sample.TrippinInMemory.Models.City City + { + get + { + return this._City; + } + set + { + this.OnCityChanging(value); + this._City = value; + this.OnCityChanged(); + this.OnPropertyChanged("City"); + } + } + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + private global::Microsoft.OData.Service.Sample.TrippinInMemory.Models.City _City; + partial void OnCityChanging(global::Microsoft.OData.Service.Sample.TrippinInMemory.Models.City value); + partial void OnCityChanged(); + /// + /// This event is raised when the value of the property is changed + /// + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + public event global::System.ComponentModel.PropertyChangedEventHandler PropertyChanged; + /// + /// The value of the property is changed + /// + /// property name + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + protected virtual void OnPropertyChanged(string property) + { + if ((this.PropertyChanged != null)) + { + this.PropertyChanged(this, new global::System.ComponentModel.PropertyChangedEventArgs(property)); + } + } + } + /// + /// There are no comments for City in the schema. + /// + internal partial class City : global::System.ComponentModel.INotifyPropertyChanged + { + /// + /// There are no comments for Property Name in the schema. + /// + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + public string Name + { + get + { + return this._Name; + } + set + { + this.OnNameChanging(value); + this._Name = value; + this.OnNameChanged(); + this.OnPropertyChanged("Name"); + } + } + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + private string _Name; + partial void OnNameChanging(string value); + partial void OnNameChanged(); + /// + /// This event is raised when the value of the property is changed + /// + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + public event global::System.ComponentModel.PropertyChangedEventHandler PropertyChanged; + /// + /// The value of the property is changed + /// + /// property name + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + protected virtual void OnPropertyChanged(string property) + { + if ((this.PropertyChanged != null)) + { + this.PropertyChanged(this, new global::System.ComponentModel.PropertyChangedEventArgs(property)); + } + } + } + /// + /// There are no comments for TripSingle in the schema. + /// + internal partial class TripSingle : global::Microsoft.OData.Client.DataServiceQuerySingle + { + /// + /// Initialize a new TripSingle object. + /// + public TripSingle(global::Microsoft.OData.Client.DataServiceContext context, string path) + : base(context, path) { } + + /// + /// Initialize a new TripSingle object. + /// + public TripSingle(global::Microsoft.OData.Client.DataServiceContext context, string path, bool isComposable) + : base(context, path, isComposable) { } + + /// + /// Initialize a new TripSingle object. + /// + public TripSingle(global::Microsoft.OData.Client.DataServiceQuerySingle query) + : base(query) { } + + } + /// + /// There are no comments for Trip in the schema. + /// + /// + /// TripId + /// + [global::Microsoft.OData.Client.Key("TripId")] + internal partial class Trip : global::Microsoft.OData.Client.BaseEntityType, global::System.ComponentModel.INotifyPropertyChanged + { + /// + /// Create a new Trip object. + /// + /// Initial value of TripId. + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + public static Trip CreateTrip(int tripId) + { + Trip trip = new Trip(); + trip.TripId = tripId; + return trip; + } + /// + /// There are no comments for Property TripId in the schema. + /// + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + public int TripId + { + get + { + return this._TripId; + } + set + { + this.OnTripIdChanging(value); + this._TripId = value; + this.OnTripIdChanged(); + this.OnPropertyChanged("TripId"); + } + } + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + private int _TripId; + partial void OnTripIdChanging(int value); + partial void OnTripIdChanged(); + /// + /// There are no comments for Property Name in the schema. + /// + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + public string Name + { + get + { + return this._Name; + } + set + { + this.OnNameChanging(value); + this._Name = value; + this.OnNameChanged(); + this.OnPropertyChanged("Name"); + } + } + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + private string _Name; + partial void OnNameChanging(string value); + partial void OnNameChanged(); + /// + /// This event is raised when the value of the property is changed + /// + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + public event global::System.ComponentModel.PropertyChangedEventHandler PropertyChanged; + /// + /// The value of the property is changed + /// + /// property name + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + protected virtual void OnPropertyChanged(string property) + { + if ((this.PropertyChanged != null)) + { + this.PropertyChanged(this, new global::System.ComponentModel.PropertyChangedEventArgs(property)); + } + } + } + /// + /// There are no comments for FlightSingle in the schema. + /// + internal partial class FlightSingle : global::Microsoft.OData.Client.DataServiceQuerySingle + { + /// + /// Initialize a new FlightSingle object. + /// + public FlightSingle(global::Microsoft.OData.Client.DataServiceContext context, string path) + : base(context, path) { } + + /// + /// Initialize a new FlightSingle object. + /// + public FlightSingle(global::Microsoft.OData.Client.DataServiceContext context, string path, bool isComposable) + : base(context, path, isComposable) { } + + /// + /// Initialize a new FlightSingle object. + /// + public FlightSingle(global::Microsoft.OData.Client.DataServiceQuerySingle query) + : base(query) { } + + /// + /// There are no comments for Airline in the schema. + /// + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + public global::Microsoft.OData.Service.Sample.TrippinInMemory.Models.AirlineSingle Airline + { + get + { + if (!this.IsComposable) + { + throw new global::System.NotSupportedException("The previous function is not composable."); + } + if ((this._Airline == null)) + { + this._Airline = new global::Microsoft.OData.Service.Sample.TrippinInMemory.Models.AirlineSingle(this.Context, GetPath("Airline")); + } + return this._Airline; + } + } + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + private global::Microsoft.OData.Service.Sample.TrippinInMemory.Models.AirlineSingle _Airline; + /// + /// There are no comments for From in the schema. + /// + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + public global::Microsoft.OData.Service.Sample.TrippinInMemory.Models.AirportSingle From + { + get + { + if (!this.IsComposable) + { + throw new global::System.NotSupportedException("The previous function is not composable."); + } + if ((this._From == null)) + { + this._From = new global::Microsoft.OData.Service.Sample.TrippinInMemory.Models.AirportSingle(this.Context, GetPath("From")); + } + return this._From; + } + } + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + private global::Microsoft.OData.Service.Sample.TrippinInMemory.Models.AirportSingle _From; + /// + /// There are no comments for To in the schema. + /// + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + public global::Microsoft.OData.Service.Sample.TrippinInMemory.Models.AirportSingle To + { + get + { + if (!this.IsComposable) + { + throw new global::System.NotSupportedException("The previous function is not composable."); + } + if ((this._To == null)) + { + this._To = new global::Microsoft.OData.Service.Sample.TrippinInMemory.Models.AirportSingle(this.Context, GetPath("To")); + } + return this._To; + } + } + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + private global::Microsoft.OData.Service.Sample.TrippinInMemory.Models.AirportSingle _To; + } + /// + /// There are no comments for Flight in the schema. + /// + [global::Microsoft.OData.Client.EntityType()] + internal partial class Flight : PublicTransportation + { + /// + /// There are no comments for Property FlightNumber in the schema. + /// + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + public string FlightNumber + { + get + { + return this._FlightNumber; + } + set + { + this.OnFlightNumberChanging(value); + this._FlightNumber = value; + this.OnFlightNumberChanged(); + this.OnPropertyChanged("FlightNumber"); + } + } + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + private string _FlightNumber; + partial void OnFlightNumberChanging(string value); + partial void OnFlightNumberChanged(); + /// + /// There are no comments for Property Airline in the schema. + /// + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + public global::Microsoft.OData.Service.Sample.TrippinInMemory.Models.Airline Airline + { + get + { + return this._Airline; + } + set + { + this.OnAirlineChanging(value); + this._Airline = value; + this.OnAirlineChanged(); + this.OnPropertyChanged("Airline"); + } + } + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + private global::Microsoft.OData.Service.Sample.TrippinInMemory.Models.Airline _Airline; + partial void OnAirlineChanging(global::Microsoft.OData.Service.Sample.TrippinInMemory.Models.Airline value); + partial void OnAirlineChanged(); + /// + /// There are no comments for Property From in the schema. + /// + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + public global::Microsoft.OData.Service.Sample.TrippinInMemory.Models.Airport From + { + get + { + return this._From; + } + set + { + this.OnFromChanging(value); + this._From = value; + this.OnFromChanged(); + this.OnPropertyChanged("From"); + } + } + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + private global::Microsoft.OData.Service.Sample.TrippinInMemory.Models.Airport _From; + partial void OnFromChanging(global::Microsoft.OData.Service.Sample.TrippinInMemory.Models.Airport value); + partial void OnFromChanged(); + /// + /// There are no comments for Property To in the schema. + /// + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + public global::Microsoft.OData.Service.Sample.TrippinInMemory.Models.Airport To + { + get + { + return this._To; + } + set + { + this.OnToChanging(value); + this._To = value; + this.OnToChanged(); + this.OnPropertyChanged("To"); + } + } + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + private global::Microsoft.OData.Service.Sample.TrippinInMemory.Models.Airport _To; + partial void OnToChanging(global::Microsoft.OData.Service.Sample.TrippinInMemory.Models.Airport value); + partial void OnToChanged(); + } + /// + /// There are no comments for EmployeeSingle in the schema. + /// + internal partial class EmployeeSingle : global::Microsoft.OData.Client.DataServiceQuerySingle + { + /// + /// Initialize a new EmployeeSingle object. + /// + public EmployeeSingle(global::Microsoft.OData.Client.DataServiceContext context, string path) + : base(context, path) { } + + /// + /// Initialize a new EmployeeSingle object. + /// + public EmployeeSingle(global::Microsoft.OData.Client.DataServiceContext context, string path, bool isComposable) + : base(context, path, isComposable) { } + + /// + /// Initialize a new EmployeeSingle object. + /// + public EmployeeSingle(global::Microsoft.OData.Client.DataServiceQuerySingle query) + : base(query) { } + + /// + /// There are no comments for Peers in the schema. + /// + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + public global::Microsoft.OData.Client.DataServiceQuery Peers + { + get + { + if (!this.IsComposable) + { + throw new global::System.NotSupportedException("The previous function is not composable."); + } + if ((this._Peers == null)) + { + this._Peers = Context.CreateQuery(GetPath("Peers")); + } + return this._Peers; + } + } + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + private global::Microsoft.OData.Client.DataServiceQuery _Peers; + /// + /// There are no comments for Friends in the schema. + /// + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + public global::Microsoft.OData.Client.DataServiceQuery Friends + { + get + { + if (!this.IsComposable) + { + throw new global::System.NotSupportedException("The previous function is not composable."); + } + if ((this._Friends == null)) + { + this._Friends = Context.CreateQuery(GetPath("Friends")); + } + return this._Friends; + } + } + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + private global::Microsoft.OData.Client.DataServiceQuery _Friends; + /// + /// There are no comments for Trips in the schema. + /// + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + public global::Microsoft.OData.Client.DataServiceQuery Trips + { + get + { + if (!this.IsComposable) + { + throw new global::System.NotSupportedException("The previous function is not composable."); + } + if ((this._Trips == null)) + { + this._Trips = Context.CreateQuery(GetPath("Trips")); + } + return this._Trips; + } + } + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + private global::Microsoft.OData.Client.DataServiceQuery _Trips; + } + /// + /// There are no comments for Employee in the schema. + /// + /// + /// UserName + /// + [global::Microsoft.OData.Client.Key("UserName")] + internal partial class Employee : Person + { + /// + /// Create a new Employee object. + /// + /// Initial value of UserName. + /// Initial value of Gender. + /// Initial value of Cost. + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + public static Employee CreateEmployee(string userName, global::Microsoft.OData.Service.Sample.TrippinInMemory.Models.PersonGender gender, long cost) + { + Employee employee = new Employee(); + employee.UserName = userName; + employee.Gender = gender; + employee.Cost = cost; + return employee; + } + /// + /// There are no comments for Property Cost in the schema. + /// + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + public long Cost + { + get + { + return this._Cost; + } + set + { + this.OnCostChanging(value); + this._Cost = value; + this.OnCostChanged(); + this.OnPropertyChanged("Cost"); + } + } + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + private long _Cost; + partial void OnCostChanging(long value); + partial void OnCostChanged(); + /// + /// There are no comments for Property Peers in the schema. + /// + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + public global::Microsoft.OData.Client.DataServiceCollection Peers + { + get + { + return this._Peers; + } + set + { + this.OnPeersChanging(value); + this._Peers = value; + this.OnPeersChanged(); + this.OnPropertyChanged("Peers"); + } + } + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + private global::Microsoft.OData.Client.DataServiceCollection _Peers = new global::Microsoft.OData.Client.DataServiceCollection(null, global::Microsoft.OData.Client.TrackingMode.None); + partial void OnPeersChanging(global::Microsoft.OData.Client.DataServiceCollection value); + partial void OnPeersChanged(); + } + /// + /// There are no comments for PersonGender in the schema. + /// + internal enum PersonGender + { + Male = 0, + Female = 1, + Unknow = 2 + } + /// + /// Class containing all extension methods + /// + internal static class ExtensionMethods + { + /// + /// Get an entity of type global::Microsoft.OData.Service.Sample.TrippinInMemory.Models.Person as global::Microsoft.OData.Service.Sample.TrippinInMemory.Models.PersonSingle specified by key from an entity set + /// + /// source entity set + /// dictionary with the names and values of keys + public static global::Microsoft.OData.Service.Sample.TrippinInMemory.Models.PersonSingle ByKey(this global::Microsoft.OData.Client.DataServiceQuery source, global::System.Collections.Generic.Dictionary keys) + { + return new global::Microsoft.OData.Service.Sample.TrippinInMemory.Models.PersonSingle(source.Context, source.GetKeyPath(global::Microsoft.OData.Client.Serializer.GetKeyString(source.Context, keys))); + } + /// + /// Get an entity of type global::Microsoft.OData.Service.Sample.TrippinInMemory.Models.Person as global::Microsoft.OData.Service.Sample.TrippinInMemory.Models.PersonSingle specified by key from an entity set + /// + /// source entity set + /// The value of userName + public static global::Microsoft.OData.Service.Sample.TrippinInMemory.Models.PersonSingle ByKey(this global::Microsoft.OData.Client.DataServiceQuery source, + string userName) + { + global::System.Collections.Generic.Dictionary keys = new global::System.Collections.Generic.Dictionary + { + { "UserName", userName } + }; + return new global::Microsoft.OData.Service.Sample.TrippinInMemory.Models.PersonSingle(source.Context, source.GetKeyPath(global::Microsoft.OData.Client.Serializer.GetKeyString(source.Context, keys))); + } + /// + /// Get an entity of type global::Microsoft.OData.Service.Sample.TrippinInMemory.Models.Airline as global::Microsoft.OData.Service.Sample.TrippinInMemory.Models.AirlineSingle specified by key from an entity set + /// + /// source entity set + /// dictionary with the names and values of keys + public static global::Microsoft.OData.Service.Sample.TrippinInMemory.Models.AirlineSingle ByKey(this global::Microsoft.OData.Client.DataServiceQuery source, global::System.Collections.Generic.Dictionary keys) + { + return new global::Microsoft.OData.Service.Sample.TrippinInMemory.Models.AirlineSingle(source.Context, source.GetKeyPath(global::Microsoft.OData.Client.Serializer.GetKeyString(source.Context, keys))); + } + /// + /// Get an entity of type global::Microsoft.OData.Service.Sample.TrippinInMemory.Models.Airline as global::Microsoft.OData.Service.Sample.TrippinInMemory.Models.AirlineSingle specified by key from an entity set + /// + /// source entity set + /// The value of airlineCode + public static global::Microsoft.OData.Service.Sample.TrippinInMemory.Models.AirlineSingle ByKey(this global::Microsoft.OData.Client.DataServiceQuery source, + string airlineCode) + { + global::System.Collections.Generic.Dictionary keys = new global::System.Collections.Generic.Dictionary + { + { "AirlineCode", airlineCode } + }; + return new global::Microsoft.OData.Service.Sample.TrippinInMemory.Models.AirlineSingle(source.Context, source.GetKeyPath(global::Microsoft.OData.Client.Serializer.GetKeyString(source.Context, keys))); + } + /// + /// Get an entity of type global::Microsoft.OData.Service.Sample.TrippinInMemory.Models.Airport as global::Microsoft.OData.Service.Sample.TrippinInMemory.Models.AirportSingle specified by key from an entity set + /// + /// source entity set + /// dictionary with the names and values of keys + public static global::Microsoft.OData.Service.Sample.TrippinInMemory.Models.AirportSingle ByKey(this global::Microsoft.OData.Client.DataServiceQuery source, global::System.Collections.Generic.Dictionary keys) + { + return new global::Microsoft.OData.Service.Sample.TrippinInMemory.Models.AirportSingle(source.Context, source.GetKeyPath(global::Microsoft.OData.Client.Serializer.GetKeyString(source.Context, keys))); + } + /// + /// Get an entity of type global::Microsoft.OData.Service.Sample.TrippinInMemory.Models.Airport as global::Microsoft.OData.Service.Sample.TrippinInMemory.Models.AirportSingle specified by key from an entity set + /// + /// source entity set + /// The value of icaoCode + public static global::Microsoft.OData.Service.Sample.TrippinInMemory.Models.AirportSingle ByKey(this global::Microsoft.OData.Client.DataServiceQuery source, + string icaoCode) + { + global::System.Collections.Generic.Dictionary keys = new global::System.Collections.Generic.Dictionary + { + { "IcaoCode", icaoCode } + }; + return new global::Microsoft.OData.Service.Sample.TrippinInMemory.Models.AirportSingle(source.Context, source.GetKeyPath(global::Microsoft.OData.Client.Serializer.GetKeyString(source.Context, keys))); + } + /// + /// Get an entity of type global::Microsoft.OData.Service.Sample.TrippinInMemory.Models.Trip as global::Microsoft.OData.Service.Sample.TrippinInMemory.Models.TripSingle specified by key from an entity set + /// + /// source entity set + /// dictionary with the names and values of keys + public static global::Microsoft.OData.Service.Sample.TrippinInMemory.Models.TripSingle ByKey(this global::Microsoft.OData.Client.DataServiceQuery source, global::System.Collections.Generic.Dictionary keys) + { + return new global::Microsoft.OData.Service.Sample.TrippinInMemory.Models.TripSingle(source.Context, source.GetKeyPath(global::Microsoft.OData.Client.Serializer.GetKeyString(source.Context, keys))); + } + /// + /// Get an entity of type global::Microsoft.OData.Service.Sample.TrippinInMemory.Models.Trip as global::Microsoft.OData.Service.Sample.TrippinInMemory.Models.TripSingle specified by key from an entity set + /// + /// source entity set + /// The value of tripId + public static global::Microsoft.OData.Service.Sample.TrippinInMemory.Models.TripSingle ByKey(this global::Microsoft.OData.Client.DataServiceQuery source, + int tripId) + { + global::System.Collections.Generic.Dictionary keys = new global::System.Collections.Generic.Dictionary + { + { "TripId", tripId } + }; + return new global::Microsoft.OData.Service.Sample.TrippinInMemory.Models.TripSingle(source.Context, source.GetKeyPath(global::Microsoft.OData.Client.Serializer.GetKeyString(source.Context, keys))); + } + /// + /// Cast an entity of type global::Microsoft.OData.Service.Sample.TrippinInMemory.Models.PublicTransportation to its derived type global::Microsoft.OData.Service.Sample.TrippinInMemory.Models.Flight + /// + /// source entity + public static global::Microsoft.OData.Service.Sample.TrippinInMemory.Models.FlightSingle CastToFlight(this global::Microsoft.OData.Client.DataServiceQuerySingle source) + { + global::Microsoft.OData.Client.DataServiceQuerySingle query = source.CastTo(); + return new global::Microsoft.OData.Service.Sample.TrippinInMemory.Models.FlightSingle(source.Context, query.GetPath(null)); + } + /// + /// Get an entity of type global::Microsoft.OData.Service.Sample.TrippinInMemory.Models.Employee as global::Microsoft.OData.Service.Sample.TrippinInMemory.Models.EmployeeSingle specified by key from an entity set + /// + /// source entity set + /// dictionary with the names and values of keys + public static global::Microsoft.OData.Service.Sample.TrippinInMemory.Models.EmployeeSingle ByKey(this global::Microsoft.OData.Client.DataServiceQuery source, global::System.Collections.Generic.Dictionary keys) + { + return new global::Microsoft.OData.Service.Sample.TrippinInMemory.Models.EmployeeSingle(source.Context, source.GetKeyPath(global::Microsoft.OData.Client.Serializer.GetKeyString(source.Context, keys))); + } + /// + /// Get an entity of type global::Microsoft.OData.Service.Sample.TrippinInMemory.Models.Employee as global::Microsoft.OData.Service.Sample.TrippinInMemory.Models.EmployeeSingle specified by key from an entity set + /// + /// source entity set + /// The value of userName + public static global::Microsoft.OData.Service.Sample.TrippinInMemory.Models.EmployeeSingle ByKey(this global::Microsoft.OData.Client.DataServiceQuery source, + string userName) + { + global::System.Collections.Generic.Dictionary keys = new global::System.Collections.Generic.Dictionary + { + { "UserName", userName } + }; + return new global::Microsoft.OData.Service.Sample.TrippinInMemory.Models.EmployeeSingle(source.Context, source.GetKeyPath(global::Microsoft.OData.Client.Serializer.GetKeyString(source.Context, keys))); + } + /// + /// Cast an entity of type global::Microsoft.OData.Service.Sample.TrippinInMemory.Models.Person to its derived type global::Microsoft.OData.Service.Sample.TrippinInMemory.Models.Employee + /// + /// source entity + public static global::Microsoft.OData.Service.Sample.TrippinInMemory.Models.EmployeeSingle CastToEmployee(this global::Microsoft.OData.Client.DataServiceQuerySingle source) + { + global::Microsoft.OData.Client.DataServiceQuerySingle query = source.CastTo(); + return new global::Microsoft.OData.Service.Sample.TrippinInMemory.Models.EmployeeSingle(source.Context, query.GetPath(null)); + } + } +} diff --git a/ODataConnectedService/test/ODataConnectedService.Tests/CodeGenReferences/EntitiesEnumsFunctionsWithInternalTypes.cs b/ODataConnectedService/test/ODataConnectedService.Tests/CodeGenReferences/EntitiesEnumsFunctionsWithInternalTypes.cs new file mode 100644 index 0000000..c94db59 --- /dev/null +++ b/ODataConnectedService/test/ODataConnectedService.Tests/CodeGenReferences/EntitiesEnumsFunctionsWithInternalTypes.cs @@ -0,0 +1,1298 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by a tool. +// Runtime Version:4.0.30319.42000 +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +// Generation date: 1/21/2020 11:02:50 AM +namespace Microsoft.OData.Service.Sample.TrippinInMemory.Models +{ + /// + /// There are no comments for Container in the schema. + /// + internal partial class Container : global::Microsoft.OData.Client.DataServiceContext + { + /// + /// Initialize a new Container object. + /// + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + public Container(global::System.Uri serviceRoot) : + base(serviceRoot, global::Microsoft.OData.Client.ODataProtocolVersion.V4) + { + this.ResolveName = new global::System.Func(this.ResolveNameFromType); + this.OnContextCreated(); + this.Format.LoadServiceModel = GeneratedEdmModel.GetInstance; + this.Format.UseJson(); + } + partial void OnContextCreated(); + /// + /// Since the namespace configured for this service reference + /// in Visual Studio is different from the one indicated in the + /// server schema, use type-mappers to map between the two. + /// + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + protected string ResolveNameFromType(global::System.Type clientType) + { + return clientType.FullName; + } + /// + /// There are no comments for People in the schema. + /// + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + public global::Microsoft.OData.Client.DataServiceQuery People + { + get + { + if ((this._People == null)) + { + this._People = base.CreateQuery("People"); + } + return this._People; + } + } + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + private global::Microsoft.OData.Client.DataServiceQuery _People; + /// + /// There are no comments for Airlines in the schema. + /// + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + public global::Microsoft.OData.Client.DataServiceQuery Airlines + { + get + { + if ((this._Airlines == null)) + { + this._Airlines = base.CreateQuery("Airlines"); + } + return this._Airlines; + } + } + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + private global::Microsoft.OData.Client.DataServiceQuery _Airlines; + /// + /// There are no comments for Airports in the schema. + /// + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + public global::Microsoft.OData.Client.DataServiceQuery Airports + { + get + { + if ((this._Airports == null)) + { + this._Airports = base.CreateQuery("Airports"); + } + return this._Airports; + } + } + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + private global::Microsoft.OData.Client.DataServiceQuery _Airports; + /// + /// There are no comments for People in the schema. + /// + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + public void AddToPeople(Person person) + { + base.AddObject("People", person); + } + /// + /// There are no comments for Airlines in the schema. + /// + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + public void AddToAirlines(Airline airline) + { + base.AddObject("Airlines", airline); + } + /// + /// There are no comments for Airports in the schema. + /// + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + public void AddToAirports(Airport airport) + { + base.AddObject("Airports", airport); + } + /// + /// There are no comments for Me in the schema. + /// + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + public PersonSingle Me + { + get + { + if ((this._Me == null)) + { + this._Me = new PersonSingle(this, "Me"); + } + return this._Me; + } + } + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + private PersonSingle _Me; + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + private abstract class GeneratedEdmModel + { + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + private static global::Microsoft.OData.Edm.IEdmModel ParsedModel = LoadModelFromString(); + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + private const string Edmx = @" + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +"; + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + public static global::Microsoft.OData.Edm.IEdmModel GetInstance() + { + return ParsedModel; + } + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + private static global::Microsoft.OData.Edm.IEdmModel LoadModelFromString() + { + global::System.Xml.XmlReader reader = CreateXmlReader(Edmx); + try + { + return global::Microsoft.OData.Edm.Csdl.CsdlReader.Parse(reader); + } + finally + { + ((global::System.IDisposable)(reader)).Dispose(); + } + } + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + private static global::System.Xml.XmlReader CreateXmlReader(string edmxToParse) + { + return global::System.Xml.XmlReader.Create(new global::System.IO.StringReader(edmxToParse)); + } + } + /// + /// There are no comments for GetPersonWithMostFriends in the schema. + /// + public global::Microsoft.OData.Service.Sample.TrippinInMemory.Models.PersonSingle GetPersonWithMostFriends() + { + return new global::Microsoft.OData.Service.Sample.TrippinInMemory.Models.PersonSingle(this.CreateFunctionQuerySingle("", "GetPersonWithMostFriends", false)); + } + /// + /// There are no comments for GetNearestAirport in the schema. + /// + public global::Microsoft.OData.Service.Sample.TrippinInMemory.Models.AirportSingle GetNearestAirport(double lat, double lon) + { + return new global::Microsoft.OData.Service.Sample.TrippinInMemory.Models.AirportSingle(this.CreateFunctionQuerySingle("", "GetNearestAirport", false, new global::Microsoft.OData.Client.UriOperationParameter("lat", lat), + new global::Microsoft.OData.Client.UriOperationParameter("lon", lon))); + } + /// + /// There are no comments for ResetDataSource in the schema. + /// + public global::Microsoft.OData.Client.DataServiceActionQuery ResetDataSource() + { + return new global::Microsoft.OData.Client.DataServiceActionQuery(this, this.BaseUri.OriginalString.Trim('/') + "/ResetDataSource"); + } + } + /// + /// There are no comments for PersonSingle in the schema. + /// + internal partial class PersonSingle : global::Microsoft.OData.Client.DataServiceQuerySingle + { + /// + /// Initialize a new PersonSingle object. + /// + public PersonSingle(global::Microsoft.OData.Client.DataServiceContext context, string path) + : base(context, path) { } + + /// + /// Initialize a new PersonSingle object. + /// + public PersonSingle(global::Microsoft.OData.Client.DataServiceContext context, string path, bool isComposable) + : base(context, path, isComposable) { } + + /// + /// Initialize a new PersonSingle object. + /// + public PersonSingle(global::Microsoft.OData.Client.DataServiceQuerySingle query) + : base(query) { } + + /// + /// There are no comments for Friends in the schema. + /// + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + public global::Microsoft.OData.Client.DataServiceQuery Friends + { + get + { + if (!this.IsComposable) + { + throw new global::System.NotSupportedException("The previous function is not composable."); + } + if ((this._Friends == null)) + { + this._Friends = Context.CreateQuery(GetPath("Friends")); + } + return this._Friends; + } + } + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + private global::Microsoft.OData.Client.DataServiceQuery _Friends; + /// + /// There are no comments for Trips in the schema. + /// + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + public global::Microsoft.OData.Client.DataServiceQuery Trips + { + get + { + if (!this.IsComposable) + { + throw new global::System.NotSupportedException("The previous function is not composable."); + } + if ((this._Trips == null)) + { + this._Trips = Context.CreateQuery(GetPath("Trips")); + } + return this._Trips; + } + } + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + private global::Microsoft.OData.Client.DataServiceQuery _Trips; + } + /// + /// There are no comments for Person in the schema. + /// + /// + /// UserName + /// + [global::Microsoft.OData.Client.Key("UserName")] + internal partial class Person : global::Microsoft.OData.Client.BaseEntityType + { + /// + /// Create a new Person object. + /// + /// Initial value of UserName. + /// Initial value of Gender. + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + public static Person CreatePerson(string userName, global::Microsoft.OData.Service.Sample.TrippinInMemory.Models.PersonGender gender) + { + Person person = new Person(); + person.UserName = userName; + person.Gender = gender; + return person; + } + /// + /// There are no comments for Property UserName in the schema. + /// + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + public string UserName + { + get + { + return this._UserName; + } + set + { + this.OnUserNameChanging(value); + this._UserName = value; + this.OnUserNameChanged(); + } + } + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + private string _UserName; + partial void OnUserNameChanging(string value); + partial void OnUserNameChanged(); + /// + /// There are no comments for Property Gender in the schema. + /// + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + public global::Microsoft.OData.Service.Sample.TrippinInMemory.Models.PersonGender Gender + { + get + { + return this._Gender; + } + set + { + this.OnGenderChanging(value); + this._Gender = value; + this.OnGenderChanged(); + } + } + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + private global::Microsoft.OData.Service.Sample.TrippinInMemory.Models.PersonGender _Gender; + partial void OnGenderChanging(global::Microsoft.OData.Service.Sample.TrippinInMemory.Models.PersonGender value); + partial void OnGenderChanged(); + /// + /// There are no comments for Property Age in the schema. + /// + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + public global::System.Nullable Age + { + get + { + return this._Age; + } + set + { + this.OnAgeChanging(value); + this._Age = value; + this.OnAgeChanged(); + } + } + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + private global::System.Nullable _Age; + partial void OnAgeChanging(global::System.Nullable value); + partial void OnAgeChanged(); + /// + /// There are no comments for Property HomeAddress in the schema. + /// + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + public global::Microsoft.OData.Service.Sample.TrippinInMemory.Models.Location HomeAddress + { + get + { + return this._HomeAddress; + } + set + { + this.OnHomeAddressChanging(value); + this._HomeAddress = value; + this.OnHomeAddressChanged(); + } + } + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + private global::Microsoft.OData.Service.Sample.TrippinInMemory.Models.Location _HomeAddress; + partial void OnHomeAddressChanging(global::Microsoft.OData.Service.Sample.TrippinInMemory.Models.Location value); + partial void OnHomeAddressChanged(); + /// + /// There are no comments for Property Friends in the schema. + /// + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + public global::System.Collections.ObjectModel.Collection Friends + { + get + { + return this._Friends; + } + set + { + this.OnFriendsChanging(value); + this._Friends = value; + this.OnFriendsChanged(); + } + } + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + private global::System.Collections.ObjectModel.Collection _Friends = new global::System.Collections.ObjectModel.Collection(); + partial void OnFriendsChanging(global::System.Collections.ObjectModel.Collection value); + partial void OnFriendsChanged(); + /// + /// There are no comments for Property Trips in the schema. + /// + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + public global::System.Collections.ObjectModel.Collection Trips + { + get + { + return this._Trips; + } + set + { + this.OnTripsChanging(value); + this._Trips = value; + this.OnTripsChanged(); + } + } + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + private global::System.Collections.ObjectModel.Collection _Trips = new global::System.Collections.ObjectModel.Collection(); + partial void OnTripsChanging(global::System.Collections.ObjectModel.Collection value); + partial void OnTripsChanged(); + } + /// + /// There are no comments for AirlineSingle in the schema. + /// + internal partial class AirlineSingle : global::Microsoft.OData.Client.DataServiceQuerySingle + { + /// + /// Initialize a new AirlineSingle object. + /// + public AirlineSingle(global::Microsoft.OData.Client.DataServiceContext context, string path) + : base(context, path) { } + + /// + /// Initialize a new AirlineSingle object. + /// + public AirlineSingle(global::Microsoft.OData.Client.DataServiceContext context, string path, bool isComposable) + : base(context, path, isComposable) { } + + /// + /// Initialize a new AirlineSingle object. + /// + public AirlineSingle(global::Microsoft.OData.Client.DataServiceQuerySingle query) + : base(query) { } + + } + /// + /// There are no comments for Airline in the schema. + /// + /// + /// AirlineCode + /// + [global::Microsoft.OData.Client.Key("AirlineCode")] + internal partial class Airline : global::Microsoft.OData.Client.BaseEntityType + { + /// + /// Create a new Airline object. + /// + /// Initial value of AirlineCode. + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + public static Airline CreateAirline(string airlineCode) + { + Airline airline = new Airline(); + airline.AirlineCode = airlineCode; + return airline; + } + /// + /// There are no comments for Property AirlineCode in the schema. + /// + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + public string AirlineCode + { + get + { + return this._AirlineCode; + } + set + { + this.OnAirlineCodeChanging(value); + this._AirlineCode = value; + this.OnAirlineCodeChanged(); + } + } + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + private string _AirlineCode; + partial void OnAirlineCodeChanging(string value); + partial void OnAirlineCodeChanged(); + /// + /// There are no comments for Property Name in the schema. + /// + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + public string Name + { + get + { + return this._Name; + } + set + { + this.OnNameChanging(value); + this._Name = value; + this.OnNameChanged(); + } + } + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + private string _Name; + partial void OnNameChanging(string value); + partial void OnNameChanged(); + } + /// + /// There are no comments for AirportSingle in the schema. + /// + internal partial class AirportSingle : global::Microsoft.OData.Client.DataServiceQuerySingle + { + /// + /// Initialize a new AirportSingle object. + /// + public AirportSingle(global::Microsoft.OData.Client.DataServiceContext context, string path) + : base(context, path) { } + + /// + /// Initialize a new AirportSingle object. + /// + public AirportSingle(global::Microsoft.OData.Client.DataServiceContext context, string path, bool isComposable) + : base(context, path, isComposable) { } + + /// + /// Initialize a new AirportSingle object. + /// + public AirportSingle(global::Microsoft.OData.Client.DataServiceQuerySingle query) + : base(query) { } + + } + /// + /// There are no comments for Airport in the schema. + /// + /// + /// IcaoCode + /// + [global::Microsoft.OData.Client.Key("IcaoCode")] + internal partial class Airport : global::Microsoft.OData.Client.BaseEntityType + { + /// + /// Create a new Airport object. + /// + /// Initial value of IcaoCode. + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + public static Airport CreateAirport(string icaoCode) + { + Airport airport = new Airport(); + airport.IcaoCode = icaoCode; + return airport; + } + /// + /// There are no comments for Property Name in the schema. + /// + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + public string Name + { + get + { + return this._Name; + } + set + { + this.OnNameChanging(value); + this._Name = value; + this.OnNameChanged(); + } + } + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + private string _Name; + partial void OnNameChanging(string value); + partial void OnNameChanged(); + /// + /// There are no comments for Property IcaoCode in the schema. + /// + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + public string IcaoCode + { + get + { + return this._IcaoCode; + } + set + { + this.OnIcaoCodeChanging(value); + this._IcaoCode = value; + this.OnIcaoCodeChanged(); + } + } + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + private string _IcaoCode; + partial void OnIcaoCodeChanging(string value); + partial void OnIcaoCodeChanged(); + } + /// + /// There are no comments for Location in the schema. + /// + internal partial class Location + { + /// + /// There are no comments for Property Address in the schema. + /// + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + public string Address + { + get + { + return this._Address; + } + set + { + this.OnAddressChanging(value); + this._Address = value; + this.OnAddressChanged(); + } + } + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + private string _Address; + partial void OnAddressChanging(string value); + partial void OnAddressChanged(); + /// + /// There are no comments for Property City in the schema. + /// + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + public global::Microsoft.OData.Service.Sample.TrippinInMemory.Models.City City + { + get + { + return this._City; + } + set + { + this.OnCityChanging(value); + this._City = value; + this.OnCityChanged(); + } + } + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + private global::Microsoft.OData.Service.Sample.TrippinInMemory.Models.City _City; + partial void OnCityChanging(global::Microsoft.OData.Service.Sample.TrippinInMemory.Models.City value); + partial void OnCityChanged(); + } + /// + /// There are no comments for City in the schema. + /// + internal partial class City + { + /// + /// There are no comments for Property Name in the schema. + /// + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + public string Name + { + get + { + return this._Name; + } + set + { + this.OnNameChanging(value); + this._Name = value; + this.OnNameChanged(); + } + } + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + private string _Name; + partial void OnNameChanging(string value); + partial void OnNameChanged(); + } + /// + /// There are no comments for TripSingle in the schema. + /// + internal partial class TripSingle : global::Microsoft.OData.Client.DataServiceQuerySingle + { + /// + /// Initialize a new TripSingle object. + /// + public TripSingle(global::Microsoft.OData.Client.DataServiceContext context, string path) + : base(context, path) { } + + /// + /// Initialize a new TripSingle object. + /// + public TripSingle(global::Microsoft.OData.Client.DataServiceContext context, string path, bool isComposable) + : base(context, path, isComposable) { } + + /// + /// Initialize a new TripSingle object. + /// + public TripSingle(global::Microsoft.OData.Client.DataServiceQuerySingle query) + : base(query) { } + + } + /// + /// There are no comments for Trip in the schema. + /// + /// + /// TripId + /// + [global::Microsoft.OData.Client.Key("TripId")] + internal partial class Trip : global::Microsoft.OData.Client.BaseEntityType + { + /// + /// Create a new Trip object. + /// + /// Initial value of TripId. + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + public static Trip CreateTrip(int tripId) + { + Trip trip = new Trip(); + trip.TripId = tripId; + return trip; + } + /// + /// There are no comments for Property TripId in the schema. + /// + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + public int TripId + { + get + { + return this._TripId; + } + set + { + this.OnTripIdChanging(value); + this._TripId = value; + this.OnTripIdChanged(); + } + } + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + private int _TripId; + partial void OnTripIdChanging(int value); + partial void OnTripIdChanged(); + /// + /// There are no comments for Property Name in the schema. + /// + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + public string Name + { + get + { + return this._Name; + } + set + { + this.OnNameChanging(value); + this._Name = value; + this.OnNameChanged(); + } + } + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + private string _Name; + partial void OnNameChanging(string value); + partial void OnNameChanged(); + } + /// + /// There are no comments for FlightSingle in the schema. + /// + internal partial class FlightSingle : global::Microsoft.OData.Client.DataServiceQuerySingle + { + /// + /// Initialize a new FlightSingle object. + /// + public FlightSingle(global::Microsoft.OData.Client.DataServiceContext context, string path) + : base(context, path) { } + + /// + /// Initialize a new FlightSingle object. + /// + public FlightSingle(global::Microsoft.OData.Client.DataServiceContext context, string path, bool isComposable) + : base(context, path, isComposable) { } + + /// + /// Initialize a new FlightSingle object. + /// + public FlightSingle(global::Microsoft.OData.Client.DataServiceQuerySingle query) + : base(query) { } + + /// + /// There are no comments for Airline in the schema. + /// + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + public global::Microsoft.OData.Service.Sample.TrippinInMemory.Models.AirlineSingle Airline + { + get + { + if (!this.IsComposable) + { + throw new global::System.NotSupportedException("The previous function is not composable."); + } + if ((this._Airline == null)) + { + this._Airline = new global::Microsoft.OData.Service.Sample.TrippinInMemory.Models.AirlineSingle(this.Context, GetPath("Airline")); + } + return this._Airline; + } + } + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + private global::Microsoft.OData.Service.Sample.TrippinInMemory.Models.AirlineSingle _Airline; + /// + /// There are no comments for From in the schema. + /// + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + public global::Microsoft.OData.Service.Sample.TrippinInMemory.Models.AirportSingle From + { + get + { + if (!this.IsComposable) + { + throw new global::System.NotSupportedException("The previous function is not composable."); + } + if ((this._From == null)) + { + this._From = new global::Microsoft.OData.Service.Sample.TrippinInMemory.Models.AirportSingle(this.Context, GetPath("From")); + } + return this._From; + } + } + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + private global::Microsoft.OData.Service.Sample.TrippinInMemory.Models.AirportSingle _From; + /// + /// There are no comments for To in the schema. + /// + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + public global::Microsoft.OData.Service.Sample.TrippinInMemory.Models.AirportSingle To + { + get + { + if (!this.IsComposable) + { + throw new global::System.NotSupportedException("The previous function is not composable."); + } + if ((this._To == null)) + { + this._To = new global::Microsoft.OData.Service.Sample.TrippinInMemory.Models.AirportSingle(this.Context, GetPath("To")); + } + return this._To; + } + } + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + private global::Microsoft.OData.Service.Sample.TrippinInMemory.Models.AirportSingle _To; + } + /// + /// There are no comments for Flight in the schema. + /// + [global::Microsoft.OData.Client.EntityType()] + internal partial class Flight : PublicTransportation + { + /// + /// There are no comments for Property FlightNumber in the schema. + /// + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + public string FlightNumber + { + get + { + return this._FlightNumber; + } + set + { + this.OnFlightNumberChanging(value); + this._FlightNumber = value; + this.OnFlightNumberChanged(); + } + } + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + private string _FlightNumber; + partial void OnFlightNumberChanging(string value); + partial void OnFlightNumberChanged(); + /// + /// There are no comments for Property Airline in the schema. + /// + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + public global::Microsoft.OData.Service.Sample.TrippinInMemory.Models.Airline Airline + { + get + { + return this._Airline; + } + set + { + this.OnAirlineChanging(value); + this._Airline = value; + this.OnAirlineChanged(); + } + } + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + private global::Microsoft.OData.Service.Sample.TrippinInMemory.Models.Airline _Airline; + partial void OnAirlineChanging(global::Microsoft.OData.Service.Sample.TrippinInMemory.Models.Airline value); + partial void OnAirlineChanged(); + /// + /// There are no comments for Property From in the schema. + /// + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + public global::Microsoft.OData.Service.Sample.TrippinInMemory.Models.Airport From + { + get + { + return this._From; + } + set + { + this.OnFromChanging(value); + this._From = value; + this.OnFromChanged(); + } + } + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + private global::Microsoft.OData.Service.Sample.TrippinInMemory.Models.Airport _From; + partial void OnFromChanging(global::Microsoft.OData.Service.Sample.TrippinInMemory.Models.Airport value); + partial void OnFromChanged(); + /// + /// There are no comments for Property To in the schema. + /// + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + public global::Microsoft.OData.Service.Sample.TrippinInMemory.Models.Airport To + { + get + { + return this._To; + } + set + { + this.OnToChanging(value); + this._To = value; + this.OnToChanged(); + } + } + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + private global::Microsoft.OData.Service.Sample.TrippinInMemory.Models.Airport _To; + partial void OnToChanging(global::Microsoft.OData.Service.Sample.TrippinInMemory.Models.Airport value); + partial void OnToChanged(); + } + /// + /// There are no comments for EmployeeSingle in the schema. + /// + internal partial class EmployeeSingle : global::Microsoft.OData.Client.DataServiceQuerySingle + { + /// + /// Initialize a new EmployeeSingle object. + /// + public EmployeeSingle(global::Microsoft.OData.Client.DataServiceContext context, string path) + : base(context, path) { } + + /// + /// Initialize a new EmployeeSingle object. + /// + public EmployeeSingle(global::Microsoft.OData.Client.DataServiceContext context, string path, bool isComposable) + : base(context, path, isComposable) { } + + /// + /// Initialize a new EmployeeSingle object. + /// + public EmployeeSingle(global::Microsoft.OData.Client.DataServiceQuerySingle query) + : base(query) { } + + /// + /// There are no comments for Peers in the schema. + /// + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + public global::Microsoft.OData.Client.DataServiceQuery Peers + { + get + { + if (!this.IsComposable) + { + throw new global::System.NotSupportedException("The previous function is not composable."); + } + if ((this._Peers == null)) + { + this._Peers = Context.CreateQuery(GetPath("Peers")); + } + return this._Peers; + } + } + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + private global::Microsoft.OData.Client.DataServiceQuery _Peers; + /// + /// There are no comments for Friends in the schema. + /// + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + public global::Microsoft.OData.Client.DataServiceQuery Friends + { + get + { + if (!this.IsComposable) + { + throw new global::System.NotSupportedException("The previous function is not composable."); + } + if ((this._Friends == null)) + { + this._Friends = Context.CreateQuery(GetPath("Friends")); + } + return this._Friends; + } + } + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + private global::Microsoft.OData.Client.DataServiceQuery _Friends; + /// + /// There are no comments for Trips in the schema. + /// + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + public global::Microsoft.OData.Client.DataServiceQuery Trips + { + get + { + if (!this.IsComposable) + { + throw new global::System.NotSupportedException("The previous function is not composable."); + } + if ((this._Trips == null)) + { + this._Trips = Context.CreateQuery(GetPath("Trips")); + } + return this._Trips; + } + } + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + private global::Microsoft.OData.Client.DataServiceQuery _Trips; + } + /// + /// There are no comments for Employee in the schema. + /// + /// + /// UserName + /// + [global::Microsoft.OData.Client.Key("UserName")] + internal partial class Employee : Person + { + /// + /// Create a new Employee object. + /// + /// Initial value of UserName. + /// Initial value of Gender. + /// Initial value of Cost. + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + public static Employee CreateEmployee(string userName, global::Microsoft.OData.Service.Sample.TrippinInMemory.Models.PersonGender gender, long cost) + { + Employee employee = new Employee(); + employee.UserName = userName; + employee.Gender = gender; + employee.Cost = cost; + return employee; + } + /// + /// There are no comments for Property Cost in the schema. + /// + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + public long Cost + { + get + { + return this._Cost; + } + set + { + this.OnCostChanging(value); + this._Cost = value; + this.OnCostChanged(); + } + } + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + private long _Cost; + partial void OnCostChanging(long value); + partial void OnCostChanged(); + /// + /// There are no comments for Property Peers in the schema. + /// + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + public global::System.Collections.ObjectModel.Collection Peers + { + get + { + return this._Peers; + } + set + { + this.OnPeersChanging(value); + this._Peers = value; + this.OnPeersChanged(); + } + } + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + private global::System.Collections.ObjectModel.Collection _Peers = new global::System.Collections.ObjectModel.Collection(); + partial void OnPeersChanging(global::System.Collections.ObjectModel.Collection value); + partial void OnPeersChanged(); + } + /// + /// There are no comments for PersonGender in the schema. + /// + internal enum PersonGender + { + Male = 0, + Female = 1, + Unknow = 2 + } + /// + /// Class containing all extension methods + /// + internal static class ExtensionMethods + { + /// + /// Get an entity of type global::Microsoft.OData.Service.Sample.TrippinInMemory.Models.Person as global::Microsoft.OData.Service.Sample.TrippinInMemory.Models.PersonSingle specified by key from an entity set + /// + /// source entity set + /// dictionary with the names and values of keys + public static global::Microsoft.OData.Service.Sample.TrippinInMemory.Models.PersonSingle ByKey(this global::Microsoft.OData.Client.DataServiceQuery source, global::System.Collections.Generic.Dictionary keys) + { + return new global::Microsoft.OData.Service.Sample.TrippinInMemory.Models.PersonSingle(source.Context, source.GetKeyPath(global::Microsoft.OData.Client.Serializer.GetKeyString(source.Context, keys))); + } + /// + /// Get an entity of type global::Microsoft.OData.Service.Sample.TrippinInMemory.Models.Person as global::Microsoft.OData.Service.Sample.TrippinInMemory.Models.PersonSingle specified by key from an entity set + /// + /// source entity set + /// The value of userName + public static global::Microsoft.OData.Service.Sample.TrippinInMemory.Models.PersonSingle ByKey(this global::Microsoft.OData.Client.DataServiceQuery source, + string userName) + { + global::System.Collections.Generic.Dictionary keys = new global::System.Collections.Generic.Dictionary + { + { "UserName", userName } + }; + return new global::Microsoft.OData.Service.Sample.TrippinInMemory.Models.PersonSingle(source.Context, source.GetKeyPath(global::Microsoft.OData.Client.Serializer.GetKeyString(source.Context, keys))); + } + /// + /// Get an entity of type global::Microsoft.OData.Service.Sample.TrippinInMemory.Models.Airline as global::Microsoft.OData.Service.Sample.TrippinInMemory.Models.AirlineSingle specified by key from an entity set + /// + /// source entity set + /// dictionary with the names and values of keys + public static global::Microsoft.OData.Service.Sample.TrippinInMemory.Models.AirlineSingle ByKey(this global::Microsoft.OData.Client.DataServiceQuery source, global::System.Collections.Generic.Dictionary keys) + { + return new global::Microsoft.OData.Service.Sample.TrippinInMemory.Models.AirlineSingle(source.Context, source.GetKeyPath(global::Microsoft.OData.Client.Serializer.GetKeyString(source.Context, keys))); + } + /// + /// Get an entity of type global::Microsoft.OData.Service.Sample.TrippinInMemory.Models.Airline as global::Microsoft.OData.Service.Sample.TrippinInMemory.Models.AirlineSingle specified by key from an entity set + /// + /// source entity set + /// The value of airlineCode + public static global::Microsoft.OData.Service.Sample.TrippinInMemory.Models.AirlineSingle ByKey(this global::Microsoft.OData.Client.DataServiceQuery source, + string airlineCode) + { + global::System.Collections.Generic.Dictionary keys = new global::System.Collections.Generic.Dictionary + { + { "AirlineCode", airlineCode } + }; + return new global::Microsoft.OData.Service.Sample.TrippinInMemory.Models.AirlineSingle(source.Context, source.GetKeyPath(global::Microsoft.OData.Client.Serializer.GetKeyString(source.Context, keys))); + } + /// + /// Get an entity of type global::Microsoft.OData.Service.Sample.TrippinInMemory.Models.Airport as global::Microsoft.OData.Service.Sample.TrippinInMemory.Models.AirportSingle specified by key from an entity set + /// + /// source entity set + /// dictionary with the names and values of keys + public static global::Microsoft.OData.Service.Sample.TrippinInMemory.Models.AirportSingle ByKey(this global::Microsoft.OData.Client.DataServiceQuery source, global::System.Collections.Generic.Dictionary keys) + { + return new global::Microsoft.OData.Service.Sample.TrippinInMemory.Models.AirportSingle(source.Context, source.GetKeyPath(global::Microsoft.OData.Client.Serializer.GetKeyString(source.Context, keys))); + } + /// + /// Get an entity of type global::Microsoft.OData.Service.Sample.TrippinInMemory.Models.Airport as global::Microsoft.OData.Service.Sample.TrippinInMemory.Models.AirportSingle specified by key from an entity set + /// + /// source entity set + /// The value of icaoCode + public static global::Microsoft.OData.Service.Sample.TrippinInMemory.Models.AirportSingle ByKey(this global::Microsoft.OData.Client.DataServiceQuery source, + string icaoCode) + { + global::System.Collections.Generic.Dictionary keys = new global::System.Collections.Generic.Dictionary + { + { "IcaoCode", icaoCode } + }; + return new global::Microsoft.OData.Service.Sample.TrippinInMemory.Models.AirportSingle(source.Context, source.GetKeyPath(global::Microsoft.OData.Client.Serializer.GetKeyString(source.Context, keys))); + } + /// + /// Get an entity of type global::Microsoft.OData.Service.Sample.TrippinInMemory.Models.Trip as global::Microsoft.OData.Service.Sample.TrippinInMemory.Models.TripSingle specified by key from an entity set + /// + /// source entity set + /// dictionary with the names and values of keys + public static global::Microsoft.OData.Service.Sample.TrippinInMemory.Models.TripSingle ByKey(this global::Microsoft.OData.Client.DataServiceQuery source, global::System.Collections.Generic.Dictionary keys) + { + return new global::Microsoft.OData.Service.Sample.TrippinInMemory.Models.TripSingle(source.Context, source.GetKeyPath(global::Microsoft.OData.Client.Serializer.GetKeyString(source.Context, keys))); + } + /// + /// Get an entity of type global::Microsoft.OData.Service.Sample.TrippinInMemory.Models.Trip as global::Microsoft.OData.Service.Sample.TrippinInMemory.Models.TripSingle specified by key from an entity set + /// + /// source entity set + /// The value of tripId + public static global::Microsoft.OData.Service.Sample.TrippinInMemory.Models.TripSingle ByKey(this global::Microsoft.OData.Client.DataServiceQuery source, + int tripId) + { + global::System.Collections.Generic.Dictionary keys = new global::System.Collections.Generic.Dictionary + { + { "TripId", tripId } + }; + return new global::Microsoft.OData.Service.Sample.TrippinInMemory.Models.TripSingle(source.Context, source.GetKeyPath(global::Microsoft.OData.Client.Serializer.GetKeyString(source.Context, keys))); + } + /// + /// Cast an entity of type global::Microsoft.OData.Service.Sample.TrippinInMemory.Models.PublicTransportation to its derived type global::Microsoft.OData.Service.Sample.TrippinInMemory.Models.Flight + /// + /// source entity + public static global::Microsoft.OData.Service.Sample.TrippinInMemory.Models.FlightSingle CastToFlight(this global::Microsoft.OData.Client.DataServiceQuerySingle source) + { + global::Microsoft.OData.Client.DataServiceQuerySingle query = source.CastTo(); + return new global::Microsoft.OData.Service.Sample.TrippinInMemory.Models.FlightSingle(source.Context, query.GetPath(null)); + } + /// + /// Get an entity of type global::Microsoft.OData.Service.Sample.TrippinInMemory.Models.Employee as global::Microsoft.OData.Service.Sample.TrippinInMemory.Models.EmployeeSingle specified by key from an entity set + /// + /// source entity set + /// dictionary with the names and values of keys + public static global::Microsoft.OData.Service.Sample.TrippinInMemory.Models.EmployeeSingle ByKey(this global::Microsoft.OData.Client.DataServiceQuery source, global::System.Collections.Generic.Dictionary keys) + { + return new global::Microsoft.OData.Service.Sample.TrippinInMemory.Models.EmployeeSingle(source.Context, source.GetKeyPath(global::Microsoft.OData.Client.Serializer.GetKeyString(source.Context, keys))); + } + /// + /// Get an entity of type global::Microsoft.OData.Service.Sample.TrippinInMemory.Models.Employee as global::Microsoft.OData.Service.Sample.TrippinInMemory.Models.EmployeeSingle specified by key from an entity set + /// + /// source entity set + /// The value of userName + public static global::Microsoft.OData.Service.Sample.TrippinInMemory.Models.EmployeeSingle ByKey(this global::Microsoft.OData.Client.DataServiceQuery source, + string userName) + { + global::System.Collections.Generic.Dictionary keys = new global::System.Collections.Generic.Dictionary + { + { "UserName", userName } + }; + return new global::Microsoft.OData.Service.Sample.TrippinInMemory.Models.EmployeeSingle(source.Context, source.GetKeyPath(global::Microsoft.OData.Client.Serializer.GetKeyString(source.Context, keys))); + } + /// + /// Cast an entity of type global::Microsoft.OData.Service.Sample.TrippinInMemory.Models.Person to its derived type global::Microsoft.OData.Service.Sample.TrippinInMemory.Models.Employee + /// + /// source entity + public static global::Microsoft.OData.Service.Sample.TrippinInMemory.Models.EmployeeSingle CastToEmployee(this global::Microsoft.OData.Client.DataServiceQuerySingle source) + { + global::Microsoft.OData.Client.DataServiceQuerySingle query = source.CastTo(); + return new global::Microsoft.OData.Service.Sample.TrippinInMemory.Models.EmployeeSingle(source.Context, query.GetPath(null)); + } + } +} diff --git a/ODataConnectedService/test/ODataConnectedService.Tests/ODataConnectedService.Tests.csproj b/ODataConnectedService/test/ODataConnectedService.Tests/ODataConnectedService.Tests.csproj new file mode 100644 index 0000000..87cfbea --- /dev/null +++ b/ODataConnectedService/test/ODataConnectedService.Tests/ODataConnectedService.Tests.csproj @@ -0,0 +1,72 @@ + + + + + Debug + AnyCPU + {903B31D0-BE14-4D9E-BA76-186FA82B3A37} + Library + Properties + ODataConnectedService.Tests + ODataConnectedService.Tests + v4.7.2 + 512 + {3AC096D0-A1C2-E12C-1390-A8335801FDAB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} + 15.0 + $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion) + $(ProgramFiles)\Common Files\microsoft shared\VSTT\$(VisualStudioVersion)\UITestExtensionPackages + False + UnitTest + + + + + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + x86 + + + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + + + + + + + + + 1.3.2 + + + 1.3.2 + + + + + + + + {a8bc5b8e-9ab7-4257-b8f1-e7c62169f9b5} + ODataConnectedService + + + + + + + + + \ No newline at end of file diff --git a/ODataConnectedService/test/ODataConnectedService.Tests/Properties/AssemblyInfo.cs b/ODataConnectedService/test/ODataConnectedService.Tests/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..42f20f3 --- /dev/null +++ b/ODataConnectedService/test/ODataConnectedService.Tests/Properties/AssemblyInfo.cs @@ -0,0 +1,20 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +[assembly: AssemblyTitle("ODataConnectedService.Tests")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("ODataConnectedService.Tests")] +[assembly: AssemblyCopyright("Copyright © 2020")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +[assembly: ComVisible(false)] + +[assembly: Guid("903b31d0-be14-4d9e-ba76-186fa82b3a37")] + +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/ODataConnectedService/test/ODataConnectedService.Tests/Templates/ODataT4CodeGeneratorTest.cs b/ODataConnectedService/test/ODataConnectedService.Tests/Templates/ODataT4CodeGeneratorTest.cs new file mode 100644 index 0000000..8be6bb6 --- /dev/null +++ b/ODataConnectedService/test/ODataConnectedService.Tests/Templates/ODataT4CodeGeneratorTest.cs @@ -0,0 +1,110 @@ +using System; +using System.IO; +using System.Reflection; +using System.Text.RegularExpressions; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Microsoft.OData.ConnectedService.Templates; + +namespace ODataConnectedService.Tests.Templates +{ + [TestClass] + public class ODataT4CodeGeneratorTest + { + [TestMethod] + public void TestEntitiesComplexTypesEnumsFunctions() + { + string edmx = LoadReferenceContent("EntitiesEnumsFunctions.xml"); + string expected = LoadReferenceContent("EntitiesEnumsFunctions.cs"); + var generator = new ODataT4CodeGenerator() + { + Edmx = edmx, + TargetLanguage = ODataT4CodeGenerator.LanguageOption.CSharp + }; + var output = generator.TransformText(); + VerifyGeneratedCode(expected, output); + } + + [TestMethod] + public void TestEntitiesComplexTypesEnumsFunctionsDSC() + { + string edmx = LoadReferenceContent("EntitiesEnumsFunctions.xml"); + string expected = LoadReferenceContent("EntitiesEnumsFunctionsDSC.cs"); + var generator = new ODataT4CodeGenerator() + { + Edmx = edmx, + TargetLanguage = ODataT4CodeGenerator.LanguageOption.CSharp, + UseDataServiceCollection = true + }; + var output = generator.TransformText(); + VerifyGeneratedCode(expected, output); + } + + [TestMethod] + public void TestEntitiesComplexTypesEnumFunctionsWithInternalTypes() + { + string edmx = LoadReferenceContent("EntitiesEnumsFunctions.xml"); + string expected = LoadReferenceContent("EntitiesEnumsFunctionsWithInternalTypes.cs"); + var generator = new ODataT4CodeGenerator() + { + Edmx = edmx, + TargetLanguage = ODataT4CodeGenerator.LanguageOption.CSharp, + MakeTypesInternal = true + + }; + var output = generator.TransformText(); + VerifyGeneratedCode(expected, output); + } + + [TestMethod] + public void TestEntitiesComplexTypesEnumFunctionsDSCWithInternalTypes() + { + string edmx = LoadReferenceContent("EntitiesEnumsFunctions.xml"); + string expected = LoadReferenceContent("EntitiesEnumsFunctionsDSCWithInternalTypes.cs"); + var generator = new ODataT4CodeGenerator() + { + Edmx = edmx, + TargetLanguage = ODataT4CodeGenerator.LanguageOption.CSharp, + UseDataServiceCollection = true, + MakeTypesInternal = true + + }; + var output = generator.TransformText(); + VerifyGeneratedCode(expected, output); + } + + static Assembly Assembly = Assembly.GetExecutingAssembly(); + const string ReferenceResourcePrefix = "ODataConnectedService.Tests.CodeGenReferences."; + + static string LoadReferenceContent(string name) + { + var fullName = $"{ReferenceResourcePrefix}{name}"; + using (var stream = Assembly.GetManifestResourceStream(fullName)) + { + if (stream == null) + { + throw new Exception($"Embedded resource '{name}' not found."); + } + var reader = new StreamReader(stream); + return reader.ReadToEnd(); + } + } + + static void VerifyGeneratedCode(string expectedCode, string actualCode) + { + var normalizedExpected = NormalizeGeneratedCode(expectedCode); + var normalizedActual = NormalizeGeneratedCode(actualCode); + Assert.AreEqual(normalizedExpected, normalizedActual); + } + + static string NormalizeGeneratedCode(string code) + { + string normalized = Regex.Replace(code, "// Generation date:.*", string.Empty, RegexOptions.Multiline); + normalized = Regex.Replace(normalized, "'Generation date:.*", string.Empty, RegexOptions.Multiline); + normalized = Regex.Replace(normalized, "// Runtime Version:.*", string.Empty, RegexOptions.Multiline); + normalized = Regex.Replace(normalized, "' Runtime Version:.*", string.Empty, RegexOptions.Multiline); + //Remove the spaces from the string to avoid indentation change errors + normalized = Regex.Replace(normalized, @"\s+", ""); + return normalized; + } + } +} From 5d35c2777004f26bef488afe81382e821de2adb1 Mon Sep 17 00:00:00 2001 From: Clement Habinshuti Date: Wed, 22 Jan 2020 11:57:21 +0300 Subject: [PATCH 09/24] Add tests for V4CodeGenDescriptor --- .../CodeGeneration/BaseCodeGenDescriptor.cs | 2 +- .../src/CodeGeneration/V4CodeGenDescriptor.cs | 6 +- .../src/ODataConnectedService.csproj | 2 + .../Templates/IODataT4CodeGeneratorFactory.cs | 13 ++ .../Templates/ODataT4CodeGeneratorFactory.cs | 16 ++ .../CodeGeneration/V4CodeGenDescriptorTest.cs | 204 ++++++++++++++++++ .../ODataConnectedService.Tests.csproj | 10 + .../Templates/ODataT4CodeGeneratorTest.cs | 2 + 8 files changed, 251 insertions(+), 4 deletions(-) create mode 100644 ODataConnectedService/src/Templates/IODataT4CodeGeneratorFactory.cs create mode 100644 ODataConnectedService/src/Templates/ODataT4CodeGeneratorFactory.cs create mode 100644 ODataConnectedService/test/ODataConnectedService.Tests/CodeGeneration/V4CodeGenDescriptorTest.cs diff --git a/ODataConnectedService/src/CodeGeneration/BaseCodeGenDescriptor.cs b/ODataConnectedService/src/CodeGeneration/BaseCodeGenDescriptor.cs index c209a8e..927cc90 100644 --- a/ODataConnectedService/src/CodeGeneration/BaseCodeGenDescriptor.cs +++ b/ODataConnectedService/src/CodeGeneration/BaseCodeGenDescriptor.cs @@ -50,7 +50,7 @@ public BaseCodeGenDescriptor(string metadataUri, ConnectedServiceHandlerContext this.ServiceConfiguration = ((ODataConnectedServiceInstance)this.Context.ServiceInstance).ServiceConfig; } - private void Init() + protected virtual void Init() { var componentModel = (IComponentModel)Shell.Package.GetGlobalService(typeof(SComponentModel)); this.PackageInstallerServices = componentModel.GetService(); diff --git a/ODataConnectedService/src/CodeGeneration/V4CodeGenDescriptor.cs b/ODataConnectedService/src/CodeGeneration/V4CodeGenDescriptor.cs index 0bf8471..3ee070c 100644 --- a/ODataConnectedService/src/CodeGeneration/V4CodeGenDescriptor.cs +++ b/ODataConnectedService/src/CodeGeneration/V4CodeGenDescriptor.cs @@ -46,7 +46,7 @@ public override async Task AddGeneratedClientCode() } else { - await AddGeneratedCSharpCode(); + await AddGeneratedCSharpCode(new ODataT4CodeGeneratorFactory()); } } @@ -76,9 +76,9 @@ private async Task AddT4File() await this.Context.HandlerHelper.AddFileAsync(tempFile, Path.Combine(referenceFolder, this.GeneratedFileNamePrefix + ".tt")); } - private async Task AddGeneratedCSharpCode() + public async Task AddGeneratedCSharpCode(IODataT4CodeGeneratorFactory codeGeneratorFactory) { - ODataT4CodeGenerator t4CodeGenerator = new ODataT4CodeGenerator(); + ODataT4CodeGenerator t4CodeGenerator = codeGeneratorFactory.Create(); t4CodeGenerator.MetadataDocumentUri = MetadataUri; t4CodeGenerator.UseDataServiceCollection = this.ServiceConfiguration.UseDataServiceCollection; t4CodeGenerator.TargetLanguage = ODataT4CodeGenerator.LanguageOption.CSharp; diff --git a/ODataConnectedService/src/ODataConnectedService.csproj b/ODataConnectedService/src/ODataConnectedService.csproj index 11b437f..1e2fe88 100644 --- a/ODataConnectedService/src/ODataConnectedService.csproj +++ b/ODataConnectedService/src/ODataConnectedService.csproj @@ -176,11 +176,13 @@ + True True ODataT4CodeGenerator.tt + diff --git a/ODataConnectedService/src/Templates/IODataT4CodeGeneratorFactory.cs b/ODataConnectedService/src/Templates/IODataT4CodeGeneratorFactory.cs new file mode 100644 index 0000000..f9d5fad --- /dev/null +++ b/ODataConnectedService/src/Templates/IODataT4CodeGeneratorFactory.cs @@ -0,0 +1,13 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Microsoft.OData.ConnectedService.Templates +{ + interface IODataT4CodeGeneratorFactory + { + ODataT4CodeGenerator Create(); + } +} diff --git a/ODataConnectedService/src/Templates/ODataT4CodeGeneratorFactory.cs b/ODataConnectedService/src/Templates/ODataT4CodeGeneratorFactory.cs new file mode 100644 index 0000000..229596b --- /dev/null +++ b/ODataConnectedService/src/Templates/ODataT4CodeGeneratorFactory.cs @@ -0,0 +1,16 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Microsoft.OData.ConnectedService.Templates +{ + class ODataT4CodeGeneratorFactory: IODataT4CodeGeneratorFactory + { + public ODataT4CodeGenerator Create() + { + return new ODataT4CodeGenerator(); + } + } +} diff --git a/ODataConnectedService/test/ODataConnectedService.Tests/CodeGeneration/V4CodeGenDescriptorTest.cs b/ODataConnectedService/test/ODataConnectedService.Tests/CodeGeneration/V4CodeGenDescriptorTest.cs new file mode 100644 index 0000000..bd2d414 --- /dev/null +++ b/ODataConnectedService/test/ODataConnectedService.Tests/CodeGeneration/V4CodeGenDescriptorTest.cs @@ -0,0 +1,204 @@ +using System.Collections.Generic; +using System.IO; +using System.Threading.Tasks; +using Microsoft.VisualStudio.ConnectedServices; +using EnvDTE; +using Moq; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Microsoft.OData.ConnectedService; +using Microsoft.OData.ConnectedService.CodeGeneration; +using Microsoft.OData.ConnectedService.Models; +using Microsoft.OData.ConnectedService.Templates; + +namespace ODataConnectedService.Tests.CodeGeneration +{ + [TestClass] + public class V4CodeGenDescriptorTest + { + readonly static string TestProjectRootPath = Path.Combine(Directory.GetCurrentDirectory(), "TempODataConnectedServiceTest"); + readonly static string ServicesRootFolder = "ConnectedServicesRoot"; + readonly static string MetadataUri = "http://service/$metadata"; + + [TestCleanup] + public void CleanUp() + { + try + { + Directory.Delete(TestProjectRootPath, true); + } + catch (System.IO.DirectoryNotFoundException) { } + } + + [TestMethod] + public void TestAddGeneratedCSharpCodePassesServiceConfigOptionsToCodeGenerator() + { + var handlerHelper = new TestConnectedServiceHandlerHelper(); + var codeGenFactory = new TestODataT4CodeGeneratorFactory(); + + var serviceConfig = new ServiceConfigurationV4() + { + UseDataServiceCollection = true, + IgnoreUnexpectedElementsAndAttributes = true, + EnableNamingAlias = true, + NamespacePrefix = "Prefix", + MakeTypesInternal = true + }; + var codeGenDescriptor = SetupCodeGenDescriptor(serviceConfig, "TestService", handlerHelper); + codeGenDescriptor.AddGeneratedCSharpCode(codeGenFactory).Wait(); + var generator = codeGenFactory.LastCreatedInstance; + Assert.AreEqual(true, generator.UseDataServiceCollection); + Assert.AreEqual(true, generator.EnableNamingAlias); + Assert.AreEqual(true, generator.MakeTypesInternal); + Assert.AreEqual("Prefix", generator.NamespacePrefix); + Assert.AreEqual(MetadataUri, generator.MetadataDocumentUri); + Assert.AreEqual(ODataT4CodeGenerator.LanguageOption.CSharp, generator.TargetLanguage); + + serviceConfig = new ServiceConfigurationV4() + { + UseDataServiceCollection = false, + IgnoreUnexpectedElementsAndAttributes = false, + EnableNamingAlias = false, + NamespacePrefix = null, + MakeTypesInternal = false + }; + codeGenDescriptor = SetupCodeGenDescriptor(serviceConfig, "TestService", handlerHelper); + codeGenDescriptor.AddGeneratedCSharpCode(codeGenFactory).Wait(); + generator = codeGenFactory.LastCreatedInstance; + Assert.AreEqual(false, generator.UseDataServiceCollection); + Assert.AreEqual(false, generator.EnableNamingAlias); + Assert.AreEqual(false, generator.MakeTypesInternal); + Assert.AreEqual(null, generator.NamespacePrefix); + Assert.AreEqual(MetadataUri, generator.MetadataDocumentUri); + Assert.AreEqual(ODataT4CodeGenerator.LanguageOption.CSharp, generator.TargetLanguage); + } + + [TestMethod] + public void TestAddGeneratedCSharpCodeGeneratesAndSavesCodeFile() + { + var serviceName = "MyService"; + ServiceConfiguration serviceConfig = new ServiceConfigurationV4() + { + MakeTypesInternal = true, + UseDataServiceCollection = false, + ServiceName = serviceName, + GeneratedFileNamePrefix = "MyFile" + }; + var handlerHelper = new TestConnectedServiceHandlerHelper(); + var codeGenDescriptor = SetupCodeGenDescriptor(serviceConfig, serviceName, handlerHelper); + codeGenDescriptor.AddGeneratedCSharpCode(new TestODataT4CodeGeneratorFactory()).Wait(); + using (var reader = new StreamReader(handlerHelper.AddedFileInputFileName)) + { + var generatedCode = reader.ReadToEnd(); + Assert.AreEqual("Generated code", generatedCode); + Assert.AreEqual(Path.Combine(TestProjectRootPath, ServicesRootFolder, serviceName, "MyFile.cs"), handlerHelper.AddedFileTargetFilePath); + } + } + + static V4CodeGenDescriptor SetupCodeGenDescriptor(ServiceConfiguration serviceConfig, string serviceName, TestConnectedServiceHandlerHelper handlerHelper) + { + var referenceFolderPath = Path.Combine(TestProjectRootPath, ServicesRootFolder, serviceName); + Directory.CreateDirectory(referenceFolderPath); + Project project = CreateTestProject(TestProjectRootPath); + var serviceInstance = new ODataConnectedServiceInstance() + { + ServiceConfig = serviceConfig, + Name = serviceName + }; + handlerHelper.ServicesRootFolder = ServicesRootFolder; + ConnectedServiceHandlerContext context = new TestConnectedServiceHandlerContext(serviceInstance, handlerHelper); + + return new TestV4CodeGenDescriptor(MetadataUri, context, project); + } + + static Project CreateTestProject(string projectPath) + { + var fullPathPropertyMock = new Mock(); + fullPathPropertyMock.SetupGet(p => p.Value).Returns(projectPath); + var projectPropertiesMock = new Mock(); + projectPropertiesMock.Setup(p => p.Item(It.Is(s => s == "FullPath"))) + .Returns(fullPathPropertyMock.Object); + var projectMock = new Mock(); + projectMock.SetupGet(p => p.Properties) + .Returns(projectPropertiesMock.Object); + return projectMock.Object; + } + } + + class TestV4CodeGenDescriptor: V4CodeGenDescriptor + { + public TestV4CodeGenDescriptor(string metadataUri, ConnectedServiceHandlerContext context, Project project) + : base(metadataUri, context, project) + { + } + protected override void Init() { } + } + + class TestODataT4CodeGenerator: ODataT4CodeGenerator + { + public override string TransformText() + { + return "Generated code"; + } + } + + class TestODataT4CodeGeneratorFactory: IODataT4CodeGeneratorFactory + { + public ODataT4CodeGenerator LastCreatedInstance { get; private set; } + public ODataT4CodeGenerator Create() + { + var generator = new TestODataT4CodeGenerator(); + LastCreatedInstance = generator; + return generator; + } + } + + class TestConnectedServiceHandlerHelper: ConnectedServiceHandlerHelper + { + // used to access the temp file that the generated code was written to + public string AddedFileInputFileName { get; private set; } + // used to find out which file the final output would be written to + public string AddedFileTargetFilePath { get; private set; } + public string ServicesRootFolder { get; set; } + public override IDictionary TokenReplacementValues { get; } + public override void AddAssemblyReference(string assemblyPath) { } + public override string GetServiceArtifactsRootFolder() => ServicesRootFolder; + public override string PerformTokenReplacement(string input, IDictionary additionalReplacementValues = null) => ""; + + public override Task AddFileAsync(string fileName, string targetPath, AddFileOptions addFileOptions = null) + { + AddedFileInputFileName = fileName; + AddedFileTargetFilePath = targetPath; + return Task.FromResult(""); + } + } + + class TestConnectedServiceHandlerContext: ConnectedServiceHandlerContext + { + public TestConnectedServiceHandlerContext(ConnectedServiceInstance serviceInstance, ConnectedServiceHandlerHelper handlerHelper ): base() + { + ServiceInstance = serviceInstance; + HandlerHelper = handlerHelper; + } + public override IDictionary Args => throw new System.NotImplementedException(); + + public override EditableXmlConfigHelper CreateEditableXmlConfigHelper() + { + return null; + } + + public override XmlConfigHelper CreateReadOnlyXmlConfigHelper() + { + throw new System.NotImplementedException(); + } + + public override TData GetExtendedDesignerData() + { + throw new System.NotImplementedException(); + } + + public override void SetExtendedDesignerData(TData data) + { + throw new System.NotImplementedException(); + } + } +} diff --git a/ODataConnectedService/test/ODataConnectedService.Tests/ODataConnectedService.Tests.csproj b/ODataConnectedService/test/ODataConnectedService.Tests/ODataConnectedService.Tests.csproj index 87cfbea..c2db9f2 100644 --- a/ODataConnectedService/test/ODataConnectedService.Tests/ODataConnectedService.Tests.csproj +++ b/ODataConnectedService/test/ODataConnectedService.Tests/ODataConnectedService.Tests.csproj @@ -39,14 +39,24 @@ 4 + + True + + + + 2.0.0 + + + 4.13.1 + 1.3.2 diff --git a/ODataConnectedService/test/ODataConnectedService.Tests/Templates/ODataT4CodeGeneratorTest.cs b/ODataConnectedService/test/ODataConnectedService.Tests/Templates/ODataT4CodeGeneratorTest.cs index 8be6bb6..fa67f6e 100644 --- a/ODataConnectedService/test/ODataConnectedService.Tests/Templates/ODataT4CodeGeneratorTest.cs +++ b/ODataConnectedService/test/ODataConnectedService.Tests/Templates/ODataT4CodeGeneratorTest.cs @@ -2,8 +2,10 @@ using System.IO; using System.Reflection; using System.Text.RegularExpressions; +using System.CodeDom.Compiler; using Microsoft.VisualStudio.TestTools.UnitTesting; using Microsoft.OData.ConnectedService.Templates; +using Microsoft.CSharp; namespace ODataConnectedService.Tests.Templates { From 92673ae9885bf89389531f4ec30c015ba0850aa2 Mon Sep 17 00:00:00 2001 From: Clement Habinshuti Date: Wed, 22 Jan 2020 15:59:22 +0300 Subject: [PATCH 10/24] Refactor V4CodeGenDescriptor --- .../src/CodeGeneration/V4CodeGenDescriptor.cs | 17 ++++--- .../src/ODataConnectedServiceHandler.cs | 3 +- .../CodeGeneration/V4CodeGenDescriptorTest.cs | 44 ++++++++++++------- 3 files changed, 39 insertions(+), 25 deletions(-) diff --git a/ODataConnectedService/src/CodeGeneration/V4CodeGenDescriptor.cs b/ODataConnectedService/src/CodeGeneration/V4CodeGenDescriptor.cs index 3ee070c..95bbae5 100644 --- a/ODataConnectedService/src/CodeGeneration/V4CodeGenDescriptor.cs +++ b/ODataConnectedService/src/CodeGeneration/V4CodeGenDescriptor.cs @@ -15,14 +15,17 @@ namespace Microsoft.OData.ConnectedService.CodeGeneration { internal class V4CodeGenDescriptor : BaseCodeGenDescriptor { - public V4CodeGenDescriptor(string metadataUri, ConnectedServiceHandlerContext context, Project project) + public V4CodeGenDescriptor(string metadataUri, ConnectedServiceHandlerContext context, Project project, IODataT4CodeGeneratorFactory codeGeneratorFactory) : base(metadataUri, context, project) { - this.ClientNuGetPackageName = Common.Constants.V4ClientNuGetPackage; - this.ClientDocUri = Common.Constants.V4DocUri; - this.ServiceConfiguration = base.ServiceConfiguration as ServiceConfigurationV4; + ClientNuGetPackageName = Common.Constants.V4ClientNuGetPackage; + ClientDocUri = Common.Constants.V4DocUri; + ServiceConfiguration = base.ServiceConfiguration as ServiceConfigurationV4; + CodeGeneratorFactory = codeGeneratorFactory; } + private IODataT4CodeGeneratorFactory CodeGeneratorFactory { get; set; } + private new ServiceConfigurationV4 ServiceConfiguration { get; set; } public override async Task AddNugetPackages() @@ -46,7 +49,7 @@ public override async Task AddGeneratedClientCode() } else { - await AddGeneratedCSharpCode(new ODataT4CodeGeneratorFactory()); + await AddGeneratedCSharpCode(); } } @@ -76,9 +79,9 @@ private async Task AddT4File() await this.Context.HandlerHelper.AddFileAsync(tempFile, Path.Combine(referenceFolder, this.GeneratedFileNamePrefix + ".tt")); } - public async Task AddGeneratedCSharpCode(IODataT4CodeGeneratorFactory codeGeneratorFactory) + private async Task AddGeneratedCSharpCode() { - ODataT4CodeGenerator t4CodeGenerator = codeGeneratorFactory.Create(); + ODataT4CodeGenerator t4CodeGenerator = CodeGeneratorFactory.Create(); t4CodeGenerator.MetadataDocumentUri = MetadataUri; t4CodeGenerator.UseDataServiceCollection = this.ServiceConfiguration.UseDataServiceCollection; t4CodeGenerator.TargetLanguage = ODataT4CodeGenerator.LanguageOption.CSharp; diff --git a/ODataConnectedService/src/ODataConnectedServiceHandler.cs b/ODataConnectedService/src/ODataConnectedServiceHandler.cs index 5ff7e60..adb562c 100644 --- a/ODataConnectedService/src/ODataConnectedServiceHandler.cs +++ b/ODataConnectedService/src/ODataConnectedServiceHandler.cs @@ -7,6 +7,7 @@ using System.Threading.Tasks; using EnvDTE; using Microsoft.OData.ConnectedService.CodeGeneration; +using Microsoft.OData.ConnectedService.Templates; using Microsoft.OData.ConnectedService.Common; using Microsoft.OData.ConnectedService.Models; using Microsoft.VisualStudio.ConnectedServices; @@ -54,7 +55,7 @@ private static async Task GenerateCode(string metadataUri } else if (edmxVersion == Common.Constants.EdmxVersion4) { - codeGenDescriptor = new V4CodeGenDescriptor(metadataUri, context, project); + codeGenDescriptor = new V4CodeGenDescriptor(metadataUri, context, project, new ODataT4CodeGeneratorFactory()); } else { diff --git a/ODataConnectedService/test/ODataConnectedService.Tests/CodeGeneration/V4CodeGenDescriptorTest.cs b/ODataConnectedService/test/ODataConnectedService.Tests/CodeGeneration/V4CodeGenDescriptorTest.cs index bd2d414..2724e27 100644 --- a/ODataConnectedService/test/ODataConnectedService.Tests/CodeGeneration/V4CodeGenDescriptorTest.cs +++ b/ODataConnectedService/test/ODataConnectedService.Tests/CodeGeneration/V4CodeGenDescriptorTest.cs @@ -26,11 +26,11 @@ public void CleanUp() { Directory.Delete(TestProjectRootPath, true); } - catch (System.IO.DirectoryNotFoundException) { } + catch (DirectoryNotFoundException) { } } [TestMethod] - public void TestAddGeneratedCSharpCodePassesServiceConfigOptionsToCodeGenerator() + public void TestAddGeneratedClientCode_PassesServiceConfigOptionsToCodeGenerator() { var handlerHelper = new TestConnectedServiceHandlerHelper(); var codeGenFactory = new TestODataT4CodeGeneratorFactory(); @@ -41,10 +41,11 @@ public void TestAddGeneratedCSharpCodePassesServiceConfigOptionsToCodeGenerator( IgnoreUnexpectedElementsAndAttributes = true, EnableNamingAlias = true, NamespacePrefix = "Prefix", - MakeTypesInternal = true + MakeTypesInternal = true, + IncludeT4File = false }; - var codeGenDescriptor = SetupCodeGenDescriptor(serviceConfig, "TestService", handlerHelper); - codeGenDescriptor.AddGeneratedCSharpCode(codeGenFactory).Wait(); + var codeGenDescriptor = SetupCodeGenDescriptor(serviceConfig, "TestService", codeGenFactory, handlerHelper); + codeGenDescriptor.AddGeneratedClientCode().Wait(); var generator = codeGenFactory.LastCreatedInstance; Assert.AreEqual(true, generator.UseDataServiceCollection); Assert.AreEqual(true, generator.EnableNamingAlias); @@ -59,10 +60,11 @@ public void TestAddGeneratedCSharpCodePassesServiceConfigOptionsToCodeGenerator( IgnoreUnexpectedElementsAndAttributes = false, EnableNamingAlias = false, NamespacePrefix = null, - MakeTypesInternal = false + MakeTypesInternal = false, + IncludeT4File = false }; - codeGenDescriptor = SetupCodeGenDescriptor(serviceConfig, "TestService", handlerHelper); - codeGenDescriptor.AddGeneratedCSharpCode(codeGenFactory).Wait(); + codeGenDescriptor = SetupCodeGenDescriptor(serviceConfig, "TestService", codeGenFactory, handlerHelper); + codeGenDescriptor.AddGeneratedClientCode().Wait(); generator = codeGenFactory.LastCreatedInstance; Assert.AreEqual(false, generator.UseDataServiceCollection); Assert.AreEqual(false, generator.EnableNamingAlias); @@ -73,7 +75,7 @@ public void TestAddGeneratedCSharpCodePassesServiceConfigOptionsToCodeGenerator( } [TestMethod] - public void TestAddGeneratedCSharpCodeGeneratesAndSavesCodeFile() + public void TestAddGeneratedClientCode_GeneratesAndSavesCodeFile() { var serviceName = "MyService"; ServiceConfiguration serviceConfig = new ServiceConfigurationV4() @@ -81,20 +83,23 @@ public void TestAddGeneratedCSharpCodeGeneratesAndSavesCodeFile() MakeTypesInternal = true, UseDataServiceCollection = false, ServiceName = serviceName, - GeneratedFileNamePrefix = "MyFile" + GeneratedFileNamePrefix = "MyFile", + IncludeT4File = false }; var handlerHelper = new TestConnectedServiceHandlerHelper(); - var codeGenDescriptor = SetupCodeGenDescriptor(serviceConfig, serviceName, handlerHelper); - codeGenDescriptor.AddGeneratedCSharpCode(new TestODataT4CodeGeneratorFactory()).Wait(); + var codeGenDescriptor = SetupCodeGenDescriptor(serviceConfig, serviceName, + new TestODataT4CodeGeneratorFactory(), handlerHelper); + codeGenDescriptor.AddGeneratedClientCode().Wait(); using (var reader = new StreamReader(handlerHelper.AddedFileInputFileName)) { var generatedCode = reader.ReadToEnd(); Assert.AreEqual("Generated code", generatedCode); - Assert.AreEqual(Path.Combine(TestProjectRootPath, ServicesRootFolder, serviceName, "MyFile.cs"), handlerHelper.AddedFileTargetFilePath); + Assert.AreEqual(Path.Combine(TestProjectRootPath, ServicesRootFolder, serviceName, "MyFile.cs"), + handlerHelper.AddedFileTargetFilePath); } } - static V4CodeGenDescriptor SetupCodeGenDescriptor(ServiceConfiguration serviceConfig, string serviceName, TestConnectedServiceHandlerHelper handlerHelper) + static V4CodeGenDescriptor SetupCodeGenDescriptor(ServiceConfiguration serviceConfig, string serviceName, IODataT4CodeGeneratorFactory codeGenFactory, TestConnectedServiceHandlerHelper handlerHelper) { var referenceFolderPath = Path.Combine(TestProjectRootPath, ServicesRootFolder, serviceName); Directory.CreateDirectory(referenceFolderPath); @@ -107,7 +112,7 @@ static V4CodeGenDescriptor SetupCodeGenDescriptor(ServiceConfiguration serviceCo handlerHelper.ServicesRootFolder = ServicesRootFolder; ConnectedServiceHandlerContext context = new TestConnectedServiceHandlerContext(serviceInstance, handlerHelper); - return new TestV4CodeGenDescriptor(MetadataUri, context, project); + return new TestV4CodeGenDescriptor(MetadataUri, context, project, codeGenFactory); } static Project CreateTestProject(string projectPath) @@ -126,8 +131,8 @@ static Project CreateTestProject(string projectPath) class TestV4CodeGenDescriptor: V4CodeGenDescriptor { - public TestV4CodeGenDescriptor(string metadataUri, ConnectedServiceHandlerContext context, Project project) - : base(metadataUri, context, project) + public TestV4CodeGenDescriptor(string metadataUri, ConnectedServiceHandlerContext context, Project project, IODataT4CodeGeneratorFactory codeGenFactory) + : base(metadataUri, context, project, codeGenFactory) { } protected override void Init() { } @@ -178,6 +183,11 @@ public TestConnectedServiceHandlerContext(ConnectedServiceInstance serviceInstan { ServiceInstance = serviceInstance; HandlerHelper = handlerHelper; + + var mockLogger = new Mock(); + mockLogger.Setup(l => l.WriteMessageAsync(It.IsAny(), It.IsAny())) + .Returns(Task.CompletedTask); + Logger = mockLogger.Object; } public override IDictionary Args => throw new System.NotImplementedException(); From dce321de31338599c0dff706fbbafad14d30407c Mon Sep 17 00:00:00 2001 From: Clement Habinshuti Date: Wed, 22 Jan 2020 19:17:13 +0300 Subject: [PATCH 11/24] Add tests for ODataConnectedServiceHander --- .../CodeGenDescriptorFactory.cs | 36 ++++++ .../ICodeGenDescriptorFactory.cs | 11 ++ .../src/ODataConnectedService.csproj | 2 + .../src/ODataConnectedServiceHandler.cs | 36 +++--- .../CodeGeneration/V4CodeGenDescriptorTest.cs | 9 +- .../ODataConnectedService.Tests.csproj | 1 + .../ODataConnectedServiceHandlerTest.cs | 112 ++++++++++++++++++ 7 files changed, 185 insertions(+), 22 deletions(-) create mode 100644 ODataConnectedService/src/CodeGeneration/CodeGenDescriptorFactory.cs create mode 100644 ODataConnectedService/src/CodeGeneration/ICodeGenDescriptorFactory.cs create mode 100644 ODataConnectedService/test/ODataConnectedService.Tests/ODataConnectedServiceHandlerTest.cs diff --git a/ODataConnectedService/src/CodeGeneration/CodeGenDescriptorFactory.cs b/ODataConnectedService/src/CodeGeneration/CodeGenDescriptorFactory.cs new file mode 100644 index 0000000..be38c41 --- /dev/null +++ b/ODataConnectedService/src/CodeGeneration/CodeGenDescriptorFactory.cs @@ -0,0 +1,36 @@ +using System; +using EnvDTE; +using Microsoft.VisualStudio.ConnectedServices; +using Microsoft.OData.ConnectedService.Templates; +using System.Globalization; + +namespace Microsoft.OData.ConnectedService.CodeGeneration +{ + class CodeGenDescriptorFactory: ICodeGenDescriptorFactory + { + public BaseCodeGenDescriptor Create(Version edmxVersion, string metadataUri, ConnectedServiceHandlerContext context, Project project) + { + if (edmxVersion == Common.Constants.EdmxVersion1 + || edmxVersion == Common.Constants.EdmxVersion2 + || edmxVersion == Common.Constants.EdmxVersion3) + { + return CreateV3CodeGenDescriptor(metadataUri, context, project); + } + else if (edmxVersion == Common.Constants.EdmxVersion4) + { + return CreateV4CodeGenDescriptor(metadataUri, context, project); + } + throw new Exception(string.Format(CultureInfo.InvariantCulture, "Not supported Edmx Version {0}", edmxVersion.ToString())); + } + + protected virtual BaseCodeGenDescriptor CreateV3CodeGenDescriptor(string metadataUri, ConnectedServiceHandlerContext context, Project project) + { + return new V3CodeGenDescriptor(metadataUri, context, project); + } + + protected virtual BaseCodeGenDescriptor CreateV4CodeGenDescriptor(string metadataUri, ConnectedServiceHandlerContext context, Project project) + { + return new V4CodeGenDescriptor(metadataUri, context, project, new ODataT4CodeGeneratorFactory()); + } + } +} diff --git a/ODataConnectedService/src/CodeGeneration/ICodeGenDescriptorFactory.cs b/ODataConnectedService/src/CodeGeneration/ICodeGenDescriptorFactory.cs new file mode 100644 index 0000000..9bafaa5 --- /dev/null +++ b/ODataConnectedService/src/CodeGeneration/ICodeGenDescriptorFactory.cs @@ -0,0 +1,11 @@ +using System; +using EnvDTE; +using Microsoft.VisualStudio.ConnectedServices; + +namespace Microsoft.OData.ConnectedService.CodeGeneration +{ + interface ICodeGenDescriptorFactory + { + BaseCodeGenDescriptor Create(Version edmxVersion, string metadataUri, ConnectedServiceHandlerContext context, Project project); + } +} diff --git a/ODataConnectedService/src/ODataConnectedService.csproj b/ODataConnectedService/src/ODataConnectedService.csproj index 1e2fe88..2b60915 100644 --- a/ODataConnectedService/src/ODataConnectedService.csproj +++ b/ODataConnectedService/src/ODataConnectedService.csproj @@ -162,6 +162,8 @@ + + diff --git a/ODataConnectedService/src/ODataConnectedServiceHandler.cs b/ODataConnectedService/src/ODataConnectedServiceHandler.cs index adb562c..cc6ec9c 100644 --- a/ODataConnectedService/src/ODataConnectedServiceHandler.cs +++ b/ODataConnectedService/src/ODataConnectedServiceHandler.cs @@ -17,12 +17,24 @@ namespace Microsoft.OData.ConnectedService [ConnectedServiceHandlerExport(Common.Constants.ProviderId, AppliesTo = "CSharp")] internal class ODataConnectedServiceHandler : ConnectedServiceHandler { + private ICodeGenDescriptorFactory codeGenDescriptorFactory; + public ODataConnectedServiceHandler(): this(new CodeGenDescriptorFactory()) + { + } + + public ODataConnectedServiceHandler(ICodeGenDescriptorFactory codeGenDescriptorFactory) + : base() + { + this.codeGenDescriptorFactory = codeGenDescriptorFactory; + } + + public override async Task AddServiceInstanceAsync(ConnectedServiceHandlerContext context, CancellationToken ct) { Project project = ProjectHelper.GetProjectFromHierarchy(context.ProjectHierarchy); ODataConnectedServiceInstance codeGenInstance = (ODataConnectedServiceInstance)context.ServiceInstance; - var codeGenDescriptor = await GenerateCode(codeGenInstance.MetadataTempFilePath, codeGenInstance.ServiceConfig.EdmxVersion, context, project); + var codeGenDescriptor = await GenerateCode(codeGenDescriptorFactory, codeGenInstance.MetadataTempFilePath, codeGenInstance.ServiceConfig.EdmxVersion, context, project); context.SetExtendedDesignerData(codeGenInstance.ServiceConfig); @@ -38,30 +50,14 @@ public override async Task UpdateServiceInstanceAsy Project project = ProjectHelper.GetProjectFromHierarchy(context.ProjectHierarchy); ODataConnectedServiceInstance codeGenInstance = (ODataConnectedServiceInstance)context.ServiceInstance; - var codeGenDescriptor = await GenerateCode(codeGenInstance.ServiceConfig.Endpoint, codeGenInstance.ServiceConfig.EdmxVersion, context, project); + var codeGenDescriptor = await GenerateCode(codeGenDescriptorFactory, codeGenInstance.ServiceConfig.Endpoint, codeGenInstance.ServiceConfig.EdmxVersion, context, project); context.SetExtendedDesignerData(codeGenInstance.ServiceConfig); return new UpdateServiceInstanceResult(); } - private static async Task GenerateCode(string metadataUri, Version edmxVersion, ConnectedServiceHandlerContext context, Project project) + private static async Task GenerateCode(ICodeGenDescriptorFactory codeGenDescriptorFactory, string metadataUri, Version edmxVersion, ConnectedServiceHandlerContext context, Project project) { - BaseCodeGenDescriptor codeGenDescriptor; - - if (edmxVersion == Common.Constants.EdmxVersion1 - || edmxVersion == Common.Constants.EdmxVersion2 - || edmxVersion == Common.Constants.EdmxVersion3) - { - codeGenDescriptor = new V3CodeGenDescriptor(metadataUri, context, project); - } - else if (edmxVersion == Common.Constants.EdmxVersion4) - { - codeGenDescriptor = new V4CodeGenDescriptor(metadataUri, context, project, new ODataT4CodeGeneratorFactory()); - } - else - { - throw new Exception(string.Format(CultureInfo.InvariantCulture, "Not supported Edmx Version {0}", edmxVersion.ToString())); - } - + BaseCodeGenDescriptor codeGenDescriptor = codeGenDescriptorFactory.Create(edmxVersion, metadataUri, context, project); await codeGenDescriptor.AddNugetPackages(); await codeGenDescriptor.AddGeneratedClientCode(); return codeGenDescriptor; diff --git a/ODataConnectedService/test/ODataConnectedService.Tests/CodeGeneration/V4CodeGenDescriptorTest.cs b/ODataConnectedService/test/ODataConnectedService.Tests/CodeGeneration/V4CodeGenDescriptorTest.cs index 2724e27..a308991 100644 --- a/ODataConnectedService/test/ODataConnectedService.Tests/CodeGeneration/V4CodeGenDescriptorTest.cs +++ b/ODataConnectedService/test/ODataConnectedService.Tests/CodeGeneration/V4CodeGenDescriptorTest.cs @@ -9,6 +9,7 @@ using Microsoft.OData.ConnectedService.CodeGeneration; using Microsoft.OData.ConnectedService.Models; using Microsoft.OData.ConnectedService.Templates; +using Microsoft.VisualStudio.Shell.Interop; namespace ODataConnectedService.Tests.CodeGeneration { @@ -179,16 +180,20 @@ public override Task AddFileAsync(string fileName, string targetPath, Ad class TestConnectedServiceHandlerContext: ConnectedServiceHandlerContext { - public TestConnectedServiceHandlerContext(ConnectedServiceInstance serviceInstance, ConnectedServiceHandlerHelper handlerHelper ): base() + public TestConnectedServiceHandlerContext(ConnectedServiceInstance serviceInstance = null, + ConnectedServiceHandlerHelper handlerHelper = null, IVsHierarchy projectHierarchy = null ): base() { ServiceInstance = serviceInstance; HandlerHelper = handlerHelper; + ProjectHierarchy = projectHierarchy; var mockLogger = new Mock(); mockLogger.Setup(l => l.WriteMessageAsync(It.IsAny(), It.IsAny())) .Returns(Task.CompletedTask); Logger = mockLogger.Object; } + + public object SavedExtendedDesignData { get; private set; } public override IDictionary Args => throw new System.NotImplementedException(); public override EditableXmlConfigHelper CreateEditableXmlConfigHelper() @@ -208,7 +213,7 @@ public override TData GetExtendedDesignerData() public override void SetExtendedDesignerData(TData data) { - throw new System.NotImplementedException(); + SavedExtendedDesignData = data; } } } diff --git a/ODataConnectedService/test/ODataConnectedService.Tests/ODataConnectedService.Tests.csproj b/ODataConnectedService/test/ODataConnectedService.Tests/ODataConnectedService.Tests.csproj index c2db9f2..41da31b 100644 --- a/ODataConnectedService/test/ODataConnectedService.Tests/ODataConnectedService.Tests.csproj +++ b/ODataConnectedService/test/ODataConnectedService.Tests/ODataConnectedService.Tests.csproj @@ -49,6 +49,7 @@ + diff --git a/ODataConnectedService/test/ODataConnectedService.Tests/ODataConnectedServiceHandlerTest.cs b/ODataConnectedService/test/ODataConnectedService.Tests/ODataConnectedServiceHandlerTest.cs new file mode 100644 index 0000000..d6d34d9 --- /dev/null +++ b/ODataConnectedService/test/ODataConnectedService.Tests/ODataConnectedServiceHandlerTest.cs @@ -0,0 +1,112 @@ +using System; +using Microsoft.VisualStudio.ConnectedServices; +using Microsoft.VisualStudio.Shell.Interop; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Microsoft.OData.ConnectedService; +using Microsoft.OData.ConnectedService.CodeGeneration; +//using Microsoft.OData.ConnectedService.Common; +using Microsoft.OData.ConnectedService.Models; +using EnvDTE; +using System.Threading.Tasks; +using ODataConnectedService.Tests.CodeGeneration; +using System.Threading; +using Moq; + +namespace ODataConnectedService.Tests +{ + [TestClass] + public class ODataConnectedServiceHandlerTest + { + [DataTestMethod] + [DataRow("AddServiceInstanceAsync", 4, "V4")] + [DataRow("AddServiceInstanceAsync", 3, "V3")] + [DataRow("AddServiceInstanceAsync", 2, "V3")] + [DataRow("AddServiceInstanceAsync", 1, "V3")] + [DataRow("UpdateServiceInstanceAsync", 4, "V4")] + [DataRow("UpdateServiceInstanceAsync", 3, "V3")] + [DataRow("UpdateServiceInstanceAsync", 2, "V3")] + [DataRow("UpdateServiceInstanceAsync", 1, "V3")] + public void TestUpdateServiceInstance_GeneratesCodeAndSavesConfig(string method, int edmxVersion, string generatorVersion) + { + var descriptorFactory = new TestCodeGenDescriptorFactory(); + var serviceHandler = new ODataConnectedServiceHandler(descriptorFactory); + var serviceConfig = new ServiceConfiguration() + { + EdmxVersion = new Version(edmxVersion, 0, 0, 0), + ServiceName = "TestService", + UseDataServiceCollection = false, + MakeTypesInternal = true + }; + var tokenSource = new CancellationTokenSource(); + var context = SetupContext(serviceConfig); + (typeof(ODataConnectedServiceHandler).GetMethod(method).Invoke( + serviceHandler, new object[] { context, tokenSource.Token }) as Task).Wait(); + var descriptor = descriptorFactory.CreatedInstance as TestCodeGenDescriptor; + Assert.IsTrue(descriptor.AddedClientCode); + Assert.IsTrue(descriptor.AddedNugetPackages); + Assert.AreEqual(generatorVersion, descriptor.Version); + Assert.AreEqual(serviceConfig, context.SavedExtendedDesignData); + } + + static TestConnectedServiceHandlerContext SetupContext(ServiceConfiguration serviceConfig) + { + var serviceInstance = new ODataConnectedServiceInstance() + { + Name = "TestService", + MetadataTempFilePath = "http://service/$metadata", + ServiceConfig = serviceConfig + }; + var projectHierarchyMock = new Mock(); + object project; + projectHierarchyMock.Setup(h => h.GetProperty(It.IsAny(), It.IsAny(), out project)); + var context = new TestConnectedServiceHandlerContext( + serviceInstance: serviceInstance, projectHierarchy: projectHierarchyMock.Object); + return context; + } + } + + class TestCodeGenDescriptorFactory: CodeGenDescriptorFactory + { + public BaseCodeGenDescriptor CreatedInstance { get; private set; } + protected override BaseCodeGenDescriptor CreateV3CodeGenDescriptor(string metadataUri, ConnectedServiceHandlerContext context, Project project) + { + var descriptor = new TestCodeGenDescriptor(metadataUri, context, project); + descriptor.Version = "V3"; + CreatedInstance = CreatedInstance ?? descriptor; + return descriptor; + } + + protected override BaseCodeGenDescriptor CreateV4CodeGenDescriptor(string metadataUri, ConnectedServiceHandlerContext context, Project project) + { + var descriptor = new TestCodeGenDescriptor(metadataUri, context, project); + descriptor.Version = "V4"; + CreatedInstance = CreatedInstance ?? descriptor; + return descriptor; + } + } + + class TestCodeGenDescriptor : BaseCodeGenDescriptor + { + public TestCodeGenDescriptor(string metadataUri, ConnectedServiceHandlerContext context, Project project) + : base(metadataUri, context, project) + { + ClientDocUri = "https://odata.org"; + } + public string Version { get; set; } + public bool AddedClientCode { get; private set; } + public bool AddedNugetPackages { get; private set; } + + protected override void Init() { } + public override Task AddGeneratedClientCode() + { + AddedClientCode = true; + return Task.CompletedTask; + } + + public override Task AddNugetPackages() + { + AddedNugetPackages = true; + return Task.CompletedTask; + } + } +} From 444ff8dedf6a238d9b090326b06a83a27a431883 Mon Sep 17 00:00:00 2001 From: Clement Habinshuti Date: Thu, 23 Jan 2020 08:59:38 +0300 Subject: [PATCH 12/24] Refactor ODataConnectedService tests --- .../src/ODataConnectedServiceHandler.cs | 29 +++-- .../CodeGeneration/V4CodeGenDescriptorTest.cs | 110 +++--------------- .../ODataConnectedService.Tests.csproj | 2 + .../ODataConnectedServiceHandlerTest.cs | 9 +- .../TestConnectedServiceHandlerContext.cs | 42 +++++++ .../TestConnectedServiceHandlerHelper.cs | 27 +++++ 6 files changed, 107 insertions(+), 112 deletions(-) create mode 100644 ODataConnectedService/test/ODataConnectedService.Tests/TestHelpers/TestConnectedServiceHandlerContext.cs create mode 100644 ODataConnectedService/test/ODataConnectedService.Tests/TestHelpers/TestConnectedServiceHandlerHelper.cs diff --git a/ODataConnectedService/src/ODataConnectedServiceHandler.cs b/ODataConnectedService/src/ODataConnectedServiceHandler.cs index cc6ec9c..96dec90 100644 --- a/ODataConnectedService/src/ODataConnectedServiceHandler.cs +++ b/ODataConnectedService/src/ODataConnectedServiceHandler.cs @@ -18,9 +18,7 @@ namespace Microsoft.OData.ConnectedService internal class ODataConnectedServiceHandler : ConnectedServiceHandler { private ICodeGenDescriptorFactory codeGenDescriptorFactory; - public ODataConnectedServiceHandler(): this(new CodeGenDescriptorFactory()) - { - } + public ODataConnectedServiceHandler(): this(new CodeGenDescriptorFactory()) {} public ODataConnectedServiceHandler(ICodeGenDescriptorFactory codeGenDescriptorFactory) : base() @@ -31,31 +29,30 @@ public ODataConnectedServiceHandler(ICodeGenDescriptorFactory codeGenDescriptorF public override async Task AddServiceInstanceAsync(ConnectedServiceHandlerContext context, CancellationToken ct) { - Project project = ProjectHelper.GetProjectFromHierarchy(context.ProjectHierarchy); - ODataConnectedServiceInstance codeGenInstance = (ODataConnectedServiceInstance)context.ServiceInstance; - - var codeGenDescriptor = await GenerateCode(codeGenDescriptorFactory, codeGenInstance.MetadataTempFilePath, codeGenInstance.ServiceConfig.EdmxVersion, context, project); - - context.SetExtendedDesignerData(codeGenInstance.ServiceConfig); - + var codeGenDescriptor = await SaveServiceInstanceAsync(context); var result = new AddServiceInstanceResult( context.ServiceInstance.Name, new Uri(codeGenDescriptor.ClientDocUri)); - return result; } public override async Task UpdateServiceInstanceAsync(ConnectedServiceHandlerContext context, CancellationToken ct) + { + await SaveServiceInstanceAsync(context); + return new UpdateServiceInstanceResult(); + } + + private async Task SaveServiceInstanceAsync(ConnectedServiceHandlerContext context) { Project project = ProjectHelper.GetProjectFromHierarchy(context.ProjectHierarchy); - ODataConnectedServiceInstance codeGenInstance = (ODataConnectedServiceInstance)context.ServiceInstance; + ODataConnectedServiceInstance serviceInstance = (ODataConnectedServiceInstance)context.ServiceInstance; - var codeGenDescriptor = await GenerateCode(codeGenDescriptorFactory, codeGenInstance.ServiceConfig.Endpoint, codeGenInstance.ServiceConfig.EdmxVersion, context, project); - context.SetExtendedDesignerData(codeGenInstance.ServiceConfig); - return new UpdateServiceInstanceResult(); + var codeGenDescriptor = await GenerateCode(serviceInstance.ServiceConfig.Endpoint, serviceInstance.ServiceConfig.EdmxVersion, context, project); + context.SetExtendedDesignerData(serviceInstance.ServiceConfig); + return codeGenDescriptor; } - private static async Task GenerateCode(ICodeGenDescriptorFactory codeGenDescriptorFactory, string metadataUri, Version edmxVersion, ConnectedServiceHandlerContext context, Project project) + private async Task GenerateCode(string metadataUri, Version edmxVersion, ConnectedServiceHandlerContext context, Project project) { BaseCodeGenDescriptor codeGenDescriptor = codeGenDescriptorFactory.Create(edmxVersion, metadataUri, context, project); await codeGenDescriptor.AddNugetPackages(); diff --git a/ODataConnectedService/test/ODataConnectedService.Tests/CodeGeneration/V4CodeGenDescriptorTest.cs b/ODataConnectedService/test/ODataConnectedService.Tests/CodeGeneration/V4CodeGenDescriptorTest.cs index a308991..f315cf8 100644 --- a/ODataConnectedService/test/ODataConnectedService.Tests/CodeGeneration/V4CodeGenDescriptorTest.cs +++ b/ODataConnectedService/test/ODataConnectedService.Tests/CodeGeneration/V4CodeGenDescriptorTest.cs @@ -9,7 +9,7 @@ using Microsoft.OData.ConnectedService.CodeGeneration; using Microsoft.OData.ConnectedService.Models; using Microsoft.OData.ConnectedService.Templates; -using Microsoft.VisualStudio.Shell.Interop; +using ODataConnectedService.Tests.TestHelpers; namespace ODataConnectedService.Tests.CodeGeneration { @@ -30,47 +30,34 @@ public void CleanUp() catch (DirectoryNotFoundException) { } } - [TestMethod] - public void TestAddGeneratedClientCode_PassesServiceConfigOptionsToCodeGenerator() + [DataTestMethod] + [DataRow(true, true, true, "Prefix", true)] + [DataRow(false, false, false, null, false)] + public void TestAddGeneratedClientCode_PassesServiceConfigOptionsToCodeGenerator( + bool useDSC, bool ignoreUnexpected, bool enableNamingAlias, + string namespacePrefix, bool makeTypesInternal) { var handlerHelper = new TestConnectedServiceHandlerHelper(); var codeGenFactory = new TestODataT4CodeGeneratorFactory(); var serviceConfig = new ServiceConfigurationV4() { - UseDataServiceCollection = true, - IgnoreUnexpectedElementsAndAttributes = true, - EnableNamingAlias = true, - NamespacePrefix = "Prefix", - MakeTypesInternal = true, + UseDataServiceCollection = useDSC, + IgnoreUnexpectedElementsAndAttributes = ignoreUnexpected, + EnableNamingAlias = enableNamingAlias, + NamespacePrefix = namespacePrefix, + MakeTypesInternal = makeTypesInternal, IncludeT4File = false }; var codeGenDescriptor = SetupCodeGenDescriptor(serviceConfig, "TestService", codeGenFactory, handlerHelper); codeGenDescriptor.AddGeneratedClientCode().Wait(); - var generator = codeGenFactory.LastCreatedInstance; - Assert.AreEqual(true, generator.UseDataServiceCollection); - Assert.AreEqual(true, generator.EnableNamingAlias); - Assert.AreEqual(true, generator.MakeTypesInternal); - Assert.AreEqual("Prefix", generator.NamespacePrefix); - Assert.AreEqual(MetadataUri, generator.MetadataDocumentUri); - Assert.AreEqual(ODataT4CodeGenerator.LanguageOption.CSharp, generator.TargetLanguage); - serviceConfig = new ServiceConfigurationV4() - { - UseDataServiceCollection = false, - IgnoreUnexpectedElementsAndAttributes = false, - EnableNamingAlias = false, - NamespacePrefix = null, - MakeTypesInternal = false, - IncludeT4File = false - }; - codeGenDescriptor = SetupCodeGenDescriptor(serviceConfig, "TestService", codeGenFactory, handlerHelper); - codeGenDescriptor.AddGeneratedClientCode().Wait(); - generator = codeGenFactory.LastCreatedInstance; - Assert.AreEqual(false, generator.UseDataServiceCollection); - Assert.AreEqual(false, generator.EnableNamingAlias); - Assert.AreEqual(false, generator.MakeTypesInternal); - Assert.AreEqual(null, generator.NamespacePrefix); + var generator = codeGenFactory.LastCreatedInstance; + Assert.AreEqual(useDSC, generator.UseDataServiceCollection); + Assert.AreEqual(enableNamingAlias, generator.EnableNamingAlias); + Assert.AreEqual(ignoreUnexpected, generator.IgnoreUnexpectedElementsAndAttributes); + Assert.AreEqual(makeTypesInternal, generator.MakeTypesInternal); + Assert.AreEqual(namespacePrefix, generator.NamespacePrefix); Assert.AreEqual(MetadataUri, generator.MetadataDocumentUri); Assert.AreEqual(ODataT4CodeGenerator.LanguageOption.CSharp, generator.TargetLanguage); } @@ -147,7 +134,7 @@ public override string TransformText() } } - class TestODataT4CodeGeneratorFactory: IODataT4CodeGeneratorFactory + class TestODataT4CodeGeneratorFactory : IODataT4CodeGeneratorFactory { public ODataT4CodeGenerator LastCreatedInstance { get; private set; } public ODataT4CodeGenerator Create() @@ -157,63 +144,4 @@ public ODataT4CodeGenerator Create() return generator; } } - - class TestConnectedServiceHandlerHelper: ConnectedServiceHandlerHelper - { - // used to access the temp file that the generated code was written to - public string AddedFileInputFileName { get; private set; } - // used to find out which file the final output would be written to - public string AddedFileTargetFilePath { get; private set; } - public string ServicesRootFolder { get; set; } - public override IDictionary TokenReplacementValues { get; } - public override void AddAssemblyReference(string assemblyPath) { } - public override string GetServiceArtifactsRootFolder() => ServicesRootFolder; - public override string PerformTokenReplacement(string input, IDictionary additionalReplacementValues = null) => ""; - - public override Task AddFileAsync(string fileName, string targetPath, AddFileOptions addFileOptions = null) - { - AddedFileInputFileName = fileName; - AddedFileTargetFilePath = targetPath; - return Task.FromResult(""); - } - } - - class TestConnectedServiceHandlerContext: ConnectedServiceHandlerContext - { - public TestConnectedServiceHandlerContext(ConnectedServiceInstance serviceInstance = null, - ConnectedServiceHandlerHelper handlerHelper = null, IVsHierarchy projectHierarchy = null ): base() - { - ServiceInstance = serviceInstance; - HandlerHelper = handlerHelper; - ProjectHierarchy = projectHierarchy; - - var mockLogger = new Mock(); - mockLogger.Setup(l => l.WriteMessageAsync(It.IsAny(), It.IsAny())) - .Returns(Task.CompletedTask); - Logger = mockLogger.Object; - } - - public object SavedExtendedDesignData { get; private set; } - public override IDictionary Args => throw new System.NotImplementedException(); - - public override EditableXmlConfigHelper CreateEditableXmlConfigHelper() - { - return null; - } - - public override XmlConfigHelper CreateReadOnlyXmlConfigHelper() - { - throw new System.NotImplementedException(); - } - - public override TData GetExtendedDesignerData() - { - throw new System.NotImplementedException(); - } - - public override void SetExtendedDesignerData(TData data) - { - SavedExtendedDesignData = data; - } - } } diff --git a/ODataConnectedService/test/ODataConnectedService.Tests/ODataConnectedService.Tests.csproj b/ODataConnectedService/test/ODataConnectedService.Tests/ODataConnectedService.Tests.csproj index 41da31b..b1025b9 100644 --- a/ODataConnectedService/test/ODataConnectedService.Tests/ODataConnectedService.Tests.csproj +++ b/ODataConnectedService/test/ODataConnectedService.Tests/ODataConnectedService.Tests.csproj @@ -50,6 +50,8 @@ + + diff --git a/ODataConnectedService/test/ODataConnectedService.Tests/ODataConnectedServiceHandlerTest.cs b/ODataConnectedService/test/ODataConnectedService.Tests/ODataConnectedServiceHandlerTest.cs index d6d34d9..3a77290 100644 --- a/ODataConnectedService/test/ODataConnectedService.Tests/ODataConnectedServiceHandlerTest.cs +++ b/ODataConnectedService/test/ODataConnectedService.Tests/ODataConnectedServiceHandlerTest.cs @@ -1,16 +1,15 @@ using System; +using System.Threading; +using System.Threading.Tasks; +using EnvDTE; using Microsoft.VisualStudio.ConnectedServices; using Microsoft.VisualStudio.Shell.Interop; using Microsoft.VisualStudio.TestTools.UnitTesting; using Microsoft.OData.ConnectedService; using Microsoft.OData.ConnectedService.CodeGeneration; -//using Microsoft.OData.ConnectedService.Common; using Microsoft.OData.ConnectedService.Models; -using EnvDTE; -using System.Threading.Tasks; -using ODataConnectedService.Tests.CodeGeneration; -using System.Threading; using Moq; +using ODataConnectedService.Tests.TestHelpers; namespace ODataConnectedService.Tests { diff --git a/ODataConnectedService/test/ODataConnectedService.Tests/TestHelpers/TestConnectedServiceHandlerContext.cs b/ODataConnectedService/test/ODataConnectedService.Tests/TestHelpers/TestConnectedServiceHandlerContext.cs new file mode 100644 index 0000000..cedb1ba --- /dev/null +++ b/ODataConnectedService/test/ODataConnectedService.Tests/TestHelpers/TestConnectedServiceHandlerContext.cs @@ -0,0 +1,42 @@ +using System.Collections.Generic; +using System.Threading.Tasks; +using Microsoft.VisualStudio.ConnectedServices; +using Microsoft.VisualStudio.Shell.Interop; +using Moq; + +namespace ODataConnectedService.Tests.TestHelpers +{ + class TestConnectedServiceHandlerContext : ConnectedServiceHandlerContext + { + public TestConnectedServiceHandlerContext(ConnectedServiceInstance serviceInstance = null, + ConnectedServiceHandlerHelper handlerHelper = null, IVsHierarchy projectHierarchy = null) : base() + { + ServiceInstance = serviceInstance; + HandlerHelper = handlerHelper; + ProjectHierarchy = projectHierarchy; + + var mockLogger = new Mock(); + mockLogger.Setup(l => l.WriteMessageAsync(It.IsAny(), It.IsAny())) + .Returns(Task.CompletedTask); + Logger = mockLogger.Object; + } + + public object SavedExtendedDesignData { get; private set; } + + public override void SetExtendedDesignerData(TData data) + { + SavedExtendedDesignData = data; + } + public override IDictionary Args => + throw new System.NotImplementedException(); + + public override EditableXmlConfigHelper CreateEditableXmlConfigHelper() => + throw new System.NotImplementedException(); + + public override XmlConfigHelper CreateReadOnlyXmlConfigHelper() => + throw new System.NotImplementedException(); + + public override TData GetExtendedDesignerData() => + throw new System.NotImplementedException(); + } +} diff --git a/ODataConnectedService/test/ODataConnectedService.Tests/TestHelpers/TestConnectedServiceHandlerHelper.cs b/ODataConnectedService/test/ODataConnectedService.Tests/TestHelpers/TestConnectedServiceHandlerHelper.cs new file mode 100644 index 0000000..440f930 --- /dev/null +++ b/ODataConnectedService/test/ODataConnectedService.Tests/TestHelpers/TestConnectedServiceHandlerHelper.cs @@ -0,0 +1,27 @@ +using System.Collections.Generic; +using System.Threading.Tasks; +using Microsoft.VisualStudio.ConnectedServices; + +namespace ODataConnectedService.Tests.TestHelpers +{ + class TestConnectedServiceHandlerHelper : ConnectedServiceHandlerHelper + { + // used to access the temp file that the generated code was written to + public string AddedFileInputFileName { get; private set; } + // used to find out which file the final output would be written to + public string AddedFileTargetFilePath { get; private set; } + public string ServicesRootFolder { get; set; } + public override Task AddFileAsync(string fileName, string targetPath, AddFileOptions addFileOptions = null) + { + AddedFileInputFileName = fileName; + AddedFileTargetFilePath = targetPath; + return Task.FromResult(string.Empty); + } + public override IDictionary TokenReplacementValues { get; } + public override void AddAssemblyReference(string assemblyPath) => + throw new System.NotImplementedException(); + public override string GetServiceArtifactsRootFolder() => ServicesRootFolder; + public override string PerformTokenReplacement(string input, IDictionary additionalReplacementValues = null) => + throw new System.NotImplementedException(); + } +} From 7373a5a8ebc03d6d0476aa0d5af4a2f1806e4ad1 Mon Sep 17 00:00:00 2001 From: Clement Habinshuti Date: Thu, 23 Jan 2020 10:05:24 +0300 Subject: [PATCH 13/24] Rename ODataConnectedService validators arguments --- .../Templates/ODataT4CodeGenerator.ttinclude | 44 +++++++++---------- 1 file changed, 22 insertions(+), 22 deletions(-) diff --git a/ODataConnectedService/src/Templates/ODataT4CodeGenerator.ttinclude b/ODataConnectedService/src/Templates/ODataT4CodeGenerator.ttinclude index a1b8edb..f1bb494 100644 --- a/ODataConnectedService/src/Templates/ODataT4CodeGenerator.ttinclude +++ b/ODataConnectedService/src/Templates/ODataT4CodeGenerator.ttinclude @@ -240,18 +240,18 @@ public enum LanguageOption /// /// Set the UseDataServiceCollection property with the given value. /// -/// The value to set. -public void ValidateAndSetUseDataServiceCollectionFromString(string stringValue) +/// The value to set. +public void ValidateAndSetUseDataServiceCollectionFromString(string inputValue) { bool boolValue; - if (!bool.TryParse(stringValue, out boolValue)) + if (!bool.TryParse(inputValue, out boolValue)) { // ******************************************************************************************************** // To fix this error, if the current text transformation is run by the TextTemplatingFileGenerator // custom tool inside Visual Studio, update the .odata.config file in the project with a valid parameter // value then hit Ctrl-S to save the .tt file to refresh the code generation. // ******************************************************************************************************** - throw new ArgumentException(string.Format(CultureInfo.InvariantCulture, "The value \"{0}\" cannot be assigned to the UseDataServiceCollection parameter because it is not a valid boolean value.", stringValue)); + throw new ArgumentException(string.Format(CultureInfo.InvariantCulture, "The value \"{0}\" cannot be assigned to the UseDataServiceCollection parameter because it is not a valid boolean value.", inputValue)); } this.UseDataServiceCollection = boolValue; @@ -260,18 +260,18 @@ public void ValidateAndSetUseDataServiceCollectionFromString(string stringValue) /// /// Tries to set the TargetLanguage property with the given value. /// -/// The value to set. -public void ValidateAndSetTargetLanguageFromString(string stringValue) +/// The value to set. +public void ValidateAndSetTargetLanguageFromString(string inputValue) { LanguageOption option; - if (!Enum.TryParse(stringValue, true, out option)) + if (!Enum.TryParse(inputValue, true, out option)) { // ******************************************************************************************************** // To fix this error, if the current text transformation is run by the TextTemplatingFileGenerator // custom tool inside Visual Studio, update the .odata.config file in the project with a valid parameter // value then hit Ctrl-S to save the .tt file to refresh the code generation. // ******************************************************************************************************** - throw new ArgumentException(string.Format(CultureInfo.InvariantCulture, "The value \"{0}\" cannot be assigned to the TargetLanguage parameter because it is not a valid LanguageOption. The supported LanguageOptions are \"CSharp\" and \"VB\".", stringValue)); + throw new ArgumentException(string.Format(CultureInfo.InvariantCulture, "The value \"{0}\" cannot be assigned to the TargetLanguage parameter because it is not a valid LanguageOption. The supported LanguageOptions are \"CSharp\" and \"VB\".", inputValue)); } this.TargetLanguage = option; @@ -280,18 +280,18 @@ public void ValidateAndSetTargetLanguageFromString(string stringValue) /// /// Set the EnableNamingAlias property with the given value. /// -/// The value to set. -public void ValidateAndSetEnableNamingAliasFromString(string stringValue) +/// The value to set. +public void ValidateAndSetEnableNamingAliasFromString(string inputValue) { bool boolValue; - if (!bool.TryParse(stringValue, out boolValue)) + if (!bool.TryParse(inputValue, out boolValue)) { // ******************************************************************************************************** // To fix this error, if the current text transformation is run by the TextTemplatingFileGenerator // custom tool inside Visual Studio, update the .odata.config file in the project with a valid parameter // value then hit Ctrl-S to save the .tt file to refresh the code generation. // ******************************************************************************************************** - throw new ArgumentException(string.Format(CultureInfo.InvariantCulture, "The value \"{0}\" cannot be assigned to the EnableNamingAlias parameter because it is not a valid boolean value.", stringValue)); + throw new ArgumentException(string.Format(CultureInfo.InvariantCulture, "The value \"{0}\" cannot be assigned to the EnableNamingAlias parameter because it is not a valid boolean value.", inputValue)); } this.EnableNamingAlias = boolValue; @@ -300,18 +300,18 @@ public void ValidateAndSetEnableNamingAliasFromString(string stringValue) /// /// Set the IgnoreUnexpectedElementsAndAttributes property with the given value. /// -/// The value to set. -public void ValidateAndSetIgnoreUnexpectedElementsAndAttributesFromString(string stringValue) +/// The value to set. +public void ValidateAndSetIgnoreUnexpectedElementsAndAttributesFromString(string inputValue) { bool boolValue; - if (!bool.TryParse(stringValue, out boolValue)) + if (!bool.TryParse(inputValue, out boolValue)) { // ******************************************************************************************************** // To fix this error, if the current text transformation is run by the TextTemplatingFileGenerator // custom tool inside Visual Studio, update the .odata.config file in the project with a valid parameter // value then hit Ctrl-S to save the .tt file to refresh the code generation. // ******************************************************************************************************** - throw new ArgumentException(string.Format(CultureInfo.InvariantCulture, "The value \"{0}\" cannot be assigned to the IgnoreUnexpectedElementsAndAttributes parameter because it is not a valid boolean value.", stringValue)); + throw new ArgumentException(string.Format(CultureInfo.InvariantCulture, "The value \"{0}\" cannot be assigned to the IgnoreUnexpectedElementsAndAttributes parameter because it is not a valid boolean value.", inputValue)); } this.IgnoreUnexpectedElementsAndAttributes = boolValue; @@ -320,21 +320,21 @@ public void ValidateAndSetIgnoreUnexpectedElementsAndAttributesFromString(string /// /// Set the MakeTypesInternal property with the given value. /// -/// The value to set. -public void ValidateAndSetMakeTypesInternalFromString(string stringValue) +/// The value to set. +public void ValidateAndSetMakeTypesInternalFromString(string inputValue) { - bool boolValue; - if (!bool.TryParse(stringValue, out boolValue)) + bool parsedValue; + if (!bool.TryParse(inputValue, out parsedValue)) { // ******************************************************************************************************** // To fix this error, if the current text transformation is run by the TextTemplatingFileGenerator // custom tool inside Visual Studio, update the .odata.config file in the project with a valid parameter // value then hit Ctrl-S to save the .tt file to refresh the code generation. // ******************************************************************************************************** - throw new ArgumentException(string.Format(CultureInfo.InvariantCulture, "The value \"{0}\" cannot be assigned to the MakeTypesInternal parameter because it is not a valid boolean value.", stringValue)); + throw new ArgumentException(string.Format(CultureInfo.InvariantCulture, "The value \"{0}\" cannot be assigned to the MakeTypesInternal parameter because it is not a valid boolean value.", inputValue)); } - this.MakeTypesInternal = boolValue; + this.MakeTypesInternal = parsedValue; } /// From 6c3097ca7d16f798449dcae0fce3a6c09c0d7b63 Mon Sep 17 00:00:00 2001 From: Clement Habinshuti Date: Thu, 23 Jan 2020 10:41:07 +0300 Subject: [PATCH 14/24] Hide option to make types internal if generating code for odata v3 or lower --- ODataConnectedService/src/ODataConnectedServiceWizard.cs | 2 +- ODataConnectedService/src/Views/AdvancedSettings.xaml | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/ODataConnectedService/src/ODataConnectedServiceWizard.cs b/ODataConnectedService/src/ODataConnectedServiceWizard.cs index 185ddcd..e5bef14 100644 --- a/ODataConnectedService/src/ODataConnectedServiceWizard.cs +++ b/ODataConnectedService/src/ODataConnectedServiceWizard.cs @@ -77,13 +77,13 @@ public ODataConnectedServiceWizard(ConnectedServiceProviderContext context) advancedSettingsViewModel.UseNamespacePrefix = serviceConfig.UseNameSpacePrefix; advancedSettingsViewModel.NamespacePrefix = serviceConfig.NamespacePrefix; advancedSettingsViewModel.UseDataServiceCollection = serviceConfig.UseDataServiceCollection; - advancedSettingsViewModel.MakeTypesInternal = serviceConfig.MakeTypesInternal; if (serviceConfig.EdmxVersion == Common.Constants.EdmxVersion4) { advancedSettingsViewModel.IgnoreUnexpectedElementsAndAttributes = serviceConfig.IgnoreUnexpectedElementsAndAttributes; advancedSettingsViewModel.EnableNamingAlias = serviceConfig.EnableNamingAlias; advancedSettingsViewModel.IncludeT4File = serviceConfig.IncludeT4File; + advancedSettingsViewModel.MakeTypesInternal = serviceConfig.MakeTypesInternal; advancedSettings.IncludeT4File.IsEnabled = false; } } diff --git a/ODataConnectedService/src/Views/AdvancedSettings.xaml b/ODataConnectedService/src/Views/AdvancedSettings.xaml index e0029cd..627b3ac 100644 --- a/ODataConnectedService/src/Views/AdvancedSettings.xaml +++ b/ODataConnectedService/src/Views/AdvancedSettings.xaml @@ -36,10 +36,6 @@ HorizontalAlignment="Left" TextWrapping="Wrap" VerticalAlignment="Center" Width="250" Margin="20, 0, 0, 5"/> - - Make generated types internal (Enable this if you don't want to expose the generated types outside of your assembly.) - Ignore unknown elements (Whether to ignore unexpected elements and attributes in the metadata document and generate the client code if any.) + + Make generated types internal (Enable this if you don't want to expose the generated types outside of your assembly.) + From b67bdd93cb4928e9aea54fe2e98586146ede779a Mon Sep 17 00:00:00 2001 From: Clement Habinshuti Date: Thu, 23 Jan 2020 10:47:18 +0300 Subject: [PATCH 15/24] Update code generator --- .../src/Templates/ODataT4CodeGenerator.cs | 44 +++++++++---------- 1 file changed, 22 insertions(+), 22 deletions(-) diff --git a/ODataConnectedService/src/Templates/ODataT4CodeGenerator.cs b/ODataConnectedService/src/Templates/ODataT4CodeGenerator.cs index 6348065..6250d8e 100644 --- a/ODataConnectedService/src/Templates/ODataT4CodeGenerator.cs +++ b/ODataConnectedService/src/Templates/ODataT4CodeGenerator.cs @@ -352,18 +352,18 @@ public enum LanguageOption /// /// Set the UseDataServiceCollection property with the given value. /// -/// The value to set. -public void ValidateAndSetUseDataServiceCollectionFromString(string stringValue) +/// The value to set. +public void ValidateAndSetUseDataServiceCollectionFromString(string inputValue) { bool boolValue; - if (!bool.TryParse(stringValue, out boolValue)) + if (!bool.TryParse(inputValue, out boolValue)) { // ******************************************************************************************************** // To fix this error, if the current text transformation is run by the TextTemplatingFileGenerator // custom tool inside Visual Studio, update the .odata.config file in the project with a valid parameter // value then hit Ctrl-S to save the .tt file to refresh the code generation. // ******************************************************************************************************** - throw new ArgumentException(string.Format(CultureInfo.InvariantCulture, "The value \"{0}\" cannot be assigned to the UseDataServiceCollection parameter because it is not a valid boolean value.", stringValue)); + throw new ArgumentException(string.Format(CultureInfo.InvariantCulture, "The value \"{0}\" cannot be assigned to the UseDataServiceCollection parameter because it is not a valid boolean value.", inputValue)); } this.UseDataServiceCollection = boolValue; @@ -372,18 +372,18 @@ public void ValidateAndSetUseDataServiceCollectionFromString(string stringValue) /// /// Tries to set the TargetLanguage property with the given value. /// -/// The value to set. -public void ValidateAndSetTargetLanguageFromString(string stringValue) +/// The value to set. +public void ValidateAndSetTargetLanguageFromString(string inputValue) { LanguageOption option; - if (!Enum.TryParse(stringValue, true, out option)) + if (!Enum.TryParse(inputValue, true, out option)) { // ******************************************************************************************************** // To fix this error, if the current text transformation is run by the TextTemplatingFileGenerator // custom tool inside Visual Studio, update the .odata.config file in the project with a valid parameter // value then hit Ctrl-S to save the .tt file to refresh the code generation. // ******************************************************************************************************** - throw new ArgumentException(string.Format(CultureInfo.InvariantCulture, "The value \"{0}\" cannot be assigned to the TargetLanguage parameter because it is not a valid LanguageOption. The supported LanguageOptions are \"CSharp\" and \"VB\".", stringValue)); + throw new ArgumentException(string.Format(CultureInfo.InvariantCulture, "The value \"{0}\" cannot be assigned to the TargetLanguage parameter because it is not a valid LanguageOption. The supported LanguageOptions are \"CSharp\" and \"VB\".", inputValue)); } this.TargetLanguage = option; @@ -392,18 +392,18 @@ public void ValidateAndSetTargetLanguageFromString(string stringValue) /// /// Set the EnableNamingAlias property with the given value. /// -/// The value to set. -public void ValidateAndSetEnableNamingAliasFromString(string stringValue) +/// The value to set. +public void ValidateAndSetEnableNamingAliasFromString(string inputValue) { bool boolValue; - if (!bool.TryParse(stringValue, out boolValue)) + if (!bool.TryParse(inputValue, out boolValue)) { // ******************************************************************************************************** // To fix this error, if the current text transformation is run by the TextTemplatingFileGenerator // custom tool inside Visual Studio, update the .odata.config file in the project with a valid parameter // value then hit Ctrl-S to save the .tt file to refresh the code generation. // ******************************************************************************************************** - throw new ArgumentException(string.Format(CultureInfo.InvariantCulture, "The value \"{0}\" cannot be assigned to the EnableNamingAlias parameter because it is not a valid boolean value.", stringValue)); + throw new ArgumentException(string.Format(CultureInfo.InvariantCulture, "The value \"{0}\" cannot be assigned to the EnableNamingAlias parameter because it is not a valid boolean value.", inputValue)); } this.EnableNamingAlias = boolValue; @@ -412,18 +412,18 @@ public void ValidateAndSetEnableNamingAliasFromString(string stringValue) /// /// Set the IgnoreUnexpectedElementsAndAttributes property with the given value. /// -/// The value to set. -public void ValidateAndSetIgnoreUnexpectedElementsAndAttributesFromString(string stringValue) +/// The value to set. +public void ValidateAndSetIgnoreUnexpectedElementsAndAttributesFromString(string inputValue) { bool boolValue; - if (!bool.TryParse(stringValue, out boolValue)) + if (!bool.TryParse(inputValue, out boolValue)) { // ******************************************************************************************************** // To fix this error, if the current text transformation is run by the TextTemplatingFileGenerator // custom tool inside Visual Studio, update the .odata.config file in the project with a valid parameter // value then hit Ctrl-S to save the .tt file to refresh the code generation. // ******************************************************************************************************** - throw new ArgumentException(string.Format(CultureInfo.InvariantCulture, "The value \"{0}\" cannot be assigned to the IgnoreUnexpectedElementsAndAttributes parameter because it is not a valid boolean value.", stringValue)); + throw new ArgumentException(string.Format(CultureInfo.InvariantCulture, "The value \"{0}\" cannot be assigned to the IgnoreUnexpectedElementsAndAttributes parameter because it is not a valid boolean value.", inputValue)); } this.IgnoreUnexpectedElementsAndAttributes = boolValue; @@ -432,21 +432,21 @@ public void ValidateAndSetIgnoreUnexpectedElementsAndAttributesFromString(string /// /// Set the MakeTypesInternal property with the given value. /// -/// The value to set. -public void ValidateAndSetMakeTypesInternalFromString(string stringValue) +/// The value to set. +public void ValidateAndSetMakeTypesInternalFromString(string inputValue) { - bool boolValue; - if (!bool.TryParse(stringValue, out boolValue)) + bool parsedValue; + if (!bool.TryParse(inputValue, out parsedValue)) { // ******************************************************************************************************** // To fix this error, if the current text transformation is run by the TextTemplatingFileGenerator // custom tool inside Visual Studio, update the .odata.config file in the project with a valid parameter // value then hit Ctrl-S to save the .tt file to refresh the code generation. // ******************************************************************************************************** - throw new ArgumentException(string.Format(CultureInfo.InvariantCulture, "The value \"{0}\" cannot be assigned to the MakeTypesInternal parameter because it is not a valid boolean value.", stringValue)); + throw new ArgumentException(string.Format(CultureInfo.InvariantCulture, "The value \"{0}\" cannot be assigned to the MakeTypesInternal parameter because it is not a valid boolean value.", inputValue)); } - this.MakeTypesInternal = boolValue; + this.MakeTypesInternal = parsedValue; } /// From 9da329216184b04fcf67323204a96250c44d6090 Mon Sep 17 00:00:00 2001 From: Clement Habinshuti Date: Thu, 23 Jan 2020 14:27:38 +0300 Subject: [PATCH 16/24] Fix indentation issues in code generator template --- .../src/Templates/ODataT4CodeGenerator.ttinclude | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ODataConnectedService/src/Templates/ODataT4CodeGenerator.ttinclude b/ODataConnectedService/src/Templates/ODataT4CodeGenerator.ttinclude index f1bb494..b33b27f 100644 --- a/ODataConnectedService/src/Templates/ODataT4CodeGenerator.ttinclude +++ b/ODataConnectedService/src/Templates/ODataT4CodeGenerator.ttinclude @@ -221,8 +221,8 @@ public bool IgnoreUnexpectedElementsAndAttributes /// public bool MakeTypesInternal { - get; - set; + get; + set; } /// From e72c731c9b4558bc94a204b4b349e7b1f9a3747b Mon Sep 17 00:00:00 2001 From: Clement Habinshuti Date: Thu, 23 Jan 2020 15:46:29 +0300 Subject: [PATCH 17/24] Rename test namespace --- .../CodeGeneration/V4CodeGenDescriptorTest.cs | 9 +++------ .../ODataConnectedServiceHandlerTest.cs | 4 ++-- .../Templates/ODataT4CodeGeneratorTest.cs | 4 +--- .../TestHelpers/TestConnectedServiceHandlerContext.cs | 2 +- .../TestHelpers/TestConnectedServiceHandlerHelper.cs | 2 +- 5 files changed, 8 insertions(+), 13 deletions(-) diff --git a/ODataConnectedService/test/ODataConnectedService.Tests/CodeGeneration/V4CodeGenDescriptorTest.cs b/ODataConnectedService/test/ODataConnectedService.Tests/CodeGeneration/V4CodeGenDescriptorTest.cs index f315cf8..cda71db 100644 --- a/ODataConnectedService/test/ODataConnectedService.Tests/CodeGeneration/V4CodeGenDescriptorTest.cs +++ b/ODataConnectedService/test/ODataConnectedService.Tests/CodeGeneration/V4CodeGenDescriptorTest.cs @@ -1,17 +1,14 @@ -using System.Collections.Generic; -using System.IO; -using System.Threading.Tasks; +using System.IO; using Microsoft.VisualStudio.ConnectedServices; using EnvDTE; using Moq; using Microsoft.VisualStudio.TestTools.UnitTesting; -using Microsoft.OData.ConnectedService; using Microsoft.OData.ConnectedService.CodeGeneration; using Microsoft.OData.ConnectedService.Models; using Microsoft.OData.ConnectedService.Templates; -using ODataConnectedService.Tests.TestHelpers; +using Microsoft.OData.ConnectedService.Tests.TestHelpers; -namespace ODataConnectedService.Tests.CodeGeneration +namespace Microsoft.OData.ConnectedService.Tests.CodeGeneration { [TestClass] public class V4CodeGenDescriptorTest diff --git a/ODataConnectedService/test/ODataConnectedService.Tests/ODataConnectedServiceHandlerTest.cs b/ODataConnectedService/test/ODataConnectedService.Tests/ODataConnectedServiceHandlerTest.cs index 3a77290..3027e7e 100644 --- a/ODataConnectedService/test/ODataConnectedService.Tests/ODataConnectedServiceHandlerTest.cs +++ b/ODataConnectedService/test/ODataConnectedService.Tests/ODataConnectedServiceHandlerTest.cs @@ -9,9 +9,9 @@ using Microsoft.OData.ConnectedService.CodeGeneration; using Microsoft.OData.ConnectedService.Models; using Moq; -using ODataConnectedService.Tests.TestHelpers; +using Microsoft.OData.ConnectedService.Tests.TestHelpers; -namespace ODataConnectedService.Tests +namespace Microsoft.OData.ConnectedService.Tests { [TestClass] public class ODataConnectedServiceHandlerTest diff --git a/ODataConnectedService/test/ODataConnectedService.Tests/Templates/ODataT4CodeGeneratorTest.cs b/ODataConnectedService/test/ODataConnectedService.Tests/Templates/ODataT4CodeGeneratorTest.cs index fa67f6e..4c0894c 100644 --- a/ODataConnectedService/test/ODataConnectedService.Tests/Templates/ODataT4CodeGeneratorTest.cs +++ b/ODataConnectedService/test/ODataConnectedService.Tests/Templates/ODataT4CodeGeneratorTest.cs @@ -2,12 +2,10 @@ using System.IO; using System.Reflection; using System.Text.RegularExpressions; -using System.CodeDom.Compiler; using Microsoft.VisualStudio.TestTools.UnitTesting; using Microsoft.OData.ConnectedService.Templates; -using Microsoft.CSharp; -namespace ODataConnectedService.Tests.Templates +namespace Microsoft.OData.ConnectedService.Tests.Templates { [TestClass] public class ODataT4CodeGeneratorTest diff --git a/ODataConnectedService/test/ODataConnectedService.Tests/TestHelpers/TestConnectedServiceHandlerContext.cs b/ODataConnectedService/test/ODataConnectedService.Tests/TestHelpers/TestConnectedServiceHandlerContext.cs index cedb1ba..9643dc0 100644 --- a/ODataConnectedService/test/ODataConnectedService.Tests/TestHelpers/TestConnectedServiceHandlerContext.cs +++ b/ODataConnectedService/test/ODataConnectedService.Tests/TestHelpers/TestConnectedServiceHandlerContext.cs @@ -4,7 +4,7 @@ using Microsoft.VisualStudio.Shell.Interop; using Moq; -namespace ODataConnectedService.Tests.TestHelpers +namespace Microsoft.OData.ConnectedService.Tests.TestHelpers { class TestConnectedServiceHandlerContext : ConnectedServiceHandlerContext { diff --git a/ODataConnectedService/test/ODataConnectedService.Tests/TestHelpers/TestConnectedServiceHandlerHelper.cs b/ODataConnectedService/test/ODataConnectedService.Tests/TestHelpers/TestConnectedServiceHandlerHelper.cs index 440f930..d0c6a05 100644 --- a/ODataConnectedService/test/ODataConnectedService.Tests/TestHelpers/TestConnectedServiceHandlerHelper.cs +++ b/ODataConnectedService/test/ODataConnectedService.Tests/TestHelpers/TestConnectedServiceHandlerHelper.cs @@ -2,7 +2,7 @@ using System.Threading.Tasks; using Microsoft.VisualStudio.ConnectedServices; -namespace ODataConnectedService.Tests.TestHelpers +namespace Microsoft.OData.ConnectedService.Tests.TestHelpers { class TestConnectedServiceHandlerHelper : ConnectedServiceHandlerHelper { From 81d69cae3b692761e121814f27c8bd32c2539cff Mon Sep 17 00:00:00 2001 From: Clement Habinshuti Date: Thu, 23 Jan 2020 15:50:43 +0300 Subject: [PATCH 18/24] Add license header to new source files --- .../src/CodeGeneration/CodeGenDescriptorFactory.cs | 7 +++++-- .../src/CodeGeneration/ICodeGenDescriptorFactory.cs | 5 ++++- ODataConnectedService/src/ODataConnectedServiceHandler.cs | 2 -- ODataConnectedService/src/ODataConnectedServiceWizard.cs | 2 -- .../src/Templates/IODataT4CodeGeneratorFactory.cs | 7 ++----- .../src/Templates/ODataT4CodeGeneratorFactory.cs | 7 ++----- .../CodeGeneration/V4CodeGenDescriptorTest.cs | 5 ++++- .../ODataConnectedServiceHandlerTest.cs | 6 ++++-- .../Templates/ODataT4CodeGeneratorTest.cs | 5 ++++- .../TestHelpers/TestConnectedServiceHandlerContext.cs | 5 ++++- .../TestHelpers/TestConnectedServiceHandlerHelper.cs | 5 ++++- 11 files changed, 33 insertions(+), 23 deletions(-) diff --git a/ODataConnectedService/src/CodeGeneration/CodeGenDescriptorFactory.cs b/ODataConnectedService/src/CodeGeneration/CodeGenDescriptorFactory.cs index be38c41..2587b5f 100644 --- a/ODataConnectedService/src/CodeGeneration/CodeGenDescriptorFactory.cs +++ b/ODataConnectedService/src/CodeGeneration/CodeGenDescriptorFactory.cs @@ -1,8 +1,11 @@ -using System; +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See License.txt in the project root for license information. + +using System; +using System.Globalization; using EnvDTE; using Microsoft.VisualStudio.ConnectedServices; using Microsoft.OData.ConnectedService.Templates; -using System.Globalization; namespace Microsoft.OData.ConnectedService.CodeGeneration { diff --git a/ODataConnectedService/src/CodeGeneration/ICodeGenDescriptorFactory.cs b/ODataConnectedService/src/CodeGeneration/ICodeGenDescriptorFactory.cs index 9bafaa5..cdff867 100644 --- a/ODataConnectedService/src/CodeGeneration/ICodeGenDescriptorFactory.cs +++ b/ODataConnectedService/src/CodeGeneration/ICodeGenDescriptorFactory.cs @@ -1,4 +1,7 @@ -using System; +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See License.txt in the project root for license information. + +using System; using EnvDTE; using Microsoft.VisualStudio.ConnectedServices; diff --git a/ODataConnectedService/src/ODataConnectedServiceHandler.cs b/ODataConnectedService/src/ODataConnectedServiceHandler.cs index 96dec90..5875790 100644 --- a/ODataConnectedService/src/ODataConnectedServiceHandler.cs +++ b/ODataConnectedService/src/ODataConnectedServiceHandler.cs @@ -2,12 +2,10 @@ // Licensed under the MIT License. See License.txt in the project root for license information. using System; -using System.Globalization; using System.Threading; using System.Threading.Tasks; using EnvDTE; using Microsoft.OData.ConnectedService.CodeGeneration; -using Microsoft.OData.ConnectedService.Templates; using Microsoft.OData.ConnectedService.Common; using Microsoft.OData.ConnectedService.Models; using Microsoft.VisualStudio.ConnectedServices; diff --git a/ODataConnectedService/src/ODataConnectedServiceWizard.cs b/ODataConnectedService/src/ODataConnectedServiceWizard.cs index e5bef14..153ea60 100644 --- a/ODataConnectedService/src/ODataConnectedServiceWizard.cs +++ b/ODataConnectedService/src/ODataConnectedServiceWizard.cs @@ -3,8 +3,6 @@ using System; using System.Threading.Tasks; -using EnvDTE; -using Microsoft.OData.ConnectedService.Common; using Microsoft.OData.ConnectedService.Models; using Microsoft.OData.ConnectedService.ViewModels; using Microsoft.OData.ConnectedService.Views; diff --git a/ODataConnectedService/src/Templates/IODataT4CodeGeneratorFactory.cs b/ODataConnectedService/src/Templates/IODataT4CodeGeneratorFactory.cs index f9d5fad..417a72b 100644 --- a/ODataConnectedService/src/Templates/IODataT4CodeGeneratorFactory.cs +++ b/ODataConnectedService/src/Templates/IODataT4CodeGeneratorFactory.cs @@ -1,8 +1,5 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See License.txt in the project root for license information. namespace Microsoft.OData.ConnectedService.Templates { diff --git a/ODataConnectedService/src/Templates/ODataT4CodeGeneratorFactory.cs b/ODataConnectedService/src/Templates/ODataT4CodeGeneratorFactory.cs index 229596b..af6dca5 100644 --- a/ODataConnectedService/src/Templates/ODataT4CodeGeneratorFactory.cs +++ b/ODataConnectedService/src/Templates/ODataT4CodeGeneratorFactory.cs @@ -1,8 +1,5 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See License.txt in the project root for license information. namespace Microsoft.OData.ConnectedService.Templates { diff --git a/ODataConnectedService/test/ODataConnectedService.Tests/CodeGeneration/V4CodeGenDescriptorTest.cs b/ODataConnectedService/test/ODataConnectedService.Tests/CodeGeneration/V4CodeGenDescriptorTest.cs index cda71db..493b76b 100644 --- a/ODataConnectedService/test/ODataConnectedService.Tests/CodeGeneration/V4CodeGenDescriptorTest.cs +++ b/ODataConnectedService/test/ODataConnectedService.Tests/CodeGeneration/V4CodeGenDescriptorTest.cs @@ -1,4 +1,7 @@ -using System.IO; +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See License.txt in the project root for license information. + +using System.IO; using Microsoft.VisualStudio.ConnectedServices; using EnvDTE; using Moq; diff --git a/ODataConnectedService/test/ODataConnectedService.Tests/ODataConnectedServiceHandlerTest.cs b/ODataConnectedService/test/ODataConnectedService.Tests/ODataConnectedServiceHandlerTest.cs index 3027e7e..82dd99a 100644 --- a/ODataConnectedService/test/ODataConnectedService.Tests/ODataConnectedServiceHandlerTest.cs +++ b/ODataConnectedService/test/ODataConnectedService.Tests/ODataConnectedServiceHandlerTest.cs @@ -1,11 +1,13 @@ -using System; +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See License.txt in the project root for license information. + +using System; using System.Threading; using System.Threading.Tasks; using EnvDTE; using Microsoft.VisualStudio.ConnectedServices; using Microsoft.VisualStudio.Shell.Interop; using Microsoft.VisualStudio.TestTools.UnitTesting; -using Microsoft.OData.ConnectedService; using Microsoft.OData.ConnectedService.CodeGeneration; using Microsoft.OData.ConnectedService.Models; using Moq; diff --git a/ODataConnectedService/test/ODataConnectedService.Tests/Templates/ODataT4CodeGeneratorTest.cs b/ODataConnectedService/test/ODataConnectedService.Tests/Templates/ODataT4CodeGeneratorTest.cs index 4c0894c..2b709ac 100644 --- a/ODataConnectedService/test/ODataConnectedService.Tests/Templates/ODataT4CodeGeneratorTest.cs +++ b/ODataConnectedService/test/ODataConnectedService.Tests/Templates/ODataT4CodeGeneratorTest.cs @@ -1,4 +1,7 @@ -using System; +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See License.txt in the project root for license information. + +using System; using System.IO; using System.Reflection; using System.Text.RegularExpressions; diff --git a/ODataConnectedService/test/ODataConnectedService.Tests/TestHelpers/TestConnectedServiceHandlerContext.cs b/ODataConnectedService/test/ODataConnectedService.Tests/TestHelpers/TestConnectedServiceHandlerContext.cs index 9643dc0..68a994b 100644 --- a/ODataConnectedService/test/ODataConnectedService.Tests/TestHelpers/TestConnectedServiceHandlerContext.cs +++ b/ODataConnectedService/test/ODataConnectedService.Tests/TestHelpers/TestConnectedServiceHandlerContext.cs @@ -1,4 +1,7 @@ -using System.Collections.Generic; +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See License.txt in the project root for license information. + +using System.Collections.Generic; using System.Threading.Tasks; using Microsoft.VisualStudio.ConnectedServices; using Microsoft.VisualStudio.Shell.Interop; diff --git a/ODataConnectedService/test/ODataConnectedService.Tests/TestHelpers/TestConnectedServiceHandlerHelper.cs b/ODataConnectedService/test/ODataConnectedService.Tests/TestHelpers/TestConnectedServiceHandlerHelper.cs index d0c6a05..09b930e 100644 --- a/ODataConnectedService/test/ODataConnectedService.Tests/TestHelpers/TestConnectedServiceHandlerHelper.cs +++ b/ODataConnectedService/test/ODataConnectedService.Tests/TestHelpers/TestConnectedServiceHandlerHelper.cs @@ -1,4 +1,7 @@ -using System.Collections.Generic; +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See License.txt in the project root for license information. + +using System.Collections.Generic; using System.Threading.Tasks; using Microsoft.VisualStudio.ConnectedServices; From c896e6c8f4d532685d89eaa819a6cec57cd4a8ef Mon Sep 17 00:00:00 2001 From: Clement Habinshuti Date: Thu, 23 Jan 2020 15:51:29 +0300 Subject: [PATCH 19/24] Add note on unit tests to README --- README.md | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/README.md b/README.md index ffe14d9..dde463e 100644 --- a/README.md +++ b/README.md @@ -23,6 +23,15 @@ This repository is for exploring new ideas and developing early prototypes of va **Question**: In Visual Studio 2017, upon configuring the service endpoint in the OData Connected Services extension and clicking "Finish", I get an error message that says "Cannot access". **Workaround**: Most reported issues for this error are related to authentication-based endpoints. This extension does not currently support authentication. To work around, download the metadata as a text file from the endpoint and then point the OData Connected Services URI to the downloaded file. +#### Unit Tests + +The `ODataConnectedService.Tests.sln` contains the unit tests for the OData connected service. The folder structure of the tests mirrors the folder structre +of the `ODataConnectedService` project. The base namespace for tests is `Microsoft.OData.ConnectedService.Tests`. Furthermore each test class has the same name +as the class it is testing, followed by the suffix `Test`. + +Example: for some class `Microsoft.OData.ConnectedService.X.Y` located in `src\X\Y.cs`, +the test class would be `Microsoft.OData.Tests.ConnectedService.Tests.X.YTest` located in `test\X\YTest.cs` + ### OData v4 Web API Scaffolding * [Source](https://github.com/OData/lab/tree/master/WebAPIODataV4Scaffolding) From be346c6785343a5243b3fbe0143a7496e064f5c8 Mon Sep 17 00:00:00 2001 From: Clement Habinshuti Date: Thu, 23 Jan 2020 15:59:58 +0300 Subject: [PATCH 20/24] Re-enable signing --- ODataConnectedService/src/ODataConnectedService.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ODataConnectedService/src/ODataConnectedService.csproj b/ODataConnectedService/src/ODataConnectedService.csproj index 2b60915..c127546 100644 --- a/ODataConnectedService/src/ODataConnectedService.csproj +++ b/ODataConnectedService/src/ODataConnectedService.csproj @@ -43,7 +43,7 @@ Program $(DevEnvDir)devenv.exe /rootSuffix exp - false + true true $(DFRootPath)\tools\35MSSharedLib1024.snk From 3dd12603a9cb6064775e10fbff429a24f0720343 Mon Sep 17 00:00:00 2001 From: Clement Habinshuti Date: Thu, 23 Jan 2020 16:13:20 +0300 Subject: [PATCH 21/24] Fix indentation issue --- .../src/Templates/ODataT4CodeGenerator.ttinclude | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ODataConnectedService/src/Templates/ODataT4CodeGenerator.ttinclude b/ODataConnectedService/src/Templates/ODataT4CodeGenerator.ttinclude index b33b27f..575f73b 100644 --- a/ODataConnectedService/src/Templates/ODataT4CodeGenerator.ttinclude +++ b/ODataConnectedService/src/Templates/ODataT4CodeGenerator.ttinclude @@ -718,8 +718,8 @@ public class CodeGenerationContext /// public bool MakeTypesInternal { - get; - set; + get; + set; } /// From a056fefd41f3b45e8ace23bc42d7e6554974b1ac Mon Sep 17 00:00:00 2001 From: Clement Habinshuti Date: Tue, 28 Jan 2020 15:37:57 +0300 Subject: [PATCH 22/24] Properly handle TypeDefinition schema elements during code generation --- .../src/Templates/ODataT4CodeGenerator.cs | 31 ++- .../Templates/ODataT4CodeGenerator.ttinclude | 23 +- .../CodeGenReferences/TypeDefinitions.xml | 28 ++ ...initionsParamsConvertedToUnderlyingType.cs | 252 ++++++++++++++++++ .../Templates/ODataT4CodeGeneratorTest.cs | 14 + 5 files changed, 328 insertions(+), 20 deletions(-) create mode 100644 ODataConnectedService/test/ODataConnectedService.Tests/CodeGenReferences/TypeDefinitions.xml create mode 100644 ODataConnectedService/test/ODataConnectedService.Tests/CodeGenReferences/TypeDefinitionsParamsConvertedToUnderlyingType.cs diff --git a/ODataConnectedService/src/Templates/ODataT4CodeGenerator.cs b/ODataConnectedService/src/Templates/ODataT4CodeGenerator.cs index 6250d8e..15337dd 100644 --- a/ODataConnectedService/src/Templates/ODataT4CodeGenerator.cs +++ b/ODataConnectedService/src/Templates/ODataT4CodeGenerator.cs @@ -333,8 +333,8 @@ public bool IgnoreUnexpectedElementsAndAttributes /// public bool MakeTypesInternal { - get; - set; + get; + set; } /// @@ -830,8 +830,8 @@ public bool UseDataServiceCollection /// public bool MakeTypesInternal { - get; - set; + get; + set; } /// @@ -1311,14 +1311,13 @@ internal void WriteNamespace(string fullNamespace) { this.WriteComplexType(complexType, boundOperationsMap); } - else + else if (type is IEdmEntityType entityType) { - IEdmEntityType entityType = type as IEdmEntityType; this.WriteEntityType(entityType, boundOperationsMap); } IEdmStructuredType structuredType = type as IEdmStructuredType; - if (structuredType.BaseType != null) + if (structuredType?.BaseType != null) { List derivedTypes; if (!structuredBaseTypeMap.TryGetValue(structuredType.BaseType, out derivedTypes)) @@ -2846,8 +2845,16 @@ internal static string GetClrTypeName(IEdmTypeReference edmTypeReference, bool u clrTypeName = context.GetPrefixedFullName(edmEntityType, context.EnableNamingAlias ? clientTemplate.GetFixedName(Customization.CustomizeNaming(edmEntityType.Name)) : clientTemplate.GetFixedName(edmEntityType.Name), clientTemplate); } - else + else if (edmType is IEdmTypeDefinition edmTypeDefinition) { + IEdmPrimitiveType underlyingType = edmTypeDefinition.UnderlyingType; + clrTypeName = Utils.GetClrTypeName(underlyingType, clientTemplate); + if (edmTypeReference.IsNullable && !clientTemplate.ClrReferenceTypes.Contains(underlyingType.PrimitiveKind) && addNullableTemplate) + { + clrTypeName = string.Format(CultureInfo.InvariantCulture, clientTemplate.SystemNullableStructureTemplate, clrTypeName); + } + } + else { IEdmCollectionType edmCollectionType = (IEdmCollectionType)edmType; IEdmTypeReference elementTypeReference = edmCollectionType.ElementType; IEdmPrimitiveType primitiveElementType = elementTypeReference.Definition as IEdmPrimitiveType; @@ -3234,10 +3241,10 @@ public ODataClientCSharpTemplate(CodeGenerationContext context) internal override string GeometryMultiPolygonTypeName { get { return "global::Microsoft.Spatial.GeometryMultiPolygon"; } } internal override string GeometryMultiLineStringTypeName { get { return "global::Microsoft.Spatial.GeometryMultiLineString"; } } internal override string GeometryMultiPointTypeName { get { return "global::Microsoft.Spatial.GeometryMultiPoint"; } } - internal override string DateTypeName { get { return "global::Microsoft.OData.Edm.Library.Date"; } } + internal override string DateTypeName { get { return "global::Microsoft.OData.Edm.Date"; } } internal override string DateTimeOffsetTypeName { get { return "global::System.DateTimeOffset"; } } internal override string DurationTypeName { get { return "global::System.TimeSpan"; } } - internal override string TimeOfDayTypeName { get { return "global::Microsoft.OData.Edm.Library.TimeOfDay"; } } + internal override string TimeOfDayTypeName { get { return "global::Microsoft.OData.Edm.TimeOfDay"; } } internal override string XmlConvertClassName { get { return "global::System.Xml.XmlConvert"; } } internal override string EnumTypeName { get { return "global::System.Enum"; } } internal override string FixPattern { get { return "@{0}"; } } @@ -5186,10 +5193,10 @@ public ODataClientVBTemplate(CodeGenerationContext context) internal override string GeometryMultiPolygonTypeName { get { return "Global.Microsoft.Spatial.GeometryMultiPolygon"; } } internal override string GeometryMultiLineStringTypeName { get { return "Global.Microsoft.Spatial.GeometryMultiLineString"; } } internal override string GeometryMultiPointTypeName { get { return "Global.Microsoft.Spatial.GeometryMultiPoint"; } } - internal override string DateTypeName { get { return "Global.Microsoft.OData.Edm.Library.Date"; } } + internal override string DateTypeName { get { return "Global.Microsoft.OData.Edm.Date"; } } internal override string DateTimeOffsetTypeName { get { return "Global.System.DateTimeOffset"; } } internal override string DurationTypeName { get { return "Global.System.TimeSpan"; } } - internal override string TimeOfDayTypeName { get { return "Global.Microsoft.OData.Edm.Library.TimeOfDay"; } } + internal override string TimeOfDayTypeName { get { return "Global.Microsoft.OData.Edm.TimeOfDay"; } } internal override string XmlConvertClassName { get { return "Global.System.Xml.XmlConvert"; } } internal override string EnumTypeName { get { return "Global.System.Enum"; } } internal override string FixPattern { get { return "[{0}]"; } } diff --git a/ODataConnectedService/src/Templates/ODataT4CodeGenerator.ttinclude b/ODataConnectedService/src/Templates/ODataT4CodeGenerator.ttinclude index 575f73b..7f6d5a3 100644 --- a/ODataConnectedService/src/Templates/ODataT4CodeGenerator.ttinclude +++ b/ODataConnectedService/src/Templates/ODataT4CodeGenerator.ttinclude @@ -1199,14 +1199,13 @@ public abstract class ODataClientTemplate : TemplateBase { this.WriteComplexType(complexType, boundOperationsMap); } - else + else if (type is IEdmEntityType entityType) { - IEdmEntityType entityType = type as IEdmEntityType; this.WriteEntityType(entityType, boundOperationsMap); } IEdmStructuredType structuredType = type as IEdmStructuredType; - if (structuredType.BaseType != null) + if (structuredType?.BaseType != null) { List derivedTypes; if (!structuredBaseTypeMap.TryGetValue(structuredType.BaseType, out derivedTypes)) @@ -2734,8 +2733,16 @@ internal static class Utils clrTypeName = context.GetPrefixedFullName(edmEntityType, context.EnableNamingAlias ? clientTemplate.GetFixedName(Customization.CustomizeNaming(edmEntityType.Name)) : clientTemplate.GetFixedName(edmEntityType.Name), clientTemplate); } - else + else if (edmType is IEdmTypeDefinition edmTypeDefinition) { + IEdmPrimitiveType underlyingType = edmTypeDefinition.UnderlyingType; + clrTypeName = Utils.GetClrTypeName(underlyingType, clientTemplate); + if (edmTypeReference.IsNullable && !clientTemplate.ClrReferenceTypes.Contains(underlyingType.PrimitiveKind) && addNullableTemplate) + { + clrTypeName = string.Format(CultureInfo.InvariantCulture, clientTemplate.SystemNullableStructureTemplate, clrTypeName); + } + } + else { IEdmCollectionType edmCollectionType = (IEdmCollectionType)edmType; IEdmTypeReference elementTypeReference = edmCollectionType.ElementType; IEdmPrimitiveType primitiveElementType = elementTypeReference.Definition as IEdmPrimitiveType; @@ -3122,10 +3129,10 @@ public sealed class ODataClientCSharpTemplate : ODataClientTemplate internal override string GeometryMultiPolygonTypeName { get { return "global::Microsoft.Spatial.GeometryMultiPolygon"; } } internal override string GeometryMultiLineStringTypeName { get { return "global::Microsoft.Spatial.GeometryMultiLineString"; } } internal override string GeometryMultiPointTypeName { get { return "global::Microsoft.Spatial.GeometryMultiPoint"; } } - internal override string DateTypeName { get { return "global::Microsoft.OData.Edm.Library.Date"; } } + internal override string DateTypeName { get { return "global::Microsoft.OData.Edm.Date"; } } internal override string DateTimeOffsetTypeName { get { return "global::System.DateTimeOffset"; } } internal override string DurationTypeName { get { return "global::System.TimeSpan"; } } - internal override string TimeOfDayTypeName { get { return "global::Microsoft.OData.Edm.Library.TimeOfDay"; } } + internal override string TimeOfDayTypeName { get { return "global::Microsoft.OData.Edm.TimeOfDay"; } } internal override string XmlConvertClassName { get { return "global::System.Xml.XmlConvert"; } } internal override string EnumTypeName { get { return "global::System.Enum"; } } internal override string FixPattern { get { return "@{0}"; } } @@ -4163,10 +4170,10 @@ public sealed class ODataClientVBTemplate : ODataClientTemplate internal override string GeometryMultiPolygonTypeName { get { return "Global.Microsoft.Spatial.GeometryMultiPolygon"; } } internal override string GeometryMultiLineStringTypeName { get { return "Global.Microsoft.Spatial.GeometryMultiLineString"; } } internal override string GeometryMultiPointTypeName { get { return "Global.Microsoft.Spatial.GeometryMultiPoint"; } } - internal override string DateTypeName { get { return "Global.Microsoft.OData.Edm.Library.Date"; } } + internal override string DateTypeName { get { return "Global.Microsoft.OData.Edm.Date"; } } internal override string DateTimeOffsetTypeName { get { return "Global.System.DateTimeOffset"; } } internal override string DurationTypeName { get { return "Global.System.TimeSpan"; } } - internal override string TimeOfDayTypeName { get { return "Global.Microsoft.OData.Edm.Library.TimeOfDay"; } } + internal override string TimeOfDayTypeName { get { return "Global.Microsoft.OData.Edm.TimeOfDay"; } } internal override string XmlConvertClassName { get { return "Global.System.Xml.XmlConvert"; } } internal override string EnumTypeName { get { return "Global.System.Enum"; } } internal override string FixPattern { get { return "[{0}]"; } } diff --git a/ODataConnectedService/test/ODataConnectedService.Tests/CodeGenReferences/TypeDefinitions.xml b/ODataConnectedService/test/ODataConnectedService.Tests/CodeGenReferences/TypeDefinitions.xml new file mode 100644 index 0000000..f5dab05 --- /dev/null +++ b/ODataConnectedService/test/ODataConnectedService.Tests/CodeGenReferences/TypeDefinitions.xml @@ -0,0 +1,28 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/ODataConnectedService/test/ODataConnectedService.Tests/CodeGenReferences/TypeDefinitionsParamsConvertedToUnderlyingType.cs b/ODataConnectedService/test/ODataConnectedService.Tests/CodeGenReferences/TypeDefinitionsParamsConvertedToUnderlyingType.cs new file mode 100644 index 0000000..fd72a2d --- /dev/null +++ b/ODataConnectedService/test/ODataConnectedService.Tests/CodeGenReferences/TypeDefinitionsParamsConvertedToUnderlyingType.cs @@ -0,0 +1,252 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by a tool. +// Runtime Version:4.0.30319.42000 +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +// Generation date: 1/28/2020 3:05:18 PM +namespace Microsoft.OData.TestService +{ + /// + /// There are no comments for PersonSingle in the schema. + /// + public partial class PersonSingle : global::Microsoft.OData.Client.DataServiceQuerySingle + { + /// + /// Initialize a new PersonSingle object. + /// + public PersonSingle(global::Microsoft.OData.Client.DataServiceContext context, string path) + : base(context, path) { } + + /// + /// Initialize a new PersonSingle object. + /// + public PersonSingle(global::Microsoft.OData.Client.DataServiceContext context, string path, bool isComposable) + : base(context, path, isComposable) { } + + /// + /// Initialize a new PersonSingle object. + /// + public PersonSingle(global::Microsoft.OData.Client.DataServiceQuerySingle query) + : base(query) { } + + } + /// + /// There are no comments for Person in the schema. + /// + /// + /// UserName + /// + [global::Microsoft.OData.Client.Key("UserName")] + public partial class Person : global::Microsoft.OData.Client.BaseEntityType + { + /// + /// Create a new Person object. + /// + /// Initial value of UserName. + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + public static Person CreatePerson(string userName) + { + Person person = new Person(); + person.UserName = userName; + return person; + } + /// + /// There are no comments for Property UserName in the schema. + /// + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + public string UserName + { + get + { + return this._UserName; + } + set + { + this.OnUserNameChanging(value); + this._UserName = value; + this.OnUserNameChanged(); + } + } + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + private string _UserName; + partial void OnUserNameChanging(string value); + partial void OnUserNameChanged(); + /// + /// There are no comments for Property WakeUpTime in the schema. + /// + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + public global::System.Nullable WakeUpTime + { + get + { + return this._WakeUpTime; + } + set + { + this.OnWakeUpTimeChanging(value); + this._WakeUpTime = value; + this.OnWakeUpTimeChanged(); + } + } + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + private global::System.Nullable _WakeUpTime; + partial void OnWakeUpTimeChanging(global::System.Nullable value); + partial void OnWakeUpTimeChanged(); + /// + /// There are no comments for ReminderView in the schema. + /// + public global::Microsoft.OData.Client.DataServiceQuery ReminderView(string StartDateTime, string EndDateTime) + { + global::System.Uri requestUri; + Context.TryGetUri(this, out requestUri); + return this.Context.CreateFunctionQuery(string.Join("/", global::System.Linq.Enumerable.Select(global::System.Linq.Enumerable.Skip(requestUri.Segments, this.Context.BaseUri.Segments.Length), s => s.Trim('/'))), "Microsoft.OData.TestService.ReminderView", false, new global::Microsoft.OData.Client.UriOperationParameter("StartDateTime", StartDateTime), + new global::Microsoft.OData.Client.UriOperationParameter("EndDateTime", EndDateTime)); + } + } + /// + /// There are no comments for ReminderSingle in the schema. + /// + public partial class ReminderSingle : global::Microsoft.OData.Client.DataServiceQuerySingle + { + /// + /// Initialize a new ReminderSingle object. + /// + public ReminderSingle(global::Microsoft.OData.Client.DataServiceContext context, string path) + : base(context, path) { } + + /// + /// Initialize a new ReminderSingle object. + /// + public ReminderSingle(global::Microsoft.OData.Client.DataServiceContext context, string path, bool isComposable) + : base(context, path, isComposable) { } + + /// + /// Initialize a new ReminderSingle object. + /// + public ReminderSingle(global::Microsoft.OData.Client.DataServiceQuerySingle query) + : base(query) { } + + } + /// + /// There are no comments for Reminder in the schema. + /// + /// + /// Id + /// + [global::Microsoft.OData.Client.Key("Id")] + public partial class Reminder : global::Microsoft.OData.Client.BaseEntityType + { + /// + /// There are no comments for Property Id in the schema. + /// + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + public global::System.Nullable Id + { + get + { + return this._Id; + } + set + { + this.OnIdChanging(value); + this._Id = value; + this.OnIdChanged(); + } + } + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + private global::System.Nullable _Id; + partial void OnIdChanging(global::System.Nullable value); + partial void OnIdChanged(); + /// + /// There are no comments for Property ReminderTime in the schema. + /// + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + public string ReminderTime + { + get + { + return this._ReminderTime; + } + set + { + this.OnReminderTimeChanging(value); + this._ReminderTime = value; + this.OnReminderTimeChanged(); + } + } + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + private string _ReminderTime; + partial void OnReminderTimeChanging(string value); + partial void OnReminderTimeChanged(); + } + /// + /// Class containing all extension methods + /// + public static class ExtensionMethods + { + /// + /// Get an entity of type global::Microsoft.OData.TestService.Person as global::Microsoft.OData.TestService.PersonSingle specified by key from an entity set + /// + /// source entity set + /// dictionary with the names and values of keys + public static global::Microsoft.OData.TestService.PersonSingle ByKey(this global::Microsoft.OData.Client.DataServiceQuery source, global::System.Collections.Generic.Dictionary keys) + { + return new global::Microsoft.OData.TestService.PersonSingle(source.Context, source.GetKeyPath(global::Microsoft.OData.Client.Serializer.GetKeyString(source.Context, keys))); + } + /// + /// Get an entity of type global::Microsoft.OData.TestService.Person as global::Microsoft.OData.TestService.PersonSingle specified by key from an entity set + /// + /// source entity set + /// The value of userName + public static global::Microsoft.OData.TestService.PersonSingle ByKey(this global::Microsoft.OData.Client.DataServiceQuery source, + string userName) + { + global::System.Collections.Generic.Dictionary keys = new global::System.Collections.Generic.Dictionary + { + { "UserName", userName } + }; + return new global::Microsoft.OData.TestService.PersonSingle(source.Context, source.GetKeyPath(global::Microsoft.OData.Client.Serializer.GetKeyString(source.Context, keys))); + } + /// + /// Get an entity of type global::Microsoft.OData.TestService.Reminder as global::Microsoft.OData.TestService.ReminderSingle specified by key from an entity set + /// + /// source entity set + /// dictionary with the names and values of keys + public static global::Microsoft.OData.TestService.ReminderSingle ByKey(this global::Microsoft.OData.Client.DataServiceQuery source, global::System.Collections.Generic.Dictionary keys) + { + return new global::Microsoft.OData.TestService.ReminderSingle(source.Context, source.GetKeyPath(global::Microsoft.OData.Client.Serializer.GetKeyString(source.Context, keys))); + } + /// + /// Get an entity of type global::Microsoft.OData.TestService.Reminder as global::Microsoft.OData.TestService.ReminderSingle specified by key from an entity set + /// + /// source entity set + /// The value of id + public static global::Microsoft.OData.TestService.ReminderSingle ByKey(this global::Microsoft.OData.Client.DataServiceQuery source, + global::System.Nullable id) + { + global::System.Collections.Generic.Dictionary keys = new global::System.Collections.Generic.Dictionary + { + { "Id", id } + }; + return new global::Microsoft.OData.TestService.ReminderSingle(source.Context, source.GetKeyPath(global::Microsoft.OData.Client.Serializer.GetKeyString(source.Context, keys))); + } + /// + /// There are no comments for ReminderView in the schema. + /// + public static global::Microsoft.OData.Client.DataServiceQuery ReminderView(this global::Microsoft.OData.Client.DataServiceQuerySingle source, string StartDateTime, string EndDateTime) + { + if (!source.IsComposable) + { + throw new global::System.NotSupportedException("The previous function is not composable."); + } + + return source.CreateFunctionQuery("Microsoft.OData.TestService.ReminderView", false, new global::Microsoft.OData.Client.UriOperationParameter("StartDateTime", StartDateTime), + new global::Microsoft.OData.Client.UriOperationParameter("EndDateTime", EndDateTime)); + } + } +} diff --git a/ODataConnectedService/test/ODataConnectedService.Tests/Templates/ODataT4CodeGeneratorTest.cs b/ODataConnectedService/test/ODataConnectedService.Tests/Templates/ODataT4CodeGeneratorTest.cs index 2b709ac..2f2157b 100644 --- a/ODataConnectedService/test/ODataConnectedService.Tests/Templates/ODataT4CodeGeneratorTest.cs +++ b/ODataConnectedService/test/ODataConnectedService.Tests/Templates/ODataT4CodeGeneratorTest.cs @@ -75,6 +75,20 @@ public void TestEntitiesComplexTypesEnumFunctionsDSCWithInternalTypes() VerifyGeneratedCode(expected, output); } + [TestMethod] + public void TestTypeDefinitionParamsConvertedToUnderlyingType() + { + string edmx = LoadReferenceContent("TypeDefinitions.xml"); + string expected = LoadReferenceContent("TypeDefinitionsParamsConvertedToUnderlyingType.cs"); + var generator = new ODataT4CodeGenerator() + { + Edmx = edmx, + TargetLanguage = ODataT4CodeGenerator.LanguageOption.CSharp + }; + var output = generator.TransformText(); + VerifyGeneratedCode(expected, output); + } + static Assembly Assembly = Assembly.GetExecutingAssembly(); const string ReferenceResourcePrefix = "ODataConnectedService.Tests.CodeGenReferences."; From ef54f9e50a49b4a644c0cd9bc607306eae21c94d Mon Sep 17 00:00:00 2001 From: Clement Habinshuti Date: Tue, 28 Jan 2020 16:58:27 +0300 Subject: [PATCH 23/24] Test support for nullable TypeDefinitions --- .../CodeGenReferences/TypeDefinitions.xml | 4 +++- .../TypeDefinitionsParamsConvertedToUnderlyingType.cs | 10 ++++++---- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/ODataConnectedService/test/ODataConnectedService.Tests/CodeGenReferences/TypeDefinitions.xml b/ODataConnectedService/test/ODataConnectedService.Tests/CodeGenReferences/TypeDefinitions.xml index f5dab05..090aaf1 100644 --- a/ODataConnectedService/test/ODataConnectedService.Tests/CodeGenReferences/TypeDefinitions.xml +++ b/ODataConnectedService/test/ODataConnectedService.Tests/CodeGenReferences/TypeDefinitions.xml @@ -16,11 +16,13 @@ - + + + diff --git a/ODataConnectedService/test/ODataConnectedService.Tests/CodeGenReferences/TypeDefinitionsParamsConvertedToUnderlyingType.cs b/ODataConnectedService/test/ODataConnectedService.Tests/CodeGenReferences/TypeDefinitionsParamsConvertedToUnderlyingType.cs index fd72a2d..4662561 100644 --- a/ODataConnectedService/test/ODataConnectedService.Tests/CodeGenReferences/TypeDefinitionsParamsConvertedToUnderlyingType.cs +++ b/ODataConnectedService/test/ODataConnectedService.Tests/CodeGenReferences/TypeDefinitionsParamsConvertedToUnderlyingType.cs @@ -100,12 +100,13 @@ public string UserName /// /// There are no comments for ReminderView in the schema. /// - public global::Microsoft.OData.Client.DataServiceQuery ReminderView(string StartDateTime, string EndDateTime) + public global::Microsoft.OData.Client.DataServiceQuery ReminderView(string StartDateTime, string EndDateTime, global::System.Nullable MaxCount) { global::System.Uri requestUri; Context.TryGetUri(this, out requestUri); return this.Context.CreateFunctionQuery(string.Join("/", global::System.Linq.Enumerable.Select(global::System.Linq.Enumerable.Skip(requestUri.Segments, this.Context.BaseUri.Segments.Length), s => s.Trim('/'))), "Microsoft.OData.TestService.ReminderView", false, new global::Microsoft.OData.Client.UriOperationParameter("StartDateTime", StartDateTime), - new global::Microsoft.OData.Client.UriOperationParameter("EndDateTime", EndDateTime)); + new global::Microsoft.OData.Client.UriOperationParameter("EndDateTime", EndDateTime), + new global::Microsoft.OData.Client.UriOperationParameter("MaxCount", MaxCount)); } } /// @@ -238,7 +239,7 @@ public static class ExtensionMethods /// /// There are no comments for ReminderView in the schema. /// - public static global::Microsoft.OData.Client.DataServiceQuery ReminderView(this global::Microsoft.OData.Client.DataServiceQuerySingle source, string StartDateTime, string EndDateTime) + public static global::Microsoft.OData.Client.DataServiceQuery ReminderView(this global::Microsoft.OData.Client.DataServiceQuerySingle source, string StartDateTime, string EndDateTime, global::System.Nullable MaxCount) { if (!source.IsComposable) { @@ -246,7 +247,8 @@ public static class ExtensionMethods } return source.CreateFunctionQuery("Microsoft.OData.TestService.ReminderView", false, new global::Microsoft.OData.Client.UriOperationParameter("StartDateTime", StartDateTime), - new global::Microsoft.OData.Client.UriOperationParameter("EndDateTime", EndDateTime)); + new global::Microsoft.OData.Client.UriOperationParameter("EndDateTime", EndDateTime), + new global::Microsoft.OData.Client.UriOperationParameter("MaxCount", MaxCount)); } } } From 5449bdbe3e2918bfdb8da51f207865a7fb8550b7 Mon Sep 17 00:00:00 2001 From: Clement Habinshuti Date: Tue, 28 Jan 2020 17:34:37 +0300 Subject: [PATCH 24/24] Refactor GetClrTypeName in code generator --- .../src/Templates/ODataT4CodeGenerator.cs | 140 +++++++++--------- .../Templates/ODataT4CodeGenerator.ttinclude | 140 +++++++++--------- 2 files changed, 142 insertions(+), 138 deletions(-) diff --git a/ODataConnectedService/src/Templates/ODataT4CodeGenerator.cs b/ODataConnectedService/src/Templates/ODataT4CodeGenerator.cs index 15337dd..72e422b 100644 --- a/ODataConnectedService/src/Templates/ODataT4CodeGenerator.cs +++ b/ODataConnectedService/src/Templates/ODataT4CodeGenerator.cs @@ -1299,15 +1299,13 @@ internal void WriteNamespace(string fullNamespace) Dictionary> structuredBaseTypeMap = new Dictionary>(); foreach(IEdmSchemaType type in schemaElements.OfType()) { - IEdmEnumType enumType = type as IEdmEnumType; - if (enumType != null) + if (type is IEdmEnumType enumType) { this.WriteEnumType(enumType); } else { - IEdmComplexType complexType = type as IEdmComplexType; - if (complexType != null) + if (type is IEdmComplexType complexType) { this.WriteComplexType(complexType, boundOperationsMap); } @@ -2806,84 +2804,77 @@ internal static string PascalCase(string text) /// The clr type name of the type reference. internal static string GetClrTypeName(IEdmTypeReference edmTypeReference, bool useDataServiceCollection, ODataClientTemplate clientTemplate, CodeGenerationContext context, bool addNullableTemplate = true, bool needGlobalPrefix = true, bool isOperationParameter = false) { - string clrTypeName; IEdmType edmType = edmTypeReference.Definition; - IEdmPrimitiveType edmPrimitiveType = edmType as IEdmPrimitiveType; - if (edmPrimitiveType != null) + if (edmType is IEdmPrimitiveType edmPrimitiveType) { - clrTypeName = Utils.GetClrTypeName(edmPrimitiveType, clientTemplate); + var clrTypeName = Utils.GetClrTypeName(edmPrimitiveType, clientTemplate); if (edmTypeReference.IsNullable && !clientTemplate.ClrReferenceTypes.Contains(edmPrimitiveType.PrimitiveKind) && addNullableTemplate) { - clrTypeName = string.Format(CultureInfo.InvariantCulture, clientTemplate.SystemNullableStructureTemplate, clrTypeName); + clrTypeName = GetNullableClrTypeName(clrTypeName, clientTemplate); } + return clrTypeName; } - else + if (edmType is IEdmComplexType edmComplexType) { - IEdmComplexType edmComplexType = edmType as IEdmComplexType; - if (edmComplexType != null) - { - clrTypeName = context.GetPrefixedFullName(edmComplexType, + var clrTypeName = context.GetPrefixedFullName(edmComplexType, context.EnableNamingAlias ? clientTemplate.GetFixedName(Customization.CustomizeNaming(edmComplexType.Name)) : clientTemplate.GetFixedName(edmComplexType.Name), clientTemplate); + return clrTypeName; + } + if (edmType is IEdmEnumType edmEnumType) + { + var clrTypeName = context.GetPrefixedFullName(edmEnumType, + context.EnableNamingAlias ? clientTemplate.GetFixedName(Customization.CustomizeNaming(edmEnumType.Name)) : clientTemplate.GetFixedName(edmEnumType.Name), clientTemplate, needGlobalPrefix); + if (edmTypeReference.IsNullable && addNullableTemplate) + { + clrTypeName = GetNullableClrTypeName(clrTypeName, clientTemplate); } - else + return clrTypeName; + } + if (edmType is IEdmEntityType edmEntityType) + { + var clrTypeName = context.GetPrefixedFullName(edmEntityType, + context.EnableNamingAlias ? clientTemplate.GetFixedName(Customization.CustomizeNaming(edmEntityType.Name)) : clientTemplate.GetFixedName(edmEntityType.Name), clientTemplate); + return clrTypeName; + } + if (edmType is IEdmTypeDefinition edmTypeDefinition) + { + var underlyingType = edmTypeDefinition.UnderlyingType; + var clrTypeName = Utils.GetClrTypeName(underlyingType, clientTemplate); + if (edmTypeReference.IsNullable && !clientTemplate.ClrReferenceTypes.Contains(underlyingType.PrimitiveKind) && addNullableTemplate) { - IEdmEnumType edmEnumType = edmType as IEdmEnumType; - if (edmEnumType != null) - { - clrTypeName = context.GetPrefixedFullName(edmEnumType, - context.EnableNamingAlias ? clientTemplate.GetFixedName(Customization.CustomizeNaming(edmEnumType.Name)) : clientTemplate.GetFixedName(edmEnumType.Name), clientTemplate, needGlobalPrefix); - if (edmTypeReference.IsNullable && addNullableTemplate) - { - clrTypeName = string.Format(CultureInfo.InvariantCulture, clientTemplate.SystemNullableStructureTemplate, clrTypeName); - } - } - else - { - IEdmEntityType edmEntityType = edmType as IEdmEntityType; - if (edmEntityType != null) - { - clrTypeName = context.GetPrefixedFullName(edmEntityType, - context.EnableNamingAlias ? clientTemplate.GetFixedName(Customization.CustomizeNaming(edmEntityType.Name)) : clientTemplate.GetFixedName(edmEntityType.Name), clientTemplate); - } - else if (edmType is IEdmTypeDefinition edmTypeDefinition) - { - IEdmPrimitiveType underlyingType = edmTypeDefinition.UnderlyingType; - clrTypeName = Utils.GetClrTypeName(underlyingType, clientTemplate); - if (edmTypeReference.IsNullable && !clientTemplate.ClrReferenceTypes.Contains(underlyingType.PrimitiveKind) && addNullableTemplate) - { - clrTypeName = string.Format(CultureInfo.InvariantCulture, clientTemplate.SystemNullableStructureTemplate, clrTypeName); - } - } - else { - IEdmCollectionType edmCollectionType = (IEdmCollectionType)edmType; - IEdmTypeReference elementTypeReference = edmCollectionType.ElementType; - IEdmPrimitiveType primitiveElementType = elementTypeReference.Definition as IEdmPrimitiveType; - if (primitiveElementType != null) - { - clrTypeName = Utils.GetClrTypeName(primitiveElementType, clientTemplate); - } - else - { - IEdmSchemaElement schemaElement = (IEdmSchemaElement)elementTypeReference.Definition; - clrTypeName = context.GetPrefixedFullName(schemaElement, - context.EnableNamingAlias ? clientTemplate.GetFixedName(Customization.CustomizeNaming(schemaElement.Name)) : clientTemplate.GetFixedName(schemaElement.Name), clientTemplate); - } - - string collectionTypeName = isOperationParameter - ? clientTemplate.ICollectionOfTStructureTemplate - : (useDataServiceCollection - ? (elementTypeReference.TypeKind() == EdmTypeKind.Entity - ? clientTemplate.DataServiceCollectionStructureTemplate - : clientTemplate.ObservableCollectionStructureTemplate) - : clientTemplate.ObjectModelCollectionStructureTemplate); - - clrTypeName = string.Format(CultureInfo.InvariantCulture, collectionTypeName, clrTypeName); - } - } + clrTypeName = GetNullableClrTypeName(clrTypeName, clientTemplate); + } + return clrTypeName; + } + if (edmType is IEdmCollectionType edmCollectionType) + { + string clrTypeName = null; + IEdmTypeReference elementTypeReference = edmCollectionType.ElementType; + IEdmPrimitiveType primitiveElementType = elementTypeReference.Definition as IEdmPrimitiveType; + if (primitiveElementType != null) + { + clrTypeName = Utils.GetClrTypeName(primitiveElementType, clientTemplate); } + else + { + IEdmSchemaElement schemaElement = (IEdmSchemaElement)elementTypeReference.Definition; + clrTypeName = context.GetPrefixedFullName(schemaElement, + context.EnableNamingAlias ? clientTemplate.GetFixedName(Customization.CustomizeNaming(schemaElement.Name)) : clientTemplate.GetFixedName(schemaElement.Name), clientTemplate); + } + + string collectionTypeName = isOperationParameter + ? clientTemplate.ICollectionOfTStructureTemplate + : (useDataServiceCollection + ? (elementTypeReference.TypeKind() == EdmTypeKind.Entity + ? clientTemplate.DataServiceCollectionStructureTemplate + : clientTemplate.ObservableCollectionStructureTemplate) + : clientTemplate.ObjectModelCollectionStructureTemplate); + + clrTypeName = string.Format(CultureInfo.InvariantCulture, collectionTypeName, clrTypeName); + return clrTypeName; } - return clrTypeName; + throw new Exception($"Could not get CLR type name for EDM type '{edmTypeReference.FullName()}'"); } /// @@ -3025,6 +3016,17 @@ internal static string GetPropertyInitializationValue(IEdmProperty property, boo return clientTemplate.NewModifier + clrTypeName + constructorParameters; } } + + /// + /// Gets the corresponding nullable type name for the given clr type + /// + /// Original CLR type name. + /// ODataClientTemplate instance that call this method. + /// The nullable version of the specified type name. + internal static string GetNullableClrTypeName(string clrTypeName, ODataClientTemplate clientTemplate) + { + return string.Format(CultureInfo.InvariantCulture, clientTemplate.SystemNullableStructureTemplate, clrTypeName); + } /// /// Gets the clr type name from the give Edm primitive type. diff --git a/ODataConnectedService/src/Templates/ODataT4CodeGenerator.ttinclude b/ODataConnectedService/src/Templates/ODataT4CodeGenerator.ttinclude index 7f6d5a3..d51dcaa 100644 --- a/ODataConnectedService/src/Templates/ODataT4CodeGenerator.ttinclude +++ b/ODataConnectedService/src/Templates/ODataT4CodeGenerator.ttinclude @@ -1187,15 +1187,13 @@ public abstract class ODataClientTemplate : TemplateBase Dictionary> structuredBaseTypeMap = new Dictionary>(); foreach(IEdmSchemaType type in schemaElements.OfType()) { - IEdmEnumType enumType = type as IEdmEnumType; - if (enumType != null) + if (type is IEdmEnumType enumType) { this.WriteEnumType(enumType); } else { - IEdmComplexType complexType = type as IEdmComplexType; - if (complexType != null) + if (type is IEdmComplexType complexType) { this.WriteComplexType(complexType, boundOperationsMap); } @@ -2694,84 +2692,77 @@ internal static class Utils /// The clr type name of the type reference. internal static string GetClrTypeName(IEdmTypeReference edmTypeReference, bool useDataServiceCollection, ODataClientTemplate clientTemplate, CodeGenerationContext context, bool addNullableTemplate = true, bool needGlobalPrefix = true, bool isOperationParameter = false) { - string clrTypeName; IEdmType edmType = edmTypeReference.Definition; - IEdmPrimitiveType edmPrimitiveType = edmType as IEdmPrimitiveType; - if (edmPrimitiveType != null) + if (edmType is IEdmPrimitiveType edmPrimitiveType) { - clrTypeName = Utils.GetClrTypeName(edmPrimitiveType, clientTemplate); + var clrTypeName = Utils.GetClrTypeName(edmPrimitiveType, clientTemplate); if (edmTypeReference.IsNullable && !clientTemplate.ClrReferenceTypes.Contains(edmPrimitiveType.PrimitiveKind) && addNullableTemplate) { - clrTypeName = string.Format(CultureInfo.InvariantCulture, clientTemplate.SystemNullableStructureTemplate, clrTypeName); + clrTypeName = GetNullableClrTypeName(clrTypeName, clientTemplate); } + return clrTypeName; } - else + if (edmType is IEdmComplexType edmComplexType) { - IEdmComplexType edmComplexType = edmType as IEdmComplexType; - if (edmComplexType != null) - { - clrTypeName = context.GetPrefixedFullName(edmComplexType, + var clrTypeName = context.GetPrefixedFullName(edmComplexType, context.EnableNamingAlias ? clientTemplate.GetFixedName(Customization.CustomizeNaming(edmComplexType.Name)) : clientTemplate.GetFixedName(edmComplexType.Name), clientTemplate); + return clrTypeName; + } + if (edmType is IEdmEnumType edmEnumType) + { + var clrTypeName = context.GetPrefixedFullName(edmEnumType, + context.EnableNamingAlias ? clientTemplate.GetFixedName(Customization.CustomizeNaming(edmEnumType.Name)) : clientTemplate.GetFixedName(edmEnumType.Name), clientTemplate, needGlobalPrefix); + if (edmTypeReference.IsNullable && addNullableTemplate) + { + clrTypeName = GetNullableClrTypeName(clrTypeName, clientTemplate); } - else + return clrTypeName; + } + if (edmType is IEdmEntityType edmEntityType) + { + var clrTypeName = context.GetPrefixedFullName(edmEntityType, + context.EnableNamingAlias ? clientTemplate.GetFixedName(Customization.CustomizeNaming(edmEntityType.Name)) : clientTemplate.GetFixedName(edmEntityType.Name), clientTemplate); + return clrTypeName; + } + if (edmType is IEdmTypeDefinition edmTypeDefinition) + { + var underlyingType = edmTypeDefinition.UnderlyingType; + var clrTypeName = Utils.GetClrTypeName(underlyingType, clientTemplate); + if (edmTypeReference.IsNullable && !clientTemplate.ClrReferenceTypes.Contains(underlyingType.PrimitiveKind) && addNullableTemplate) { - IEdmEnumType edmEnumType = edmType as IEdmEnumType; - if (edmEnumType != null) - { - clrTypeName = context.GetPrefixedFullName(edmEnumType, - context.EnableNamingAlias ? clientTemplate.GetFixedName(Customization.CustomizeNaming(edmEnumType.Name)) : clientTemplate.GetFixedName(edmEnumType.Name), clientTemplate, needGlobalPrefix); - if (edmTypeReference.IsNullable && addNullableTemplate) - { - clrTypeName = string.Format(CultureInfo.InvariantCulture, clientTemplate.SystemNullableStructureTemplate, clrTypeName); - } - } - else - { - IEdmEntityType edmEntityType = edmType as IEdmEntityType; - if (edmEntityType != null) - { - clrTypeName = context.GetPrefixedFullName(edmEntityType, - context.EnableNamingAlias ? clientTemplate.GetFixedName(Customization.CustomizeNaming(edmEntityType.Name)) : clientTemplate.GetFixedName(edmEntityType.Name), clientTemplate); - } - else if (edmType is IEdmTypeDefinition edmTypeDefinition) - { - IEdmPrimitiveType underlyingType = edmTypeDefinition.UnderlyingType; - clrTypeName = Utils.GetClrTypeName(underlyingType, clientTemplate); - if (edmTypeReference.IsNullable && !clientTemplate.ClrReferenceTypes.Contains(underlyingType.PrimitiveKind) && addNullableTemplate) - { - clrTypeName = string.Format(CultureInfo.InvariantCulture, clientTemplate.SystemNullableStructureTemplate, clrTypeName); - } - } - else { - IEdmCollectionType edmCollectionType = (IEdmCollectionType)edmType; - IEdmTypeReference elementTypeReference = edmCollectionType.ElementType; - IEdmPrimitiveType primitiveElementType = elementTypeReference.Definition as IEdmPrimitiveType; - if (primitiveElementType != null) - { - clrTypeName = Utils.GetClrTypeName(primitiveElementType, clientTemplate); - } - else - { - IEdmSchemaElement schemaElement = (IEdmSchemaElement)elementTypeReference.Definition; - clrTypeName = context.GetPrefixedFullName(schemaElement, - context.EnableNamingAlias ? clientTemplate.GetFixedName(Customization.CustomizeNaming(schemaElement.Name)) : clientTemplate.GetFixedName(schemaElement.Name), clientTemplate); - } - - string collectionTypeName = isOperationParameter - ? clientTemplate.ICollectionOfTStructureTemplate - : (useDataServiceCollection - ? (elementTypeReference.TypeKind() == EdmTypeKind.Entity - ? clientTemplate.DataServiceCollectionStructureTemplate - : clientTemplate.ObservableCollectionStructureTemplate) - : clientTemplate.ObjectModelCollectionStructureTemplate); - - clrTypeName = string.Format(CultureInfo.InvariantCulture, collectionTypeName, clrTypeName); - } - } + clrTypeName = GetNullableClrTypeName(clrTypeName, clientTemplate); + } + return clrTypeName; + } + if (edmType is IEdmCollectionType edmCollectionType) + { + string clrTypeName = null; + IEdmTypeReference elementTypeReference = edmCollectionType.ElementType; + IEdmPrimitiveType primitiveElementType = elementTypeReference.Definition as IEdmPrimitiveType; + if (primitiveElementType != null) + { + clrTypeName = Utils.GetClrTypeName(primitiveElementType, clientTemplate); } + else + { + IEdmSchemaElement schemaElement = (IEdmSchemaElement)elementTypeReference.Definition; + clrTypeName = context.GetPrefixedFullName(schemaElement, + context.EnableNamingAlias ? clientTemplate.GetFixedName(Customization.CustomizeNaming(schemaElement.Name)) : clientTemplate.GetFixedName(schemaElement.Name), clientTemplate); + } + + string collectionTypeName = isOperationParameter + ? clientTemplate.ICollectionOfTStructureTemplate + : (useDataServiceCollection + ? (elementTypeReference.TypeKind() == EdmTypeKind.Entity + ? clientTemplate.DataServiceCollectionStructureTemplate + : clientTemplate.ObservableCollectionStructureTemplate) + : clientTemplate.ObjectModelCollectionStructureTemplate); + + clrTypeName = string.Format(CultureInfo.InvariantCulture, collectionTypeName, clrTypeName); + return clrTypeName; } - return clrTypeName; + throw new Exception($"Could not get CLR type name for EDM type '{edmTypeReference.FullName()}'"); } /// @@ -2913,6 +2904,17 @@ internal static class Utils return clientTemplate.NewModifier + clrTypeName + constructorParameters; } } + + /// + /// Gets the corresponding nullable type name for the given clr type + /// + /// Original CLR type name. + /// ODataClientTemplate instance that call this method. + /// The nullable version of the specified type name. + internal static string GetNullableClrTypeName(string clrTypeName, ODataClientTemplate clientTemplate) + { + return string.Format(CultureInfo.InvariantCulture, clientTemplate.SystemNullableStructureTemplate, clrTypeName); + } /// /// Gets the clr type name from the give Edm primitive type.