public SignupCommandHandler(CleanArchitectureDbContext context, UserManager <ApplicationUser> userManager, SignInManager <ApplicationUser> signInManager, RoleManager <IdentityRole> roleManager) { _context = context; _userManager = userManager; _signInManager = signInManager; _roleManager = roleManager; }
internal static void InitializeDbForTests(CleanArchitectureDbContext db) { PredefinedData.InitializePolls(); db.Polls.AddRange(PredefinedData.Polls); db.SaveChanges(); }
public LoginQueryHandler(CleanArchitectureDbContext context, UserManager <ApplicationUser> userManager, SignInManager <ApplicationUser> signInManager, RoleManager <IdentityRole> roleManager, IConfiguration configuration) { _context = context; _userManager = userManager; _signInManager = signInManager; _roleManager = roleManager; _configuration = configuration; }
protected override void ConfigureWebHost(IWebHostBuilder builder) { builder.ConfigureServices(services => { // Remove the app's ApplicationDbContext registration. ServiceDescriptor descriptor = services.SingleOrDefault( d => d.ServiceType == typeof(DbContextOptions <CleanArchitectureDbContext>)); if (descriptor != null) { services.Remove(descriptor); } // Add ApplicationDbContext using an in-memory database for testing. services.AddDbContext <CleanArchitectureDbContext>(options => options.UseInMemoryDatabase("InMemoryDbForTesting")); // Build the service provider. ServiceProvider serviceProvider = services.BuildServiceProvider(); // Create a scope to obtain a reference to the database context (CleanArchitectureDbContext). using IServiceScope scope = serviceProvider.CreateScope(); IServiceProvider scopedServices = scope.ServiceProvider; CleanArchitectureDbContext db = scopedServices.GetRequiredService <CleanArchitectureDbContext>(); ILogger <CustomWebApplicationFactory <TStartup> > logger = scopedServices .GetRequiredService <ILogger <CustomWebApplicationFactory <TStartup> > >(); db.Database.EnsureCreated(); try { // Seed the database with test data. DatabaseInitializer.InitializeDbForTests(db); } catch (Exception ex) { logger.LogError(ex, "An error occurred seeding the " + "database with test messages. Error: {Message}", ex.Message); } }); }
public void Add_Poll_To_Database() { // In-memory database only exists while the connection is open var connection = new SqliteConnection("DataSource=:memory:"); connection.Open(); try { DbContextOptions <CleanArchitectureDbContext> options = new DbContextOptionsBuilder <CleanArchitectureDbContext>() .UseSqlite(connection) .Options; // Create the schema in the database using (var context = new CleanArchitectureDbContext(options)) { context.Database.EnsureCreated(); } string title = "test title"; Poll poll = this.GetDefaultPoll(title); // Run the test against one instance of the context using (var context = new CleanArchitectureDbContext(options)) { var pollGateway = new PollGateway(context); pollGateway.CreateAsync(poll); context.SaveChanges(); } // Use a separate instance of the context to verify correct data was saved to database using (var context = new CleanArchitectureDbContext(options)) { context.Polls.Count().Should().Be(1); context.Polls.Single().Title.Should().Be("test title"); } } finally { connection.Close(); } }
public UserRepository(CleanArchitectureDbContext dbContext) { _dbContext = dbContext; }
public PollGateway(CleanArchitectureDbContext dbContext) => this.dbContext = dbContext;
public AccountController(UserManager <ApplicationUser> userManager, CleanArchitectureDbContext dbContext) { _userManager = userManager; _dbContext = dbContext; }
public UserRepository(CleanArchitectureDbContext dbContext) : base(dbContext, dbContext.User) { }
public ExceptionMiddleware(RequestDelegate next, CleanArchitectureDbContext context) { _next = next; _context = context; }
internal static void ReinitializeDbForTests(CleanArchitectureDbContext db) { db.Polls.RemoveRange(db.Polls); InitializeDbForTests(db); }
public ValidateTokenQueryHandler(CleanArchitectureDbContext context) { _context = context; }