Has anybody considered the best approach when writing unit tests for the ViewModelComposition spike that has been introduced to the prism drops?
The issue I came across is that to register a DataTemplate resource we use the pack URI syntax. This requires you to create a Uri with,
When running the executable application, WPF is initialized and there are no problems. Unfortunately when executing unit tests, WPF is not initialized and the .Net Uri parser does not know about the pack syntax (you get a UriFormatException). Try creating
a new unit test that creates a pack uri as above! As far as I can tell, the initialization actually happens in the PackUriHelper static constructor. Since PackUriHelper is a static class and all methods expect to take a pack Uri, the only way for me to force
the static constructor to run is to call a method with a different Uri scheme, and catch the exception.
My current solution is to register a generic uri parser myself at the start of every test that would require it (code below). This seems a bit of a hack? Any guidance on a better method?
UriParser.Register(new GenericUriParser(GenericUriParserOptions.GenericAuthority), "pack", -1);