示例#1
0
        public async Task StartAsync_Throws_WhenPortInUse()
        {
            var tcpListener = new TcpListener(IPAddress.Loopback, 0);

            tcpListener.Start();
            try
            {
                var port       = ((IPEndPoint)tcpListener.LocalEndpoint).Port;
                var apiBuilder = new ApiBuilder(Substitute.For <ISimulation>());
                apiBuilder.SetPort(port);
                var apiSimulator = new ApiSimulator(apiBuilder);
                try
                {
                    await apiSimulator.StartAsync().ShouldThrowAsync <IOException>();
                }
                finally
                {
                    await apiSimulator.StopAsync();
                }
            }
            finally
            {
                tcpListener.Stop();
            }
        }
示例#2
0
        public void SetPort_SetsPort()
        {
            var apiBuilder = new ApiBuilder(Substitute.For <ISimulation>());

            ApiBuilder self = apiBuilder.SetPort(1234);

            apiBuilder.Port.ShouldBe(1234);
            self.ShouldBe(apiBuilder);
        }
示例#3
0
        public async Task StartAsync_Fails_WhenPortAlreadyUsed()
        {
            var listener = new TcpListener(IPAddress.Loopback, 0);

            listener.Start();
            try
            {
                var usedPort     = ((IPEndPoint)listener.LocalEndpoint).Port;
                var apiBuilder   = new ApiBuilder(Substitute.For <ISimulation>());
                var apiSimulator = new ApiSimulator(apiBuilder.SetPort(usedPort));

                await apiSimulator.StartAsync().ShouldThrowAsync <IOException>();
            }
            finally
            {
                listener.Stop();
            }
        }