public void Returns_the_default_pool_size()
        {
            var property = CreateProperty();

            var factory = new SqlServerSequenceValueGeneratorFactory(new SqlStatementExecutor());

            Assert.Equal(5, factory.GetPoolSize(property));
        }
        public void Default_block_size_is_used_if_not_set_anywhere()
        {
            var property = CreateProperty();

            var factory = new SqlServerSequenceValueGeneratorFactory(new SqlStatementExecutor());

            Assert.Equal(SqlServerSequenceValueGeneratorFactory.DefaultBlockSize, factory.GetBlockSize(property));
        }
        public void Default_block_size_is_used_if_not_set_anywhere()
        {
            var property = CreateProperty();

            var factory = new SqlServerSequenceValueGeneratorFactory(new SqlStatementExecutor());

            Assert.Equal(SqlServerSequenceValueGeneratorFactory.DefaultBlockSize, factory.GetBlockSize(property));
        }
        public void Default_Sequence_name_is_used_if_not_set_anywhere()
        {
            var property = CreateProperty();

            var factory = new SqlServerSequenceValueGeneratorFactory(new SqlStatementExecutor());

            Assert.Equal("MyTable_Sequence", factory.GetSequenceName(property));
        }
        public void Block_size_is_obtained_from_model_annotation_if_not_set_on_property_or_type()
        {
            var property = CreateProperty();
            property.EntityType.Model["StoreSequenceBlockSize"] = "11";

            var factory = new SqlServerSequenceValueGeneratorFactory(new SqlStatementExecutor());

            Assert.Equal(11, factory.GetBlockSize(property));
        }
        public void Sequence_name_is_the_cache_key()
        {
            var property = CreateProperty();

            property["StoreSequenceName"] = "Led";

            var factory = new SqlServerSequenceValueGeneratorFactory(new SqlStatementExecutor());

            Assert.Equal("Led", factory.GetCacheKey(property));
        }
        public void Block_size_is_obtained_from_model_annotation_if_not_set_on_property_or_type()
        {
            var property = CreateProperty();

            property.EntityType.Model["StoreSequenceBlockSize"] = "11";

            var factory = new SqlServerSequenceValueGeneratorFactory(new SqlStatementExecutor());

            Assert.Equal(11, factory.GetBlockSize(property));
        }
        public void Sequence_name_is_obtained_from_model_annotation_if_not_set_on_property_or_type()
        {
            var property = CreateProperty();

            property.EntityType.Model["StoreSequenceName"] = "Robert";

            var factory = new SqlServerSequenceValueGeneratorFactory(new SqlStatementExecutor());

            Assert.Equal("Robert", factory.GetSequenceName(property));
        }
        public void Sequence_name_is_obtained_from_entity_type_annotation_if_not_set_on_property()
        {
            var property = CreateProperty();
            property.EntityType["StoreSequenceName"] = "Robert";
            property.EntityType.Model["StoreSequenceName"] = "Jimmy";

            var factory = new SqlServerSequenceValueGeneratorFactory(new SqlStatementExecutor());

            Assert.Equal("Robert", factory.GetSequenceName(property));
        }
        public void Creates_DropSequenceOperation()
        {
            var property = CreateProperty();

            property["StoreSequenceName"] = "Page";

            var factory = new SqlServerSequenceValueGeneratorFactory(new SqlStatementExecutor());

            var operation = (DropSequenceOperation)factory.GetDownMigrationOperations(property).Single();

            Assert.Equal("Page", operation.SequenceName);
        }
        public void Sequence_name_is_the_cache_key()
        {
            var property = new ModelBuilder()
                           .Entity <Robot>()
                           .Property(e => e.Id)
                           .ForSqlServer(b => b.UseSequence("DaneelOlivaw", "R"))
                           .Metadata;

            var factory = new SqlServerSequenceValueGeneratorFactory(new SqlStatementExecutor(new LoggerFactory()));

            Assert.Equal("R.DaneelOlivaw", factory.GetCacheKey(property));
        }
        public void Sequence_name_is_obtained_from_default_sequence()
        {
            var property = new ModelBuilder()
                           .Entity <Robot>()
                           .Property(e => e.Id)
                           .ForSqlServer(b => b.UseSequence())
                           .Metadata;

            var factory = new SqlServerSequenceValueGeneratorFactory(new SqlStatementExecutor(new LoggerFactory()));

            Assert.Equal("EntityFrameworkDefaultSequence", factory.GetSequenceName(property));
        }
        public void Schema_qualified_sequence_name_is_obtained_from_named_sequence()
        {
            var property = new ModelBuilder()
                           .Entity <Robot>()
                           .Property(e => e.Id)
                           .ForSqlServer(b => b.UseSequence("DaneelOlivaw", "R"))
                           .Metadata;

            var factory = new SqlServerSequenceValueGeneratorFactory(new SqlStatementExecutor(new LoggerFactory()));

            Assert.Equal("R.DaneelOlivaw", factory.GetSequenceName(property));
        }
Esempio n. 14
0
        public void Block_size_is_obtained_from_named_sequence()
        {
            var property = CreateConventionModelBuilder()
                           .Entity <Robot>()
                           .Property(e => e.Id)
                           .ForSqlServer(b => b.UseSequence("DaneelOlivaw"))
                           .Metadata;

            var factory = new SqlServerSequenceValueGeneratorFactory(new SqlStatementExecutor(new LoggerFactory()));

            Assert.Equal(10, factory.GetBlockSize(property));
        }
Esempio n. 15
0
        public void Sequence_name_is_obtained_from_specified_sequence()
        {
            var property = CreateConventionModelBuilder()
                           .ForSqlServer(b => b.Sequence("DaneelOlivaw").IncrementBy(11))
                           .Entity <Robot>()
                           .Property(e => e.Id)
                           .ForSqlServer(b => b.UseSequence("DaneelOlivaw"))
                           .Metadata;

            var factory = new SqlServerSequenceValueGeneratorFactory(new SqlStatementExecutor(new LoggerFactory()));

            Assert.Equal("DaneelOlivaw", factory.GetSequenceName(property));
        }
        public void Block_size_is_obtained_from_specified_default_sequence()
        {
            var property = new ModelBuilder()
                           .ForSqlServer(b => b.Sequence().IncrementBy(11))
                           .Entity <Robot>()
                           .Property(e => e.Id)
                           .ForSqlServer(b => b.UseSequence())
                           .Metadata;

            var factory = new SqlServerSequenceValueGeneratorFactory(new SqlStatementExecutor(new LoggerFactory()));

            Assert.Equal(11, factory.GetBlockSize(property));
        }
        public void Creates_the_appropriate_value_generator()
        {
            var property = CreateProperty();

            property["StoreSequenceBlockSize"] = "11";
            property["StoreSequenceName"]      = "Zeppelin";

            var factory = new SqlServerSequenceValueGeneratorFactory(new SqlStatementExecutor());

            var generator = (SqlServerSequenceValueGenerator)factory.Create(property);

            Assert.Equal("Zeppelin", generator.SequenceName);
            Assert.Equal(11, generator.BlockSize);
        }
        public void Non_positive_block_sizes_are_not_allowed()
        {
            var property = new ModelBuilder()
                           .ForSqlServer(b => b.Sequence("DaneelOlivaw").IncrementBy(-1))
                           .Entity <Robot>()
                           .Property(e => e.Id)
                           .ForSqlServer(b => b.UseSequence("DaneelOlivaw"))
                           .Metadata;

            var factory = new SqlServerSequenceValueGeneratorFactory(new SqlStatementExecutor(new LoggerFactory()));

            Assert.Equal(
                Strings.SequenceBadBlockSize(-1, "DaneelOlivaw"),
                Assert.Throws <NotSupportedException>(() => factory.GetBlockSize(property)).Message);
        }
        public void Returns_sequence_generator_for_all_integer_types_setup_for_server_values()
        {
            var sequenceFactory = new SqlServerSequenceValueGeneratorFactory(new SqlStatementExecutor());

            var selector = new SqlServerValueGeneratorSelector(
                new SimpleValueGeneratorFactory<GuidValueGenerator>(),
                new SimpleValueGeneratorFactory<TemporaryValueGenerator>(),
                sequenceFactory,
                new SimpleValueGeneratorFactory<SequentialGuidValueGenerator>());

            Assert.Same(sequenceFactory, selector.Select(CreateProperty(typeof(long), ValueGenerationOnAdd.Server)));
            Assert.Same(sequenceFactory, selector.Select(CreateProperty(typeof(int), ValueGenerationOnAdd.Server)));
            Assert.Same(sequenceFactory, selector.Select(CreateProperty(typeof(short), ValueGenerationOnAdd.Server)));
            Assert.Same(sequenceFactory, selector.Select(CreateProperty(typeof(byte), ValueGenerationOnAdd.Server)));
        }
        public void Returns_sequence_generator_for_all_integer_types_setup_for_server_values()
        {
            var sequenceFactory = new SqlServerSequenceValueGeneratorFactory(new SqlStatementExecutor());

            var selector = new SqlServerValueGeneratorSelector(
                new SimpleValueGeneratorFactory <GuidValueGenerator>(),
                new SimpleValueGeneratorFactory <TemporaryValueGenerator>(),
                sequenceFactory,
                new SimpleValueGeneratorFactory <SequentialGuidValueGenerator>());

            Assert.Same(sequenceFactory, selector.Select(CreateProperty(typeof(long), ValueGenerationOnAdd.Server)));
            Assert.Same(sequenceFactory, selector.Select(CreateProperty(typeof(int), ValueGenerationOnAdd.Server)));
            Assert.Same(sequenceFactory, selector.Select(CreateProperty(typeof(short), ValueGenerationOnAdd.Server)));
            Assert.Same(sequenceFactory, selector.Select(CreateProperty(typeof(byte), ValueGenerationOnAdd.Server)));
        }
        public void Returns_sequence_generator_when_explicitly_configured_on_model()
        {
            var sequenceFactory = new SqlServerSequenceValueGeneratorFactory(new SqlStatementExecutor(new LoggerFactory()));

            var selector = new SqlServerValueGeneratorSelector(
                new SimpleValueGeneratorFactory <GuidValueGenerator>(),
                new SimpleValueGeneratorFactory <TemporaryValueGenerator>(),
                sequenceFactory,
                new SimpleValueGeneratorFactory <SequentialGuidValueGenerator>());

            Assert.Same(sequenceFactory, selector.Select(CreateModelSequenceProperty <long>()));
            Assert.Same(sequenceFactory, selector.Select(CreateModelSequenceProperty <int>()));
            Assert.Same(sequenceFactory, selector.Select(CreateModelSequenceProperty <short>()));
            Assert.Same(sequenceFactory, selector.Select(CreateModelSequenceProperty <byte>()));
        }
        public void Creates_CreateSequenceOperation()
        {
            var property = CreateProperty();

            property["StoreSequenceBlockSize"] = "11";
            property["StoreSequenceName"]      = "Plant";

            var factory = new SqlServerSequenceValueGeneratorFactory(new SqlStatementExecutor());

            var operation = (CreateSequenceOperation)factory.GetUpMigrationOperations(property).Single();

            Assert.Equal("BIGINT", operation.Sequence.DataType);
            Assert.Equal(0, operation.Sequence.StartWith);
            Assert.Equal(11, operation.Sequence.IncrementBy);
            Assert.Equal("Plant", operation.Sequence.Name);
        }
        public void Creates_the_appropriate_value_generator()
        {
            var property = new ModelBuilder()
                           .ForSqlServer(b => b.Sequence("DaneelOlivaw", "R").IncrementBy(11))
                           .Entity <Robot>()
                           .Property(e => e.Id)
                           .ForSqlServer(b => b.UseSequence("DaneelOlivaw", "R"))
                           .Metadata;

            var factory = new SqlServerSequenceValueGeneratorFactory(new SqlStatementExecutor(new LoggerFactory()));

            var generator = (SqlServerSequenceValueGenerator)factory.Create(property);

            Assert.Equal("R.DaneelOlivaw", generator.SequenceName);
            Assert.Equal(11, generator.BlockSize);
        }
        private static void CreateDatabaseSequence(BronieContext context, DataStoreConnection storeConnection)
        {
            var executor = new SqlStatementExecutor();

            var operations = new SqlServerSequenceValueGeneratorFactory(executor)
                             .GetUpMigrationOperations(context.Model.GetEntityType(typeof(Pegasus))
                                                       .GetProperty("Identifier"));

            var sql = new SqlServerMigrationOperationSqlGenerator(new SqlServerTypeMapper())
                      .Generate(operations, generateIdempotentSql: false);

            // TODO: Should be able to get relational connection without cast
            var connection = ((RelationalConnection)storeConnection).DbConnection;

            executor.ExecuteNonQuery(connection, sql);
        }
Esempio n. 25
0
        public void Sequence_name_is_obtained_from_model_specified_model_default_sequence()
        {
            var property = CreateConventionModelBuilder()
                           .ForSqlServer(b =>
            {
                b.UseSequence();
                b.Sequence().IncrementBy(11);
            })
                           .Entity <Robot>()
                           .Property(e => e.Id)
                           .GenerateValueOnAdd()
                           .Metadata;

            var factory = new SqlServerSequenceValueGeneratorFactory(new SqlStatementExecutor(new LoggerFactory()));

            Assert.Equal("EntityFrameworkDefaultSequence", factory.GetSequenceName(property));
        }
        public void Creates_CreateSequenceOperation()
        {
            var property = CreateProperty();
            property["StoreSequenceBlockSize"] = "11";
            property["StoreSequenceName"] = "Plant";

            var factory = new SqlServerSequenceValueGeneratorFactory(new SqlStatementExecutor());

            var operation = (CreateSequenceOperation)factory.GetUpMigrationOperations(property).Single();

            Assert.Equal("BIGINT", operation.Sequence.DataType);
            Assert.Equal(0, operation.Sequence.StartWith);
            Assert.Equal(11, operation.Sequence.IncrementBy);
            Assert.Equal("Plant", operation.Sequence.Name);
        }
        public void Creates_DropSequenceOperation()
        {
            var property = CreateProperty();
            property["StoreSequenceName"] = "Page";

            var factory = new SqlServerSequenceValueGeneratorFactory(new SqlStatementExecutor());

            var operation = (DropSequenceOperation)factory.GetDownMigrationOperations(property).Single();

            Assert.Equal("Page", operation.SequenceName);
        }
        public void Creates_the_appropriate_value_generator()
        {
            var property = CreateProperty();
            property["StoreSequenceBlockSize"] = "11";
            property["StoreSequenceName"] = "Zeppelin";

            var factory = new SqlServerSequenceValueGeneratorFactory(new SqlStatementExecutor());

            var generator = (SqlServerSequenceValueGenerator)factory.Create(property);

            Assert.Equal("Zeppelin", generator.SequenceName);
            Assert.Equal(11, generator.BlockSize);
        }
        public void Returns_the_default_pool_size()
        {
            var property = CreateProperty();

            var factory = new SqlServerSequenceValueGeneratorFactory(new SqlStatementExecutor());

            Assert.Equal(5, factory.GetPoolSize(property));
        }
        public void Sequence_name_is_the_cache_key()
        {
            var property = CreateProperty();
            property["StoreSequenceName"] = "Led";

            var factory = new SqlServerSequenceValueGeneratorFactory(new SqlStatementExecutor());

            Assert.Equal("Led", factory.GetCacheKey(property));
        }
        public void Default_Sequence_name_is_used_if_not_set_anywhere()
        {
            var property = CreateProperty();

            var factory = new SqlServerSequenceValueGeneratorFactory(new SqlStatementExecutor());

            Assert.Equal("MyTable_Sequence", factory.GetSequenceName(property));
        }
        private static void CreateDatabaseSequence(BronieContext context, RelationalConnection storeConnection)
        {
            var executor = new SqlStatementExecutor();

            var operations = new SqlServerSequenceValueGeneratorFactory(executor)
                .GetUpMigrationOperations(context.Model.GetEntityType(typeof(Pegasus))
                    .GetProperty("Identifier"));

            var sql = new SqlServerMigrationOperationSqlGenerator(new SqlServerTypeMapper())
                .Generate(operations);

            // TODO: Should be able to get relational connection without cast
            var connection = storeConnection.DbConnection;

            executor.ExecuteNonQuery(connection, storeConnection.DbTransaction, sql);
        }