示例#1
0
        public async Task Should_insert_0_to_auto_increment_column(SqliteAutoIncrementBehavior behavior, int id, int expectedId)
        {
            var testEntity = new TestEntityWithAutoIncrement {
                Id = id
            };
            var testEntities = new[] { testEntity };

            var options = new SqliteBulkInsertOptions {
                AutoIncrementBehavior = behavior
            };
            await SUT.BulkInsertAsync(testEntities, options);

            var loadedEntity = await AssertDbContext.TestEntitiesWithAutoIncrement.FirstOrDefaultAsync();

            loadedEntity.Id.Should().Be(expectedId);
            loadedEntity.Name.Should().BeNull();
        }
示例#2
0
        public async Task Should_write_all_provided_column_values_as_is_despite_dotnet_default_value()
        {
            var testEntity = new TestEntityWithDotnetDefaultValues
            {
                Id             = Guid.Empty,
                Int            = 0,
                String         = null !,
                NullableInt    = null,
                NullableString = null
            };
            var testEntities = new[] { testEntity };

            var options = new SqliteBulkInsertOptions
            {
                // we skip TestEntityWithDefaultValues.String
                MembersToInsert = EntityMembersProvider.From <TestEntityWithDotnetDefaultValues>(e => new
                {
                    e.Id,
                    e.Int,
                    e.NullableInt,
                    e.NullableString
                })
            };

            await SUT.BulkInsertAsync(testEntities, options);

            var loadedEntity = await AssertDbContext.TestEntitiesWithDotnetDefaultValues.FirstOrDefaultAsync();

            loadedEntity.Should().BeEquivalentTo(new TestEntityWithSqlDefaultValues
            {
                Id             = Guid.Empty,                           // persisted as-is
                Int            = 0,                                    // persisted as-is
                NullableInt    = null,                                 // persisted as-is
                String         = "3",                                  // DEFAULT value constraint
                NullableString = null                                  // persisted as-is
            });
        }