I am trying to write unit tests for my new payment provider, but I am finding that OrderContext.MetaDataContext is null.
I'm sure I'm missing something fairly simple, but cannot work out what it is.
Any help would be greatly appreciated.
When moving into unit test project you have to copy like Web.Config from your Web project to the unit test App.Config. Make sure that all Mediachase config files and other config files also goes into the Unit test project.
What I´m guessing is that you are missing some Config files and then you may not have initilized the Order context.
We also experienced issues with licensing (especially when you touch some of the meta data parts). Forgot the details but issue was either license issused based on IP or MAC didn't work in unit tests.
Hmm, I have run EpiServer Commerce within a Console Application, Unit test, totally outside the Context of the Commerce IIS web application. I don´t recall any issue except when you forget to copy config files, settings, license files etc or when a context isn´t initilized correctly.
If you want to go more into Unit Test with EpiServer you can take a look on these
You need two things.1 . configs file should be with bin2. SQL Context is null and you will need to set that. Pseudo code is like this
if sqlcontext is null
Initialize sqlcontext.I hope this will help and solve the issue.
For anyone reading this, we've been working on a massive comemrce build and one of the better ways we found to test everythign was instead of trying to get things like the metadata context to workk under test. We created wrappers for all the big parts of the system. It's not ideal but after you have wrappers fo the main components life gets a lot easer, I wrote about the experience here
How To Unit Test EpiServer Commerce