public static IServiceCollection RegisterRepositories <TDbContext>( this IServiceCollection services, Action <IRepositoryOptions> repositoryOptions = null) where TDbContext : DbContext { var genericTypeDbSet = typeof(DbSet <>); var dbContextType = typeof(TDbContext); var properties = dbContextType.GetProperties(); var dbSetProperties = properties.Where(property => property.PropertyType.IsGenericType); var entities = dbSetProperties.Select(property => property.PropertyType.GetGenericArguments().FirstOrDefault()); return(RegisterRepositories <TDbContext>( services, RepositoryOptionsBuilder.Build(repositoryOptions ?? RepositoryOptionsBuilder.Default), entities.ToArray())); }
public void SetUp() { dbContextOptions = DbContextOptionsTestBuilder .Build(services => services); testDbContext = new TestDbContext(dbContextOptions); sut = new EntityFrameworkRepository <TestDbContext, User>(testDbContext, RepositoryOptionsBuilder.Build(RepositoryOptionsBuilder.Default)); }