2

I'm upgrading an old project to DD4T 2.5 & Tridion 9.5 and it had some unit tests in NUnit.

I replaced the dependency injection with DD4T.DI.Autofac so instead of registering everything ourselves I just call UseDD4T() in the setup of the unit tests.

Unfortunately when I run the tests I get an error:

System.IO.DirectoryNotFoundException : Could not find part of the path 'R:\path\to\ProjectFolder.Tests\bin\Debug\bin'.

I checked the code DD4T.DI.Autofac: https://github.com/dd4t/DD4T.DI.Autofac/blob/develop/source/DD4T.DI.Autofac/Bootstrap.cs

I see they're using this to get the assemblies.

var binDirectory = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "bin");

When running the application this works fine, but for unit testing it's giving this error. Does anybody know a fix?

1 Answer 1

3

The DD4T.DI.Autofac module only works when you are running it inside a web application. According to some, you should not use dependency injection frameworks inside a unit test at all (see https://stackoverflow.com/questions/32594803/using-di-container-in-unit-tests for example).

I noticed someone (probably you, Rory?) created an issue for this in github. We will have a look at it, it shouldn't be too hard to make it work within NUnit also. If you want to make the DD4T community happy, you could fix that one line yourself and submit a pull request. That is definitely the fastest option!

2
  • Thanks for the help, I've created a PR for a fix. I've also checked out the link you've provided. I'll adjust the unit tests to not use the DI, but I'll leave the PR there anyway. Could you take a look at my other issue with DD4T.Model? github.com/dd4t/DD4T.Model/issues/44 github.com/dd4t/DD4T.Model/pull/45 I think my fix there might be a bit too sloppy, but I didn't look into it anymore since nobody was replying.
    – Rory
    Commented Apr 25, 2022 at 15:49
  • For the DD4T.Model I created a new fix that I think is better, I was also able to reproduce the issue through the unit tests.
    – Rory
    Commented Apr 26, 2022 at 9:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.