Advertisement
Guest User

Untitled

a guest
Feb 8th, 2016
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.27 KB | None | 0 0
  1. [ Binding ]
  2. public class RegistrationSteps
  3. {
  4. private RegistrationId _regId;
  5.  
  6. [ Given( @"account registered" ) ]
  7. public void GivenAccountRegistered( RegistrationInfo regInfo )
  8. {
  9. var regId = new RegistrationId( Guid.NewGuid() );
  10. Sp.SendToCore( new CreateRegistration( regId, regInfo ) );
  11. Sp.Ap.Do( () =>
  12. {
  13. // Wait for registration to complete
  14. var registration = Sp.Support.GetView< RegistrationView >( regId );
  15. registration.Value.Completed.Should().BeTrue();
  16. } );
  17. }
  18.  
  19. [ When( @"I register for new account" ) ]
  20. public void WhenIRegisterForNewAccount( RegistrationInfo regInfo )
  21. {
  22. this._regId = new RegistrationId( Guid.NewGuid() );
  23. Sp.SendToCore( new CreateRegistration( this._regId, regInfo ) );
  24. }
  25.  
  26. [ Then( @"registration succeeds" ) ]
  27. public void ThenRegistrationSucceeds()
  28. {
  29. Sp.Ap.Do( () =>
  30. {
  31. var view = Sp.Support.GetView< RegistrationView >( this._regId );
  32. view.HasValue.Should().BeTrue();
  33. var registration = view.Value;
  34.  
  35. registration.HasProblems.Should().BeFalse();
  36. registration.Status.Should().Be( "Registration completed" );
  37. } );
  38. }
  39.  
  40. [ Then( @"I can login with '(.*)' and password '(.*)'" ) ]
  41. public void ThenICanLoginWithAndPassword( string email, string password )
  42. {
  43. Sp.Ap.Do( () =>
  44. {
  45. var loginsIndex = Sp.Support.GetSingleton< LoginsIndex >();
  46. var userId = loginsIndex.Logins[ Email.From( email ) ];
  47.  
  48. var user = Sp.Support.GetView< LoginView >( new UserId( userId ) );
  49.  
  50. var passwordHash = user.Value.PasswordHash;
  51. passwordHash.Should().Be( PasswordHash.Generate( password, passwordHash.Salt, new PasswordGenerator() ) );
  52. } );
  53. }
  54.  
  55. [ Then( @"user '(.*)' exists as '(.*)'" ) ]
  56. public void ThenUserExistsAs( string email, string role )
  57. {
  58. Sp.Ap.Do( () =>
  59. {
  60. var loginsIndex = Sp.Support.GetSingleton< LoginsIndex >();
  61. var userId = loginsIndex.Logins[ Email.From( email ) ];
  62.  
  63. var user = Sp.Support.GetView< LoginView >( new UserId( userId ) ).Value;
  64.  
  65. user.UserRole.Should().Be( UserRole.Admin );
  66. } );
  67. }
  68.  
  69. [ Then( @"company '(.*)' exists" ) ]
  70. public void ThenCompanyExists( string tenantName )
  71. {
  72. Sp.Ap.Do( () =>
  73. {
  74. var tenantsIndex = Sp.Support.GetSingleton< TenantsIndex >();
  75. var tenantId = tenantsIndex.Names[ new TenantName( tenantName ) ];
  76.  
  77. var tenant = Sp.Support.GetView< TenantView >( new TenantId( tenantId ) ).Value;
  78.  
  79. tenant.Name.Should().Be( new TenantName( tenantName ) );
  80. } );
  81. }
  82.  
  83. [ Then( @"registration fails with message ""(.*)""" ) ]
  84. public void ThenRegistrationFailsWithMessage( string errorMessage )
  85. {
  86. Sp.Ap.Do( () =>
  87. {
  88. var registration = Sp.Support.GetView< RegistrationView >( this._regId ).Value;
  89. registration.HasProblems.Should().BeTrue( "failed registration should show it has problems" );
  90. registration.Problem.Should().Be( errorMessage );
  91. } );
  92. }
  93.  
  94. [ StepArgumentTransformation ]
  95. public RegistrationInfo RegistrationInfoTransform( Table regTable )
  96. {
  97. var regInfoBuilder = new RegistrationInfoBuilder( regTable.GetValue( "User Email" ), regTable.GetValue( "User Name" ),
  98. regTable.GetValue( "User Password" ), regTable.GetValue( "Company Name" ) )
  99. {
  100. OptionalTenantPhone = regTable.GetValue( "Company Phone" ),
  101. OptionalTenantUrl = regTable.GetValue( "Company Website" )
  102. };
  103. return regInfoBuilder.Build( new PasswordGenerator() );
  104. }
  105. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement