Ejemplo n.º 1
0
        public void ThrowExceptionWhenTryConfigureAfterBuild()
        {
            IDatabaseBuilder builder = Database
                                       .Builder
                                       .UseConnection(ServerHelper.Connection);

            builder.Build();

            IModelFactory         modelFactory         = Substitute.For <IModelFactory>();
            IQueryProviderFactory queryProviderFactory = Substitute.For <IQueryProviderFactory>();

            void ShouldThrowException(Action action)
            {
                action
                .Should()
                .Throw <InvalidOperationException>(
                    "The configuration is not allowed if the Build method has already been called.");
            }

            ShouldThrowException(() => builder.UseConnection(ServerHelper.Connection));
            ShouldThrowException(() => builder.UseConnection(ServerHelper.Connection.ConnectionString));
            ShouldThrowException(() => builder.UseDatabaseConfiguration <DatabaseConfiguration>());
            ShouldThrowException(() => builder.UseDatabaseConfiguration(new DatabaseConfiguration()));
            ShouldThrowException(() => builder.UseModelFactory(modelFactory));
            ShouldThrowException(() => builder.UseQueryProviderFactory(queryProviderFactory));
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="KormBuilder"/> class.
        /// </summary>
        /// <param name="services">The service collection.</param>
        /// <param name="connectionSettings">The database connection settings.</param>
        public KormBuilder(IServiceCollection services, KormConnectionSettings connectionSettings)
        {
            Services           = Check.NotNull(services, nameof(services));
            ConnectionSettings = Check.NotNull(connectionSettings, nameof(connectionSettings));
            Check.NotNullOrWhiteSpace(
                connectionSettings.ConnectionString, nameof(connectionSettings), Resources.EmptyConnectionStringInSettings);

            _builder = Database.Builder;
            _builder.UseConnection(connectionSettings);
        }
 /// <summary>
 /// Use <paramref name="connectionString"/> which instance of <see cref="IDatabase"/> will use for accessing to database.
 /// </summary>
 /// <param name="builder">Databse builder.</param>
 /// <param name="connectionString">Connection string.</param>
 /// <returns>Database builder.</returns>
 public static IDatabaseBuilder UseConnection(this IDatabaseBuilder builder, string connectionString)
 => builder.UseConnection(new KormConnectionSettings()
 {
     ConnectionString = connectionString
 });