Exemplo n.º 1
0
        public static ContainerHost Open(int preferredPort = 0)
        {
            var port    = preferredPort == 0 ? TestTcpUtils.FindFreePort() : preferredPort;
            var address = new Address($"amqp://localhost:{port}");
            var host    = new ContainerHost(address);

            host.Listeners[0].SASL.EnableExternalMechanism  = true;
            host.Listeners[0].SASL.EnableAnonymousMechanism = true;
            host.Open();
            return(host);
        }
Exemplo n.º 2
0
        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();
                }
            }
        }
Exemplo n.º 3
0
        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();
                }
            }
        }