1
1
using JsonApiDotNetCore . Models ;
2
2
using JsonApiDotNetCore . Services ;
3
+ using System ;
3
4
using System . Linq ;
4
5
5
6
namespace JsonApiDotNetCore . Internal . Query
@@ -15,7 +16,21 @@ public abstract class BaseAttrQuery
15
16
16
17
public BaseAttrQuery ( IJsonApiContext jsonApiContext , BaseQuery baseQuery )
17
18
{
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
+
19
34
if ( baseQuery . IsAttributeOfRelationship )
20
35
{
21
36
Relationship = GetRelationship ( baseQuery . Relationship ) ;
@@ -48,8 +63,8 @@ private RelationshipAttribute GetRelationship(string propertyName)
48
63
49
64
private AttrAttribute GetAttribute ( RelationshipAttribute relationship , string attribute )
50
65
{
51
- var relatedContextExntity = _jsonApiContext . ResourceGraph . GetContextEntity ( relationship . Type ) ;
52
- return relatedContextExntity . Attributes
66
+ var relatedContextEntity = _jsonApiContext . ResourceGraph . GetContextEntity ( relationship . Type ) ;
67
+ return relatedContextEntity . Attributes
53
68
. FirstOrDefault ( a => a . Is ( attribute ) ) ;
54
69
}
55
70
}
0 commit comments