Created
September 10, 2009 03:22
-
-
Save cprieto/184269 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 Xunit; | |
using Xunit.Extensions; | |
using Machine.Specifications; | |
using It=Machine.Specifications.It; | |
namespace Membership.App.Facts | |
{ | |
[Subject("Membership Service")] | |
public class when_member_data_is_totally_correct | |
{ | |
Because of = () => { }; | |
It must_check_username_available_in_repository = () => { }; | |
It must_save_member_to_repository = () => { }; | |
} | |
[Subject("Membership Service")] | |
public class when_member_data_is_incorrect | |
{ | |
Because of = () => { }; | |
It must_throw_a_validation_exception = () => { | |
}; | |
It must_not_save_member_to_repository = () => { }; | |
} | |
[Subject("Membership Service")] | |
public class when_username_already_exists : Membership_service_subscription_context | |
{ | |
Because of = () => { }; | |
It must_throw_a_validation_exception = () => { | |
signup.Username = "username"; | |
Assert.Throws<Exception>(() => suo.Register(signup)); | |
}; | |
} | |
[Subject("Membership Service")] | |
public class when_member_is_going_to_be_registered : Membership_service_subscription_context | |
{ | |
Because of = () => { | |
suo.Register(signup); | |
}; | |
It must_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; | |
protected static IMembershipService suo; | |
protected static SignUpForm signup; | |
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