Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test.Initialize fails to start after upgrading to NServiceBus 5.2.0 #20

Closed
janovesk opened this issue Feb 13, 2015 · 18 comments
Closed
Labels
Milestone

Comments

@janovesk
Copy link
Contributor

Who's affected

Anybody using NServiceBus.Testing in their unit tests combined with NServiceBus 5.2.0.

Symptoms

Test.Initialize fails to run. It throws a KeyNotFoundException.

Issue

FakeTestTransport is not overriding Configure from TransportDefinition to enable the FakeTestTransportConfigurer. This means no LocalAdress is setup, which makes UnicastBus throw when it tries to get it.

SetUp : System.Collections.Generic.KeyNotFoundException : The given key (NServiceBus.LocalAddress) was not present in the dictionary.
   at NServiceBus.Settings.SettingsHolder.Get(String key) in c:\BuildAgent\work\3206e2123f54fce4\src\NServiceBus.Core\Settings\SettingsHolder.cs: line 23
   at NServiceBus.Features.UnicastBus.Setup(FeatureConfigurationContext context) in c:\BuildAgent\work\3206e2123f54fce4\src\NServiceBus.Core\Unicast\Config\UnicastBus.cs: line 45
   at NServiceBus.Features.FeatureActivator.ActivateFeature(FeatureState featureState, IEnumerable`1 featuresToActivate, FeatureConfigurationContext context) in c:\BuildAgent\work\3206e2123f54fce4\src\NServiceBus.Core\Features\FeatureActivator.cs: line 235
   at NServiceBus.Features.FeatureActivator.SetupFeatures(FeatureConfigurationContext context) in c:\BuildAgent\work\3206e2123f54fce4\src\NServiceBus.Core\Features\FeatureActivator.cs: line 116
   at NServiceBus.Configure.Initialize() in c:\BuildAgent\work\3206e2123f54fce4\src\NServiceBus.Core\Configure.cs: line 115
   at NServiceBus.Testing.Test.Initialize(Action`1 customisations) in c:\BuildAgent\work\1b05a2fea6e4cd32\src\NServiceBus.Testing\Test.cs: line 55
   at FailingTestInitialise.Class1.Test_initialise() in Class1.cs: line 12

Issue initially reported by Henrik Røn in the Google Group: https://groups.google.com/forum/#!topic/particularsoftware/424_6KCv6oI

@janovesk janovesk self-assigned this Feb 13, 2015
@danielmarbach
Copy link
Contributor

Can you also define a milestone for the hotfix? // @andreasohlund

@Henrik-R
Copy link

If you start fixes this issue you might as well look into the WARN logged about encryption not being set-up properly in the same exception.

2015-02-13 12:17:45.970 WARN NServiceBus.Features.Encryptor You have configured a encryption service via either ConfigurationBuilder.RijndaelEncryptionService or ConfigurationBuilder.RegisterEncryptionService however no properties were found on type that require encryption.
Perhaps you forgot to define your encryption message conventions or to define message properties using as WireEncryptedString.
2015-02-13 12:17:45.970 WARN NServiceBus.Features.Encryptor You have configured a encryption service via either ConfigurationBuilder.RijndaelEncryptionService or ConfigurationBuilder.RegisterEncryptionService however no properties were found on type that require encryption.
Perhaps you forgot to define your encryption message conventions or to define message properties using as WireEncryptedString.

@SeanFeldman SeanFeldman added this to the 5.0.4 milestone Feb 13, 2015
@SeanFeldman
Copy link
Contributor

Fixed by commit f761c53

@OnamChilwan
Copy link

Is this fixed now? I have 5.2.0 installed as well as 5.0.4 for NServiceBus.Testing and am experiencing the same issue.

@SeanFeldman
Copy link
Contributor

@OnamChilwan released with 5.0.4 Are you still having this issue? If you do, could you please provide repro?

@pablocastilla
Copy link

In this version we can not initialize the Test.Initialize without scanning. In 5.0.3 we did this:
Test.Initialize(a => a.TypesToScan(new List()));

Now, in 5.0.4, it gives the exception reported in this issue.

We need to work that way because of how TFS executes the unit tests.

@OnamChilwan
Copy link

Yes I am still experiencing this issue unfortunately. If you need further details then more than happy to do so. Just for reference, my package contains

package id="Moq" version="4.2.1408.0717" targetFramework="net40"
package id="NServiceBus" version="5.2.0" targetFramework="net45"
package id="NServiceBus.Testing" version="5.0.4" targetFramework="net45"
package id="NUnit" version="2.6.4" targetFramework="net45"

@janovesk
Copy link
Contributor Author

@OnamChilwan and @pablocastilla : Would you be able to provide a reproduction for us? Either upoload to gihub or just paste a failing test + the version of NServiceBus and NServiceBus.Testing here.

@OnamChilwan
Copy link

Will do. The problem exists in production ready code which I am moving across to another solution. Shouldn't be too long.

@janovesk
Copy link
Contributor Author

@pablocastilla : I'm pretty sure you can work around your issue by using Test.Initialize(a => a.AssembliesToScan(Assembly.LoadFrom("NServiceBus.Testing.dll")));

@pablocastilla
Copy link

@janovesk I get an "Interface Not Found" exception if I do that.

@janovesk
Copy link
Contributor Author

@pablocastilla Can you give me a repro and/or the entire message exception?

public void ShouldNotThrowWithExplicitLoadOfNServiceBusTesting()
{
    Assert.DoesNotThrow(() => Test.Initialize(a => a.AssembliesToScan(Assembly.LoadFrom("NServiceBus.Testing.dll"))));
}

is working here, so I'm puzzled by why you're getting an exception.

@OnamChilwan
Copy link

Uploaded to https://github.com/OnamChilwan/TestIssue. If you run the unit test I have only the one in there but there are 2 static methods. One which creates the KeyNotFound exception and another which informs me I must use a concrete type. Though the latter is not so important.

@pablocastilla
Copy link

@janovesk It works... sorry, it was the test what failed :)

@janovesk
Copy link
Contributor Author

janovesk commented Mar 1, 2015

Hi @OnamChilwan!

Thanks for providing the reproduction.

The real issue here is that NServiceBus.Testing.dll needs to be scanned by the Test.Initialize() code to initialize properly. If you use the Test.Initialize() with no parameters, it will default to scan all in the current directory. That works. If you override the assemblies scanned either by AssembliesToScan() or TypesToScan() and DO NOT include NServiceBus.Testing.dll, if will fail.

For now you can work around the problem by including NserviceBus.Testing.dll in the list of assemblies you scan on start-up. For example by changing GetAssembliesToScan() to

 private static IEnumerable<Assembly> GetAssembliesToScan()
 {
     return new[]
     {
         AssemblyFromType<IAllOrderItemsCancelledV2>(),
         Assembly.LoadFrom("NServiceBus.Testing.dll")
     };
 }

It should no longer throw a KeyNotFound exception.

I'm looking into how we will fix this permanently in NServiceBus.Testing.

BTW: The exception with the concrete type is because you are using an interface based event in your handler without providing the event conventions to Test.Initialize(). That is not related to this error. Fix it by simply making sure you register the event convention.

@janovesk janovesk reopened this Mar 1, 2015
@janovesk
Copy link
Contributor Author

janovesk commented Mar 2, 2015

This will be fixed by a better way of handling assembly scanning in a future version of NServiceBus. I recommend using the workarounds mentioned until then.

@janovesk janovesk closed this as completed Mar 2, 2015
@OnamChilwan
Copy link

Brilliant thank you very much. That works a treat now though I imagine as you said its a workaround this will change in the next update so that NServiceBus.Testing doesn't need to be included in the assembly scanning?

EDIT

Just saw your post which answers my question.

@andreasohlund andreasohlund added this to the 5.0.4 milestone Oct 21, 2015
@andreasohlund andreasohlund reopened this Oct 21, 2015
@andreasohlund
Copy link
Member

This was reintroduced when we released core v5.0.5 since we had forgot to remove the projects from the core support-5.0 branch. Re-releasing this as 5.0.7

@andreasohlund andreasohlund modified the milestones: 5.0.7, 5.0.4 Oct 21, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

8 participants