Esempio n. 1
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();
		}
Esempio n. 2
0
		public LicensesViewModel GetLicensesViewModel(ICollection<License> licenses)
		{
			var licensesViewModel = new LicensesViewModel();
			licensesViewModel.LicenseItems = new List<LicenseItemViewModel>();

			foreach (var license in licenses)
			{
				var licenseItemViewModel = new LicenseItemViewModel();
				licenseItemViewModel.File = new LicenseItemFileViewModel();

				licenseItemViewModel.Id = license.Id.ToString();
				licenseItemViewModel.Number = license.LicenseNumber;
				licenseItemViewModel.ExpirationDate = license.ExpirationDate;
				licenseItemViewModel.State = _refManager.GetAllStates()[license.State];
				licenseItemViewModel.Status = license.Status;
				licenseItemViewModel.CHUMSId = license.AppraiserId;
				licenseItemViewModel.FHARoster = license.FHARoster;
				licenseItemViewModel.LicenseType = license.LicenseType;
				if (license.LicenseFiles != null)
				{
					var licenseFile = license.LicenseFiles.OrderByDescending(lf => lf.Uploaded).FirstOrDefault(lf => !lf.IsDeleted);
					if (licenseFile != null)
					{
						licenseItemViewModel.File.LicenseId = license.Id.ToString();
						licenseItemViewModel.File.FileId = licenseFile.FileId;
						var documentInfo = _documentService.GetDocumentInfo(licenseFile.FileId);
						licenseItemViewModel.File.Name = documentInfo.Name;
						var user = _usersManager.GetById(documentInfo.AddedByUserId.Value);
						licenseItemViewModel.File.UploadedByUserEmail = user.Email;
						licenseItemViewModel.File.Uploaded = documentInfo.DateAdded;
					}
				}
				licensesViewModel.LicenseItems.Add(licenseItemViewModel);
			}
			return licensesViewModel;
		}
Esempio n. 3
0
		private bool IsLicenseValid(LicenseItemViewModel license, AppraiserUserLicensesViewModel viewModel)
		{
			DateTime? expirationDate;
			int? licenseType;

			license.Status = _ascGovLicenseService.ValidateLicense(license.Number, license.StateId, out expirationDate, out licenseType);
			var result = _hudService.CheckFHARoster(license.Number);

			license.CHUMSId = result.CHUMSId;
			license.FHARoster = result.FHARoster;
			if (license.Status == LicenseStatus.Rejected)
			{
				license.AlertMessage = Constants.ErrorMessages.LicenseInvalid;
			}

			if (_appraiserUserService.IsLicenseUniqForUser(User.Identity.Name, viewModel.EditUserId, license))
			{
				license.Status = LicenseStatus.Rejected;
				license.AlertMessage = Constants.ErrorMessages.LicenseDuplicate;
			}

			license.IsEditable = (license.Status == LicenseStatus.Rejected);
			license.ExpirationDate = expirationDate;
			if (licenseType.HasValue)
				license.LicenseType = SafeConvert.ToEnum<LicenseType>(licenseType).Value;

			return string.IsNullOrEmpty(license.AlertMessage);
		}
Esempio n. 4
0
		public void LicenseManager_SaveLicense_Should_save_license()
		{
			//arrange
			var date = DateTime.Now;
			var license = new LicenseItemViewModel()
			{
				Id = "1",
				Number = "one",
				State = "LA",
				Status = LicenseStatus.Active,
				ExpirationDate = date
			};
			var user = new AppraiserUser()
			{
				Licenses=new List<License>()
			};
			user.Licenses.Count.Should().Be(0);
			//act
			_target.SaveLicense(user, license);
			//assert
			user.Licenses.Count.Should().Be(1);
			user.Licenses.Where(l => l.LicenseNumber == license.Number && l.State == license.State && l.Status == LicenseStatus.Active && l.ExpirationDate == date).Count().Should().Be(1);		
		}
Esempio n. 5
0
		public void AppraiserWizard_IsLicenseValid_should_set_IsEditable_true_if_license_state_is_Rejected()
		{
			string itemToEditID = Guid.NewGuid().ToString();

			var model = new AppraiserUserLicensesViewModel();
			LicenseItemViewModel itemToSave = new LicenseItemViewModel() { Id = itemToEditID };
			itemToSave.Number = "testNumber";
			itemToSave.Status = LicenseStatus.Active;
			DateTime? outDatetime;
			int? outLicenseType;
			AscGovLicenseService.ValidateLicense(Arg.Any<string>(), Arg.Any<string>(), out outDatetime, out outLicenseType).Returns(LicenseStatus.Rejected);
			model.Licenses.LicenseItems.Add(itemToSave);
			//act
			var act = Target.LicenseSave(model, itemToEditID);
			//assert
			itemToSave.IsEditable.Should().BeTrue();
		}
Esempio n. 6
0
		public void AppraiserWizard_IsLicenseValid_should_populate_alert_message_if_license_not_uniq_for_user()
		{
			string itemToEditID = Guid.NewGuid().ToString();

			var model = new AppraiserUserLicensesViewModel();
			LicenseItemViewModel itemToSave = new LicenseItemViewModel() { Id = itemToEditID };
			itemToSave.IsEditable = true;
			itemToSave.Number = "testNumber";
			itemToSave.Status = LicenseStatus.Active;
			DateTime? outDatetime;
			int? outLicenseType;
			AscGovLicenseService.ValidateLicense(Arg.Any<string>(), Arg.Any<string>(), out outDatetime, out outLicenseType).Returns(LicenseStatus.Expired);
			AppraiserUserService.IsLicenseUniqForUser(Arg.Any<string>(), Arg.Any<int?>(), Arg.Any<LicenseItemViewModel>()).Returns(true);
			model.Licenses.LicenseItems.Add(itemToSave);
			//act
			var act = Target.LicenseSave(model, itemToEditID);
			//assert
			itemToSave.Status.Should().Be(LicenseStatus.Rejected);
			itemToSave.AlertMessage.Should().NotBeNullOrEmpty().And.Contain("Specified license");
		}
Esempio n. 7
0
		public void AppraiserWizard_License_Save_should_populate_notification_license_updated_to_viewBag_if_new_item_saved()
		{
			string itemToEditID = "123";

			var model = new AppraiserUserLicensesViewModel();
			LicenseItemViewModel itemToSave = new LicenseItemViewModel() { Id = itemToEditID };
			itemToSave.Number = "testNumber";
			itemToSave.Status = LicenseStatus.Expired;
			DateTime? outDatetime;
			int? outLicenseType;
			AscGovLicenseService.ValidateLicense(Arg.Any<string>(), Arg.Any<string>(), out outDatetime, out outLicenseType).Returns(LicenseStatus.Active);
			AppraiserUserService.IsLicenseUniqForUser(Arg.Any<string>(), Arg.Any<int?>(), Arg.Any<LicenseItemViewModel>()).Returns(false);
			AppraiserUserService.GetAppraiserLicenses(Arg.Any<string>(), Arg.Any<int?>()).Returns(model);
			model.Licenses.LicenseItems.Add(itemToSave);
			//act
			var act = Target.LicenseSave(model, itemToEditID);
			//assert
			itemToSave.Status.Should().NotBe(LicenseStatus.Expired);
			string notificationMessage = Target.ViewBag.NotificationMessage;
			notificationMessage.Should().NotBeNullOrEmpty();
			notificationMessage.Should().BeEquivalentTo(Constants.Notifications.LicenseUpdated);

		}
Esempio n. 8
0
		public void AppraiserWizard_License_Edit_should_change_status_for_edit_item()
		{
			string itemToEditID = Guid.NewGuid().ToString();

			var model = new AppraiserUserLicensesViewModel();
			LicenseItemViewModel itemToEdit = new LicenseItemViewModel() { Id = itemToEditID };
			DateTime? outDatetime;
			int? outLicenseType;
			AscGovLicenseService.ValidateLicense(Arg.Any<string>(), Arg.Any<string>(), out outDatetime, out outLicenseType).Returns(LicenseStatus.Rejected);

			model.Licenses.LicenseItems.Add(itemToEdit);
			//act
			var act = Target.LicenseEdit(model, itemToEditID);
			//assert
			itemToEdit.IsEditable.Should().BeTrue();
		}
Esempio n. 9
0
		public void AppraiserWizard_License_Edit_should_validate_current_editing_item()
		{
			string itemToEditID = Guid.NewGuid().ToString();

			var model = new AppraiserUserLicensesViewModel();
			LicenseItemViewModel editingItem = new LicenseItemViewModel();
			LicenseItemViewModel itemToEdit = new LicenseItemViewModel() { Id = itemToEditID };
			editingItem.IsEditable = true;
			editingItem.Number = "testNumber";
			editingItem.Status = LicenseStatus.Active;
			DateTime? outDatetime;
			int? outLicenseType;
			AscGovLicenseService.ValidateLicense(Arg.Any<string>(), Arg.Any<string>(), out outDatetime, out outLicenseType).Returns(LicenseStatus.Rejected);

			model.Licenses.LicenseItems.Add(editingItem);
			model.Licenses.LicenseItems.Add(itemToEdit);
			//act
			var act = Target.LicenseEdit(model, itemToEditID);
			//assert
			editingItem.Status.Should().NotBe(LicenseStatus.Active);
		}
Esempio n. 10
0
		public void SaveLicense(AppraiserUser userAppraiser, LicenseItemViewModel currentLicense)
		{
			if (userAppraiser == null)
			{
				throw new ArgumentNullException("appraiser user");
			}
			if (currentLicense == null)
			{
				throw new ArgumentNullException("licenseItemViewModel");
			}
			if (!_refManager.GetAllStates().ContainsKey(currentLicense.StateId))
			{
				throw new ArgumentOutOfRangeException("unknow license state: " + currentLicense.StateId);
			}

			var license = userAppraiser.Licenses.SingleOrDefault(e => e.Id.ToString() == currentLicense.Id);
			if (license == null)
			{
				license = new License();
				userAppraiser.Licenses.Add(license);
			}

			license.LicenseNumber = currentLicense.Number;
			license.ExpirationDate = currentLicense.ExpirationDate.Value;
			license.State = currentLicense.StateId;
			license.Status = currentLicense.Status;
			license.AppraiserId = currentLicense.CHUMSId;
			license.FHARoster = currentLicense.FHARoster;
			license.LicenseType = currentLicense.LicenseType;
		}