public async Task it_should_add_a_refresh_token(DatabaseEngine engine) { // Arrange await using var container = new DatabaseTestContainerBuilder().Build(engine); var configuration = new ConfigurationBuilder().For(container).Build(engine); var manager = new DatabaseManagerBuilder().With(configuration).Build(engine); var runner = new MigratorRunnerBuilder().With(configuration).Build(engine); var sut = new UserRepositoryBuilder().With(configuration).Build(engine); await container.StartAsync(); await manager.EnsureDatabaseCreated(); runner.MigrateUp(); const string username = "******"; var user = new UserBuilder().WithUserName(username).Build(); await sut.CreateAsync(user); // Act var persistedUser = await sut.FindByNameAsync(username); await sut.AssignRefreshToken("some_token", persistedUser !); // Assert var result = await sut.FindByNameAsync(username); result !.RefreshTokens.Should().ContainSingle("some_token"); }
public async Task it_should_create_a_user(DatabaseEngine engine) { // Arrange await using var container = new DatabaseTestContainerBuilder().Build(engine); var configuration = new ConfigurationBuilder().For(container).Build(engine); var manager = new DatabaseManagerBuilder().With(configuration).Build(engine); var runner = new MigratorRunnerBuilder().With(configuration).Build(engine); var sut = new UserRepositoryBuilder().With(configuration).Build(engine); await container.StartAsync(); await manager.EnsureDatabaseCreated(); runner.MigrateUp(); // Act const string username = "******"; var user = new UserBuilder().WithUserName(username).Build(); await sut.CreateAsync(user); // Assert var result = await sut.FindByNameAsync(username); result.Should().BeEquivalentTo(user, opt => opt.Excluding(x => x.Id)); }
public async Task it_ensures_that_database_is_created(DatabaseEngine engine) { // Arrange await using var container = new DatabaseTestContainerBuilder().Build(engine); var configuration = new ConfigurationBuilder().For(container).Build(engine); var sut = new DatabaseManagerBuilder().With(configuration).Build(engine); await container.StartAsync(); // Act await sut.EnsureDatabaseCreated(); await sut.Drop(); await sut.EnsureDatabaseCreated(); // Assert (await sut.DatabaseExists()).Should().BeTrue(); }
public async Task it_should_update_a_user(DatabaseEngine engine) { // Arrange await using var container = new DatabaseTestContainerBuilder().Build(engine); var configuration = new ConfigurationBuilder().For(container).Build(engine); var manager = new DatabaseManagerBuilder().With(configuration).Build(engine); var runner = new MigratorRunnerBuilder().With(configuration).Build(engine); var sut = new UserRepositoryBuilder().With(configuration).Build(engine); await container.StartAsync(); await manager.EnsureDatabaseCreated(); runner.MigrateUp(); const string username = "******"; var user = new UserBuilder().WithUserName(username).Build(); await sut.CreateAsync(user); // Act var persistedUser = await sut.FindByNameAsync(username); persistedUser !.FirstName = "NewFirstName"; persistedUser.LastName = "NewLastName"; persistedUser.PhoneNumber = "NewPhoneNumber"; persistedUser.SecurityStamp = Guid.NewGuid().ToString(); persistedUser.PhoneNumberConfirmed = true; persistedUser.EmailConfirmed = true; persistedUser.TwoFactorEnabled = true; persistedUser.LockoutEnd = new DateTimeOffset(DateTime.Today); persistedUser.LockoutEnabled = true; persistedUser.AccessFailedCount = 10; await sut.UpdateAsync(persistedUser); // Assert var result = await sut.FindByNameAsync(username); result.Should().BeEquivalentTo(persistedUser, opt => opt.Excluding(x => x.Id)); }