I am creating SQLite In Memory database for unit testing:
var connection = new SqliteConnection("DataSource=:memory:");
connection.Open();
try
{
var options = new DbContextOptionsBuilder<BloggingContext>()
.UseSqlite(connection)
.Options;
// Create the schema in the database
using (var context = new BloggingContext(options))
{
context.Database.EnsureCreated();
}
// Run the test against one instance of the context
using (var context = new BloggingContext(options))
{
var service = new BlogService(context);
service.Add("http://sample.com");
}
// Use a separate instance of the context to verify correct data was saved to database
using (var context = new BloggingContext(options))
{
Assert.AreEqual(1, context.Blogs.Count());
Assert.AreEqual("http://sample.com", context.Blogs.Single().Url);
}
}
context.Database.EnsureCreated(); fails with with exception: Message: Microsoft.Data.Sqlite.SqliteException : SQLite Error 1: 'near "MAX": syntax error'.
There is github issue saying: The issue here is varchar(max) is SqlServer specific type. The scaffolding should not add it as relational type which gets passed to migration in other providers which is prone to generate invalid sql at migration.
But how then can I use SQLite in Memory for unit tests if my database contains many varchar(max) columns?
_offerContext.Set<Aggregate>().FindAsync(id);
I am getting exception: typeof(Microsoft.Data.Sqlite.SqliteException): SQLite Error 1: 'no such table: Offers'. ---- Microsoft.Data.Sqlite.SqliteException : SQLite Error 1: 'no such table: Offers'. instead of null. If am passing id with existing entity it return correct object. But I want to test behaviour when I don't find an entity.