Example #1
0
		public void Createuser_should_throw_exceptions_if_any_parameter_is_null()
		{
			UserViewModel userViewModel = new UserViewModel();
			//act
			Target.Invoking(um => um.CreateUser(null, RoleType.DvsSuperAdmin)).ShouldThrow<ArgumentNullException>().And.ParamName.Should().Contain("UserViewModel");
			Target.Invoking(um => um.CreateUser(new UserViewModel(), RoleType.DvsSuperAdmin)).ShouldThrow<ArgumentNullException>().And.ParamName.Should().Contain("Email");
			Target.Invoking(um => um.CreateUser(new UserViewModel() { Email = "email" }, RoleType.DvsSuperAdmin)).ShouldThrow<ArgumentNullException>().And.ParamName.Should().Contain("password");
		}
Example #2
0
		public User CreateUser(UserViewModel userViewModel, RoleType userRole, bool isActivated = true)
		{
			if (userViewModel == null)
				throw new ArgumentNullException("UserViewModel cannot be null");
			if (string.IsNullOrWhiteSpace(userViewModel.Email))
				throw new ArgumentNullException("User Email cannot be null or blank");
			if (string.IsNullOrWhiteSpace(userViewModel.Password))
				throw new ArgumentNullException("User password cannot be null or blank");

			User dbUser = new User();
			dbUser.FirstName = userViewModel.FirstName;
			dbUser.LastName = userViewModel.LastName;
			dbUser.IsActivated = isActivated;
			dbUser.Roles = new Role[] { _referenceManagement.GetRoleWithoutCache(userRole) };
			dbUser.Email = userViewModel.Email;
			CreateUser(dbUser, userViewModel.Password);

			return dbUser;
		}
Example #3
0
		public void Createuser_should_populate_data_to_corresponding_fields_()
		{
			string firstName = "First Name";
			string lastName = "Last Name";
			bool isActivated = false;
			string email = "*****@*****.**";
			UserViewModel userViewModel = new UserViewModel()
			{
				Email = email,
				FirstName = firstName,
				LastName = lastName,
				Password = "******"
			};
			Target.CreateUser(userViewModel, RoleType.DvsSuperAdmin, isActivated);
			UserRepository.Received().Add(Arg.Is<User>(ur =>
					string.Equals(ur.Email, email) &&
					string.Equals(ur.FirstName, firstName) &&
					string.Equals(ur.LastName, lastName) &&
					ur.IsActivated == isActivated &&
					ur.Roles.Count == 1 &&
					ur.Roles.Contains(ReferenceManagement.GetRole(RoleType.DvsSuperAdmin))));

		}