Skip to content

Make ModelledResponse<T> testable #94

Open
@jackwalkernz

Description

@jackwalkernz

Feature request

Is your feature request related to a problem? Please describe.

Hi. I am trying to unit test the this library and I am coming across the issue of ModeledResponse<T> not being testable.

ModeledResponse<T> does not have a parameterless constructor, meaning that a framework like NSubstitute or Moq cannot create a proxy object easily.

ModeledResponse<T>.Trip/ModeledResponse<T>.Trips are both inaccessible properties making them unusable using a Mock wrapper like what Moq does (see below).

_myMock.Setup(obj => obj.Trip = fakeTripInstance)

Describe the solution you'd like

I would like for either ModeledResponse<T> to have a parameterless constructor and for the JSON deserialization process to happen outside the constructor, or for the behaviour to be contained within some kind of class outside of ModeledResponse<T>.

An alternative is to have ModeledResponse<T> inherit from a new abstraction IModeledResponse<T> where T : BaseModel.

This is probably preferred as it doesn't require a reconsideration of how conversions are handled. This would also mean that IPostgrestTable<T> and Table<T> would need their response types to be updated respectively.

Describe alternatives you've considered

I have tried numerous mocking frameworks with these classes and how their are configured means they are very sealed and unmockable.

Happy to make a PR if need be 😃

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions