protected override async Task When()
        {
            var overallConcurrentHandlerLimit = Math.Min(Instance.Configuration.ConcurrentHandlerLimit.Value, Instance.Configuration.GlobalConcurrentHandlerLimit.Value);

            _totalCommandsToSend = overallConcurrentHandlerLimit * 2;
            _expectedNumberOfCommandsToBeSeenBeforeTheBusStops = overallConcurrentHandlerLimit;

            SlowCommandHandler.Reset();

            await Enumerable.Range(0, _totalCommandsToSend)
            .Select(i => Bus.Send(new SlowCommand()))
            .WhenAll();

            await TimeSpan.FromSeconds(TimeoutSeconds)
            .WaitUntil(() => MethodCallCounter.AllReceivedMessages.OfType <SlowCommand>().Count() >= _expectedNumberOfCommandsToBeSeenBeforeTheBusStops);

            _messagesReceivedBeforeTheBusWasStopped = MethodCallCounter.AllReceivedMessages.OfType <SlowCommand>().Count();
            await Bus.Stop();

            MethodCallCounter.Clear();
            SlowCommandHandler.HandlerSemaphore.Release(_totalCommandsToSend);
            await Task.Delay(TimeSpan.FromSeconds(0.25));

            _messagesReceivedAfterTheBusWasStopped = MethodCallCounter.AllReceivedMessages.OfType <SlowCommand>().Count();
        }
        private const int _expectedTotalCallCount = 11; // 5 interceptors * 2 + 1 handler

        protected override async Task <IBus> Given()
        {
            MethodCallCounter.Clear();

            var testFixtureType = GetType();
            var typeProvider    = new TestHarnessTypeProvider(new[] { testFixtureType.Assembly }, new[] { testFixtureType.Namespace });
            var logger          = TestHarnessLoggerFactory.Create();

            var bus = new BusBuilder().Configure()
                      .WithTransport(new InProcessTransportConfiguration())
                      .WithNames("MyTestSuite", Environment.MachineName)
                      .WithTypesFrom(typeProvider)
                      .WithDependencyResolver(new DependencyResolver(typeProvider))
                      .WithDefaultTimeout(TimeSpan.FromSeconds(TimeoutSeconds))
                      .WithMaxDeliveryAttempts(1)
                      .WithGlobalInboundInterceptorTypes(typeof(SomeGlobalInterceptor))
                      .WithLogger(logger)
                      .WithDebugOptions(
                dc =>
                dc.RemoveAllExistingNamespaceElementsOnStartup(
                    "I understand this will delete EVERYTHING in my namespace. I promise to only use this for test suites."))
                      .Build();
            await bus.Start();

            return(bus);
        }
        protected override async Task <IBus> Given()
        {
            MethodCallCounter.Clear();

            var testFixtureType = GetType();
            var outboundAuditingInterceptorType = typeof(OutboundAuditingInterceptor);
            var auditEventType = typeof(AuditEvent);
            var typeProvider   = new TestHarnessTypeProvider(new[] { testFixtureType.Assembly, outboundAuditingInterceptorType.Assembly },
                                                             new[] { testFixtureType.Namespace, outboundAuditingInterceptorType.Namespace, auditEventType.Namespace });
            var logger = TestHarnessLoggerFactory.Create();

            var dependencyResolver = new DependencyResolver(typeProvider);

            var bus = new BusBuilder().Configure()
                      .WithNames("MyTestSuite", Environment.MachineName)
                      .WithConnectionString(CommonResources.ServiceBusConnectionString)
                      .WithTypesFrom(typeProvider)
                      .WithDependencyResolver(dependencyResolver)
                      .WithDefaultTimeout(TimeSpan.FromSeconds(10))
                      .WithMaxDeliveryAttempts(1)
                      .WithHeartbeatInterval(TimeSpan.MaxValue)
                      .WithGlobalOutboundInterceptorTypes(typeof(OutboundAuditingInterceptor))
                      .WithLogger(logger)
                      .WithDebugOptions(
                dc =>
                dc.RemoveAllExistingNamespaceElementsOnStartup(
                    "I understand this will delete EVERYTHING in my namespace. I promise to only use this for test suites."))
                      .Build();

            await bus.Start();

            return(bus);
        }
Beispiel #4
0
        protected virtual async Task Given(IConfigurationScenario <BusBuilderConfiguration> scenario)
        {
            MethodCallCounter.Clear();

            Instance = scenario.CreateInstance();
            Reconfigure();

            Bus = Instance.Configuration.Build();
            await Bus.Start();
        }
        protected override async Task When()
        {
            MethodCallCounter.Clear();

            var command1 = new FooCommand(_id1);
            var command2 = new FooCommand(_id2);

            await Subject.Dispatch(await _brokeredMessageFactory.Create(command1));

            await Subject.Dispatch(await _brokeredMessageFactory.Create(command2));

            MethodCallCounter.Stop();
        }
        protected override async Task When()
        {
            Enumerable.Range(0, _totalCommands)
            .Select(i => Bus.Send(new SlowCommand()))
            .WaitAll();
            await Task.Delay(TimeSpan.FromMilliseconds(500));

            await Bus.Stop();

            _commandHandlerInvocationCount = MethodCallCounter.AllReceivedMessages.OfType <SlowCommand>().Count();
            Console.WriteLine("Bus has stopped.");
            Console.WriteLine("Number of commands received immediately afterwards: {0}", _commandHandlerInvocationCount);
            MethodCallCounter.Clear();

            await Task.Delay(TimeSpan.FromSeconds(2));

            _additionalCommandHandlerInvocationCount = MethodCallCounter.AllReceivedMessages.OfType <SlowCommand>().Count();
            Console.WriteLine("Number of commands received after that: {0}", _additionalCommandHandlerInvocationCount);
            MethodCallCounter.Stop();
        }
Beispiel #7
0
        public virtual void TestFixtureSetUp()
        {
            Task.Run(async() =>
            {
                MethodCallCounter.Clear();
                Subject = await Given();

                _sw = Stopwatch.StartNew();
                try
                {
                    await When();
                }
                finally
                {
                    _sw.Stop();

                    Console.WriteLine("Elapsed time: {0} seconds", _sw.Elapsed.TotalSeconds);
                }
            }).Wait();
        }
Beispiel #8
0
        public void TestFixtureSetUp()
        {
            Task.Run(async() =>
            {
                MethodCallCounter.Clear();

                Bus = await new TestHarnessBusFactory(GetType()).CreateAndStart();
                Console.WriteLine();
                Console.WriteLine();

                await Given();
                Console.WriteLine();
                Console.WriteLine();

                await When();
                MethodCallCounter.Stop();
                Console.WriteLine();
                Console.WriteLine();
            }).Wait();
        }