示例#1
0
 public MacApplicationsAssociationsLoader(
     IProcessService processService,
     UtiToExtensionsMappingConfiguration configuration)
 {
     _processService = processService;
     _configuration  = configuration;
 }
    private static void RegisterUtiToExtensionsMappingConfiguration(IMutableDependencyResolver services,
                                                                    IConfiguration configuration)
    {
        var config = new UtiToExtensionsMappingConfiguration();

        configuration.GetSection("UtiToExtensionsMapping").Bind(config);
        services.RegisterConstant(config);
    }
    public async Task TestLoadAssociatedApplicationsAsync(string output, int resultsCount)
    {
        var configuration = new UtiToExtensionsMappingConfiguration
        {
            UtiToExtensionsMapping = new Dictionary <string, List <string> >
            {
                ["public.text"] = new List <string>
                {
                    Extension
                }
            }
        };
        var apps = new[]
        {
            new ApplicationModel
            {
                ExecutePath = "/home/app"
            }
        };

        _autoMocker.Use(configuration);
        _autoMocker
        .Setup <IProcessService, Task <string> >(m =>
                                                 m.ExecuteAndGetOutputAsync(
                                                     "/System/Library/Frameworks/CoreServices.framework/Versions/A/Frameworks/LaunchServices.framework/Versions/A/Support/lsregister",
                                                     "-dump Bundle"))
        .ReturnsAsync(output);

        var service = _autoMocker.CreateInstance <MacApplicationsAssociationsLoader>();

        var associations = await service.LoadAssociatedApplicationsAsync(apps);

        Assert.NotNull(associations);
        Assert.Equal(resultsCount, associations.Count);

        if (resultsCount == 1)
        {
            Assert.True(associations.ContainsKey(Extension));
            Assert.Single(associations[Extension]);

            Assert.Equal(apps.Single(), associations[Extension].Single());
        }
    }