public static ReferenceDbContext Create() { var options = new DbContextOptionsBuilder <ReferenceDbContext>() .UseInMemoryDatabase(Guid.NewGuid().ToString()) .Options; var context = new ReferenceDbContext(options); context.Database.EnsureCreated(); context.Todos.AddRange(new[] { new Todo { Id = Guid.NewGuid(), Title = $"Title - {Guid.NewGuid().ToString()}" }, new Todo { Id = Guid.NewGuid(), Title = $"Title - {Guid.NewGuid().ToString()}" }, new Todo { Id = Guid.NewGuid(), Title = $"Title - {Guid.NewGuid().ToString()}" } }); context.SaveChanges(); return(context); }
public CreateNewTodoCommandHandlerTests() { _context = GetDbContext(false); _commandHandler = new CreateNewTodoCommandHandler(_context); _command = new CreateNewTodoCommand() { Id = Guid.NewGuid(), Title = "Test One", }; }
public static void Destroy(ReferenceDbContext context) { if (!context.Database.IsInMemory()) { return; } context.Database.EnsureDeleted(); context.Dispose(); }
public ReferenceDbContext GetDbContext(bool useSqlLite = false) { var builder = new DbContextOptionsBuilder <ReferenceDbContext>(); if (useSqlLite) { builder.UseSqlite("DataSource=:memory:", x => { }); } else { builder.UseInMemoryDatabase(Guid.NewGuid().ToString()); } var dbContext = new ReferenceDbContext(builder.Options); if (useSqlLite) { dbContext.Database.OpenConnection(); } dbContext.Database.EnsureCreated(); return(dbContext); }
public GetTodosListQueryHandlerTests(QueryTestFixture fixture) { _context = fixture.Context; }
public CreateNewTodoCommandHandler(ReferenceDbContext context) { _context = context; }
public TodoToggleIsCompleteCommandHandler(ReferenceDbContext context) { _context = context; }
public QueryTestFixture() { Context = ReferenceDbContextFactory.Create(); }
public GetTodosListQueryHandler(ReferenceDbContext context) { _context = context; }