Ejemplo n.º 1
0
		public User SetupDatabase(SetupVariables setupVariables, out Exception exception)
		{
			exception = null;
			try
			{
				_setupRepository.SetupDatabase();
			}
			catch (Exception exc)
			{
				exception = exc;
				return null;
			}

			var settings = _settingsManager.Current;
			settings.ForumTitle = setupVariables.ForumTitle;
			settings.SmtpServer = setupVariables.SmtpServer;
			settings.SmtpPort = setupVariables.SmtpPort;
			settings.MailerAddress = setupVariables.MailerAddress;
			settings.UseSslSmtp = setupVariables.UseSslSmtp;
			settings.UseEsmtp = setupVariables.UseEsmtp;
			settings.SmtpUser = setupVariables.SmtpUser;
			settings.SmtpPassword = setupVariables.SmtpPassword;
			_settingsManager.SaveCurrent();

			var user = _userService.CreateUser(setupVariables.Name, setupVariables.Email, setupVariables.Password, true, "");
			user.Roles = new List<string> {PermanentRoles.Admin, PermanentRoles.Moderator};
			var profile = new Profile(user.UserID) { IsTos = true, IsSubscribed = true, TimeZone = setupVariables.ServerTimeZone, IsDaylightSaving = setupVariables.ServerDaylightSaving, ShowDetails = true };
			_profileService.Create(profile);
			var edit = new UserEdit(user, profile);
			_userService.EditUser(user, edit, false, false, null, null, "", user);
			PopForumsActivation.StartServicesIfRunningInstance();
			return user;
		}
Ejemplo n.º 2
0
		public UserEdit(User user, Profile profile)
		{
			UserID = user.UserID;
			Name = user.Name;
			Email = user.Email;
			IsApproved = user.IsApproved;
			IsSubscribed = profile.IsSubscribed;
			Signature = profile.Signature;
			ShowDetails = profile.ShowDetails;
			Location = profile.Location;
			IsPlainText = profile.IsPlainText;
			Dob = profile.Dob;
			Web = profile.Web;
			Aim = profile.Aim;
			Icq = profile.Icq;
			YahooMessenger = profile.YahooMessenger;
			Facebook = profile.Facebook;
			Twitter = profile.Twitter;
			TimeZone = profile.TimeZone;
			IsDaylightSaving = profile.IsDaylightSaving;
			HideVanity = profile.HideVanity;
			Roles = user.Roles.ToArray();
			AvatarID = profile.AvatarID;
			ImageID = profile.ImageID;
		}
Ejemplo n.º 3
0
		public void Create(Profile profile)
		{
			_sqlObjectFactory.GetConnection().Using(connection => 
				connection.Command("INSERT INTO pf_Profile (UserID, IsSubscribed, Signature, ShowDetails, Location, IsPlainText, DOB, Web, AIM, ICQ, YahooMessenger, Facebook, Twitter, IsTos, TimeZone, IsDaylightSaving, AvatarID, ImageID, HideVanity, LastPostID, Points) VALUES (@UserID, @IsSubscribed, @Signature, @ShowDetails, @Location, @IsPlainText, @DOB, @Web, @AIM, @ICQ, @YahooMessenger, @Facebook, @Twitter, @IsTos, @TimeZone, @IsDaylightSaving, @AvatarID, @ImageID, @HideVanity, @LastPostID, @Points)")
					.AddParameter("@UserID", profile.UserID)
					.AddParameter("@IsSubscribed", profile.IsSubscribed)
					.AddParameter("@Signature", profile.Signature.NullToEmpty())
					.AddParameter("@ShowDetails", profile.ShowDetails)
					.AddParameter("@Location", profile.Location.NullToEmpty())
					.AddParameter("@IsPlainText", profile.IsPlainText)
					.AddParameter("@DOB", profile.Dob.GetObjectOrDbNull())
					.AddParameter("@Web", profile.Web.NullToEmpty())
					.AddParameter("@AIM", profile.Aim.NullToEmpty())
					.AddParameter("@ICQ", profile.Icq.NullToEmpty())
					.AddParameter("@YahooMessenger", profile.YahooMessenger.NullToEmpty())
					.AddParameter("@Facebook", profile.Facebook.NullToEmpty())
					.AddParameter("@Twitter", profile.Twitter.NullToEmpty())
					.AddParameter("@IsTos", profile.IsTos)
					.AddParameter("@TimeZone", profile.TimeZone)
					.AddParameter("@IsDaylightSaving", profile.IsDaylightSaving)
					.AddParameter("@AvatarID", profile.AvatarID.GetObjectOrDbNull())
					.AddParameter("@ImageID", profile.ImageID.GetObjectOrDbNull())
					.AddParameter("@HideVanity", profile.HideVanity)
					.AddParameter("@LastPostID", profile.LastPostID.GetObjectOrDbNull())
					.AddParameter("@Points", profile.Points)
					.ExecuteNonQuery());
		}
Ejemplo n.º 4
0
		public void CreateFromProfileThrowsWithoutUserID()
		{
			var service = GetService();
			var profile = new Profile();
			Assert.Throws<Exception>(() => service.Create(profile));
			_profileRepo.Verify(p => p.Create(profile), Times.Never());
		}
Ejemplo n.º 5
0
		public void CreateFromProfileObject()
		{
			var service = GetService();
			var profile = new Profile(123) { Aim = "blah", Location = "Cleveland" };
			_profileRepo.Setup(p => p.Create(profile));
			service.Create(profile);
			_profileRepo.Verify(p => p.Create(profile), Times.Once());
		}
Ejemplo n.º 6
0
		public ClientSettings GetClientSettings(Profile profile)
		{
			var settings = new ClientSettings
			{
			    HideVanity = profile.HideVanity,
			    UsePlainText = profile.IsPlainText
			};
			return settings;
		}
Ejemplo n.º 7
0
		public void GetProfile()
		{
			var service = GetService();
			var profile = new Profile(123) { Aim = "blah", Location = "Cleveland" };
			var user = UserServiceTests.GetDummyUser("Jeff", "*****@*****.**");
			_profileRepo.Setup(p => p.GetProfile(user.UserID)).Returns(profile);
			var result = service.GetProfile(user);
			Assert.AreEqual(profile, result);
			_profileRepo.Verify(p => p.GetProfile(user.UserID), Times.Once());
		}
		public void MapPlainText()
		{
			var profile = new Profile
			              	{
			              		IsPlainText = true,
			              		HideVanity = false
			              	};
			var mapper = new ClientSettingsMapper();
			var settings = mapper.GetClientSettings(profile);
			Assert.AreEqual(profile.IsPlainText, settings.UsePlainText);
		}
		public void MapHideVanity()
		{
			var profile = new Profile
			{
				IsPlainText = false,
				HideVanity = true
			};
			var mapper = new ClientSettingsMapper();
			var settings = mapper.GetClientSettings(profile);
			Assert.AreEqual(profile.HideVanity, settings.HideVanity);
		}
Ejemplo n.º 10
0
		public void Init(Profile profile)
		{
			UtcOffset = SettingsManager.Current.ServerTimeZone;
			UsesDaylightSaving = SettingsManager.Current.ServerDaylightSaving;
			if (profile != null)
			{
				UtcOffset = profile.TimeZone;
				UsesDaylightSaving = profile.IsDaylightSaving;
			}
			_isInit = true;
		}
Ejemplo n.º 11
0
		public void GetProfileForEditParsesSig()
		{
			var service = GetService();
			var profile = new Profile(123) { Aim = "blah", Location = "Cleveland", Signature = "blah" };
			var user = UserServiceTests.GetDummyUser("Jeff", "*****@*****.**");
			_profileRepo.Setup(p => p.GetProfile(user.UserID)).Returns(profile);
			_textParsingService.Setup(t => t.ClientHtmlToForumCode("blah")).Returns("parsed");
			var result = service.GetProfileForEdit(user);
			Assert.AreEqual("parsed", result.Signature);
			_profileRepo.Verify(p => p.GetProfile(user.UserID), Times.Once());
		}
Ejemplo n.º 12
0
		public Profile Create(User user, SignupData signupData)
		{
			var profile = new Profile(user.UserID)
			              	{
			              		TimeZone = signupData.TimeZone,
			              		IsDaylightSaving = signupData.IsDaylightSaving,
			              		IsSubscribed = signupData.IsSubscribed,
			              		IsTos = signupData.IsTos
			              	};
			_profileRepository.Create(profile);
			return profile;
		}
Ejemplo n.º 13
0
		public UserEditProfile(Profile profile)
		{
			IsSubscribed = profile.IsSubscribed;
			Signature = profile.Signature;
			ShowDetails = profile.ShowDetails;
			Location = profile.Location;
			IsPlainText = profile.IsPlainText;
			Dob = profile.Dob;
			Web = profile.Web;
			Aim = profile.Aim;
			Icq = profile.Icq;
			YahooMessenger = profile.YahooMessenger;
			Facebook = profile.Facebook;
			Twitter = profile.Twitter;
			TimeZone = profile.TimeZone;
			IsDaylightSaving = profile.IsDaylightSaving;
			HideVanity = profile.HideVanity;
		}
Ejemplo n.º 14
0
		public DisplayProfile(User user, Profile profile, UserImage userImage)
		{
			UserID = user.UserID;
			Name = user.Name;
			Joined = user.CreationDate;
			Dob = profile.Dob;
			Location = profile.Location;
			Web = profile.Web;
			Aim = profile.Aim;
			YahooMessenger = profile.YahooMessenger;
			Icq = profile.Icq;
			Facebook = profile.Facebook;
			Twitter = profile.Twitter;
			AvatarID = profile.AvatarID;
			ImageID = profile.ImageID;
			ShowDetails = profile.ShowDetails;
			if (userImage != null && userImage.IsApproved)
				IsImageApproved = true;
			Points = profile.Points;
		}
Ejemplo n.º 15
0
		public void EditUserNoDeletePhoto()
		{
			var service = GetMockedUserService();
			var user = new User(1, DateTime.MinValue);
			user.Roles = new List<string>();
			var userEdit = new UserEdit();
			var returnedProfile = GetReturnedProfile(userEdit);
			returnedProfile.ImageID = 3;
			_mockProfileRepo.Setup(p => p.GetProfile(1)).Returns(returnedProfile);
			var profile = new Profile();
			_mockProfileRepo.Setup(p => p.Update(It.IsAny<Profile>())).Callback<Profile>(p => profile = p);
			service.EditUser(user, userEdit, false, false, null, null, "123", user);
			_mockProfileRepo.Verify(p => p.Update(It.IsAny<Profile>()), Times.Once());
			Assert.AreEqual(3, profile.ImageID);
		}
Ejemplo n.º 16
0
		public bool Update(Profile profile)
		{
			var success = false;
			_sqlObjectFactory.GetConnection().Using(connection => 
				success = connection.Command("UPDATE pf_Profile SET IsSubscribed = @IsSubscribed, Signature = @Signature, ShowDetails = @ShowDetails, Location = @Location, IsPlainText = @IsPlainText, DOB = @DOB, Web = @Web, AIM = @AIM, ICQ = @ICQ, YahooMessenger = @YahooMessenger, Facebook = @Facebook, Twitter = @Twitter, IsTos = @IsTos, TimeZone = @TimeZone, IsDaylightSaving = @IsDaylightSaving, AvatarID = @AvatarID, ImageID = @ImageID, HideVanity = @HideVanity, LastPostID = @LastPostID, Points = @Points WHERE UserID = @UserID")
					.AddParameter("@IsSubscribed", profile.IsSubscribed)
					.AddParameter("@Signature", profile.Signature.NullToEmpty())
					.AddParameter("@ShowDetails", profile.ShowDetails)
					.AddParameter("@Location", profile.Location.NullToEmpty())
					.AddParameter("@IsPlainText", profile.IsPlainText)
					.AddParameter("@DOB", profile.Dob.GetObjectOrDbNull())
					.AddParameter("@Web", profile.Web.NullToEmpty())
					.AddParameter("@AIM", profile.Aim.NullToEmpty())
					.AddParameter("@ICQ", profile.Icq.NullToEmpty())
					.AddParameter("@YahooMessenger", profile.YahooMessenger.NullToEmpty())
					.AddParameter("@Facebook", profile.Facebook.NullToEmpty())
					.AddParameter("@Twitter", profile.Twitter.NullToEmpty())
					.AddParameter("@IsTos", profile.IsTos)
					.AddParameter("@TimeZone", profile.TimeZone)
					.AddParameter("@IsDaylightSaving", profile.IsDaylightSaving)
					.AddParameter("@AvatarID", profile.AvatarID.GetObjectOrDbNull())
					.AddParameter("@ImageID", profile.ImageID.GetObjectOrDbNull())
					.AddParameter("@HideVanity", profile.HideVanity)
					.AddParameter("@LastPostID", profile.LastPostID.GetObjectOrDbNull())
					.AddParameter("@Points", profile.Points)
					.AddParameter("@UserID", profile.UserID)
					.ExecuteNonQuery() == 1);
			_cacheHelper.RemoveCacheObject(CacheKeys.UserProfile(profile.UserID));
			return success;
		}
Ejemplo n.º 17
0
		public void UpdateTrimsSig()
		{
			var service = GetService();
			var profile = new Profile(123) { Aim = "blah", Location = "Cleveland", Signature = " " };
			var trimProfile = new Profile { Signature = "no"};
			_profileRepo.Setup(p => p.Update(It.IsAny<Profile>())).Returns(true).Callback<Profile>(p => trimProfile = p);
			service.Update(profile);
			Assert.AreEqual("", trimProfile.Signature);
		}
Ejemplo n.º 18
0
		public void UpdateThrowsWithNoProfile()
		{
			var service = GetService();
			var profile = new Profile(123) { Aim = "blah", Location = "Cleveland", Signature = "" };
			_profileRepo.Setup(p => p.Update(profile)).Returns(false);
			Assert.Throws<Exception>(() => service.Update(profile));
			_profileRepo.Verify(p => p.Update(profile), Times.Once());
		}
Ejemplo n.º 19
0
		public void ClientSettingsFromMapperWithUser()
		{
			var controller = GetController();
			var context = new HttpContextHelper();
			controller.ControllerContext = new ControllerContext(context.MockContext.Object, new RouteData(), controller);
			var user = UserTest.GetTestUser();
			controller.SetUser(user);
			var profile = new Profile();
			_profileService.Setup(p => p.GetProfile(user)).Returns(profile);
			controller.ClientSettings();
			_clientSettingsMapper.Verify(c => c.GetClientSettings(profile), Times.Exactly(1));
		}
Ejemplo n.º 20
0
		public void ManagePhotosView()
		{
			var controller = GetController();
			var contextHelper = new HttpContextHelper();
			controller.ControllerContext = new ControllerContext(contextHelper.MockContext.Object, new RouteData(), controller);
			var user = UserTest.GetTestUser();
			controller.SetUser(user);
			var profile = new Profile(user.UserID);
			_profileService.Setup(p => p.GetProfile(user)).Returns(profile);
			var result = controller.ManagePhotos();
			Assert.IsInstanceOf<UserEditPhoto>(result.ViewData.Model);
			Assert.AreNotEqual("EditAccountNoUser", result.ViewName);
			_profileService.Verify(p => p.GetProfile(user), Times.Once());
		}
Ejemplo n.º 21
0
		public void UserIDSet()
		{
			const int id = 123;
			var profile = new Profile(id);
			Assert.AreEqual(id, profile.UserID);
		}
Ejemplo n.º 22
0
		public void Update(Profile profile)
		{
			profile.Signature = profile.Signature.Trim();
			if (!_profileRepository.Update(profile))
				throw new Exception(String.Format("Profile with UserID {0} does not exist.", profile.UserID));
		}
Ejemplo n.º 23
0
		public void UserEditPhotosNoDeletePhoto()
		{
			var service = GetMockedUserService();
			var user = new User(1, DateTime.MinValue);
			var userEdit = new UserEdit();
			var returnedProfile = GetReturnedProfile(userEdit);
			returnedProfile.ImageID = 3;
			_mockProfileRepo.Setup(p => p.GetProfile(1)).Returns(returnedProfile);
			var profile = new Profile();
			_mockProfileRepo.Setup(p => p.Update(It.IsAny<Profile>())).Callback<Profile>(p => profile = p);
			service.EditUserProfileImages(user, false, false, null, null);
			_mockProfileRepo.Verify(p => p.Update(It.IsAny<Profile>()), Times.Once());
			_mockUserImageRepo.Verify(u => u.DeleteImagesByUserID(user.UserID), Times.Never());
			Assert.AreEqual(3, profile.ImageID);
		}
Ejemplo n.º 24
0
		public void Create(Profile profile)
		{
			if (profile.UserID == 0)
				throw new Exception("Can't create a profile not associated with a valid UserID");
			_profileRepository.Create(profile);
		}
Ejemplo n.º 25
0
		public void EditUserProfileOnly()
		{
			var service = GetMockedUserService();
			var user = new User(1, DateTime.MinValue);
			user.Roles = new List<string>();
			var userEdit = new UserEdit();
			var profile = new Profile();
			var returnedProfile = GetReturnedProfile(userEdit);
			_mockProfileRepo.Setup(p => p.GetProfile(1)).Returns(returnedProfile);
			_mockProfileRepo.Setup(p => p.Update(It.IsAny<Profile>())).Callback<Profile>(p => profile = p);

			service.EditUser(user, userEdit, false, false, null, null, "123", user);

			_mockUserRepo.Verify(u => u.ChangeEmail(It.IsAny<User>(), It.IsAny<string>()), Times.Never());
			_mockUserRepo.Verify(u => u.ChangeName(It.IsAny<User>(), It.IsAny<string>()), Times.Never());
			_mockUserRepo.Verify(u => u.SetHashedPassword(It.IsAny<User>(), It.IsAny<string>(), It.IsAny<Guid>()), Times.Never());
			_mockProfileRepo.Verify(p => p.Update(It.IsAny<Profile>()), Times.Once());
		}
Ejemplo n.º 26
0
		public void Update()
		{
			var service = GetService();
			var profile = new Profile(123) {Aim = "blah", Location = "Cleveland", Signature = ""};
			_profileRepo.Setup(p => p.Update(profile)).Returns(true);
			service.Update(profile);
			_profileRepo.Verify(p => p.Update(profile), Times.Once());
		}
Ejemplo n.º 27
0
		public void EditUserProfile()
		{
			var service = GetMockedUserService();
			var user = new User(1, DateTime.MinValue);
			user.Roles = new List<string>();
			var returnedProfile = new Profile(1);
			var profile = new Profile();
			_mockProfileRepo.Setup(p => p.GetProfile(1)).Returns(returnedProfile);
			_mockProfileRepo.Setup(p => p.Update(It.IsAny<Profile>())).Callback<Profile>(p => profile = p);
			_mockTextParser.Setup(t => t.ForumCodeToHtml(It.IsAny<string>())).Returns("parsed");
			var userEdit = new UserEditProfile
			               	{
			               		Aim = "a", Dob = new DateTime(2000,1,1), HideVanity = true, Icq = "i", IsDaylightSaving = true, IsPlainText = true, IsSubscribed = true, Location = "l", Facebook = "fb", Twitter = "tw", ShowDetails = true, Signature = "s", TimeZone = -7, Web = "w", YahooMessenger = "y"
			               	};
			service.EditUserProfile(user, userEdit);
			_mockProfileRepo.Verify(p => p.Update(It.IsAny<Profile>()), Times.Once());
			Assert.AreEqual("a", profile.Aim);
			Assert.AreEqual(new DateTime(2000, 1, 1), profile.Dob);
			Assert.IsTrue(profile.HideVanity);
			Assert.AreEqual("i", profile.Icq);
			Assert.IsTrue(profile.IsDaylightSaving);
			Assert.IsTrue(profile.IsPlainText);
			Assert.IsTrue(profile.IsSubscribed);
			Assert.AreEqual("l", profile.Location);
			Assert.AreEqual("fb", profile.Facebook);
			Assert.AreEqual("tw", profile.Twitter);
			Assert.IsTrue(profile.ShowDetails);
			Assert.AreEqual("parsed", profile.Signature);
			Assert.AreEqual(-7, profile.TimeZone);
			Assert.AreEqual("w", profile.Web);
			Assert.AreEqual("y", profile.YahooMessenger);
		}