public void ConfigureServices(IServiceCollection services) { services.AddTransient(provider => { var optionsBuilder = new DbContextOptionsBuilder(); var dbPath = Path.Join(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), "dev"); var dbConn = Configuration["Connection:SqliteConn"]; optionsBuilder.UseSqlite($"Data Source={Path.Join(dbPath, dbConn)}"); var context = new HestiaContext(optionsBuilder.Options); if (!Directory.Exists(dbPath)) { Directory.CreateDirectory(dbPath); } context.Database.EnsureCreated(); return(new HestiaContext(optionsBuilder.Options)); }); services.AddTransient <ISnapshotRetrieval, SnapshotEFClient>(); services.AddTransient <IFileRetrieval, SnapshotEFClient>(); services.AddSingleton <ILogger>(_ => Log.Logger); services.AddCors(); services.AddControllers(); services.AddSwaggerGen(c => { c.SwaggerDoc("v1", new OpenApiInfo { Title = "Hestia API", Version = "v1" }); }); }
private void SeedDb() { using var context = new HestiaContext(Options); context.Database.EnsureDeleted(); context.Database.EnsureCreated(); context.Snapshots.Add(SeededRepo); context.SaveChanges(); }
private static void EnsureDBCreated(HestiaContext context, string dbFolder) { if (!Directory.Exists(dbFolder)) { Directory.CreateDirectory(dbFolder); } context.Database.EnsureCreated(); }
public void GetLinesForFileRetrievesTheExpectedLines() { using var context = new HestiaContext(Options); var client = new SnapshotEFClient(context); var lines = client.GetLinesForFile(SeededFileId); lines.Should() .HaveCount(1); }
public void GetFileDetailsShouldReturnNoneIfFileWasNotFound() { using var context = new HestiaContext(Options); var client = new SnapshotEFClient(context); client.GetFileDetails("invalid") .IsNone .Should() .BeTrue(); }
public void GetFileDetailsShouldReturnSeededFileDetails() { using var context = new HestiaContext(Options); var client = new SnapshotEFClient(context); client.GetFileDetails(SeededFileId) .Match(x => x, () => null) ?.Id.Should() .Be(SeededFileId); }
public void GetSnapshotByIdShouldReturnSeededSnapshot() { using var context = new HestiaContext(Options); var client = new SnapshotEFClient(context); client.GetSnapshotById(SeededSnapshotId) .Match(x => x, () => null) ?.Id.Should() .Be(SeededSnapshotId); }
public void GetAllFilesForSnapshotRetrievesAllFilesForSnapshotId() { using var context = new HestiaContext(Options); var client = new SnapshotEFClient(context); var files = client.GetAllFilesForSnapshot(SeededSnapshotId); files.First() .Id.Should() .Be(SeededFileId); }
public void GetAllSnapshotsShouldReturnTheSeededSnapshots() { using var context = new HestiaContext(Options); var client = new SnapshotEFClient(context); client.GetAllSnapshotsHeaders() .First() .Id .Should() .Be(SeededSnapshotId); }
private static HestiaContext CreateContext(string dbName, string dbPath) { var finalPath = BuildDBPath(dbName, dbPath); Log.Logger.Information($"Using sqlite db at {finalPath}"); var contextBuilder = new DbContextOptionsBuilder(); contextBuilder.UseSqlite($@"Data Source={finalPath}"); var dbContext = new HestiaContext(contextBuilder.Options); EnsureDBCreated(dbContext, Path.GetDirectoryName(finalPath) !); return(dbContext); }
public void InsertSnapshotSyncShouldPersistAsExpected() { using var context = new HestiaContext(Options); var client = new SnapshotEFClient(context); client.InsertSnapshotSync(NewSnapshot); context.Snapshots.Count() .Should() .Be(2); context.Snapshots.ToList()[1] .Name .Should() .Be("somename"); context.SourceLines .Should() .HaveCount(1); }
public void InsertSnapshotShouldPersistAsExpected() { using var context = new HestiaContext(Options); var scheduler = new TestScheduler(); var client = new SnapshotEFClient(context); scheduler.Start(() => client.InsertSnapshot(NewSnapshot)); context.Snapshots.Count() .Should() .Be(2); context.Snapshots.ToList()[1] .Name .Should() .Be("somename"); context.SourceLines .Should() .HaveCount(1); }