Skip to content

v3.0.0 final release branch #449

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
Nov 13, 2018
Merged
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
21 changes: 18 additions & 3 deletions src/JsonApiDotNetCore/Internal/Query/BaseAttrQuery.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using JsonApiDotNetCore.Models;
using JsonApiDotNetCore.Services;
using System;
using System.Linq;

namespace JsonApiDotNetCore.Internal.Query
Expand All @@ -15,7 +16,21 @@ public abstract class BaseAttrQuery

public BaseAttrQuery(IJsonApiContext jsonApiContext, BaseQuery baseQuery)
{
_jsonApiContext = jsonApiContext;
_jsonApiContext = jsonApiContext ?? throw new ArgumentNullException(nameof(jsonApiContext));

if(_jsonApiContext.RequestEntity == null)
throw new ArgumentException($"{nameof(IJsonApiContext)}.{nameof(_jsonApiContext.RequestEntity)} cannot be null. "
+ "This property contains the ResourceGraph node for the requested entity. "
+ "If this is a unit test, you need to mock this member. "
+ "See this issue to check the current status of improved test guidelines: "
+ "https://github.com/json-api-dotnet/JsonApiDotNetCore/issues/251", nameof(jsonApiContext));

if(_jsonApiContext.ResourceGraph == null)
throw new ArgumentException($"{nameof(IJsonApiContext)}.{nameof(_jsonApiContext.ResourceGraph)} cannot be null. "
+ "If this is a unit test, you need to construct a graph containing the resources being tested. "
+ "See this issue to check the current status of improved test guidelines: "
+ "https://github.com/json-api-dotnet/JsonApiDotNetCore/issues/251", nameof(jsonApiContext));

if (baseQuery.IsAttributeOfRelationship)
{
Relationship = GetRelationship(baseQuery.Relationship);
Expand Down Expand Up @@ -48,8 +63,8 @@ private RelationshipAttribute GetRelationship(string propertyName)

private AttrAttribute GetAttribute(RelationshipAttribute relationship, string attribute)
{
var relatedContextExntity = _jsonApiContext.ResourceGraph.GetContextEntity(relationship.Type);
return relatedContextExntity.Attributes
var relatedContextEntity = _jsonApiContext.ResourceGraph.GetContextEntity(relationship.Type);
return relatedContextEntity.Attributes
.FirstOrDefault(a => a.Is(attribute));
}
}
Expand Down