Starting to implement unit tests in C#, using MSTest
In this particular test I am trying to verify that an ArgumentNullException
is being thrown. Even though my code does throw the exception my test is failing because it apparently did not receive that type of exception.
Where am I going wrong? Bound to be something simple....
My test looks like this:
[TestMethod()]
[ExpectedException(typeof(ArgumentNullException), "A null HttpContent was inappropriately allowed")]
public void Test_HttpContent_Null_Throws_Exception()
{
MultipartFormDataMemoryStreamProvider provider = new MultipartFormDataMemoryStreamProvider();
Assert.ThrowsException<ArgumentNullException>(()=>provider.GetStream(null, null));
}
And the GetStreams()
method looks like this:
public override Stream GetStream(HttpContent parent, HttpContentHeaders headers)
{
if (parent == null)
throw new ArgumentNullException("parent");
if (headers == null)
throw new ArgumentNullException("headers");
var contentDisposition = headers.ContentDisposition;
if (contentDisposition == null)
throw new InvalidOperationException("Did not find required 'Content-Disposition' header field in MIME multipart body part.");
_isFormData.Add(String.IsNullOrEmpty(contentDisposition.FileName));
return base.GetStream(parent, headers);
}