Example #1
0
            public void SetupActivationWithInvalidUserThrowsException()
            {
                // Arrange
                ActivationTokenCreationRequestDto invalidUserRequest = new ActivationTokenCreationRequestDto
                {
                    UserToActivate = new UserDto
                    {
                        Id = Guid.Empty
                    }
                };

                // Act
                try
                {
                    adminService.SetupActivationToken(invalidUserRequest);
                    // Assert
                    Assert.Fail("validation exception should have been thrown");
                }
                catch (ValidationException vex)
                {
                    Assert.AreEqual("SRVEX30069", vex.Code, "Validation exception code was not correct");
                }
            }
Example #2
0
            public void SetupActivationTokenWithValidDataCallsCorrectMethods()
            {
                // Arrange
                string baseUrl = "base";
                string fakeActivationToken = "fakeToken";
                IEmailManager emailManagerMock = MockRepository.GenerateMock<IEmailManager>();
                IAccountManager accountManagerMock = MockRepository.GenerateMock<IAccountManager>();
                ActivationTokenCreationRequestDto creationRequest = new ActivationTokenCreationRequestDto()
                {
                    BaseEmailUrlForUser = baseUrl,
                    UserToActivate = new UserDto
                    {
                        Id = new Guid("11111111-1111-1111-1111-111111111111"),
                        UserName = "******",
                        FirstName = "bill",
                        LastName = "smith",
                        Email = "*****@*****.**"
                    }
                };
                accountManagerMock.Expect(am => am.CreateDefaultActivationToken(Arg<Guid>.Is.Equal(creationRequest.UserToActivate.Id))).Return(fakeActivationToken).Repeat.Once();

                // verify that the activation token from account manager is used in email manager call
                // also verify data looks correct
                emailManagerMock.Expect(em => em.SendActivationEmail(Arg<string>.Is.Equal(baseUrl + fakeActivationToken),
                                                                    Arg<User>.Matches(u => u.Extension.FirstName == creationRequest.UserToActivate.FirstName &&
                                                                                           u.Extension.LastName == creationRequest.UserToActivate.LastName &&
                                                                                           u.Id == creationRequest.UserToActivate.Id &&
                                                                                           u.UserName == creationRequest.UserToActivate.UserName &&
                                                                                           u.UserMembership.Email == creationRequest.UserToActivate.Email))).Return(true).Repeat.Once();

                adminService.AccountManager = accountManagerMock;
                adminService.EmailManager = emailManagerMock;

                // Act
                bool result = adminService.SetupActivationToken(creationRequest);

                // Assert
                accountManagerMock.VerifyAllExpectations();
                emailManagerMock.VerifyAllExpectations();
                Assert.IsTrue(result, "service should have returned true");
            }  
Example #3
0
        public bool SetupResetPasswordToken(ActivationTokenCreationRequestDto request)
        {
            if (request == null || request.UserToActivate == null ||
                request.UserToActivate.Id == Guid.Empty)
            {
                throw new ValidationException(ErrorFactory.CreateAndLogError(Errors.SRVEX30069, "AdminService.SetupResetPasswordToken", arguments: new object[] { request }));
            }

            string activationToken = accountManager.CreateResetPasswordActivationToken(request.UserToActivate.Id);

            return emailManager.SendResetPasswordEmail(request.BaseEmailUrlForUser + activationToken, DataTransferObjectsConverter.ConvertUserDtoToUser(request.UserToActivate));
        }