コード例 #1
0
        public void when_get_free_port_it_should_find_same_port_few_times()
        {
            var freePort = NetworkTools.GetFreeTcpPort();

            NetworkTools.GetFreeTcpPort().Should().Be(freePort);
            NetworkTools.GetFreeTcpPort().Should().Be(freePort);
        }
コード例 #2
0
        public void when_there_is_no_free_ports_in_range_it_should_fail()
        {
            const ushort rangeStart    = 50000;
            const ushort rangeFinish   = 50002;
            var          occupiedPorts = OccupyPortRange(rangeStart, rangeFinish).ToArray();

            Action sut = () => NetworkTools.GetFreeTcpPort(rangeStart, rangeFinish);

            sut.Should().ThrowExactly <ArgumentException>().Which.Message.Should().Contain("range");

            FreePortRange(occupiedPorts);
        }