public void BasicGetSetEnvironmentVariable(string prefix) { string name = prefix + System.IO.Path.GetRandomFileName(); ProcessMethods.SetEnvironmentVariable(name, "BasicGetSetEnvironmentVariable"); ProcessMethods.GetEnvironmentVariable(name).Should().Be("BasicGetSetEnvironmentVariable"); ProcessMethods.SetEnvironmentVariable(name, null); ProcessMethods.GetEnvironmentVariable(name).Should().BeNull(); }
unsafe static LRESULT WindowProcedure(WindowHandle window, WindowMessage message, WPARAM wParam, LPARAM lParam) { switch (message) { case WindowMessage.Create: SIZE baseUnits = Windows.GetDialogBaseUnits(); // Create listbox and static text windows. hwndList = Windows.CreateWindow("listbox", null, WindowStyles.Child | WindowStyles.Visible | (WindowStyles)ListBoxStyles.Standard, ExtendedWindowStyles.None, baseUnits.cx, baseUnits.cy * 3, baseUnits.cx * 64 + Windows.GetSystemMetrics(SystemMetric.CXVSCROLL), baseUnits.cy * 20, window, (IntPtr)ID_LIST, ((CREATESTRUCT *)lParam)->hInstance, IntPtr.Zero); hwndText = Windows.CreateWindow("static", null, WindowStyles.Child | WindowStyles.Visible | (WindowStyles)StaticStyles.Left, ExtendedWindowStyles.None, baseUnits.cx, baseUnits.cy, Windows.GetSystemMetrics(SystemMetric.CYSCREEN), baseUnits.cy, window, (IntPtr)ID_TEXT, ((CREATESTRUCT *)lParam)->hInstance, IntPtr.Zero); FillListBox(hwndList); return(0); case WindowMessage.SetFocus: hwndList.SetFocus(); return(0); case WindowMessage.Command: if (wParam.LowWord == ID_LIST && (wParam.HighWord == (ushort)ListBoxNotification.SelectionChange)) { // Get current selection. uint iIndex = hwndList.SendMessage(ListBoxMessage.GetCurrentSelection, 0, 0); int iLength = hwndList.SendMessage(ListBoxMessage.GetTextLength, iIndex, 0) + 1; char *nameBuffer = stackalloc char[iLength]; int result = hwndList.SendMessage(ListBoxMessage.GetText, iIndex, nameBuffer); // Get environment string. string value = ProcessMethods.GetEnvironmentVariable(new string(nameBuffer, 0, result)); // Show it in window. hwndText.SetWindowText(value); } return(0); case WindowMessage.Destroy: Windows.PostQuitMessage(0); return(0); } return(Windows.DefaultWindowProcedure(window, message, wParam, lParam)); }
public void ListEnvironmentVariables_Basic(string prefix) { string name = prefix + System.IO.Path.GetRandomFileName(); ProcessMethods.SetEnvironmentVariable(name, "test"); ProcessMethods.GetEnvironmentVariable(name).Should().Be("test"); var variables = ProcessMethods.GetEnvironmentVariables(); variables.Should().ContainKey(name); variables[name].Should().Be("test"); ProcessMethods.SetEnvironmentVariable(name, null); ProcessMethods.GetEnvironmentVariable(name).Should().BeNull(); variables = ProcessMethods.GetEnvironmentVariables(); variables.Should().NotContainKey(name); }
public void GetEnvironmentVariable_GetNullStringThrows() { Action action = () => ProcessMethods.GetEnvironmentVariable(null); action.ShouldThrow <ArgumentNullException>(); }