Skip to content

Commit

Permalink
Package updates (#15)
Browse files Browse the repository at this point in the history
* Renamed method to avoid clash with built-in method from newer version of FluentAssertions

* Package updates
  • Loading branch information
bkoelman authored Apr 6, 2022
1 parent a2fb679 commit 6524e5e
Show file tree
Hide file tree
Showing 54 changed files with 205 additions and 191 deletions.
8 changes: 4 additions & 4 deletions .config/dotnet-tools.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@
"isRoot": true,
"tools": {
"jetbrains.resharper.globaltools": {
"version": "2021.3.0",
"version": "2021.3.4",
"commands": [
"jb"
]
},
"regitlint": {
"version": "6.0.6",
"version": "6.0.8",
"commands": [
"regitlint"
]
Expand All @@ -21,10 +21,10 @@
]
},
"dotnet-reportgenerator-globaltool": {
"version": "5.0.0",
"version": "5.1.4",
"commands": [
"reportgenerator"
]
}
}
}
}
3 changes: 2 additions & 1 deletion CodingGuidelines.ruleset
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,15 @@
<Rule Id="AV1555" Action="Warning" />
<Rule Id="AV1564" Action="Info" />
<Rule Id="AV1568" Action="Warning" />
<Rule Id="AV1580" Action="None" />
<Rule Id="AV1706" Action="Warning" />
<Rule Id="AV1710" Action="Info" />
<Rule Id="AV1711" Action="Info" />
<Rule Id="AV1738" Action="Warning" />
<Rule Id="AV1739" Action="Warning" />
<Rule Id="AV1745" Action="Warning" />
<Rule Id="AV1755" Action="Warning" />
<Rule Id="AV2210" Action="None" />
<Rule Id="AV2210" Action="Warning" />
<Rule Id="AV2220" Action="Warning" />
<Rule Id="AV2230" Action="Info" />
<Rule Id="AV2305" Action="None" />
Expand Down
16 changes: 10 additions & 6 deletions Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
<PropertyGroup>
<TargetFrameworkName>net6.0</TargetFrameworkName>
<AspNetVersion>6.0.*</AspNetVersion>
<JsonApiDotNetCoreVersion>5.0.0-pre1</JsonApiDotNetCoreVersion>
<MongoDBDriverVersion>2.14.*</MongoDBDriverVersion>
<JsonApiDotNetCoreMongoDbVersionPrefix>5.0.0</JsonApiDotNetCoreMongoDbVersionPrefix>
<JsonApiDotNetCoreVersion>5.0.1</JsonApiDotNetCoreVersion>
<MongoDBDriverVersion>2.15.0</MongoDBDriverVersion>
<JsonApiDotNetCoreMongoDbVersionPrefix>5.0.1</JsonApiDotNetCoreMongoDbVersionPrefix>
<CodeAnalysisRuleSet>$(MSBuildThisFileDirectory)CodingGuidelines.ruleset</CodeAnalysisRuleSet>
<WarningLevel>9999</WarningLevel>
<Nullable>enable</Nullable>
Expand All @@ -15,7 +15,7 @@

<ItemGroup>
<PackageReference Include="JetBrains.Annotations" Version="2021.3.0" PrivateAssets="All" />
<PackageReference Include="CSharpGuidelinesAnalyzer" Version="3.7.1" PrivateAssets="All" />
<PackageReference Include="CSharpGuidelinesAnalyzer" Version="3.8.0" PrivateAssets="All" />
<AdditionalFiles Include="$(MSBuildThisFileDirectory)CSharpGuidelinesAnalyzer.config" Visible="False" />
</ItemGroup>

Expand All @@ -25,10 +25,14 @@
<GenerateDocumentationFile>true</GenerateDocumentationFile>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)'=='Debug'">
<NoWarn>$(NoWarn);AV2210</NoWarn>
</PropertyGroup>

<!-- Test Project Dependencies -->
<PropertyGroup>
<CoverletVersion>3.1.0</CoverletVersion>
<CoverletVersion>3.1.2</CoverletVersion>
<MoqVersion>4.16.1</MoqVersion>
<TestSdkVersion>17.0.0</TestSdkVersion>
<TestSdkVersion>17.1.0</TestSdkVersion>
</PropertyGroup>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
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
2 changes: 1 addition & 1 deletion src/JsonApiDotNetCore.MongoDb/Repositories/MongoModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public MongoModel(IResourceGraph resourceGraph)

foreach (ResourceType resourceType in resourceGraph.GetResourceTypes())
{
RuntimeEntityType entityType = AddEntityType(resourceType.ClrType.Name, resourceType.ClrType);
RuntimeEntityType entityType = AddEntityType(resourceType.ClrType.FullName!, resourceType.ClrType);
SetEntityProperties(entityType, resourceType);
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using JsonApiDotNetCore.Configuration;
using JsonApiDotNetCore.MongoDb.Errors;
using JsonApiDotNetCore.Queries;
using JsonApiDotNetCore.Queries.Expressions;
Expand All @@ -12,9 +13,8 @@ public void Validate(QueryLayer layer)
ArgumentGuard.NotNull(layer, nameof(layer));

bool hasIncludes = layer.Include?.Elements.Any() == true;
bool hasSparseRelationshipSets = layer.Projection?.Any(pair => pair.Key is RelationshipAttribute) == true;

if (hasIncludes || hasSparseRelationshipSets)
if (hasIncludes || HasSparseRelationshipSets(layer.Selection))
{
throw new UnsupportedRelationshipException();
}
Expand All @@ -24,6 +24,24 @@ public void Validate(QueryLayer layer)
ValidateExpression(layer.Pagination);
}

private static bool HasSparseRelationshipSets(FieldSelection? selection)
{
if (selection is { IsEmpty: false })
{
foreach (ResourceType resourceType in selection.GetResourceTypes())
{
FieldSelectors selectors = selection.GetOrCreateSelectors(resourceType);

if (selectors.Any(pair => pair.Key is RelationshipAttribute))
{
return true;
}
}
}

return false;
}

private void ValidateExpression(QueryExpression? expression)
{
if (expression != null)
Expand Down
15 changes: 10 additions & 5 deletions src/JsonApiDotNetCore.MongoDb/Repositories/MongoRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,9 @@ public virtual Task<int> CountAsync(FilterExpression? topFilter, CancellationTok
return query.CountAsync(cancellationToken);
}

#pragma warning disable AV1130 // Return type in method signature should be an interface to an unchangeable collection
protected virtual IMongoQueryable<TResource> ApplyQueryLayer(QueryLayer queryLayer)
#pragma warning restore AV1130 // Return type in method signature should be an interface to an unchangeable collection
{
ArgumentGuard.NotNull(queryLayer, nameof(queryLayer));

Expand Down Expand Up @@ -120,7 +122,9 @@ protected virtual IMongoQueryable<TResource> ApplyQueryLayer(QueryLayer queryLay
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 Expand Up @@ -150,9 +154,9 @@ private void AssertNoRelationshipsInSparseFieldSets()
}

/// <inheritdoc />
public virtual Task<TResource> GetForCreateAsync(TId id, CancellationToken cancellationToken)
public virtual Task<TResource> GetForCreateAsync(Type resourceClrType, TId id, CancellationToken cancellationToken)
{
var resource = _resourceFactory.CreateInstance<TResource>();
var resource = (TResource)_resourceFactory.CreateInstance(resourceClrType);
resource.Id = id;

return Task.FromResult(resource);
Expand Down Expand Up @@ -228,9 +232,9 @@ await SaveChangesAsync(async () =>
}

/// <inheritdoc />
public virtual async Task DeleteAsync(TId id, CancellationToken cancellationToken)
public virtual async Task DeleteAsync(TResource? resourceFromDatabase, TId id, CancellationToken cancellationToken)
{
var placeholderResource = _resourceFactory.CreateInstance<TResource>();
TResource placeholderResource = resourceFromDatabase ?? _resourceFactory.CreateInstance<TResource>();
placeholderResource.Id = id;

await _resourceDefinitionAccessor.OnWritingAsync(placeholderResource, WriteOperationKind.DeleteResource, cancellationToken);
Expand Down Expand Up @@ -263,7 +267,8 @@ public virtual Task SetRelationshipAsync(TResource leftResource, object? rightVa
}

/// <inheritdoc />
public virtual Task AddToToManyRelationshipAsync(TId leftId, ISet<IIdentifiable> rightResourceIds, CancellationToken cancellationToken)
public virtual Task AddToToManyRelationshipAsync(TResource? leftResource, TId leftId, ISet<IIdentifiable> rightResourceIds,
CancellationToken cancellationToken)
{
throw new UnsupportedRelationshipException();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public async Task Can_create_resource()
(HttpResponseMessage httpResponse, Document responseDocument) = await _testContext.ExecutePostAtomicAsync<Document>(route, requestBody);

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

responseDocument.Results.ShouldHaveCount(1);

Expand Down Expand Up @@ -119,7 +119,7 @@ public async Task Can_create_resources()
(HttpResponseMessage httpResponse, Document responseDocument) = await _testContext.ExecutePostAtomicAsync<Document>(route, requestBody);

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

responseDocument.Results.ShouldHaveCount(elementCount);

Expand Down Expand Up @@ -192,7 +192,7 @@ public async Task Can_create_resource_without_attributes_or_relationships()
(HttpResponseMessage httpResponse, Document responseDocument) = await _testContext.ExecutePostAtomicAsync<Document>(route, requestBody);

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

responseDocument.Results.ShouldHaveCount(1);

Expand Down Expand Up @@ -248,7 +248,7 @@ public async Task Cannot_create_resource_with_client_generated_ID()
(HttpResponseMessage httpResponse, Document responseDocument) = await _testContext.ExecutePostAtomicAsync<Document>(route, requestBody);

// Assert
httpResponse.Should().HaveStatusCode(HttpStatusCode.Forbidden);
httpResponse.ShouldHaveStatusCode(HttpStatusCode.Forbidden);

responseDocument.Errors.ShouldHaveCount(1);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public async Task Can_create_resource_with_client_generated_string_ID_having_sid
(HttpResponseMessage httpResponse, Document responseDocument) = await _testContext.ExecutePostAtomicAsync<Document>(route, requestBody);

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

string isoCode = $"{newLanguage.IsoCode}{ContainerTypeToHideFromAutoDiscovery.ImplicitlyChangingTextLanguageDefinition.Suffix}";

Expand Down Expand Up @@ -110,7 +110,7 @@ public async Task Can_create_resource_with_client_generated_string_ID_having_no_
(HttpResponseMessage httpResponse, string responseDocument) = await _testContext.ExecutePostAtomicAsync<string>(route, requestBody);

// Assert
httpResponse.Should().HaveStatusCode(HttpStatusCode.NoContent);
httpResponse.ShouldHaveStatusCode(HttpStatusCode.NoContent);

responseDocument.Should().BeEmpty();

Expand Down Expand Up @@ -163,7 +163,7 @@ await _testContext.RunOnDatabaseAsync(async dbContext =>
(HttpResponseMessage httpResponse, Document responseDocument) = await _testContext.ExecutePostAtomicAsync<Document>(route, requestBody);

// Assert
httpResponse.Should().HaveStatusCode(HttpStatusCode.Conflict);
httpResponse.ShouldHaveStatusCode(HttpStatusCode.Conflict);

responseDocument.Errors.ShouldHaveCount(1);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ await _testContext.RunOnDatabaseAsync(async dbContext =>
(HttpResponseMessage httpResponse, Document responseDocument) = await _testContext.ExecutePostAtomicAsync<Document>(route, requestBody);

// Assert
httpResponse.Should().HaveStatusCode(HttpStatusCode.BadRequest);
httpResponse.ShouldHaveStatusCode(HttpStatusCode.BadRequest);

responseDocument.Errors.ShouldHaveCount(1);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ await _testContext.RunOnDatabaseAsync(async dbContext =>
(HttpResponseMessage httpResponse, Document responseDocument) = await _testContext.ExecutePostAtomicAsync<Document>(route, requestBody);

// Assert
httpResponse.Should().HaveStatusCode(HttpStatusCode.BadRequest);
httpResponse.ShouldHaveStatusCode(HttpStatusCode.BadRequest);

responseDocument.Errors.ShouldHaveCount(1);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ await _testContext.RunOnDatabaseAsync(async dbContext =>
(HttpResponseMessage httpResponse, string responseDocument) = await _testContext.ExecutePostAtomicAsync<string>(route, requestBody);

// Assert
httpResponse.Should().HaveStatusCode(HttpStatusCode.NoContent);
httpResponse.ShouldHaveStatusCode(HttpStatusCode.NoContent);

responseDocument.Should().BeEmpty();

Expand Down Expand Up @@ -104,7 +104,7 @@ await _testContext.RunOnDatabaseAsync(async dbContext =>
(HttpResponseMessage httpResponse, string responseDocument) = await _testContext.ExecutePostAtomicAsync<string>(route, requestBody);

// Assert
httpResponse.Should().HaveStatusCode(HttpStatusCode.NoContent);
httpResponse.ShouldHaveStatusCode(HttpStatusCode.NoContent);

responseDocument.Should().BeEmpty();

Expand Down Expand Up @@ -144,7 +144,7 @@ public async Task Cannot_delete_resource_for_unknown_ID()
(HttpResponseMessage httpResponse, Document responseDocument) = await _testContext.ExecutePostAtomicAsync<Document>(route, requestBody);

// Assert
httpResponse.Should().HaveStatusCode(HttpStatusCode.NotFound);
httpResponse.ShouldHaveStatusCode(HttpStatusCode.NotFound);

responseDocument.Errors.ShouldHaveCount(1);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public async Task Can_update_resource_using_local_ID()
(HttpResponseMessage httpResponse, Document responseDocument) = await _testContext.ExecutePostAtomicAsync<Document>(route, requestBody);

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

responseDocument.Results.ShouldHaveCount(2);

Expand Down Expand Up @@ -133,7 +133,7 @@ public async Task Can_delete_resource_using_local_ID()
(HttpResponseMessage httpResponse, Document responseDocument) = await _testContext.ExecutePostAtomicAsync<Document>(route, requestBody);

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

responseDocument.Results.ShouldHaveCount(2);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public async Task Returns_resource_meta_in_create_resource_with_side_effects()
(HttpResponseMessage httpResponse, Document responseDocument) = await _testContext.ExecutePostAtomicAsync<Document>(route, requestBody);

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

responseDocument.Results.ShouldHaveCount(2);

Expand Down Expand Up @@ -143,7 +143,7 @@ await _testContext.RunOnDatabaseAsync(async dbContext =>
(HttpResponseMessage httpResponse, Document responseDocument) = await _testContext.ExecutePostAtomicAsync<Document>(route, requestBody);

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

responseDocument.Results.ShouldHaveCount(1);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,6 @@ public async Task Can_process_high_number_of_operations_when_unconstrained()
(HttpResponseMessage httpResponse, _) = await _testContext.ExecutePostAtomicAsync<Document>(route, requestBody);

// Assert
httpResponse.Should().HaveStatusCode(HttpStatusCode.OK);
httpResponse.ShouldHaveStatusCode(HttpStatusCode.OK);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ await _testContext.RunOnDatabaseAsync(async dbContext =>
(HttpResponseMessage httpResponse, Document responseDocument) = await _testContext.ExecutePostAtomicAsync<Document>(route, requestBody);

// Assert
httpResponse.Should().HaveStatusCode(HttpStatusCode.NotFound);
httpResponse.ShouldHaveStatusCode(HttpStatusCode.NotFound);

responseDocument.Errors.ShouldHaveCount(1);

Expand Down Expand Up @@ -137,7 +137,7 @@ await _testContext.RunOnDatabaseAsync(async dbContext =>
(HttpResponseMessage httpResponse, Document responseDocument) = await _testContext.ExecutePostAtomicAsync<Document>(route, requestBody);

// Assert
httpResponse.Should().HaveStatusCode(HttpStatusCode.NotFound);
httpResponse.ShouldHaveStatusCode(HttpStatusCode.NotFound);

responseDocument.Errors.ShouldHaveCount(1);

Expand Down Expand Up @@ -202,7 +202,7 @@ await _testContext.RunOnDatabaseAsync(async dbContext =>
(HttpResponseMessage httpResponse, Document responseDocument) = await _testContext.ExecutePostAtomicAsync<Document>(route, requestBody);

// Assert
httpResponse.Should().HaveStatusCode(HttpStatusCode.NotFound);
httpResponse.ShouldHaveStatusCode(HttpStatusCode.NotFound);

responseDocument.Errors.ShouldHaveCount(1);

Expand Down
Loading

0 comments on commit 6524e5e

Please sign in to comment.