Skip to content

Commit

Permalink
Bump to ODL 7.9.4, Enable property name case-insensitive
Browse files Browse the repository at this point in the history
  • Loading branch information
xuzhg committed Nov 7, 2021
1 parent 2b178ae commit 1b26be5
Show file tree
Hide file tree
Showing 8 changed files with 61 additions and 6 deletions.
7 changes: 7 additions & 0 deletions sample/ODataRoutingSample/Controllers/ProductsController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
// </copyright>
//------------------------------------------------------------------------------

using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
Expand Down Expand Up @@ -32,18 +33,24 @@ public ProductsController(MyDataContext context)
{
Category = "Goods",
Color = Color.Red,
CreatedDate = new DateTimeOffset(2001, 4, 15, 16, 24, 8, TimeSpan.FromHours(-8)),
UpdatedDate = new DateTimeOffset(2011, 2, 15, 16, 24, 8, TimeSpan.FromHours(-8)),
Detail = new ProductDetail { Id = "3", Info = "Zhang" },
},
new Product
{
Category = "Magazine",
Color = Color.Blue,
CreatedDate = new DateTimeOffset(2021, 12, 27, 9, 12, 8, TimeSpan.FromHours(-8)),
UpdatedDate = null,
Detail = new ProductDetail { Id = "4", Info = "Jinchan" },
},
new Product
{
Category = "Fiction",
Color = Color.Green,
CreatedDate = new DateTimeOffset(1978, 11, 15, 9, 24, 8, TimeSpan.FromHours(-8)),
UpdatedDate = new DateTimeOffset(1987, 2, 25, 5, 1, 8, TimeSpan.FromHours(-8)),
Detail = new ProductDetail { Id = "5", Info = "Hollewye" },
},
};
Expand Down
6 changes: 6 additions & 0 deletions sample/ODataRoutingSample/Models/Product.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
// </copyright>
//------------------------------------------------------------------------------

using System;

namespace ODataRoutingSample.Models
{
public class Product
Expand All @@ -15,6 +17,10 @@ public class Product

public Color Color { get; set; }

public DateTimeOffset CreatedDate { get; set; }

public DateTimeOffset? UpdatedDate { get; set; }

public virtual ProductDetail Detail { get; set; }
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,10 @@ public static IContainerBuilder AddDefaultWebApiServices(this IContainerBuilder

// WebAPI should read untyped values as structural values by setting ReadUntypedAsString=false.
// In ODL 8.x, ReadUntypedAsString option will be deleted.
ReadUntypedAsString = false
ReadUntypedAsString = false,

// Enable read property name case-insensitive from payload.
EnablePropertyNameCaseInsensitive = true
});

builder.AddServicePrototype(new ODataMessageWriterSettings
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ namespace Microsoft.AspNetCore.OData.Abstracts
/// </summary>
internal class DefaultContainerBuilder : IContainerBuilder
{

internal IServiceCollection Services { get; } = new ServiceCollection();

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,13 @@
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.OData.ModelBuilder" Version="1.0.7" />
<PackageReference Include="Microsoft.OData.Core" Version="7.9.2" />
<PackageReference Include="Microsoft.OData.Edm" Version="7.9.2" />
<PackageReference Include="Microsoft.OData.Core" Version="7.9.4" />
<PackageReference Include="Microsoft.OData.Edm" Version="7.9.4" />
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.0.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.Spatial" Version="7.9.2" />
<PackageReference Include="Microsoft.Spatial" Version="7.9.4" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
using Microsoft.AspNetCore.OData.Deltas;
using Microsoft.AspNetCore.OData.Query;
using Microsoft.AspNetCore.OData.Routing.Controllers;
using Xunit;

namespace Microsoft.AspNetCore.OData.E2E.Tests.DateTimeOffsetSupport
{
Expand Down Expand Up @@ -59,6 +60,17 @@ public IActionResult Get(int key)
[HttpPost]
public IActionResult Post([FromBody]File file)
{
if (file.FileId == 99)
{
// Special test case for property name case-insensitive
Assert.Equal("abc", file.Name);
Assert.Equal(DateTimeOffset.Parse("10/28/2021 9:33:26 PM +08:00"), file.CreatedDate);
Assert.Equal(DateTimeOffset.Parse("11/1/2021 10:48:12 AM +08:00"), file.DeleteDate);

// special string used to verify at test case.
return Ok("PropertyCaseInsensitive");
}

_db.Files.Add(file);
_db.SaveChanges();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,34 @@ public async Task CreateDeleteFileEntityRoundTrip(string mode)
getResponse = await client.GetAsync(fileUri);
Assert.Equal(HttpStatusCode.NotFound, getResponse.StatusCode);
}

[Fact]
public async Task CreateFileEntity_Works_UsingDifferentPropertyNameCase()
{
// Arrange
HttpClient client = CreateClient();
string filesUri = $"convention/Files";
string content =
"{" +
"\"fileid\":99," + // use a special ID to test
"\"naMe\":\"abc\"," +
"\"creaTeddate\":\"2021-10-28T21:33:26+08:00\"," +
"\"deLEteDate\":\"2021-11-01T10:48:12+08:00\"" +
"}";

// Act: POST ~/Files
HttpRequestMessage postRequest = new HttpRequestMessage(HttpMethod.Post, filesUri);
postRequest.Content = new StringContent(content);
postRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json");

var postResponse = await client.SendAsync(postRequest);

// Assert
Assert.Equal(HttpStatusCode.OK, postResponse.StatusCode);

string payload = await postResponse.Content.ReadAsStringAsync();
Assert.Contains("PropertyCaseInsensitive", payload);
}
#endregion

#region Query option on DateTime
Expand Down
2 changes: 1 addition & 1 deletion tool/builder.versions.settings.targets
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

<!-- For NuGet Package Dependencies -->
<PropertyGroup>
<ODataLibPackageDependency>[7.9.2, 8.0.0)</ODataLibPackageDependency>
<ODataLibPackageDependency>[7.9.4, 8.0.0)</ODataLibPackageDependency>
<ODataModelBuilderPackageDependency>[1.0.7, 2.0.0)</ODataModelBuilderPackageDependency>
</PropertyGroup>

Expand Down

0 comments on commit 1b26be5

Please sign in to comment.