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(); } }
public void SetPort_SetsPort() { var apiBuilder = new ApiBuilder(Substitute.For <ISimulation>()); ApiBuilder self = apiBuilder.SetPort(1234); apiBuilder.Port.ShouldBe(1234); self.ShouldBe(apiBuilder); }
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(); } }