Ejemplo n.º 1
0
		public void GetContactInfo_should_throw_UnauthorizedAccessException_if_current_user_is_dvs_user()
		{
			var user = new User() { Roles = new List<Role>(new Role[] { new Role() { Id = (int)RoleType.DvsSuperAdmin } }) };
			_securityContext.CurrentUser.Returns(user);

			_target.Invoking(a => a.GetContactInfo(Arg.Any<int>())).ShouldThrow<UnauthorizedAccessException>();
		}
Ejemplo n.º 2
0
		public void CreateUser(User user, string password)
		{
			string salt = Guid.NewGuid().ToString().Replace("-", string.Empty);
			user.Salt = salt;
			user.PasswordHash = PasswordHelper.EncodePassword(user.Salt, password, MembershipPasswordFormat.Hashed);
			CreateUser(user);
		}
Ejemplo n.º 3
0
		public void AppraiserManagement_GetById_Should_return_entity()
		{
			//Arrange
			var user = new User()
			{
				Email = "*****@*****.**",
				FirstName = "TheBest",
				LastName = "NameEver"
			};
			var expected = new AppraiserUser()
			{
				User = user,
				Id = 1,
				Status = AppraiserUserStatus.Active
			};
			AppraiserUserRepository.GetByUserId(1).Returns(expected);
			//Act
			var actual = Target.GetById(1);
			//Assert
			actual.User.Email.Should().Be(expected.User.Email);
			actual.User.FirstName.Should().Be(expected.User.FirstName);
			actual.User.LastName.Should().Be(expected.User.LastName);
			actual.Id.Should().Be(expected.Id);
			actual.Status.Should().Be(expected.Status);
		}
Ejemplo n.º 4
0
		public void DVSUserManager_GetDvsUserByEmail_Should_return_entity()
		{
			//arrange
			var user = new User()
			{
				Email = "*****@*****.**",
				FirstName = "TheBest",
				LastName = "NameEver"
			};
			var expected = new DvsUser()
			{
				User = user,
				Id = 1,
				Status = DvsUserStatus.Active
			};
			_dvsUserRepository.GetByUserId(user.Id).Returns(expected);
			//act
			var actual = _target.GetDvsUserByUserId(expected.User.Id);
			//assert
			actual.User.Email.Should().Be(expected.User.Email);
			actual.User.FirstName.Should().Be(expected.User.FirstName);
			actual.User.LastName.Should().Be(expected.User.LastName);
			actual.Id.Should().Be(expected.Id);
			actual.Status.Should().Be(expected.Status);
		}
		public void SaveNote_should_save_note()
		{
			var clientCompany = new ClientCompany();
			var user = new User();
			var text = string.Empty;
			_target.SaveNote(clientCompany, user, text);
		}
Ejemplo n.º 6
0
		private void InitCurrentUser(User user, AppraiserUser appraiserUser)
		{
			appraiserUser.User = user;

			SecurityContext.CurrentUser.Returns(user);
			CurrentAppraiser.CurrentAppraiser.Returns(appraiserUser);
		}
Ejemplo n.º 7
0
		public void GetContactInfo_should_throw_UnauthorizedAccessException_if_order_is_inaccessible_for_appraiser_user()
		{
			var user = new User() { Id = 0, Roles = new List<Role>(new Role[] { new Role() { Id = (int)RoleType.Appraiser } }) };
			_securityContext.CurrentUser.Returns(user);
			_appraiserOrderRepository.GetById(Arg.Any<int>()).ReturnsForAnyArgs(new AppraiserOrder() { AppraiserUser = new AppraiserUser() { User = new User() { Id = 1 } } });

			_target.Invoking(a => a.GetContactInfo(Arg.Any<int>())).ShouldThrow<UnauthorizedAccessException>();
		}
Ejemplo n.º 8
0
		private void ApplySecurityRules(IEnumerable<AppraiserUser> results, User curentUser)
		{
			if (curentUser.PrimaryRole.RoleType == RoleType.AppraisalCompanyAdmin ||
			curentUser.PrimaryRole.RoleType == RoleType.CompanyAdminAndAppraiser)
			{
				var appraiserUser = _appraiserManagement.GetByEmail(curentUser.Email);
				results = results.Where(r => r.Company != null && string.Equals(r.Company.CompanyName, appraiserUser.Company.CompanyName));
			}
		}
Ejemplo n.º 9
0
		public void GetContactInfo_should_throw_UnauthorizedAccessException_if_order_is_inaccessible_for_client_user()
		{
			var user = new User() { Id = 0, Roles = new List<Role>(new Role[] { new Role() { Id = (int)RoleType.SuperUser } }) };
			_securityContext.CurrentUser.Returns(user);
			_orderRepository.GetById(Arg.Any<int>()).ReturnsForAnyArgs(new Order() { OrderStatus = OrderStatus.PendingAssignment });
			_clientManager.GetByEmail(Arg.Any<string>()).ReturnsForAnyArgs(new ClientUser() { User = user });
			Expression<Func<Order, bool>> accessCondition = o => false;
			_clientDashboardService.HasClientUserAccessToOrder(Arg.Any<ClientUser>()).ReturnsForAnyArgs(accessCondition);

			_target.Invoking(a => a.GetContactInfo(Arg.Any<int>())).ShouldThrow<UnauthorizedAccessException>();
		}
Ejemplo n.º 10
0
		public void SaveNote(ClientCompany clientCompany, User user, string text)
		{
			var note = new ClientCompanyAdminNote
			           	{
			           		Company = clientCompany, 
										Text = text, 
										User = user, 
										Date = DateTime.Now
			           	};
			_clientCompanyAdminNotesRepository.Add(note);
		}
Ejemplo n.º 11
0
		public void CheckAndCreateUser(User user, string password)
		{
			if (user == null)
				throw new ArgumentNullException("user");
			if (string.IsNullOrEmpty(password))
				throw new ArgumentNullException(password);

			if (_userRepository.ExistsUser(user.Email))
				throw new Exception(string.Format("User with email {0} already exists", user.Email));
			CreateUser(user, password);
		}
Ejemplo n.º 12
0
    public void CreateAppraiserUser(SignUpAppraiserViewModel signUpAppraiser)
    {
      User user = new User();
      user.DateCreated = DateTime.Now;
      user.Email = signUpAppraiser.Email;
      user.FirstName = signUpAppraiser.FirstName;
      user.LastName = signUpAppraiser.LastName;
      user.Roles = new Role[] { _referenceManagement.GetRoleWithoutCache(RoleType.Appraiser) };

      _appraiserManager.CheckAndCreateAppraiserUser(user, signUpAppraiser.Password);
    }
Ejemplo n.º 13
0
    private User CreateUser(int i)
    {
      User user = new User()
      {
        Id = i,
        IsActivated = true,
        Email = string.Format("{0}@mail.com", i.ToString()),
        FirstName = i.ToString(),
        LastName = i.ToString(),
        
      };
      user.Roles = new Role[] { new Role() { Id = (int)RoleType.DvsAdmin, DisplayName = RoleType.DvsAdmin.ToString() } };

      return user;
    }
Ejemplo n.º 14
0
		public void CreateCompanyWithAppraisalCompanyAdminUser_should_create_AppraisalCompanyViewModel_and_populate_it()
		{
			var user = new User();
			UsersManagement.CreateUser(Arg.Any<UserViewModel>(), Arg.Any<RoleType>()).Returns(user);

			string companyName = "TestCompany";
			AppraisalCompanySignUpViewModel appraisalCompanySignUpViewModel = new AppraisalCompanySignUpViewModel() { LocationState = "CA, California" };
			appraisalCompanySignUpViewModel.CompanyName = companyName;
			AppraisalCompanyDetail companyDetails = new AppraisalCompanyDetail();
			AppraisalCompanyManagement.CreateAppraisalCompany(Arg.Any<AppraisalCompanyProfileViewModel>()).Returns(companyDetails);

			//act
			Target.CreateCompanyWithAppraisalCompanyAdminUser(appraisalCompanySignUpViewModel);
			AppraisalCompanyManagement.Received().CreateAppraisalCompany(Arg.Is<AppraisalCompanyProfileViewModel>(ac =>
				string.Equals(ac.CompanyName, companyName)));
		}
Ejemplo n.º 15
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;
		}
Ejemplo n.º 16
0
		public void UserRepositoryTest_Delete()
		{
			//arrange
			User user = new User()
			{
				LastName = "user",
				FirstName = "user",
				Email = "*****@*****.**",
			};
			user.Roles = new List<Role>() { _referenceRepository.GetRole(RoleType.DvsSuperAdmin) };			
			_repository.Add(user);
			SaveChanges();
			//act
			_repository.Delete(user.Id);
			SaveChanges();			
			var dbEntry = _repository.GetById(user.Id);
			//assert
			dbEntry.Should().BeNull();
		}
Ejemplo n.º 17
0
		public void UserRepositoryTest_Add()
		{
			//arrange
			User user = new User()
			{
				LastName = "user",
				FirstName = "user",
				Email = "*****@*****.**",
			};
			user.Roles = new Role[] { _referenceRepository.GetRole(RoleType.DvsSuperAdmin) };
			//act
			_repository.Add(user);
			SaveChanges();
			//assert
			_repository.Get().Where(e => e.Id == user.Id).Single().Id.Should().Be(user.Id);
			_repository.Get().Where(e => e.Id == user.Id).Single().GetType().Should().Be(typeof(User));
			_repository.Get().Where(e => e.Id == user.Id).Single().Roles.Should().HaveCount(1);
			_repository.Get().Where(e => e.Id == user.Id).Single().Roles.Single().RoleType.Should().Be(RoleType.DvsSuperAdmin);
		}
Ejemplo n.º 18
0
		public void DVSUserManager_Create_User_two_param_Should_should_pass_parameters_to_repository()
		{
			//arrange
			var user = new User()
			{
				Email = "*****@*****.**",
				FirstName = "TheBest",
				LastName = "NameEver"
			};
			var expected = new DvsUser()
			{
				User = user,
				Id = 1,
				Status = DvsUserStatus.Active
			};			
			//act
			_target.CreateDvsUser(expected, "pwd");
			//assert
			_dvsUserRepository.Received().Add(expected);
		}
Ejemplo n.º 19
0
		public void GetNotesByCompanyId_should_get_list_of_ClientCompanyAdminNoteViewModel()
		{
			var companyId = string.Empty;
			var noteId = Arg.Any<int>();
			var company = new ClientCompany { CompanyId = companyId };
			var date = DateTime.Today;
			var user = new User();
			var notets = new[]
			{
			  new ClientCompanyAdminNote
			  {
					Id = noteId,
					Company = company,
					Date = date,
					User = user,
 					Text = string.Empty
			  }
			};
			_clientCompanyAdminNotesRepository.GetNotesByCompanyId(companyId).Returns(notets);
			_target.GetNotesByCompanyId(companyId);
		}
Ejemplo n.º 20
0
		public void ChangeTrackingTest_Add()
		{
			string firstName = Guid.NewGuid().ToString();

			User user = new User()
			{
				IsActivated = true,
				Email = "*****@*****.**",
				FirstName = firstName,
				LastName = "TestLastName1",
			};
			user.Roles = new Role[] { DVSContext.Roles.Find((int)RoleType.DvsSuperAdmin) };

			DVSContext.Users.Add(user);
			DVSContext.SaveChanges();

			var changeField = DVSContext.ChangeFields.SingleOrDefault(e => e.NewValue == firstName && e.OldValue == null && e.FieldName == "FirstName");
			changeField.Should().NotBeNull();
			changeField.ChangeEntity.EntityName.Should().Be("User");
			changeField.ChangeEntity.KeyValue.Should().NotBe(0);
			changeField.ChangeEntity.ChangeAction.Should().Be(ChangeAction.Added);
		}
Ejemplo n.º 21
0
		public void LicenseManagerTest_SaveNewLicenseForAppraiser()
		{
			string userEmail = "*****@*****.**";
			User testUser = new User() {
				FirstName = "John",
				LastName = "Doe",
 				Email = userEmail,
				IsPasswordClear = true,
				Roles = new Role[] { new Role() { Id = (int)RoleType.Appraiser, DisplayName = "Appraiser" } }
			};
			AppraiserUser userAppraiser = new AppraiserUser() {
				User = testUser,
				StatusId = SafeConvert.ToString(AppraiserUserStatus.Active),
				Licenses = new List<License>()
			};
			this.DVSContext.AppraiserUsers.Add(userAppraiser);
			this.DVSContext.SaveChanges();
			AppraiserUser testAppraiser = this.DVSContext.AppraiserUsers.SingleOrDefault(u => u.User.Email == userEmail);

			LicenseItemViewModel currentLicense = new LicenseItemViewModel() {
				Id = Guid.NewGuid().ToString(),
				Number = "1234",
				ExpirationDate = DateTime.Now.AddMonths(2),
				State = "KS",
				Status = LicenseStatus.Active,
				CHUMSId = "111111",
				FHARoster = true,
				LicenseType = null
			};

			Target.SaveLicense(testAppraiser, currentLicense);
			Action act = () => this.DVSContext.SaveChanges();
			act.ShouldNotThrow();

			AppraiserUser testAppraiserWithLicenses = this.DVSContext.AppraiserUsers.SingleOrDefault(u => u.User.Email == userEmail);
			testAppraiserWithLicenses.Licenses.Should().HaveCount(1);
			License license = testAppraiserWithLicenses.Licenses.Single();
			license.LicenseType.Should().BeNull();
		}
Ejemplo n.º 22
0
		private IEnumerable<HotList> GenerateCurrentAppraiserWithinOrder(User user, params AppraiserOrder[] orders)
		{
			var result = new List<HotList>();

			InitCurrentUser(user, new AppraiserUser { Id = 123 });

			foreach (var appraiserOrder in orders)
			{
				var resultItem = new HotList();

				resultItem.AppraiserOrder = appraiserOrder;
				resultItem.AppraiserUser = CurrentAppraiser.CurrentAppraiser;
				resultItem.AppraiserId = CurrentAppraiser.CurrentAppraiser.Id;
				resultItem.Order = appraiserOrder.Order ?? new Order { PropertyAddress = new Address() };
				resultItem.OrderCreated = resultItem.AppraiserOrder.CreatedDate;
				resultItem.OrderNumber = resultItem.Order.OrderPublicId;
				resultItem.OrderStatus = resultItem.AppraiserOrder.AppraiserOrderStatusId;
				resultItem.PropertyAddress = resultItem.Order.PropertyAddress;

				result.Add(resultItem);
			}

			return result;
		}
Ejemplo n.º 23
0
		public void CreateUser(User user)
		{
			_userRepository.Add(user);
		}
Ejemplo n.º 24
0
		public bool GetIsExpiredPassword(User user)
		{
			var passwordChangeInterval = _referenceManagement.GetConfigParam(ConfigType.PasswordChangeInterval);

			if (user.DatePasswordChange.AddDays(passwordChangeInterval) < DateTime.Now && passwordChangeInterval != 0)
				return true;
			else return false;
		}
Ejemplo n.º 25
0
		public void Update(User user)
		{
			if (user == null)
				throw new ArgumentNullException("user");
			_userRepository.Update(user);
		}
Ejemplo n.º 26
0
		private void FillContuctUsModel(ContactUsViewModel model, User user)
		{
			model.Name = user.FullName;
			model.Email = user.Email;

			Phone userPhone = null;
			var appraiser = _appraiserManagement.GetByEmail(user.Email);

			if (appraiser == null)
			{
				userPhone = GetUserPhone(user.Phones);
			}
			else
			{
				if (appraiser.ContactInfo != null)
				{
					userPhone = GetUserPhone(appraiser.ContactInfo.Phones);
				}
				if (appraiser.Company != null)
				{
					model.CompanyName = appraiser.Company.CompanyName;
					model.HasCompany = true;
				}
			}
			model.PhoneNumber = userPhone != null ? userPhone.Number : string.Empty;
		}
Ejemplo n.º 27
0
		public void UserRepositoryTest_GetById()
		{
			//arrange
			User user = new User()
			{
				LastName = "Smoking",
				FirstName = "Kills",
				Email = "*****@*****.**",
			};
			user.Roles = new Role[] { _referenceRepository.GetRole(RoleType.DvsSuperAdmin) };
			_repository.Add(user);
			SaveChanges();
			//act
			var dbEntry = _repository.GetById(user.Id);
			//assert
			dbEntry.LastName.Should().Be("Smoking");
			dbEntry.FirstName.Should().Be("Kills");
			dbEntry.Email.Should().Be("*****@*****.**");
		}
Ejemplo n.º 28
0
		public AppraiserUser CheckAndCreateAppraiserUser(User user, string password)
		{
			return CheckAndCreateAppraiserUser(user, password, AppraiserUserStatus.Applied);
		}
Ejemplo n.º 29
0
		public AppraiserUser CheckAndCreateAppraiserUser(User user, string password, AppraiserUserStatus defaultStatus)
		{
			if (user == null)
				throw new ArgumentNullException("user");
			if (string.IsNullOrEmpty(password))
				throw new ArgumentNullException("password");

			string salt = Guid.NewGuid().ToString().Replace("-", "");
			user.Salt = salt;
			user.PasswordHash = PasswordHelper.EncodePassword(user.Salt, password, MembershipPasswordFormat.Hashed);

			if (GetByEmail(user.Email) != null)
				throw new ArgumentException("AppraiserUserDetails already exists for user ", user.Email);
			AppraiserUser appraiserUser = new AppraiserUser();
			appraiserUser.User = user;
			appraiserUser.Status = defaultStatus;
			SetInitialScore(appraiserUser);
			CreateUser(appraiserUser);
			return appraiserUser;
		}
Ejemplo n.º 30
0
		public void UserRepositoryTest_UserPreferences()
		{
			//arrange
			User user = new User()
			{
				LastName = "user",
				FirstName = "user",
				Email = "*****@*****.**",
				UserPreferences = new List<UserPreference>()
			};
			user.Roles = new Role[] { _referenceRepository.GetRole(RoleType.DvsSuperAdmin) };
			_repository.Add(user);
			SaveChanges();

			var dbEntry = _repository.GetByEmail("*****@*****.**");
			dbEntry.UserPreferences.Should().NotBeNull();
			dbEntry.UserPreferences.Should().HaveCount(0);

			dbEntry.UserPreferences.Add(new UserPreference() { Key = UserPreferenceType.LastCompletedAppriserSignUpStep, Value = "somevalue" });		

			_repository.Update(dbEntry);
			SaveChanges();		

			var updatedUser = (new UserRepository(this.DbFactory)).GetById(dbEntry.Id);

			updatedUser.UserPreferences.Where(e => e.Key == UserPreferenceType.LastCompletedAppriserSignUpStep).Should().HaveCount(1);
			updatedUser.UserPreferences.Where(e => e.Key == UserPreferenceType.LastCompletedAppriserSignUpStep).Single().Value.Should().Be("somevalue");
		}