Skip to content

Improve Testability #251

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
jaredcnance opened this issue Apr 5, 2018 · 1 comment
Closed

Improve Testability #251

jaredcnance opened this issue Apr 5, 2018 · 1 comment

Comments

@jaredcnance
Copy link
Contributor

jaredcnance commented Apr 5, 2018

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

@maurei
Copy link
Member

maurei commented Oct 10, 2019

JsonApiContext does no longer exist. #558. This greatly improves testability.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

No branches or pull requests

2 participants