Exemplo n.º 1
0
        public void Initialize()
        {
            fixture = new Fixture();

            mockBusEngine = new Mock <IBusEngine>();

            mockLogger        = new Mock <ILogger>();
            mockLoggerFactory = new Mock <ILoggerFactory>();

            mockLoggerFactory.Setup(p => p.CreateLogger(It.IsAny <string>())).Returns(() => mockLogger.Object);

            mockCommandContextFactory  = new Mock <ICommandContextFactory>();
            mockCommandMessageFactory  = new Mock <ICommandMessageFactory>();
            mockEventContextFactory    = new Mock <IEventContextFactory>();
            mockEventMessageFactory    = new Mock <IEventMessageFactory>();
            mockContainer              = new Mock <IContainer>();
            mockCorrelationIdGenerator = new Mock <ICorrelationIdGenerator>();

            options = new NybusOptions
            {
                LoggerFactory          = mockLoggerFactory.Object,
                CommandContextFactory  = mockCommandContextFactory.Object,
                EventContextFactory    = mockEventContextFactory.Object,
                CommandMessageFactory  = mockCommandMessageFactory.Object,
                EventMessageFactory    = mockEventMessageFactory.Object,
                Container              = mockContainer.Object,
                CorrelationIdGenerator = mockCorrelationIdGenerator.Object
            };
        }
Exemplo n.º 2
0
        public void Initialize()
        {
            fixture = new Fixture();

            testBusEngine = new InMemoryBusEngine();

            mockLoggerFactory         = new Mock <ILoggerFactory>();
            mockLogger                = new Mock <ILogger>();
            mockCommandContextFactory = new Mock <ICommandContextFactory>();
            mockCommandMessageFactory = new Mock <ICommandMessageFactory>();
            mockEventContextFactory   = new Mock <IEventContextFactory>();
            mockEventMessageFactory   = new Mock <IEventMessageFactory>();
            mockContainer             = new Mock <IContainer>();
            mockScope = new Mock <IScope>();
            mockCorrelationIdGenerator = new Mock <ICorrelationIdGenerator>();

            options = new NybusOptions
            {
                LoggerFactory          = mockLoggerFactory.Object,
                CommandContextFactory  = mockCommandContextFactory.Object,
                EventContextFactory    = mockEventContextFactory.Object,
                CommandMessageFactory  = mockCommandMessageFactory.Object,
                EventMessageFactory    = mockEventMessageFactory.Object,
                Container              = mockContainer.Object,
                CorrelationIdGenerator = mockCorrelationIdGenerator.Object
            };

            mockCommandHandler = new Mock <ICommandHandler <TestCommand> >();
            mockEventHandler   = new Mock <IEventHandler <TestEvent> >();

            mockContainer.Setup(p => p.BeginScope()).Returns(mockScope.Object);

            mockLoggerFactory.Setup(p => p.CreateLogger(It.IsAny <string>())).Returns(() => mockLogger.Object);
        }
Exemplo n.º 3
0
            public void Options_are_configured()
            {
                var options = new NybusOptions();

                options.UseCastleWindsor(MockKernel.Object);

                Assert.That(options.Container, Is.InstanceOf <WindsorBusContainer>());

                WindsorBusContainer container = (WindsorBusContainer)options.Container;

                Assert.That(container.Kernel, Is.SameAs(MockKernel.Object));
            }
        public static void UseCastleWindsor(this NybusOptions options, IKernel kernel)
        {
            if (options == null)
            {
                throw new ArgumentNullException(nameof(options));
            }

            if (kernel == null)
            {
                throw new ArgumentNullException(nameof(kernel));
            }

            options.Container = new WindsorBusContainer(kernel);
        }
Exemplo n.º 5
0
        public static IServiceCollection AddNybusLegacy(this IServiceCollection services, NybusConfigurator nybusConfigurator = null, SubscriptionsConfigurator subscriptionsConfigurator = null)
        {
            services.AddHostedService <NybusLegacyHostedService>();

            services.AddSingleton <IContainer, ServiceProviderContainer>();

            services.AddSingleton(Clock.Default);

            services.AddSingleton <ILoggerFactory, NybusLoggerFactoryAdapter>();

            services.AddSingleton <NybusOptions>();

            services.AddSingleton <IBusEngine, InMemoryBusEngine>();

            services.AddSingleton <IBusBuilder>(sp =>
            {
                var container = sp.GetRequiredService <IContainer>();

                var engine = sp.GetRequiredService <IBusEngine>();

                var loggerFactory = sp.GetRequiredService <ILoggerFactory>();

                var options = new NybusOptions
                {
                    Container     = container,
                    LoggerFactory = loggerFactory
                };

                nybusConfigurator?.Invoke(options);

                var builder = new NybusBusBuilder(engine, options);

                subscriptionsConfigurator?.Invoke(builder);

                return(builder);
            });

            services.AddSingleton(sp =>
            {
                var builder = sp.GetRequiredService <IBusBuilder>();

                return(builder.Build());
            });

            return(services);
        }
Exemplo n.º 6
0
            public void Requires_Kernel()
            {
                var options = new NybusOptions();

                WindsorExtensions.UseCastleWindsor(options, null);
            }