Ejemplo n.º 1
0
        public void GetAccessRequest_Success()
        {
            // Arrange
            var user       = PrincipalHelper.CreateForRole();
            var helper     = new TestHelper();
            var controller = helper.CreateController <AccessRequestController>(user);

            var service = helper.GetService <Mock <IPimsRepository> >();
            var mapper  = helper.GetService <IMapper>();

            var accessRequest = EntityHelper.CreateAccessRequest(1);

            service.Setup(m => m.AccessRequest.Get(It.IsAny <long>())).Returns(accessRequest);
            var model = mapper.Map <Model.AccessRequestModel>(accessRequest);

            // Act
            var result = controller.GetAccessRequest(1);

            // Assert
            var actionResult = Assert.IsType <JsonResult>(result);
            var actualResult = Assert.IsType <Model.AccessRequestModel>(actionResult.Value);

            Assert.Equal(model, actualResult, new ShallowPropertyCompare());
            Assert.Equal(model.RoleId, actualResult.RoleId, new DeepPropertyCompare());
            Assert.Equal(model.User.Id, actualResult.User.Id);
            service.Verify(m => m.AccessRequest.Get(1), Times.Once());
        }
Ejemplo n.º 2
0
        public async void UpdateAccessRequestAsync_Success()
        {
            // Arrange
            var helper     = new TestHelper();
            var controller = helper.CreateController <UserController>(Permissions.AdminUsers);

            var mapper        = helper.GetService <IMapper>();
            var service       = helper.GetService <Mock <IPimsKeycloakService> >();
            var accessRequest = EntityHelper.CreateAccessRequest();

            service.Setup(m => m.UpdateAccessRequestAsync(It.IsAny <Entity.AccessRequest>())).Returns(Task.FromResult(accessRequest));
            var model = mapper.Map <Model.AccessRequestModel>(accessRequest);

            // Act
            var result = await controller.UpdateAccessRequestAsync(model);

            // Assert
            var actionResult = Assert.IsType <JsonResult>(result);

            Assert.Null(actionResult.StatusCode);
            var actualResult   = Assert.IsType <Model.AccessRequestModel>(actionResult.Value);
            var expectedResult = mapper.Map <Model.AccessRequestModel>(accessRequest);

            Assert.Equal(expectedResult, actualResult, new DeepPropertyCompare());
            service.Verify(m => m.UpdateAccessRequestAsync(It.IsAny <Entity.AccessRequest>()), Times.Once());
        }
Ejemplo n.º 3
0
        public void GetAccessRequests_PageMax_Success()
        {
            // Arrange
            var helper     = new TestHelper();
            var controller = helper.CreateController <AccessRequestController>(Permissions.AdminUsers);

            var mapper         = helper.GetService <IMapper>();
            var service        = helper.GetService <Mock <IPimsAdminService> >();
            var accessRequest1 = EntityHelper.CreateAccessRequest(1);
            var accessRequest2 = EntityHelper.CreateAccessRequest(2);
            var accessRequests = new[] { accessRequest1, accessRequest2 };
            var paged          = new Entity.Models.Paged <Entity.AccessRequest>(accessRequests);

            service.Setup(m => m.User.GetAccessRequests(It.IsAny <AccessRequestFilter>())).Returns(paged);

            // Act
            var result = controller.GetPage(2, 100);

            // Assert
            var actionResult = Assert.IsType <JsonResult>(result);

            Assert.Null(actionResult.StatusCode);
            var actualResult = Assert.IsType <PageModel <Model.AccessRequestModel> >(actionResult.Value);

            Assert.Equal(mapper.Map <Model.AccessRequestModel[]>(accessRequests), actualResult.Items, new DeepPropertyCompare());
            service.Verify(m => m.User.GetAccessRequests(It.IsAny <AccessRequestFilter>()), Times.Once());
        }
Ejemplo n.º 4
0
        public async void AddAccessRequest_Success()
        {
            // Arrange
            var user       = PrincipalHelper.CreateForRole();
            var helper     = new TestHelper();
            var controller = helper.CreateController <UserController>(user);

            var service = helper.GetService <Mock <IPimsService> >();
            var mapper  = helper.GetService <IMapper>();

            service.Setup(m => m.User.AddAccessRequest(It.IsAny <Entity.AccessRequest>()));

            var accessRequest = EntityHelper.CreateAccessRequest();
            var model         = mapper.Map <Model.AccessRequestModel>(accessRequest);

            // Act
            var result = await controller.AddAccessRequestAsync(model);

            // Assert
            var actionResult = Assert.IsType <CreatedAtActionResult>(result);
            var actualResult = Assert.IsType <Model.AccessRequestModel>(actionResult.Value);

            Assert.Equal(model, actualResult, new ShallowPropertyCompare());
            Assert.Equal(model.Agencies, actualResult.Agencies, new DeepPropertyCompare());
            Assert.Equal(model.Roles, actualResult.Roles, new DeepPropertyCompare());
            Assert.Equal(model.User.Id, actualResult.User.Id);
            service.Verify(m => m.User.AddAccessRequest(It.IsAny <Entity.AccessRequest>()), Times.Once());
        }
Ejemplo n.º 5
0
        public void AccessRequestRole_Role_Constructor_ArgumentNullException()
        {
            // Arrange
            var accessRequest = EntityHelper.CreateAccessRequest(5);

            // Act
            // Assert
            Assert.Throws <ArgumentNullException>(() => new AccessRequestRole(accessRequest, null));
        }
Ejemplo n.º 6
0
        public void AccessRequestRole_Id_Constructor()
        {
            // Arrange
            var accessRequest = EntityHelper.CreateAccessRequest(5);
            var role          = EntityHelper.CreateRole("role");

            // Act
            var accessRequestAgency = new AccessRequestRole(accessRequest.Id, role.Id);

            // Assert
            accessRequestAgency.AccessRequestId.Should().Be(accessRequest.Id);
            accessRequestAgency.RoleId.Should().Be(role.Id);
        }
Ejemplo n.º 7
0
        public void AccessRequestOrganization_Id_Constructor()
        {
            // Arrange
            var accessRequest = EntityHelper.CreateAccessRequest(5);
            var organization  = EntityHelper.CreateOrganization(2, "ORG");

            // Act
            var accessRequestOrganization = new PimsAccessRequestOrganization(accessRequest.AccessRequestId, organization.Id);

            // Assert
            accessRequestOrganization.AccessRequestId.Should().Be(accessRequest.AccessRequestId);
            accessRequestOrganization.OrganizationId.Should().Be(organization.Id);
        }
Ejemplo n.º 8
0
        public void AccessRequestAgency_Id_Constructor()
        {
            // Arrange
            var accessRequest = EntityHelper.CreateAccessRequest(5);
            var agency        = EntityHelper.CreateAgency(2);

            // Act
            var accessRequestAgency = new AccessRequestAgency(accessRequest.Id, agency.Id);

            // Assert
            accessRequestAgency.AccessRequestId.Should().Be(accessRequest.Id);
            accessRequestAgency.AgencyId.Should().Be(agency.Id);
        }