Ejemplo n.º 1
0
        private static EfCoreRillStore CreateRillStore(IConfiguration configuration)
        {
            var pass = configuration["SqlServer:Pass"];

            if (string.IsNullOrWhiteSpace(pass))
            {
                throw new System.Exception("Password is missing.");
            }

            var dbContextOptions = new DbContextOptionsBuilder <RillDbContext>()
                                   .UseSqlServer($@"Server=.,1401;Database=RillTests;User=sa;Password={pass};MultipleActiveResultSets=True;TrustServerCertificate=true")
                                   .Options;

            using var dbContext = new RillDbContext(dbContextOptions);

            if (!dbContext.Database.EnsureCreated())
            {
                dbContext.Database.ExecuteSqlRaw("TRUNCATE TABLE dbo.RillEvent;");
                dbContext.Database.ExecuteSqlRaw("DELETE FROM dbo.RillCommit;");
                dbContext.Database.ExecuteSqlRaw("DELETE FROM dbo.Rill;");
            }
            dbContext.Database.CloseConnection();

            return(new EfCoreRillStore(dbContextOptions));
        }
Ejemplo n.º 2
0
        private static async ValueTask <IRillStore> CreateEfRillStoreAsync(IConfiguration configuration)
        {
            var dbContextOptions = new DbContextOptionsBuilder <RillDbContext>()
                                   .UseSqlServer($@"Server=.,1401;Database=Rill;User=sa;Password={configuration["SqlServer:Pass"]};MultipleActiveResultSets=True;TrustServerCertificate=true")
                                   .Options;

            await using var dbContext = new RillDbContext(dbContextOptions);
            await dbContext.Database.EnsureCreatedAsync();

            await dbContext.Database.CloseConnectionAsync();

            return(new EfCoreRillStore(dbContextOptions));
        }