Esempio n. 1
0
        public virtual void SetUp()
        {
            userStoreMock = MockRepository.GenerateMock <IUserStore <ApplicationUser> >();
            gamingGroupInviteConsumerMock   = MockRepository.GenerateMock <IGamingGroupInviteConsumer>();
            userRegistererMock              = MockRepository.GenerateMock <IUserRegisterer>();
            this.firstTimeAuthenticatorMock = MockRepository.GenerateMock <IFirstTimeAuthenticator>();
            this.authenticationManagerMock  = MockRepository.GenerateMock <IAuthenticationManager>();
            var dataProtector = MockRepository.GenerateMock <IDataProtector>();

            dataProtectionProviderMock = MockRepository.GenerateMock <IDataProtectionProvider>();
            gamingGroupRetrieverMock   = MockRepository.GenerateMock <IGamingGroupRetriever>();
            dataProtectionProviderMock.Expect(mock => mock.Create(Arg <string> .Is.Anything)).Return(dataProtector);

            userManager = new ApplicationUserManager(userStoreMock, dataProtectionProviderMock);
            accountControllerPartialMock = MockRepository.GeneratePartialMock <AccountController>(
                userManager,
                userRegistererMock,
                this.firstTimeAuthenticatorMock,
                this.authenticationManagerMock,
                gamingGroupInviteConsumerMock,
                gamingGroupRetrieverMock);
            currentUser = new ApplicationUser()
            {
                Id = "new application user",
                CurrentGamingGroupId = 1
            };
            registerViewModel = new RegisterViewModel()
            {
                ConfirmPassword = "******",
                Password        = "******",
                UserName        = "******",
                EmailAddress    = "*****@*****.**"
            };
        }
        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));
        }
        private void SetupExpectations(bool isAuthenticated = true, bool userHasGamingGroup = true)
        {
            _actionExecutingContext = new ActionExecutingContext
            {
                ActionParameters = new Dictionary <string, object>()
            };
            _userStoreMock = MockRepository.GenerateMock <IUserStore <ApplicationUser> >();
            _dataProtectionProviderMock = MockRepository.GenerateMock <IDataProtectionProvider>();
            var dataProtector = MockRepository.GenerateMock <IDataProtector>();

            _dataProtectionProviderMock.Expect(mock => mock.Create(Arg <string> .Is.Anything)).Return(dataProtector);
            _userManager            = new ApplicationUserManager(_userStoreMock, _dataProtectionProviderMock);
            _clientIdCalculatorMock = MockRepository.GenerateMock <ClientIdCalculator>();
            //need to simulate like the parameter exists on the method
            _actionExecutingContext.ActionParameters[UserContextAttribute.UserContextKey] = null;

            var httpContextBase = MockRepository.GenerateMock <HttpContextBase>();

            _actionExecutingContext.HttpContext = httpContextBase;

            var principal = MockRepository.GenerateMock <IPrincipal>();

            httpContextBase.Expect(contextBase => contextBase.User)
            .Repeat.Any()
            .Return(principal);
            _identity = MockRepository.GenerateMock <IIdentity>();
            principal.Expect(mock => mock.Identity)
            .Repeat.Any()
            .Return(_identity);
            _identity.Expect(mock => mock.IsAuthenticated)
            .Repeat.Once()
            .Return(isAuthenticated);

            var requestBaseMock = MockRepository.GenerateMock <HttpRequestBase>();

            httpContextBase.Expect(mock => mock.Request)
            .Return(requestBaseMock);
            _requestParameters = new NameValueCollection();
            requestBaseMock.Expect(mock => mock.Params)
            .Return(_requestParameters);

            _userContextActionFilter = MockRepository.GeneratePartialMock <UserContextAttribute>();
            _applicationUser         = new ApplicationUser()
            {
                Id = "user id",
                CurrentGamingGroupId = userHasGamingGroup ? (int?)315 : null
            };
            var task = Task.FromResult(_applicationUser);

            //TODO can't figure out how to mock the GetUserId() extension method, so have to be less strict here
            _userStoreMock.Expect(mock => mock.FindByIdAsync(Arg <string> .Is.Anything))
            .Repeat.Once()
            .Return(task);
        }
 public virtual void SetUp()
 {
     pendingGamingGroupInvitationRetriever = MockRepository.GenerateMock<IPendingGamingGroupInvitationRetriever>();
     var dataProtector = MockRepository.GenerateMock<IDataProtector>();
     dataProtectionProviderMock = MockRepository.GenerateMock<IDataProtectionProvider>();
     dataProtectionProviderMock.Expect(mock => mock.Create(Arg<string>.Is.Anything)).Return(dataProtector);
     userStoreMock = MockRepository.GenerateMock<IUserStore<ApplicationUser>>();
     applicationUserManagerMock = MockRepository.GenerateMock<ApplicationUserManager>(userStoreMock, dataProtectionProviderMock);
     dataContextMock = MockRepository.GenerateMock<IDataContext>();
     gamingGroupInviteConsumer = new GamingGroupInviteConsumer(
         pendingGamingGroupInvitationRetriever, 
         applicationUserManagerMock, 
         dataContextMock);
     currentUser = new ApplicationUser()
     {
         Id = "user id"
     };
     gamingGroupInvitations = new List<GamingGroupInvitation>();
 }
Esempio n. 5
0
        public virtual void SetUp()
        {
            pendingGamingGroupInvitationRetriever = MockRepository.GenerateMock <IPendingGamingGroupInvitationRetriever>();
            var dataProtector = MockRepository.GenerateMock <IDataProtector>();

            dataProtectionProviderMock = MockRepository.GenerateMock <IDataProtectionProvider>();
            dataProtectionProviderMock.Expect(mock => mock.Create(Arg <string> .Is.Anything)).Return(dataProtector);
            userStoreMock = MockRepository.GenerateMock <IUserStore <ApplicationUser> >();
            applicationUserManagerMock = MockRepository.GenerateMock <ApplicationUserManager>(userStoreMock, dataProtectionProviderMock);
            dataContextMock            = MockRepository.GenerateMock <IDataContext>();
            gamingGroupInviteConsumer  = new GamingGroupInviteConsumer(
                pendingGamingGroupInvitationRetriever,
                applicationUserManagerMock,
                dataContextMock);
            currentUser = new ApplicationUser()
            {
                Id = "user id"
            };
            gamingGroupInvitations = new List <GamingGroupInvitation>();
        }
        public virtual void SetUp()
        {
            userStoreMock = MockRepository.GenerateMock<IUserStore<ApplicationUser>>();
            gamingGroupInviteConsumerMock = MockRepository.GenerateMock<IGamingGroupInviteConsumer>();
            userRegistererMock = MockRepository.GenerateMock<IUserRegisterer>();
            this.firstTimeAuthenticatorMock = MockRepository.GenerateMock<IFirstTimeAuthenticator>();
            this.authenticationManagerMock = MockRepository.GenerateMock<IAuthenticationManager>();
            var dataProtector = MockRepository.GenerateMock<IDataProtector>();
            dataProtectionProviderMock = MockRepository.GenerateMock<IDataProtectionProvider>();
            gamingGroupRetrieverMock = MockRepository.GenerateMock<IGamingGroupRetriever>();
            
            boardGameGeekUserSaver = MockRepository.GenerateMock<IBoardGameGeekUserSaver>();
            boardGameGeekApiClient = MockRepository.GenerateMock<IBoardGameGeekApiClient>();
            userRetriever = MockRepository.GenerateMock<IUserRetriever>();

            dataProtectionProviderMock.Expect(mock => mock.Create(Arg<string>.Is.Anything)).Return(dataProtector);

            userManager = new ApplicationUserManager(userStoreMock, dataProtectionProviderMock);
            accountControllerPartialMock = MockRepository.GeneratePartialMock<AccountController>(
                userManager,
                userRegistererMock,
                this.firstTimeAuthenticatorMock,
                this.authenticationManagerMock,
                gamingGroupInviteConsumerMock, 
                gamingGroupRetrieverMock,
                boardGameGeekUserSaver,
                boardGameGeekApiClient,
                userRetriever);
            currentUser = new ApplicationUser()
            {
                Id = "new application user",
                CurrentGamingGroupId = 1
            };
            registerViewModel = new RegisterViewModel()
            {
                ConfirmPassword = "******",
                Password = "******",
                UserName = "******",
                EmailAddress = "*****@*****.**"
            };
        }
Esempio n. 7
0
        public void SetUp()
        {
            autoMocker = new RhinoAutoMocker <UserSessionsController>();

            IDataProtector dataProtector = MockRepository.GenerateMock <IDataProtector>();

            userStoreMock = MockRepository.GenerateMock <IUserStore <ApplicationUser> >();
            IDataProtectionProvider dataProtectionProvider = MockRepository.GenerateMock <IDataProtectionProvider>();

            dataProtectionProvider.Expect(mock => mock.Create("ASP.N‌​ET Identity")).Return(dataProtector);
            ApplicationUserManager applicationUserManager = MockRepository.GeneratePartialMock <ApplicationUserManager>(userStoreMock, dataProtectionProvider);

            autoMocker.Inject(applicationUserManager);

            var controllerContextMock = MockRepository.GeneratePartialMock <HttpControllerContext>();
            HttpActionDescriptor actionDescriptorMock = MockRepository.GenerateMock <HttpActionDescriptor>();

            autoMocker.ClassUnderTest.ActionContext = new HttpActionContext(controllerContextMock, actionDescriptorMock);
            autoMocker.ClassUnderTest.Request       = new HttpRequestMessage();
            autoMocker.ClassUnderTest.Request.SetConfiguration(new HttpConfiguration());

            AutomapperConfiguration.Configure();
        }
Esempio n. 8
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));
        }
Esempio n. 9
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));
        }
        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));
        }