public void When_BlogArticle_is_mapped_to_a_BlogArticleDetailsModel_then_no_data_is_retrieved_from_process_classes() { BlogProcess .Expect(process => process.GetBlogArticle(Arg <Guid> .Is.Anything)) .Repeat.Never(); BlogProcess.Replay(); UserProcess .Expect(process => process.GetUser(Arg <Guid> .Is.Anything)) .Repeat.Never(); UserProcess.Replay(); var blogArticle = BlogArticleCreator.CreateSingle(); var user = UserCreator.CreateSingle(); blogArticle.AuthorId = user.Id; var result = Mapper.MapToDetail(blogArticle, user); Assert.AreEqual(blogArticle.Id, result.Id); Assert.AreEqual(blogArticle.ModificationDate, result.ModificationDate); Assert.AreEqual(blogArticle.PublishDate, result.PublishDate); Assert.AreEqual(blogArticle.Title, result.Title); Assert.AreEqual(blogArticle.Content, result.Content); Assert.AreEqual(blogArticle.CreationDate, result.CreationDate); Assert.AreEqual(user.Login.LoginName, result.AuthorName); }
public void When_CreatUser_is_called_with_an_emailAddress_that_already_exists_then_the_MembershipCreateStatus_is_DuplicateEmail() { UserProcess .Expect(process => process.GetUserByLoginName(Arg <string> .Is.Anything)) .Return(null) .Repeat.Once(); UserProcess .Expect(process => process.GetUserByEmailAddress(Arg <string> .Is.Anything)) .Return(UserCreator.CreateSingle()) .Repeat.Once(); UserProcess.Replay(); MembershipCreateStatus createStatus; var result = CustomMembershipProvider.CreateUser( string.Empty, string.Empty, string.Empty, string.Empty, string.Empty, false, Guid.Empty, out createStatus); Assert.IsNull(result); Assert.AreEqual(MembershipCreateStatus.DuplicateEmail, createStatus); }
public void When_User_is_mapped_to_a_MembershipUser_then_the_User_is_not_retrieved_from_the_IUserProcess() { var user = UserCreator.CreateSingle(); UserProcess .Expect(process => process.GetUser(user.Id)) .Return(user) .Repeat.Never(); UserProcess.Replay(); var result = Mapper.Map(user); Assert.IsNotNull(result); Assert.IsNotNull(result.ProviderUserKey); Assert.AreEqual(user.Id, (Guid)result.ProviderUserKey); //Assert.AreEqual(user.BandId, result.BandId); Assert.AreEqual(user.Login.CreationDate, result.CreationDate.ToUniversalTime()); Assert.AreEqual(user.Login.EmailAddress, result.Email); Assert.AreEqual(user.Login.IsApproved, result.IsApproved); Assert.AreEqual(user.Login.IsLockedOut, result.IsLockedOut); Assert.AreEqual(user.Login.IsOnline, result.IsOnline); Assert.AreEqual(user.Login.LastActivityDate, result.LastActivityDate.ToUniversalTime()); Assert.AreEqual(user.Login.LastLockoutDate, result.LastLockoutDate.ToUniversalTime()); Assert.AreEqual(user.Login.LastLoginDate, result.LastLoginDate.ToUniversalTime()); Assert.AreEqual(user.Login.LastPasswordChangedDate, result.LastPasswordChangedDate.ToUniversalTime()); //Assert.AreEqual(user.ModificationDate, result.ModificationDate); //Assert.AreEqual(user.Name, result.Name); UserProcess.VerifyAllExpectations(); }
public void When_ValidateUser_is_called_with_a_valid_UserName_and_a_valid_Password_then_true_is_returned() { const string decryptedPassword = "******"; var user = UserCreator.CreateSingle(); UserProcess .Expect(process => process.GetUserByLoginName(user.Login.LoginName)) .Return(user) .Repeat.Once(); UserProcess.Replay(); CryptographyProcess .Expect(process => process.Decrypt(user.Login.Password)) .Return(decryptedPassword) .Repeat.Once(); CryptographyProcess.Replay(); var result = CustomMembershipProvider.ValidateUser(user.Login.LoginName, decryptedPassword); UserProcess.VerifyAllExpectations(); CryptographyProcess.VerifyAllExpectations(); Assert.IsTrue(result); }
public void When_ValidateUser_is_called_with_an_invalid_UserName_then_false_is_returned() { UserProcess .Expect(process => process.GetUserByLoginName(Arg <string> .Is.Anything)) .Return(null) .Repeat.Once(); UserProcess.Replay(); var result = CustomMembershipProvider.ValidateUser("userName", "password"); Assert.IsFalse(result); }
public void When_Index_is_called_GetBlogArticles_on_IBlogProcess_is_called_and_the_result_is_mapped_with_BlogArticleMapper() { var user = UserCreator.CreateSingle(); var blogArticles = BlogArticleCreator.CreateCollection(); foreach (var blogArticle in blogArticles) { blogArticle.AuthorId = user.Id; } UserProcess .Expect(process => process.GetUser(user.Id)) .Return(user) .Repeat.Once(); UserProcess.Replay(); BlogProcess .Expect(process => process.GetBlogArticles()) .Return(blogArticles) .Repeat.Once(); BlogProcess.Replay(); var blogArticleDetailsModelcollection = CreateBlogArticleDetailsModelCollection(); BlogArticleMapper .Expect(mapper => mapper.Map( Arg <IEnumerable <BlogArticle> > .Matches(articles => blogArticles.All(blogArticle => articles.Any(article => article.Id == blogArticle.Id))), Arg <IEnumerable <User> > .Matches(users => users.Any(u => u == user)))) .Return(blogArticleDetailsModelcollection) .Repeat.Once(); BlogArticleMapper.Replay(); var result = Controller.Index().Result as ViewResult; Assert.IsNotNull(result); var model = result.Model as ItemListModel <BlogArticleDetailsModel>; Assert.IsNotNull(model); UserProcess.VerifyAllExpectations(); BlogProcess.VerifyAllExpectations(); BlogArticleMapper.VerifyAllExpectations(); }
public void When_MembershipUser_is_mapped_to_a_User_then_the_User_is_retrieved_from_the_IUserProcess() { var lastActivityDate = DateTime.Now.AddMilliseconds(30); var user = UserCreator.CreateSingle(); UserProcess .Expect(process => process.GetUser(user.Id)) .Return(user) .Repeat.Once(); UserProcess.Replay(); var membershipUser = new MembershipUser( "CustomMembershipProvider", user.Login.LoginName, user.Id, user.Login.EmailAddress, "", "", true, false, user.Login.CreationDate, user.Login.LastLoginDate, lastActivityDate, user.Login.LastPasswordChangedDate, user.Login.LastLockoutDate); var result = Mapper.Map(membershipUser); Assert.IsNotNull(membershipUser.ProviderUserKey); Assert.AreEqual((Guid)membershipUser.ProviderUserKey, result.Id); //Assert.AreEqual(user.BandId, result.BandId); Assert.AreEqual(user.Login.CreationDate, result.Login.CreationDate); Assert.AreEqual(user.Login.EmailAddress, result.Login.EmailAddress); Assert.AreEqual(user.Login.IsApproved, result.Login.IsApproved); Assert.AreEqual(user.Login.IsLockedOut, result.Login.IsLockedOut); Assert.AreEqual(user.Login.IsOnline, result.Login.IsOnline); Assert.AreEqual(lastActivityDate, result.Login.LastActivityDate); Assert.AreEqual(user.Login.LastLockoutDate, result.Login.LastLockoutDate); Assert.AreEqual(user.Login.LastLoginDate, result.Login.LastLoginDate); Assert.AreEqual(user.Login.LastPasswordChangedDate, result.Login.LastPasswordChangedDate); //Assert.AreEqual(user.Login.ModificationDate, result.Login.ModificationDate); //Assert.AreEqual(user.Name, result.Name); UserProcess.VerifyAllExpectations(); }
public void When_a_list_of_BlogArticles_is_mapped_to_a_BlogArticleDetailsModels_then_no_data_is_retrieved_from_process_classes() { BlogProcess .Expect(process => process.GetBlogArticle(Arg <Guid> .Is.Anything)) .Repeat.Never(); BlogProcess.Replay(); UserProcess .Expect(process => process.GetUser(Arg <Guid> .Is.Anything)) .Repeat.Never(); UserProcess.Replay(); var blogArticles = BlogArticleCreator.CreateCollection(); var user = UserCreator.CreateSingle(); foreach (var blogArticle in blogArticles) { blogArticle.AuthorId = user.Id; } var result = Mapper.Map(blogArticles, new[] { user }); foreach (var blogarticleDetailsModel in result.Items) { Assert.AreEqual(user.Login.LoginName, blogarticleDetailsModel.AuthorName); } foreach (var blogArticle in blogArticles) { Assert.IsTrue(result.Items.Single(model => model.Id == blogArticle.Id && model.ModificationDate == blogArticle.ModificationDate && model.PublishDate == blogArticle.PublishDate && model.Title == blogArticle.Title && model.Content == blogArticle.Content && model.CreationDate == blogArticle.CreationDate) != null); } }
public void When_Details_is_called_GetBlogArticle_on_IBlogProcess_is_called_with_the_correct_parameter_and_the_result_is_mapped_with_BlogArticleMapper() { var entity = BlogArticleCreator.CreateSingle(); var author = UserCreator.CreateSingle(); entity.AuthorId = author.Id; UserProcess .Expect(process => process.GetUser(entity.AuthorId)) .Return(author) .Repeat.Once(); UserProcess.Replay(); BlogProcess .Expect(process => process.GetBlogArticle(entity.Id)) .Return(entity) .Repeat.Once(); BlogProcess.Replay(); var detailsModel = CreateBlogArticleDetailsModel(entity.Id); BlogArticleMapper .Expect(mapper => mapper.MapToDetail(entity, author)) .Return(detailsModel) .Repeat.Once(); BlogArticleMapper.Replay(); var result = Controller.Details(entity.Id).Result as ViewResult;; Assert.IsNotNull(result); BlogProcess.VerifyAllExpectations(); UserProcess.VerifyAllExpectations(); BlogArticleMapper.VerifyAllExpectations(); }
public void When_CreatUser_is_called_then_the_User_is_created_and_registered_under_the_Band_that_is_provided_by_the_BandProcess() { var band = BandCreator.CreateSingle(); var user = UserCreator.CreateSingle(); var login = user.Login; const string encryptedPassword = "******"; BandProcess .Expect(process => process.EnsureBandExists()) .Return(band) .Repeat.Once(); BandProcess.Replay(); CryptographyProcess .Expect(process => process.Encrypt(login.Password)) .Return(encryptedPassword) .Repeat.Once(); CryptographyProcess.Replay(); UserProcess .Expect(process => process.GetUserByLoginName(Arg <string> .Is.Anything)) .Return(null) .Repeat.Once(); UserProcess .Expect(process => process.GetUserByEmailAddress(Arg <string> .Is.Anything)) .Return(null) .Repeat.Once(); UserProcess .Expect(process => process.AddUser(Arg <User> .Matches(u => u.BandId == band.Id && u.Login.Password == encryptedPassword && u.Login.IsOnline && u.Login.LastLoginDate > DateTime.UtcNow.AddSeconds(-2) && u.Login.LastActivityDate > DateTime.UtcNow.AddSeconds(-2) && u.Login.LastPasswordChangedDate > DateTime.UtcNow.AddSeconds(-2)))) .Return(user) .Repeat.Once(); UserProcess.Replay(); var membershipUser = CreateMembershipUser(user); UserMapper .Expect(mapper => mapper.Map(user)) .Return(membershipUser) .Repeat.Once(); UserMapper.Replay(); MembershipCreateStatus createStatus; var result = CustomMembershipProvider.CreateUser( login.LoginName, login.Password, login.EmailAddress, string.Empty, string.Empty, login.IsApproved, login.Id, out createStatus); Assert.IsNotNull(result); Assert.IsNotNull(result.ProviderUserKey); Assert.AreEqual(user.Login.LoginName, result.UserName); Assert.AreEqual(MembershipCreateStatus.Success, createStatus); BandProcess.VerifyAllExpectations(); CryptographyProcess.VerifyAllExpectations(); UserProcess.VerifyAllExpectations(); UserMapper.VerifyAllExpectations(); }