public void Secret_should_different_between_two_generate() { string secret1; string secret2; SecretGenerator secretGenerator = new SecretGenerator(); secret1 = secretGenerator.GenerateSecret(); secret2 = secretGenerator.GenerateSecret(); Assert.NotEqual(secret1, secret2); }
public void Should_different_Between_2_Digits() { //given var secretGenerator = new SecretGenerator(); var secret = secretGenerator.GenerateSecret(); //when var secret1 = secretGenerator.GenerateSecret(); //then Assert.NotEqual(secret, secret1); }
public void SignUp(TodoContext context, SignUpRequest signUpRequest) { _signUpRequestValidator.ValidateAndThrow(signUpRequest); var user = context.Users .SingleOrDefault(u => u.Email == signUpRequest.Email); if (user != null) { throw new TodoException(ServiceError.UserAlreadyRegistered); } var confirmationSecret = _secretGenerator.GenerateSecret(); var pendingUser = new PendingUser { Email = signUpRequest.Email, Password = signUpRequest.Password, Secret = confirmationSecret }; context.PendingUsers.Add(pendingUser); context.SaveChanges(); _signUpConfirmationNotifier.Notify( pendingUser.Email, pendingUser.Secret); }
public SessionDTO SignIn(TodoContext context, SignInRequest signInRequest) { _signInRequestValidator.ValidateAndThrow(signInRequest); var user = context.Users.SingleOrDefault(u => u.Email == signInRequest.Email); if (user == null) { throw new TodoException(ServiceError.NoSuchUser); } if (user.Password != signInRequest.Password) { throw new TodoException(ServiceError.InvalidPassword); } ++user.AuthenticationCount; user.LastActivityAt = _timeProvider.GetCurrentTime(); var session = new Session { Token = _secretGenerator.GenerateSecret(), User = user, LastAccessTime = _timeProvider.GetCurrentTime() }; context.Sessions.Add(session); context.SaveChanges(); return(new SessionDTO { SessionToken = session.Token }); }
public void Should_create_proper_random_secret() { var secretGenerator = new SecretGenerator(); var secret = secretGenerator.GenerateSecret(); Assert.Equal(4, secret.Length); Assert.Equal(4, secret.Distinct().Count()); }
public void SecretGeneratedShouldHaveLengthOfFour() { var secretGenerator = new SecretGenerator(); var secret = secretGenerator.GenerateSecret(); var expected = secret.Count(); var actual = 4; Assert.Equal(expected, actual); }
public void Should_return_non_repeatable_secret_numbers() { var secretGenerator = new SecretGenerator(); var secret = secretGenerator.GenerateSecret(); var secretChars = secret.ToCharArray(); var len = 4; var actual = secretChars.Length == len && secretChars.Distinct().Count() == len; Assert.Equal(true, actual); }
public void Should_GenerateSecret_return_valid_secret() { // given var secretGenerator = new SecretGenerator(); // when var secret = secretGenerator.GenerateSecret(); // then Assert.True(IsSecretValid(secret)); }
public void Should_Generat_4_Digits() { //given var secretGenerator = new SecretGenerator(); var secret = secretGenerator.GenerateSecret(); //when var secretLength = 4; //then Assert.Equal(secret.Length, secretLength); }
public void Secret_length_should_be_4() { // given string secret = string.Empty; var secretGenerator = new SecretGenerator(); // when secret = secretGenerator.GenerateSecret(); // then Assert.Equal(4, secret.Length); }
public static async Task DBSetup(string[] args, IHost host) { var serviceScopeFactory = (IServiceScopeFactory)host.Services.GetService(typeof(IServiceScopeFactory)); using var scope = serviceScopeFactory.CreateScope(); var eventStoreContext = scope.ServiceProvider.GetRequiredService <EventStoreContext>(); var appDatabaseContext = scope.ServiceProvider.GetRequiredService <AppDatabaseContext>(); var configuration = scope.ServiceProvider.GetRequiredService <IConfiguration>(); if (args.Contains("ci")) { args = new string[4] { "dropdb", "migratedb", "seeddb", "stop" } } ; if (args.Contains("dropdb")) { eventStoreContext.Database.EnsureDeleted(); } if (args.Contains("migratedb")) { eventStoreContext.Database.Migrate(); } if (args.Contains("seeddb")) { eventStoreContext.Database.EnsureCreated(); await DataSeeder.SeedAsync(appDatabaseContext, configuration); } if (args.Contains("secret")) { Console.WriteLine(SecretGenerator.GenerateSecret()); Environment.Exit(0); } if (args.Contains("stop")) { Environment.Exit(0); } } }
private static void ProcessDatabase(string[] args, IHost host) { var services = (IServiceScopeFactory)host.Services.GetService(typeof(IServiceScopeFactory)); using var scope = services.CreateScope(); var eventStoreDbContext = scope.ServiceProvider.GetRequiredService <EventStoreDatabaseContext>(); var databaseContext = scope.ServiceProvider.GetRequiredService <IDatabaseContext>(); var configuration = scope.ServiceProvider.GetRequiredService <IConfiguration>(); if (args.Contains("ci")) { args = new string[4] { "dropdb", "migratedb", "seeddb", "stop" } } ; if (args.Contains("dropdb")) { eventStoreDbContext.Database.EnsureDeleted(); } if (args.Contains("migratedb")) { eventStoreDbContext.Database.Migrate(); } if (args.Contains("seeddb")) { eventStoreDbContext.Database.EnsureCreated(); DataSeeder.Seed(databaseContext); } if (args.Contains("secret")) { Console.WriteLine(SecretGenerator.GenerateSecret()); Environment.Exit(0); } if (args.Contains("stop")) { Environment.Exit(0); } }
public void RequestPasswordReset(TodoContext context, RequestPasswordResetRequest requestPasswordResetRequest) { _requestPasswordResetRequestValidator.ValidateAndThrow(requestPasswordResetRequest); var email = requestPasswordResetRequest.Email; var user = context.Users.SingleOrDefault(u => u.Email == email); if (user == null) { throw new TodoException(ServiceError.NoSuchUser); } var resetPasswordRequestSecret = _secretGenerator.GenerateSecret(); var pendingPasswordReset = new PendingPasswordReset { UserId = user.UserId, Secret = resetPasswordRequestSecret }; context.PendingPasswordResets.Add(pendingPasswordReset); context.SaveChanges(); _resetPasswordNotifier.Notify(email, resetPasswordRequestSecret); }