public void GetOrganizations_Filtered_Success() { // Arrange var helper = new TestHelper(); var controller = helper.CreateController <OrganizationController>(Permissions.AdminOrganizations); var mapper = helper.GetService <IMapper>(); var service = helper.GetService <Mock <IPimsRepository> >(); var organizations = new Entity.PimsOrganization[] { EntityHelper.CreateOrganization(1, "organization1"), EntityHelper.CreateOrganization(2, "organization2") }; var paged = new Entity.Models.Paged <Entity.PimsOrganization>(organizations); service.Setup(m => m.UserOrganization.Get(It.IsAny <Entity.Models.OrganizationFilter>())).Returns(paged); var filter = new Entity.Models.OrganizationFilter(1, 10); // Act var result = controller.GetOrganizations(filter); // Assert var actionResult = Assert.IsType <JsonResult>(result); Assert.Null(actionResult.StatusCode); var actualResult = Assert.IsType <Pims.Api.Models.PageModel <Model.OrganizationModel> >(actionResult.Value); Assert.Equal(mapper.Map <Model.OrganizationModel[]>(organizations), actualResult.Items, new DeepPropertyCompare()); service.Verify(m => m.UserOrganization.Get(filter), Times.Once()); }
/// <summary> /// Create a new instance of a PropertyOrganization class. /// </summary> /// <param name="property"></param> /// <param name="organization"></param> public PimsPropertyOrganization(PimsProperty property, PimsOrganization organization):this() { this.Property = property ?? throw new ArgumentNullException(nameof(property)); this.PropertyId = property.PropertyId; this.Organization = organization ?? throw new ArgumentNullException(nameof(organization)); this.OrganizationId = organization.Id; }
/// <summary> /// Create a new instance of a UserOrganization class. /// </summary> /// <param name="user"></param> /// <param name="organization"></param> /// <param name="role"></param> public PimsUserOrganization(PimsUser user, PimsOrganization organization, PimsRole role) { this.User = user ?? throw new ArgumentNullException(nameof(user)); this.UserId = user.Id; this.Organization = organization ?? throw new ArgumentNullException(nameof(organization)); this.OrganizationId = organization.Id; this.Role = role ?? throw new ArgumentNullException(nameof(role)); this.RoleId = role.RoleId; }
/// <summary> /// Create a new instance of a AccessRequestOrganization class. /// </summary> /// <param name="accessRequest"></param> /// <param name="organization"></param> public PimsAccessRequestOrganization(PimsAccessRequest accessRequest, PimsOrganization organization) : this() { this.AccessRequest = accessRequest; this.AccessRequestId = accessRequest?.AccessRequestId ?? throw new ArgumentNullException(nameof(accessRequest)); this.Organization = organization; this.OrganizationId = organization?.OrganizationId ?? throw new ArgumentNullException(nameof(organization)); }
/// <summary> /// Create a new instance of a Parcel and add it to the database context. /// </summary> /// <param name="context"></param> /// <param name="name"></param> /// <param name="type"></param> /// <param name="identifierType"></param> /// <param name="address"></param> /// <returns></returns> public static Entity.PimsOrganization CreateOrganization(this PimsContext context, long id, string name, Entity.PimsOrganizationType type = null, Entity.PimsOrgIdentifierType identifierType = null, Entity.PimsAddress address = null) { type ??= context.PimsOrganizationTypes.FirstOrDefault() ?? throw new InvalidOperationException("Unable to find an organization type."); identifierType ??= context.PimsOrgIdentifierTypes.FirstOrDefault() ?? throw new InvalidOperationException("Unable to find an organization identifier type."); address ??= EntityHelper.CreateAddress(id); var organization = new Entity.PimsOrganization(name, type, identifierType, address) { Id = id, ConcurrencyControlNumber = 1 }; return(organization); }
/// <summary> /// Create a new instance of an AccessRequest for a default user. /// </summary> /// <param name="id"></param> /// <param name="keycloakUserId"></param> /// <param name="username"></param> /// <param name="firstName"></param> /// <param name="lastName"></param> /// <param name="person"></param> /// <param name="role"></param> /// <param name="organization"></param> /// <returns></returns> public static Entity.PimsUser CreateUser(long id, Guid keycloakUserId, string username, string firstName = "given name", string lastName = "surname", Entity.PimsRole role = null, Entity.PimsOrganization organization = null, Entity.PimsAddress address = null) { organization ??= EntityHelper.CreateOrganization(id, "Organization 1"); role ??= EntityHelper.CreateRole("Real Estate Manager"); var person = new Entity.PimsPerson(lastName, firstName, address); person.PimsContactMethods = new List <Entity.PimsContactMethod>(); var user = new Entity.PimsUser(keycloakUserId, username, person) { Id = id, IssueDate = DateTime.UtcNow, ConcurrencyControlNumber = 1 }; user.PimsUserRoles.Add(new Entity.PimsUserRole() { Role = role, RoleId = role.Id, User = user, UserId = user.Id }); user.PimsUserOrganizations.Add(new Entity.PimsUserOrganization() { Organization = organization, OrganizationId = organization.Id, User = user, UserId = user.Id }); return(user); }
/// <summary> /// Create a new instance of a Lease. /// </summary> /// <returns></returns> public static Entity.PimsLease CreateLease(int pid, string lFileNo = null, string tenantFirstName = null, string tenantLastName = null, string motiFirstName = null, string motiLastName = null, PimsAddress address = null, bool addTenant = false, bool addProperty = true, PimsLeaseProgramType pimsLeaseProgramType = null, PimsLeasePurposeType pimsLeasePurposeType = null, PimsLeaseStatusType pimsLeaseStatusType = null, PimsLeasePayRvblType pimsLeasePayRvblType = null, PimsLeaseCategoryType pimsLeaseCategoryType = null, PimsLeaseInitiatorType pimsLeaseInitiatorType = null, PimsLeaseResponsibilityType pimsLeaseResponsibilityType = null, PimsLeaseLicenseType pimsLeaseLicenseType = null, PimsRegion region = null) { var lease = new Entity.PimsLease() { LeaseId = pid, LFileNo = lFileNo, ConcurrencyControlNumber = 1, }; var person = new Entity.PimsPerson() { FirstName = tenantFirstName, Surname = tenantLastName }; person.PimsPersonAddresses.Add(new PimsPersonAddress() { Person = person, Address = address }); var organization = new Entity.PimsOrganization(); organization.PimsOrganizationAddresses.Add(new PimsOrganizationAddress() { Organization = organization, Address = address }); if (addProperty) { lease.PimsPropertyLeases.Add(new PimsPropertyLease() { Property = new Entity.PimsProperty() { Pid = pid }, Lease = lease }); } lease.MotiContact = $"{motiFirstName} {motiLastName}"; lease.LeaseProgramTypeCodeNavigation = pimsLeaseProgramType ?? new Entity.PimsLeaseProgramType() { Id = "testProgramType" }; lease.LeasePurposeTypeCodeNavigation = pimsLeasePurposeType ?? new Entity.PimsLeasePurposeType() { Id = "testPurposeType" }; lease.LeaseStatusTypeCodeNavigation = pimsLeaseStatusType ?? new Entity.PimsLeaseStatusType() { Id = "testStatusType" }; lease.LeasePayRvblTypeCodeNavigation = pimsLeasePayRvblType ?? new Entity.PimsLeasePayRvblType() { Id = "testRvblType" }; lease.LeaseCategoryTypeCodeNavigation = pimsLeaseCategoryType ?? new Entity.PimsLeaseCategoryType() { Id = "testCategoryType" }; lease.LeaseInitiatorTypeCodeNavigation = pimsLeaseInitiatorType ?? new Entity.PimsLeaseInitiatorType() { Id = "testInitiatorType" }; lease.LeaseResponsibilityTypeCodeNavigation = pimsLeaseResponsibilityType ?? new Entity.PimsLeaseResponsibilityType() { Id = "testResponsibilityType" }; lease.LeaseLicenseTypeCodeNavigation = pimsLeaseLicenseType ?? new Entity.PimsLeaseLicenseType() { Id = "testType" }; if (region != null) { lease.RegionCodeNavigation = region; } if (addTenant) { lease.PimsLeaseTenants.Add(new PimsLeaseTenant(lease, person, organization, new PimsLessorType("tst"))); } return(lease); }
/// <summary> /// Create a new instance of an AccessRequest for the specified user. /// </summary> /// <param name="id"></param> /// <param name="user"></param> /// <param name="role"></param> /// <param name="organization"></param> /// <returns></returns> public static Entity.PimsAccessRequest CreateAccessRequest(long id, Entity.PimsUser user, Entity.PimsRole role, Entity.PimsOrganization organization) { user ??= EntityHelper.CreateUser("test"); role ??= EntityHelper.CreateRole("Real Estate Manager"); var accessRequest = new Entity.PimsAccessRequest() { AccessRequestId = id, UserId = user.Id, User = user, RoleId = role.Id, Role = role }; organization ??= EntityHelper.CreateOrganization(id, "test", EntityHelper.CreateOrganizationType("Type 1"), EntityHelper.CreateOrganizationIdentifierType("Identifier 1"), EntityHelper.CreateAddress(id)); accessRequest.PimsAccessRequestOrganizations.Add(new Entity.PimsAccessRequestOrganization() { AccessRequestId = id, AccessRequest = accessRequest, OrganizationId = organization.Id, Organization = organization }); return(accessRequest); }