コード例 #1
0
            public virtual async Task WhenAlreadyConfirmed_RedirectsToAccount(Func <Fakes, User> getCurrentUser)
            {
                // Arrange
                var controller = GetController();
                var account    = GetAccount(controller);

                // Act
                var result = await InvokeCancelChangeEmail(controller, account, getCurrentUser);

                // Assert
                GetMock <IUserService>().Verify(u => u.CancelChangeEmailAddress(It.IsAny <User>()), Times.Never);
                ResultAssert.IsRedirectToRoute(result, new { action = controller.AccountAction });
            }
コード例 #2
0
            public async Task RedirectsToAccountPage()
            {
                var user = new User {
                    Username = "******"
                };
                var controller = GetController <UsersController>();

                controller.SetCurrentUser(user);

                var result = await controller.GenerateApiKey(expirationInDays : null);

                ResultAssert.IsRedirectToRoute(result, new { action = "Account" });
            }
コード例 #3
0
            public virtual async Task UpdatesEmailPreferences(Func <Fakes, User> getCurrentUser, bool emailAllowed, bool notifyPackagePushed)
            {
                // Arrange
                var controller = GetController();
                var account    = GetAccount(controller);

                // Act
                var result = await InvokeChangeEmailSubscription(controller, getCurrentUser, emailAllowed, notifyPackagePushed);

                // Assert
                ResultAssert.IsRedirectToRoute(result, new { action = controller.AccountAction });
                GetMock <IUserService>().Verify(u => u.ChangeEmailSubscriptionAsync(account, emailAllowed, notifyPackagePushed));
            }
コード例 #4
0
            public void RedirectsToAccountPage()
            {
                var user = new User {
                    Username = "******"
                };
                var controller = GetController <UsersController>();

                controller.SetCurrentUser(user);

                var result = controller.GenerateApiKey();

                ResultAssert.IsRedirectToRoute(result, new { action = "Account", controller = "Users" });
            }
コード例 #5
0
            public void VerifyPackageKeyReturnsEmptyResultIfApiKeyExistsButIdAndVersionAreEmpty()
            {
                // Arrange
                var controller = new TestableApiController();

                controller.SetCurrentUser(new User());

                // Act
                var result = controller.VerifyPackageKey(null, null);

                // Assert
                ResultAssert.IsEmpty(result);
            }
コード例 #6
0
            public async Task WhenAccountMissingReturns404(bool isAdmin)
            {
                // Arrange
                var controller = GetController();

                // Act
                var result = await InvokeConfirmMember(controller, account : null, isAdmin : isAdmin);

                // Assert
                ResultAssert.IsStatusCode(result, HttpStatusCode.NotFound);

                GetMock <IUserService>().Verify(s => s.AddMemberAsync(It.IsAny <Organization>(), Fakes.User.Username, defaultConfirmationToken), Times.Never);
                GetMock <IMessageService>().Verify(s => s.SendOrganizationMemberUpdatedNotice(It.IsAny <Organization>(), It.IsAny <Membership>()), Times.Never);
            }
コード例 #7
0
            public async Task WhenAccountMissingReturns404(bool isAdmin)
            {
                // Arrange
                var controller = GetController();

                // Act
                var result = await InvokeRejectMember(controller, account : null, isAdmin : isAdmin);

                // Assert
                ResultAssert.IsStatusCode(result, HttpStatusCode.NotFound);

                GetMock <IUserService>().Verify(s => s.RejectMembershipRequestAsync(It.IsAny <Organization>(), It.IsAny <string>(), It.IsAny <string>()), Times.Never);
                GetMock <IMessageService>().Verify(s => s.SendOrganizationMembershipRequestRejectedNotice(It.IsAny <Organization>(), It.IsAny <User>()), Times.Never);
            }
コード例 #8
0
            public void RedirectsToAccountPage()
            {
                var controller = GetController <UsersController>();
                var user       = new User {
                    Username = "******"
                };

                controller.SetUser(user);
                GetMock <IUserService>()
                .Setup(u => u.FindByUsername(It.IsAny <string>()))
                .Returns(user);
                var result = controller.GenerateApiKey();

                ResultAssert.IsRedirectToRoute(result, new { action = "Account", controller = "Users" });
            }
コード例 #9
0
            public void WillReturnTheAccountViewModelWithTheUserApiKey()
            {
                var controller = GetController <UsersController>();
                var stubApiKey = Guid.NewGuid();

                controller.SetCurrentUser(new User {
                    Key = 42, ApiKey = stubApiKey
                });

                // act
                var model = ResultAssert.IsView <AccountViewModel>(controller.Account());

                // verify
                Assert.Equal(stubApiKey.ToString(), model.ApiKey);
            }
コード例 #10
0
            public void ReturnsViewIfModelStateInvalid()
            {
                // Arrange
                var controller = GetController <UsersController>();

                controller.ModelState.AddModelError("test", "test");
                var inputModel = new PasswordChangeViewModel();

                // Act
                var result = controller.ChangePassword(inputModel);

                // Assert
                var outputModel = ResultAssert.IsView <PasswordChangeViewModel>(result);

                Assert.Same(inputModel, outputModel);
            }
コード例 #11
0
            public virtual void WhenAccountAlreadyConfirmed(Func <Fakes, User> getCurrentUser)
            {
                // Arrange
                var controller = GetController();
                var account    = GetAccount(controller);

                // Act
                var result = InvokeConfirmationRequired(controller, account, getCurrentUser);

                // Assert
                var model = ResultAssert.IsView <ConfirmationViewModel>(result);

                Assert.True(model.AlreadyConfirmed);
                Assert.Equal(account.EmailAddress, model.ConfirmedEmailAddress);
                Assert.Null(model.UnconfirmedEmailAddress);
            }
コード例 #12
0
            public async Task GivenNoCredential_ItRedirectsBackWithNoChangesMade()
            {
                // Arrange
                var user = Fakes.CreateUser("test",
                                            CredentialBuilder.CreatePbkdf2Password("password"));
                var controller = GetController <UsersController>();

                controller.SetCurrentUser(user);

                // Act
                var result = await controller.RemoveCredential(CredentialTypes.ExternalPrefix + "MicrosoftAccount");

                // Assert
                ResultAssert.IsRedirectToRoute(result, new { action = "Account" });
                Assert.Equal(1, user.Credentials.Count);
            }
コード例 #13
0
            public void WhenCurrentUserIsCollaborator_ReturnsReadOnly()
            {
                // Arrange
                var controller = GetController();
                var account    = GetAccount(controller);

                controller.SetCurrentUser(Fakes.OrganizationCollaborator);

                // Act
                var result = InvokeAccount(controller);

                // Assert
                var model = ResultAssert.IsView <OrganizationAccountViewModel>(result, "ManageOrganization");

                Assert.False(model.CanManage);
            }
コード例 #14
0
            public virtual async Task WhenNewEmailIsSame_RedirectsWithoutChange(Func <Fakes, User> getCurrentUser)
            {
                // Arrange
                var controller = GetController();
                var account    = GetAccount(controller);
                var model      = CreateViewModel(account);

                model.ChangeEmail.NewEmail = account.EmailAddress;

                // Act
                var result = await InvokeChangeEmail(controller, account, getCurrentUser, model);

                // Assert
                GetMock <IUserService>().Verify(u => u.ChangeEmailAddress(It.IsAny <User>(), It.IsAny <string>()), Times.Never);
                ResultAssert.IsRedirectToRoute(result, new { action = controller.AccountAction });
            }
コード例 #15
0
            public virtual async Task WhenUnconfirmed_CancelsEmailChangeRequest(Func <Fakes, User> getCurrentUser)
            {
                // Arrange
                var controller = GetController();
                var account    = GetAccount(controller);

                account.UnconfirmedEmailAddress = account.EmailAddress;
                account.EmailAddress            = null;

                // Act
                var result = await InvokeCancelChangeEmail(controller, account, getCurrentUser);

                // Assert
                GetMock <IUserService>().Verify(u => u.CancelChangeEmailAddress(account), Times.Once);
                ResultAssert.IsRedirectToRoute(result, new { action = controller.AccountAction });
                Assert.Equal(controller.Messages.EmailUpdateCancelled, controller.TempData["Message"]);
            }
コード例 #16
0
            public async Task GivenNoOtherLoginCredentials_ItRedirectsBackWithAnErrorMessage()
            {
                // Arrange
                var user = Fakes.CreateUser("test",
                                            CredentialBuilder.CreatePbkdf2Password("password"));
                var controller = GetController <UsersController>();

                controller.SetCurrentUser(user);

                // Act
                var result = await controller.RemovePassword();

                // Assert
                ResultAssert.IsRedirectToRoute(result, new { action = "Account" });
                Assert.Equal(Strings.CannotRemoveOnlyLoginCredential, controller.TempData["Message"]);
                Assert.Equal(1, user.Credentials.Count);
            }
コード例 #17
0
            public async Task GivenNoOtherLoginCredentials_ItRedirectsBackWithAnErrorMessage()
            {
                // Arrange
                var cred       = CredentialBuilder.CreateExternalCredential("MicrosoftAccount", "blorg", "bloog");
                var user       = Fakes.CreateUser("test", cred);
                var controller = GetController <UsersController>();

                controller.SetCurrentUser(user);

                // Act
                var result = await controller.RemoveCredential(cred.Type);

                // Assert
                ResultAssert.IsRedirectToRoute(result, new { action = "Account" });
                Assert.Equal(Strings.CannotRemoveOnlyLoginCredential, controller.TempData["Message"]);
                Assert.Equal(1, user.Credentials.Count);
            }
コード例 #18
0
            public async Task WhenUserIsNotMember_ReturnsNonSuccess()
            {
                // Arrange
                var controller = GetController();
                var account    = GetAccount(controller);

                controller.SetCurrentUser(Fakes.User);

                // Act
                var result = await InvokeConfirm(controller, account);

                // Assert
                var model = ResultAssert.IsView <ConfirmationViewModel>(result);

                Assert.True(model.WrongUsername);
                Assert.False(model.SuccessfulConfirmation);
            }
コード例 #19
0
            public async Task GivenNoPassword_ItRedirectsBackWithNoChangesMade()
            {
                // Arrange
                var fakes = Get <Fakes>();
                var user  = fakes.CreateUser("test",
                                             CredentialBuilder.CreateExternalCredential("MicrosoftAccount", "blorg", "bloog"));
                var controller = GetController <UsersController>();

                controller.SetCurrentUser(user);

                // Act
                var result = await controller.RemovePassword();

                // Assert
                ResultAssert.IsRedirectToRoute(result, new { action = "Account" });
                Assert.Equal(Strings.NoCredentialToRemove, controller.TempData["Message"]);
                Assert.Equal(1, user.Credentials.Count);
            }
コード例 #20
0
            public void WillThrowIfAPackageWithTheIdAndSemanticVersionDoesNotExist()
            {
                // Arrange
                var controller = new TestableApiController();

                controller.MockPackageService.Setup(x => x.FindPackageByIdAndVersion("theId", "1.0.42", true)).Returns((Package)null);
                controller.SetCurrentUser(new User());

                // Act
                var result = controller.PublishPackage("theId", "1.0.42");

                // Assert
                ResultAssert.IsStatusCode(
                    result,
                    HttpStatusCode.NotFound,
                    String.Format(Strings.PackageWithIdAndVersionNotFound, "theId", "1.0.42"));
                controller.MockPackageService.Verify(x => x.MarkPackageListed(It.IsAny <Package>(), It.IsAny <bool>()), Times.Never());
            }
コード例 #21
0
            public virtual async Task WhenAlreadyConfirmed_DoesNotSendEmail(Func <Fakes, User> getCurrentUser)
            {
                // Arrange
                var controller = GetController();
                var account    = GetAccount(controller);

                // Act
                var result = await InvokeConfirmationRequiredPostAsync(controller, account, getCurrentUser);

                // Assert
                var mailService = GetMock <IMessageService>();

                mailService.Verify(m => m.SendMessageAsync(It.IsAny <NewAccountMessage>(), It.IsAny <bool>(), It.IsAny <bool>()), Times.Never);

                var model = ResultAssert.IsView <ConfirmationViewModel>(result);

                Assert.False(model.SentEmail);
            }
コード例 #22
0
            public async Task WhenIsNotConfirmedAndTokenDoesNotMatch_ShowsError(Func <Fakes, User> getCurrentUser)
            {
                // Arrange
                var controller = GetController();
                var account    = GetAccount(controller);

                account.EmailConfirmationToken = "token";

                account.UnconfirmedEmailAddress = "*****@*****.**";

                // Act
                var result = await InvokeConfirm(controller, account, getCurrentUser, "wrongToken");

                // Assert
                var model = ResultAssert.IsView <ConfirmationViewModel>(result);

                Assert.False(model.SuccessfulConfirmation);
            }
コード例 #23
0
            public void WillReturnTheAccountViewModelWithTheCuratedFeeds()
            {
                var controller = GetController <UsersController>();

                controller.SetCurrentUser(new User {
                    Key = 42
                });
                GetMock <ICuratedFeedService>()
                .Setup(stub => stub.GetFeedsForManager(42))
                .Returns(new[] { new CuratedFeed {
                                     Name = "theCuratedFeed"
                                 } });

                // act
                var model = ResultAssert.IsView <AccountViewModel>(controller.Account(), viewName: "Account");

                // verify
                Assert.Equal("theCuratedFeed", model.CuratedFeeds.First());
            }
コード例 #24
0
            public virtual async Task WithNullUser_ShowsError(Func <Fakes, User> getCurrentUser)
            {
                // Arrange
                var controller      = GetController();
                var accountUsername = "******";

                controller.SetCurrentUser(getCurrentUser(Fakes));

                // Act
                var result = await controller.Confirm(accountUsername, "token");

                // Assert
                var model = ResultAssert.IsView <ConfirmationViewModel>(result);

                Assert.Equal(accountUsername, model.AccountName);
                Assert.False(model.SuccessfulConfirmation);
                Assert.True(model.WrongUsername);
                Assert.True(model.AlreadyConfirmed);
            }
コード例 #25
0
            public async Task WhenIsNotConfirmedAndEntityExceptionThrown_ShowsErrorForDuplicateEmail(Func <Fakes, User> getCurrentUser)
            {
                // Arrange
                var controller = GetController();
                var account    = GetAccount(controller);
                var token      = account.EmailConfirmationToken = "token";

                account.UnconfirmedEmailAddress = "*****@*****.**";

                // Act
                var result = await InvokeConfirm(controller, account, getCurrentUser, token,
                                                 exception : new EntityException("msg"));

                // Assert
                var model = ResultAssert.IsView <ConfirmationViewModel>(result);

                Assert.False(model.SuccessfulConfirmation);
                Assert.True(model.DuplicateEmailAddress);
            }
コード例 #26
0
            public void WillReturnTheAccountViewModelWithTheUserApiKey()
            {
                var controller = GetController <UsersController>();

                controller.SetUser("user");
                var stubApiKey = Guid.NewGuid();

                GetMock <IUserService>()
                .Setup(s => s.FindByUsername("user"))
                .Returns(new User {
                    Key = 42, ApiKey = stubApiKey
                });

                // act
                var model = ResultAssert.IsView <AccountViewModel>(controller.Account());

                // verify
                Assert.Equal(stubApiKey.ToString(), model.ApiKey);
            }
コード例 #27
0
            public async Task WhenAddOrganizationThrowsEntityException_ReturnsViewWithMessage()
            {
                var message = "message";

                var mockUserService = GetMock <IUserService>();

                mockUserService
                .Setup(x => x.AddOrganizationAsync(OrgName, OrgEmail, Admin))
                .Throws(new EntityException(message));

                var controller = GetController <OrganizationsController>();

                controller.SetCurrentUser(Admin);

                var result = await controller.Add(Model);

                ResultAssert.IsView <AddOrganizationViewModel>(result);
                Assert.Equal(message, controller.TempData["ErrorMessage"]);
            }
コード例 #28
0
            public void UpdatesEmailAllowedSetting()
            {
                var user = new User("aUsername")
                {
                    EmailAddress = "*****@*****.**",
                    EmailAllowed = true
                };

                var controller = GetController <UsersController>();

                controller.SetCurrentUser(user);
                GetMock <IUserService>()
                .Setup(u => u.ChangeEmailSubscription(user, false));

                var result = controller.ChangeEmailSubscription(false);

                ResultAssert.IsRedirectToRoute(result, new { action = "Account" });
                GetMock <IUserService>().Verify(u => u.ChangeEmailSubscription(user, false));
            }
コード例 #29
0
            public void VerifyPackageKeyReturns200IfUserIsAnOwner()
            {
                // Arrange
                var user    = new User();
                var package = new Package {
                    PackageRegistration = new PackageRegistration()
                };

                package.PackageRegistration.Owners.Add(user);
                var controller = new TestableApiController();

                controller.SetCurrentUser(user);
                controller.MockPackageService.Setup(s => s.FindPackageByIdAndVersion("foo", "1.0.0", true)).Returns(package);

                // Act
                var result = controller.VerifyPackageKey("foo", "1.0.0");

                // Assert
                ResultAssert.IsEmpty(result);
            }
コード例 #30
0
            public async Task ShowsAnErrorForWrongUsername()
            {
                var user = new User
                {
                    Username = "******",
                    UnconfirmedEmailAddress = "*****@*****.**",
                    EmailConfirmationToken  = "aToken",
                };

                var controller = GetController <UsersController>();

                controller.SetCurrentUser(user);

                var result = await controller.Confirm("wrongUsername", "aToken");

                var model = ResultAssert.IsView <ConfirmationViewModel>(result);

                Assert.False(model.SuccessfulConfirmation);
                Assert.True(model.WrongUsername);
            }