|
| 1 | +using AideClinicalReview; |
| 2 | +using Microsoft.Extensions.DependencyInjection; |
| 3 | +using Microsoft.Extensions.Logging; |
| 4 | +using Monai.Deploy.Messaging.API; |
| 5 | +using Monai.Deploy.Messaging.Events; |
| 6 | +using Monai.Deploy.WorkflowManager.TaskManager.AideClinicalReview; |
| 7 | +using Monai.Deploy.WorkflowManager.TaskManager.API; |
| 8 | +using Monai.Deploy.Messaging.Common; |
| 9 | +using Moq; |
| 10 | +using Xunit; |
| 11 | + |
| 12 | +namespace TaskManager.AideClinicalReview.Tests |
| 13 | +{ |
| 14 | + public class AideClinicalReviewPluginTests |
| 15 | + { |
| 16 | + private readonly Mock<ILogger<AideClinicalReviewPlugin>> _logger; |
| 17 | + private readonly Mock<IMessageBrokerPublisherService> _messageBrokerPublisherService; |
| 18 | + private readonly Mock<IServiceScopeFactory> _serviceScopeFactory; |
| 19 | + private readonly Mock<IServiceScope> _serviceScope; |
| 20 | + |
| 21 | + public AideClinicalReviewPluginTests() |
| 22 | + { |
| 23 | + _logger = new Mock<ILogger<AideClinicalReviewPlugin>>(); |
| 24 | + _messageBrokerPublisherService = new Mock<IMessageBrokerPublisherService>(); |
| 25 | + _serviceScopeFactory = new Mock<IServiceScopeFactory>(); |
| 26 | + _serviceScope = new Mock<IServiceScope>(); |
| 27 | + |
| 28 | + _serviceScopeFactory.Setup(p => p.CreateScope()).Returns(_serviceScope.Object); |
| 29 | + |
| 30 | + var serviceProvider = new Mock<IServiceProvider>(); |
| 31 | + |
| 32 | + _serviceScope.Setup(x => x.ServiceProvider).Returns(serviceProvider.Object); |
| 33 | + |
| 34 | + _logger.Setup(p => p.IsEnabled(It.IsAny<LogLevel>())).Returns(true); |
| 35 | + } |
| 36 | + |
| 37 | + [Fact(DisplayName = "Throws when missing required plug-in arguments")] |
| 38 | + public void AideClinicalReviewPlugin_ThrowsWhenMissingPluginArguments() |
| 39 | + { |
| 40 | + var message = GenerateTaskDispatchEvent(); |
| 41 | + Assert.Throws<InvalidTaskException>(() => new AideClinicalReviewPlugin(_serviceScopeFactory.Object, _messageBrokerPublisherService.Object, _logger.Object, message)); |
| 42 | + |
| 43 | + foreach (var key in Keys.RequiredParameters.Take(Keys.RequiredParameters.Count - 1)) |
| 44 | + { |
| 45 | + message.TaskPluginArguments.Add(key, Guid.NewGuid().ToString()); |
| 46 | + Assert.Throws<InvalidTaskException>(() => new AideClinicalReviewPlugin(_serviceScopeFactory.Object, _messageBrokerPublisherService.Object, _logger.Object, message)); |
| 47 | + } |
| 48 | + } |
| 49 | + |
| 50 | + private static TaskDispatchEvent GenerateTaskDispatchEventWithValidArguments() |
| 51 | + { |
| 52 | + var message = GenerateTaskDispatchEvent(); |
| 53 | + message.TaskPluginArguments[Keys.QueueName] = "queue-name"; |
| 54 | + message.TaskPluginArguments[Keys.WorkflowName] = "workflowName"; |
| 55 | + message.TaskPluginArguments[Keys.PatientName] = "patientname"; |
| 56 | + message.TaskPluginArguments[Keys.PatientId] = "patientid"; |
| 57 | + message.TaskPluginArguments[Keys.PatientDob] = "patientdob"; |
| 58 | + message.TaskPluginArguments[Keys.PatientSex] = "patientsex"; |
| 59 | + message.TaskPluginArguments[Keys.ReviewedTaskDetails] = "taskdetails"; |
| 60 | + return message; |
| 61 | + } |
| 62 | + |
| 63 | + private static TaskDispatchEvent GenerateTaskDispatchEvent() |
| 64 | + { |
| 65 | + var message = new TaskDispatchEvent |
| 66 | + { |
| 67 | + CorrelationId = Guid.NewGuid().ToString(), |
| 68 | + ExecutionId = Guid.NewGuid().ToString(), |
| 69 | + TaskPluginType = Guid.NewGuid().ToString(), |
| 70 | + WorkflowInstanceId = Guid.NewGuid().ToString(), |
| 71 | + TaskId = Guid.NewGuid().ToString(), |
| 72 | + IntermediateStorage = new Storage |
| 73 | + { |
| 74 | + Name = Guid.NewGuid().ToString(), |
| 75 | + Endpoint = Guid.NewGuid().ToString(), |
| 76 | + Credentials = new Credentials |
| 77 | + { |
| 78 | + AccessKey = Guid.NewGuid().ToString(), |
| 79 | + AccessToken = Guid.NewGuid().ToString() |
| 80 | + }, |
| 81 | + Bucket = Guid.NewGuid().ToString(), |
| 82 | + RelativeRootPath = Guid.NewGuid().ToString(), |
| 83 | + } |
| 84 | + }; |
| 85 | + message.Inputs.Add(new Storage |
| 86 | + { |
| 87 | + Name = "input-dicom", |
| 88 | + Endpoint = Guid.NewGuid().ToString(), |
| 89 | + Credentials = new Credentials |
| 90 | + { |
| 91 | + AccessKey = Guid.NewGuid().ToString(), |
| 92 | + AccessToken = Guid.NewGuid().ToString() |
| 93 | + }, |
| 94 | + Bucket = Guid.NewGuid().ToString(), |
| 95 | + RelativeRootPath = Guid.NewGuid().ToString(), |
| 96 | + }); |
| 97 | + message.Inputs.Add(new Storage |
| 98 | + { |
| 99 | + Name = "input-ehr", |
| 100 | + Endpoint = Guid.NewGuid().ToString(), |
| 101 | + Credentials = new Credentials |
| 102 | + { |
| 103 | + AccessKey = Guid.NewGuid().ToString(), |
| 104 | + AccessToken = Guid.NewGuid().ToString() |
| 105 | + }, |
| 106 | + Bucket = Guid.NewGuid().ToString(), |
| 107 | + RelativeRootPath = Guid.NewGuid().ToString(), |
| 108 | + }); |
| 109 | + message.Outputs.Add(new Storage |
| 110 | + { |
| 111 | + Name = "output", |
| 112 | + Endpoint = Guid.NewGuid().ToString(), |
| 113 | + Credentials = new Credentials |
| 114 | + { |
| 115 | + AccessKey = Guid.NewGuid().ToString(), |
| 116 | + AccessToken = Guid.NewGuid().ToString() |
| 117 | + }, |
| 118 | + Bucket = Guid.NewGuid().ToString(), |
| 119 | + RelativeRootPath = Guid.NewGuid().ToString(), |
| 120 | + }); |
| 121 | + return message; |
| 122 | + } |
| 123 | + } |
| 124 | +} |
0 commit comments