Beispiel #1
0
        public AnnouncementPreferenceServiceTestBase()
        {
            _connection = new SqliteConnection("Filename=:memory:");
            _connection.Open();
            _connection.CreateFunction("newid", NewId);


            _options = new DbContextOptionsBuilder <PocDbContext>()
                       .EnableSensitiveDataLogging()
                       .UseSqlite(_connection)
                       .AddInterceptors(new SqliteCommandInterceptor())
                       .UseQueryTrackingBehavior(QueryTrackingBehavior.NoTracking)
                       .Options;

            Context = new PocDbContext(_options);

            Context.Database.EnsureDeleted();
            Context.Database.Migrate();
            Context.Database.EnsureCreated();

            var services = new ServiceCollection()
                           .AddLogging()
                           .BuildServiceProvider();

            Service = new AnnouncementPreferenceService(Context, services.GetRequiredService <ILogger <EntityService <AnnouncementPreference> > >());
        }
Beispiel #2
0
 protected EntityService(
     PocDbContext context,
     ILogger <EntityService <T> > logger)
 {
     Context = context;
     Logger  = logger;
 }
        public SqliteProductServiceTestBase()
        {
            _connection = new SqliteConnection("Filename=:memory:");
            _connection.Open();

            //  TODO: Work out how to resolve this. Identity/autoincrement does not translate from MSSQL to SQLite...
            //  For Primary keys that are Guid's this will do the job!
            _connection.CreateFunction("newid", NewId);

            _options = new DbContextOptionsBuilder <PocDbContext>()
                       .EnableSensitiveDataLogging()
                       .UseSqlite(_connection)
                       .AddInterceptors(new SqliteCommandInterceptor()) //  Apply bespoke incompatibilities.
                       .UseQueryTrackingBehavior(QueryTrackingBehavior.NoTracking)
                       .Options;

            Context = new PocDbContext(_options);

            Context.Database.EnsureDeleted();
            Context.Database.Migrate();
            Context.Database.EnsureCreated();

            var services = new ServiceCollection()
                           .AddLogging()
                           .BuildServiceProvider();

            Service = new ProductService(Context, services.GetRequiredService <ILogger <EntityService <Product> > >());
        }
 protected void InitializeData(Product[] entities)
 {
     using var context = new PocDbContext(_options);
     foreach (var entity in entities)
     {
         context.Add(entity);
     }
     context.SaveChanges();
 }
Beispiel #5
0
 protected void InitializeData(AnnouncementPreference[] entities)
 {
     using (var context = new PocDbContext(_options))
     {
         foreach (var entity in entities)
         {
             context.Add(entity);
         }
         context.SaveChanges();
     }
 }
        /// <summary>
        /// Seeds the given database
        /// </summary>
        /// <param name="context">The database to be seeded</param>
        public static void Seed(this PocDbContext context)
        {
            context.Database.Migrate();

            if (!context.Set <Role>().Any())
            {
                context.AddRange(Role.List());
                context.AddRange(Status.List());
                context.AddRange(KeyKind.List());

                context.SaveChanges();
            }
        }
        public ProductServiceTestBase()
        {
            _options = new DbContextOptionsBuilder <PocDbContext>()
                       .EnableSensitiveDataLogging()
                       .UseInMemoryDatabase(databaseName: $"TESTING_{this.GetType().Name}_{DateTime.Now.Ticks}")
                       .UseQueryTrackingBehavior(QueryTrackingBehavior.NoTracking)
                       .Options;

            var services = new ServiceCollection()
                           .AddLogging()
                           .BuildServiceProvider();

            Context = new PocDbContext(_options);

            Service = new ProductService(new PocDbContext(_options), services.GetService <ILogger <EntityService <Product> > >());
        }
Beispiel #8
0
 public UserPreferenceService(
     PocDbContext context,
     ILogger <EntityService <UserPreference> > logger) : base(context, logger)
 {
 }
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="context"></param>
 public DbKeyStorageContainer(PocDbContext context)
 {
     _context = context;
 }
 public AnnouncementPreferenceService(
     PocDbContext context,
     ILogger <EntityService <AnnouncementPreference> > logger) : base(context, logger)
 {
 }
 public ProductService(
     PocDbContext context,
     ILogger <EntityService <Product> > logger) : base(context, logger)
 {
 }