예제 #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));
        }