Exemplo n.º 1
0
        public async Task Should_create_temp_table_without_primary_key()
        {
            ConfigureModel = builder => builder.ConfigureTempTable <int>();

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

            var constraints = await AssertDbContext.GetTempTableConstraints <TempTable <int> >().ToListAsync();

            constraints.Should().HaveCount(0);
        }
        public async Task Should_create_temp_table_without_primary_key()
        {
            ConfigureModel = builder => builder.ConfigureTempTable <int>();

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

            var constraints = await AssertDbContext.GetTempTableConstraints <TempTable <int> >().ToListAsync().ConfigureAwait(false);

            constraints.Should().HaveCount(0);
        }
        public async Task Should_create_primary_key_for_entityType()
        {
            var tableName = await ArrangeDbContext.CreateTempTableAsync <TestEntity>();

            await _sut.CreatePrimaryKeyAsync(ActDbContext, ActDbContext.GetEntityType <TestEntity>(), tableName);

            var constraints = await AssertDbContext.GetTempTableConstraints <TestEntity>().ToListAsync();

            constraints.Should().HaveCount(1)
            .And.Subject.First().CONSTRAINT_TYPE.Should().Be("PRIMARY KEY");

            var keyColumns = await AssertDbContext.GetTempTableKeyColumns <TestEntity>().ToListAsync();

            keyColumns.Should().HaveCount(1)
            .And.Subject.First().COLUMN_NAME.Should().Be(nameof(TestEntity.Id));
        }
Exemplo n.º 4
0
        public async Task Should_create_pk_if_options_flag_is_set()
        {
            _optionsWithNonUniqueName.PrimaryKeyCreation = PrimaryKeyPropertiesProviders.AdaptiveForced;

            ConfigureModel = builder => builder.ConfigureTempTable <int, string>().Property(s => s.Column2).HasMaxLength(100);

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

            var constraints = await AssertDbContext.GetTempTableConstraints <TempTable <int, string> >().ToListAsync();

            constraints.Should().HaveCount(1)
            .And.Subject.First().CONSTRAINT_TYPE.Should().Be("PRIMARY KEY");

            var keyColumns = await AssertDbContext.GetTempTableKeyColumns <TempTable <int, string> >().ToListAsync();

            keyColumns.Should().HaveCount(2);
            keyColumns[0].COLUMN_NAME.Should().Be(nameof(TempTable <int, string> .Column1));
            keyColumns[1].COLUMN_NAME.Should().Be(nameof(TempTable <int, string> .Column2));
        }
Exemplo n.º 5
0
        public async Task Should_create_primary_key_for_entityType()
        {
            await using var tempTableReference = await ArrangeDbContext.CreateTempTableAsync <TestEntity>(new TempTableCreationOptions
            {
                TableNameProvider  = DefaultTempTableNameProvider.Instance,
                PrimaryKeyCreation = PrimaryKeyPropertiesProviders.None
            });

            var entityType = ActDbContext.GetEntityType <TestEntity>();
            await SUT.CreatePrimaryKeyAsync(ActDbContext, PrimaryKeyPropertiesProviders.AdaptiveForced.GetPrimaryKeyProperties(entityType, entityType.GetProperties().ToList()), tempTableReference.Name);

            var constraints = await AssertDbContext.GetTempTableConstraints <TestEntity>().ToListAsync();

            constraints.Should().HaveCount(1)
            .And.Subject.First().CONSTRAINT_TYPE.Should().Be("PRIMARY KEY");

            var keyColumns = await AssertDbContext.GetTempTableKeyColumns <TestEntity>().ToListAsync();

            keyColumns.Should().HaveCount(1)
            .And.Subject.First().COLUMN_NAME.Should().Be(nameof(TestEntity.Id));
        }