Skip to content

Update to build against JsonApiDotNetCore v5.1.2 #18

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<PropertyGroup>
<TargetFrameworkName>net6.0</TargetFrameworkName>
<AspNetVersion>6.0.*</AspNetVersion>
<JsonApiDotNetCoreVersion>5.1.0</JsonApiDotNetCoreVersion>
<JsonApiDotNetCoreVersion>5.1.2</JsonApiDotNetCoreVersion>
<MongoDBDriverVersion>2.15.0</MongoDBDriverVersion>
<JsonApiDotNetCoreMongoDbVersionPrefix>5.1.0</JsonApiDotNetCoreMongoDbVersionPrefix>
<CodeAnalysisRuleSet>$(MSBuildThisFileDirectory)CodingGuidelines.ruleset</CodeAnalysisRuleSet>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
using JsonApiDotNetCore.Queries.Internal;
using Microsoft.Extensions.DependencyInjection;

#pragma warning disable AV1130 // Return type in method signature should be an interface to an unchangeable collection

namespace JsonApiDotNetCore.MongoDb.Configuration;

public static class ServiceCollectionExtensions
Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
using JsonApiDotNetCore.Errors;
using JsonApiDotNetCore.Middleware;
using JsonApiDotNetCore.MongoDb.Errors;
using JsonApiDotNetCore.MongoDb.Queries.Internal.QueryableBuilding;
using JsonApiDotNetCore.MongoDb.Resources;
using JsonApiDotNetCore.Queries;
using JsonApiDotNetCore.Queries.Expressions;
Expand Down Expand Up @@ -115,16 +114,14 @@ protected virtual IMongoQueryable<TResource> ApplyQueryLayer(QueryLayer queryLay

var nameFactory = new LambdaParameterNameFactory();

var builder = new MongoQueryableBuilder(source.Expression, source.ElementType, typeof(Queryable), nameFactory, _resourceFactory,
var builder = new QueryableBuilder(source.Expression, source.ElementType, typeof(Queryable), nameFactory, _resourceFactory,
new MongoModel(_resourceGraph));

Expression expression = builder.ApplyQuery(queryLayer);
return (IMongoQueryable<TResource>)source.Provider.CreateQuery<TResource>(expression);
}

#pragma warning disable AV1130 // Return type in method signature should be an interface to an unchangeable collection
protected virtual IQueryable<TResource> GetAll()
#pragma warning restore AV1130 // Return type in method signature should be an interface to an unchangeable collection
{
return _mongoDataAccess.ActiveSession != null ? Collection.AsQueryable(_mongoDataAccess.ActiveSession) : Collection.AsQueryable();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System.Globalization;
using System.Net;
using System.Reflection;
using System.Web;
Expand Down Expand Up @@ -49,7 +50,9 @@ await _testContext.RunOnDatabaseAsync(async dbContext =>
});

string attributeName = propertyName.Camelize();
string route = $"/filterableResources?filter=equals({attributeName},'{propertyValue}')";
string? attributeValue = Convert.ToString(propertyValue, CultureInfo.InvariantCulture);

string route = $"/filterableResources?filter=equals({attributeName},'{attributeValue}')";

// Act
(HttpResponseMessage httpResponse, Document responseDocument) = await _testContext.ExecuteGetAsync<Document>(route);
Expand Down Expand Up @@ -77,7 +80,7 @@ await _testContext.RunOnDatabaseAsync(async dbContext =>
await dbContext.SaveChangesAsync();
});

string route = $"/filterableResources?filter=equals(someDecimal,'{resource.SomeDecimal}')";
string route = $"/filterableResources?filter=equals(someDecimal,'{resource.SomeDecimal.ToString(CultureInfo.InvariantCulture)}')";

// Act
(HttpResponseMessage httpResponse, Document responseDocument) = await _testContext.ExecuteGetAsync<Document>(route);
Expand Down Expand Up @@ -117,6 +120,36 @@ await _testContext.RunOnDatabaseAsync(async dbContext =>
responseDocument.Data.ManyValue[0].Attributes.ShouldContainKey("someGuid").With(value => value.Should().Be(resource.SomeGuid));
}

[Fact]
public async Task Can_filter_equality_on_type_DateTime_in_local_time_zone()
{
// Arrange
var resource = new FilterableResource
{
SomeDateTimeInLocalZone = 27.January(2003).At(11, 22, 33, 44)
};

await _testContext.RunOnDatabaseAsync(async dbContext =>
{
await dbContext.ClearTableAsync<FilterableResource>();
dbContext.FilterableResources.AddRange(resource, new FilterableResource());
await dbContext.SaveChangesAsync();
});

string route = $"/filterableResources?filter=equals(someDateTimeInLocalZone,'{resource.SomeDateTimeInLocalZone:O}')";

// Act
(HttpResponseMessage httpResponse, Document responseDocument) = await _testContext.ExecuteGetAsync<Document>(route);

// Assert
httpResponse.ShouldHaveStatusCode(HttpStatusCode.OK);

responseDocument.Data.ManyValue.ShouldHaveCount(1);

responseDocument.Data.ManyValue[0].Attributes.ShouldContainKey("someDateTimeInLocalZone")
.With(value => value.Should().Be(resource.SomeDateTimeInLocalZone));
}

[Fact]
public async Task Can_filter_equality_on_type_DateTime_in_UTC_time_zone()
{
Expand Down Expand Up @@ -191,7 +224,7 @@ await _testContext.RunOnDatabaseAsync(async dbContext =>
await dbContext.SaveChangesAsync();
});

string route = $"/filterableResources?filter=equals(someTimeSpan,'{resource.SomeTimeSpan}')";
string route = $"/filterableResources?filter=equals(someTimeSpan,'{resource.SomeTimeSpan:c}')";

// Act
(HttpResponseMessage httpResponse, Document responseDocument) = await _testContext.ExecuteGetAsync<Document>(route);
Expand Down
Loading