Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- [ Binding ]
- public class RegistrationSteps
- {
- private RegistrationId _regId;
- [ Given( @"account registered" ) ]
- public void GivenAccountRegistered( RegistrationInfo regInfo )
- {
- var regId = new RegistrationId( Guid.NewGuid() );
- Sp.SendToCore( new CreateRegistration( regId, regInfo ) );
- Sp.Ap.Do( () =>
- {
- // Wait for registration to complete
- var registration = Sp.Support.GetView< RegistrationView >( regId );
- registration.Value.Completed.Should().BeTrue();
- } );
- }
- [ When( @"I register for new account" ) ]
- public void WhenIRegisterForNewAccount( RegistrationInfo regInfo )
- {
- this._regId = new RegistrationId( Guid.NewGuid() );
- Sp.SendToCore( new CreateRegistration( this._regId, regInfo ) );
- }
- [ Then( @"registration succeeds" ) ]
- public void ThenRegistrationSucceeds()
- {
- Sp.Ap.Do( () =>
- {
- var view = Sp.Support.GetView< RegistrationView >( this._regId );
- view.HasValue.Should().BeTrue();
- var registration = view.Value;
- registration.HasProblems.Should().BeFalse();
- registration.Status.Should().Be( "Registration completed" );
- } );
- }
- [ Then( @"I can login with '(.*)' and password '(.*)'" ) ]
- public void ThenICanLoginWithAndPassword( string email, string password )
- {
- Sp.Ap.Do( () =>
- {
- var loginsIndex = Sp.Support.GetSingleton< LoginsIndex >();
- var userId = loginsIndex.Logins[ Email.From( email ) ];
- var user = Sp.Support.GetView< LoginView >( new UserId( userId ) );
- var passwordHash = user.Value.PasswordHash;
- passwordHash.Should().Be( PasswordHash.Generate( password, passwordHash.Salt, new PasswordGenerator() ) );
- } );
- }
- [ Then( @"user '(.*)' exists as '(.*)'" ) ]
- public void ThenUserExistsAs( string email, string role )
- {
- Sp.Ap.Do( () =>
- {
- var loginsIndex = Sp.Support.GetSingleton< LoginsIndex >();
- var userId = loginsIndex.Logins[ Email.From( email ) ];
- var user = Sp.Support.GetView< LoginView >( new UserId( userId ) ).Value;
- user.UserRole.Should().Be( UserRole.Admin );
- } );
- }
- [ Then( @"company '(.*)' exists" ) ]
- public void ThenCompanyExists( string tenantName )
- {
- Sp.Ap.Do( () =>
- {
- var tenantsIndex = Sp.Support.GetSingleton< TenantsIndex >();
- var tenantId = tenantsIndex.Names[ new TenantName( tenantName ) ];
- var tenant = Sp.Support.GetView< TenantView >( new TenantId( tenantId ) ).Value;
- tenant.Name.Should().Be( new TenantName( tenantName ) );
- } );
- }
- [ Then( @"registration fails with message ""(.*)""" ) ]
- public void ThenRegistrationFailsWithMessage( string errorMessage )
- {
- Sp.Ap.Do( () =>
- {
- var registration = Sp.Support.GetView< RegistrationView >( this._regId ).Value;
- registration.HasProblems.Should().BeTrue( "failed registration should show it has problems" );
- registration.Problem.Should().Be( errorMessage );
- } );
- }
- [ StepArgumentTransformation ]
- public RegistrationInfo RegistrationInfoTransform( Table regTable )
- {
- var regInfoBuilder = new RegistrationInfoBuilder( regTable.GetValue( "User Email" ), regTable.GetValue( "User Name" ),
- regTable.GetValue( "User Password" ), regTable.GetValue( "Company Name" ) )
- {
- OptionalTenantPhone = regTable.GetValue( "Company Phone" ),
- OptionalTenantUrl = regTable.GetValue( "Company Website" )
- };
- return regInfoBuilder.Build( new PasswordGenerator() );
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement