I have implemented a command/query architecture for a project I am working on, but am having trouble testing my classes that require use of the associated factories. The basis of my architecture can be found here: http://ift.tt/XWiswO
In particular, I have something similar to the following
public interface IQueryFactory
{
TQuery CreateQuery<TQuery, TResult>()
where TQuery : IQuery<TResult>;
}
public interface IQuery<TResult>
{
}
public interface IQueryHandler<in TQuery, out TResult>
where TQuery : IQuery<TResult>
{
TResult Execute(TQuery query);
}
public interface IQueryHandlerFactory
{
IQueryHandler<TQuery, TResult> CreateQueryHandler<TQuery, TResult>()
where TQuery : IQuery<TResult>;
}
public class GetFooDataQuery : IQuery<IEnumerable<FooData>>
{
public int FooId { get; set; }
}
public class GetFooQueryHandler : IQueryHandler<GetFooDataQuery, IEnumerable<FooData>>
{
private readonly IFooRepository _fooRepository;
public GetFooDataQueryHandler(IFooRepository fooRepository)
{
_fooRepository = fooRepository;
}
public IEnumerable<FooData> Execute(GetFooDataQuery query)
{
return _fooRepository.Foo.Where(x => x.fooId > query.FooId).ToList();
}
}
My classes that need to query the database have a constructor that includes a query factory and a query handler factory. Everything gets wired up via Ninject.
It works fine, but I am finding it difficult to create Unit tests for any class that includes query factories as I need to include the factories as part of the constructor. Any help would be greatly appreciated.
Aucun commentaire:
Enregistrer un commentaire