Guest User

Untitled

a guest
Jul 23rd, 2018
209
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.75 KB | None | 0 0
  1. using FakeItEasy;
  2. using Machine.Fakes;
  3. using Machine.Specifications;
  4. using UserGroup.Web.Models;
  5. using UserGroup.Web.Services;
  6.  
  7. namespace UserGroup.Web.Specs.Models
  8. {
  9. public class ANewWebUser : BehaviorConfigBase
  10. {
  11. public override void EstablishContext(IFakeAccessor fakeAccessor)
  12. {
  13. base.EstablishContext(fakeAccessor);
  14. var hashing = fakeAccessor.The<IHashing>();
  15. hashing.WhenToldTo(h => h.GetHash("password", A<string>.Ignored)).Return("barFoo");
  16. hashing.WhenToldTo(h => h.GetHash("wordpass", A<string>.Ignored)).Return("fooBar");
  17. }
  18.  
  19. public override object CreateSubject(IFakeAccessor fakeAccessor)
  20. {
  21. return WebUser.Create("user", "mail", "password", fakeAccessor.The<IHashing>());
  22. }
  23. }
  24.  
  25. public class when_a_webuser_is_created : WithSubject<WebUser>
  26. {
  27. Establish context = () => With(new ANewWebUser());
  28.  
  29. It should_store_the_hash =
  30. () => Subject.PasswordHash.ShouldEqual("barFoo");
  31.  
  32. It should_hash_the_password =
  33. () => The<IHashing>().WasToldTo(h => h.GetHash("password", A<string>.Ignored));
  34. }
  35.  
  36. public class when_validating_a_wrong_password_on_a_webuser : WithSubject<WebUser>
  37. {
  38. Establish context = () => With(new ANewWebUser());
  39.  
  40. Because of = () => _result = Subject.ValidatePassword("wordpass", The<IHashing>());
  41.  
  42. It should_it_fail =
  43. () => _result.ShouldBeFalse();
  44.  
  45. It should_hash_the_password =
  46. () => The<IHashing>().WasToldTo(h => h.GetHash("wordpass", A<string>.Ignored));
  47.  
  48. It should_not_change_the_passwordhash =
  49. () => Subject.PasswordHash.ShouldEqual("barFoo");
  50.  
  51. static bool _result;
  52. }
  53.  
  54. public class when_validating_a_correct_password_on_a_webuser : WithSubject<WebUser>
  55. {
  56. Establish context = () => With(new ANewWebUser());
  57.  
  58. Because of = () => _result = Subject.ValidatePassword("password", The<IHashing>());
  59.  
  60. It should_it_ok =
  61. () => _result.ShouldBeTrue();
  62.  
  63. It should_hash_the_password =
  64. () => The<IHashing>().WasToldTo(h => h.GetHash("password", A<string>.Ignored));
  65.  
  66. It should_not_change_the_passwordhash =
  67. () => Subject.PasswordHash.ShouldEqual("barFoo");
  68.  
  69. static bool _result;
  70. }
  71.  
  72. public class when_setting_a_password_on_a_webuser : WithSubject<WebUser>
  73.  
  74. {
  75. Establish context = () => With(new ANewWebUser());
  76.  
  77. Because of = () => Subject.SetPassword("wordpass", The<IHashing>());
  78.  
  79. It should_hash_the_password =
  80. () => The<IHashing>().WasToldTo(h => h.GetHash("wordpass", A<string>.Ignored));
  81.  
  82. It should_store_the_hash =
  83. () => Subject.PasswordHash.ShouldEqual("fooBar");
  84. }
  85. }
Add Comment
Please, Sign In to add comment