public async Task OneDepartmentPermission_ReturnsForCompany() { int unitId = 99; int departmentId = 88; int userId = 1; A.CallTo(() => PermissionService.GetImplicitByUnitType(UnitType.Master)).Returns(new List <PermissionType> { PermissionType.EndreKompetanseType }); A.CallTo(() => AuthorizationQueries.GetUnitPermissionsByUserId(A <int> .Ignored, A <int?> .Ignored, A <PermissionType[]> .Ignored)).Returns(new List <UnitPermission> { new UnitPermission { UnitId = departmentId, PermissionType = PermissionType.LesNyheter } }); A.CallTo(() => UnitQueries.GetByIdList(A <IEnumerable <int> > .Ignored)).Returns(new List <UnitWithParent> { new UnitWithParent { Id = departmentId, ParentId = unitId, Type = UnitType.Department } }); A.CallTo(() => PermissionService.GetByUnitType(UnitType.Department)).Returns(new List <PermissionType>()); A.CallTo(() => UnitQueries.GetHierarchyUp(departmentId)).Returns(new List <UnitWithParent> { new UnitWithParent { Id = unitId, ParentId = null, Type = UnitType.Company } }); var list = await AuthorizationService.GetUnitPermissions(userId, null, PermissionType.EndreKompetanseType); Assert.That(list != null && list.Count() == 2); Assert.That(list.First().PermissionType == PermissionType.EndreKompetanseType && list.First().UnitId == UnitConstants.MasterUnitId); Assert.That(list.Last().PermissionType == PermissionType.LesNyheter && list.Last().UnitId == unitId); }
public async Task NoPermissions_ReturnsImplicitMasterPermissions() { int userId = 1; A.CallTo(() => PermissionService.GetImplicitByUnitType(UnitType.Master)).Returns(new List <PermissionType> { PermissionType.EndreKompetanseType }); A.CallTo(() => AuthorizationQueries.GetUnitPermissionsByUserId(A <int> .Ignored, A <int?> .Ignored, A <PermissionType[]> .Ignored)).Returns(new List <UnitPermission>()); var list = await AuthorizationService.GetUnitPermissions(userId, null, PermissionType.EndreKompetanseType); Assert.That(list != null && list.Count() == 1); Assert.That(list.Single().PermissionType == PermissionType.EndreKompetanseType && list.Single().UnitId == UnitConstants.MasterUnitId); }