Hi guys,
We're trying to set up some unit tests to test some custom code using the Dynamicweb API but hit a few roadblocks. For example, something like this will crash:
var order = new Order();
because the order instantiates a new PriceIInfo which tries to initialize its Currency field from Context.Currency. Since this context is missing during unit tests, we get a null reference exception.
If I recall correctly you mentioned earlier that stuff like HttpContext has been abstracted in order to allow unit testing (and other scenarios). That led to the discovery of IContext class and methods like SetDefaultContext. However, after implementing our own IContext and ISession, the following still fails:
var priceInfo = default(PriceInfo); var exception = default(Exception); Dynamicweb.Context.SetDefaultContext(new TestContext()); // Our own implementation of IContext Dynamicweb.Ecommerce.Common.Context.Currency = new Currency(); // Should assign to our Context, but doesn't // Act try { priceInfo = new PriceInfo(); } catch (Exception ex) { exception = ex; } // Assert Assert.NotNull(priceInfo); Assert.Null(exception);
Are we on the right track? Can you provide some guidance / pointers on how to make this work?
Thanks in advance,
Imar