Mocking derived class with abstract base class
Hi, I have the following setup:
Now I would like to unit test GetSomeStuff, and ensuring correct HTTP status codes are returned based on response from .GetAsync() method. How would I unit test this?
**BASE CLASS**
public abstract class SomeBaseAbstractClass<TItem, TResponse>
{
protected EctocloudCosmosRepository(IMapper mapper, IRepository<TItem> repository, ILogger logger)
{
_mapper = mapper;
_repository = repository;
_logger = logger;
}
public async Task<TResponse> GetAsync(string id, CancellationToken token)
{
// some logic removed for brevity
}
}
**IMPLEMENTED CLASS**
public class Repository : SomeBaseAbstractClass<Item, Response>
{
// ctor
// methods
}
**CONTROLLER**
public async Task<ActionResult> GetSomeStuff(
[FromRoute] string id,
[FromServices] Repository repository)
{
var response = await repository.GetAsync(id, HttpContext.RequestAborted);
return HandleResponse(response);
}**BASE CLASS**
public abstract class SomeBaseAbstractClass<TItem, TResponse>
{
protected EctocloudCosmosRepository(IMapper mapper, IRepository<TItem> repository, ILogger logger)
{
_mapper = mapper;
_repository = repository;
_logger = logger;
}
public async Task<TResponse> GetAsync(string id, CancellationToken token)
{
// some logic removed for brevity
}
}
**IMPLEMENTED CLASS**
public class Repository : SomeBaseAbstractClass<Item, Response>
{
// ctor
// methods
}
**CONTROLLER**
public async Task<ActionResult> GetSomeStuff(
[FromRoute] string id,
[FromServices] Repository repository)
{
var response = await repository.GetAsync(id, HttpContext.RequestAborted);
return HandleResponse(response);
}Now I would like to unit test GetSomeStuff, and ensuring correct HTTP status codes are returned based on response from .GetAsync() method. How would I unit test this?