public void should_begin_monitoring_when_started_if_mapping_exists() { var buildMonitor = Substitute.For<IBuildMonitor>(); var buildMonitorFactory = Substitute.For<IBuildMonitorFactory>(); buildMonitorFactory.Create(Arg.Any<IInputDevice>()).Returns(buildMonitor); var buildMonitorFactories = Substitute.For<IIndex<string, IBuildMonitorFactory>>(); buildMonitorFactories["key"].ReturnsForAnyArgs(buildMonitorFactory); var outputDevice = new OutputDeviceBuilder().Build(); var inputDevice = new InputDeviceBuilder().Build(); var mapping = new Mapping { OutputDeviceId = outputDevice.Id }; mapping.InputGroups.Add(new InputGroup { InputDeviceId = inputDevice.Id, Inputs = { "Build1", "Build2" } }); var config = new ConfigBuilder() .WithOutputDevice(outputDevice) .WithInputDevice(inputDevice) .WithMapping(mapping) .Build(); var service = new EmanateService(config, buildMonitorFactories); service.Start(); buildMonitor.Received().BeginMonitoring(); }
public ConfigBuilder WithMapping(Mapping mapping, bool generateDependencies = true) { config.Mappings.Add(mapping); if (generateDependencies) { if (config.OutputDevices.All(d => d.Id != mapping.OutputDeviceId)) { var outputDevice = new OutputDeviceBuilder() .WithId(mapping.OutputDeviceId) .Build(); WithOutputDevice(outputDevice); } foreach (var inputGroup in mapping.InputGroups) { if (config.InputDevices.All(d => d.Id != inputGroup.InputDeviceId)) { var inputDevice = new InputDeviceBuilder() .WithId(inputGroup.InputDeviceId) .Build(); WithInputDevice(inputDevice); } } } return this; }
public bool NewOutputDevice(OutputDeviceTypeInfo outputDeviceTypeInfo, out IOutputDevice newOutputDevice) { if (outputDeviceTypeInfo == null) { throw new NullReferenceException(); } newOutputDevice = outputDeviceTypeInfo != null? OutputDeviceBuilder.GetNew(outputDeviceTypeInfo) : null; if (newOutputDevice as IFileOutputable != null) { var openingFileDialogArgs = new OpenFileByUserEventArgs() { InitialDirectory = (MainForm.SelectedIDE.ProgramFile.FileName.IsNotNullOrEmpty()) ? Path.GetDirectoryName(MainForm.SelectedIDE.ProgramFile.FileName) : (MainForm.SelectedIDE.ParentWorkplace.MainForm.RecentFiles.Count > 2) ? Path.GetDirectoryName(MainForm.SelectedIDE.ParentWorkplace.MainForm.RecentFiles[0]) : Path.GetDirectoryName(Application.ExecutablePath), Filter = "Text Files (*.txt)|*.txt|Binary Files (*.bin)|*.txt|All Files (*.*)|*.*", FilterIndex = 1, RestoreDirectory = true }; OpeningFileByUser?.Invoke(this, openingFileDialogArgs); if (openingFileDialogArgs.Answer == DialogResult.OK) { try { if (!(System.IO.File.Exists(openingFileDialogArgs.FileName) && (System.IO.File.GetAttributes(openingFileDialogArgs.FileName) & FileAttributes.ReadOnly) != 0)) { (newOutputDevice as IFileOutputable).FileName = openingFileDialogArgs.FileName; } else { return(false); } } catch (Exception ex) { MessageBox.Show("Error: Could not read file from disk. Original error: " + ex.Message); return(false); } } else { return(false); } } if (newOutputDevice != null) { this.OutputDevices.Add(newOutputDevice); newOutputDevice.ParentWorkplace = this; newOutputDevice.Id = this.OutputDevices.Count - 1; } if (newOutputDevice as IInputDevice != null) { this.InputDevices.Add(newOutputDevice as IInputDevice); } return(true); }