public async Task CreateTableAndDropTable(OrmConnectionFactory factory) { using (var c = await factory.OpenConnectionAsync()) { await c.CreateTableAsync <NoPk>(false); Assert.True(await c.TableExistsAsync <NoPk>()); await c.DropTableIfExistsAsync <NoPk>(); Assert.False(await c.TableExistsAsync <NoPk>()); await c.CreateTableAsync <NoPk>(false); Assert.True(await c.TableExistsAsync <NoPk>()); } }
public async Task CreateTableThatAlreadyExistThrowError(OrmConnectionFactory factory) { using (var c = await factory.OpenConnectionAsync()) { await c.CreateTableAsync <NoPk>(true); Assert.True(await c.TableExistsAsync <NoPk>()); c.Insert(new NoPk { StringCol = "1" }); c.Insert(new NoPk { StringCol = "2" }); c.Insert(new NoPk { StringCol = "3" }); await Assert.ThrowsAsync <OrmException>(async() => await c.CreateTableAsync <NoPk>(false)); //Ensure table has not been dropped Assert.True(await c.TableExistsAsync <NoPk>()); Assert.Equal(3, await c.CountAsync <NoPk>()); } }
public async Task CreateTableWithColumnsAndAttributes(OrmConnectionFactory factory) { using (var c = await factory.OpenConnectionAsync()) { Assert.False(await c.TableExistsAsync <WithAttributes>()); await c.CreateTableAsync <WithAttributes>(false); Assert.True(await c.TableExistsAsync <WithAttributes>()); await c.InsertAsync(new WithAttributes { DecimalCol = 1234.56m, NotNullString = "this is not null", UniqueIndexedString = "val1", TenCharsStringCol = "max10chars", DecimalColLimited = 90.12m, IgnoredCol = "this should be ignored", ComputedField = 0 }); var r1 = await c.FirstOrDefaultAsync <WithAttributes>(x => x.Id == 1); Assert.NotNull(r1); Assert.Equal(1, r1.Id); Assert.Null(r1.IgnoredCol); Assert.Equal("N/A", r1.DefaultValueCol); Assert.Equal(5, r1.ComputedField); Assert.Null(r1.NullableDecimalCol); c.Insert(new WithAttributes { DefaultValueCol = "Not default this time", UniqueIndexedString = "val2", NotNullString = "this is not null either", NullableDecimalCol = 123 }); var r2 = await c.FirstOrDefaultAsync <WithAttributes>(x => x.Id == 2); Assert.NotNull(r2); Assert.Equal(2, r2.Id); Assert.Equal("Not default this time", r2.DefaultValueCol); Assert.Equal(123, r2.NullableDecimalCol); // NotNullString cannot be null await Assert.ThrowsAsync <OrmException>(() => c.InsertAsync(new WithAttributes())); // UniqueIndexString duplicate await Assert.ThrowsAsync <OrmException>(() => c.InsertAsync(new WithAttributes { NotNullString = "1234", UniqueIndexedString = "val1" })); // No truncation tests with SQLite if (!c.DialectProvider.GetType().Name.ToLower().Contains("sqlite")) { // Data truncated await Assert.ThrowsAsync <OrmException>(() => c.InsertAsync(new WithAttributes { NotNullString = "1234", TenCharsStringCol = "1234567890A" })); } } }