11using JsonApiDotNetCore . Models ;
22using JsonApiDotNetCore . Services ;
3+ using System ;
34using System . Linq ;
45
56namespace 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