I'm using Microsoft.VisualStudio.TestTools.UnitTesting
for unit testing.
I have this test which asserts that an exception was thrown and it is failing
[TestMethod]
public async Task ShouldThrowHttpExceptionIfPassedObjectIsNull()
{
_mockLogger = new Mock<ILogger<DataService>>();
// setup memoryCache
object expected = null;
_mockNullMemoryCache = MockMemoryCacheService.GetNullMemoryCache(expected);
_mockSessionManagementService = new MockSessionManagementService();
_ds = new DataService(
_mockLogger.Object,
_mockNullMemoryCache.Object,
_mockSessionManagementService
);
Assert.ThrowsException<HttpException>(() => _ds.RetrieveFileData<object>(_incorrectFilePath, false));
}
When I debug it, the last line of code to run before it errors out and fails is this:
The exception ex
is a system.invalidOperationException
but that shouldn't matter because it throws an HttpException not matter what. Why is the test failing with the reason:
Test Name: ShouldThrowHttpExceptionIfPassedObjectIsNull Test FullName: xxx.xxx.xxx.xxx.ShouldThrowHttpExceptionIfPassedObjectIsNull Test Source: C:\Users\xxx\xxx.cs : line 88 Test Outcome: Failed Test Duration: 0:04:35.5251661
Result StackTrace: at xxxxxx.d__10.MoveNext() in C:\Users\xxx\xxx\xxx.cs:line 101 --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) Result Message: Assert.ThrowsException failed. No exception thrown. HttpException exception was expected.
EDIT The code then moves into this code block after the image:
else
{
// Parsing issue
_logger.LogError(string.Format("Id={0}, Could not retrieve data from {1} : Malformed source data", _sessionManagementService.SessionId, url));
throw new HttpException(HttpStatusCode.InternalServerError, "Malformed source data", true);
}
As it is throwing the HttpException above, it throws a DllNotFoundException.
Exception thrown: 'System.DllNotFoundException' in System.Private.CoreLib.ni.dll
Additional information: Unable to load DLL 'combase.dll': The specified module could not be found. (Exception from HRESULT: 0x8007007E)