Example #1
0
        public void ConnectionStringProvider_should_return_connection_string_specified_in_the_configuration_file()
        {
            //Arrange
            var provider = new ConnectionStringConfigurationParameterProvider();

            //Assert
            Assert.AreEqual(ConfigurationManager.ConnectionStrings["CSTest1"], provider.GetConnectionString("CSTest1"));
        }
Example #2
0
        public void ConnectionStringProvider_shuld_throw_ConfigurationErrorsException_when_name_does_not_exist()
        {
            //Arrange
            var provider = new ConnectionStringConfigurationParameterProvider();

            //Assert
            Assert.Throws <ConfigurationErrorsException>(() => provider.GetConnectionString("ErrorTest1"));
        }
Example #3
0
        public void ConnectionStringProvider_exception_should_contain_ConnectionString_name()
        {
            //Arrange
            var parameterKey = "ErrorTest1";
            var provider     = new ConnectionStringConfigurationParameterProvider();

            //Assert
            var exc = Assert.Throws <ConfigurationErrorsException>(() => provider.GetConnectionString(parameterKey));

            exc.Message.Should().Contain(parameterKey);
        }
        protected static WindsorContainer CreateContainerForEventStoreType(Func <IReadOnlyList <IEventMigration> > migrationsfactory, Type eventStoreType, string eventStoreConnectionString = null)
        {
            var container = new WindsorContainer();

            container.ConfigureWiringForTestsCallBeforeAllOtherWiring();

            container.Register(
                Component.For <IUtcTimeTimeSource, DummyTimeSource>()
                .Instance(DummyTimeSource.Now)
                .LifestyleSingleton(),
                Component.For <IServiceBus>()
                .ImplementedBy <SynchronousBus>()
                .LifestylePerWebRequest(),
                Component.For <IEnumerable <IEventMigration> >()
                .UsingFactoryMethod(migrationsfactory)
                .LifestylePerWebRequest(),
                Component.For <IEventStoreSession, IUnitOfWorkParticipant>()
                .ImplementedBy <EventStoreSession>()
                .LifestylePerWebRequest(),
                Component.For <IWindsorContainer>().Instance(container)
                );


            if (eventStoreType == typeof(SqlServerEventStore))
            {
                if (eventStoreConnectionString == null)
                {
                    var masterConnectionSTring = new ConnectionStringConfigurationParameterProvider().GetConnectionString("MasterDB");
                    var dbManager = new TemporaryLocalDbManager(masterConnectionSTring.ConnectionString, container);

                    eventStoreConnectionString = dbManager.CreateOrGetLocalDb($"{nameof(EventStreamMutatorTestsBase)}_EventStore");
                }

                container.Register(
                    Component.For <IEventStore>()
                    .ImplementedBy <SqlServerEventStore>()
                    .DependsOn(Dependency.OnValue <string>(eventStoreConnectionString))
                    .LifestyleScoped());
            }
            else if (eventStoreType == typeof(InMemoryEventStore))
            {
                container.Register(
                    Component.For <IEventStore>()
                    .UsingFactoryMethod(
                        kernel =>
                {
                    var store = kernel.Resolve <InMemoryEventStore>();
                    store.TestingOnlyReplaceMigrations(migrationsfactory());
                    return(store);
                })
                    .LifestyleScoped(),
                    Component.For <InMemoryEventStore>()
                    .ImplementedBy <InMemoryEventStore>()
                    .LifestyleSingleton());
            }
            else
            {
                throw new Exception($"Unsupported type of event store {eventStoreType}");
            }

            container.ConfigureWiringForTestsCallAfterAllOtherWiring();
            return(container);
        }