Skip to content
This repository has been archived by the owner on Dec 29, 2020. It is now read-only.

Commit

Permalink
Merge pull request #133 from TrevorPilley/develop
Browse files Browse the repository at this point in the history
4.1.4.0
  • Loading branch information
TrevorPilley authored Oct 30, 2019
2 parents 01d25a6 + 814d20b commit 5e8c48d
Show file tree
Hide file tree
Showing 99 changed files with 579 additions and 382 deletions.
11 changes: 7 additions & 4 deletions Net.Http.WebApi.OData.Tests/Metadata/MetadataProviderTests.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
namespace Net.Http.WebApi.OData.Tests.Metadata
{
using System.Xml.Linq;
using Net.Http.WebApi.OData.Metadata;
using Net.Http.WebApi.OData.Model;
using Xunit;
Expand All @@ -11,9 +12,7 @@ public void Create_Returns_CSDL()
{
TestHelper.EnsureEDM();

var csdlDocument = MetadataProvider.Create(EntityDataModel.Current);

Assert.Equal(@"<edmx:Edmx xmlns:edmx=""http://docs.oasis-open.org/odata/ns/edmx"" Version=""4.0"">
var expected = XDocument.Parse(@"<edmx:Edmx xmlns:edmx=""http://docs.oasis-open.org/odata/ns/edmx"" Version=""4.0"">
<edmx:DataServices>
<Schema xmlns=""http://docs.oasis-open.org/odata/ns/edm"" Namespace=""NorthwindModel"">
<EnumType Name=""AccessLevel"" UnderlyingType=""Edm.Int32"" IsFlags=""True"">
Expand Down Expand Up @@ -239,7 +238,11 @@ public void Create_Returns_CSDL()
</Annotations>
</Schema>
</edmx:DataServices>
</edmx:Edmx>", csdlDocument.ToString());
</edmx:Edmx>");

var csdlDocument = MetadataProvider.Create(EntityDataModel.Current);

Assert.Equal(expected.ToString(), csdlDocument.ToString());
}
}
}
13 changes: 10 additions & 3 deletions Net.Http.WebApi.OData.Tests/Net.Http.WebApi.OData.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<TargetFrameworkProfile />
<LangVersion>7.3</LangVersion>
<NuGetPackageImportStamp>
</NuGetPackageImportStamp>
</PropertyGroup>
Expand Down Expand Up @@ -41,10 +42,10 @@
</PropertyGroup>
<ItemGroup>
<Reference Include="Castle.Core, Version=4.0.0.0, Culture=neutral, PublicKeyToken=407dd0808d44fbdc, processorArchitecture=MSIL">
<HintPath>..\packages\Castle.Core.4.2.1\lib\net45\Castle.Core.dll</HintPath>
<HintPath>..\packages\Castle.Core.4.4.0\lib\net45\Castle.Core.dll</HintPath>
</Reference>
<Reference Include="Moq, Version=4.7.145.0, Culture=neutral, PublicKeyToken=69f491c39445e920, processorArchitecture=MSIL">
<HintPath>..\packages\Moq.4.7.145\lib\net45\Moq.dll</HintPath>
<Reference Include="Moq, Version=4.13.0.0, Culture=neutral, PublicKeyToken=69f491c39445e920, processorArchitecture=MSIL">
<HintPath>..\packages\Moq.4.13.1\lib\net45\Moq.dll</HintPath>
</Reference>
<Reference Include="Newtonsoft.Json, Version=10.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<HintPath>..\packages\Newtonsoft.Json.10.0.3\lib\net45\Newtonsoft.Json.dll</HintPath>
Expand All @@ -57,7 +58,13 @@
<Reference Include="System.Net.Http.Formatting, Version=5.2.7.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>..\packages\Microsoft.AspNet.WebApi.Client.5.2.7\lib\net45\System.Net.Http.Formatting.dll</HintPath>
</Reference>
<Reference Include="System.Runtime.CompilerServices.Unsafe, Version=4.0.5.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>..\packages\System.Runtime.CompilerServices.Unsafe.4.6.0\lib\netstandard1.0\System.Runtime.CompilerServices.Unsafe.dll</HintPath>
</Reference>
<Reference Include="System.Runtime.Serialization" />
<Reference Include="System.Threading.Tasks.Extensions, Version=4.2.0.1, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
<HintPath>..\packages\System.Threading.Tasks.Extensions.4.5.3\lib\portable-net45+win8+wp8+wpa81\System.Threading.Tasks.Extensions.dll</HintPath>
</Reference>
<Reference Include="System.Web.Http, Version=5.2.7.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>..\packages\Microsoft.AspNet.WebApi.Core.5.2.7\lib\net45\System.Web.Http.dll</HintPath>
</Reference>
Expand Down
2 changes: 1 addition & 1 deletion Net.Http.WebApi.OData.Tests/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("Project Contributors")]
[assembly: AssemblyProduct("Net.Http.WebApi.OData.Tests")]
[assembly: AssemblyCopyright("Copyright 2012 - 2018 Project Contributors all rights reserved.")]
[assembly: AssemblyCopyright("Copyright 2012 - 2019 Project Contributors all rights reserved.")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]

Expand Down
8 changes: 8 additions & 0 deletions Net.Http.WebApi.OData.Tests/app.config
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,14 @@
<assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-10.0.0.0" newVersion="10.0.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Threading.Tasks.Extensions" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.2.0.1" newVersion="4.2.0.1" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Runtime.CompilerServices.Unsafe" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.0.5.0" newVersion="4.0.5.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
</configuration>
6 changes: 4 additions & 2 deletions Net.Http.WebApi.OData.Tests/packages.config
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Castle.Core" version="4.2.1" targetFramework="net45" />
<package id="Castle.Core" version="4.4.0" targetFramework="net45" />
<package id="Microsoft.AspNet.WebApi.Client" version="5.2.7" targetFramework="net45" />
<package id="Microsoft.AspNet.WebApi.Core" version="5.2.7" targetFramework="net45" />
<package id="Moq" version="4.7.145" targetFramework="net45" />
<package id="Moq" version="4.13.1" targetFramework="net45" />
<package id="Newtonsoft.Json" version="10.0.3" targetFramework="net45" />
<package id="System.Runtime.CompilerServices.Unsafe" version="4.6.0" targetFramework="net45" />
<package id="System.Threading.Tasks.Extensions" version="4.5.3" targetFramework="net45" />
<package id="xunit" version="2.1.0" targetFramework="net45" />
<package id="xunit.abstractions" version="2.0.0" targetFramework="net45" />
<package id="xunit.assert" version="2.1.0" targetFramework="net45" />
Expand Down
5 changes: 2 additions & 3 deletions Net.Http.WebApi.OData.nuspec
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,11 @@
<authors>Trevor Pilley and Project Contributors</authors>
<owners>Trevor Pilley</owners>
<description>A library which makes it easy to consume an OData 4.0 Query with ASP.NET WebApi.</description>
<releaseNotes>See https://github.com/TrevorPilley/Net.Http.WebApi.OData/releases for a summary of changes made in this release of the package.
</releaseNotes>
<releaseNotes>See https://github.com/TrevorPilley/Net.Http.WebApi.OData/releases for a summary of changes made in this release of the package.</releaseNotes>
<language>en-GB</language>
<projectUrl>https://github.com/TrevorPilley/Net.Http.WebApi.OData/</projectUrl>
<licenseUrl>https://github.com/TrevorPilley/Net.Http.WebApi.OData/blob/master/License.txt</licenseUrl>
<copyright>Copyright 2012 - 2018 Project Contributors</copyright>
<copyright>Copyright 2012 - 2019 Project Contributors</copyright>
<requireLicenseAcceptance>false</requireLicenseAcceptance>
<tags>OData Parser WebApi ASP.NET</tags>
<dependencies>
Expand Down
4 changes: 2 additions & 2 deletions Net.Http.WebApi.OData.ruleset
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<RuleSet Name="Net.Http.WebApi.OData Rules" Description="Net.Http.WebApi.OData Custom Rules." ToolsVersion="14.0">
<RuleSet Name="Net.Http.WebApi.OData Rules" Description="Net.Http.WebApi.OData Custom Rules." ToolsVersion="16.0">
<IncludeAll Action="Warning" />
<Rules AnalyzerId="Microsoft.Analyzers.ManagedCodeAnalysis" RuleNamespace="Microsoft.Rules.Managed">
<Rule Id="CA1000" Action="Error" />
Expand All @@ -13,7 +13,7 @@
<Rule Id="CA1008" Action="Error" />
<Rule Id="CA1009" Action="Error" />
<Rule Id="CA1010" Action="Error" />
<Rule Id="CA1011" Action="Error" />
<Rule Id="CA1011" Action="Warning" />
<Rule Id="CA1012" Action="Error" />
<Rule Id="CA1013" Action="Error" />
<Rule Id="CA1014" Action="Error" />
Expand Down
4 changes: 2 additions & 2 deletions Net.Http.WebApi.OData.sln
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15
VisualStudioVersion = 15.0.28010.2016
# Visual Studio Version 16
VisualStudioVersion = 16.0.29411.108
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Net.Http.WebApi.OData", "Net.Http.WebApi.OData\Net.Http.WebApi.OData.csproj", "{67FBEB32-944E-4022-8B80-5589762B2B05}"
EndProject
Expand Down
6 changes: 3 additions & 3 deletions Net.Http.WebApi.OData/HttpConfigurationODataExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// -----------------------------------------------------------------------
// <copyright file="HttpConfigurationODataExtensions.cs" company="Project Contributors">
// Copyright 2012 - 2018 Project Contributors
// Copyright 2012 - 2019 Project Contributors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -43,12 +43,12 @@ public static void UseOData(
Action<EntityDataModelBuilder> entityDataModelBuilderCallback,
IEqualityComparer<string> entitySetNameComparer)
{
if (configuration == null)
if (configuration is null)
{
throw new ArgumentNullException(nameof(configuration));
}

if (entityDataModelBuilderCallback == null)
if (entityDataModelBuilderCallback is null)
{
throw new ArgumentNullException(nameof(entityDataModelBuilderCallback));
}
Expand Down
88 changes: 76 additions & 12 deletions Net.Http.WebApi.OData/HttpRequestMessageExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// -----------------------------------------------------------------------
// <copyright file="HttpRequestMessageExtensions.cs" company="Project Contributors">
// Copyright 2012 - 2018 Project Contributors
// Copyright 2012 - 2019 Project Contributors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand All @@ -18,11 +18,11 @@ namespace Net.Http.WebApi.OData
using System.Linq;
using System.Net;
using System.Net.Http;
using Model;
using Query;
using Net.Http.WebApi.OData.Model;
using Net.Http.WebApi.OData.Query;

/// <summary>
/// Extensions for the <see cref="HttpRequestMessage"/> class
/// Extensions for the <see cref="HttpRequestMessage"/> class.
/// </summary>
public static class HttpRequestMessageExtensions
{
Expand All @@ -35,7 +35,7 @@ public static class HttpRequestMessageExtensions
/// <returns>An initialized System.Net.Http.HttpResponseMessage wired up to the associated System.Net.Http.HttpRequestMessage.</returns>
/// <example>
/// <code>request.CreateODataErrorResponse(HttpStatusCode.BadRequest, "Path segment not supported: 'Foo'.");</code>
/// <para>{ "error": { "code": "400", "message": "Path segment not supported: 'Foo'." } }</para>
/// <para>{ "error": { "code": "400", "message": "Path segment not supported: 'Foo'." } }.</para>
/// </example>
public static HttpResponseMessage CreateODataErrorResponse(this HttpRequestMessage request, HttpStatusCode statusCode, string message)
=> CreateODataErrorResponse(request, statusCode, message, null);
Expand All @@ -50,7 +50,7 @@ public static HttpResponseMessage CreateODataErrorResponse(this HttpRequestMessa
/// <returns>An initialized System.Net.Http.HttpResponseMessage wired up to the associated System.Net.Http.HttpRequestMessage.</returns>
/// <example>
/// <code>request.CreateODataErrorResponse(HttpStatusCode.BadRequest, "400", "Path segment not supported: 'Foo'.");</code>
/// <para>{ "error": { "code": "400", "message": "Path segment not supported: 'Foo'." } }</para>
/// <para>{ "error": { "code": "400", "message": "Path segment not supported: 'Foo'." } }.</para>
/// </example>
public static HttpResponseMessage CreateODataErrorResponse(this HttpRequestMessage request, HttpStatusCode statusCode, string message, string target)
{
Expand Down Expand Up @@ -87,10 +87,22 @@ public static HttpResponseMessage CreateODataErrorResponse(this HttpRequestMessa
/// request.CreateODataErrorResponse(e);
/// }
/// </code>
/// <para>{ "error": { "code": "400", "message": "Path segment not supported: 'Foo'.", "target": "Foo" } }</para>
/// <para>{ "error": { "code": "400", "message": "Path segment not supported: 'Foo'.", "target": "Foo" } }.</para>
/// </example>
public static HttpResponseMessage CreateODataErrorResponse(this HttpRequestMessage request, ODataException exception)
=> CreateODataErrorResponse(request, exception.StatusCode, exception.Message, exception.Target);
{
if (request is null)
{
throw new ArgumentNullException(nameof(request));
}

if (exception is null)
{
throw new ArgumentNullException(nameof(exception));
}

return request.CreateODataErrorResponse(exception.StatusCode, exception.Message, exception.Target);
}

/// <summary>
/// Creates the OData response message from the specified request message.
Expand Down Expand Up @@ -134,7 +146,7 @@ public static HttpResponseMessage CreateODataResponse(this HttpRequestMessage re
/// <param name="value">The string content of the HTTP response message.</param>
/// <returns>An initialized System.Net.Http.HttpResponseMessage wired up to the associated System.Net.Http.HttpRequestMessage.</returns>
public static HttpResponseMessage CreateODataResponse(this HttpRequestMessage request, string value)
=> CreateODataResponse(request, value == null ? HttpStatusCode.NoContent : HttpStatusCode.OK, value);
=> CreateODataResponse(request, value is null ? HttpStatusCode.NoContent : HttpStatusCode.OK, value);

/// <summary>
/// Creates the OData response message from the specified request message.
Expand Down Expand Up @@ -162,7 +174,7 @@ public static HttpResponseMessage CreateODataResponse<T>(this HttpRequestMessage
/// <returns>The OData request options for the request.</returns>
public static ODataRequestOptions ReadODataRequestOptions(this HttpRequestMessage request)
{
if (request == null)
if (request is null)
{
throw new ArgumentNullException(nameof(request));
}
Expand All @@ -184,7 +196,7 @@ public static ODataRequestOptions ReadODataRequestOptions(this HttpRequestMessag
/// <returns>The EntitySet the OData request relates to.</returns>
public static EntitySet ResolveEntitySet(this HttpRequestMessage request)
{
if (request == null)
if (request is null)
{
throw new ArgumentNullException(nameof(request));
}
Expand All @@ -206,6 +218,11 @@ public static EntitySet ResolveEntitySet(this HttpRequestMessage request)
/// <returns>A <see cref="Uri"/> containing the @odata.context URI, or null if the metadata for the request is none.</returns>
public static Uri ResolveODataContextUri(this HttpRequestMessage request)
{
if (request is null)
{
throw new ArgumentNullException(nameof(request));
}

var requestOptions = request.ReadODataRequestOptions();

if (requestOptions.MetadataLevel == ODataMetadataLevel.None)
Expand All @@ -224,6 +241,16 @@ public static Uri ResolveODataContextUri(this HttpRequestMessage request)
/// <returns>A <see cref="Uri"/> containing the @odata.context URI, or null if the metadata for the request is none.</returns>
public static Uri ResolveODataContextUri(this HttpRequestMessage request, EntitySet entitySet)
{
if (request is null)
{
throw new ArgumentNullException(nameof(request));
}

if (entitySet is null)
{
throw new ArgumentNullException(nameof(entitySet));
}

var requestOptions = request.ReadODataRequestOptions();

if (requestOptions.MetadataLevel == ODataMetadataLevel.None)
Expand All @@ -243,6 +270,16 @@ public static Uri ResolveODataContextUri(this HttpRequestMessage request, Entity
/// <returns>A <see cref="Uri"/> containing the @odata.context URI, or null if the metadata for the request is none.</returns>
public static Uri ResolveODataContextUri(this HttpRequestMessage request, EntitySet entitySet, SelectExpandQueryOption selectExpandQueryOption)
{
if (request is null)
{
throw new ArgumentNullException(nameof(request));
}

if (entitySet is null)
{
throw new ArgumentNullException(nameof(entitySet));
}

var requestOptions = request.ReadODataRequestOptions();

if (requestOptions.MetadataLevel == ODataMetadataLevel.None)
Expand All @@ -263,6 +300,11 @@ public static Uri ResolveODataContextUri(this HttpRequestMessage request, Entity
/// <returns>A <see cref="Uri"/> containing the @odata.context URI, or null if the metadata for the request is none.</returns>
public static Uri ResolveODataContextUri<TEntityKey>(this HttpRequestMessage request, EntitySet entitySet, TEntityKey entityKey)
{
if (request is null)
{
throw new ArgumentNullException(nameof(request));
}

var requestOptions = request.ReadODataRequestOptions();

if (requestOptions.MetadataLevel == ODataMetadataLevel.None)
Expand All @@ -284,6 +326,16 @@ public static Uri ResolveODataContextUri<TEntityKey>(this HttpRequestMessage req
/// <returns>A <see cref="Uri"/> containing the @odata.context URI, or null if the metadata for the request is none.</returns>
public static Uri ResolveODataContextUri<TEntityKey>(this HttpRequestMessage request, EntitySet entitySet, TEntityKey entityKey, string propertyName)
{
if (request is null)
{
throw new ArgumentNullException(nameof(request));
}

if (entitySet is null)
{
throw new ArgumentNullException(nameof(entitySet));
}

var requestOptions = request.ReadODataRequestOptions();

if (requestOptions.MetadataLevel == ODataMetadataLevel.None)
Expand All @@ -303,7 +355,19 @@ public static Uri ResolveODataContextUri<TEntityKey>(this HttpRequestMessage req
/// <param name="entityKey">The Entity Key for the item in the EntitySet.</param>
/// <returns>A <see cref="Uri"/> containing the address of the Entity with the specified Entity Key.</returns>
public static Uri ResolveODataEntityUri<TEntityKey>(this HttpRequestMessage request, EntitySet entitySet, TEntityKey entityKey)
=> new Uri(request.RequestUri.ODataEntityUriBuilder(entitySet, entityKey).ToString());
{
if (request is null)
{
throw new ArgumentNullException(nameof(request));
}

if (entitySet is null)
{
throw new ArgumentNullException(nameof(entitySet));
}

return new Uri(request.RequestUri.ODataEntityUriBuilder(entitySet, entityKey).ToString());
}

internal static string ReadHeaderValue(this HttpRequestMessage request, string name)
{
Expand Down
Loading

0 comments on commit 5e8c48d

Please sign in to comment.