private static async Task <AuthorizedTask> AddUserAndInitiateRequest( string uniqueData, DbDependentTestApplication app, Action <AddUserCommand> configration = null ) { var contentRepository = app.Services.GetContentRepository(); var addUserCommand = app.TestData.Users().CreateAddCommand(uniqueData); if (configration != null) { configration(addUserCommand); } await contentRepository .WithElevatedPermissions() .Users() .AddAsync(addUserCommand); await contentRepository .Users() .AccountRecovery() .InitiateAsync(new InitiateUserAccountRecoveryViaEmailCommand() { UserAreaCode = addUserCommand.UserAreaCode, Username = addUserCommand.Email }); var resetRequest = await GetResetRequest(app, addUserCommand.OutputUserId); return(resetRequest); }
private static async Task <AuthorizedTask> AddUserAndInitiate( string uniqueData, DbDependentTestApplication app, Action <AddUserCommand> configration = null ) { var contentRepository = app.Services.GetContentRepository(); var addUserCommand = app.TestData.Users().CreateAddCommand(uniqueData); if (configration != null) { configration(addUserCommand); } var userId = await contentRepository .WithElevatedPermissions() .Users() .AddAsync(addUserCommand); await contentRepository .Users() .AccountVerification() .EmailFlow() .InitiateAsync(new InitiateUserAccountVerificationViaEmailCommand() { UserId = userId }); var authorizedTask = await GetAuthorizedTask(app, userId); return(authorizedTask); }
private static async Task <AuthorizedTask> AddUserAndInitiateRequest( string uniqueData, DbDependentTestApplication app ) { var contentRepository = app.Services.GetContentRepository(); var dbContext = app.Services.GetRequiredService <CofoundryDbContext>(); var addUserCommand = app.TestData.Users().CreateAddCommand(uniqueData); await contentRepository .WithElevatedPermissions() .Users() .AddAsync(addUserCommand); await contentRepository .Users() .AccountRecovery() .InitiateAsync(new InitiateUserAccountRecoveryViaEmailCommand() { UserAreaCode = addUserCommand.UserAreaCode, Username = addUserCommand.Email }); var authorizedTask = await dbContext .AuthorizedTasks .Include(u => u.User) .SingleAsync(u => u.UserId == addUserCommand.OutputUserId); return(authorizedTask); }
private static async Task <User> GetUserByIdAsync(DbDependentTestApplication app, int userId) { var dbContext = app.Services.GetRequiredService <CofoundryDbContext>(); return(await dbContext .Users .AsNoTracking() .FilterById(userId) .SingleOrDefaultAsync()); }
/// <summary> /// <para> /// Creates a new <see cref="DbDependentTestApplication"/> instance /// which can be used to create and work with test entities directly /// through the domain layer with the same API used in the domain /// integration tests project. /// </para> /// <para> /// Note that although the test app and client instances share the same base /// service configuration, they don't seem to share the service collection and /// therefore the same singleton instances, so be aware that features like in-memory /// caching are not shared. To get around this, the caching services in the client /// app will be reset when a new client is created. /// </para> /// <para> /// The application should be disposed of /// when you are done with it. /// </para> /// </summary> public static DbDependentTestApplication CreateApp <TEntryPoint>(this WebApplicationFactory <TEntryPoint> factory) where TEntryPoint : class { var seededEntities = factory.Services.GetRequiredService <SeededEntities>(); var factoryWithAppDependencies = factory.WithServices(services => { DbDependentTestApplicationServiceProviderFactory.ConfigureTestServices(services); }); var app = new DbDependentTestApplication(factoryWithAppDependencies.Services, seededEntities); return(app); }
private static async Task <AuthorizedTask> GetAuthorizedTask( DbDependentTestApplication app, int userId ) { var dbContext = app.Services.GetRequiredService <CofoundryDbContext>(); var authorizedTask = await dbContext .AuthorizedTasks .AsNoTracking() .Include(u => u.User) .SingleAsync(u => u.UserId == userId); return(authorizedTask); }
private static async Task <User> AddUser(DbDependentTestApplication app, string uniqueData, Action <AddUserCommand> configureCommand = null) { var dbContext = app.Services.GetRequiredService <CofoundryDbContext>(); var userId = await app.TestData.Users().AddAsync(uniqueData, c => { c.Password = PASSWORD; configureCommand?.Invoke(c); }); var user = await dbContext .Users .AsNoTracking() .FilterById(userId) .SingleAsync(); return(user); }
private static async Task <AuthorizedTask> AddUserAndInitiate( string uniqueData, DbDependentTestApplication app, Action <AddUserCommand> configration = null ) { var contentRepository = app.Services.GetContentRepository(); var dbContext = app.Services.GetRequiredService <CofoundryDbContext>(); var addUserCommand = app.TestData.Users().CreateAddCommand(uniqueData); if (configration != null) { configration(addUserCommand); } var userId = await contentRepository .WithElevatedPermissions() .Users() .AddAsync(addUserCommand); await contentRepository .Users() .AccountVerification() .EmailFlow() .InitiateAsync(new InitiateUserAccountVerificationViaEmailCommand() { UserId = userId }); var authorizedTask = await dbContext .AuthorizedTasks .AsNoTracking() .Include(u => u.User) .Include(u => u.IPAddress) .SingleAsync(u => u.UserId == addUserCommand.OutputUserId); return(authorizedTask); }