mimo
mimo

Reputation: 6827

Stub generic Interface with MS Fakes

How to create a Stub IRepository<TModel>? I have 3 interfaces:

namespace DataAccessLayer.Repository.Interfaces 
{
    public interface IRepository<TModel> : IDisposable {...}
    public interface ICustomerRepository : IRepository<CustomerModel> {...}
    public interface IRepositoryContainer {...}
}

My DataAccessLayer.fakes looks as follows:

<StubGeneration>
    <Clear/>
    <Add FullName="DataAccessLayer.Repository.Interfaces.IRepositoryContainer!"/>
    <Add FullName="DataAccessLayer.Repository.Interfaces.IRiadRepository!"/>
    <Add FullName="DataAccessLayer.Repository.Interfaces.IRepository!"/>
</StubGeneration>

In my unit tests I can see StubIRepositoryContainer and also ICustomerRepository, but stub for IRepository<TModel> is not generated.

Thanks.

Upvotes: 0

Views: 333

Answers (1)

doobop
doobop

Reputation: 4520

I think your name filtering is too limited. Try removing the '!' from IRepository line in your fakes configuration file.

<Add FullName="DataAccessLayer.Repository.Interfaces.IRepository"/>

That raises the question if the syntax will allow filtering with the '!'. The couple of variations I tried did not work ("IRepository!TModel"). Here's some information about Parameter Naming Type Conventions.

Upvotes: 1

Related Questions