I'm trying to figure out how to test this scenario and coming up blank.
I have a listener service that will trigger the following when a file is detected in a mailslot:
IEventDispatcher _dispatcher;
IListener _mailslotListener;
public Service (IEventDispatcher dispatcher, IMailslotListener mailslotListener) {
_dispatcher = dispatcher;
_mailslotListener = mailslotListener;
}
public async void _Listener_OnFileDetected(object sender, MailslotArgs) {
string filePath = args.Message;
Directory.CreateDirectory(TempLocation);
FileId = Guid.NewGuid();
string tempPath = Path.Combine(TempLocation, FileId.ToString());
File.Move(filePath, tempPath);
await _dispatcher.DispatchEvent("documentPrinted", FileId);
}
This will move the file passed in to a temp location and rename it with a Guid. In my test, I'm trying to verify that the file was moved successfully, but I'm not sure how to access the Guid used and passed to the _dispatcher.DispatchEvent call.
I'm able to verify that the event was raised, but that's as far as I've gotten as the value being a random Guid seems to be an issue when asserting equality in the test.
[Test]
public void OnFileDetected_CallsDispatchEvent()
{
Directory.CreateDirectory(tempPath);
listenerService._Listener_OnFileDetected(null, new MailslotArgs(testFilePath));
mockEventDispatcher.Verify(m => m.DispatchEvent("fileDetected",
It.IsAny<Guid>()),
Times.Once);
}