I have a basic test case that puts together a Delta object to pass to my controller's 'PATCH' action which I am able to do successfully. My test code is as follows
[TestMethod]
public async Task Patch_Product()
{
// Act
var delta = new Delta<Product>(typeof(Product));
delta.TrySetPropertyValue("Name", "PatchedProduct");
delta.TrySetPropertyValue("Comment", "A test Product that has been patched");
var result = await productController.Patch(1, delta);
// Assert
Assert.IsNotNull(result);
}
The moment the code hits the first line in the Patch action which is as follows
Validate(patch.GetEntity());
It fails with the following exception: System.InvalidOperationException: ApiController.Configuration must not be null.
I verified that the ApiController.Configuration is in fact null for all of my other tests as well for GET, POST, DELETE etc. However none of these controller action call the 'Validate()' method which is where this exception is thrown. Has anyone encountered this before? Is there a way to get a test against PATCH work by potentially mocking the context?
I tried passing in a blank configuration as well in my test as follows:
productController.Configuration = new HttpConfiguration();
But this does not seem to work either. I get this exception:
System.IO.FileNotFoundException: Could not load file or assembly 'Newtonsoft.Json, Version=6.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed' or one of its dependencies. The system cannot find the file specified.