A few weeks ago I jumped on MEND (ComponentModel), and now I use it for a lot of my plugins, as well as for shared libraries. All in all, it was wonderful aside from the frequent errors on my part, which led to frustrating debugging sessions.
In any case, my application works fine, but my code changes related to MEF led to the failure of my automatic builds. Most of my unit tests were unsuccessful simply because the modules I tested depended on other modules that MEF had to load. I worked on these situations, bypassing MEF and directly creating these objects.
In other words, through MEF I will have something like
[Import] public ICandyInterface ci { get; set; }
and
[Export(typeof(ICandyInterface))] public class MyCandy : ICandyInterface { [ImportingConstructor] public MyCandy( [Import("name_param")] string name) {} ... }
But in my unit tests, I would just use
CandyInterface MyCandy = new CandyInterface( "Godiva");
In addition, CandyInterface requires a connection to the database I was working with, simply adding a test database to my unit test folder, and I have NUnit for all tests.
So here are my questions regarding this situation:
- Is this a bad way to do something?
- You recommend composing parts in [SetUp]
- I have not yet learned how to use mocks in unit testing - is this a good example of the case when I could mock a basic database connection (somehow) just to return dummy data and not require a database?
- If you have encountered something similar before, can you offer your experience and how you solved your problem? (or should it go into the wiki community?)
Dave source share