Exemple #1
0
        public void ItReturnsTheNewlyCreatedGamingGroupResult()
        {
            NewlyCreatedGamingGroupResult actualResult = autoMocker.ClassUnderTest.CreateNewGamingGroup(gamingGroupName, TransactionSource.RestApi, currentUser);

            Assert.AreSame(expectedGamingGroup, actualResult.NewlyCreatedGamingGroup);
            Assert.AreSame(expectedPlayer, actualResult.NewlyCreatedPlayer);
        }
Exemple #2
0
        public virtual NewlyCreatedGamingGroupResult CreateNewGamingGroup(
            string gamingGroupName,
            TransactionSource registrationSource,
            ApplicationUser currentUser)
        {
            ValidateGamingGroupName(gamingGroupName);

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

            NewlyCreatedGamingGroupResult newlyCreatedGamingGroupResult = new NewlyCreatedGamingGroupResult();
            GamingGroup newGamingGroup = dataContext.Save <GamingGroup>(gamingGroup, currentUser);

            newlyCreatedGamingGroupResult.NewlyCreatedGamingGroup = newGamingGroup;
            //commit changes since we'll need the GamingGroup.Id
            dataContext.CommitAllChanges();

            Player newlyCreatedPlayer = this.AssociateUserWithGamingGroup(currentUser, newGamingGroup);

            newlyCreatedGamingGroupResult.NewlyCreatedPlayer = newlyCreatedPlayer;

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

            return(newlyCreatedGamingGroupResult);
        }
Exemple #3
0
        public async Task <NewlyRegisteredUser> CreateGamingGroupAndSendEmailConfirmation(
            ApplicationUser applicationUser,
            TransactionSource registrationSource)
        {
            //fetch this first since we want to fail as early as possible if the config entry is missing
            var callbackUrl = this.GetCallbackUrlFromConfig();

            NewlyCreatedGamingGroupResult result = this.gamingGroupSaver.CreateNewGamingGroup(
                applicationUser.UserName + "'s Gaming Group",
                registrationSource,
                applicationUser);

            await this.SendConfirmationEmail(applicationUser, callbackUrl);

            return(new NewlyRegisteredUser
            {
                GamingGroupId = result.NewlyCreatedGamingGroup.Id,
                GamingGroupName = result.NewlyCreatedGamingGroup.Name,
                PlayerId = result.NewlyCreatedPlayer.Id,
                PlayerName = result.NewlyCreatedPlayer.Name,
                UserId = applicationUser.Id
            });
        }
        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));
        }