public void ValidateUserUserIsLockedOut() { const string userName = "******"; var user = new MembershipUser { UserName = userName, IsLockedOut = true }; var membershipRepository = Substitute.For<IMembershipRepository>(); membershipRepository.GetUser(user.UserName).Returns(user); var settingsRepository = Substitute.For<ISettingsRepository>(); var emailService = Substitute.For<IEmailService>(); var localisationService = Substitute.For<ILocalizationService>(); var membershipService = new MembershipService(membershipRepository, settingsRepository, emailService, localisationService, _activityService, _privateMessageService, _membershipUserPointsService, _topicNotificationService, _voteService, _badgeService, _categoryNotificationService, _api, _loggingService); var status = membershipService.ValidateUser(userName, "password", 1); Assert.IsFalse(status); Assert.AreEqual(membershipService.LastLoginStatus, LoginAttemptStatus.UserLockedOut); }
public void BeforeUserRegisteredCancel() { var membershipRepository = Substitute.For<IMembershipRepository>(); var settingsRepository = Substitute.For<ISettingsRepository>(); var emailService = Substitute.For<IEmailService>(); var localisationService = Substitute.For<ILocalizationService>(); var membershipService = new MembershipService(membershipRepository, settingsRepository, emailService, localisationService, _activityService, _privateMessageService, _membershipUserPointsService, _topicNotificationService, _voteService, _badgeService, _categoryNotificationService, _api, _loggingService); EventManager.Instance.BeforeRegisterUser += EventManagerInstance_BeforeRegisterUserCancel; var newUser = new MembershipUser { UserName = "******", Password = "******" }; membershipRepository.GetUser(newUser.UserName).Returns(x => null); membershipService.CreateUser(newUser); membershipRepository.DidNotReceive().Add(Arg.Is<MembershipUser>(x => x.UserName == "SpongeBob")); EventManager.Instance.BeforeRegisterUser -= EventManagerInstance_BeforeRegisterUserCancel; }
public void ExportUsers() { var membershipRepository = Substitute.For<IMembershipRepository>(); var usersFromDb = new List<MembershipUser> { new MembershipUser { UserName = "******", Email = "*****@*****.**", CreateDate = DateTime.Parse("02/04/2011 17:30"), Age = 18, Location = "henry location", Website = "www.henry.com", Facebook = "facebook", Signature = "signature" }, new MembershipUser { UserName = "******", Email = "*****@*****.**", CreateDate = DateTime.Parse("02/04/2011 17:30"), Age = 45, Location = "alison location", Website = "www.alison.com", Facebook = "facebook", Signature = "signature" } }; membershipRepository.GetAll().Returns(x => usersFromDb); var settingsRepository = Substitute.For<ISettingsRepository>(); var emailService = Substitute.For<IEmailService>(); var localisationService = Substitute.For<ILocalizationService>(); var membershipService = new MembershipService(membershipRepository, settingsRepository, emailService, localisationService, _activityService, _privateMessageService, _membershipUserPointsService, _topicNotificationService, _voteService, _badgeService, _categoryNotificationService, _api, _loggingService); var export = membershipService.ToCsv(); Assert.AreEqual(export, "Henry,[email protected],02/04/2011 17:30:00,18,henry location,www.henry.com,facebook,signature\r\nAlison,[email protected],02/04/2011 17:30:00,45,alison location,www.alison.com,facebook,signature\r\n"); }
public void BeforeUserRegisteredAllow() { var membershipRepository = Substitute.For<IMembershipRepository>(); var settingsRepository = Substitute.For<ISettingsRepository>(); settingsRepository.GetSettings().Returns(new Settings { NewMemberStartingRole = new MembershipRole{RoleName = "Test"} }); var emailService = Substitute.For<IEmailService>(); var localisationService = Substitute.For<ILocalizationService>(); var membershipService = new MembershipService(membershipRepository, settingsRepository, emailService, localisationService, _activityService, _privateMessageService, _membershipUserPointsService, _topicNotificationService, _voteService, _badgeService, _categoryNotificationService, _api, _loggingService); EventManager.Instance.BeforeRegisterUser += EventManagerInstance_BeforeRegisterUserAllow; var newUser = new MembershipUser { UserName = "******", Password = "******" }; membershipRepository.GetUser(newUser.UserName).Returns(x => null); membershipService.CreateUser(newUser); membershipRepository.Received().Add(Arg.Is<MembershipUser>(x => x.UserName == "SpongeBob")); Assert.AreEqual(newUser.Email, TestString); EventManager.Instance.BeforeRegisterUser -= EventManagerInstance_BeforeRegisterUserAllow; }
public void AfterUpdateProfile() { var membershipRepository = Substitute.For<IMembershipRepository>(); var settingsRepository = Substitute.For<ISettingsRepository>(); var emailService = Substitute.For<IEmailService>(); var localisationService = Substitute.For<ILocalizationService>(); var membershipService = new MembershipService(membershipRepository, settingsRepository, emailService, localisationService, _activityService, _privateMessageService, _membershipUserPointsService, _topicNotificationService, _voteService, _badgeService, _categoryNotificationService, _api, _loggingService); var user = new MembershipUser {UserName = "******"}; EventManager.Instance.AfterUpdateProfile += eventsService_AfterUpdateProfile; membershipService.ProfileUpdated(user); Assert.AreEqual(user.Email, TestString); EventManager.Instance.AfterUpdateProfile -= eventsService_AfterUpdateProfile; }
public void BeforeUpdateProfileCancel() { var membershipRepository = Substitute.For<IMembershipRepository>(); var settingsRepository = Substitute.For<ISettingsRepository>(); var emailService = Substitute.For<IEmailService>(); var localisationService = Substitute.For<ILocalizationService>(); var membershipService = new MembershipService(membershipRepository, settingsRepository, emailService, localisationService, _activityService, _privateMessageService, _membershipUserPointsService, _topicNotificationService, _voteService, _badgeService, _categoryNotificationService, _api, _loggingService); var user = new MembershipUser { UserName = "******" }; EventManager.Instance.BeforeUpdateProfile += eventsService_BeforeUpdateProfileCancel; membershipService.ProfileUpdated(user); membershipRepository.DidNotReceive().Update(Arg.Is<MembershipUser>(x => x.UserName == "SpongeBob")); EventManager.Instance.BeforeUpdateProfile -= eventsService_BeforeUpdateProfileCancel; }
public void ImportSingleUserInsufficientValues() { var membershipRepository = Substitute.For<IMembershipRepository>(); membershipRepository.GetUser("Henry").Returns(x => null); var settingsRepository = Substitute.For<ISettingsRepository>(); var emailService = Substitute.For<IEmailService>(); var localisationService = Substitute.For<ILocalizationService>(); var testData = new List<string> { "Henry", }; var membershipService = new MembershipService(membershipRepository, settingsRepository, emailService, localisationService, _activityService, _privateMessageService, _membershipUserPointsService, _topicNotificationService, _voteService, _badgeService, _categoryNotificationService, _api, _loggingService); var report = membershipService.FromCsv(testData); Assert.IsTrue(report.Errors.Count == 1 && report.Errors[0].ErrorWarningType == CsvErrorWarningType.MissingKeyOrValue && report.Warnings.Count == 0); }
public void ImportSingleUser() { var membershipRepository = Substitute.For<IMembershipRepository>(); membershipRepository.GetUser("Henry").Returns(x => null); var settingsRepository = Substitute.For<ISettingsRepository>(); var emailService = Substitute.For<IEmailService>(); var localisationService = Substitute.For<ILocalizationService>(); var testData = new List<string> { "Henry,[email protected],02/04/2011 17:30,18,henry location,www.henry.com,facebook,signature", }; var membershipService = new MembershipService(membershipRepository, settingsRepository, emailService, localisationService, _activityService, _privateMessageService, _membershipUserPointsService, _topicNotificationService, _voteService, _badgeService, _categoryNotificationService, _api, _loggingService); var report = membershipService.FromCsv(testData); Assert.IsTrue(report.Errors.Count == 0 && report.Warnings.Count == 0); }
public void ValidateUserMaxFailedPasswordAttemptMaxExceeded() { const string userName = "******"; const int passwordAttempts = 1; var user = new MembershipUser { UserName = userName, IsApproved = true, Password = "******", FailedPasswordAttemptCount = passwordAttempts, PasswordSalt = "aaaa" }; var membershipRepository = Substitute.For<IMembershipRepository>(); membershipRepository.GetUser(user.UserName).Returns(user); var settingsRepository = Substitute.For<ISettingsRepository>(); var emailService = Substitute.For<IEmailService>(); var localisationService = Substitute.For<ILocalizationService>(); var membershipService = new MembershipService(membershipRepository, settingsRepository, emailService, localisationService, _activityService, _privateMessageService, _membershipUserPointsService, _topicNotificationService, _voteService, _badgeService, _categoryNotificationService, _api, _loggingService); var status = membershipService.ValidateUser(userName, "password", 2); Assert.IsFalse(status); Assert.IsTrue(user.IsLockedOut); Assert.AreEqual(membershipService.LastLoginStatus, LoginAttemptStatus.PasswordIncorrect); Assert.AreEqual(user.FailedPasswordAttemptCount, passwordAttempts + 1); }
public void ImportUserExists() { var membershipRepository = Substitute.For<IMembershipRepository>(); membershipRepository.GetUser("Henry").Returns(x => new MembershipUser{UserName="******"}); membershipRepository.GetUser("Alison").Returns(x => null); var settingsRepository = Substitute.For<ISettingsRepository>(); var emailService = Substitute.For<IEmailService>(); var localisationService = Substitute.For<ILocalizationService>(); var testData = new List<string> { "Henry,[email protected],02/04/2011 17:30,18,henry location,,,signature", "Alison,[email protected],02/04/2011 17:30,18,henry location,,,signature" }; var membershipService = new MembershipService(membershipRepository, settingsRepository, emailService, localisationService, _activityService, _privateMessageService, _membershipUserPointsService, _topicNotificationService, _voteService, _badgeService, _categoryNotificationService, _api, _loggingService); var report = membershipService.FromCsv(testData); // Second user ok membershipRepository.Received().Add(Arg.Is<MembershipUser>(x => x.UserName == "Alison" && x.Email == "*****@*****.**" && x.Age == 18 && x.Location == "henry location" && x.Website == string.Empty && x.Facebook == string.Empty && x.Signature == "signature")); // First user failed Assert.IsTrue(report.Errors.Count == 1 && report.Errors[0].ErrorWarningType == CsvErrorWarningType.AlreadyExists && report.Warnings.Count == 0); }
public void ImportUserExceptionThrown() { var membershipRepository = Substitute.For<IMembershipRepository>(); membershipRepository.GetUser("Henry").Returns(x => null); membershipRepository.GetUser("Alison").Returns(x => null); membershipRepository.When(x => x.Add(Arg.Any<MembershipUser>())).Do(x => { throw new Exception(); }); var settingsRepository = Substitute.For<ISettingsRepository>(); var emailService = Substitute.For<IEmailService>(); var localisationService = Substitute.For<ILocalizationService>(); var testData = new List<string> { "Henry,[email protected],02/04/2011 17:30,18,henry location,,,signature", "Alison,[email protected],02/04/2011 17:30,18,henry location,,,signature" }; var membershipService = new MembershipService(membershipRepository, settingsRepository, emailService, localisationService, _activityService, _privateMessageService, _membershipUserPointsService, _topicNotificationService, _voteService, _badgeService, _categoryNotificationService, _api, _loggingService); var report = membershipService.FromCsv(testData); // Second user still processed (but will fail) - checks code does not break out of loop membershipRepository.Received().Add(Arg.Is<MembershipUser>(x => x.UserName == "Alison" && x.Email == "*****@*****.**" && x.Age == 18 && x.Location == "henry location" && x.Website == string.Empty && x.Facebook == string.Empty && x.Signature == "signature")); Assert.IsTrue(report.Errors.Count == 2 && report.Errors[0].ErrorWarningType == CsvErrorWarningType.GeneralError && report.Warnings.Count == 0); }