public async Task TestGetUnmountedDrivesEnabled(string output, string[] names, string[] fullNames)
        {
            var configuration = new UnmountedDrivesConfiguration
            {
                IsEnabled = true
            };

            _autoMocker.Use(configuration);
            _autoMocker
            .Setup <IEnvironmentService, string>(m => m.NewLine)
            .Returns("\n");
            _autoMocker
            .Setup <IProcessService, Task <string> >(m =>
                                                     m.ExecuteAndGetOutputAsync("lsblk", "--noheadings --raw -o NAME,MOUNTPOINT"))
            .ReturnsAsync(output);

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

            await service.ReloadUnmountedDrivesAsync();

            var drives = service.UnmountedDrives;

            Assert.NotNull(drives);

            var actualNames = drives.Select(d => d.Name).ToArray();

            Assert.Equal(names, actualNames);

            var actualFullNames = drives.Select(d => d.FullName).ToArray();

            Assert.Equal(fullNames, actualFullNames);
        }
        private static void RegisterUnmountedDrivesConfiguration(IMutableDependencyResolver services,
                                                                 IConfiguration configuration)
        {
            var config = new UnmountedDrivesConfiguration();

            configuration.GetSection("UnmountedDrives").Bind(config);
            services.RegisterConstant(config);
        }
Example #3
0
 public LinuxUnmountedDriveService(
     IProcessService processService,
     IEnvironmentService environmentService,
     UnmountedDrivesConfiguration configuration)
 {
     _processService     = processService;
     _environmentService = environmentService;
     _configuration      = configuration;
 }
Example #4
0
        public async Task TestGetUnmountedDrivesEnabledException()
        {
            var configuration = new UnmountedDrivesConfiguration
            {
                IsEnabled = true
            };

            _autoMocker.Use(configuration);
            _autoMocker
            .Setup <IProcessService, Task <string> >(m =>
                                                     m.ExecuteAndGetOutputAsync("lsblk", "--noheadings --raw -o NAME,MOUNTPOINT"))
            .ThrowsAsync(new Exception());

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

            var drives = await service.GetUnmountedDrivesAsync();

            Assert.NotNull(drives);
            Assert.Empty(drives);
        }
        public async Task TestGetUnmountedDrivesEnabledException()
        {
            var configuration = new UnmountedDrivesConfiguration
            {
                IsEnabled = true
            };

            _autoMocker.Use(configuration);
            _autoMocker
            .Setup <IProcessService, Task <string> >(m =>
                                                     m.ExecuteAndGetOutputAsync("diskutil", "list"))
            .ThrowsAsync(new Exception());

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

            await service.ReloadUnmountedDrivesAsync();

            var drives = service.UnmountedDrives;

            Assert.NotNull(drives);
            Assert.Empty(drives);
        }
        public async Task TestGetUnmountedDrivesEnabled(string listOutput, string dfOutput,
                                                        string[] names, string[] fullNames)
        {
            var configuration = new UnmountedDrivesConfiguration
            {
                IsEnabled = true
            };

            _autoMocker.Use(configuration);
            _autoMocker
            .Setup <IEnvironmentService, string>(m => m.NewLine)
            .Returns("\n");
            _autoMocker
            .Setup <IProcessService, Task <string> >(m =>
                                                     m.ExecuteAndGetOutputAsync("diskutil", "list"))
            .ReturnsAsync(listOutput);
            _autoMocker
            .Setup <IProcessService, Task <string> >(m =>
                                                     m.ExecuteAndGetOutputAsync("df", "-Hl"))
            .ReturnsAsync(dfOutput);

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

            await service.ReloadUnmountedDrivesAsync();

            var drives = service.UnmountedDrives;

            Assert.NotNull(drives);

            var actualNames = drives.Select(d => d.Name).ToArray();

            Assert.Equal(names, actualNames);

            var actualFullNames = drives.Select(d => d.FullName).ToArray();

            Assert.Equal(fullNames, actualFullNames);
        }