private TextParsingService GetService()
		{
			_mockSettingsManager = new Mock<ISettingsManager>();
			_settings = new Settings();
			_mockSettingsManager.Setup(s => s.Current).Returns(_settings);
			return new TextParsingService(_mockSettingsManager.Object);
		}
		public void CreateView()
		{
			var controller = GetController();
			var settings = new Settings();
			_settingsManager.Setup(s => s.Current).Returns(settings);
			var result = controller.Create();
			Assert.IsInstanceOf<ViewResult>(result);
		}
Exemplo n.º 3
0
		public void GetTopicsStartRowCalcd()
		{
			var forum = new Forum(1) { TopicCount = 300 };
			var topicService = GetTopicService();
			var settings = new Settings { TopicsPerPage = 20 };
			_settingsManager.Setup(s => s.Current).Returns(settings);
			PagerContext pagerContext;
			topicService.GetTopics(forum, false, 3, out pagerContext);
			_topicRepo.Verify(t => t.Get(It.IsAny<int>(), It.IsAny<bool>(), 41, It.IsAny<int>()), Times.Once());
		}
		public void GetTopicsStartRowCalcd()
		{
			var user = new User(123, DateTime.MaxValue);
			var service = GetService();
			var settings = new Settings { TopicsPerPage = 20 };
			_mockSettingsManager.Setup(s => s.Current).Returns(settings);
			PagerContext pagerContext;
			service.GetTopics(user, 3, out pagerContext);
			_mockFaveRepo.Verify(s => s.GetFavoriteTopics(user.UserID, 41, 20), Times.Once());
			pagerContext.PageSize = settings.TopicsPerPage;
		}
		public void GetTopicsFromRepo()
		{
			var user = new User(123, DateTime.MaxValue);
			var service = GetService();
			var settings = new Settings { TopicsPerPage = 20 };
			_mockSettingsManager.Setup(s => s.Current).Returns(settings);
			var list = new List<Topic>();
			_mockFaveRepo.Setup(s => s.GetFavoriteTopics(user.UserID, 1, 20)).Returns(list);
			PagerContext pagerContext;
			var result = service.GetTopics(user, 1, out pagerContext);
			Assert.AreSame(list, result);
		}
Exemplo n.º 6
0
		public void GetTopicsFromRepo()
		{
			var forum = new Forum(1) { TopicCount = 3 };
			var topicService = GetTopicService();
			var repoTopics = new List<Topic>();
			var settings = new Settings {TopicsPerPage = 20};
			_topicRepo.Setup(t => t.Get(1, true, 1, settings.TopicsPerPage)).Returns(repoTopics);
			_settingsManager.Setup(s => s.Current).Returns(settings);
			PagerContext pagerContext;
			var topics = topicService.GetTopics(forum, true, 1, out pagerContext);
			Assert.AreSame(repoTopics, topics);
		}
Exemplo n.º 7
0
		public void SendCallsSmtpWrapper()
		{
			var wrapper = new Mock<ISmtpWrapper>();
			var resultMessage = new MailMessage();
			wrapper.Setup(w => w.Send(It.IsAny<MailMessage>()))
				.Returns(SmtpStatusCode.Ok)
				.Callback<MailMessage>(msg => resultMessage = msg);
			const string mailerAddress = "*****@*****.**";
			const string forumTitle = "superawesome";
			var user = UserTest.GetTestUser();
			var settings = new Settings { MailerAddress = mailerAddress, ForumTitle = forumTitle};
			var settingsManager = new Mock<ISettingsManager>();
			settingsManager.Setup(s => s.Current).Returns(settings);
			var mailer = new NewAccountMailer(settingsManager.Object, wrapper.Object);
			var result = mailer.Send(user, "http://blah/");
			Assert.AreEqual(SmtpStatusCode.Ok, result);
			Assert.AreEqual(resultMessage.To[0].DisplayName, user.Name);
			Assert.AreEqual(resultMessage.To[0].Address, user.Email);
			Assert.AreEqual(resultMessage.From.DisplayName, forumTitle);
			Assert.AreEqual(resultMessage.From.Address, mailerAddress);
		}
Exemplo n.º 8
0
		private void LoadSettings()
		{
			var dictionary = _settingsRepository.Get();
			var settings = new Settings();
			foreach (var setting in dictionary.Keys)
			{
				var property = settings.GetType().GetProperty(setting);
				if (property == null)
				{
					_errorLog.Log(null, ErrorSeverity.Warning, String.Format("Settings repository returned a setting called {0}, which does not exist in code.", setting));
				}
				else
				{
					switch (property.PropertyType.FullName)
					{
						case "System.Boolean":
							property.SetValue(settings, Convert.ToBoolean(dictionary[setting]), null);
							break;
						case "System.String":
							property.SetValue(settings, dictionary[setting], null);
							break;
						case "System.Int32":
							property.SetValue(settings, Convert.ToInt32(dictionary[setting]), null);
							break;
						case "System.Double":
							property.SetValue(settings, Convert.ToDouble(dictionary[setting]), null);
							break;
						case "System.DateTime":
							property.SetValue(settings, Convert.ToDateTime(dictionary[setting]), null);
							break;
						default:
							throw new Exception(String.Format("Settings loader not coded to convert values of type {0}.", property.PropertyType.FullName));
					}
				}
			}
			_settings = settings;
			_lastLoad = DateTime.UtcNow;
		}
Exemplo n.º 9
0
		public void CreateUserFromSignup()
		{
			const string name = "jeff";
			const string nameCensor = "jeffcensor";
			const string email = "*****@*****.**";
			const string password = "******";
			const string ip = "127.0.0.1";
			var userManager = GetMockedUserService();
			var dummyUser = GetDummyUser(nameCensor, email);
			_mockUserRepo.Setup(r => r.CreateUser(nameCensor, email, It.IsAny<DateTime>(), true, It.IsAny<string>(), It.IsAny<Guid>(), It.IsAny<Guid>())).Returns(dummyUser);
			_mockTextParser.Setup(t => t.Censor(name)).Returns(nameCensor);
			var settings = new Settings();
			_mockSettingsManager.Setup(s => s.Current).Returns(settings);
			var signUpdata = new SignupData {Email = email, Name = name, Password = password};
			var user = userManager.CreateUser(signUpdata, ip);
			_mockUserRepo.Verify(r => r.CreateUser(nameCensor, email, It.IsAny<DateTime>(), true, It.IsAny<string>(), It.IsAny<Guid>(), It.IsAny<Guid>()), Times.Once());
			_mockSecurityLogService.Verify(s => s.CreateLogEntry(null, user, ip, String.Empty, SecurityLogType.UserCreated));
		}
Exemplo n.º 10
0
		public void CreateViewWithData()
		{
			var controller = GetController();
			const string tos = "blah blah blah";
			var settings = new Settings {TermsOfService = tos};
			_settingsManager.Setup(s => s.Current).Returns(settings);
			controller.Create();
			Assert.IsInstanceOf<String>(controller.ViewData[AccountController.CoppaDateKey]);
			Assert.IsInstanceOf<String>(controller.ViewData[AccountController.TosKey]);
			Assert.AreEqual(tos, controller.ViewData[AccountController.TosKey]);
		}
Exemplo n.º 11
0
		public void CreateNotValid()
		{
			var controller = GetController();
			var context = new HttpContextHelper();
			controller.ControllerContext = new ControllerContext(context.MockContext.Object, new RouteData(), controller);
			const string tos = "blah blah blah";
			var settings = new Settings {TermsOfService = tos};
			_settingsManager.Setup(s => s.Current).Returns(settings);
			_userService.Setup(u => u.IsEmailInUse(It.IsAny<string>())).Returns(true);
			_userService.Setup(u => u.IsNameInUse(It.IsAny<string>())).Returns(true);
			var signUp = new SignupData {Email = "*****@*****.**", IsCoppa = true, IsDaylightSaving = true, IsSubscribed = true, IsTos = true, Name = "Diana", Password = "******", PasswordRetype = "pwd", TimeZone = -5};
			var result = controller.Create(signUp).Result;
			Assert.IsFalse(controller.ModelState.IsValid);
			Assert.IsInstanceOf<ViewResult>(result);
			Assert.IsInstanceOf<String>(controller.ViewData[AccountController.CoppaDateKey]);
			Assert.IsInstanceOf<String>(controller.ViewData[AccountController.TosKey]);
			Assert.AreEqual(tos, controller.ViewData[AccountController.TosKey]);
			_userService.Verify(u => u.CreateUser(It.IsAny<SignupData>(), It.IsAny<string>()), Times.Never());
			_profileService.Verify(p => p.Create(It.IsAny<User>(), It.IsAny<SignupData>()), Times.Never());
			_newAccountMailer.Verify(n => n.Send(It.IsAny<User>(), It.IsAny<string>()), Times.Never());
		}
Exemplo n.º 12
0
		public void CreateValidNotCallExternalAuthAssociateWithoutAuthResult()
		{
			var controller = GetController();
			MockUpUrl(controller);
			_userService.Setup(u => u.IsEmailInUse(It.IsAny<string>())).Returns(false);
			_userService.Setup(u => u.IsNameInUse(It.IsAny<string>())).Returns(false);
			var user = UserServiceTests.GetDummyUser("Diana", "*****@*****.**");
			var signUp = new SignupData { Email = "*****@*****.**", IsCoppa = true, IsDaylightSaving = true, IsSubscribed = true, IsTos = true, Name = "Diana", Password = "******", PasswordRetype = "passwerd", TimeZone = -5 };
			_userService.Setup(u => u.CreateUser(signUp, It.IsAny<string>())).Returns(user);
			_newAccountMailer.Setup(n => n.Send(It.IsAny<User>(), It.IsAny<string>())).Returns(System.Net.Mail.SmtpStatusCode.CommandNotImplemented);
			var settings = new Settings { IsNewUserApproved = true };
			_settingsManager.Setup(s => s.Current).Returns(settings);
			var authManager = new Mock<IAuthenticationManager>();
			_owinContext.Setup(x => x.Authentication).Returns(authManager.Object);
			var authResult = Task.FromResult <ExternalAuthenticationResult>(null);
			_externalAuth.Setup(x => x.GetAuthenticationResult(authManager.Object)).Returns(authResult);

			var result = controller.Create(signUp).Result;

			_userAssociationManager.Verify(x => x.Associate(user, It.IsAny<ExternalAuthenticationResult>(), It.IsAny<string>()), Times.Never);
		}
Exemplo n.º 13
0
		public void CreateValid()
		{
			var controller = GetController();
			MockUpUrl(controller);
			_userService.Setup(u => u.IsEmailInUse(It.IsAny<string>())).Returns(false);
			_userService.Setup(u => u.IsNameInUse(It.IsAny<string>())).Returns(false);
			var user = UserServiceTests.GetDummyUser("Diana", "*****@*****.**");
			var signUp = new SignupData { Email = "*****@*****.**", IsCoppa = true, IsDaylightSaving = true, IsSubscribed = true, IsTos = true, Name = "Diana", Password = "******", PasswordRetype = "passwerd", TimeZone = -5 };
			_userService.Setup(u => u.CreateUser(signUp, It.IsAny<string>())).Returns(user);
			_newAccountMailer.Setup(n => n.Send(It.IsAny<User>(), It.IsAny<string>())).Returns(System.Net.Mail.SmtpStatusCode.CommandNotImplemented);
			var settings = new Settings { IsNewUserApproved = true };
			_settingsManager.Setup(s => s.Current).Returns(settings);
			var authManager = new Mock<IAuthenticationManager>();
			_owinContext.Setup(x => x.Authentication).Returns(authManager.Object);
			var authResult = Task.FromResult<ExternalAuthenticationResult>(null);
			_externalAuth.Setup(x => x.GetAuthenticationResult(It.IsAny<IAuthenticationManager>())).Returns(authResult);

			var result = controller.Create(signUp).Result;

			Assert.IsTrue(controller.ModelState.IsValid);
			Assert.AreEqual("AccountCreated", result.ViewName);
			Assert.IsTrue(result.ViewData["EmailProblem"].ToString().Contains(System.Net.Mail.SmtpStatusCode.CommandNotImplemented.ToString()));
			_userService.Verify(u => u.CreateUser(signUp, It.IsAny<string>()), Times.Once());
			_profileService.Verify(p => p.Create(user, signUp), Times.Once());
			_newAccountMailer.Verify(n => n.Send(user, It.IsAny<string>()), Times.Once());
		}
Exemplo n.º 14
0
		public void FlushCurrent()
		{
			_settings = null;
		}
		public void GetTopicsStartRowCalcd()
		{
			var user = new User(123, DateTime.MaxValue);
			var service = GetService();
			var settings = new Settings { TopicsPerPage = 20 };
			_mockSettingsManager.Setup(s => s.Current).Returns(settings);
			PagerContext pagerContext;
			service.GetTopics(user, 3, out pagerContext);
			_mockSubRepo.Verify(s => s.GetSubscribedTopics(user.UserID, 41, 20), Times.Once());
			Assert.AreEqual(20, pagerContext.PageSize);
		}
Exemplo n.º 16
0
		public void GetTopicsPagerContextIncludesPageIndexAndCalcdTotalPages()
		{
			var forum = new Forum(1) {TopicCount = 301};
			var forum2 = new Forum(2) {TopicCount = 300};
			var forum3 = new Forum(3) {TopicCount = 299};
			var topicService = GetTopicService();
			var settings = new Settings { TopicsPerPage = 20 };
			_topicRepo.Setup(t => t.Get(It.IsAny<int>(), It.IsAny<bool>(), It.IsAny<int>(), settings.TopicsPerPage)).Returns(new List<Topic>());
			_settingsManager.Setup(s => s.Current).Returns(settings);
			PagerContext pagerContext;
			topicService.GetTopics(forum, false, 3, out pagerContext);
			Assert.AreEqual(3, pagerContext.PageIndex);
			Assert.AreEqual(16, pagerContext.PageCount);
			topicService.GetTopics(forum2, false, 4, out pagerContext);
			Assert.AreEqual(4, pagerContext.PageIndex);
			Assert.AreEqual(15, pagerContext.PageCount);
			topicService.GetTopics(forum3, false, 5, out pagerContext);
			Assert.AreEqual(5, pagerContext.PageIndex);
			Assert.AreEqual(15, pagerContext.PageCount);
			Assert.AreEqual(settings.TopicsPerPage, pagerContext.PageSize);
		}