Could not find concrete type mapped to ... #nservicebus #ncrunch

Know your tools. Today, I learned that to successfully run NServiceBus tests through NCrunch - and this is really related to the IoC aspects of NServiceBus why it's not product specific - you need to do a little more with regards to your test setup than just doing

Test.Initialize();

I ran into the following output in the NCrunch error window:

System.ArgumentException: Could not find a concrete type mapped to IfInsurance....IPolicyActivatedMessage
   at NServiceBus.MessageInterfaces.MessageMapper.Reflection.MessageMapper.CreateInstance(Type t)
   at NServiceBus.MessageInterfaces.MessageMapper.Reflection.MessageMapper.CreateInstance[T]()
   at NServiceBus.MessageInterfaces.MessageMapper.Reflection.MessageMapper.CreateInstance[T](Action`1 action)
   at NServiceBus.Testing.StubBus.CreateInstance[T](Action`1 action) in c:\BuildAgent\work\d4de8921a0aabf04\src\testing\StubBus.cs:line 242
   at NServiceBus.Testing.Handler`1.OnMessage[TMessage](String messageId, Action`1 initializeMessage) in c:\BuildAgent\work\d4de8921a0aabf04\src\testing\Handler.cs:line 241
   at NServiceBus.Testing.Handler`1.OnMessage[TMessage](Action`1 initializeMessage) in c:\BuildAgent\work\d4de8921a0aabf04\src\testing\Handler.cs:line 230
   at IfInsurance.Motor.MessagingService.UnitTest.PolicyProcesses.PolicyActivatedMessageHandlerTests.Handle_WhenMessageDoesNotContainBuinessDomainMotor_DoNothing() in ...

... and this even with the unit test working just fine when running through another test runner (ReSharper in this case):

Funky, huh? 

As it turns out, to successfully make them play along, you need to configure your test assembly runner to load any dependencies you might need. Pretty self-explanatory when spelled out, but it sure took me a while to find the root cause of this issue! Anyway, right-click your test assembly in the NCrunch runner window and choose to Configure selected component.


Then, add your dependencies (the messaging contracts assemblies in my case) as Additional files to include.


With that out of the way, NCrunch should be in line with your other test runner and, hopefully, you're happier. ;-) 


Comments

Popular posts from this blog

Auto Mapper and Record Types - will they blend?

Unit testing your Azure functions - part 2: Queues and Blobs

Testing WCF services with user credentials and binary endpoints