public void ChangePasswordWithInvalidEmailShouldReturnFalse()
 {
     var mock = new AccountServiceMock();
     var resetKey = Guid.NewGuid();
     var result = mock.AccountService.ChangePassword("Test", null, "New", resetKey);
     Assert.IsFalse(result.Success);
 }
        public void ChangePasswordWithInvalidEmailShouldReturnFalse()
        {
            var mock     = new AccountServiceMock();
            var resetKey = Guid.NewGuid();
            var result   = mock.AccountService.ChangePassword("Test", null, "New", resetKey);

            Assert.IsFalse(result.Success);
        }
 public void ChangePasswordWithInvalidResetKeyAndNoOldPasswordShouldReturnFalse()
 {
     var mock = new AccountServiceMock();
     var userId = Guid.NewGuid();
     var resetKey = Guid.NewGuid();
     mock.UserManagerMock.Setup(u => u.Get("Test")).Returns(new User(userId, "Test", "Test"));
     var result = mock.AccountService.ChangePassword("Test", null, "New", Guid.NewGuid());
     Assert.IsFalse(result.Success);
 }
        public void SendPasswordResetLinkWithInvalidEmailShouldReturnFalse()
        {
            var mock = new AccountServiceMock();

            mock.UserManagerMock.Setup(u => u.GetId("Test")).Returns(new Guid());
            var result = mock.AccountService.SendPasswordResetLink("Test");

            Assert.IsFalse(result.Success);
        }
        public void ChangePasswordWithInvalidResetKeyAndNoOldPasswordShouldReturnFalse()
        {
            var mock     = new AccountServiceMock();
            var userId   = Guid.NewGuid();
            var resetKey = Guid.NewGuid();

            mock.UserManagerMock.Setup(u => u.Get("Test")).Returns(new User(userId, "Test", "Test"));
            var result = mock.AccountService.ChangePassword("Test", null, "New", Guid.NewGuid());

            Assert.IsFalse(result.Success);
        }
 public void RegisterAccountWithAutoApproveOnShouldCreateNewAccountAndSendCorrectMail()
 {
     var mock = new AccountServiceMock();
     var userId = Guid.NewGuid();
     var user = new User(userId, "Test", "Test");
     user.PreferredCulture = "en";
     mock.UserManagerMock.Setup(m => m.Create("Test", "Test", "en", It.IsAny<string>(), false, true, It.IsAny<string>())).Returns(user);
     mock.MailerMock.Setup(m => m.SendApprovedAccountMail("en", "Test", "Test", It.IsAny<Guid>())).Returns(true);
     var result = mock.AccountService.RegisterAccount(new RegisterViewModel { Name = "Test", Email = "Test", AcceptedTerms = true });
     Assert.IsTrue(result.Success);
     Assert.IsNull(result.Message);
     mock.UserManagerMock.Verify(m => m.Create("Test", "Test", "en", It.IsAny<string>(), false, true, It.IsAny<string>()), Times.Once());
     mock.SecurityManagerMock.Verify(s => s.SetVerificationId(userId, It.IsAny<Guid>()), Times.Once());
     mock.MailerMock.Verify(s => s.SendApprovedAccountMail("en", "Test", "Test", It.IsAny<Guid>()), Times.Once());
     mock.RoleManagerMock.Verify(r => r.AddUserToRole(MembershipTestData.MainGroupId, user.Id, PlatformConstants.USERROLE, null, null), Times.Once());
     mock.DataSourceMock.Verify(m => m.SaveChanges(), Times.Exactly(2));
 }
 public void ChangePasswordWithValidResetKeyAndNoOldPasswordShouldChangePasswordAndSendMail()
 {
     var mock = new AccountServiceMock();
     var userId = Guid.NewGuid();
     var resetKey = Guid.NewGuid();
     var user = new User(userId, "Test", "Test");
     user.PreferredCulture = "en";
     mock.UserManagerMock.Setup(u => u.Get("Test")).Returns(user);
     mock.SecurityManagerMock.Setup(s => s.ChangePassword(userId, null, "New", resetKey)).Returns(true);
     mock.MailerMock.Setup(m => m.SendPasswordSetMail("en", "Test", "Test")).Returns(true);
     var result = mock.AccountService.ChangePassword("Test", null, "New", resetKey);
     Assert.IsTrue(result.Success);
     Assert.IsNull(result.Message);
     mock.DataSourceMock.Verify(m => m.SaveChanges(), Times.Once());
     mock.SecurityManagerMock.Verify(s => s.ChangePassword(userId, null, "New", resetKey), Times.Once());
     mock.MailerMock.Verify(m => m.SendPasswordSetMail("en", "Test", "Test"), Times.Once());
 }
        public void ChangePasswordWithValidResetKeyAndNoOldPasswordShouldChangePasswordAndSendMail()
        {
            var mock     = new AccountServiceMock();
            var userId   = Guid.NewGuid();
            var resetKey = Guid.NewGuid();
            var user     = new User(userId, "Test", "Test");

            user.PreferredCulture = "en";
            mock.UserManagerMock.Setup(u => u.Get("Test")).Returns(user);
            mock.SecurityManagerMock.Setup(s => s.ChangePassword(userId, null, "New", resetKey)).Returns(true);
            mock.MailerMock.Setup(m => m.SendPasswordSetMail("en", "Test", "Test")).Returns(true);
            var result = mock.AccountService.ChangePassword("Test", null, "New", resetKey);

            Assert.IsTrue(result.Success);
            Assert.IsNull(result.Message);
            mock.DataSourceMock.Verify(m => m.SaveChanges(), Times.Once());
            mock.SecurityManagerMock.Verify(s => s.ChangePassword(userId, null, "New", resetKey), Times.Once());
            mock.MailerMock.Verify(m => m.SendPasswordSetMail("en", "Test", "Test"), Times.Once());
        }
        public void SendPasswordResetLinkWithValidEmailShouldSetVerificationIdAndSendMail()
        {
            var mock           = new AccountServiceMock();
            var userId         = Guid.NewGuid();
            var verificationId = Guid.NewGuid();
            var user           = new User(userId, "Test", "Test");

            user.PreferredCulture = "en";
            mock.UserManagerMock.Setup(u => u.GetId("Test")).Returns(user.Id);
            mock.UserManagerMock.Setup(u => u.Get(user.Id)).Returns(user);
            mock.MailerMock.Setup(m => m.SendSetPasswordMail("en", "Test", "Test", It.IsAny <Guid>())).Returns(true);
            var result = mock.AccountService.SendPasswordResetLink("Test");

            Assert.IsTrue(result.Success);
            Assert.IsNull(result.Message);
            mock.DataSourceMock.Verify(m => m.SaveChanges(), Times.Once());
            mock.SecurityManagerMock.Verify(s => s.SetVerificationId(userId, It.IsAny <Guid>()), Times.Once());
            mock.MailerMock.Verify(m => m.SendSetPasswordMail("en", "Test", "Test", It.IsAny <Guid>()), Times.Once());
        }
        public void UpdateAccountByUserHimselfShouldUpdateEmailAndNotSendEmailChangedMail()
        {
            var mock   = new AccountServiceMock();
            var userId = Guid.NewGuid();

            _userContextMock.Setup(m => m.Id).Returns(userId);
            mock.UserManagerMock.Setup(m => m.Update(userId, "Test", "New", "en")).Returns(new User(userId, "Test", "New"));
            mock.UserManagerMock.Setup(m => m.GetEmail(userId)).Returns("Test");
            mock.SecurityManagerMock.Setup(s => s.ValidateUser(userId, "Test")).Returns(ValidateUserResult.Valid);
            mock.MailerMock.Setup(m => m.SendEmailChangedMail("en", "Test", "New", "Test")).Returns(true);
            var result = mock.AccountService.UpdateAccount(new UserViewModel {
                Id = userId, Name = "Test", Email = "New", PreferredCulture = "en", Password = "******"
            });

            _userContextMock.Setup(m => m.Id).Returns(Guid.NewGuid());
            Assert.IsTrue(result.Success);
            mock.UserManagerMock.Verify(m => m.Update(userId, "Test", "New", "en"), Times.Once());
            mock.DataSourceMock.Verify(m => m.SaveChanges(), Times.Once());
            mock.MailerMock.Verify(m => m.SendEmailChangedMail("en", "Test", "New", "Test"), Times.Never());
        }
        public void RegisterAccountWithAutoApproveOnShouldCreateNewAccountAndSendCorrectMail()
        {
            var mock   = new AccountServiceMock();
            var userId = Guid.NewGuid();
            var user   = new User(userId, "Test", "Test");

            user.PreferredCulture = "en";
            mock.UserManagerMock.Setup(m => m.Create("Test", "Test", "en", It.IsAny <string>(), false, true, It.IsAny <string>())).Returns(user);
            mock.MailerMock.Setup(m => m.SendApprovedAccountMail("en", "Test", "Test", It.IsAny <Guid>())).Returns(true);
            var result = mock.AccountService.RegisterAccount(new RegisterViewModel {
                Name = "Test", Email = "Test", AcceptedTerms = true
            });

            Assert.IsTrue(result.Success);
            Assert.IsNull(result.Message);
            mock.UserManagerMock.Verify(m => m.Create("Test", "Test", "en", It.IsAny <string>(), false, true, It.IsAny <string>()), Times.Once());
            mock.SecurityManagerMock.Verify(s => s.SetVerificationId(userId, It.IsAny <Guid>()), Times.Once());
            mock.MailerMock.Verify(s => s.SendApprovedAccountMail("en", "Test", "Test", It.IsAny <Guid>()), Times.Once());
            mock.RoleManagerMock.Verify(r => r.AddUserToRole(MembershipTestData.MainGroupId, user.Id, PlatformConstants.USERROLE, null, null), Times.Once());
            mock.DataSourceMock.Verify(m => m.SaveChanges(), Times.Exactly(2));
        }
 public void UpdateAccountByUserHimselfShouldUpdateEmailAndNotSendEmailChangedMail()
 {
     var mock = new AccountServiceMock();
     var userId = Guid.NewGuid();
     _userContextMock.Setup(m => m.Id).Returns(userId);
     mock.UserManagerMock.Setup(m => m.Update(userId, "Test", "New", "en")).Returns(new User(userId, "Test", "New"));
     mock.UserManagerMock.Setup(m => m.GetEmail(userId)).Returns("Test");
     mock.SecurityManagerMock.Setup(s => s.ValidateUser(userId, "Test")).Returns(ValidateUserResult.Valid);
     mock.MailerMock.Setup(m => m.SendEmailChangedMail("en", "Test", "New", "Test")).Returns(true);
     var result = mock.AccountService.UpdateAccount(new UserViewModel { Id = userId, Name = "Test", Email = "New", PreferredCulture = "en", Password = "******" });
     _userContextMock.Setup(m => m.Id).Returns(Guid.NewGuid());
     Assert.IsTrue(result.Success);
     mock.UserManagerMock.Verify(m => m.Update(userId, "Test", "New", "en"), Times.Once());
     mock.DataSourceMock.Verify(m => m.SaveChanges(), Times.Once());
     mock.MailerMock.Verify(m => m.SendEmailChangedMail("en", "Test", "New", "Test"), Times.Never());
 }
 public void SendPasswordResetLinkWithValidEmailShouldSetVerificationIdAndSendMail()
 {
     var mock = new AccountServiceMock();
     var userId = Guid.NewGuid();
     var verificationId = Guid.NewGuid();
     var user = new User(userId, "Test", "Test");
     user.PreferredCulture = "en";
     mock.UserManagerMock.Setup(u => u.GetId("Test")).Returns(user.Id);
     mock.UserManagerMock.Setup(u => u.Get(user.Id)).Returns(user);
     mock.MailerMock.Setup(m => m.SendSetPasswordMail("en", "Test", "Test", It.IsAny<Guid>())).Returns(true);
     var result = mock.AccountService.SendPasswordResetLink("Test");
     Assert.IsTrue(result.Success);
     Assert.IsNull(result.Message);
     mock.DataSourceMock.Verify(m => m.SaveChanges(), Times.Once());
     mock.SecurityManagerMock.Verify(s => s.SetVerificationId(userId, It.IsAny<Guid>()), Times.Once());
     mock.MailerMock.Verify(m => m.SendSetPasswordMail("en", "Test", "Test", It.IsAny<Guid>()), Times.Once());
 }
 public void SendPasswordResetLinkWithInvalidEmailShouldReturnFalse()
 {
     var mock = new AccountServiceMock();
     mock.UserManagerMock.Setup(u => u.GetId("Test")).Returns(new Guid());
     var result = mock.AccountService.SendPasswordResetLink("Test");
     Assert.IsFalse(result.Success);
 }