Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using FakeItEasy;
- using Machine.Fakes;
- using Machine.Specifications;
- using UserGroup.Web.Models;
- using UserGroup.Web.Services;
- namespace UserGroup.Web.Specs.Models
- {
- public class ANewWebUser : BehaviorConfigBase
- {
- public override void EstablishContext(IFakeAccessor fakeAccessor)
- {
- base.EstablishContext(fakeAccessor);
- var hashing = fakeAccessor.The<IHashing>();
- hashing.WhenToldTo(h => h.GetHash("password", A<string>.Ignored)).Return("barFoo");
- hashing.WhenToldTo(h => h.GetHash("wordpass", A<string>.Ignored)).Return("fooBar");
- }
- public override object CreateSubject(IFakeAccessor fakeAccessor)
- {
- return WebUser.Create("user", "mail", "password", fakeAccessor.The<IHashing>());
- }
- }
- public class when_a_webuser_is_created : WithSubject<WebUser>
- {
- Establish context = () => With(new ANewWebUser());
- It should_store_the_hash =
- () => Subject.PasswordHash.ShouldEqual("barFoo");
- It should_hash_the_password =
- () => The<IHashing>().WasToldTo(h => h.GetHash("password", A<string>.Ignored));
- }
- public class when_validating_a_wrong_password_on_a_webuser : WithSubject<WebUser>
- {
- Establish context = () => With(new ANewWebUser());
- Because of = () => _result = Subject.ValidatePassword("wordpass", The<IHashing>());
- It should_it_fail =
- () => _result.ShouldBeFalse();
- It should_hash_the_password =
- () => The<IHashing>().WasToldTo(h => h.GetHash("wordpass", A<string>.Ignored));
- It should_not_change_the_passwordhash =
- () => Subject.PasswordHash.ShouldEqual("barFoo");
- static bool _result;
- }
- public class when_validating_a_correct_password_on_a_webuser : WithSubject<WebUser>
- {
- Establish context = () => With(new ANewWebUser());
- Because of = () => _result = Subject.ValidatePassword("password", The<IHashing>());
- It should_it_ok =
- () => _result.ShouldBeTrue();
- It should_hash_the_password =
- () => The<IHashing>().WasToldTo(h => h.GetHash("password", A<string>.Ignored));
- It should_not_change_the_passwordhash =
- () => Subject.PasswordHash.ShouldEqual("barFoo");
- static bool _result;
- }
- public class when_setting_a_password_on_a_webuser : WithSubject<WebUser>
- {
- Establish context = () => With(new ANewWebUser());
- Because of = () => Subject.SetPassword("wordpass", The<IHashing>());
- It should_hash_the_password =
- () => The<IHashing>().WasToldTo(h => h.GetHash("wordpass", A<string>.Ignored));
- It should_store_the_hash =
- () => Subject.PasswordHash.ShouldEqual("fooBar");
- }
- }
Add Comment
Please, Sign In to add comment