public void ThrowsWardenExceptionIfNetShFails()
            {
                var tcpPortManager = new LocalTcpPortManager(FirewallManager, NetShRunner);

                NetShRunner.AddRule(Arg.Any <int>(), Arg.Any <string>()).ReturnsForAnyArgs(false);

                var exception = Record.Exception(() => tcpPortManager.ReserveLocalPort(8888, "userName"));

                Assert.IsType <Exception>(exception);
            }
            public void ZeroPortReturnsNewPort()
            {
                var tcpPortManager = new LocalTcpPortManager(FirewallManager, NetShRunner);

                NetShRunner.AddRule(Arg.Any <int>(), Arg.Any <string>()).ReturnsForAnyArgs(true);

                var port = tcpPortManager.ReserveLocalPort(0, "userName");

                Assert.True(port > 0);
            }
            public void ThrowWardenExecptionIfFirewallManagerFails()
            {
                var tcpPortManager = new LocalTcpPortManager(FirewallManager, NetShRunner);

                NetShRunner.AddRule(Arg.Any <int>(), Arg.Any <string>()).ReturnsForAnyArgs(true);
                FirewallManager.When(x => x.OpenPort(Arg.Any <int>(), Arg.Any <string>())).Do(x => { throw new Exception(); });

                var exception = Record.Exception(() => tcpPortManager.ReserveLocalPort(8888, "userName"));

                Assert.IsType <Exception>(exception);
            }
            public void CallsNetShRunnerFirewallManagerAndReturnsPort()
            {
                var tcpPortManager = new LocalTcpPortManager(FirewallManager, NetShRunner);

                NetShRunner.AddRule(Arg.Any <int>(), Arg.Any <string>()).ReturnsForAnyArgs(true);

                var port = tcpPortManager.ReserveLocalPort(8888, "userName");

                NetShRunner.Received().AddRule(Arg.Is(8888), Arg.Is("userName"));
                FirewallManager.Received().OpenPort(Arg.Is(8888), Arg.Is("userName"));
                Assert.Equal(8888, port);
            }
            public void ThrowsArgumentNullExceptionIfUserNameNull()
            {
                var tcpPortManager = new LocalTcpPortManager(null, null);

                Assert.Throws <ArgumentNullException>(() => tcpPortManager.ReserveLocalPort(100, null));
            }