Пример #1
0
        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"
                });
            });
        }
Пример #2
0
        private void SeedDb()
        {
            using var context = new HestiaContext(Options);
            context.Database.EnsureDeleted();
            context.Database.EnsureCreated();
            context.Snapshots.Add(SeededRepo);

            context.SaveChanges();
        }
Пример #3
0
        private static void EnsureDBCreated(HestiaContext context, string dbFolder)
        {
            if (!Directory.Exists(dbFolder))
            {
                Directory.CreateDirectory(dbFolder);
            }

            context.Database.EnsureCreated();
        }
Пример #4
0
        public void GetLinesForFileRetrievesTheExpectedLines()
        {
            using var context = new HestiaContext(Options);
            var client = new SnapshotEFClient(context);

            var lines = client.GetLinesForFile(SeededFileId);

            lines.Should()
            .HaveCount(1);
        }
Пример #5
0
        public void GetFileDetailsShouldReturnNoneIfFileWasNotFound()
        {
            using var context = new HestiaContext(Options);
            var client = new SnapshotEFClient(context);

            client.GetFileDetails("invalid")
            .IsNone
            .Should()
            .BeTrue();
        }
Пример #6
0
        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);
        }
Пример #7
0
        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);
        }
Пример #8
0
        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);
        }
Пример #9
0
        public void GetAllSnapshotsShouldReturnTheSeededSnapshots()
        {
            using var context = new HestiaContext(Options);
            var client = new SnapshotEFClient(context);

            client.GetAllSnapshotsHeaders()
            .First()
            .Id
            .Should()
            .Be(SeededSnapshotId);
        }
Пример #10
0
        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);
        }
Пример #11
0
        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);
        }
Пример #12
0
        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);
        }