dimanche 27 août 2017

Testing masstransit consumer

I am trying to test masstransit consumer my consumer look like this:

public class FilePolicyEvaluationConsumer : IFilePolicyEvaluationConsumer
{
    public readonly IFilePolicyEvaluationCore _filePolicyEvaluationCore;
    public readonly IRepositoryClient _repositoryClient;
    public readonly IFPRepository _fPRepository;

    public FilePolicyEvaluationConsumer()
    {

    }

    public FilePolicyEvaluationConsumer(IFilePolicyEvaluationCore filePolicyEvaluationCore, IRepositoryClient repositoryClient, IFPRepository fPRepository)
    {
        _filePolicyEvaluationCore = filePolicyEvaluationCore;
        _repositoryClient = repositoryClient;
        _fPRepository = fPRepository;
    }

    public  Task Consume(ConsumeContext<InvokePolicyOnFileMessage> context)
    {
        return Task.Run( async () => {
            Guid fileId = context.Message.FileId;
            FileMetadata fileMetaData = await  _repositoryClient.GetFileMetadata(fileId);
            _filePolicyEvaluationCore.Run(fileMetaData, context.Message.CorrelationId);
        });

    }

but when i configure the test like this

_harness = new InMemoryTestHarness();
        FilePolicyEvaluationConsumer filePolicy = new FilePolicyEvaluationConsumer(); 
        _consumer = _harness.Consumer<FilePolicyEvaluationConsumer>();


        await _harness.Start();
        await _harness.InputQueueSendEndpoint.Send(message1);

when i enter in the test to consumer all objects _filePolicyEvaluationCore,_repositoryClient,_fPRepository in the consumer are null, how can i inject to this objects?

Aucun commentaire:

Enregistrer un commentaire