c# - MassTransit consumer hard to test -


i having 2 issues testing masstransit consumers:

  1. sync issue
  2. messagedata

the first 1 this:

var testconsumer = testfactory.forconsumer<imageuploadconsumer>().new(                 test =>                 {                     test.useconsumerfactory(new instanceconsumerfactory<imageuploadconsumer>(imageconsumer));                                         test.publish(message, (scenario, context) =>                     {                      });                                     });              testconsumer.execute(); //is non blocking 

the following line (below) fails, because line:

        moqfilemetarepo.verify(_ => _.add(it.isany<ifilemeta>()),times.once );  

is executed 9.9/10 before... line ever did:

    public async task consume(consumecontext<imageuploadwiththumb> context) 

my fix has been do

moqfilemetarepo             .setup(repo => repo.add(it.isany<ifilemeta>()))             .callback(() => { autoevent.set(); }); 

and call following before assert:

autoevent.waitone(timespan.fromseconds(10)); 

which lot of work. , makes tdd or testing in general hassle, fear going ignored on time.

messagedata issue one. here's payload i'm sending through

        message = new imageuploadwiththumb()         {             id = guid.newguid(),             filename = "test.jpg",             user = "me",             extension = "jpg",             originalimage = new constantmessagedata<byte[]>(new uri("https://g00gle.com"), new byte[] { 1, 2, 3 })         }; 

i'm expecting byte[] { 1, 2, 3 } on other end without having resort creating actual persistence.

instead: got error

on sender side messagedata.value resolves ok. consumer totally bombs. works in prod though =_= not testing should be.

i want mock , unittest consumer w/o having wrestle framework - preferably in under 5 mins or so. there way out while sticking mt3?

i suggest looking @ masstransit.testframework package. require nunit, take classes , port own test framework.

all of masstransit unit tests written using fixtures in framework. original .testing namespace in world of hurt right not, didn't survive , i'm unsure it's working completely. wasn't designed async, difficult transition without trashing entirely.


Comments

Popular posts from this blog

matlab - error with cyclic autocorrelation function -

django - (fields.E300) Field defines a relation with model 'AbstractEmailUser' which is either not installed, or is abstract -

c# - What is a good .Net RefEdit control to use with ExcelDna? -