If I have something like this:
static class ManifestGenerator
{
public static void GenerateManifestFile(){
var doc = new XDocument();
...
... xml stuff added to doc
...
doc.Save(manifestFilePath)
}
Now can you please tell me how can I create a unit test that will ensure that the method generates correct xml?
How can I mock XDocument (I am using Moq), without adding additional parameters to the method call
Don’t try to mock
XDocument. That’s not the problem here – it’s the access to the file system which is annoying. You could pass in aStreamto write the manifest to instead:Then you can test that with a
MemoryStream, but use aFileStreamto the manifest path in reality. You might even make this method internal (using[InternalsVisibleTo]so you can still access it from tests) and a public parameterless overload along the lines of:You then don’t test that code, but you can test all your real logic.