public async Task TestDbSave() { var conn = new SqliteConnection("DataSource=:memory:"); conn.Open(); try { var options = new DbContextOptionsBuilder <CountDataContext>() .UseSqlite(conn) .Options; // Create the schema in the database using (var context = new CountDataContext(options)) { context.Database.EnsureCreated(); } // Run the test against one instance of the context using (var context = new CountDataContext(options)) { var service = new SqliteDataTransfer(context, NullLoggerFactory.Instance); await service.SaveDataAsync(new PulseDTO { Count = 123456 }); } // Use a separate instance of the context to verify correct data was saved to database using (var context = new CountDataContext(options)) { var pulseCount = await context.PulseCounts.SingleAsync(); Assert.That(pulseCount.Count, Is.EqualTo(123456)); } } finally { conn.Close(); } }
public SqliteDataTransfer(CountDataContext dbContext, ILoggerFactory loggerFactory) { Logger = loggerFactory.CreateLogger <SqliteDataTransfer>(); Db = dbContext; }