From 2547678479e113d2f90d703cb2b3d2a98c39c89a Mon Sep 17 00:00:00 2001 From: Jared Nance Date: Sun, 14 Oct 2018 17:56:27 -0700 Subject: [PATCH] rename contextGraph to resourceGraph --- .../JsonApiDeserializer_Benchmarks.cs | 8 +- .../JsonApiSerializer_Benchmarks.cs | 8 +- .../NoEntityFrameworkExample/Startup.cs | 2 +- .../Startup.cs | 2 +- .../Builders/ContextGraphBuilder.cs | 32 ++-- .../Builders/DocumentBuilder.cs | 22 +-- .../Configuration/JsonApiOptions.cs | 18 +- .../Controllers/BaseJsonApiController.cs | 4 +- .../Data/DefaultEntityRepository.cs | 2 +- .../IApplicationBuilderExtensions.cs | 12 +- .../IServiceCollectionExtensions.cs | 16 +- .../Extensions/ModelStateExtensions.cs | 6 +- .../Graph/ServiceDiscoveryFacade.cs | 4 +- .../Internal/ContextGraph.cs | 169 +---------------- .../Internal/Query/RelatedAttrFilterQuery.cs | 2 +- .../Internal/ResourceGraph.cs | 174 ++++++++++++++++++ .../Middleware/TypeMatchFilter.cs | 2 +- .../Models/HasOneAttribute.cs | 2 +- .../Models/ResourceDefinition.cs | 6 +- .../Serialization/JsonApiDeSerializer.cs | 14 +- .../Services/EntityResourceService.cs | 6 +- .../Services/IJsonApiContext.cs | 2 +- .../Services/JsonApiContext.cs | 10 +- .../Operations/OperationProcessorResolver.cs | 2 +- .../Processors/CreateOpProcessor.cs | 12 +- .../Operations/Processors/GetOpProcessor.cs | 18 +- .../Processors/RemoveOpProcessor.cs | 10 +- .../Processors/UpdateOpProcessor.cs | 12 +- src/JsonApiDotNetCore/api/.manifest | 86 ++++----- .../ServiceDiscoveryFacadeTests.cs | 2 +- .../Builders/ContextGraphBuilder_Tests.cs | 24 +-- .../Builders/DocumentBuilder_Tests.cs | 42 ++--- .../BaseJsonApiController_Tests.cs | 10 +- .../IServiceCollectionExtensionsTests.cs | 4 +- .../Internal/ContextGraphBuilder_Tests.cs | 20 +- .../Models/ResourceDefinitionTests.cs | 4 +- .../Serialization/JsonApiDeSerializerTests.cs | 108 +++++------ .../Serialization/JsonApiSerializerTests.cs | 24 +-- .../Services/EntityResourceService_Tests.cs | 4 +- .../OperationsProcessorResolverTests.cs | 8 +- .../Processors/CreateOpProcessorTests.cs | 4 +- 41 files changed, 466 insertions(+), 451 deletions(-) create mode 100644 src/JsonApiDotNetCore/Internal/ResourceGraph.cs diff --git a/benchmarks/Serialization/JsonApiDeserializer_Benchmarks.cs b/benchmarks/Serialization/JsonApiDeserializer_Benchmarks.cs index 5487a38666..d65f0e65c1 100644 --- a/benchmarks/Serialization/JsonApiDeserializer_Benchmarks.cs +++ b/benchmarks/Serialization/JsonApiDeserializer_Benchmarks.cs @@ -32,13 +32,13 @@ public class JsonApiDeserializer_Benchmarks { private readonly JsonApiDeSerializer _jsonApiDeSerializer; public JsonApiDeserializer_Benchmarks() { - var contextGraphBuilder = new ContextGraphBuilder(); - contextGraphBuilder.AddResource(TYPE_NAME); - var contextGraph = contextGraphBuilder.Build(); + var resourceGraphBuilder = new ResourceGraphBuilder(); + resourceGraphBuilder.AddResource(TYPE_NAME); + var resourceGraph = resourceGraphBuilder.Build(); var jsonApiContextMock = new Mock(); jsonApiContextMock.SetupAllProperties(); - jsonApiContextMock.Setup(m => m.ContextGraph).Returns(contextGraph); + jsonApiContextMock.Setup(m => m.ResourceGraph).Returns(resourceGraph); jsonApiContextMock.Setup(m => m.AttributesToUpdate).Returns(new Dictionary()); var jsonApiOptions = new JsonApiOptions(); diff --git a/benchmarks/Serialization/JsonApiSerializer_Benchmarks.cs b/benchmarks/Serialization/JsonApiSerializer_Benchmarks.cs index 3d5ef7c001..d80540434b 100644 --- a/benchmarks/Serialization/JsonApiSerializer_Benchmarks.cs +++ b/benchmarks/Serialization/JsonApiSerializer_Benchmarks.cs @@ -19,13 +19,13 @@ public class JsonApiSerializer_Benchmarks { private readonly JsonApiSerializer _jsonApiSerializer; public JsonApiSerializer_Benchmarks() { - var contextGraphBuilder = new ContextGraphBuilder(); - contextGraphBuilder.AddResource(TYPE_NAME); - var contextGraph = contextGraphBuilder.Build(); + var resourceGraphBuilder = new ResourceGraphBuilder(); + resourceGraphBuilder.AddResource(TYPE_NAME); + var resourceGraph = resourceGraphBuilder.Build(); var jsonApiContextMock = new Mock(); jsonApiContextMock.SetupAllProperties(); - jsonApiContextMock.Setup(m => m.ContextGraph).Returns(contextGraph); + jsonApiContextMock.Setup(m => m.ResourceGraph).Returns(resourceGraph); jsonApiContextMock.Setup(m => m.AttributesToUpdate).Returns(new Dictionary()); var jsonApiOptions = new JsonApiOptions(); diff --git a/src/Examples/NoEntityFrameworkExample/Startup.cs b/src/Examples/NoEntityFrameworkExample/Startup.cs index 711b54cfa3..d42c44fa42 100755 --- a/src/Examples/NoEntityFrameworkExample/Startup.cs +++ b/src/Examples/NoEntityFrameworkExample/Startup.cs @@ -35,7 +35,7 @@ public virtual IServiceProvider ConfigureServices(IServiceCollection services) services.AddJsonApi(options => { options.Namespace = "api/v1"; - options.BuildContextGraph((builder) => { + options.BuildResourceGraph((builder) => { builder.AddResource("custom-todo-items"); }); }, mvcBuilder); diff --git a/src/Examples/ResourceEntitySeparationExample/Startup.cs b/src/Examples/ResourceEntitySeparationExample/Startup.cs index 5e0f045d13..a99febfee8 100644 --- a/src/Examples/ResourceEntitySeparationExample/Startup.cs +++ b/src/Examples/ResourceEntitySeparationExample/Startup.cs @@ -49,7 +49,7 @@ public virtual IServiceProvider ConfigureServices(IServiceCollection services) options.Namespace = "api/v1"; options.DefaultPageSize = 10; options.IncludeTotalRecordCount = true; - options.BuildContextGraph((builder) => { + options.BuildResourceGraph((builder) => { builder.AddResource("courses"); builder.AddResource("departments"); builder.AddResource("students"); diff --git a/src/JsonApiDotNetCore/Builders/ContextGraphBuilder.cs b/src/JsonApiDotNetCore/Builders/ContextGraphBuilder.cs index 2eb6074b94..80ba077866 100644 --- a/src/JsonApiDotNetCore/Builders/ContextGraphBuilder.cs +++ b/src/JsonApiDotNetCore/Builders/ContextGraphBuilder.cs @@ -13,12 +13,12 @@ namespace JsonApiDotNetCore.Builders { - public interface IContextGraphBuilder + public interface IResourceGraphBuilder { /// - /// Construct the + /// Construct the /// - IContextGraph Build(); + IResourceGraph Build(); /// /// Add a json:api resource @@ -29,7 +29,7 @@ public interface IContextGraphBuilder /// If nothing is specified, the configured name formatter will be used. /// See . /// - IContextGraphBuilder AddResource(string pluralizedTypeName = null) where TResource : class, IIdentifiable; + IResourceGraphBuilder AddResource(string pluralizedTypeName = null) where TResource : class, IIdentifiable; /// /// Add a json:api resource @@ -41,7 +41,7 @@ public interface IContextGraphBuilder /// If nothing is specified, the configured name formatter will be used. /// See . /// - IContextGraphBuilder AddResource(string pluralizedTypeName = null) where TResource : class, IIdentifiable; + IResourceGraphBuilder AddResource(string pluralizedTypeName = null) where TResource : class, IIdentifiable; /// /// Add a json:api resource @@ -53,20 +53,20 @@ public interface IContextGraphBuilder /// If nothing is specified, the configured name formatter will be used. /// See . /// - IContextGraphBuilder AddResource(Type entityType, Type idType, string pluralizedTypeName = null); + IResourceGraphBuilder AddResource(Type entityType, Type idType, string pluralizedTypeName = null); /// /// Add all the models that are part of the provided /// that also implement /// /// The implementation type. - IContextGraphBuilder AddDbContext() where T : DbContext; + IResourceGraphBuilder AddDbContext() where T : DbContext; /// /// Specify the used to format resource names. /// /// Formatter used to define exposed resource names by convention. - IContextGraphBuilder UseNameFormatter(IResourceNameFormatter resourceNameFormatter); + IResourceGraphBuilder UseNameFormatter(IResourceNameFormatter resourceNameFormatter); /// /// Which links to include. Defaults to . @@ -74,7 +74,7 @@ public interface IContextGraphBuilder Link DocumentLinks { get; set; } } - public class ContextGraphBuilder : IContextGraphBuilder + public class ResourceGraphBuilder : IResourceGraphBuilder { private List _entities = new List(); private List _validationResults = new List(); @@ -83,25 +83,25 @@ public class ContextGraphBuilder : IContextGraphBuilder public Link DocumentLinks { get; set; } = Link.All; - public IContextGraph Build() + public IResourceGraph Build() { // this must be done at build so that call order doesn't matter _entities.ForEach(e => e.Links = GetLinkFlags(e.EntityType)); - var graph = new ContextGraph(_entities, _usesDbContext, _validationResults); + var graph = new ResourceGraph(_entities, _usesDbContext, _validationResults); return graph; } /// - public IContextGraphBuilder AddResource(string pluralizedTypeName = null) where TResource : class, IIdentifiable + public IResourceGraphBuilder AddResource(string pluralizedTypeName = null) where TResource : class, IIdentifiable => AddResource(pluralizedTypeName); /// - public IContextGraphBuilder AddResource(string pluralizedTypeName = null) where TResource : class, IIdentifiable + public IResourceGraphBuilder AddResource(string pluralizedTypeName = null) where TResource : class, IIdentifiable => AddResource(typeof(TResource), typeof(TId), pluralizedTypeName); /// - public IContextGraphBuilder AddResource(Type entityType, Type idType, string pluralizedTypeName = null) + public IResourceGraphBuilder AddResource(Type entityType, Type idType, string pluralizedTypeName = null) { AssertEntityIsNotAlreadyDefined(entityType); @@ -222,7 +222,7 @@ protected virtual Type GetRelationshipType(RelationshipAttribute relation, Prope private Type GetResourceDefinitionType(Type entityType) => typeof(ResourceDefinition<>).MakeGenericType(entityType); /// - public IContextGraphBuilder AddDbContext() where T : DbContext + public IResourceGraphBuilder AddDbContext() where T : DbContext { _usesDbContext = true; @@ -290,7 +290,7 @@ private void AssertEntityIsNotAlreadyDefined(Type entityType) } /// - public IContextGraphBuilder UseNameFormatter(IResourceNameFormatter resourceNameFormatter) + public IResourceGraphBuilder UseNameFormatter(IResourceNameFormatter resourceNameFormatter) { _resourceNameFormatter = resourceNameFormatter; return this; diff --git a/src/JsonApiDotNetCore/Builders/DocumentBuilder.cs b/src/JsonApiDotNetCore/Builders/DocumentBuilder.cs index c6abed49a7..2d2c978179 100644 --- a/src/JsonApiDotNetCore/Builders/DocumentBuilder.cs +++ b/src/JsonApiDotNetCore/Builders/DocumentBuilder.cs @@ -12,7 +12,7 @@ namespace JsonApiDotNetCore.Builders public class DocumentBuilder : IDocumentBuilder { private readonly IJsonApiContext _jsonApiContext; - private readonly IContextGraph _contextGraph; + private readonly IResourceGraph _resourceGraph; private readonly IRequestMeta _requestMeta; private readonly DocumentBuilderOptions _documentBuilderOptions; private readonly IScopedServiceProvider _scopedServiceProvider; @@ -24,7 +24,7 @@ public DocumentBuilder( IScopedServiceProvider scopedServiceProvider = null) { _jsonApiContext = jsonApiContext; - _contextGraph = jsonApiContext.ContextGraph; + _resourceGraph = jsonApiContext.ResourceGraph; _requestMeta = requestMeta; _documentBuilderOptions = documentBuilderOptionsProvider?.GetDocumentBuilderOptions() ?? new DocumentBuilderOptions(); _scopedServiceProvider = scopedServiceProvider; @@ -32,7 +32,7 @@ public DocumentBuilder( public Document Build(IIdentifiable entity) { - var contextEntity = _contextGraph.GetContextEntity(entity.GetType()); + var contextEntity = _resourceGraph.GetContextEntity(entity.GetType()); var resourceDefinition = _scopedServiceProvider?.GetService(contextEntity.ResourceType) as IResourceDefinition; var document = new Document @@ -52,7 +52,7 @@ public Document Build(IIdentifiable entity) public Documents Build(IEnumerable entities) { var entityType = entities.GetElementType(); - var contextEntity = _contextGraph.GetContextEntity(entityType); + var contextEntity = _resourceGraph.GetContextEntity(entityType); var resourceDefinition = _scopedServiceProvider?.GetService(contextEntity.ResourceType) as IResourceDefinition; var enumeratedEntities = entities as IList ?? entities.ToList(); @@ -179,7 +179,7 @@ private RelationshipData GetRelationshipData(RelationshipAttribute attr, Context } // this only includes the navigation property, we need to actually check the navigation property Id - var navigationEntity = _jsonApiContext.ContextGraph.GetRelationshipValue(entity, attr); + var navigationEntity = _jsonApiContext.ResourceGraph.GetRelationshipValue(entity, attr); if (navigationEntity == null) relationshipData.SingleData = attr.IsHasOne ? GetIndependentRelationshipIdentifier((HasOneAttribute)attr, entity) @@ -217,7 +217,7 @@ private List IncludeRelationshipChain( if(relationship == null) throw new JsonApiException(400, $"{parentEntity.EntityName} does not contain relationship {requestedRelationship}"); - var navigationEntity = _jsonApiContext.ContextGraph.GetRelationshipValue(parentResource, relationship); + var navigationEntity = _jsonApiContext.ResourceGraph.GetRelationshipValue(parentResource, relationship); if (navigationEntity is IEnumerable hasManyNavigationEntity) { foreach (IIdentifiable includedEntity in hasManyNavigationEntity) @@ -240,7 +240,7 @@ private List IncludeSingleResourceRelationships( { if (relationshipChainIndex < relationshipChain.Length) { - var nextContextEntity = _jsonApiContext.ContextGraph.GetContextEntity(relationship.Type); + var nextContextEntity = _jsonApiContext.ResourceGraph.GetContextEntity(relationship.Type); var resource = (IIdentifiable)navigationEntity; // recursive call if (relationshipChainIndex < relationshipChain.Length - 1) @@ -271,7 +271,7 @@ private ResourceObject GetIncludedEntity(IIdentifiable entity) { if (entity == null) return null; - var contextEntity = _jsonApiContext.ContextGraph.GetContextEntity(entity.GetType()); + var contextEntity = _jsonApiContext.ResourceGraph.GetContextEntity(entity.GetType()); var resourceDefinition = _scopedServiceProvider.GetService(contextEntity.ResourceType) as IResourceDefinition; var data = GetData(contextEntity, entity, resourceDefinition); @@ -296,7 +296,7 @@ private List GetRelationships(IEnumerable enti // so, we just lookup the type of the first entity on the graph // this is better than trying to get it from the generic parameter since it could // be less specific than what is registered on the graph (e.g. IEnumerable) - typeName = typeName ?? _jsonApiContext.ContextGraph.GetContextEntity(entity.GetType()).EntityName; + typeName = typeName ?? _jsonApiContext.ResourceGraph.GetContextEntity(entity.GetType()).EntityName; relationships.Add(new ResourceIdentifierObject { Type = typeName, @@ -309,7 +309,7 @@ private List GetRelationships(IEnumerable enti private ResourceIdentifierObject GetRelationship(object entity) { var objType = entity.GetType(); - var contextEntity = _jsonApiContext.ContextGraph.GetContextEntity(objType); + var contextEntity = _jsonApiContext.ResourceGraph.GetContextEntity(objType); if (entity is IIdentifiable identifiableEntity) return new ResourceIdentifierObject @@ -327,7 +327,7 @@ private ResourceIdentifierObject GetIndependentRelationshipIdentifier(HasOneAttr if (independentRelationshipIdentifier == null) return null; - var relatedContextEntity = _jsonApiContext.ContextGraph.GetContextEntity(hasOne.Type); + var relatedContextEntity = _jsonApiContext.ResourceGraph.GetContextEntity(hasOne.Type); if (relatedContextEntity == null) // TODO: this should probably be a debug log at minimum return null; diff --git a/src/JsonApiDotNetCore/Configuration/JsonApiOptions.cs b/src/JsonApiDotNetCore/Configuration/JsonApiOptions.cs index e4d61e3864..80dfdfa572 100644 --- a/src/JsonApiDotNetCore/Configuration/JsonApiOptions.cs +++ b/src/JsonApiDotNetCore/Configuration/JsonApiOptions.cs @@ -77,7 +77,7 @@ public class JsonApiOptions /// /// The graph of all resources exposed by this application. /// - public IContextGraph ContextGraph { get; set; } + public IResourceGraph ResourceGraph { get; set; } /// /// Use relative links for all resources. @@ -158,28 +158,28 @@ public IContractResolver JsonContractResolver ContractResolver = new DasherizedResolver() }; - public void BuildContextGraph(Action builder) where TContext : DbContext + public void BuildResourceGraph(Action builder) where TContext : DbContext { - BuildContextGraph(builder); + BuildResourceGraph(builder); - ContextGraphBuilder.AddDbContext(); + ResourceGraphBuilder.AddDbContext(); - ContextGraph = ContextGraphBuilder.Build(); + ResourceGraph = ResourceGraphBuilder.Build(); } - public void BuildContextGraph(Action builder) + public void BuildResourceGraph(Action builder) { if (builder == null) return; - builder(ContextGraphBuilder); + builder(ResourceGraphBuilder); - ContextGraph = ContextGraphBuilder.Build(); + ResourceGraph = ResourceGraphBuilder.Build(); } public void EnableExtension(JsonApiExtension extension) => EnabledExtensions.Add(extension); - internal IContextGraphBuilder ContextGraphBuilder { get; } = new ContextGraphBuilder(); + internal IResourceGraphBuilder ResourceGraphBuilder { get; } = new ResourceGraphBuilder(); internal List EnabledExtensions { get; set; } = new List(); } } diff --git a/src/JsonApiDotNetCore/Controllers/BaseJsonApiController.cs b/src/JsonApiDotNetCore/Controllers/BaseJsonApiController.cs index 0423b76ac0..93fd4826e2 100644 --- a/src/JsonApiDotNetCore/Controllers/BaseJsonApiController.cs +++ b/src/JsonApiDotNetCore/Controllers/BaseJsonApiController.cs @@ -156,7 +156,7 @@ public virtual async Task PostAsync([FromBody] T entity) return Forbidden(); if (_jsonApiContext.Options.ValidateModelState && !ModelState.IsValid) - return UnprocessableEntity(ModelState.ConvertToErrorCollection(_jsonApiContext.ContextGraph)); + return UnprocessableEntity(ModelState.ConvertToErrorCollection(_jsonApiContext.ResourceGraph)); entity = await _create.CreateAsync(entity); @@ -171,7 +171,7 @@ public virtual async Task PatchAsync(TId id, [FromBody] T entity) return UnprocessableEntity(); if (_jsonApiContext.Options.ValidateModelState && !ModelState.IsValid) - return UnprocessableEntity(ModelState.ConvertToErrorCollection(_jsonApiContext.ContextGraph)); + return UnprocessableEntity(ModelState.ConvertToErrorCollection(_jsonApiContext.ResourceGraph)); var updatedEntity = await _update.UpdateAsync(id, entity); diff --git a/src/JsonApiDotNetCore/Data/DefaultEntityRepository.cs b/src/JsonApiDotNetCore/Data/DefaultEntityRepository.cs index c0c7c93192..b94a39bb37 100644 --- a/src/JsonApiDotNetCore/Data/DefaultEntityRepository.cs +++ b/src/JsonApiDotNetCore/Data/DefaultEntityRepository.cs @@ -317,7 +317,7 @@ public virtual IQueryable Include(IQueryable entities, string : $"{internalRelationshipPath}.{relationship.RelationshipPath}"; if(i < relationshipChain.Length) - entity = _jsonApiContext.ContextGraph.GetContextEntity(relationship.Type); + entity = _jsonApiContext.ResourceGraph.GetContextEntity(relationship.Type); } return entities.Include(internalRelationshipPath); diff --git a/src/JsonApiDotNetCore/Extensions/IApplicationBuilderExtensions.cs b/src/JsonApiDotNetCore/Extensions/IApplicationBuilderExtensions.cs index 996d7eb9de..20cee086d6 100644 --- a/src/JsonApiDotNetCore/Extensions/IApplicationBuilderExtensions.cs +++ b/src/JsonApiDotNetCore/Extensions/IApplicationBuilderExtensions.cs @@ -14,7 +14,7 @@ public static class IApplicationBuilderExtensions public static IApplicationBuilder UseJsonApi(this IApplicationBuilder app, bool useMvc = true) { DisableDetailedErrorsIfProduction(app); - LogContextGraphValidations(app); + LogResourceGraphValidations(app); app.UseMiddleware(); @@ -35,14 +35,14 @@ private static void DisableDetailedErrorsIfProduction(IApplicationBuilder app) } } - private static void LogContextGraphValidations(IApplicationBuilder app) + private static void LogResourceGraphValidations(IApplicationBuilder app) { - var logger = app.ApplicationServices.GetService(typeof(ILogger)) as ILogger; - var contextGraph = app.ApplicationServices.GetService(typeof(IContextGraph)) as ContextGraph; + var logger = app.ApplicationServices.GetService(typeof(ILogger)) as ILogger; + var resourceGraph = app.ApplicationServices.GetService(typeof(IResourceGraph)) as ResourceGraph; - if (logger != null && contextGraph != null) + if (logger != null && resourceGraph != null) { - contextGraph.ValidationResults.ForEach((v) => + resourceGraph.ValidationResults.ForEach((v) => logger.Log( v.LogLevel, new EventId(), diff --git a/src/JsonApiDotNetCore/Extensions/IServiceCollectionExtensions.cs b/src/JsonApiDotNetCore/Extensions/IServiceCollectionExtensions.cs index 74168c8b0d..d1c1de352c 100644 --- a/src/JsonApiDotNetCore/Extensions/IServiceCollectionExtensions.cs +++ b/src/JsonApiDotNetCore/Extensions/IServiceCollectionExtensions.cs @@ -48,7 +48,7 @@ public static IServiceCollection AddJsonApi( { var config = new JsonApiOptions(); options(config); - config.BuildContextGraph(builder => builder.AddDbContext()); + config.BuildResourceGraph(builder => builder.AddDbContext()); mvcBuilder.AddMvcOptions(opt => AddMvcOptions(opt, config)); @@ -67,7 +67,7 @@ public static IServiceCollection AddJsonApi( if(autoDiscover != null) { - var facade = new ServiceDiscoveryFacade(services, config.ContextGraphBuilder); + var facade = new ServiceDiscoveryFacade(services, config.ResourceGraphBuilder); autoDiscover(facade); } @@ -88,8 +88,8 @@ public static void AddJsonApiInternals( this IServiceCollection services, JsonApiOptions jsonApiOptions) where TContext : DbContext { - if (jsonApiOptions.ContextGraph == null) - jsonApiOptions.BuildContextGraph(null); + if (jsonApiOptions.ResourceGraph == null) + jsonApiOptions.BuildResourceGraph(null); services.AddScoped>(); @@ -100,10 +100,10 @@ public static void AddJsonApiInternals( this IServiceCollection services, JsonApiOptions jsonApiOptions) { - if (jsonApiOptions.ContextGraph == null) - jsonApiOptions.ContextGraph = jsonApiOptions.ContextGraphBuilder.Build(); + if (jsonApiOptions.ResourceGraph == null) + jsonApiOptions.ResourceGraph = jsonApiOptions.ResourceGraphBuilder.Build(); - if (jsonApiOptions.ContextGraph.UsesDbContext == false) + if (jsonApiOptions.ResourceGraph.UsesDbContext == false) { services.AddScoped(); services.AddSingleton(new DbContextOptionsBuilder().Options); @@ -137,7 +137,7 @@ public static void AddJsonApiInternals( services.AddScoped(typeof(IResourceService<,>), typeof(EntityResourceService<,>)); services.AddSingleton(jsonApiOptions); - services.AddSingleton(jsonApiOptions.ContextGraph); + services.AddSingleton(jsonApiOptions.ResourceGraph); services.AddScoped(); services.AddSingleton(); services.AddScoped(); diff --git a/src/JsonApiDotNetCore/Extensions/ModelStateExtensions.cs b/src/JsonApiDotNetCore/Extensions/ModelStateExtensions.cs index 43c33c21f2..4b31a7f021 100644 --- a/src/JsonApiDotNetCore/Extensions/ModelStateExtensions.cs +++ b/src/JsonApiDotNetCore/Extensions/ModelStateExtensions.cs @@ -7,7 +7,7 @@ namespace JsonApiDotNetCore.Extensions { public static class ModelStateExtensions { - [Obsolete("Use Generic Method ConvertToErrorCollection(IContextGraph contextGraph) instead for full validation errors")] + [Obsolete("Use Generic Method ConvertToErrorCollection(IResourceGraph resourceGraph) instead for full validation errors")] public static ErrorCollection ConvertToErrorCollection(this ModelStateDictionary modelState) { ErrorCollection collection = new ErrorCollection(); @@ -27,7 +27,7 @@ public static ErrorCollection ConvertToErrorCollection(this ModelStateDictionary return collection; } - public static ErrorCollection ConvertToErrorCollection(this ModelStateDictionary modelState, IContextGraph contextGraph) + public static ErrorCollection ConvertToErrorCollection(this ModelStateDictionary modelState, IResourceGraph resourceGraph) { ErrorCollection collection = new ErrorCollection(); foreach (var entry in modelState) @@ -35,7 +35,7 @@ public static ErrorCollection ConvertToErrorCollection(this ModelStateDiction if (entry.Value.Errors.Any() == false) continue; - var attrName = contextGraph.GetPublicAttributeName(entry.Key); + var attrName = resourceGraph.GetPublicAttributeName(entry.Key); foreach (var modelError in entry.Value.Errors) { diff --git a/src/JsonApiDotNetCore/Graph/ServiceDiscoveryFacade.cs b/src/JsonApiDotNetCore/Graph/ServiceDiscoveryFacade.cs index f8a1300c7f..99c3845108 100644 --- a/src/JsonApiDotNetCore/Graph/ServiceDiscoveryFacade.cs +++ b/src/JsonApiDotNetCore/Graph/ServiceDiscoveryFacade.cs @@ -48,12 +48,12 @@ public class ServiceDiscoveryFacade }; private readonly IServiceCollection _services; - private readonly IContextGraphBuilder _graphBuilder; + private readonly IResourceGraphBuilder _graphBuilder; private readonly List _identifiables = new List(); public ServiceDiscoveryFacade( IServiceCollection services, - IContextGraphBuilder graphBuilder) + IResourceGraphBuilder graphBuilder) { _services = services; _graphBuilder = graphBuilder; diff --git a/src/JsonApiDotNetCore/Internal/ContextGraph.cs b/src/JsonApiDotNetCore/Internal/ContextGraph.cs index 3ea6758365..18aab6646e 100644 --- a/src/JsonApiDotNetCore/Internal/ContextGraph.cs +++ b/src/JsonApiDotNetCore/Internal/ContextGraph.cs @@ -6,169 +6,10 @@ namespace JsonApiDotNetCore.Internal { - public interface IContextGraph - { - /// - /// Gets the value of the navigation property, defined by the relationshipName, - /// on the provided instance. - /// - /// The resource instance - /// The navigation property name. - /// - /// - /// _graph.GetRelationship(todoItem, nameof(TodoItem.Owner)); - /// - /// - /// - /// In the case of a `HasManyThrough` relationship, it will not traverse the relationship - /// and will instead return the value of the shadow property (e.g. Articles.Tags). - /// If you want to traverse the relationship, you should use . - /// - object GetRelationship(TParent resource, string propertyName); + /// + [Obsolete("Use IResourceGraph instead.")] + public interface IContextGraph : IResourceGraph { } - /// - /// Gets the value of the navigation property (defined by the ) - /// on the provided instance. - /// In the case of `HasManyThrough` relationships, it will traverse the through entity and return the - /// value of the relationship on the other side of a join entity (e.g. Articles.ArticleTags.Tag). - /// - /// The resource instance - /// The attribute used to define the relationship. - /// - /// - /// _graph.GetRelationshipValue(todoItem, nameof(TodoItem.Owner)); - /// - /// - object GetRelationshipValue(TParent resource, RelationshipAttribute relationship) where TParent : IIdentifiable; - - /// - /// Get the internal navigation property name for the specified public - /// relationship name. - /// - /// The public relationship name specified by a or - /// - /// - /// _graph.GetRelationshipName<TodoItem>("achieved-date"); - /// // returns "AchievedDate" - /// - /// - string GetRelationshipName(string relationshipName); - - /// - /// Get the resource metadata by the DbSet property name - /// - ContextEntity GetContextEntity(string dbSetName); - - /// - /// Get the resource metadata by the resource type - /// - ContextEntity GetContextEntity(Type entityType); - - /// - /// Get the public attribute name for a type based on the internal attribute name. - /// - /// The internal attribute name for a . - string GetPublicAttributeName(string internalAttributeName); - - /// - /// Was built against an EntityFrameworkCore DbContext ? - /// - bool UsesDbContext { get; } - } - - public class ContextGraph : IContextGraph - { - internal List Entities { get; } - internal List ValidationResults { get; } - internal static IContextGraph Instance { get; set; } - - public ContextGraph() { } - public ContextGraph(List entities, bool usesDbContext) - { - Entities = entities; - UsesDbContext = usesDbContext; - ValidationResults = new List(); - Instance = this; - } - - // eventually, this is the planned public constructor - // to avoid breaking changes, we will be leaving the original constructor in place - // until the context graph validation process is completed - // you can track progress on this issue here: https://github.com/json-api-dotnet/JsonApiDotNetCore/issues/170 - internal ContextGraph(List entities, bool usesDbContext, List validationResults) - { - Entities = entities; - UsesDbContext = usesDbContext; - ValidationResults = validationResults; - Instance = this; - } - - /// - public bool UsesDbContext { get; } - - /// - public ContextEntity GetContextEntity(string entityName) - => Entities.SingleOrDefault(e => string.Equals(e.EntityName, entityName, StringComparison.OrdinalIgnoreCase)); - - /// - public ContextEntity GetContextEntity(Type entityType) - => Entities.SingleOrDefault(e => e.EntityType == entityType); - - /// - public object GetRelationship(TParent entity, string relationshipName) - { - var parentEntityType = entity.GetType(); - - var navigationProperty = parentEntityType - .GetProperties() - .SingleOrDefault(p => string.Equals(p.Name, relationshipName, StringComparison.OrdinalIgnoreCase)); - - if (navigationProperty == null) - throw new JsonApiException(400, $"{parentEntityType} does not contain a relationship named {relationshipName}"); - - return navigationProperty.GetValue(entity); - } - - public object GetRelationshipValue(TParent resource, RelationshipAttribute relationship) where TParent : IIdentifiable - { - if(relationship is HasManyThroughAttribute hasManyThroughRelationship) - { - return GetHasManyThrough(resource, hasManyThroughRelationship); - } - - return GetRelationship(resource, relationship.InternalRelationshipName); - } - - private IEnumerable GetHasManyThrough(IIdentifiable parent, HasManyThroughAttribute hasManyThrough) - { - var throughProperty = GetRelationship(parent, hasManyThrough.InternalThroughName); - if (throughProperty is IEnumerable hasManyNavigationEntity) - { - foreach (var includedEntity in hasManyNavigationEntity) - { - var targetValue = hasManyThrough.RightProperty.GetValue(includedEntity) as IIdentifiable; - yield return targetValue; - } - } - } - - /// - public string GetRelationshipName(string relationshipName) - { - var entityType = typeof(TParent); - return Entities - .SingleOrDefault(e => e.EntityType == entityType) - ?.Relationships - .SingleOrDefault(r => r.Is(relationshipName)) - ?.InternalRelationshipName; - } - - public string GetPublicAttributeName(string internalAttributeName) - { - return GetContextEntity(typeof(TParent)) - .Attributes - .SingleOrDefault(a => a.InternalAttributeName == internalAttributeName)? - .PublicAttributeName; - } - } + [Obsolete("Use ResourceGraph instead.")] + public class ContextGraph : ResourceGraph { } } diff --git a/src/JsonApiDotNetCore/Internal/Query/RelatedAttrFilterQuery.cs b/src/JsonApiDotNetCore/Internal/Query/RelatedAttrFilterQuery.cs index 9b117c0913..f01865adf4 100644 --- a/src/JsonApiDotNetCore/Internal/Query/RelatedAttrFilterQuery.cs +++ b/src/JsonApiDotNetCore/Internal/Query/RelatedAttrFilterQuery.cs @@ -42,7 +42,7 @@ private RelationshipAttribute GetRelationship(string propertyName) private AttrAttribute GetAttribute(RelationshipAttribute relationship, string attribute) { - var relatedContextExntity = _jsonApiContext.ContextGraph.GetContextEntity(relationship.Type); + var relatedContextExntity = _jsonApiContext.ResourceGraph.GetContextEntity(relationship.Type); return relatedContextExntity.Attributes .FirstOrDefault(a => a.Is(attribute)); } diff --git a/src/JsonApiDotNetCore/Internal/ResourceGraph.cs b/src/JsonApiDotNetCore/Internal/ResourceGraph.cs new file mode 100644 index 0000000000..1d517cfd16 --- /dev/null +++ b/src/JsonApiDotNetCore/Internal/ResourceGraph.cs @@ -0,0 +1,174 @@ +using System; +using System.Collections; +using System.Collections.Generic; +using System.Linq; +using JsonApiDotNetCore.Models; + +namespace JsonApiDotNetCore.Internal +{ + public interface IResourceGraph + { + /// + /// Gets the value of the navigation property, defined by the relationshipName, + /// on the provided instance. + /// + /// The resource instance + /// The navigation property name. + /// + /// + /// _graph.GetRelationship(todoItem, nameof(TodoItem.Owner)); + /// + /// + /// + /// In the case of a `HasManyThrough` relationship, it will not traverse the relationship + /// and will instead return the value of the shadow property (e.g. Articles.Tags). + /// If you want to traverse the relationship, you should use . + /// + object GetRelationship(TParent resource, string propertyName); + + /// + /// Gets the value of the navigation property (defined by the ) + /// on the provided instance. + /// In the case of `HasManyThrough` relationships, it will traverse the through entity and return the + /// value of the relationship on the other side of a join entity (e.g. Articles.ArticleTags.Tag). + /// + /// The resource instance + /// The attribute used to define the relationship. + /// + /// + /// _graph.GetRelationshipValue(todoItem, nameof(TodoItem.Owner)); + /// + /// + object GetRelationshipValue(TParent resource, RelationshipAttribute relationship) where TParent : IIdentifiable; + + /// + /// Get the internal navigation property name for the specified public + /// relationship name. + /// + /// The public relationship name specified by a or + /// + /// + /// _graph.GetRelationshipName<TodoItem>("achieved-date"); + /// // returns "AchievedDate" + /// + /// + string GetRelationshipName(string relationshipName); + + /// + /// Get the resource metadata by the DbSet property name + /// + ContextEntity GetContextEntity(string dbSetName); + + /// + /// Get the resource metadata by the resource type + /// + ContextEntity GetContextEntity(Type entityType); + + /// + /// Get the public attribute name for a type based on the internal attribute name. + /// + /// The internal attribute name for a . + string GetPublicAttributeName(string internalAttributeName); + + /// + /// Was built against an EntityFrameworkCore DbContext ? + /// + bool UsesDbContext { get; } + } + + public class ResourceGraph : IResourceGraph + { + internal List Entities { get; } + internal List ValidationResults { get; } + internal static IResourceGraph Instance { get; set; } + + public ResourceGraph() { } + public ResourceGraph(List entities, bool usesDbContext) + { + Entities = entities; + UsesDbContext = usesDbContext; + ValidationResults = new List(); + Instance = this; + } + + // eventually, this is the planned public constructor + // to avoid breaking changes, we will be leaving the original constructor in place + // until the context graph validation process is completed + // you can track progress on this issue here: https://github.com/json-api-dotnet/JsonApiDotNetCore/issues/170 + internal ResourceGraph(List entities, bool usesDbContext, List validationResults) + { + Entities = entities; + UsesDbContext = usesDbContext; + ValidationResults = validationResults; + Instance = this; + } + + /// + public bool UsesDbContext { get; } + + /// + public ContextEntity GetContextEntity(string entityName) + => Entities.SingleOrDefault(e => string.Equals(e.EntityName, entityName, StringComparison.OrdinalIgnoreCase)); + + /// + public ContextEntity GetContextEntity(Type entityType) + => Entities.SingleOrDefault(e => e.EntityType == entityType); + + /// + public object GetRelationship(TParent entity, string relationshipName) + { + var parentEntityType = entity.GetType(); + + var navigationProperty = parentEntityType + .GetProperties() + .SingleOrDefault(p => string.Equals(p.Name, relationshipName, StringComparison.OrdinalIgnoreCase)); + + if (navigationProperty == null) + throw new JsonApiException(400, $"{parentEntityType} does not contain a relationship named {relationshipName}"); + + return navigationProperty.GetValue(entity); + } + + public object GetRelationshipValue(TParent resource, RelationshipAttribute relationship) where TParent : IIdentifiable + { + if(relationship is HasManyThroughAttribute hasManyThroughRelationship) + { + return GetHasManyThrough(resource, hasManyThroughRelationship); + } + + return GetRelationship(resource, relationship.InternalRelationshipName); + } + + private IEnumerable GetHasManyThrough(IIdentifiable parent, HasManyThroughAttribute hasManyThrough) + { + var throughProperty = GetRelationship(parent, hasManyThrough.InternalThroughName); + if (throughProperty is IEnumerable hasManyNavigationEntity) + { + foreach (var includedEntity in hasManyNavigationEntity) + { + var targetValue = hasManyThrough.RightProperty.GetValue(includedEntity) as IIdentifiable; + yield return targetValue; + } + } + } + + /// + public string GetRelationshipName(string relationshipName) + { + var entityType = typeof(TParent); + return Entities + .SingleOrDefault(e => e.EntityType == entityType) + ?.Relationships + .SingleOrDefault(r => r.Is(relationshipName)) + ?.InternalRelationshipName; + } + + public string GetPublicAttributeName(string internalAttributeName) + { + return GetContextEntity(typeof(TParent)) + .Attributes + .SingleOrDefault(a => a.InternalAttributeName == internalAttributeName)? + .PublicAttributeName; + } + } +} diff --git a/src/JsonApiDotNetCore/Middleware/TypeMatchFilter.cs b/src/JsonApiDotNetCore/Middleware/TypeMatchFilter.cs index 5c061babe6..66a5103ce4 100644 --- a/src/JsonApiDotNetCore/Middleware/TypeMatchFilter.cs +++ b/src/JsonApiDotNetCore/Middleware/TypeMatchFilter.cs @@ -29,7 +29,7 @@ public void OnActionExecuting(ActionExecutingContext context) if (deserializedType != null && targetType != null && deserializedType != targetType) { - var expectedJsonApiResource = _jsonApiContext.ContextGraph.GetContextEntity(targetType); + var expectedJsonApiResource = _jsonApiContext.ResourceGraph.GetContextEntity(targetType); throw new JsonApiException(409, $"Cannot '{context.HttpContext.Request.Method}' type '{_jsonApiContext.RequestEntity.EntityName}' " diff --git a/src/JsonApiDotNetCore/Models/HasOneAttribute.cs b/src/JsonApiDotNetCore/Models/HasOneAttribute.cs index 4c145727eb..7e3cc6fb1a 100644 --- a/src/JsonApiDotNetCore/Models/HasOneAttribute.cs +++ b/src/JsonApiDotNetCore/Models/HasOneAttribute.cs @@ -61,7 +61,7 @@ public override void SetValue(object resource, object newValue) } // HACK: this will likely require boxing - // we should be able to move some of the reflection into the ContextGraphBuilder + // we should be able to move some of the reflection into the ResourceGraphBuilder /// /// Gets the value of the independent identifier (e.g. Article.AuthorId) /// diff --git a/src/JsonApiDotNetCore/Models/ResourceDefinition.cs b/src/JsonApiDotNetCore/Models/ResourceDefinition.cs index c9cffb7062..2ce960e875 100644 --- a/src/JsonApiDotNetCore/Models/ResourceDefinition.cs +++ b/src/JsonApiDotNetCore/Models/ResourceDefinition.cs @@ -22,7 +22,7 @@ public interface IResourceDefinition /// The resource type public class ResourceDefinition : IResourceDefinition where T : class, IIdentifiable { - private readonly IContextGraph _graph; + private readonly IResourceGraph _graph; private readonly ContextEntity _contextEntity; internal readonly bool _instanceAttrsAreSpecified; @@ -31,8 +31,8 @@ public class ResourceDefinition : IResourceDefinition where T : class, IIdent public ResourceDefinition() { - _graph = ContextGraph.Instance; - _contextEntity = ContextGraph.Instance.GetContextEntity(typeof(T)); + _graph = ResourceGraph.Instance; + _contextEntity = ResourceGraph.Instance.GetContextEntity(typeof(T)); _instanceAttrsAreSpecified = InstanceOutputAttrsAreSpecified(); } diff --git a/src/JsonApiDotNetCore/Serialization/JsonApiDeSerializer.cs b/src/JsonApiDotNetCore/Serialization/JsonApiDeSerializer.cs index 33a3f2e119..9c46c22500 100644 --- a/src/JsonApiDotNetCore/Serialization/JsonApiDeSerializer.cs +++ b/src/JsonApiDotNetCore/Serialization/JsonApiDeSerializer.cs @@ -116,10 +116,10 @@ public object DocumentToObject(ResourceObject data, List include if (data == null) throw new JsonApiException(422, "Failed to deserialize document as json:api."); - var contextEntity = _jsonApiContext.ContextGraph.GetContextEntity(data.Type?.ToString()); + var contextEntity = _jsonApiContext.ResourceGraph.GetContextEntity(data.Type?.ToString()); _jsonApiContext.RequestEntity = contextEntity ?? throw new JsonApiException(400, message: $"This API does not contain a json:api resource named '{data.Type}'.", - detail: "This resource is not registered on the ContextGraph. " + detail: "This resource is not registered on the ResourceGraph. " + "If you are using Entity Framework, make sure the DbSet matches the expected resource name. " + "If you have manually registered the resource, check that the call to AddResource correctly sets the public name."); @@ -218,12 +218,12 @@ private object SetHasOneRelationship(object entity, if(included != null) { var navigationPropertyValue = attr.GetValue(entity); - var contextGraphEntity = _jsonApiContext.ContextGraph.GetContextEntity(attr.Type); - if(navigationPropertyValue != null && contextGraphEntity != null) + var resourceGraphEntity = _jsonApiContext.ResourceGraph.GetContextEntity(attr.Type); + if(navigationPropertyValue != null && resourceGraphEntity != null) { var includedResource = included.SingleOrDefault(r => r.Type == rio.Type && r.Id == rio.Id); if(includedResource != null) - SetRelationships(navigationPropertyValue, contextGraphEntity, includedResource.Relationships, included); + SetRelationships(navigationPropertyValue, resourceGraphEntity, includedResource.Relationships, included); } } @@ -304,7 +304,7 @@ private object SetHasManyRelationship(object entity, private IIdentifiable GetIncludedRelationship(ResourceIdentifierObject relatedResourceIdentifier, List includedResources, RelationshipAttribute relationshipAttr) { - // at this point we can be sure the relationshipAttr.Type is IIdentifiable because we were able to successfully build the ContextGraph + // at this point we can be sure the relationshipAttr.Type is IIdentifiable because we were able to successfully build the ResourceGraph var relatedInstance = relationshipAttr.Type.New(); relatedInstance.StringId = relatedResourceIdentifier.Id; @@ -316,7 +316,7 @@ private IIdentifiable GetIncludedRelationship(ResourceIdentifierObject relatedRe if (includedResource == null) return relatedInstance; - var contextEntity = _jsonApiContext.ContextGraph.GetContextEntity(relationshipAttr.Type); + var contextEntity = _jsonApiContext.ResourceGraph.GetContextEntity(relationshipAttr.Type); if (contextEntity == null) throw new JsonApiException(400, $"Included type '{relationshipAttr.Type}' is not a registered json:api resource."); diff --git a/src/JsonApiDotNetCore/Services/EntityResourceService.cs b/src/JsonApiDotNetCore/Services/EntityResourceService.cs index 2ce3b9147d..63547eed80 100644 --- a/src/JsonApiDotNetCore/Services/EntityResourceService.cs +++ b/src/JsonApiDotNetCore/Services/EntityResourceService.cs @@ -140,11 +140,11 @@ public virtual async Task GetRelationshipAsync(TId id, string relationsh var resource = MapOut(entity); // compound-property -> CompoundProperty - var navigationPropertyName = _jsonApiContext.ContextGraph.GetRelationshipName(relationshipName); + var navigationPropertyName = _jsonApiContext.ResourceGraph.GetRelationshipName(relationshipName); if (navigationPropertyName == null) throw new JsonApiException(422, $"Relationship '{relationshipName}' does not exist on resource '{typeof(TResource)}'."); - var relationshipValue = _jsonApiContext.ContextGraph.GetRelationship(resource, navigationPropertyName); + var relationshipValue = _jsonApiContext.ResourceGraph.GetRelationship(resource, navigationPropertyName); return relationshipValue; } @@ -165,7 +165,7 @@ public virtual async Task UpdateRelationshipsAsync(TId id, string relationshipNa throw new JsonApiException(404, $"Entity with id {id} could not be found."); } - var relationship = _jsonApiContext.ContextGraph + var relationship = _jsonApiContext.ResourceGraph .GetContextEntity(typeof(TResource)) .Relationships .FirstOrDefault(r => r.Is(relationshipName)); diff --git a/src/JsonApiDotNetCore/Services/IJsonApiContext.cs b/src/JsonApiDotNetCore/Services/IJsonApiContext.cs index 80995596ea..2509d7124f 100644 --- a/src/JsonApiDotNetCore/Services/IJsonApiContext.cs +++ b/src/JsonApiDotNetCore/Services/IJsonApiContext.cs @@ -13,7 +13,7 @@ namespace JsonApiDotNetCore.Services public interface IJsonApiApplication { JsonApiOptions Options { get; set; } - IContextGraph ContextGraph { get; set; } + IResourceGraph ResourceGraph { get; set; } } public interface IQueryRequest diff --git a/src/JsonApiDotNetCore/Services/JsonApiContext.cs b/src/JsonApiDotNetCore/Services/JsonApiContext.cs index 1e9b53eb51..2553cbe451 100644 --- a/src/JsonApiDotNetCore/Services/JsonApiContext.cs +++ b/src/JsonApiDotNetCore/Services/JsonApiContext.cs @@ -18,7 +18,7 @@ public class JsonApiContext : IJsonApiContext private readonly IControllerContext _controllerContext; public JsonApiContext( - IContextGraph contextGraph, + IResourceGraph resourceGraph, IHttpContextAccessor httpContextAccessor, JsonApiOptions options, IMetaBuilder metaBuilder, @@ -26,7 +26,7 @@ public JsonApiContext( IQueryParser queryParser, IControllerContext controllerContext) { - ContextGraph = contextGraph; + ResourceGraph = resourceGraph; _httpContextAccessor = httpContextAccessor; Options = options; MetaBuilder = metaBuilder; @@ -36,7 +36,7 @@ public JsonApiContext( } public JsonApiOptions Options { get; set; } - public IContextGraph ContextGraph { get; set; } + public IResourceGraph ResourceGraph { get; set; } [Obsolete("Use the proxied member IControllerContext.RequestEntity instead.")] public ContextEntity RequestEntity { get => _controllerContext.RequestEntity; set => _controllerContext.RequestEntity = value; } public string BasePath { get; set; } @@ -62,9 +62,9 @@ public IJsonApiContext ApplyContext(object controller) throw new JsonApiException(500, $"Cannot ApplyContext from null controller for type {typeof(T)}"); _controllerContext.ControllerType = controller.GetType(); - _controllerContext.RequestEntity = ContextGraph.GetContextEntity(typeof(T)); + _controllerContext.RequestEntity = ResourceGraph.GetContextEntity(typeof(T)); if (_controllerContext.RequestEntity == null) - throw new JsonApiException(500, $"A resource has not been properly defined for type '{typeof(T)}'. Ensure it has been registered on the ContextGraph."); + throw new JsonApiException(500, $"A resource has not been properly defined for type '{typeof(T)}'. Ensure it has been registered on the ResourceGraph."); var context = _httpContextAccessor.HttpContext; diff --git a/src/JsonApiDotNetCore/Services/Operations/OperationProcessorResolver.cs b/src/JsonApiDotNetCore/Services/Operations/OperationProcessorResolver.cs index a702638c5d..d509340c0d 100644 --- a/src/JsonApiDotNetCore/Services/Operations/OperationProcessorResolver.cs +++ b/src/JsonApiDotNetCore/Services/Operations/OperationProcessorResolver.cs @@ -104,7 +104,7 @@ public IOpProcessor LocateUpdateService(Operation operation) private ContextEntity GetResourceMetadata(string resourceName) { - var contextEntity = _context.ContextGraph.GetContextEntity(resourceName); + var contextEntity = _context.ResourceGraph.GetContextEntity(resourceName); if(contextEntity == null) throw new JsonApiException(400, $"This API does not expose a resource of type '{resourceName}'."); diff --git a/src/JsonApiDotNetCore/Services/Operations/Processors/CreateOpProcessor.cs b/src/JsonApiDotNetCore/Services/Operations/Processors/CreateOpProcessor.cs index 5ecdf6f38a..ebc600a5fb 100644 --- a/src/JsonApiDotNetCore/Services/Operations/Processors/CreateOpProcessor.cs +++ b/src/JsonApiDotNetCore/Services/Operations/Processors/CreateOpProcessor.cs @@ -23,8 +23,8 @@ public CreateOpProcessor( ICreateService service, IJsonApiDeSerializer deSerializer, IDocumentBuilder documentBuilder, - IContextGraph contextGraph - ) : base(service, deSerializer, documentBuilder, contextGraph) + IResourceGraph resourceGraph + ) : base(service, deSerializer, documentBuilder, resourceGraph) { } } @@ -34,18 +34,18 @@ public class CreateOpProcessor : ICreateOpProcessor private readonly ICreateService _service; private readonly IJsonApiDeSerializer _deSerializer; private readonly IDocumentBuilder _documentBuilder; - private readonly IContextGraph _contextGraph; + private readonly IResourceGraph _resourceGraph; public CreateOpProcessor( ICreateService service, IJsonApiDeSerializer deSerializer, IDocumentBuilder documentBuilder, - IContextGraph contextGraph) + IResourceGraph resourceGraph) { _service = service; _deSerializer = deSerializer; _documentBuilder = documentBuilder; - _contextGraph = contextGraph; + _resourceGraph = resourceGraph; } public async Task ProcessAsync(Operation operation) @@ -59,7 +59,7 @@ public async Task ProcessAsync(Operation operation) }; operationResult.Data = _documentBuilder.GetData( - _contextGraph.GetContextEntity(operation.GetResourceTypeName()), + _resourceGraph.GetContextEntity(operation.GetResourceTypeName()), result); // we need to persist the original request localId so that subsequent operations diff --git a/src/JsonApiDotNetCore/Services/Operations/Processors/GetOpProcessor.cs b/src/JsonApiDotNetCore/Services/Operations/Processors/GetOpProcessor.cs index 6e0ad06b51..0551b0a3cd 100644 --- a/src/JsonApiDotNetCore/Services/Operations/Processors/GetOpProcessor.cs +++ b/src/JsonApiDotNetCore/Services/Operations/Processors/GetOpProcessor.cs @@ -38,9 +38,9 @@ public GetOpProcessor( IGetRelationshipService getRelationship, IJsonApiDeSerializer deSerializer, IDocumentBuilder documentBuilder, - IContextGraph contextGraph, + IResourceGraph resourceGraph, IJsonApiContext jsonApiContext - ) : base(getAll, getById, getRelationship, deSerializer, documentBuilder, contextGraph, jsonApiContext) + ) : base(getAll, getById, getRelationship, deSerializer, documentBuilder, resourceGraph, jsonApiContext) { } } @@ -53,7 +53,7 @@ public class GetOpProcessor : IGetOpProcessor private readonly IGetRelationshipService _getRelationship; private readonly IJsonApiDeSerializer _deSerializer; private readonly IDocumentBuilder _documentBuilder; - private readonly IContextGraph _contextGraph; + private readonly IResourceGraph _resourceGraph; private readonly IJsonApiContext _jsonApiContext; /// @@ -63,7 +63,7 @@ public GetOpProcessor( IGetRelationshipService getRelationship, IJsonApiDeSerializer deSerializer, IDocumentBuilder documentBuilder, - IContextGraph contextGraph, + IResourceGraph resourceGraph, IJsonApiContext jsonApiContext) { _getAll = getAll; @@ -71,7 +71,7 @@ public GetOpProcessor( _getRelationship = getRelationship; _deSerializer = deSerializer; _documentBuilder = documentBuilder; - _contextGraph = contextGraph; + _resourceGraph = resourceGraph; _jsonApiContext = jsonApiContext.ApplyContext(this); } @@ -100,7 +100,7 @@ private async Task GetAllAsync(Operation operation) foreach (var resource in result) { var doc = _documentBuilder.GetData( - _contextGraph.GetContextEntity(operation.GetResourceTypeName()), + _resourceGraph.GetContextEntity(operation.GetResourceTypeName()), resource); operations.Add(doc); } @@ -121,7 +121,7 @@ private async Task GetByIdAsync(Operation operation) throw new JsonApiException(404, $"Could not find '{operation.Ref.Type}' record with id '{operation.Ref.Id}'"); var doc = _documentBuilder.GetData( - _contextGraph.GetContextEntity(operation.GetResourceTypeName()), + _resourceGraph.GetContextEntity(operation.GetResourceTypeName()), result); return doc; @@ -134,10 +134,10 @@ private async Task GetRelationshipAsync(Operation operation) // TODO: need a better way to get the ContextEntity from a relationship name // when no generic parameter is available - var relationshipType = _contextGraph.GetContextEntity(operation.GetResourceTypeName()) + var relationshipType = _resourceGraph.GetContextEntity(operation.GetResourceTypeName()) .Relationships.Single(r => r.Is(operation.Ref.Relationship)).Type; - var relatedContextEntity = _jsonApiContext.ContextGraph.GetContextEntity(relationshipType); + var relatedContextEntity = _jsonApiContext.ResourceGraph.GetContextEntity(relationshipType); if (result == null) return null; diff --git a/src/JsonApiDotNetCore/Services/Operations/Processors/RemoveOpProcessor.cs b/src/JsonApiDotNetCore/Services/Operations/Processors/RemoveOpProcessor.cs index a1aebadc66..f3efe7939c 100644 --- a/src/JsonApiDotNetCore/Services/Operations/Processors/RemoveOpProcessor.cs +++ b/src/JsonApiDotNetCore/Services/Operations/Processors/RemoveOpProcessor.cs @@ -22,8 +22,8 @@ public RemoveOpProcessor( IDeleteService service, IJsonApiDeSerializer deSerializer, IDocumentBuilder documentBuilder, - IContextGraph contextGraph - ) : base(service, deSerializer, documentBuilder, contextGraph) + IResourceGraph resourceGraph + ) : base(service, deSerializer, documentBuilder, resourceGraph) { } } @@ -33,18 +33,18 @@ public class RemoveOpProcessor : IRemoveOpProcessor private readonly IDeleteService _service; private readonly IJsonApiDeSerializer _deSerializer; private readonly IDocumentBuilder _documentBuilder; - private readonly IContextGraph _contextGraph; + private readonly IResourceGraph _resourceGraph; public RemoveOpProcessor( IDeleteService service, IJsonApiDeSerializer deSerializer, IDocumentBuilder documentBuilder, - IContextGraph contextGraph) + IResourceGraph resourceGraph) { _service = service; _deSerializer = deSerializer; _documentBuilder = documentBuilder; - _contextGraph = contextGraph; + _resourceGraph = resourceGraph; } public async Task ProcessAsync(Operation operation) diff --git a/src/JsonApiDotNetCore/Services/Operations/Processors/UpdateOpProcessor.cs b/src/JsonApiDotNetCore/Services/Operations/Processors/UpdateOpProcessor.cs index 1ea690a52c..9b136b30c0 100644 --- a/src/JsonApiDotNetCore/Services/Operations/Processors/UpdateOpProcessor.cs +++ b/src/JsonApiDotNetCore/Services/Operations/Processors/UpdateOpProcessor.cs @@ -22,8 +22,8 @@ public UpdateOpProcessor( IUpdateService service, IJsonApiDeSerializer deSerializer, IDocumentBuilder documentBuilder, - IContextGraph contextGraph - ) : base(service, deSerializer, documentBuilder, contextGraph) + IResourceGraph resourceGraph + ) : base(service, deSerializer, documentBuilder, resourceGraph) { } } @@ -33,18 +33,18 @@ public class UpdateOpProcessor : IUpdateOpProcessor private readonly IUpdateService _service; private readonly IJsonApiDeSerializer _deSerializer; private readonly IDocumentBuilder _documentBuilder; - private readonly IContextGraph _contextGraph; + private readonly IResourceGraph _resourceGraph; public UpdateOpProcessor( IUpdateService service, IJsonApiDeSerializer deSerializer, IDocumentBuilder documentBuilder, - IContextGraph contextGraph) + IResourceGraph resourceGraph) { _service = service; _deSerializer = deSerializer; _documentBuilder = documentBuilder; - _contextGraph = contextGraph; + _resourceGraph = resourceGraph; } public async Task ProcessAsync(Operation operation) @@ -63,7 +63,7 @@ public async Task ProcessAsync(Operation operation) Op = OperationCode.update }; - operationResult.Data = _documentBuilder.GetData(_contextGraph.GetContextEntity(operation.GetResourceTypeName()), result); + operationResult.Data = _documentBuilder.GetData(_resourceGraph.GetContextEntity(operation.GetResourceTypeName()), result); return operationResult; } diff --git a/src/JsonApiDotNetCore/api/.manifest b/src/JsonApiDotNetCore/api/.manifest index 41d94c66fb..caadae227a 100644 --- a/src/JsonApiDotNetCore/api/.manifest +++ b/src/JsonApiDotNetCore/api/.manifest @@ -1,14 +1,14 @@ { "JsonApiDotNetCore.Builders": "JsonApiDotNetCore.Builders.yml", - "JsonApiDotNetCore.Builders.ContextGraphBuilder": "JsonApiDotNetCore.Builders.ContextGraphBuilder.yml", - "JsonApiDotNetCore.Builders.ContextGraphBuilder.AddDbContext``1": "JsonApiDotNetCore.Builders.ContextGraphBuilder.yml", - "JsonApiDotNetCore.Builders.ContextGraphBuilder.AddResource``1(System.String)": "JsonApiDotNetCore.Builders.ContextGraphBuilder.yml", - "JsonApiDotNetCore.Builders.ContextGraphBuilder.AddResource``2(System.String)": "JsonApiDotNetCore.Builders.ContextGraphBuilder.yml", - "JsonApiDotNetCore.Builders.ContextGraphBuilder.Build": "JsonApiDotNetCore.Builders.ContextGraphBuilder.yml", - "JsonApiDotNetCore.Builders.ContextGraphBuilder.DocumentLinks": "JsonApiDotNetCore.Builders.ContextGraphBuilder.yml", - "JsonApiDotNetCore.Builders.ContextGraphBuilder.GetAttributes(System.Type)": "JsonApiDotNetCore.Builders.ContextGraphBuilder.yml", - "JsonApiDotNetCore.Builders.ContextGraphBuilder.GetRelationships(System.Type)": "JsonApiDotNetCore.Builders.ContextGraphBuilder.yml", - "JsonApiDotNetCore.Builders.ContextGraphBuilder.GetRelationshipType(JsonApiDotNetCore.Models.RelationshipAttribute,System.Reflection.PropertyInfo)": "JsonApiDotNetCore.Builders.ContextGraphBuilder.yml", + "JsonApiDotNetCore.Builders.ResourceGraphBuilder": "JsonApiDotNetCore.Builders.ResourceGraphBuilder.yml", + "JsonApiDotNetCore.Builders.ResourceGraphBuilder.AddDbContext``1": "JsonApiDotNetCore.Builders.ResourceGraphBuilder.yml", + "JsonApiDotNetCore.Builders.ResourceGraphBuilder.AddResource``1(System.String)": "JsonApiDotNetCore.Builders.ResourceGraphBuilder.yml", + "JsonApiDotNetCore.Builders.ResourceGraphBuilder.AddResource``2(System.String)": "JsonApiDotNetCore.Builders.ResourceGraphBuilder.yml", + "JsonApiDotNetCore.Builders.ResourceGraphBuilder.Build": "JsonApiDotNetCore.Builders.ResourceGraphBuilder.yml", + "JsonApiDotNetCore.Builders.ResourceGraphBuilder.DocumentLinks": "JsonApiDotNetCore.Builders.ResourceGraphBuilder.yml", + "JsonApiDotNetCore.Builders.ResourceGraphBuilder.GetAttributes(System.Type)": "JsonApiDotNetCore.Builders.ResourceGraphBuilder.yml", + "JsonApiDotNetCore.Builders.ResourceGraphBuilder.GetRelationships(System.Type)": "JsonApiDotNetCore.Builders.ResourceGraphBuilder.yml", + "JsonApiDotNetCore.Builders.ResourceGraphBuilder.GetRelationshipType(JsonApiDotNetCore.Models.RelationshipAttribute,System.Reflection.PropertyInfo)": "JsonApiDotNetCore.Builders.ResourceGraphBuilder.yml", "JsonApiDotNetCore.Builders.DocumentBuilder": "JsonApiDotNetCore.Builders.DocumentBuilder.yml", "JsonApiDotNetCore.Builders.DocumentBuilder.#ctor(JsonApiDotNetCore.Services.IJsonApiContext,JsonApiDotNetCore.Services.IRequestMeta,JsonApiDotNetCore.Builders.IDocumentBuilderOptionsProvider)": "JsonApiDotNetCore.Builders.DocumentBuilder.yml", "JsonApiDotNetCore.Builders.DocumentBuilder.Build(JsonApiDotNetCore.Models.IIdentifiable)": "JsonApiDotNetCore.Builders.DocumentBuilder.yml", @@ -20,12 +20,12 @@ "JsonApiDotNetCore.Builders.DocumentBuilderOptionsProvider": "JsonApiDotNetCore.Builders.DocumentBuilderOptionsProvider.yml", "JsonApiDotNetCore.Builders.DocumentBuilderOptionsProvider.#ctor(JsonApiDotNetCore.Services.IJsonApiContext,Microsoft.AspNetCore.Http.IHttpContextAccessor)": "JsonApiDotNetCore.Builders.DocumentBuilderOptionsProvider.yml", "JsonApiDotNetCore.Builders.DocumentBuilderOptionsProvider.GetDocumentBuilderOptions": "JsonApiDotNetCore.Builders.DocumentBuilderOptionsProvider.yml", - "JsonApiDotNetCore.Builders.IContextGraphBuilder": "JsonApiDotNetCore.Builders.IContextGraphBuilder.yml", - "JsonApiDotNetCore.Builders.IContextGraphBuilder.AddDbContext``1": "JsonApiDotNetCore.Builders.IContextGraphBuilder.yml", - "JsonApiDotNetCore.Builders.IContextGraphBuilder.AddResource``1(System.String)": "JsonApiDotNetCore.Builders.IContextGraphBuilder.yml", - "JsonApiDotNetCore.Builders.IContextGraphBuilder.AddResource``2(System.String)": "JsonApiDotNetCore.Builders.IContextGraphBuilder.yml", - "JsonApiDotNetCore.Builders.IContextGraphBuilder.Build": "JsonApiDotNetCore.Builders.IContextGraphBuilder.yml", - "JsonApiDotNetCore.Builders.IContextGraphBuilder.DocumentLinks": "JsonApiDotNetCore.Builders.IContextGraphBuilder.yml", + "JsonApiDotNetCore.Builders.IResourceGraphBuilder": "JsonApiDotNetCore.Builders.IResourceGraphBuilder.yml", + "JsonApiDotNetCore.Builders.IResourceGraphBuilder.AddDbContext``1": "JsonApiDotNetCore.Builders.IResourceGraphBuilder.yml", + "JsonApiDotNetCore.Builders.IResourceGraphBuilder.AddResource``1(System.String)": "JsonApiDotNetCore.Builders.IResourceGraphBuilder.yml", + "JsonApiDotNetCore.Builders.IResourceGraphBuilder.AddResource``2(System.String)": "JsonApiDotNetCore.Builders.IResourceGraphBuilder.yml", + "JsonApiDotNetCore.Builders.IResourceGraphBuilder.Build": "JsonApiDotNetCore.Builders.IResourceGraphBuilder.yml", + "JsonApiDotNetCore.Builders.IResourceGraphBuilder.DocumentLinks": "JsonApiDotNetCore.Builders.IResourceGraphBuilder.yml", "JsonApiDotNetCore.Builders.IDocumentBuilder": "JsonApiDotNetCore.Builders.IDocumentBuilder.yml", "JsonApiDotNetCore.Builders.IDocumentBuilder.Build(JsonApiDotNetCore.Models.IIdentifiable)": "JsonApiDotNetCore.Builders.IDocumentBuilder.yml", "JsonApiDotNetCore.Builders.IDocumentBuilder.Build(System.Collections.Generic.IEnumerable{JsonApiDotNetCore.Models.IIdentifiable})": "JsonApiDotNetCore.Builders.IDocumentBuilder.yml", @@ -50,9 +50,9 @@ "JsonApiDotNetCore.Configuration.JsonApiOptions": "JsonApiDotNetCore.Configuration.JsonApiOptions.yml", "JsonApiDotNetCore.Configuration.JsonApiOptions.AllowClientGeneratedIds": "JsonApiDotNetCore.Configuration.JsonApiOptions.yml", "JsonApiDotNetCore.Configuration.JsonApiOptions.AllowCustomQueryParameters": "JsonApiDotNetCore.Configuration.JsonApiOptions.yml", - "JsonApiDotNetCore.Configuration.JsonApiOptions.BuildContextGraph(System.Action{JsonApiDotNetCore.Builders.IContextGraphBuilder})": "JsonApiDotNetCore.Configuration.JsonApiOptions.yml", - "JsonApiDotNetCore.Configuration.JsonApiOptions.BuildContextGraph``1(System.Action{JsonApiDotNetCore.Builders.IContextGraphBuilder})": "JsonApiDotNetCore.Configuration.JsonApiOptions.yml", - "JsonApiDotNetCore.Configuration.JsonApiOptions.ContextGraph": "JsonApiDotNetCore.Configuration.JsonApiOptions.yml", + "JsonApiDotNetCore.Configuration.JsonApiOptions.BuildResourceGraph(System.Action{JsonApiDotNetCore.Builders.IResourceGraphBuilder})": "JsonApiDotNetCore.Configuration.JsonApiOptions.yml", + "JsonApiDotNetCore.Configuration.JsonApiOptions.BuildResourceGraph``1(System.Action{JsonApiDotNetCore.Builders.IResourceGraphBuilder})": "JsonApiDotNetCore.Configuration.JsonApiOptions.yml", + "JsonApiDotNetCore.Configuration.JsonApiOptions.ResourceGraph": "JsonApiDotNetCore.Configuration.JsonApiOptions.yml", "JsonApiDotNetCore.Configuration.JsonApiOptions.DefaultPageSize": "JsonApiDotNetCore.Configuration.JsonApiOptions.yml", "JsonApiDotNetCore.Configuration.JsonApiOptions.DisableErrorSource": "JsonApiDotNetCore.Configuration.JsonApiOptions.yml", "JsonApiDotNetCore.Configuration.JsonApiOptions.DisableErrorStackTraces": "JsonApiDotNetCore.Configuration.JsonApiOptions.yml", @@ -250,14 +250,14 @@ "JsonApiDotNetCore.Internal.ContextEntity.IdentityType": "JsonApiDotNetCore.Internal.ContextEntity.yml", "JsonApiDotNetCore.Internal.ContextEntity.Links": "JsonApiDotNetCore.Internal.ContextEntity.yml", "JsonApiDotNetCore.Internal.ContextEntity.Relationships": "JsonApiDotNetCore.Internal.ContextEntity.yml", - "JsonApiDotNetCore.Internal.ContextGraph": "JsonApiDotNetCore.Internal.ContextGraph.yml", - "JsonApiDotNetCore.Internal.ContextGraph.#ctor": "JsonApiDotNetCore.Internal.ContextGraph.yml", - "JsonApiDotNetCore.Internal.ContextGraph.#ctor(System.Collections.Generic.List{JsonApiDotNetCore.Internal.ContextEntity},System.Boolean)": "JsonApiDotNetCore.Internal.ContextGraph.yml", - "JsonApiDotNetCore.Internal.ContextGraph.GetContextEntity(System.String)": "JsonApiDotNetCore.Internal.ContextGraph.yml", - "JsonApiDotNetCore.Internal.ContextGraph.GetContextEntity(System.Type)": "JsonApiDotNetCore.Internal.ContextGraph.yml", - "JsonApiDotNetCore.Internal.ContextGraph.GetRelationship``1(``0,System.String)": "JsonApiDotNetCore.Internal.ContextGraph.yml", - "JsonApiDotNetCore.Internal.ContextGraph.GetRelationshipName``1(System.String)": "JsonApiDotNetCore.Internal.ContextGraph.yml", - "JsonApiDotNetCore.Internal.ContextGraph.UsesDbContext": "JsonApiDotNetCore.Internal.ContextGraph.yml", + "JsonApiDotNetCore.Internal.ResourceGraph": "JsonApiDotNetCore.Internal.ResourceGraph.yml", + "JsonApiDotNetCore.Internal.ResourceGraph.#ctor": "JsonApiDotNetCore.Internal.ResourceGraph.yml", + "JsonApiDotNetCore.Internal.ResourceGraph.#ctor(System.Collections.Generic.List{JsonApiDotNetCore.Internal.ContextEntity},System.Boolean)": "JsonApiDotNetCore.Internal.ResourceGraph.yml", + "JsonApiDotNetCore.Internal.ResourceGraph.GetContextEntity(System.String)": "JsonApiDotNetCore.Internal.ResourceGraph.yml", + "JsonApiDotNetCore.Internal.ResourceGraph.GetContextEntity(System.Type)": "JsonApiDotNetCore.Internal.ResourceGraph.yml", + "JsonApiDotNetCore.Internal.ResourceGraph.GetRelationship``1(``0,System.String)": "JsonApiDotNetCore.Internal.ResourceGraph.yml", + "JsonApiDotNetCore.Internal.ResourceGraph.GetRelationshipName``1(System.String)": "JsonApiDotNetCore.Internal.ResourceGraph.yml", + "JsonApiDotNetCore.Internal.ResourceGraph.UsesDbContext": "JsonApiDotNetCore.Internal.ResourceGraph.yml", "JsonApiDotNetCore.Internal.DasherizedRoutingConvention": "JsonApiDotNetCore.Internal.DasherizedRoutingConvention.yml", "JsonApiDotNetCore.Internal.DasherizedRoutingConvention.#ctor(System.String)": "JsonApiDotNetCore.Internal.DasherizedRoutingConvention.yml", "JsonApiDotNetCore.Internal.DasherizedRoutingConvention.Apply(Microsoft.AspNetCore.Mvc.ApplicationModels.ApplicationModel)": "JsonApiDotNetCore.Internal.DasherizedRoutingConvention.yml", @@ -300,12 +300,12 @@ "JsonApiDotNetCore.Internal.Generics.IGenericProcessorFactory": "JsonApiDotNetCore.Internal.Generics.IGenericProcessorFactory.yml", "JsonApiDotNetCore.Internal.Generics.IGenericProcessorFactory.GetProcessor``1(System.Type,System.Type)": "JsonApiDotNetCore.Internal.Generics.IGenericProcessorFactory.yml", "JsonApiDotNetCore.Internal.Generics.IGenericProcessorFactory.GetProcessor``1(System.Type,System.Type,System.Type)": "JsonApiDotNetCore.Internal.Generics.IGenericProcessorFactory.yml", - "JsonApiDotNetCore.Internal.IContextGraph": "JsonApiDotNetCore.Internal.IContextGraph.yml", - "JsonApiDotNetCore.Internal.IContextGraph.GetContextEntity(System.String)": "JsonApiDotNetCore.Internal.IContextGraph.yml", - "JsonApiDotNetCore.Internal.IContextGraph.GetContextEntity(System.Type)": "JsonApiDotNetCore.Internal.IContextGraph.yml", - "JsonApiDotNetCore.Internal.IContextGraph.GetRelationship``1(``0,System.String)": "JsonApiDotNetCore.Internal.IContextGraph.yml", - "JsonApiDotNetCore.Internal.IContextGraph.GetRelationshipName``1(System.String)": "JsonApiDotNetCore.Internal.IContextGraph.yml", - "JsonApiDotNetCore.Internal.IContextGraph.UsesDbContext": "JsonApiDotNetCore.Internal.IContextGraph.yml", + "JsonApiDotNetCore.Internal.IResourceGraph": "JsonApiDotNetCore.Internal.IResourceGraph.yml", + "JsonApiDotNetCore.Internal.IResourceGraph.GetContextEntity(System.String)": "JsonApiDotNetCore.Internal.IResourceGraph.yml", + "JsonApiDotNetCore.Internal.IResourceGraph.GetContextEntity(System.Type)": "JsonApiDotNetCore.Internal.IResourceGraph.yml", + "JsonApiDotNetCore.Internal.IResourceGraph.GetRelationship``1(``0,System.String)": "JsonApiDotNetCore.Internal.IResourceGraph.yml", + "JsonApiDotNetCore.Internal.IResourceGraph.GetRelationshipName``1(System.String)": "JsonApiDotNetCore.Internal.IResourceGraph.yml", + "JsonApiDotNetCore.Internal.IResourceGraph.UsesDbContext": "JsonApiDotNetCore.Internal.IResourceGraph.yml", "JsonApiDotNetCore.Internal.JsonApiException": "JsonApiDotNetCore.Internal.JsonApiException.yml", "JsonApiDotNetCore.Internal.JsonApiException.#ctor(JsonApiDotNetCore.Internal.Error)": "JsonApiDotNetCore.Internal.JsonApiException.yml", "JsonApiDotNetCore.Internal.JsonApiException.#ctor(JsonApiDotNetCore.Internal.ErrorCollection)": "JsonApiDotNetCore.Internal.JsonApiException.yml", @@ -568,7 +568,7 @@ "JsonApiDotNetCore.Services.IJsonApiContext.ApplyContext``1(System.Object)": "JsonApiDotNetCore.Services.IJsonApiContext.yml", "JsonApiDotNetCore.Services.IJsonApiContext.AttributesToUpdate": "JsonApiDotNetCore.Services.IJsonApiContext.yml", "JsonApiDotNetCore.Services.IJsonApiContext.BasePath": "JsonApiDotNetCore.Services.IJsonApiContext.yml", - "JsonApiDotNetCore.Services.IJsonApiContext.ContextGraph": "JsonApiDotNetCore.Services.IJsonApiContext.yml", + "JsonApiDotNetCore.Services.IJsonApiContext.ResourceGraph": "JsonApiDotNetCore.Services.IJsonApiContext.yml", "JsonApiDotNetCore.Services.IJsonApiContext.ControllerType": "JsonApiDotNetCore.Services.IJsonApiContext.yml", "JsonApiDotNetCore.Services.IJsonApiContext.DocumentMeta": "JsonApiDotNetCore.Services.IJsonApiContext.yml", "JsonApiDotNetCore.Services.IJsonApiContext.GenericProcessorFactory": "JsonApiDotNetCore.Services.IJsonApiContext.yml", @@ -604,11 +604,11 @@ "JsonApiDotNetCore.Services.IUpdateService`2": "JsonApiDotNetCore.Services.IUpdateService-2.yml", "JsonApiDotNetCore.Services.IUpdateService`2.UpdateAsync(`1,`0)": "JsonApiDotNetCore.Services.IUpdateService-2.yml", "JsonApiDotNetCore.Services.JsonApiContext": "JsonApiDotNetCore.Services.JsonApiContext.yml", - "JsonApiDotNetCore.Services.JsonApiContext.#ctor(JsonApiDotNetCore.Internal.IContextGraph,Microsoft.AspNetCore.Http.IHttpContextAccessor,JsonApiDotNetCore.Configuration.JsonApiOptions,JsonApiDotNetCore.Builders.IMetaBuilder,JsonApiDotNetCore.Internal.Generics.IGenericProcessorFactory,JsonApiDotNetCore.Services.IQueryParser,JsonApiDotNetCore.Services.IControllerContext)": "JsonApiDotNetCore.Services.JsonApiContext.yml", + "JsonApiDotNetCore.Services.JsonApiContext.#ctor(JsonApiDotNetCore.Internal.IResourceGraph,Microsoft.AspNetCore.Http.IHttpContextAccessor,JsonApiDotNetCore.Configuration.JsonApiOptions,JsonApiDotNetCore.Builders.IMetaBuilder,JsonApiDotNetCore.Internal.Generics.IGenericProcessorFactory,JsonApiDotNetCore.Services.IQueryParser,JsonApiDotNetCore.Services.IControllerContext)": "JsonApiDotNetCore.Services.JsonApiContext.yml", "JsonApiDotNetCore.Services.JsonApiContext.ApplyContext``1(System.Object)": "JsonApiDotNetCore.Services.JsonApiContext.yml", "JsonApiDotNetCore.Services.JsonApiContext.AttributesToUpdate": "JsonApiDotNetCore.Services.JsonApiContext.yml", "JsonApiDotNetCore.Services.JsonApiContext.BasePath": "JsonApiDotNetCore.Services.JsonApiContext.yml", - "JsonApiDotNetCore.Services.JsonApiContext.ContextGraph": "JsonApiDotNetCore.Services.JsonApiContext.yml", + "JsonApiDotNetCore.Services.JsonApiContext.ResourceGraph": "JsonApiDotNetCore.Services.JsonApiContext.yml", "JsonApiDotNetCore.Services.JsonApiContext.ControllerType": "JsonApiDotNetCore.Services.JsonApiContext.yml", "JsonApiDotNetCore.Services.JsonApiContext.DocumentMeta": "JsonApiDotNetCore.Services.JsonApiContext.yml", "JsonApiDotNetCore.Services.JsonApiContext.GenericProcessorFactory": "JsonApiDotNetCore.Services.JsonApiContext.yml", @@ -644,14 +644,14 @@ "JsonApiDotNetCore.Services.Operations.OperationsProcessor.ProcessAsync(System.Collections.Generic.List{JsonApiDotNetCore.Models.Operations.Operation})": "JsonApiDotNetCore.Services.Operations.OperationsProcessor.yml", "JsonApiDotNetCore.Services.Operations.Processors": "JsonApiDotNetCore.Services.Operations.Processors.yml", "JsonApiDotNetCore.Services.Operations.Processors.CreateOpProcessor`1": "JsonApiDotNetCore.Services.Operations.Processors.CreateOpProcessor-1.yml", - "JsonApiDotNetCore.Services.Operations.Processors.CreateOpProcessor`1.#ctor(JsonApiDotNetCore.Services.ICreateService{`0,System.Int32},JsonApiDotNetCore.Serialization.IJsonApiDeSerializer,JsonApiDotNetCore.Builders.IDocumentBuilder,JsonApiDotNetCore.Internal.IContextGraph)": "JsonApiDotNetCore.Services.Operations.Processors.CreateOpProcessor-1.yml", + "JsonApiDotNetCore.Services.Operations.Processors.CreateOpProcessor`1.#ctor(JsonApiDotNetCore.Services.ICreateService{`0,System.Int32},JsonApiDotNetCore.Serialization.IJsonApiDeSerializer,JsonApiDotNetCore.Builders.IDocumentBuilder,JsonApiDotNetCore.Internal.IResourceGraph)": "JsonApiDotNetCore.Services.Operations.Processors.CreateOpProcessor-1.yml", "JsonApiDotNetCore.Services.Operations.Processors.CreateOpProcessor`2": "JsonApiDotNetCore.Services.Operations.Processors.CreateOpProcessor-2.yml", - "JsonApiDotNetCore.Services.Operations.Processors.CreateOpProcessor`2.#ctor(JsonApiDotNetCore.Services.ICreateService{`0,`1},JsonApiDotNetCore.Serialization.IJsonApiDeSerializer,JsonApiDotNetCore.Builders.IDocumentBuilder,JsonApiDotNetCore.Internal.IContextGraph)": "JsonApiDotNetCore.Services.Operations.Processors.CreateOpProcessor-2.yml", + "JsonApiDotNetCore.Services.Operations.Processors.CreateOpProcessor`2.#ctor(JsonApiDotNetCore.Services.ICreateService{`0,`1},JsonApiDotNetCore.Serialization.IJsonApiDeSerializer,JsonApiDotNetCore.Builders.IDocumentBuilder,JsonApiDotNetCore.Internal.IResourceGraph)": "JsonApiDotNetCore.Services.Operations.Processors.CreateOpProcessor-2.yml", "JsonApiDotNetCore.Services.Operations.Processors.CreateOpProcessor`2.ProcessAsync(JsonApiDotNetCore.Models.Operations.Operation)": "JsonApiDotNetCore.Services.Operations.Processors.CreateOpProcessor-2.yml", "JsonApiDotNetCore.Services.Operations.Processors.GetOpProcessor`1": "JsonApiDotNetCore.Services.Operations.Processors.GetOpProcessor-1.yml", - "JsonApiDotNetCore.Services.Operations.Processors.GetOpProcessor`1.#ctor(JsonApiDotNetCore.Services.IGetAllService{`0,System.Int32},JsonApiDotNetCore.Services.IGetByIdService{`0,System.Int32},JsonApiDotNetCore.Services.IGetRelationshipService{`0,System.Int32},JsonApiDotNetCore.Serialization.IJsonApiDeSerializer,JsonApiDotNetCore.Builders.IDocumentBuilder,JsonApiDotNetCore.Internal.IContextGraph,JsonApiDotNetCore.Services.IJsonApiContext)": "JsonApiDotNetCore.Services.Operations.Processors.GetOpProcessor-1.yml", + "JsonApiDotNetCore.Services.Operations.Processors.GetOpProcessor`1.#ctor(JsonApiDotNetCore.Services.IGetAllService{`0,System.Int32},JsonApiDotNetCore.Services.IGetByIdService{`0,System.Int32},JsonApiDotNetCore.Services.IGetRelationshipService{`0,System.Int32},JsonApiDotNetCore.Serialization.IJsonApiDeSerializer,JsonApiDotNetCore.Builders.IDocumentBuilder,JsonApiDotNetCore.Internal.IResourceGraph,JsonApiDotNetCore.Services.IJsonApiContext)": "JsonApiDotNetCore.Services.Operations.Processors.GetOpProcessor-1.yml", "JsonApiDotNetCore.Services.Operations.Processors.GetOpProcessor`2": "JsonApiDotNetCore.Services.Operations.Processors.GetOpProcessor-2.yml", - "JsonApiDotNetCore.Services.Operations.Processors.GetOpProcessor`2.#ctor(JsonApiDotNetCore.Services.IGetAllService{`0,`1},JsonApiDotNetCore.Services.IGetByIdService{`0,`1},JsonApiDotNetCore.Services.IGetRelationshipService{`0,`1},JsonApiDotNetCore.Serialization.IJsonApiDeSerializer,JsonApiDotNetCore.Builders.IDocumentBuilder,JsonApiDotNetCore.Internal.IContextGraph,JsonApiDotNetCore.Services.IJsonApiContext)": "JsonApiDotNetCore.Services.Operations.Processors.GetOpProcessor-2.yml", + "JsonApiDotNetCore.Services.Operations.Processors.GetOpProcessor`2.#ctor(JsonApiDotNetCore.Services.IGetAllService{`0,`1},JsonApiDotNetCore.Services.IGetByIdService{`0,`1},JsonApiDotNetCore.Services.IGetRelationshipService{`0,`1},JsonApiDotNetCore.Serialization.IJsonApiDeSerializer,JsonApiDotNetCore.Builders.IDocumentBuilder,JsonApiDotNetCore.Internal.IResourceGraph,JsonApiDotNetCore.Services.IJsonApiContext)": "JsonApiDotNetCore.Services.Operations.Processors.GetOpProcessor-2.yml", "JsonApiDotNetCore.Services.Operations.Processors.GetOpProcessor`2.ProcessAsync(JsonApiDotNetCore.Models.Operations.Operation)": "JsonApiDotNetCore.Services.Operations.Processors.GetOpProcessor-2.yml", "JsonApiDotNetCore.Services.Operations.Processors.ICreateOpProcessor`1": "JsonApiDotNetCore.Services.Operations.Processors.ICreateOpProcessor-1.yml", "JsonApiDotNetCore.Services.Operations.Processors.ICreateOpProcessor`2": "JsonApiDotNetCore.Services.Operations.Processors.ICreateOpProcessor-2.yml", @@ -662,14 +662,14 @@ "JsonApiDotNetCore.Services.Operations.Processors.IUpdateOpProcessor`1": "JsonApiDotNetCore.Services.Operations.Processors.IUpdateOpProcessor-1.yml", "JsonApiDotNetCore.Services.Operations.Processors.IUpdateOpProcessor`2": "JsonApiDotNetCore.Services.Operations.Processors.IUpdateOpProcessor-2.yml", "JsonApiDotNetCore.Services.Operations.Processors.RemoveOpProcessor`1": "JsonApiDotNetCore.Services.Operations.Processors.RemoveOpProcessor-1.yml", - "JsonApiDotNetCore.Services.Operations.Processors.RemoveOpProcessor`1.#ctor(JsonApiDotNetCore.Services.IDeleteService{`0,System.Int32},JsonApiDotNetCore.Serialization.IJsonApiDeSerializer,JsonApiDotNetCore.Builders.IDocumentBuilder,JsonApiDotNetCore.Internal.IContextGraph)": "JsonApiDotNetCore.Services.Operations.Processors.RemoveOpProcessor-1.yml", + "JsonApiDotNetCore.Services.Operations.Processors.RemoveOpProcessor`1.#ctor(JsonApiDotNetCore.Services.IDeleteService{`0,System.Int32},JsonApiDotNetCore.Serialization.IJsonApiDeSerializer,JsonApiDotNetCore.Builders.IDocumentBuilder,JsonApiDotNetCore.Internal.IResourceGraph)": "JsonApiDotNetCore.Services.Operations.Processors.RemoveOpProcessor-1.yml", "JsonApiDotNetCore.Services.Operations.Processors.RemoveOpProcessor`2": "JsonApiDotNetCore.Services.Operations.Processors.RemoveOpProcessor-2.yml", - "JsonApiDotNetCore.Services.Operations.Processors.RemoveOpProcessor`2.#ctor(JsonApiDotNetCore.Services.IDeleteService{`0,`1},JsonApiDotNetCore.Serialization.IJsonApiDeSerializer,JsonApiDotNetCore.Builders.IDocumentBuilder,JsonApiDotNetCore.Internal.IContextGraph)": "JsonApiDotNetCore.Services.Operations.Processors.RemoveOpProcessor-2.yml", + "JsonApiDotNetCore.Services.Operations.Processors.RemoveOpProcessor`2.#ctor(JsonApiDotNetCore.Services.IDeleteService{`0,`1},JsonApiDotNetCore.Serialization.IJsonApiDeSerializer,JsonApiDotNetCore.Builders.IDocumentBuilder,JsonApiDotNetCore.Internal.IResourceGraph)": "JsonApiDotNetCore.Services.Operations.Processors.RemoveOpProcessor-2.yml", "JsonApiDotNetCore.Services.Operations.Processors.RemoveOpProcessor`2.ProcessAsync(JsonApiDotNetCore.Models.Operations.Operation)": "JsonApiDotNetCore.Services.Operations.Processors.RemoveOpProcessor-2.yml", "JsonApiDotNetCore.Services.Operations.Processors.UpdateOpProcessor`1": "JsonApiDotNetCore.Services.Operations.Processors.UpdateOpProcessor-1.yml", - "JsonApiDotNetCore.Services.Operations.Processors.UpdateOpProcessor`1.#ctor(JsonApiDotNetCore.Services.IUpdateService{`0,System.Int32},JsonApiDotNetCore.Serialization.IJsonApiDeSerializer,JsonApiDotNetCore.Builders.IDocumentBuilder,JsonApiDotNetCore.Internal.IContextGraph)": "JsonApiDotNetCore.Services.Operations.Processors.UpdateOpProcessor-1.yml", + "JsonApiDotNetCore.Services.Operations.Processors.UpdateOpProcessor`1.#ctor(JsonApiDotNetCore.Services.IUpdateService{`0,System.Int32},JsonApiDotNetCore.Serialization.IJsonApiDeSerializer,JsonApiDotNetCore.Builders.IDocumentBuilder,JsonApiDotNetCore.Internal.IResourceGraph)": "JsonApiDotNetCore.Services.Operations.Processors.UpdateOpProcessor-1.yml", "JsonApiDotNetCore.Services.Operations.Processors.UpdateOpProcessor`2": "JsonApiDotNetCore.Services.Operations.Processors.UpdateOpProcessor-2.yml", - "JsonApiDotNetCore.Services.Operations.Processors.UpdateOpProcessor`2.#ctor(JsonApiDotNetCore.Services.IUpdateService{`0,`1},JsonApiDotNetCore.Serialization.IJsonApiDeSerializer,JsonApiDotNetCore.Builders.IDocumentBuilder,JsonApiDotNetCore.Internal.IContextGraph)": "JsonApiDotNetCore.Services.Operations.Processors.UpdateOpProcessor-2.yml", + "JsonApiDotNetCore.Services.Operations.Processors.UpdateOpProcessor`2.#ctor(JsonApiDotNetCore.Services.IUpdateService{`0,`1},JsonApiDotNetCore.Serialization.IJsonApiDeSerializer,JsonApiDotNetCore.Builders.IDocumentBuilder,JsonApiDotNetCore.Internal.IResourceGraph)": "JsonApiDotNetCore.Services.Operations.Processors.UpdateOpProcessor-2.yml", "JsonApiDotNetCore.Services.Operations.Processors.UpdateOpProcessor`2.ProcessAsync(JsonApiDotNetCore.Models.Operations.Operation)": "JsonApiDotNetCore.Services.Operations.Processors.UpdateOpProcessor-2.yml", "JsonApiDotNetCore.Services.QueryAccessor": "JsonApiDotNetCore.Services.QueryAccessor.yml", "JsonApiDotNetCore.Services.QueryAccessor.#ctor(JsonApiDotNetCore.Services.IJsonApiContext,Microsoft.Extensions.Logging.ILogger{JsonApiDotNetCore.Services.QueryAccessor})": "JsonApiDotNetCore.Services.QueryAccessor.yml", diff --git a/test/DiscoveryTests/ServiceDiscoveryFacadeTests.cs b/test/DiscoveryTests/ServiceDiscoveryFacadeTests.cs index 433d23557b..15667c1872 100644 --- a/test/DiscoveryTests/ServiceDiscoveryFacadeTests.cs +++ b/test/DiscoveryTests/ServiceDiscoveryFacadeTests.cs @@ -16,7 +16,7 @@ namespace DiscoveryTests public class ServiceDiscoveryFacadeTests { private readonly IServiceCollection _services = new ServiceCollection(); - private readonly ContextGraphBuilder _graphBuilder = new ContextGraphBuilder(); + private readonly ResourceGraphBuilder _graphBuilder = new ResourceGraphBuilder(); private ServiceDiscoveryFacade _facade => new ServiceDiscoveryFacade(_services, _graphBuilder); [Fact] diff --git a/test/UnitTests/Builders/ContextGraphBuilder_Tests.cs b/test/UnitTests/Builders/ContextGraphBuilder_Tests.cs index a0f54ad443..eab003309f 100644 --- a/test/UnitTests/Builders/ContextGraphBuilder_Tests.cs +++ b/test/UnitTests/Builders/ContextGraphBuilder_Tests.cs @@ -15,7 +15,7 @@ namespace UnitTests { - public class ContextGraphBuilder_Tests + public class ResourceGraphBuilder_Tests { class NonDbResource : Identifiable {} class DbResource : Identifiable {} @@ -23,18 +23,18 @@ class TestContext : DbContext { public DbSet DbResources { get; set; } } - public ContextGraphBuilder_Tests() + public ResourceGraphBuilder_Tests() { JsonApiOptions.ResourceNameFormatter = new DefaultResourceNameFormatter(); } [Fact] - public void Can_Build_ContextGraph_Using_Builder() + public void Can_Build_ResourceGraph_Using_Builder() { // arrange var services = new ServiceCollection(); services.AddJsonApi(opt => { - opt.BuildContextGraph(b => { + opt.BuildResourceGraph(b => { b.AddResource("non-db-resources"); }); }); @@ -43,9 +43,9 @@ public void Can_Build_ContextGraph_Using_Builder() var container = services.BuildServiceProvider(); // assert - var contextGraph = container.GetRequiredService(); - var dbResource = contextGraph.GetContextEntity("db-resources"); - var nonDbResource = contextGraph.GetContextEntity("non-db-resources"); + var resourceGraph = container.GetRequiredService(); + var dbResource = resourceGraph.GetContextEntity("db-resources"); + var nonDbResource = resourceGraph.GetContextEntity("non-db-resources"); Assert.Equal(typeof(DbResource), dbResource.EntityType); Assert.Equal(typeof(NonDbResource), nonDbResource.EntityType); Assert.Equal(typeof(ResourceDefinition), nonDbResource.ResourceType); @@ -55,7 +55,7 @@ public void Can_Build_ContextGraph_Using_Builder() public void Resources_Without_Names_Specified_Will_Use_Default_Formatter() { // arrange - var builder = new ContextGraphBuilder(); + var builder = new ResourceGraphBuilder(); builder.AddResource(); // act @@ -71,7 +71,7 @@ public void Resources_Without_Names_Specified_Will_Use_Configured_Formatter() { // arrange JsonApiOptions.ResourceNameFormatter = new CamelCaseNameFormatter(); - var builder = new ContextGraphBuilder(); + var builder = new ResourceGraphBuilder(); builder.AddResource(); // act @@ -86,7 +86,7 @@ public void Resources_Without_Names_Specified_Will_Use_Configured_Formatter() public void Attrs_Without_Names_Specified_Will_Use_Default_Formatter() { // arrange - var builder = new ContextGraphBuilder(); + var builder = new ResourceGraphBuilder(); builder.AddResource(); // act @@ -102,7 +102,7 @@ public void Attrs_Without_Names_Specified_Will_Use_Configured_Formatter() { // arrange JsonApiOptions.ResourceNameFormatter = new CamelCaseNameFormatter(); - var builder = new ContextGraphBuilder(); + var builder = new ResourceGraphBuilder(); builder.AddResource(); // act @@ -117,7 +117,7 @@ public void Attrs_Without_Names_Specified_Will_Use_Configured_Formatter() public void Relationships_Without_Names_Specified_Will_Use_Default_Formatter() { // arrange - var builder = new ContextGraphBuilder(); + var builder = new ResourceGraphBuilder(); builder.AddResource(); // act diff --git a/test/UnitTests/Builders/DocumentBuilder_Tests.cs b/test/UnitTests/Builders/DocumentBuilder_Tests.cs index 3282b8f6f4..d15a44ca4f 100644 --- a/test/UnitTests/Builders/DocumentBuilder_Tests.cs +++ b/test/UnitTests/Builders/DocumentBuilder_Tests.cs @@ -25,7 +25,7 @@ public DocumentBuilder_Tests() _options = new JsonApiOptions(); - _options.BuildContextGraph(builder => + _options.BuildResourceGraph(builder => { builder.AddResource("models"); builder.AddResource("related-models"); @@ -36,8 +36,8 @@ public DocumentBuilder_Tests() .Returns(_options); _jsonApiContextMock - .Setup(m => m.ContextGraph) - .Returns(_options.ContextGraph); + .Setup(m => m.ResourceGraph) + .Returns(_options.ResourceGraph); _jsonApiContextMock .Setup(m => m.MetaBuilder) @@ -54,7 +54,7 @@ public DocumentBuilder_Tests() _jsonApiContextMock .Setup(m => m.RequestEntity) - .Returns(_options.ContextGraph.GetContextEntity(typeof(Model))); + .Returns(_options.ResourceGraph.GetContextEntity(typeof(Model))); } [Fact] @@ -84,11 +84,11 @@ public void Page_Links_Can_Be_Disabled_Globally() _pageManager.TotalRecords = 1; _pageManager.CurrentPage = 1; - _options.BuildContextGraph(builder => builder.DocumentLinks = Link.None); + _options.BuildResourceGraph(builder => builder.DocumentLinks = Link.None); _jsonApiContextMock - .Setup(m => m.ContextGraph) - .Returns(_options.ContextGraph); + .Setup(m => m.ResourceGraph) + .Returns(_options.ResourceGraph); var documentBuilder = new DocumentBuilder(_jsonApiContextMock.Object); var entity = new Model(); @@ -109,8 +109,8 @@ public void Related_Links_Can_Be_Disabled() _pageManager.CurrentPage = 1; _jsonApiContextMock - .Setup(m => m.ContextGraph) - .Returns(_options.ContextGraph); + .Setup(m => m.ResourceGraph) + .Returns(_options.ResourceGraph); var documentBuilder = new DocumentBuilder(_jsonApiContextMock.Object); var entity = new Model(); @@ -130,8 +130,8 @@ public void Related_Data_Included_In_Relationships_By_Default() const string relationshipName = "related-model"; const int relatedId = 1; _jsonApiContextMock - .Setup(m => m.ContextGraph) - .Returns(_options.ContextGraph); + .Setup(m => m.ResourceGraph) + .Returns(_options.ResourceGraph); var documentBuilder = new DocumentBuilder(_jsonApiContextMock.Object); var entity = new Model @@ -162,8 +162,8 @@ public void IndependentIdentifier_Included_In_HasOne_Relationships_By_Default() const string relationshipName = "related-model"; const int relatedId = 1; _jsonApiContextMock - .Setup(m => m.ContextGraph) - .Returns(_options.ContextGraph); + .Setup(m => m.ResourceGraph) + .Returns(_options.ResourceGraph); var documentBuilder = new DocumentBuilder(_jsonApiContextMock.Object); var entity = new Model @@ -268,10 +268,10 @@ IEnumerator IEnumerable.GetEnumerator() public void Build_Will_Use_Resource_If_Defined_For_Multiple_Documents() { var entities = new[] { new User() }; - var contextGraph = new ContextGraphBuilder() + var resourceGraph = new ResourceGraphBuilder() .AddResource("user") .Build(); - _jsonApiContextMock.Setup(m => m.ContextGraph).Returns(contextGraph); + _jsonApiContextMock.Setup(m => m.ResourceGraph).Returns(resourceGraph); var scopedServiceProvider = new TestScopedServiceProvider( new ServiceCollection() @@ -291,10 +291,10 @@ public void Build_Will_Use_Resource_If_Defined_For_Multiple_Documents() public void Build_Will_Use_Resource_If_Defined_For_Single_Document() { var entity = new User(); - var contextGraph = new ContextGraphBuilder() + var resourceGraph = new ResourceGraphBuilder() .AddResource("user") .Build(); - _jsonApiContextMock.Setup(m => m.ContextGraph).Returns(contextGraph); + _jsonApiContextMock.Setup(m => m.ResourceGraph).Returns(resourceGraph); var scopedServiceProvider = new TestScopedServiceProvider( new ServiceCollection() @@ -313,10 +313,10 @@ public void Build_Will_Use_Resource_If_Defined_For_Single_Document() public void Build_Will_Use_Instance_Specific_Resource_If_Defined_For_Multiple_Documents() { var entities = new[] { new User() }; - var contextGraph = new ContextGraphBuilder() + var resourceGraph = new ResourceGraphBuilder() .AddResource("user") .Build(); - _jsonApiContextMock.Setup(m => m.ContextGraph).Returns(contextGraph); + _jsonApiContextMock.Setup(m => m.ResourceGraph).Returns(resourceGraph); var scopedServiceProvider = new TestScopedServiceProvider( new ServiceCollection() @@ -336,10 +336,10 @@ public void Build_Will_Use_Instance_Specific_Resource_If_Defined_For_Multiple_Do public void Build_Will_Use_Instance_Specific_Resource_If_Defined_For_Single_Document() { var entity = new User(); - var contextGraph = new ContextGraphBuilder() + var resourceGraph = new ResourceGraphBuilder() .AddResource("user") .Build(); - _jsonApiContextMock.Setup(m => m.ContextGraph).Returns(contextGraph); + _jsonApiContextMock.Setup(m => m.ResourceGraph).Returns(resourceGraph); var scopedServiceProvider = new TestScopedServiceProvider( new ServiceCollection() diff --git a/test/UnitTests/Controllers/BaseJsonApiController_Tests.cs b/test/UnitTests/Controllers/BaseJsonApiController_Tests.cs index 7327bb18a3..3397aa4eda 100644 --- a/test/UnitTests/Controllers/BaseJsonApiController_Tests.cs +++ b/test/UnitTests/Controllers/BaseJsonApiController_Tests.cs @@ -18,7 +18,7 @@ public class Resource : Identifiable [Attr("test-attribute")] public string TestAttribute { get; set; } } private Mock _jsonApiContextMock = new Mock(); - private Mock _contextGraphMock = new Mock(); + private Mock _resourceGraphMock = new Mock(); [Fact] public async Task GetAsync_Calls_Service() @@ -188,8 +188,8 @@ public async Task PatchAsync_ModelStateInvalid_ValidateModelStateEnabled() const int id = 0; var resource = new Resource(); var serviceMock = new Mock>(); - _jsonApiContextMock.SetupGet(a => a.ContextGraph).Returns(_contextGraphMock.Object); - _contextGraphMock.Setup(a => a.GetPublicAttributeName("TestAttribute")).Returns("test-attribute"); + _jsonApiContextMock.SetupGet(a => a.ResourceGraph).Returns(_resourceGraphMock.Object); + _resourceGraphMock.Setup(a => a.GetPublicAttributeName("TestAttribute")).Returns("test-attribute"); _jsonApiContextMock.Setup(a => a.ApplyContext(It.IsAny>())).Returns(_jsonApiContextMock.Object); _jsonApiContextMock.SetupGet(a => a.Options).Returns(new JsonApiOptions{ValidateModelState = true}); var controller = new BaseJsonApiController(_jsonApiContextMock.Object, update: serviceMock.Object); @@ -266,8 +266,8 @@ public async Task PostAsync_ModelStateInvalid_ValidateModelStateEnabled() // arrange var resource = new Resource(); var serviceMock = new Mock>(); - _jsonApiContextMock.SetupGet(a => a.ContextGraph).Returns(_contextGraphMock.Object); - _contextGraphMock.Setup(a => a.GetPublicAttributeName("TestAttribute")).Returns("test-attribute"); + _jsonApiContextMock.SetupGet(a => a.ResourceGraph).Returns(_resourceGraphMock.Object); + _resourceGraphMock.Setup(a => a.GetPublicAttributeName("TestAttribute")).Returns("test-attribute"); _jsonApiContextMock.Setup(a => a.ApplyContext(It.IsAny>())).Returns(_jsonApiContextMock.Object); _jsonApiContextMock.SetupGet(a => a.Options).Returns(new JsonApiOptions { ValidateModelState = true }); var controller = new BaseJsonApiController(_jsonApiContextMock.Object, create: serviceMock.Object); diff --git a/test/UnitTests/Extensions/IServiceCollectionExtensionsTests.cs b/test/UnitTests/Extensions/IServiceCollectionExtensionsTests.cs index 946c081b62..3b49dda9bf 100644 --- a/test/UnitTests/Extensions/IServiceCollectionExtensionsTests.cs +++ b/test/UnitTests/Extensions/IServiceCollectionExtensionsTests.cs @@ -42,7 +42,7 @@ public void AddJsonApiInternals_Adds_All_Required_Services() Assert.NotNull(provider.GetService()); Assert.NotNull(provider.GetService(typeof(IEntityRepository))); Assert.NotNull(provider.GetService()); - Assert.NotNull(provider.GetService()); + Assert.NotNull(provider.GetService()); Assert.NotNull(provider.GetService()); Assert.NotNull(provider.GetService()); Assert.NotNull(provider.GetService()); @@ -125,7 +125,7 @@ public void AddJsonApi_With_Context_Uses_DbSet_PropertyName_If_NoOtherSpecified( // assert var provider = services.BuildServiceProvider(); - var graph = provider.GetService(); + var graph = provider.GetService(); var resource = graph.GetContextEntity(typeof(IntResource)); Assert.Equal("resource", resource.EntityName); } diff --git a/test/UnitTests/Internal/ContextGraphBuilder_Tests.cs b/test/UnitTests/Internal/ContextGraphBuilder_Tests.cs index 5f56ac0bd8..122b2cd67b 100644 --- a/test/UnitTests/Internal/ContextGraphBuilder_Tests.cs +++ b/test/UnitTests/Internal/ContextGraphBuilder_Tests.cs @@ -6,35 +6,35 @@ namespace UnitTests.Internal { - public class ContextGraphBuilder_Tests + public class ResourceGraphBuilder_Tests { [Fact] public void AddDbContext_Does_Not_Throw_If_Context_Contains_Members_That_DoNot_Implement_IIdentifiable() { // arrange - var contextGraphBuilder = new ContextGraphBuilder(); + var resourceGraphBuilder = new ResourceGraphBuilder(); // act - contextGraphBuilder.AddDbContext(); - var contextGraph = contextGraphBuilder.Build() as ContextGraph; + resourceGraphBuilder.AddDbContext(); + var resourceGraph = resourceGraphBuilder.Build() as ResourceGraph; // assert - Assert.Empty(contextGraph.Entities); + Assert.Empty(resourceGraph.Entities); } [Fact] public void Adding_DbContext_Members_That_DoNot_Implement_IIdentifiable_Creates_Warning() { // arrange - var contextGraphBuilder = new ContextGraphBuilder(); + var resourceGraphBuilder = new ResourceGraphBuilder(); // act - contextGraphBuilder.AddDbContext(); - var contextGraph = contextGraphBuilder.Build() as ContextGraph; + resourceGraphBuilder.AddDbContext(); + var resourceGraph = resourceGraphBuilder.Build() as ResourceGraph; // assert - Assert.Single(contextGraph.ValidationResults); - Assert.Contains(contextGraph.ValidationResults, v => v.LogLevel == LogLevel.Warning); + Assert.Single(resourceGraph.ValidationResults); + Assert.Contains(resourceGraph.ValidationResults, v => v.LogLevel == LogLevel.Warning); } private class Foo { } diff --git a/test/UnitTests/Models/ResourceDefinitionTests.cs b/test/UnitTests/Models/ResourceDefinitionTests.cs index e7a1e75dcf..f058dbc946 100644 --- a/test/UnitTests/Models/ResourceDefinitionTests.cs +++ b/test/UnitTests/Models/ResourceDefinitionTests.cs @@ -10,11 +10,11 @@ namespace UnitTests.Models { public class ResourceDefinition_Scenario_Tests { - private readonly IContextGraph _graph; + private readonly IResourceGraph _graph; public ResourceDefinition_Scenario_Tests() { - _graph = new ContextGraphBuilder() + _graph = new ResourceGraphBuilder() .AddResource("models") .Build(); } diff --git a/test/UnitTests/Serialization/JsonApiDeSerializerTests.cs b/test/UnitTests/Serialization/JsonApiDeSerializerTests.cs index 9ea44cd6dd..f1cdcdc1e6 100644 --- a/test/UnitTests/Serialization/JsonApiDeSerializerTests.cs +++ b/test/UnitTests/Serialization/JsonApiDeSerializerTests.cs @@ -19,13 +19,13 @@ public class JsonApiDeSerializerTests public void Can_Deserialize_Complex_Types() { // arrange - var contextGraphBuilder = new ContextGraphBuilder(); - contextGraphBuilder.AddResource("test-resource"); - var contextGraph = contextGraphBuilder.Build(); + var resourceGraphBuilder = new ResourceGraphBuilder(); + resourceGraphBuilder.AddResource("test-resource"); + var resourceGraph = resourceGraphBuilder.Build(); var jsonApiContextMock = new Mock(); jsonApiContextMock.SetupAllProperties(); - jsonApiContextMock.Setup(m => m.ContextGraph).Returns(contextGraph); + jsonApiContextMock.Setup(m => m.ResourceGraph).Returns(resourceGraph); jsonApiContextMock.Setup(m => m.AttributesToUpdate).Returns(new Dictionary()); var jsonApiOptions = new JsonApiOptions(); @@ -58,13 +58,13 @@ public void Can_Deserialize_Complex_Types() public void Can_Deserialize_Complex_List_Types() { // arrange - var contextGraphBuilder = new ContextGraphBuilder(); - contextGraphBuilder.AddResource("test-resource"); - var contextGraph = contextGraphBuilder.Build(); + var resourceGraphBuilder = new ResourceGraphBuilder(); + resourceGraphBuilder.AddResource("test-resource"); + var resourceGraph = resourceGraphBuilder.Build(); var jsonApiContextMock = new Mock(); jsonApiContextMock.SetupAllProperties(); - jsonApiContextMock.Setup(m => m.ContextGraph).Returns(contextGraph); + jsonApiContextMock.Setup(m => m.ResourceGraph).Returns(resourceGraph); jsonApiContextMock.Setup(m => m.AttributesToUpdate).Returns(new Dictionary()); var jsonApiOptions = new JsonApiOptions(); jsonApiOptions.SerializerSettings.ContractResolver = new CamelCasePropertyNamesContractResolver(); @@ -97,13 +97,13 @@ public void Can_Deserialize_Complex_List_Types() public void Can_Deserialize_Complex_Types_With_Dasherized_Attrs() { // arrange - var contextGraphBuilder = new ContextGraphBuilder(); - contextGraphBuilder.AddResource("test-resource"); - var contextGraph = contextGraphBuilder.Build(); + var resourceGraphBuilder = new ResourceGraphBuilder(); + resourceGraphBuilder.AddResource("test-resource"); + var resourceGraph = resourceGraphBuilder.Build(); var jsonApiContextMock = new Mock(); jsonApiContextMock.SetupAllProperties(); - jsonApiContextMock.Setup(m => m.ContextGraph).Returns(contextGraph); + jsonApiContextMock.Setup(m => m.ResourceGraph).Returns(resourceGraph); jsonApiContextMock.Setup(m => m.AttributesToUpdate).Returns(new Dictionary()); var jsonApiOptions = new JsonApiOptions(); @@ -138,15 +138,15 @@ public void Can_Deserialize_Complex_Types_With_Dasherized_Attrs() public void Immutable_Attrs_Are_Not_Included_In_AttributesToUpdate() { // arrange - var contextGraphBuilder = new ContextGraphBuilder(); - contextGraphBuilder.AddResource("test-resource"); - var contextGraph = contextGraphBuilder.Build(); + var resourceGraphBuilder = new ResourceGraphBuilder(); + resourceGraphBuilder.AddResource("test-resource"); + var resourceGraph = resourceGraphBuilder.Build(); var attributesToUpdate = new Dictionary(); var jsonApiContextMock = new Mock(); jsonApiContextMock.SetupAllProperties(); - jsonApiContextMock.Setup(m => m.ContextGraph).Returns(contextGraph); + jsonApiContextMock.Setup(m => m.ResourceGraph).Returns(resourceGraph); jsonApiContextMock.Setup(m => m.AttributesToUpdate).Returns(attributesToUpdate); var jsonApiOptions = new JsonApiOptions(); @@ -187,14 +187,14 @@ public void Immutable_Attrs_Are_Not_Included_In_AttributesToUpdate() public void Can_Deserialize_Independent_Side_Of_One_To_One_Relationship() { // arrange - var contextGraphBuilder = new ContextGraphBuilder(); - contextGraphBuilder.AddResource("independents"); - contextGraphBuilder.AddResource("dependents"); - var contextGraph = contextGraphBuilder.Build(); + var resourceGraphBuilder = new ResourceGraphBuilder(); + resourceGraphBuilder.AddResource("independents"); + resourceGraphBuilder.AddResource("dependents"); + var resourceGraph = resourceGraphBuilder.Build(); var jsonApiContextMock = new Mock(); jsonApiContextMock.SetupAllProperties(); - jsonApiContextMock.Setup(m => m.ContextGraph).Returns(contextGraph); + jsonApiContextMock.Setup(m => m.ResourceGraph).Returns(resourceGraph); jsonApiContextMock.Setup(m => m.AttributesToUpdate).Returns(new Dictionary()); var jsonApiOptions = new JsonApiOptions(); @@ -226,14 +226,14 @@ public void Can_Deserialize_Independent_Side_Of_One_To_One_Relationship() public void Can_Deserialize_Independent_Side_Of_One_To_One_Relationship_With_Relationship_Body() { // arrange - var contextGraphBuilder = new ContextGraphBuilder(); - contextGraphBuilder.AddResource("independents"); - contextGraphBuilder.AddResource("dependents"); - var contextGraph = contextGraphBuilder.Build(); + var resourceGraphBuilder = new ResourceGraphBuilder(); + resourceGraphBuilder.AddResource("independents"); + resourceGraphBuilder.AddResource("dependents"); + var resourceGraph = resourceGraphBuilder.Build(); var jsonApiContextMock = new Mock(); jsonApiContextMock.SetupAllProperties(); - jsonApiContextMock.Setup(m => m.ContextGraph).Returns(contextGraph); + jsonApiContextMock.Setup(m => m.ResourceGraph).Returns(resourceGraph); jsonApiContextMock.Setup(m => m.AttributesToUpdate).Returns(new Dictionary()); jsonApiContextMock.Setup(m => m.HasOneRelationshipPointers).Returns(new HasOneRelationshipPointers()); @@ -277,14 +277,14 @@ public void Can_Deserialize_Independent_Side_Of_One_To_One_Relationship_With_Rel public void Sets_The_DocumentMeta_Property_In_JsonApiContext() { // arrange - var contextGraphBuilder = new ContextGraphBuilder(); - contextGraphBuilder.AddResource("independents"); - contextGraphBuilder.AddResource("dependents"); - var contextGraph = contextGraphBuilder.Build(); + var resourceGraphBuilder = new ResourceGraphBuilder(); + resourceGraphBuilder.AddResource("independents"); + resourceGraphBuilder.AddResource("dependents"); + var resourceGraph = resourceGraphBuilder.Build(); var jsonApiContextMock = new Mock(); jsonApiContextMock.SetupAllProperties(); - jsonApiContextMock.Setup(m => m.ContextGraph).Returns(contextGraph); + jsonApiContextMock.Setup(m => m.ResourceGraph).Returns(resourceGraph); jsonApiContextMock.Setup(m => m.AttributesToUpdate).Returns(new Dictionary()); var jsonApiOptions = new JsonApiOptions(); @@ -352,14 +352,14 @@ private class Dependent : Identifiable public void Can_Deserialize_Object_With_HasManyRelationship() { // arrange - var contextGraphBuilder = new ContextGraphBuilder(); - contextGraphBuilder.AddResource("independents"); - contextGraphBuilder.AddResource("dependents"); - var contextGraph = contextGraphBuilder.Build(); + var resourceGraphBuilder = new ResourceGraphBuilder(); + resourceGraphBuilder.AddResource("independents"); + resourceGraphBuilder.AddResource("dependents"); + var resourceGraph = resourceGraphBuilder.Build(); var jsonApiContextMock = new Mock(); jsonApiContextMock.SetupAllProperties(); - jsonApiContextMock.Setup(m => m.ContextGraph).Returns(contextGraph); + jsonApiContextMock.Setup(m => m.ResourceGraph).Returns(resourceGraph); jsonApiContextMock.Setup(m => m.AttributesToUpdate).Returns(new Dictionary()); jsonApiContextMock.Setup(m => m.HasManyRelationshipPointers).Returns(new HasManyRelationshipPointers()); @@ -405,14 +405,14 @@ public void Can_Deserialize_Object_With_HasManyRelationship() public void Sets_Attribute_Values_On_Included_HasMany_Relationships() { // arrange - var contextGraphBuilder = new ContextGraphBuilder(); - contextGraphBuilder.AddResource("independents"); - contextGraphBuilder.AddResource("dependents"); - var contextGraph = contextGraphBuilder.Build(); + var resourceGraphBuilder = new ResourceGraphBuilder(); + resourceGraphBuilder.AddResource("independents"); + resourceGraphBuilder.AddResource("dependents"); + var resourceGraph = resourceGraphBuilder.Build(); var jsonApiContextMock = new Mock(); jsonApiContextMock.SetupAllProperties(); - jsonApiContextMock.Setup(m => m.ContextGraph).Returns(contextGraph); + jsonApiContextMock.Setup(m => m.ResourceGraph).Returns(resourceGraph); jsonApiContextMock.Setup(m => m.AttributesToUpdate).Returns(new Dictionary()); jsonApiContextMock.Setup(m => m.HasManyRelationshipPointers).Returns(new HasManyRelationshipPointers()); @@ -469,14 +469,14 @@ public void Sets_Attribute_Values_On_Included_HasMany_Relationships() public void Sets_Attribute_Values_On_Included_HasOne_Relationships() { // arrange - var contextGraphBuilder = new ContextGraphBuilder(); - contextGraphBuilder.AddResource("independents"); - contextGraphBuilder.AddResource("dependents"); - var contextGraph = contextGraphBuilder.Build(); + var resourceGraphBuilder = new ResourceGraphBuilder(); + resourceGraphBuilder.AddResource("independents"); + resourceGraphBuilder.AddResource("dependents"); + var resourceGraph = resourceGraphBuilder.Build(); var jsonApiContextMock = new Mock(); jsonApiContextMock.SetupAllProperties(); - jsonApiContextMock.Setup(m => m.ContextGraph).Returns(contextGraph); + jsonApiContextMock.Setup(m => m.ResourceGraph).Returns(resourceGraph); jsonApiContextMock.Setup(m => m.AttributesToUpdate).Returns(new Dictionary()); jsonApiContextMock.Setup(m => m.RelationshipsToUpdate).Returns(new Dictionary()); jsonApiContextMock.Setup(m => m.HasManyRelationshipPointers).Returns(new HasManyRelationshipPointers()); @@ -530,12 +530,12 @@ public void Sets_Attribute_Values_On_Included_HasOne_Relationships() public void Can_Deserialize_Nested_Included_HasMany_Relationships() { // arrange - var contextGraphBuilder = new ContextGraphBuilder(); - contextGraphBuilder.AddResource("independents"); - contextGraphBuilder.AddResource("dependents"); - contextGraphBuilder.AddResource("many-to-manys"); + var resourceGraphBuilder = new ResourceGraphBuilder(); + resourceGraphBuilder.AddResource("independents"); + resourceGraphBuilder.AddResource("dependents"); + resourceGraphBuilder.AddResource("many-to-manys"); - var deserializer = GetDeserializer(contextGraphBuilder); + var deserializer = GetDeserializer(resourceGraphBuilder); var contentString = @"{ @@ -661,13 +661,13 @@ public void Can_Deserialize_Nested_Included_HasMany_Relationships() // Assert.NotEqual(result.ManyToManys[0].Independent, result.ManyToManys[1].Independent); } - private JsonApiDeSerializer GetDeserializer(ContextGraphBuilder contextGraphBuilder) + private JsonApiDeSerializer GetDeserializer(ResourceGraphBuilder resourceGraphBuilder) { - var contextGraph = contextGraphBuilder.Build(); + var resourceGraph = resourceGraphBuilder.Build(); var jsonApiContextMock = new Mock(); jsonApiContextMock.SetupAllProperties(); - jsonApiContextMock.Setup(m => m.ContextGraph).Returns(contextGraph); + jsonApiContextMock.Setup(m => m.ResourceGraph).Returns(resourceGraph); jsonApiContextMock.Setup(m => m.AttributesToUpdate).Returns(new Dictionary()); jsonApiContextMock.Setup(m => m.RelationshipsToUpdate).Returns(new Dictionary()); jsonApiContextMock.Setup(m => m.HasManyRelationshipPointers).Returns(new HasManyRelationshipPointers()); diff --git a/test/UnitTests/Serialization/JsonApiSerializerTests.cs b/test/UnitTests/Serialization/JsonApiSerializerTests.cs index c6b4a09128..c781617d03 100644 --- a/test/UnitTests/Serialization/JsonApiSerializerTests.cs +++ b/test/UnitTests/Serialization/JsonApiSerializerTests.cs @@ -21,10 +21,10 @@ public class JsonApiSerializerTests public void Can_Serialize_Complex_Types() { // arrange - var contextGraphBuilder = new ContextGraphBuilder(); - contextGraphBuilder.AddResource("test-resource"); + var resourceGraphBuilder = new ResourceGraphBuilder(); + resourceGraphBuilder.AddResource("test-resource"); - var serializer = GetSerializer(contextGraphBuilder); + var serializer = GetSerializer(resourceGraphBuilder); var resource = new TestResource { @@ -69,13 +69,13 @@ public void Can_Serialize_Complex_Types() public void Can_Serialize_Deeply_Nested_Relationships() { // arrange - var contextGraphBuilder = new ContextGraphBuilder(); - contextGraphBuilder.AddResource("test-resource"); - contextGraphBuilder.AddResource("children"); - contextGraphBuilder.AddResource("infections"); + var resourceGraphBuilder = new ResourceGraphBuilder(); + resourceGraphBuilder.AddResource("test-resource"); + resourceGraphBuilder.AddResource("children"); + resourceGraphBuilder.AddResource("infections"); var serializer = GetSerializer( - contextGraphBuilder, + resourceGraphBuilder, included: new List { "children.infections" } ); @@ -206,16 +206,16 @@ public void Can_Serialize_Deeply_Nested_Relationships() } private JsonApiSerializer GetSerializer( - ContextGraphBuilder contextGraphBuilder, + ResourceGraphBuilder resourceGraphBuilder, List included = null) { - var contextGraph = contextGraphBuilder.Build(); + var resourceGraph = resourceGraphBuilder.Build(); var jsonApiContextMock = new Mock(); jsonApiContextMock.SetupAllProperties(); - jsonApiContextMock.Setup(m => m.ContextGraph).Returns(contextGraph); + jsonApiContextMock.Setup(m => m.ResourceGraph).Returns(resourceGraph); jsonApiContextMock.Setup(m => m.Options).Returns(new JsonApiOptions()); - jsonApiContextMock.Setup(m => m.RequestEntity).Returns(contextGraph.GetContextEntity("test-resource")); + jsonApiContextMock.Setup(m => m.RequestEntity).Returns(resourceGraph.GetContextEntity("test-resource")); // jsonApiContextMock.Setup(m => m.AttributesToUpdate).Returns(new Dictionary()); // jsonApiContextMock.Setup(m => m.RelationshipsToUpdate).Returns(new Dictionary()); // jsonApiContextMock.Setup(m => m.HasManyRelationshipPointers).Returns(new HasManyRelationshipPointers()); diff --git a/test/UnitTests/Services/EntityResourceService_Tests.cs b/test/UnitTests/Services/EntityResourceService_Tests.cs index 0f27f70924..4380a6622b 100644 --- a/test/UnitTests/Services/EntityResourceService_Tests.cs +++ b/test/UnitTests/Services/EntityResourceService_Tests.cs @@ -19,9 +19,9 @@ public class EntityResourceService_Tests public EntityResourceService_Tests() { _jsonApiContextMock - .Setup(m => m.ContextGraph) + .Setup(m => m.ResourceGraph) .Returns( - new ContextGraphBuilder() + new ResourceGraphBuilder() .AddResource("todo-items") .Build() ); diff --git a/test/UnitTests/Services/Operations/OperationsProcessorResolverTests.cs b/test/UnitTests/Services/Operations/OperationsProcessorResolverTests.cs index 1e7026f2ee..6ebfc0bda5 100644 --- a/test/UnitTests/Services/Operations/OperationsProcessorResolverTests.cs +++ b/test/UnitTests/Services/Operations/OperationsProcessorResolverTests.cs @@ -24,7 +24,7 @@ public OperationProcessorResolverTests() public void LocateCreateService_Throws_400_For_Entity_Not_Registered() { // arrange - _jsonApiContextMock.Setup(m => m.ContextGraph).Returns(new ContextGraphBuilder().Build()); + _jsonApiContextMock.Setup(m => m.ResourceGraph).Returns(new ResourceGraphBuilder().Build()); var service = GetService(); var op = new Operation { @@ -43,7 +43,7 @@ public void LocateCreateService_Throws_400_For_Entity_Not_Registered() public void LocateGetService_Throws_400_For_Entity_Not_Registered() { // arrange - _jsonApiContextMock.Setup(m => m.ContextGraph).Returns(new ContextGraphBuilder().Build()); + _jsonApiContextMock.Setup(m => m.ResourceGraph).Returns(new ResourceGraphBuilder().Build()); var service = GetService(); var op = new Operation { @@ -62,7 +62,7 @@ public void LocateGetService_Throws_400_For_Entity_Not_Registered() public void LocateRemoveService_Throws_400_For_Entity_Not_Registered() { // arrange - _jsonApiContextMock.Setup(m => m.ContextGraph).Returns(new ContextGraphBuilder().Build()); + _jsonApiContextMock.Setup(m => m.ResourceGraph).Returns(new ResourceGraphBuilder().Build()); var service = GetService(); var op = new Operation { @@ -81,7 +81,7 @@ public void LocateRemoveService_Throws_400_For_Entity_Not_Registered() public void LocateUpdateService_Throws_400_For_Entity_Not_Registered() { // arrange - _jsonApiContextMock.Setup(m => m.ContextGraph).Returns(new ContextGraphBuilder().Build()); + _jsonApiContextMock.Setup(m => m.ResourceGraph).Returns(new ResourceGraphBuilder().Build()); var service = GetService(); var op = new Operation { diff --git a/test/UnitTests/Services/Operations/Processors/CreateOpProcessorTests.cs b/test/UnitTests/Services/Operations/Processors/CreateOpProcessorTests.cs index 274fda556b..73f9c272b9 100644 --- a/test/UnitTests/Services/Operations/Processors/CreateOpProcessorTests.cs +++ b/test/UnitTests/Services/Operations/Processors/CreateOpProcessorTests.cs @@ -44,7 +44,7 @@ public async Task ProcessAsync_Deserializes_And_Creates() Data = data, }; - var contextGraph = new ContextGraphBuilder() + var resourceGraph = new ResourceGraphBuilder() .AddResource("test-resources") .Build(); @@ -55,7 +55,7 @@ public async Task ProcessAsync_Deserializes_And_Creates() _createServiceMock.Object, _deserializerMock.Object, _documentBuilderMock.Object, - contextGraph + resourceGraph ); _documentBuilderMock.Setup(m => m.GetData(It.IsAny(), It.IsAny()))