Skip to content

Commit

Permalink
Fix unit test
Browse files Browse the repository at this point in the history
Signed-off-by: Neil South <[email protected]>
  • Loading branch information
mocsharp committed Aug 17, 2023
1 parent fa9dbeb commit 22c23d2
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*/

using System;
using System.Reflection;
using System.Threading.Tasks;
using FellowOakDicom;
using Microsoft.Extensions.DependencyInjection;
Expand All @@ -36,7 +37,7 @@ public class ExternalAppIncoming : IInputDataPlugin
private readonly IServiceScopeFactory _serviceScopeFactory;
private readonly PluginConfiguration _options;

public string Name => "Remote App Execution Incoming";
public string Name => GetType().GetCustomAttribute<PluginNameAttribute>()?.Name ?? GetType().Name;
public ExternalAppIncoming(
ILogger<ExternalAppIncoming> logger,
IServiceScopeFactory serviceScopeFactory,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*/

using System;
using System.Reflection;
using System.Threading;
using System.Threading.Tasks;
using FellowOakDicom;
Expand All @@ -36,7 +37,7 @@ public class ExternalAppOutgoing : IOutputDataPlugin
private readonly IServiceScopeFactory _serviceScopeFactory;
private readonly PluginConfiguration _options;

public string Name => "Remote App Execution Outgoing";
public string Name => GetType().GetCustomAttribute<PluginNameAttribute>()?.Name ?? GetType().Name;

public ExternalAppOutgoing(
ILogger<ExternalAppOutgoing> logger,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,11 @@
using System;
using System.Collections.Generic;
using System.IO.Abstractions;
using System.Reflection;
using Microsoft.Extensions.Logging;
using Monai.Deploy.InformaticsGateway.Api;
using Monai.Deploy.InformaticsGateway.Common;
using Monai.Deploy.InformaticsGateway.ExecutionPlugins;
using Monai.Deploy.InformaticsGateway.Services.Common;
using Monai.Deploy.InformaticsGateway.SharedTest;
using Monai.Deploy.InformaticsGateway.Test.Plugins;
Expand Down Expand Up @@ -52,17 +54,19 @@ public void RegisteredPlugins_WhenCalled_ReturnsListOfPlugins()
p => VerifyPlugin(p, typeof(TestInputDataPluginAddWorkflow)),
p => VerifyPlugin(p, typeof(TestInputDataPluginResumeWorkflow)),
p => VerifyPlugin(p, typeof(TestInputDataPluginModifyDicomFile)),
p => VerifyPlugin(p, typeof(TestInputDataPluginVirtualAE)));
p => VerifyPlugin(p, typeof(TestInputDataPluginVirtualAE)),
p => VerifyPlugin(p, typeof(ExternalAppIncoming)));

_logger.VerifyLogging($"{typeof(IInputDataPlugin).Name} data plug-in found {typeof(TestInputDataPluginAddWorkflow).Name}: {typeof(TestInputDataPluginAddWorkflow).GetShortTypeAssemblyName()}.", LogLevel.Information, Times.Once());
_logger.VerifyLogging($"{typeof(IInputDataPlugin).Name} data plug-in found {typeof(TestInputDataPluginResumeWorkflow).Name}: {typeof(TestInputDataPluginResumeWorkflow).GetShortTypeAssemblyName()}.", LogLevel.Information, Times.Once());
_logger.VerifyLogging($"{typeof(IInputDataPlugin).Name} data plug-in found {typeof(TestInputDataPluginModifyDicomFile).Name}: {typeof(TestInputDataPluginModifyDicomFile).GetShortTypeAssemblyName()}.", LogLevel.Information, Times.Once());
_logger.VerifyLogging($"{typeof(IInputDataPlugin).Name} data plug-in found {typeof(TestInputDataPluginVirtualAE).Name}: {typeof(TestInputDataPluginVirtualAE).GetShortTypeAssemblyName()}.", LogLevel.Information, Times.Once());
_logger.VerifyLogging($"{typeof(IInputDataPlugin).Name} data plug-in found {typeof(TestInputDataPluginAddWorkflow).GetCustomAttribute<PluginNameAttribute>()?.Name}: {typeof(TestInputDataPluginAddWorkflow).GetShortTypeAssemblyName()}.", LogLevel.Information, Times.Once());
_logger.VerifyLogging($"{typeof(IInputDataPlugin).Name} data plug-in found {typeof(TestInputDataPluginResumeWorkflow).GetCustomAttribute<PluginNameAttribute>()?.Name}: {typeof(TestInputDataPluginResumeWorkflow).GetShortTypeAssemblyName()}.", LogLevel.Information, Times.Once());
_logger.VerifyLogging($"{typeof(IInputDataPlugin).Name} data plug-in found {typeof(TestInputDataPluginModifyDicomFile).GetCustomAttribute<PluginNameAttribute>()?.Name}: {typeof(TestInputDataPluginModifyDicomFile).GetShortTypeAssemblyName()}.", LogLevel.Information, Times.Once());
_logger.VerifyLogging($"{typeof(IInputDataPlugin).Name} data plug-in found {typeof(TestInputDataPluginVirtualAE).GetCustomAttribute<PluginNameAttribute>()?.Name}: {typeof(TestInputDataPluginVirtualAE).GetShortTypeAssemblyName()}.", LogLevel.Information, Times.Once());
_logger.VerifyLogging($"{typeof(IInputDataPlugin).Name} data plug-in found {typeof(ExternalAppIncoming).GetCustomAttribute<PluginNameAttribute>()?.Name}: {typeof(ExternalAppIncoming).GetShortTypeAssemblyName()}.", LogLevel.Information, Times.Once());
}

private void VerifyPlugin(KeyValuePair<string, string> values, Type type)
{
Assert.Equal(values.Key, type.Name);
Assert.Equal(values.Key, type.GetCustomAttribute<PluginNameAttribute>()?.Name);
Assert.Equal(values.Value, type.GetShortTypeAssemblyName());
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,11 @@
using System;
using System.Collections.Generic;
using System.IO.Abstractions;
using System.Reflection;
using Microsoft.Extensions.Logging;
using Monai.Deploy.InformaticsGateway.Api;
using Monai.Deploy.InformaticsGateway.Common;
using Monai.Deploy.InformaticsGateway.ExecutionPlugins;
using Monai.Deploy.InformaticsGateway.Services.Common;
using Monai.Deploy.InformaticsGateway.SharedTest;
using Monai.Deploy.InformaticsGateway.Test.Plugins;
Expand Down Expand Up @@ -50,15 +52,18 @@ public void RegisteredPlugins_WhenCalled_ReturnsListOfPlugins()

Assert.Collection(result,
p => VerifyPlugin(p, typeof(TestOutputDataPluginAddMessage)),
p => VerifyPlugin(p, typeof(TestOutputDataPluginModifyDicomFile)));
p => VerifyPlugin(p, typeof(TestOutputDataPluginModifyDicomFile)),
p => VerifyPlugin(p, typeof(ExternalAppOutgoing))
);

_logger.VerifyLogging($"{typeof(IOutputDataPlugin).Name} data plug-in found {typeof(TestOutputDataPluginAddMessage).Name}: {typeof(TestOutputDataPluginAddMessage).GetShortTypeAssemblyName()}.", LogLevel.Information, Times.Once());
_logger.VerifyLogging($"{typeof(IOutputDataPlugin).Name} data plug-in found {typeof(TestOutputDataPluginModifyDicomFile).Name}: {typeof(TestOutputDataPluginModifyDicomFile).GetShortTypeAssemblyName()}.", LogLevel.Information, Times.Once());
_logger.VerifyLogging($"{typeof(IOutputDataPlugin).Name} data plug-in found {typeof(TestOutputDataPluginAddMessage).GetCustomAttribute<PluginNameAttribute>()?.Name}: {typeof(TestOutputDataPluginAddMessage).GetShortTypeAssemblyName()}.", LogLevel.Information, Times.Once());
_logger.VerifyLogging($"{typeof(IOutputDataPlugin).Name} data plug-in found {typeof(TestOutputDataPluginModifyDicomFile).GetCustomAttribute<PluginNameAttribute>()?.Name}: {typeof(TestOutputDataPluginModifyDicomFile).GetShortTypeAssemblyName()}.", LogLevel.Information, Times.Once());
_logger.VerifyLogging($"{typeof(IOutputDataPlugin).Name} data plug-in found {typeof(ExternalAppOutgoing).GetCustomAttribute<PluginNameAttribute>()?.Name}: {typeof(ExternalAppOutgoing).GetShortTypeAssemblyName()}.", LogLevel.Information, Times.Once());
}

private void VerifyPlugin(KeyValuePair<string, string> values, Type type)
{
Assert.Equal(values.Key, type.Name);
Assert.Equal(values.Key, type.GetCustomAttribute<PluginNameAttribute>()?.Name);
Assert.Equal(values.Value, type.GetShortTypeAssemblyName());
}
}
Expand Down

0 comments on commit 22c23d2

Please sign in to comment.