public void TestOpening(DesktopEnvironment desktopEnvironment, string command) { var args = $@"--workdir \""{Directory}\"""; var uowMock = new Mock <IUnitOfWork>(); uowMock .Setup(m => m.GetRepository <TerminalSettings>()) .Returns(new Mock <IRepository <TerminalSettings> >().Object); _autoMocker .Setup <IUnitOfWorkFactory, IUnitOfWork>(m => m.Create()) .Returns(uowMock.Object); _autoMocker .Setup <IProcessService>(m => m.Run(command, args)) .Verifiable(); _autoMocker .Setup <IDesktopEnvironmentService, DesktopEnvironment>(m => m.GetDesktopEnvironment()) .Returns(desktopEnvironment); _autoMocker .Setup <IShellCommandWrappingService, (string, string)>(m => m.WrapWithNohup(It.IsAny <string>(), It.IsAny <string>())) .Returns <string, string>((c, a) => (c, a)); var terminalService = _autoMocker.CreateInstance <LinuxTerminalService>(); terminalService.Open(Directory); _autoMocker.Verify <IProcessService>(m => m.Run(command, args), Times.Once); }
public void TestFileServiceOpeningLinux(DesktopEnvironment desktopEnvironment, string command) { const string wrappedCommand = "wrappedCommand"; const string wrappedArguments = "wrappedArguments"; var processServiceMock = new Mock <IProcessService>(); processServiceMock .Setup(m => m.Run(command, It.IsAny <string>())) .Verifiable(); var shellCommandWrappingService = new Mock <IShellCommandWrappingService>(); shellCommandWrappingService .Setup(m => m.WrapWithNohup(command, It.IsAny <string>())) .Returns((wrappedCommand, wrappedArguments)); var desktopEnvironmentService = new Mock <IDesktopEnvironmentService>(); desktopEnvironmentService .Setup(m => m.GetDesktopEnvironment()) .Returns(desktopEnvironment); var fileOpeningService = new LinuxResourceOpeningService( processServiceMock.Object, shellCommandWrappingService.Object, desktopEnvironmentService.Object); fileOpeningService.Open(FileName); processServiceMock.Verify(m => m.Run(wrappedCommand, wrappedArguments), Times.Once()); }
public void TestDesktopEnvironment(string environmentName, DesktopEnvironment expectedEnvironment, string environmentVariable) { _autoMocker .Setup <IEnvironmentService, string>(m => m.GetEnvironmentVariable(environmentVariable)) .Returns(environmentName); var desktopEnvironmentService = _autoMocker.CreateInstance <DesktopEnvironmentService>(); var actualEnvironment = desktopEnvironmentService.GetDesktopEnvironment(); Assert.Equal(expectedEnvironment, actualEnvironment); }
public void TestDesktopEnvironment(string environmentName, DesktopEnvironment expectedEnvironment, string environmentVariable) { var environmentServiceMock = new Mock <IEnvironmentService>(); environmentServiceMock .Setup(m => m.GetEnvironmentVariable(environmentVariable)) .Returns(environmentName); var desktopEnvironmentService = new DesktopEnvironmentService(environmentServiceMock.Object); var actualEnvironment = desktopEnvironmentService.GetDesktopEnvironment(); Assert.Equal(expectedEnvironment, actualEnvironment); }
public IdGenerator(DesktopEnvironment de) { // ASSUME: there is no holes in the sequential ids ControlNo maxId = 0; FindMaxId(de); id = maxId; void FindMaxId(Control control) { foreach (var child in control.Controls) { if (child.Id > maxId) { maxId = child.Id; } FindMaxId(child); } } }
static void Main(string[] args) { Console.WriteLine("SDEE Project CodeName -"); Console.WriteLine("Test cmd window"); Console.WriteLine("Do not close this window directly, it's not safe because the Skin Engine would not be stopped properly."); var dep = new DesktopEnvironment(); MyTaskbarXaml taskbar = new MyTaskbarXaml(); MyStartMenu startMenu = new MyStartMenu() { Visibility = Visibility.Hidden, VerticalAlignment = VerticalAlignment.Bottom, HorizontalAlignment = HorizontalAlignment.Left, Margin = new Thickness(0, 0, 0, taskbar.Height) }; taskbar.ToggleStartMenu += (s, e) => startMenu.Toggle(); dep.Desktop.Content = new MyDesktop(); Grid explorerGrid = new Grid(); explorerGrid.Children.Add(taskbar); explorerGrid.Children.Add(startMenu); dep.FloatingElements.Add(explorerGrid); dep.GetNewSkinWindowControl = () => new MySkinWindow(); //dep.FloatingElements.Add(new Button() { Width=double.NaN, Height = 50, Opacity = 0.7, // VerticalAlignment = VerticalAlignment.Top, Margin = new Thickness(10, 10, 0, 0) }); //dep.FloatingElements.Add(new CheckBox() { Width = 500, Height = 400, Opacity=0.2 }); dep.Run(); dep.Shutdown(); }
public void TestFileServiceOpeningLinux(DesktopEnvironment desktopEnvironment, string command) { const string wrappedCommand = "wrappedCommand"; const string wrappedArguments = "wrappedArguments"; _autoMocker .Setup <IProcessService>(m => m.Run(command, It.IsAny <string>())) .Verifiable(); _autoMocker .Setup <IShellCommandWrappingService, (string, string)>(m => m.WrapWithNohup(command, It.IsAny <string>())) .Returns((wrappedCommand, wrappedArguments)); _autoMocker .Setup <IDesktopEnvironmentService, DesktopEnvironment>(m => m.GetDesktopEnvironment()) .Returns(desktopEnvironment); var fileOpeningService = _autoMocker.CreateInstance <LinuxResourceOpeningService>(); fileOpeningService.Open(FileName); _autoMocker .Verify <IProcessService>(m => m.Run(wrappedCommand, wrappedArguments), Times.Once); }
private string ExecuteCommand(string line) { const string duplicateSpacesRegex = @"\s+"; string[] commandWords = Regex.Replace(line, duplicateSpacesRegex, " ").Split(' '); string output = ""; switch (commandWords[0].ToLower()) { case CommandSyntax.Commands.Set: if (!FocusedControl.Attributes.ContainsKey(commandWords[1])) { throw new FormatException(); // InvalidAttributeException } FocusedControl.Attributes[commandWords[1]] = commandWords[2]; break; case CommandSyntax.Commands.Tree: { output = $"{FocusedControl}\n"; Tree(FocusedControl, 1); void Tree(Control control, int indentation) { foreach (var child in control.Controls) { output += $"{new string('\t', indentation)}{child}\n"; Tree(child, indentation + 1); } } } break; case CommandSyntax.Commands.Append: { if (!TryGetControl(out Control control)) { throw new FormatException(); } Control.Load(control); } break; case CommandSyntax.Commands.Attributes: { output = $"{FocusedControl.Type}\n"; foreach (var attribute in FocusedControl.Attributes) { output += $"{attribute}\n"; } } break; case CommandSyntax.Commands.Focus: { if (!TryGetReference(out ControlReference reference)) { throw new FormatException(); } if (!DesktopEnvironment.TryGetControl(reference, out Control control)) { throw new InvalidControlException(); } FocusedControl = control; } break; case CommandSyntax.Commands.Delete: { if (!TryGetReference(out ControlReference reference)) { throw new FormatException(); } if (!DesktopEnvironment.TryDelete(reference)) { throw new InvalidControlException(); } } break; default: throw new InvalidCommandException(); } return(output); bool TryGetControl(out Control control) { control = null; if (!Enum.TryParse(commandWords[1], ignoreCase: true, out ControlType type)) { return(false); } switch (type) { case ControlType.SimpleRect: // BBNEXT control = new SimpleRectControl(FocusedControl, Color.Blue, id: _idGenerator.GenerateNextId()) { Position = new Vector2i(ControlLayout.ScreenSize, ControlLayout.StickToRightOrBottom(30)), Size = new Vector2i(ControlLayout.ScreenSize, 30) }; break; default: return(false); } return(true); } bool TryGetReference(out ControlReference reference) { reference = null; if (!Enum.TryParse(commandWords[1], ignoreCase: true, out ControlType type)) { return(false); } if (!uint.TryParse(commandWords[2], out uint no)) { return(false); } reference = new ControlReference(type, no); return(true); } }