Created
September 10, 2009 04:18
-
-
Save cprieto/184293 to your computer and use it in GitHub Desktop.
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 System; | |
using Moq; | |
using Rioshu.Educa; | |
using Rioshu.Educa.Data; | |
using Rioshu.Educa.Models; | |
using Rioshu.Educa.Services; | |
using Machine.Specifications; | |
using It=Machine.Specifications.It; | |
namespace Membership.App.Facts | |
{ | |
[Subject(typeof(MembershipService), "Registering a user")] | |
public class when_member_data_is_totally_correct : Membership_service_subscription_context | |
{ | |
Because of = () => { | |
suo.Register(signup); | |
}; | |
It should_save_member_to_repository = () => { | |
memberRepository.Verify(r => r.Add(Moq.It.Is<Member>(m => m.Username == "username"))); | |
}; | |
} | |
[Subject(typeof(MembershipService), "Registering a user")] | |
public class when_member_data_is_incorrect : Membership_service_subscription_context | |
{ | |
static Exception exception; | |
Because of = () => { | |
signup.Username = string.Empty; | |
exception = Catch.Exception(() => suo.Register(signup)); | |
}; | |
It should_throw_a_validation_exception = () => { | |
exception.ShouldNotBeNull(); | |
exception.ShouldBeOfType<ValidationException>(); | |
}; | |
} | |
[Subject(typeof(MembershipService), "Registering a user"), Tags("failure")] | |
public class when_username_already_exists : Membership_service_subscription_context | |
{ | |
static Exception exception; | |
Because of = () => { | |
signup.Username = "username"; | |
exception = Catch.Exception(() => suo.Register(signup)); | |
}; | |
It should_throw_a_validation_exception = () => { | |
exception.ShouldNotBeNull(); | |
exception.ShouldBeOfType<ValidationException>(); | |
}; | |
} | |
[Subject(typeof(MembershipService), "Registering a user")] | |
public class when_member_is_going_to_be_registered : Membership_service_subscription_context | |
{ | |
Because of = () => { | |
suo.Register(signup); | |
}; | |
It should_check_if_username_is_already_taken = () => { | |
memberRepository.Verify(r => r.GetByUsername(Moq.It.IsAny<string>())); | |
}; | |
} | |
public class Membership_service_subscription_context | |
{ | |
protected static Mock<IMemberRepository> memberRepository = new Mock<IMemberRepository>(); | |
protected static IMembershipService suo; | |
protected static SignUpForm signup; | |
protected static Member member; | |
Establish context = () => | |
{ | |
member = new Member("username", "first name", "last name", string.Empty, DateTime.Now, Gender.Male, MemberType.Student); | |
signup = new SignUpForm | |
{ | |
Username = "non.exists", | |
FirstName = "first name", | |
LastName = "last name", | |
Email = "email@mail.com", | |
Password = "password", | |
RepeatPassword = "password", | |
BirthDate = DateTime.Now, | |
SchoolId = 1 | |
}; | |
memberRepository.Setup(r => r.GetByUsername(member.Username)).Returns(member); | |
memberRepository.Setup(r => r.GetByUsername("non.exist")).Returns(() => null); | |
suo = new MembershipService(); | |
}; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment