c# - Moq Callback is fine in first test, but same code returns null in second test -


would know why, when using moq in 2 tests have following code:

var magentochannelmock = new mock<imagentochannel>();  var magentochannelmock = new mock<imagentochannel>();  magentochannelmock.setup(x => x.salesorderinvoicecreate(it.isany<string>(), "2", it.isany<orderitemidqty[]>(), it.isany<string>(), it.isany<string>(), it.isany<string>()))                 .callback<string, string, orderitemidqty[], string, string, string>((s1, s2, x, s3, s4, s5) => invoicessent = x); 

i have 2 tests in test class, when run each individually, run fine , callback object "invoicessent" contains expected value. when run both tests @ same time, second test run gets null returned callback.

any idea?

[test] public void invoice_3line_qtythatisinvoicedshouldbe12() {     //arrange     orderitemidqty[] invoicessent = null;     var magentochannelmock = new mock<imagentochannel>();      magentochannelmock.setup(x => x.salesorderinfo(it.isany<string>(), it.isany<string>()))                       .returns(new salesorderentity() { items = new salesorderitementity[] { new salesorderitementity() { qty_ordered = "12", item_id = "1", sku = "sku123" } } });     magentochannelmock.setup(x => x.salesorderinvoicecreate(it.isany<string>(), "2", it.isany<orderitemidqty[]>(), it.isany<string>(), it.isany<string>(), it.isany<string>()))         .callback<string, string, orderitemidqty[], string, string, string>((s1, s2, x, s3, s4, s5) => invoicessent = x);      testprojioccontainer.container().registerinstance( magentochannelmock.object);      var magentoapirepository = testprojioccontainer.resolveobjectfortesting<imagentoapirepository>();      var orderlineitem = new orderlineitem{quantity = 4, material = new material{sku = "sku123"},channellineitemreference = "123"};      var testinvoice = new list<invoiceline>         {             new invoiceline(orderlineitem),             new invoiceline(orderlineitem),             new invoiceline(orderlineitem)         };      //act     magentoapirepository.createorderinvoice("2", testinvoice);      //assert     assert.areequal(testinvoice.sum(x=>x.quantity), (int)invoicessent.sum(x=>x.qty) ); }    [test] public void invoice_1line_qty4() {     //arrange     orderitemidqty[] invoicessent = null;     var magentochannelmock = new mock<imagentochannel>();      magentochannelmock.setup(x => x.salesorderinfo(it.isany<string>(), it.isany<string>()))                       .returns(new salesorderentity() { items = new salesorderitementity[] { new salesorderitementity() { qty_ordered = "12", item_id = "1", sku = "sku123" } } });     magentochannelmock.setup(x => x.salesorderinvoicecreate(it.isany<string>(), it.isany<string>(), it.isany<orderitemidqty[]>(), it.isany<string>(), it.isany<string>(), it.isany<string>()))         .callback<string, string, orderitemidqty[], string, string, string>((s1, s2, x, s3, s4, s5) => invoicessent = x);      testprojioccontainer.container().registerinstance(typeof(imagentochannel), "", magentochannelmock.object, new hierarchicallifetimemanager());      var magentoapirepository = testprojioccontainer.resolveobjectfortesting<imagentoapirepository>();      var orderlineitem = new orderlineitem { quantity = 4, material = new material { sku = "sku123" }, channellineitemreference = "123" };      var testinvoice = new list<invoiceline>         {             new invoiceline(orderlineitem)         };      //act     magentoapirepository.createorderinvoice("1", testinvoice);      //assert     assert.areequal(4, (int)invoicessent.sum(x => x.qty)); } 


Comments

Popular posts from this blog

qt - Using float or double for own QML classes -

Create Outlook appointment via C# .Net -

ios - Swift Array Resetting Itself -