Example #1
0
        protected override IAmJustSayingFluently CreateSystemUnderTest()
        {
            var handler = Substitute.For <IHandler <GenericMessage> >();

            handler.When(x => x.Handle(Arg.Any <GenericMessage>()))
            .Do(x => _handler.Complete((GenericMessage)x.Args()[0]));

            Monitoring = Substitute.For <IMessageMonitor>();

            ServiceBus = CreateMeABus.InRegion(RegionEndpoint.EUWest1.SystemName)
                         .WithMonitoring(Monitoring)
                         .ConfigurePublisherWith(c =>
            {
                c.PublishFailureBackoffMilliseconds = _config.PublishFailureBackoffMilliseconds;
                c.PublishFailureReAttempts          = _config.PublishFailureReAttempts;
            })
                         .WithSnsMessagePublisher <GenericMessage>()
                         .WithSqsTopicSubscriber()
                         .IntoQueue("queuename")
                         .ConfigureSubscriptionWith(cf =>
            {
                cf.MessageRetentionSeconds  = 60;
                cf.VisibilityTimeoutSeconds = JustSayingConstants.DEFAULT_VISIBILITY_TIMEOUT;
                cf.InstancePosition         = 1;
            })
                         .WithMessageHandler(handler);

            ServiceBus.StartListening();
            return(ServiceBus);
        }
        protected override IAmJustSayingFluently CreateSystemUnderTest()
        {
            const int TimeoutMillis = 1000;

            var snsHandler = Substitute.For <IHandlerAsync <GenericMessage> >();

            snsHandler.When(x => x.Handle(Arg.Any <GenericMessage>()))
            .Do(x =>
            {
                var msg = (GenericMessage)x.Args()[0];
                if (_snsHandler != null)
                {
                    _snsHandler.Complete(msg).Wait(TimeoutMillis);
                }
            });

            var sqsHandler = Substitute.For <IHandlerAsync <AnotherGenericMessage> >();

            sqsHandler.When(x => x.Handle(Arg.Any <AnotherGenericMessage>()))
            .Do(x =>
            {
                var msg = (AnotherGenericMessage)x.Args()[0];
                if (_sqsHandler != null)
                {
                    _sqsHandler.Complete(msg).Wait(TimeoutMillis);
                }
            });

            Monitoring = Substitute.For <IMessageMonitor>();

            ServiceBus = CreateMeABus.WithLogging(new LoggerFactory())
                         .InRegion(RegionEndpoint.EUWest1.SystemName)
                         .WithMonitoring(Monitoring)

                         .ConfigurePublisherWith(c =>
            {
                c.PublishFailureBackoffMilliseconds = _config.PublishFailureBackoffMilliseconds;
                c.PublishFailureReAttempts          = _config.PublishFailureReAttempts;
            })

                         .WithSnsMessagePublisher <GenericMessage>()
                         .WithSqsTopicSubscriber()
                         .IntoQueue("queuename")
                         .ConfigureSubscriptionWith(cf =>
            {
                cf.MessageRetentionSeconds  = 60;
                cf.VisibilityTimeoutSeconds = JustSayingConstants.DEFAULT_VISIBILITY_TIMEOUT;
                cf.InstancePosition         = 1;
            })
                         .WithMessageHandler(snsHandler)

                         .WithSqsMessagePublisher <AnotherGenericMessage>(configuration => { })
                         .WithSqsPointToPointSubscriber()
                         .IntoDefaultQueue()
                         .WithMessageHandler(sqsHandler);

            ServiceBus.StartListening();
            return(ServiceBus);
        }
        protected override IAmJustSayingFluently CreateSystemUnderTest()
        {
            const int TimeoutMillis = 1000;

            var snsHandler = Substitute.For <IHandlerAsync <SimpleMessage> >();

            snsHandler.When(x => x.Handle(Arg.Any <SimpleMessage>()))
            .Do(x =>
            {
                var msg = (SimpleMessage)x.Args()[0];
                _snsHandler?.Complete(msg).Wait(TimeoutMillis);
            });

            var sqsHandler = Substitute.For <IHandlerAsync <AnotherSimpleMessage> >();

            sqsHandler.When(x => x.Handle(Arg.Any <AnotherSimpleMessage>()))
            .Do(x =>
            {
                var msg = (AnotherSimpleMessage)x.Args()[0];
                _sqsHandler?.Complete(msg).Wait(TimeoutMillis);
            });

            Monitoring = Substitute.For <IMessageMonitor>();

            ServiceBus = TestFixture.Builder()
                         .WithMonitoring(Monitoring)
                         .ConfigurePublisherWith(c =>
            {
                c.PublishFailureBackoffMilliseconds = _config.PublishFailureBackoffMilliseconds;
                c.PublishFailureReAttempts          = _config.PublishFailureReAttempts;
            })
                         .WithSnsMessagePublisher <SimpleMessage>()
                         .WithSqsTopicSubscriber()
                         .IntoQueue(TestFixture.UniqueName)
                         .ConfigureSubscriptionWith(cf =>
            {
                cf.MessageRetentionSeconds  = 60;
                cf.VisibilityTimeoutSeconds = JustSayingConstants.DefaultVisibilityTimeout;
                cf.InstancePosition         = 1;
            })
                         .WithMessageHandler(snsHandler)
                         .WithSqsMessagePublisher <AnotherSimpleMessage>(configuration => { })
                         .WithSqsPointToPointSubscriber()
                         .IntoDefaultQueue()
                         .WithMessageHandler(sqsHandler);

            ServiceBus.StartListening();

            return(ServiceBus);
        }