Created
August 13, 2013 12:14
-
-
Save ritasker/6220510 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 DoUrden.BudgetCalculator.Domain; | |
using DoUrden.BudgetCalculator.Domain.Interfaces.Logic; | |
using DoUrden.BudgetCalculator.Domain.Interfaces.Services; | |
using DoUrden.BudgetCalculator.Domain.Interfaces.Services.Repositories; | |
using DoUrden.BudgetCalculator.Web.Modules.Authentication; | |
using Moq; | |
using Nancy; | |
using NUnit.Framework; | |
namespace DoUrden.BudgetCalculator.Tests.Unit.Modules | |
{ | |
[TestFixture] | |
public class AuthenticationModule_PostRegister_Tests | |
{ | |
private Mock<ISecurityLogic> _securityLogic; | |
private Mock<IMemberRepository> _memberRepository; | |
private AuthenticationModule _subject; | |
private RegistrationViewModel _viewModel; | |
private Mock<IEmailService> _emailService; | |
[SetUp] | |
public void Setup() | |
{ | |
//ARRANGE | |
Member member = new Member(); | |
_viewModel = new RegistrationViewModel { Email = "[email protected]" }; | |
_securityLogic = new Mock<ISecurityLogic>(); | |
_securityLogic | |
.Setup(x => x.GenerateSalt(128)) | |
.Verifiable(); | |
_memberRepository = new Mock<IMemberRepository>(); | |
_memberRepository | |
.Setup(x=>x.Add(It.IsAny<Member>())) | |
.Returns(member) | |
.Verifiable(); | |
_emailService = new Mock<IEmailService>(); | |
_emailService | |
.Setup(x => x.NewEmail()) | |
.Returns(_emailService.Object); | |
_emailService | |
.Setup(x => x.FromTemplate("Registration")) | |
.Returns(_emailService.Object); | |
_emailService | |
.Setup(x => x.WithBodyParameters(new[] {member.Id, _viewModel.Email})) | |
.Returns(_emailService.Object); | |
_emailService | |
.Setup(x=>x.Send()) | |
.Verifiable(); | |
_subject = new AuthenticationModule(_memberRepository.Object, _securityLogic.Object, _emailService.Object); | |
_subject.Context = new NancyContext(); | |
} | |
[Test] | |
public void PostRegister_ValidRegistration_NewSaltIsGenerated() | |
{ | |
//ACT | |
_subject.PostRegister(_viewModel); | |
//ASSERT | |
_securityLogic.Verify(); | |
} | |
[Test] | |
public void PostRegister_ValidRegistration_NewMemberSaved() | |
{ | |
//ACT | |
_subject.PostRegister(_viewModel); | |
//ASSERT | |
_memberRepository.Verify(); | |
} | |
[Test] | |
public void PostRegister_ValidRegistration_EmailSent() | |
{ | |
//ACT | |
_subject.PostRegister(_viewModel); | |
//ASSERT | |
_emailService.Verify(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment