Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 73f2f33

Browse files
check for null properties and add error message
1 parent 89c38dc commit 73f2f33

File tree

1 file changed

+18
-3
lines changed

1 file changed

+18
-3
lines changed

‎src/JsonApiDotNetCore/Internal/Query/BaseAttrQuery.cs‎

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using JsonApiDotNetCore.Models;
22
using JsonApiDotNetCore.Services;
3+
using System;
34
using System.Linq;
45

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

1617
public BaseAttrQuery(IJsonApiContext jsonApiContext, BaseQuery baseQuery)
1718
{
18-
_jsonApiContext = jsonApiContext;
19+
_jsonApiContext = jsonApiContext ?? throw new ArgumentNullException(nameof(jsonApiContext));
20+
21+
if(_jsonApiContext.RequestEntity == null)
22+
throw new ArgumentException($"{nameof(IJsonApiContext)}.{nameof(_jsonApiContext.RequestEntity)} cannot be null. "
23+
+ "This property contains the ResourceGraph node for the requested entity. "
24+
+ "If this is a unit test, you need to mock this member. "
25+
+ "See this issue to check the current status of improved test guidelines: "
26+
+ "https://github.com/json-api-dotnet/JsonApiDotNetCore/issues/251", nameof(jsonApiContext));
27+
28+
if(_jsonApiContext.ResourceGraph == null)
29+
throw new ArgumentException($"{nameof(IJsonApiContext)}.{nameof(_jsonApiContext.ResourceGraph)} cannot be null. "
30+
+ "If this is a unit test, you need to construct a graph containing the resources being tested. "
31+
+ "See this issue to check the current status of improved test guidelines: "
32+
+ "https://github.com/json-api-dotnet/JsonApiDotNetCore/issues/251", nameof(jsonApiContext));
33+
1934
if (baseQuery.IsAttributeOfRelationship)
2035
{
2136
Relationship = GetRelationship(baseQuery.Relationship);
@@ -48,8 +63,8 @@ private RelationshipAttribute GetRelationship(string propertyName)
4863

4964
private AttrAttribute GetAttribute(RelationshipAttribute relationship, string attribute)
5065
{
51-
var relatedContextExntity = _jsonApiContext.ResourceGraph.GetContextEntity(relationship.Type);
52-
return relatedContextExntity.Attributes
66+
var relatedContextEntity = _jsonApiContext.ResourceGraph.GetContextEntity(relationship.Type);
67+
return relatedContextEntity.Attributes
5368
.FirstOrDefault(a => a.Is(attribute));
5469
}
5570
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /