Skip to content

Improve Testability #251

Closed
Closed
@jaredcnance

Description

@jaredcnance

A primary goal of this task is to make it easy to write end to end tests without thinking about json:api.

    public class MockJsonApiContextFactory
    {
        public static Mock<IJsonApiContext> GetWithSingleResource<TResource, TId>() 
            where TResource : class, IIdentifiable<TId>
        {
            var resourceGraph = new ResourceGraphBuilder()
                .AddResource<TResource, TId>()
                .Build();

            var requestEntity = resourceGraph.GetContextEntity(typeof(TResource));
            var jsonApiContextMock = new Mock<IJsonApiContext>();
            jsonApiContextMock.Setup(c => c.ResourceGraph).Returns(resourceGraph);
            jsonApiContextMock.Setup(c => c.RequestEntity).Returns(requestEntity);
            return jsonApiContextMock;
        }
    }
  • Consider adding "enhanced exception messages" if the environment is test (or something along those lines)

https://github.com/json-api-dotnet/JsonApiDotNetCore/blob/master/test/UnitTests/TestScopedServiceProvider.cs

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions