public async Task Dispose_SetsStateToStopped() { var serviceBusBuilder = new ServiceBusBuilder(Substitute.For <ISimulation>()); var serviceBusSimulator = new ServiceBusSimulator(serviceBusBuilder); await serviceBusSimulator.StartAsync(); serviceBusSimulator.Dispose(); serviceBusSimulator.State.ShouldBe(SimulatorState.Stopped); }
public async Task StartAsync_UsesDefaultPort_WhenNotSecured() { var serviceBusBuilder = new ServiceBusBuilder(Substitute.For <ISimulation>()); var serviceBusSimulator = new ServiceBusSimulator(serviceBusBuilder); await serviceBusSimulator.StartAsync(); try { serviceBusSimulator.Port.ShouldBe(5672); } finally { await serviceBusSimulator.StopAsync(); } }
public async Task StartAsync_ReportsActiveConnectionString() { var serviceBusBuilder = new ServiceBusBuilder(Substitute.For <ISimulation>()); var serviceBusSimulator = new ServiceBusSimulator(serviceBusBuilder); await serviceBusSimulator.StartAsync(); try { serviceBusSimulator.ConnectionString.ShouldBe($"Endpoint=sb://127.0.0.1:{serviceBusSimulator.Port};SharedAccessKeyName=all;SharedAccessKey=CLwo3FQ3S39Z4pFOQDefaiUd1dSsli4XOAj3Y9Uh1E=;TransportType=Amqp"); } finally { await serviceBusSimulator.StopAsync(); } }
public async Task StartAsync_ReportsActiveLocation() { var serviceBusBuilder = new ServiceBusBuilder(Substitute.For <ISimulation>()); var serviceBusSimulator = new ServiceBusSimulator(serviceBusBuilder); await serviceBusSimulator.StartAsync(); try { serviceBusSimulator.Location.ShouldStartWith($"amqp://127.0.0.1:{serviceBusSimulator.Port}"); } finally { await serviceBusSimulator.StopAsync(); } }
public async Task StartAsync_ReportsActivePort() { var serviceBusBuilder = new ServiceBusBuilder(Substitute.For <ISimulation>()); var serviceBusSimulator = new ServiceBusSimulator(serviceBusBuilder); await serviceBusSimulator.StartAsync(); try { serviceBusSimulator.Port.ShouldNotBe(0); } finally { await serviceBusSimulator.StopAsync(); } }
public async Task StartAsync_SetsStateToRunning() { var serviceBusBuilder = new ServiceBusBuilder(Substitute.For <ISimulation>()); var serviceBusSimulator = new ServiceBusSimulator(serviceBusBuilder); await serviceBusSimulator.StartAsync(); try { serviceBusSimulator.State.ShouldBe(SimulatorState.Running); } finally { await serviceBusSimulator.StopAsync(); } }
public async Task Abort_SetsStateToStopped() { var serviceBusBuilder = new ServiceBusBuilder(Substitute.For <ISimulation>()); var serviceBusSimulator = new ServiceBusSimulator(serviceBusBuilder); await serviceBusSimulator.StartAsync(); try { serviceBusSimulator.Abort(); serviceBusSimulator.State.ShouldBe(SimulatorState.Stopped); } finally { await serviceBusSimulator.StopAsync(); } }
public async Task StartAsync_Throws_WhenPortInvalid() { ServiceBusBuilder serviceBusBuilder = new ServiceBusBuilder(Substitute.For <ISimulation>()).SetPort(ushort.MaxValue + 10); var serviceBusSimulator = new ServiceBusSimulator(serviceBusBuilder); Func <Task> action = async() => await serviceBusSimulator.StartAsync(); try { (await action.ShouldThrowAsync <ArgumentOutOfRangeException>()) .ParamName.ShouldBe("port"); serviceBusSimulator.State.ShouldBe(SimulatorState.Stopped); } finally { await serviceBusSimulator.StopAsync(); } }
public async Task StartAsync_UsesDefaultSecurePort_WhenSecured() { using X509Certificate2 certificate = TestCertificate.Find(); ServiceBusBuilder serviceBusBuilder = new ServiceBusBuilder(Substitute.For <ISimulation>()) .SetCertificate(certificate); var serviceBusSimulator = new ServiceBusSimulator(serviceBusBuilder); await serviceBusSimulator.StartAsync(); try { serviceBusSimulator.Port.ShouldBe(5671); } finally { await serviceBusSimulator.StopAsync(); } }
public async Task StartAsync_ReportsActiveLocation_WhenSecured() { using X509Certificate2 certificate = TestCertificate.Find(); ServiceBusBuilder serviceBusBuilder = new ServiceBusBuilder(Substitute.For <ISimulation>()) .SetCertificate(certificate); var serviceBusSimulator = new ServiceBusSimulator(serviceBusBuilder); await serviceBusSimulator.StartAsync(); try { serviceBusSimulator.Location.ShouldStartWith($"amqps://127.0.0.1:{serviceBusSimulator.Port}"); } finally { await serviceBusSimulator.StopAsync(); } }
public async Task StartAsync_UsesRandomPort_WhenDefaultIsUsed() { using (TestTcpUtils.BlockAllLocalPorts(5672)) { var serviceBusBuilder = new ServiceBusBuilder(Substitute.For <ISimulation>()); var serviceBusSimulator = new ServiceBusSimulator(serviceBusBuilder); await serviceBusSimulator.StartAsync(); try { serviceBusSimulator.Port.ShouldNotBe(5672); } finally { await serviceBusSimulator.StopAsync(); } } }
public async Task StartAsync_ReportsActivePortFromSettings_WhenSettingsPortNotZero(int port, bool secured) { var serviceBusBuilder = new ServiceBusBuilder(Substitute.For <ISimulation>()); serviceBusBuilder.SetPort(port); serviceBusBuilder.SetCertificate(secured ? new X509Certificate2() : null); var serviceBusSimulator = new ServiceBusSimulator(serviceBusBuilder); await serviceBusSimulator.StartAsync(); try { serviceBusSimulator.Port.ShouldBe(port); } finally { await serviceBusSimulator.StopAsync(); } }
public async Task StartAsync_Throws_WhenPortAlreadyInUse() { var availablePort = TestTcpUtils.FindFreePort(); using (TestTcpUtils.BlockAllLocalPorts(availablePort)) { ServiceBusBuilder serviceBusBuilder = new ServiceBusBuilder(Substitute.For <ISimulation>()).SetPort(availablePort); var serviceBusSimulator = new ServiceBusSimulator(serviceBusBuilder); Func <Task> action = async() => await serviceBusSimulator.StartAsync(); try { await action.ShouldThrowAsync <SocketException>(); serviceBusSimulator.State.ShouldBe(SimulatorState.Stopped); } finally { await serviceBusSimulator.StopAsync(); } } }