microsoft / microsoft/aspire

Have ServiceEndpointResolver implement an interface

Open
#4,229 0 comments 0 reactions 0 assignees View on GitHub
area-service-discovery
Dominant language
C#
Stars
6.3k
Forks
991
Avg merge
2d 15h
Merged PRs (30d)
196

Description

### Details of issue
In my aspnet core application I am utilising dependency injection to provide ServiceEndpointResolver in the constructor of my controllers which works as expected for my application. However now that I am reviewing my unit tests, all the controllers which utilise ServiceEndpointResolver as an argument are failing even after using Moq to create the parameter for the constructor.

using the mock repository results in the below error
` System.NotSupportedException: Type to Mock (ServiceEndpointResolver) must be an interface, a delegate or a non-sealed, non-static class.`

Attempting to use Nsubsitute results in the below error
` System.NotSupportedException: Parent does not have a default constructore. The default constructor must be explicitly defined.`

What i would like to make it easier for developers is if ServiceEndpointResolver was an implementation of IServiceEndpointResolver to allow for test cases to easily be implemented and pass.

### Workaround available
Implementation of a dedicated constructor without ServiceEndpointResolver and additional code in class to handle the null case.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.