public async Task GetCurrentEntryAsync_NetshReturnsUnknownResult_ReturnsUnknownResult()
        {
            processRunner.RunAsync(
                Arg.Is(NetshCommandFactory.Executable),
                Arg.Is(NetshCommandFactory.GetShowCommandArguments())).Returns("127.0.0.1 80 192.168.42.42 80");
            var tempController = new PortProxyController(settings, processRunner);
            await tempController.RefreshCurrentConnectAddressAsync().ConfigureAwait(false);

            var currentEntry = await tempController.GetCurrentEntryAsync().ConfigureAwait(false);

            Assert.That(currentEntry, Is.Not.Null);
            Assert.That(currentEntry.Name, Is.EqualTo("<unknown>"));
        }
        public async Task GetCurrentEntryAsync_NetshReturnsKnownResultWithPort8080_ReturnsEntry()
        {
            settings.Entries.Returns(
                new List <CommandEntry> {
                new CommandEntry {
                    Name = "MyEntry", Address = "192.168.42.42:8080"
                }
            });
            processRunner.RunAsync(
                Arg.Is(NetshCommandFactory.Executable),
                Arg.Is(NetshCommandFactory.GetShowCommandArguments())).Returns("127.0.0.1 80 192.168.42.42 8080");
            IPortProxyControllerAsync tempController = new PortProxyController(settings, processRunner);
            await tempController.RefreshCurrentConnectAddressAsync().ConfigureAwait(false);

            var currentEntry = await tempController.GetCurrentEntryAsync().ConfigureAwait(false);

            Assert.That(currentEntry, Is.SameAs(settings.Entries[0]));
        }
        public async Task SetCurrentEntryAsync_EntryIsInConfig_RunsProcessSettingNewAddress()
        {
            const string ListenAddress  = "127.0.0.1";
            const string MyEntryAddress = "192.168.42.42";

            settings.ListenAddress.Returns(ListenAddress);
            settings.Entries.Returns(
                new List <CommandEntry> {
                new CommandEntry {
                    Name = "MyEntry", Address = MyEntryAddress
                }
            });
            await controller.SetCurrentEntryAsync("MyEntry").ConfigureAwait(false);

            await processRunner.Received().RunAsync(
                Arg.Is(NetshCommandFactory.Executable),
                Arg.Is(NetshCommandFactory.GetAddCommandArguments(ListenAddress, MyEntryAddress)))
            .ConfigureAwait(false);
        }
 public void GetDeleteCommandArguments_ValidParameter_ReturnsCommandArguments()
 {
     Assert.That(
         NetshCommandFactory.GetDeleteCommandArguments("127.0.0.1"),
         Is.EqualTo("interface portproxy delete v4tov4 listenport=80 listenaddress=127.0.0.1 protocol=tcp"));
 }
 public void GetAddCommandArguments_ValidParameter_ReturnsCommandArguments()
 {
     Assert.That(
         NetshCommandFactory.GetAddCommandArguments("127.0.0.1", "192.168.42.42"),
         Is.EqualTo("interface portproxy add v4tov4 listenport=80 listenaddress=127.0.0.1 connectport=80 connectaddress=192.168.42.42 protocol=tcp"));
 }
 public void GetShowCommandArguments_ReturnsCommandArguments()
 {
     Assert.That(
         NetshCommandFactory.GetShowCommandArguments(),
         Is.EqualTo("interface portproxy show v4tov4"));
 }
 public void Constructor_ValidProcessRunner_DoesNotUpdateCurrentEntry()
 {
     processRunner.DidNotReceive().RunAsync(
         Arg.Is(NetshCommandFactory.Executable),
         Arg.Is(NetshCommandFactory.GetShowCommandArguments()));
 }