Created
February 24, 2011 13:49
-
-
Save DerAlbertCom/842171 to your computer and use it in GitHub Desktop.
A quick spike for setting the SubjectCreator in BehaviorConfigBase
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment