Skip to content

Commit

Permalink
Change Server Menu
Browse files Browse the repository at this point in the history
  • Loading branch information
k3ldar committed Dec 19, 2023
1 parent 5b71cd7 commit c3fd002
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 10 deletions.
2 changes: 1 addition & 1 deletion src/GCATests/GSendCS/ServerAddressProcessorTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ public void Delete_ExclusiveAccessNotAvailable_ReturnsErrorCodeExclusiveAccessDe
public void Delete_ExistingServerAddress_StillReadableWhilstFileStreamOpen_WhenFileDoesNotExist()
{
string serverSettingsFile = Path.GetTempFileName();
File.WriteAllText(serverSettingsFile, "[\"http://127.0.0.1:7150\"]");
File.WriteAllText(serverSettingsFile, "[\"http://127.0.0.1:7150/\"]");
MockCommandLineArgs mockArgs = new();
MockDisplay mockDisplay = new();

Expand Down
9 changes: 7 additions & 2 deletions src/GCATests/Mocks/MockRunProgram.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,13 @@ public int Run(string programName, string parameters, bool useShellExecute, bool

public string Run(string programName, string parameters)
{
throw new NotImplementedException();
return Run(programName, parameters, out int _);
}

public string Run(string programName, string parameters, out int exitCode)
{
throw new NotImplementedException();
exitCode = ExitCode;
return Result;
}

public int ReturnValue { get; set; } = Int32.MinValue;
Expand All @@ -36,5 +37,9 @@ public string Run(string programName, string parameters, out int exitCode)
public bool WaitForFinish { get; set; }

public int TimeoutMilliseconds { get; set; }

public int ExitCode { get; set; }

public string Result { get; set; }
}
}
4 changes: 3 additions & 1 deletion src/GCATests/Shared/Plugins/ServerMenuPluginTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,11 @@ public class ServerMenuPluginTests
[TestMethod]
public void ServerMenuPlugin_ConstructValidInstance_Success()
{
MockRunProgram mockRunProgram = new MockRunProgram();
mockRunProgram.Result = string.Empty;
IPluginMenu parentMenu = new MockPluginMenu("test", MenuType.MenuItem, null);
MockSenderPluginHost pluginHost = new(parentMenu);
ServerMenuPlugin sut = new(new ServerConfigurationUpdated(), new CommonUtils(), new MockRunProgram());
ServerMenuPlugin sut = new(new MockGSendApiWrapper(), new ServerConfigurationUpdated(), new CommonUtils(), mockRunProgram);
sut.Initialize(pluginHost);

Assert.IsNotNull(sut);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
using System;
using System.Collections.Generic;
using System.Runtime.CompilerServices;
using System.Windows.Forms;

using GSendApi;

using GSendControls.Abstractions;
using GSendControls.Threads;

Expand All @@ -18,14 +21,16 @@ namespace GSendControls.Plugins.InternalPlugins.ServerMenu
/// </summary>
public sealed class ServerMenuPlugin : IGSendPluginModule
{
private readonly IGSendApiWrapper _gSendApiWrapper;
private readonly ICommonUtils _commonUtils;
private const int MaximumServerNameMenuItems = 10;
private List<IPluginMenu> _pluginMenus;
private IPluginHost _pluginHost;
private readonly IRunProgram _runProgram;

public ServerMenuPlugin(IServerConfigurationUpdated serverConfigurationUpdated, ICommonUtils commonUtils, IRunProgram runProgram)
public ServerMenuPlugin(IGSendApiWrapper gSendApiWrapper, IServerConfigurationUpdated serverConfigurationUpdated, ICommonUtils commonUtils, IRunProgram runProgram)
{
_gSendApiWrapper = gSendApiWrapper ?? throw new ArgumentNullException(nameof(gSendApiWrapper));
_commonUtils = commonUtils ?? throw new ArgumentNullException(nameof(commonUtils));
_runProgram = runProgram ?? throw new ArgumentNullException(nameof(runProgram));

Expand Down Expand Up @@ -60,7 +65,7 @@ public IReadOnlyList<IPluginMenu> MenuItems

for (int i = 0; i < MaximumServerNameMenuItems; i++)
{
_pluginMenus.Add(new ServerSelectMenuItem(parentServerMenu, i + 2));
_pluginMenus.Add(new ServerSelectMenuItem(parentServerMenu, i + 2, _gSendApiWrapper));
}

UpdateServerMenuItems();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
using System;
using System.Drawing;

using GSendApi;

using GSendControls.Abstractions;

using GSendShared;
Expand All @@ -10,14 +12,16 @@ namespace GSendControls.Plugins.InternalPlugins.ServerMenu
{
public sealed class ServerSelectMenuItem : IPluginMenu
{
private readonly IGSendApiWrapper _gSendApiWrapper;
private Uri _uri = null;

public ServerSelectMenuItem(IPluginMenu parentMenu, int index)
public ServerSelectMenuItem(IPluginMenu parentMenu, int index, IGSendApiWrapper gSendApiWrapper)
{
_gSendApiWrapper = gSendApiWrapper ?? throw new ArgumentNullException(nameof(gSendApiWrapper));
ParentMenu = parentMenu ?? throw new ArgumentNullException(nameof(parentMenu));
Index = index;
}

public Image MenuImage => null;

public MenuType MenuType => MenuType.MenuItem;
Expand All @@ -32,7 +36,7 @@ public ServerSelectMenuItem(IPluginMenu parentMenu, int index)

public void Clicked()
{

_gSendApiWrapper.ServerAddress = _uri ?? throw new InvalidOperationException("Invalid Server Address");
}

public void ClientMessageReceived(IClientBaseMessage clientMessage)
Expand All @@ -49,7 +53,10 @@ public bool GetShortcut(out string groupName, out string shortcutName)

public bool IsChecked()
{
return false;
if (_uri == null)
return false;

return _uri.Equals(_gSendApiWrapper.ServerAddress);
}

public bool IsEnabled()
Expand Down

0 comments on commit c3fd002

Please sign in to comment.