예제 #1
0
        public virtual NewlyCreatedGamingGroupResult CreateNewGamingGroup(
            string gamingGroupName,
            TransactionSource registrationSource,
            ApplicationUser currentUser)
        {
            ValidateGamingGroupName(gamingGroupName);

            var gamingGroup = new GamingGroup()
            {
                OwningUserId = currentUser.Id,
                Name = gamingGroupName
            };

            var newlyCreatedGamingGroupResult = new NewlyCreatedGamingGroupResult();
            var newGamingGroup = dataContext.Save<GamingGroup>(gamingGroup, currentUser);
            newlyCreatedGamingGroupResult.NewlyCreatedGamingGroup = newGamingGroup;
            //commit changes since we'll need the GamingGroup.Id
            dataContext.CommitAllChanges();

            var newlyCreatedPlayer = this.AssociateUserWithGamingGroup(currentUser, newGamingGroup);
            newlyCreatedGamingGroupResult.NewlyCreatedPlayer = newlyCreatedPlayer;

            new Task(() => eventTracker.TrackGamingGroupCreation(registrationSource)).Start();

            return newlyCreatedGamingGroupResult;
        }
        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 = "******"
            };

            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));
        }