Guest User

Untitled

a guest
Dec 17th, 2017
366
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.98 KB | None | 0 0
  1. Feature: RegisterUser
  2. In order to register a user successfully
  3. A valid username, email, password (and confirmation password) must be entered
  4.  
  5.  
  6. @register
  7. Scenario: Valid Register User
  8. Given I have entered a username "testing", an email "testing@gmail.com", a password "123456" and a confirmation password "123456"
  9. When I press submit
  10. Then the response code should be 200
  11. And the user should be added to the database with verfied set to False
  12.  
  13. Background:
  14. Given I have registered a user "testing", "testing@gmail.com", "123456" and "123456"
  15.  
  16. @register
  17. Scenario: Username Already Taken
  18. Given I have entered a username "testing", an email "testing1@gmail.com", a password "123456" and a confirmation password "123456"
  19. When I press submit
  20. Then the response code should be 400
  21.  
  22. using NUnit.Framework;
  23. using System;
  24. using System.Net.Http;
  25. using TechTalk.SpecFlow;
  26.  
  27. namespace Tests.Specs
  28. {
  29. [Binding]
  30. public class RegisterUserSteps
  31. {
  32. private RegisterUserModel userInfo = new RegisterUserModel();
  33. private RegisterUserController user = new RegisterUserController()
  34. {
  35. Request = new HttpRequestMessage(),
  36. Configuration = new System.Web.Http.HttpConfiguration()
  37. };
  38. private ApiResponse response = new ApiResponse();
  39. private static string userTableName = "usersTable";
  40. private static string userTablePartitionKey = "USER_INFO";
  41. private static string userTableRowKey = "testing@gmail.com";
  42.  
  43.  
  44. [Given(@"I have entered a username ""(.*)"", an email ""(.*)"", a password ""(.*)"" and a confirmation password ""(.*)""")]
  45. public void GivenIHaveEnteredAUsernameAnEmailAPasswordAndAConfirmationPassword(string p0, string p1, string p2, string p3)
  46. {
  47. userInfo.Username = p0;
  48. userInfo.Email = p1;
  49. userInfo.Password = p2;
  50. userInfo.ConfirmPassword = p3;
  51. }
  52.  
  53. [When(@"I press submit")]
  54. public void WhenIPressSubmit()
  55. {
  56. response = user.Register(userInfo);
  57. }
  58.  
  59. [Then(@"the response code should be (.*)")]
  60. public void ThenTheResponseCodeShouldBe(int p0)
  61. {
  62. Assert.AreEqual(p0, response.Status);
  63. }
  64.  
  65.  
  66. [Then(@"the user should be added to the database with verfied set to False")]
  67. public void ThenTheUserShouldBeAddedToTheDatabaseWithVerfiedSetToFalse()
  68. {
  69. UserEntity user = AzureUtilities.RetrieveEntity<UserEntity>(userTableName, userTablePartitionKey, userTableRowKey);
  70. Assert.IsNotNull(user);
  71. Assert.AreEqual(userInfo.Username, user.Username);
  72. Assert.AreEqual(userInfo.Email, user.RowKey);
  73. Assert.IsFalse(user.Verified);
  74. }
  75.  
  76. [Given(@"I have registered a user ""(.*)"", ""(.*)"", ""(.*)"" and ""(.*)""")]
  77. public void GivenIHaveRegisteredAUserAnd(string p0, string p1, string p2, string p3)
  78. {
  79. //Using methods here that have been defined in previous steps
  80. GivenIHaveEnteredAUsernameAnEmailAPasswordAndAConfirmationPassword(p0, p1, p2, p3);
  81. WhenIPressSubmit();
  82. ThenTheResponseCodeShouldBe(200);
  83. }
Add Comment
Please, Sign In to add comment