Beispiel #1
0
        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",
     };
 }
Beispiel #3
0
        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;
 }
Beispiel #6
0
 public CreateNewTodoCommandHandler(ReferenceDbContext context)
 {
     _context = context;
 }
Beispiel #7
0
 public TodoToggleIsCompleteCommandHandler(ReferenceDbContext context)
 {
     _context = context;
 }
Beispiel #8
0
 public QueryTestFixture()
 {
     Context = ReferenceDbContextFactory.Create();
 }
 public GetTodosListQueryHandler(ReferenceDbContext context)
 {
     _context = context;
 }