-
-
Notifications
You must be signed in to change notification settings - Fork 5
Add example projects and tests #4
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
Changes from 1 commit
Commits
Show all changes
43 commits
Select commit
Hold shift + click to select a range
99e7d50
Add example projects and tests
mrnkr c53096a
throw proper error when fetching relationships
mrnkr b42b381
relationship creation tests
mrnkr c815c29
fix: unsupported relationships message
mrnkr c3f9dcf
test to-many relationship creation
mrnkr f348ff9
test unsupported filters
mrnkr 1b49d01
test for readonly attributes
mrnkr fc94301
suggested changes to validation and IModel implementation
mrnkr ab7fed5
cleanup last commit
mrnkr 970692b
remove unnecessary MongoDBRefs
mrnkr 3ec805d
added update relationship tests
mrnkr 0a3604e
address review comments
mrnkr ca2588d
update README.md
mrnkr 1bcef1f
address review comments
mrnkr e384b4e
bring latest changes in IntegrationTestContext
mrnkr aa140cb
Fixed handling DateTimes with ambiguous kind.
310b972
Added test for resource meta
f3e63b2
Cleanup solution: Move GettingStarted to the root and make it the def…
09456b0
Simplified code
465d720
fix README.md
mrnkr 054501b
remove unnecessary test for sparse fieldsets
mrnkr 2446ae4
remove unnecessary tests from CreateResourceTests
mrnkr a7b8713
address review comments
mrnkr c97d773
fix: custom query parameter support
mrnkr 78f058c
fix: sort on HasMany test passing
mrnkr 72430bc
added tests for relationship support in SparseFieldSetTests
mrnkr 99192c1
remove unnecessary ReadWrite tests
mrnkr afb71a5
fix: sort ids descending test
mrnkr a3742bd
cleanup sparse fieldset tests
mrnkr 5341ba9
move MongoDatabaseExtensions to test project
mrnkr 27f72f7
fix: sparse fieldset test
mrnkr e4b94bd
cleanup tests
mrnkr aae4eeb
latest requested changes minus ReadWrite tests
mrnkr 0f3272b
add missing ReadWrite tests
mrnkr a9e1bc8
Fixed failing tests
4e5bf56
address review comments
mrnkr 33add8b
Fixed: do not return relationship links in response json
2a73164
Fixed: the Task returned from Collection.InsertOneAsync was not await…
11646fc
address review comments
mrnkr 461eb32
Cleanup IoC registrations to properly detect when non-string IDs are …
4e50bc3
Removed unused types
d7c7520
Updated example
3451619
rename public static class ServiceCollectionExtensions.cs to ServiceC…
mrnkr File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
17 changes: 17 additions & 0 deletions
17
src/JsonApiDotNetCore.MongoDb/Errors/UnsupportedComparisonExpressionException.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
using System.Net; | ||
using JsonApiDotNetCore.Errors; | ||
using JsonApiDotNetCore.Serialization.Objects; | ||
|
||
namespace JsonApiDotNetCore.MongoDb.Errors | ||
{ | ||
public sealed class UnsupportedComparisonExpressionException : JsonApiException | ||
{ | ||
public UnsupportedComparisonExpressionException() | ||
: base(new Error(HttpStatusCode.BadRequest) | ||
{ | ||
Title = "Comparing attributes against each other is not supported when using MongoDB." | ||
}) | ||
{ | ||
} | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
src/JsonApiDotNetCore.MongoDb/Errors/UnsupportedRelationshipException.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
using System.Net; | ||
using JsonApiDotNetCore.Errors; | ||
using JsonApiDotNetCore.Serialization.Objects; | ||
|
||
namespace JsonApiDotNetCore.MongoDb.Errors | ||
{ | ||
public sealed class UnsupportedRelationshipException : JsonApiException | ||
bart-degreed marked this conversation as resolved.
Show resolved
Hide resolved
|
||
{ | ||
public UnsupportedRelationshipException() | ||
: base(new Error(HttpStatusCode.BadRequest) | ||
{ | ||
Title = "Relationships are not supported when using MongoDB." | ||
}) | ||
{ | ||
} | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using JsonApiDotNetCore.Configuration; | ||
using Microsoft.EntityFrameworkCore.Infrastructure; | ||
using Microsoft.EntityFrameworkCore.Metadata; | ||
|
||
namespace JsonApiDotNetCore.MongoDb.Internal | ||
bart-degreed marked this conversation as resolved.
Show resolved
Hide resolved
|
||
{ | ||
internal sealed class MongoDbModel : IModel | ||
{ | ||
private readonly IResourceContextProvider _resourceContextProvider; | ||
|
||
public object this[string name] => throw new NotImplementedException(); | ||
|
||
public MongoDbModel(IResourceContextProvider resourceContextProvider) | ||
{ | ||
_resourceContextProvider = resourceContextProvider ?? throw new ArgumentNullException(nameof(resourceContextProvider)); | ||
} | ||
|
||
public IEnumerable<IEntityType> GetEntityTypes() | ||
{ | ||
var resourceContexts = _resourceContextProvider.GetResourceContexts(); | ||
return resourceContexts.Select(resourceContext => new MongoEntityType(resourceContext, this)); | ||
} | ||
|
||
public IAnnotation FindAnnotation(string name) => throw new NotImplementedException(); | ||
public IEnumerable<IAnnotation> GetAnnotations() => throw new NotImplementedException(); | ||
public IEntityType FindEntityType(string name) => throw new NotImplementedException(); | ||
public IEntityType FindEntityType(string name, string definingNavigationName, IEntityType definingEntityType) => throw new NotImplementedException(); | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Reflection; | ||
using Microsoft.EntityFrameworkCore.Infrastructure; | ||
using Microsoft.EntityFrameworkCore.Metadata; | ||
|
||
namespace JsonApiDotNetCore.MongoDb.Internal | ||
{ | ||
internal sealed class MongoDbProperty : IProperty | ||
{ | ||
public IEntityType DeclaringEntityType { get; } | ||
public PropertyInfo PropertyInfo { get; } | ||
|
||
public string Name => throw new NotImplementedException(); | ||
public Type ClrType => throw new NotImplementedException(); | ||
public FieldInfo FieldInfo => throw new NotImplementedException(); | ||
public ITypeBase DeclaringType => throw new NotImplementedException(); | ||
public bool IsNullable => throw new NotImplementedException(); | ||
public ValueGenerated ValueGenerated => throw new NotImplementedException(); | ||
public bool IsConcurrencyToken => throw new NotImplementedException(); | ||
public object this[string name] => throw new NotImplementedException(); | ||
|
||
public MongoDbProperty(PropertyInfo propertyInfo, MongoEntityType owner) | ||
{ | ||
DeclaringEntityType = owner ?? throw new ArgumentNullException(nameof(owner)); | ||
PropertyInfo = propertyInfo ?? throw new ArgumentNullException(nameof(propertyInfo)); | ||
} | ||
|
||
public IAnnotation FindAnnotation(string name) => throw new NotImplementedException(); | ||
public IEnumerable<IAnnotation> GetAnnotations() => throw new NotImplementedException(); | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using JsonApiDotNetCore.Configuration; | ||
using Microsoft.EntityFrameworkCore.Infrastructure; | ||
using Microsoft.EntityFrameworkCore.Metadata; | ||
|
||
namespace JsonApiDotNetCore.MongoDb.Internal | ||
{ | ||
internal sealed class MongoEntityType : IEntityType | ||
{ | ||
private readonly ResourceContext _resourceContext; | ||
|
||
public IModel Model { get; } | ||
public Type ClrType => _resourceContext.ResourceType; | ||
|
||
public string Name => throw new NotImplementedException(); | ||
public IEntityType BaseType => throw new NotImplementedException(); | ||
public string DefiningNavigationName => throw new NotImplementedException(); | ||
public IEntityType DefiningEntityType => throw new NotImplementedException(); | ||
public object this[string name] => throw new NotImplementedException(); | ||
|
||
public MongoEntityType(ResourceContext resourceContext, MongoDbModel owner) | ||
{ | ||
_resourceContext = resourceContext ?? throw new ArgumentNullException(nameof(resourceContext)); | ||
Model = owner ?? throw new ArgumentNullException(nameof(owner)); | ||
} | ||
|
||
public IEnumerable<IProperty> GetProperties() | ||
{ | ||
return _resourceContext.Attributes.Select(attr => new MongoDbProperty(attr.Property, this)); | ||
} | ||
|
||
public IAnnotation FindAnnotation(string name) => throw new NotImplementedException(); | ||
public IEnumerable<IAnnotation> GetAnnotations() => throw new NotImplementedException(); | ||
public IKey FindPrimaryKey() => throw new NotImplementedException(); | ||
public IKey FindKey(IReadOnlyList<IProperty> properties) => throw new NotImplementedException(); | ||
public IEnumerable<IKey> GetKeys() => throw new NotImplementedException(); | ||
public IForeignKey FindForeignKey(IReadOnlyList<IProperty> properties, IKey principalKey, IEntityType principalEntityType) => throw new NotImplementedException(); | ||
public IEnumerable<IForeignKey> GetForeignKeys() => throw new NotImplementedException(); | ||
public IIndex FindIndex(IReadOnlyList<IProperty> properties) => throw new NotImplementedException(); | ||
public IEnumerable<IIndex> GetIndexes() => throw new NotImplementedException(); | ||
public IProperty FindProperty(string name) => throw new NotImplementedException(); | ||
public IServiceProperty FindServiceProperty(string name) => throw new NotImplementedException(); | ||
public IEnumerable<IServiceProperty> GetServiceProperties() => throw new NotImplementedException(); | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
64 changes: 64 additions & 0 deletions
64
src/JsonApiDotNetCore.MongoDb/Queries/Expressions/MongoDbQueryExpressionValidator.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
using System; | ||
using System.Linq; | ||
using System.Net; | ||
using JsonApiDotNetCore.Errors; | ||
using JsonApiDotNetCore.MongoDb.Errors; | ||
using JsonApiDotNetCore.Queries; | ||
using JsonApiDotNetCore.Queries.Expressions; | ||
using JsonApiDotNetCore.Resources.Annotations; | ||
using JsonApiDotNetCore.Serialization.Objects; | ||
|
||
namespace JsonApiDotNetCore.MongoDb.Queries.Expressions | ||
{ | ||
internal sealed class MongoDbQueryExpressionValidator : QueryExpressionRewriter<object> | ||
{ | ||
public void Validate(QueryLayer layer) | ||
{ | ||
if (layer == null) throw new ArgumentNullException(nameof(layer)); | ||
|
||
bool hasIncludes = layer.Include?.Elements.Any() == true; | ||
var hasSparseRelationshipSets = layer.Projection?.Any(pair => pair.Key is RelationshipAttribute) == true; | ||
|
||
if (hasIncludes || hasSparseRelationshipSets) | ||
{ | ||
throw new UnsupportedRelationshipException(); | ||
} | ||
|
||
ValidateExpression(layer.Filter); | ||
ValidateExpression(layer.Sort); | ||
ValidateExpression(layer.Pagination); | ||
} | ||
|
||
private void ValidateExpression(QueryExpression expression) | ||
{ | ||
if (expression != null) | ||
{ | ||
Visit(expression, null); | ||
} | ||
} | ||
|
||
public override QueryExpression VisitResourceFieldChain(ResourceFieldChainExpression expression, object argument) | ||
{ | ||
if (expression != null) | ||
{ | ||
if (expression.Fields.Count > 1 || expression.Fields.First() is RelationshipAttribute) | ||
{ | ||
throw new UnsupportedRelationshipException(); | ||
} | ||
} | ||
|
||
return base.VisitResourceFieldChain(expression, argument); | ||
} | ||
|
||
public override QueryExpression VisitComparison(ComparisonExpression expression, object argument) | ||
{ | ||
if (expression?.Left is ResourceFieldChainExpression && expression.Right is ResourceFieldChainExpression) | ||
{ | ||
// https://jira.mongodb.org/browse/CSHARP-1592 | ||
throw new UnsupportedComparisonExpressionException(); | ||
} | ||
|
||
return base.VisitComparison(expression, argument); | ||
} | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.