Esempio n. 1
0
        public async Task Should_reuse_name_after_it_is_freed_although_previously_not_dropped()
        {
            ConfigureModel = builder => builder.ConfigureTempTableEntity <CustomTempTable>();

            var options = new TempTableCreationOptions
            {
                TableNameProvider  = ReusingTempTableNameProvider.Instance,
                PrimaryKeyCreation = PrimaryKeyPropertiesProviders.None,
                DropTableOnDispose = false
            };

            // ReSharper disable once RedundantArgumentDefaultValue
            await using (await SUT.CreateTempTableAsync(ActDbContext.GetEntityType <CustomTempTable>(), options).ConfigureAwait(false))
            {
            }

            options.TruncateTableIfExists = true;
            await using var tempTable     = await SUT.CreateTempTableAsync(ActDbContext.GetEntityType <CustomTempTable>(), options).ConfigureAwait(false);

            var columns = AssertDbContext.GetTempTableColumns("#CustomTempTable_1").ToList();

            columns.Should().HaveCount(2);

            ValidateColumn(columns[0], nameof(CustomTempTable.Column1), "int", false);
            ValidateColumn(columns[1], nameof(CustomTempTable.Column2), "nvarchar", true);

            AssertDbContext.GetTempTableColumns("#CustomTempTable_2").ToList()
            .Should().HaveCount(0);
        }
Esempio n. 2
0
        public async Task Should_reuse_name_in_sorted_order()
        {
            ConfigureModel = builder => builder.ConfigureTempTableEntity <CustomTempTable>();

            var options = new TempTableCreationOptions {
                TableNameProvider = ReusingTempTableNameProvider.Instance, PrimaryKeyCreation = PrimaryKeyPropertiesProviders.None
            };

            // #CustomTempTable_1
            await using (await SUT.CreateTempTableAsync(ActDbContext.GetEntityType <CustomTempTable>(), options).ConfigureAwait(false))
            {
                // #CustomTempTable_2
                await using (await SUT.CreateTempTableAsync(ActDbContext.GetEntityType <CustomTempTable>(), options).ConfigureAwait(false))
                {
                }
            }

            // #CustomTempTable_1
            await using var tempTable = await SUT.CreateTempTableAsync(ActDbContext.GetEntityType <CustomTempTable>(), options).ConfigureAwait(false);

            var columns = AssertDbContext.GetTempTableColumns("#CustomTempTable_1").ToList();

            columns.Should().HaveCount(2);

            ValidateColumn(columns[0], nameof(CustomTempTable.Column1), "int", false);
            ValidateColumn(columns[1], nameof(CustomTempTable.Column2), "nvarchar", true);
        }
Esempio n. 3
0
        public async Task Should_create_temp_table_with_one_column()
        {
            ConfigureModel = builder => builder.ConfigureTempTable <int>();

            await using var tempTable = await SUT.CreateTempTableAsync(ActDbContext.GetEntityType <TempTable <int> >(), _optionsWithNonUniqueName);

            AssertDbContext.GetTempTableColumns <TempTable <int> >().ToList().Should().HaveCount(1);
        }
        public async Task Should_create_temp_table_with_one_column()
        {
            ConfigureModel = builder => builder.ConfigureTempTable <int>();

            await _sut.CreateTempTableAsync(ActDbContext, ActDbContext.GetEntityType <TempTable <int> >(), new TempTableCreationOptions()).ConfigureAwait(false);

            AssertDbContext.GetTempTableColumns <TempTable <int> >().ToList().Should().HaveCount(1);
        }
Esempio n. 5
0
        public async Task Should_create_temp_table_with_decimal_with_explicit_precision()
        {
            ConfigureModel = builder => builder.ConfigureTempTable <decimal>().Property(t => t.Column1).HasColumnType("decimal(20,5)");

            await using var tempTable = await SUT.CreateTempTableAsync(ActDbContext.GetEntityType <TempTable <decimal> >(), _optionsWithNonUniqueName);

            var columns = AssertDbContext.GetTempTableColumns <TempTable <decimal> >().ToList();

            ValidateColumn(columns[0], nameof(TempTable <decimal> .Column1), "decimal", false, 20, 5);
        }
Esempio n. 6
0
        public async Task Should_create_temp_table_with_bool()
        {
            ConfigureModel = builder => builder.ConfigureTempTable <bool>();

            await using var tempTable = await SUT.CreateTempTableAsync(ActDbContext.GetEntityType <TempTable <bool> >(), _optionsWithNonUniqueName);

            var columns = AssertDbContext.GetTempTableColumns <TempTable <bool> >().ToList();

            ValidateColumn(columns[0], nameof(TempTable <bool> .Column1), "bit", false);
        }
Esempio n. 7
0
        public async Task Should_create_temp_table_with_string_with_max_length()
        {
            ConfigureModel = builder => builder.ConfigureTempTable <string>().Property(t => t.Column1).HasMaxLength(50);

            await using var tempTable = await SUT.CreateTempTableAsync(ActDbContext.GetEntityType <TempTable <string> >(), _optionsWithNonUniqueName);

            var columns = AssertDbContext.GetTempTableColumns <TempTable <string> >().ToList();

            ValidateColumn(columns[0], nameof(TempTable <string> .Column1), "nvarchar", false, charMaxLength: 50);
        }
        public async Task Should_create_temp_table_with_nullable_int()
        {
            ConfigureModel = builder => builder.ConfigureTempTable <int?>();

            await _sut.CreateTempTableAsync(ActDbContext, ActDbContext.GetEntityType <TempTable <int?> >(), new TempTableCreationOptions()).ConfigureAwait(false);

            var columns = AssertDbContext.GetTempTableColumns <TempTable <int?> >().ToList();

            ValidateColumn(columns[0], nameof(TempTable <int?> .Column1), "int", true);
        }
        public async Task Should_create_temp_table_with_string_with_max_length()
        {
            ConfigureModel = builder => builder.ConfigureTempTable <string>().Property(t => t.Column1).HasMaxLength(50);

            await _sut.CreateTempTableAsync(ActDbContext, ActDbContext.GetEntityType <TempTable <string> >(), new TempTableCreationOptions()).ConfigureAwait(false);

            var columns = AssertDbContext.GetTempTableColumns <TempTable <string> >().ToList();

            ValidateColumn(columns[0], nameof(TempTable <string> .Column1), "nvarchar", true, charMaxLength: 50);
        }
        public async Task Should_create_make_nullable_int_to_non_nullable_if_set_via_modelbuilder()
        {
            ConfigureModel = builder => builder.ConfigureTempTable <int?>().Property(t => t.Column1).IsRequired();

            await _sut.CreateTempTableAsync(ActDbContext, ActDbContext.GetEntityType <TempTable <int?> >(), new TempTableCreationOptions()).ConfigureAwait(false);

            var columns = AssertDbContext.GetTempTableColumns <TempTable <int?> >().ToList();

            ValidateColumn(columns[0], nameof(TempTable <int?> .Column1), "int", false);
        }
Esempio n. 11
0
        public async Task Should_create_temp_table_with_decimal()
        {
            ConfigureModel = builder => builder.ConfigureTempTable <decimal>();

            await using var tempTable = await SUT.CreateTempTableAsync(ActDbContext.GetEntityType <TempTable <decimal> >(), _optionsWithNonUniqueName);

            var columns = AssertDbContext.GetTempTableColumns <TempTable <decimal> >().ToList();

            ValidateColumn(columns[0], nameof(TempTable <decimal> .Column1), "TEXT", false); // decimal is stored as TEXT (see SqliteTypeMappingSource)
        }
Esempio n. 12
0
        public async Task Should_create_make_nullable_int_to_non_nullable_if_set_via_modelbuilder()
        {
            ConfigureModel = builder => builder.ConfigureTempTable <int?>().Property(t => t.Column1).IsRequired();

            await using var tempTable = await SUT.CreateTempTableAsync(ActDbContext.GetEntityType <TempTable <int?> >(), _optionsWithNonUniqueName);

            var columns = AssertDbContext.GetTempTableColumns <TempTable <int?> >().ToList();

            ValidateColumn(columns[0], nameof(TempTable <int?> .Column1), "int", false);
        }
Esempio n. 13
0
        public async Task Should_return_reference_to_remove_temp_table()
        {
            ConfigureModel = builder => builder.ConfigureTempTableEntity <CustomTempTable>();

            // ReSharper disable once RedundantArgumentDefaultValue
            var tempTableReference = await SUT.CreateTempTableAsync(ActDbContext.GetEntityType <CustomTempTable>(), _optionsWithNonUniqueName);

            await tempTableReference.DisposeAsync();

            var columns = AssertDbContext.GetTempTableColumns <CustomTempTable>().ToList();

            columns.Should().BeEmpty();
        }
Esempio n. 14
0
        public async Task Should_create_temp_table_with_2_columns()
        {
            ConfigureModel = builder => builder.ConfigureTempTable <int, string>();

            await using var tempTable = await SUT.CreateTempTableAsync(ActDbContext.GetEntityType <TempTable <int, string> >(), _optionsWithNonUniqueName);

            var columns = AssertDbContext.GetTempTableColumns <TempTable <int, string> >().ToList();

            columns.Should().HaveCount(2);

            ValidateColumn(columns[0], nameof(TempTable <int, string> .Column1), "int", false);
            ValidateColumn(columns[1], nameof(TempTable <int, string> .Column2), "nvarchar", false);
        }
        public async Task Should_create_temp_table_with_2_columns()
        {
            ConfigureModel = builder => builder.ConfigureTempTable <int, string>();

            await _sut.CreateTempTableAsync(ActDbContext, ActDbContext.GetEntityType <TempTable <int, string> >(), new TempTableCreationOptions()).ConfigureAwait(false);

            var columns = AssertDbContext.GetTempTableColumns <TempTable <int, string> >().ToList();

            columns.Should().HaveCount(2);

            ValidateColumn(columns[0], nameof(TempTable <int, string> .Column1), "int", false);
            ValidateColumn(columns[1], nameof(TempTable <int, string> .Column2), "nvarchar", true);
        }
Esempio n. 16
0
        public async Task Should_delete_temp_table_on_disposeAsync_if_DropTableOnDispose_is_true()
        {
            ConfigureModel = builder => builder.ConfigureTempTableEntity <CustomTempTable>();

            _optionsWithNonUniqueName.DropTableOnDispose = true;

            await using (await SUT.CreateTempTableAsync(ActDbContext.GetEntityType <CustomTempTable>(), _optionsWithNonUniqueName).ConfigureAwait(false))
            {
            }

            AssertDbContext.GetTempTableColumns <CustomTempTable>().ToList()
            .Should().HaveCount(0);
        }
Esempio n. 17
0
        public async Task Should_create_temp_table_with_default_database_collation()
        {
            ConfigureModel = builder => builder.ConfigureTempTableEntity <CustomTempTable>();
            _optionsWithNonUniqueName.UseDefaultDatabaseCollation = true;

            await SUT.CreateTempTableAsync(ActDbContext.GetEntityType <CustomTempTable>(), _optionsWithNonUniqueName).ConfigureAwait(false);

            var columns = AssertDbContext.GetTempTableColumns <CustomTempTable>().ToList();

            columns.Should().HaveCount(2);

            ValidateColumn(columns[0], nameof(CustomTempTable.Column1), "int", false);
            ValidateColumn(columns[1], nameof(CustomTempTable.Column2), "nvarchar", true);
        }
Esempio n. 18
0
        public async Task Should_create_temp_table_for_keyless_entity()
        {
            ConfigureModel = builder => builder.ConfigureTempTableEntity <CustomTempTable>();

            // ReSharper disable once RedundantArgumentDefaultValue
            await using var tempTable = await SUT.CreateTempTableAsync(ActDbContext.GetEntityType <CustomTempTable>(), _optionsWithNonUniqueName);

            var columns = AssertDbContext.GetTempTableColumns <CustomTempTable>().ToList();

            columns.Should().HaveCount(2);

            ValidateColumn(columns[0], nameof(CustomTempTable.Column1), "int", false);
            ValidateColumn(columns[1], nameof(CustomTempTable.Column2), "nvarchar", true);
        }
Esempio n. 19
0
        public async Task Should_create_temp_table_with_provided_column_only()
        {
            ConfigureModel = builder => builder.ConfigureTempTableEntity <CustomTempTable>();

            _optionsWithNonUniqueName.MembersToInclude = EntityMembersProvider.From <CustomTempTable>(t => t.Column1);

            // ReSharper disable once RedundantArgumentDefaultValue
            await using var tempTable = await SUT.CreateTempTableAsync(ActDbContext.GetEntityType <CustomTempTable>(), _optionsWithNonUniqueName);

            var columns = AssertDbContext.GetTempTableColumns <CustomTempTable>().ToList();

            columns.Should().HaveCount(1);

            ValidateColumn(columns[0], nameof(CustomTempTable.Column1), "int", false);
        }
Esempio n. 20
0
        public async Task Should_create_temp_table_for_entityType()
        {
            // ReSharper disable once RedundantArgumentDefaultValue
            await using var tempTable = await SUT.CreateTempTableAsync(ActDbContext.GetEntityType <TestEntity>(), _optionsWithNonUniqueName);

            var columns = AssertDbContext.GetTempTableColumns <TestEntity>().OrderBy(c => c.Name).ToList();

            columns.Should().HaveCount(6);

            ValidateColumn(columns[0], nameof(TestEntity.ConvertibleClass), "INTEGER", true);
            ValidateColumn(columns[1], nameof(TestEntity.Count), "INTEGER", false);
            ValidateColumn(columns[2], nameof(TestEntity.Id), "TEXT", false);
            ValidateColumn(columns[3], nameof(TestEntity.Name), "TEXT", true);
            ValidateColumn(columns[4], nameof(TestEntity.PropertyWithBackingField), "INTEGER", false);
            ValidateColumn(columns[5], "_privateField", "INTEGER", false);
        }
Esempio n. 21
0
        public async Task Should_not_delete_temp_table_on_disposeAsync_if_DropTableOnDispose_is_false()
        {
            ConfigureModel = builder => builder.ConfigureTempTableEntity <CustomTempTable>();

            _optionsWithNonUniqueName.DropTableOnDispose = false;

            await using (await SUT.CreateTempTableAsync(ActDbContext.GetEntityType <CustomTempTable>(), _optionsWithNonUniqueName).ConfigureAwait(false))
            {
            }

            var columns = AssertDbContext.GetTempTableColumns <CustomTempTable>().ToList();

            columns.Should().HaveCount(2);

            ValidateColumn(columns[0], nameof(CustomTempTable.Column1), "int", false);
            ValidateColumn(columns[1], nameof(CustomTempTable.Column2), "nvarchar", true);
        }
Esempio n. 22
0
        public async Task Should_create_temp_table_with_reusable_name()
        {
            ConfigureModel = builder => builder.ConfigureTempTableEntity <CustomTempTable>();

            var options = new TempTableCreationOptions {
                TableNameProvider = ReusingTempTableNameProvider.Instance, PrimaryKeyCreation = PrimaryKeyPropertiesProviders.None
            };

            // ReSharper disable once RedundantArgumentDefaultValue
            await using var tempTable = await SUT.CreateTempTableAsync(ActDbContext.GetEntityType <CustomTempTable>(), options).ConfigureAwait(false);

            var columns = AssertDbContext.GetTempTableColumns("#CustomTempTable_1").ToList();

            columns.Should().HaveCount(2);

            ValidateColumn(columns[0], nameof(CustomTempTable.Column1), "int", false);
            ValidateColumn(columns[1], nameof(CustomTempTable.Column2), "nvarchar", true);
        }
Esempio n. 23
0
        public async Task Should_not_reuse_name_before_it_is_freed()
        {
            ConfigureModel = builder => builder.ConfigureTempTableEntity <CustomTempTable>();

            var options = new TempTableCreationOptions {
                TableNameProvider = ReusingTempTableNameProvider.Instance
            };

            // ReSharper disable once RedundantArgumentDefaultValue
            await using (await SUT.CreateTempTableAsync(ActDbContext.GetEntityType <CustomTempTable>(), options).ConfigureAwait(false))
            {
                await SUT.CreateTempTableAsync(ActDbContext.GetEntityType <CustomTempTable>(), options).ConfigureAwait(false);
            }

            var columns = AssertDbContext.GetTempTableColumns("#CustomTempTable_2").ToList();

            columns.Should().HaveCount(2);

            ValidateColumn(columns[0], nameof(CustomTempTable.Column1), "INTEGER", false);
            ValidateColumn(columns[1], nameof(CustomTempTable.Column2), "TEXT", true);
        }