Esempio n. 1
0
        public async Task<RegisterNewUserResult> RegisterUser(NewUser newUser)
        {
            ApplicationUser newApplicationUser = new ApplicationUser()
            {
                UserName = newUser.UserName,
                Email = newUser.EmailAddress,
                EmailConfirmed = true
            };

            IdentityResult identityResult = await applicationUserManager.CreateAsync(newApplicationUser, newUser.Password);

            NewlyRegisteredUser newlyRegisteredUser = new NewlyRegisteredUser
            {
                UserId = newApplicationUser.Id
            };

            if(identityResult.Succeeded)
            {
                newlyRegisteredUser = await this.SignInAndAssociateGamingGroup(newUser, newApplicationUser);
            }

            RegisterNewUserResult result = new RegisterNewUserResult
            {
                Result = identityResult,
                NewlyRegisteredUser = newlyRegisteredUser
            };

            return result;
        }
Esempio n. 2
0
        public void SetUp()
        {
            firstTimeUserAuthenticatorMock = MockRepository.GenerateMock<IFirstTimeAuthenticator>();
            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);
            authenticationManagerMock = MockRepository.GenerateMock<IAuthenticationManager>();
            signInManagerMock = MockRepository.GenerateMock<ApplicationSignInManager>(applicationUserManagerMock, authenticationManagerMock);
            dataContextMock = MockRepository.GenerateMock<IDataContext>();
            eventTrackerMock = MockRepository.GenerateMock<INemeStatsEventTracker>();
            gamingGroupInviteConsumerMock = MockRepository.GenerateMock<IGamingGroupInviteConsumer>();

            userRegisterer = new UserRegisterer(
                applicationUserManagerMock, 
                firstTimeUserAuthenticatorMock, 
                dataContextMock, 
                signInManagerMock,
                eventTrackerMock,
                gamingGroupInviteConsumerMock);

            Guid invitationId = Guid.NewGuid();
            const int PLAYER_ID = 1938;
            GamingGroupInvitation invitation = new GamingGroupInvitation
            {
                Id = invitationId,
                PlayerId = PLAYER_ID,
                GamingGroupId = 10
            };
            newUser = new NewUser()
            {
                UserName = "******",
                EmailAddress = "the email",
                GamingGroupInvitationId = invitationId,
                Source = TransactionSource.WebApplication
            };
            expectedNewlyRegisteredUser = new NewlyRegisteredUser
            {
                GamingGroupId = invitation.GamingGroupId,
                GamingGroupName = "some awesome gaming group name",
                PlayerId = PLAYER_ID,
                PlayerName = "some awesome player name",
                UserId = applicationUserIdAfterSaving
            };
            IdentityResult result = IdentityResult.Success;

            dataContextMock.Expect(mock => mock.FindById<GamingGroupInvitation>(invitationId))
                           .Return(invitation);
            applicationUserManagerMock.Expect(mock => mock.CreateAsync(Arg<ApplicationUser>.Is.Anything, Arg<string>.Is.Anything))
                                      .Return(Task.FromResult(result))
                                      .WhenCalled(invocation => ((ApplicationUser)invocation.Arguments[0]).Id = applicationUserIdAfterSaving);
                                      
            signInManagerMock.Expect(mock => mock.SignInAsync(
                                                                          Arg<ApplicationUser>.Is.Anything,
                                                                          Arg<bool>.Is.Anything,
                                                                          Arg<bool>.Is.Anything))
                                         
                                         .Return(Task.FromResult(-1));
            gamingGroupInviteConsumerMock.Expect(mock => mock.AddNewUserToGamingGroup(Arg<string>.Is.Anything, Arg<Guid>.Is.Anything))
                                         .Return(expectedNewlyRegisteredUser);
            firstTimeUserAuthenticatorMock.Expect(mock => mock.CreateGamingGroupAndSendEmailConfirmation(
                Arg<ApplicationUser>.Is.Anything,
                Arg<TransactionSource>.Is.Anything))
                .Return(Task.FromResult(expectedNewlyRegisteredUser));
        }