Beispiel #1
0
        public CQRSDbContext GetDbContext(bool useSqlLite = false)
        {
            var builder = new DbContextOptionsBuilder <CQRSDbContext>();

            if (useSqlLite)
            {
                builder.UseSqlite("DataSource=:memory:", x => { });
            }
            else
            {
                builder.UseInMemoryDatabase(Guid.NewGuid().ToString());
            }

            var dbContext = new CQRSDbContext(builder.Options);

            if (useSqlLite)
            {
                // SQLite needs to open connection to the DB.
                // Not required for in-memory-database.
                dbContext.Database.OpenConnection();
            }

            dbContext.Database.EnsureCreated();

            return(dbContext);
        }
Beispiel #2
0
        public static CQRSDbContext Create()
        {
            var options = new DbContextOptionsBuilder <CQRSDbContext>()
                          .UseInMemoryDatabase(Guid.NewGuid().ToString())
                          .Options;

            var context = new CQRSDbContext(options);

            context.Database.EnsureCreated();

            context.Customers.AddRange(new[] {
                new Customer {
                    CustomerId = "ADAM", ContactName = "Adam Cogan"
                },
                new Customer {
                    CustomerId = "JASON", ContactName = "Jason Taylor"
                },
                new Customer {
                    CustomerId = "BREND", ContactName = "Brendan Richards"
                },
            });

            context.SaveChanges();

            return(context);
        }
Beispiel #3
0
 public PersonRepository(CQRSDbContext context)
 {
     _context = context;
 }
Beispiel #4
0
 public CommandTestBase()
 {
     _context = CQRSContextFactory.Create();
 }
 public GetCustomersListQueryHandlerTests(QueryTestFixture fixture)
 {
     _context = fixture.Context;
     _mapper  = fixture.Mapper;
 }
Beispiel #6
0
        public static void Destroy(CQRSDbContext context)
        {
            context.Database.EnsureDeleted();

            context.Dispose();
        }
 public GetCustomerDetailQueryHandlerTests(QueryTestFixture fixture)
 {
     _context = fixture.Context;
 }