public void SetUp()
{
var userStoreMock = MockRepository.GenerateMock<IUserStore<ApplicationUser>>();
var dataProtector = MockRepository.GenerateMock<IDataProtector>();
dataProtectionProviderMock = MockRepository.GenerateMock<IDataProtectionProvider>();
dataProtectionProviderMock.Expect(mock => mock.Create(Arg<string>.Is.Anything)).Return(dataProtector);
applicationUserManagerMock = MockRepository.GenerateMock<ApplicationUserManager>(userStoreMock, dataProtectionProviderMock);
gamingGroupSaverMock = MockRepository.GenerateMock<IGamingGroupSaver>();
configurationManagerMock = MockRepository.GenerateMock<IConfigurationManager>();
dataContextMock = MockRepository.GenerateMock<IDataContext>();
firstTimeAuthenticator = new FirstTimeAuthenticator(
gamingGroupSaverMock,
applicationUserManagerMock,
configurationManagerMock,
dataContextMock);
applicationUser = new ApplicationUser
{
Id = "user id",
UserName = "user name"
};
registrationSource = TransactionSource.RestApi;
var appSettingsMock = MockRepository.GenerateMock<IAppSettings>();
configurationManagerMock.Expect(mock => mock.AppSettings)
.Return(appSettingsMock);
appSettingsMock.Expect(mock => mock.Get(FirstTimeAuthenticator.APP_KEY_EMAIL_CONFIRMATION_CALLBACK_URL))
.Return(callbackUrl);
expectedNewlyCreatedGamingGroupResult = new NewlyCreatedGamingGroupResult
{
NewlyCreatedGamingGroup = new GamingGroup { Id = 1 },
NewlyCreatedPlayer = new Player { Id = 100, Name = "some awesome player name"}
};
gamingGroupSaverMock.Expect(mock => mock.CreateNewGamingGroup(
Arg<string>.Is.Anything,
Arg<TransactionSource>.Is.Anything,
Arg<ApplicationUser>.Is.Anything))
.Return(expectedNewlyCreatedGamingGroupResult);
applicationUserManagerMock.Expect(mock => mock.GenerateEmailConfirmationTokenAsync(applicationUser.Id))
.Return(Task.FromResult(confirmationToken));
string expectedCallbackUrl = callbackUrl + string.Format(
FirstTimeAuthenticator.CONFIRMATION_EMAIL_CALLBACK_URL_SUFFIX,
applicationUser.Id,
HttpUtility.UrlEncode(confirmationToken));
string expectedEmailBody = string.Format(FirstTimeAuthenticator.CONFIRMATION_EMAIL_BODY, expectedCallbackUrl);
applicationUserManagerMock.Expect(mock => mock.SendEmailAsync(
applicationUser.Id,
FirstTimeAuthenticator.EMAIL_SUBJECT,
expectedEmailBody))
.Return(Task.FromResult(-1));
}