public async Task GetPermittedIds_ReturnsEntityIds() { string eId1 = "id-1", eId2 = "id-2"; var up = new UserPermissions { EntityPermissions = new[] { new EntityPermission { EntityId = eId1, EntityKey = "ek", PermissionKeys = new[] { "pk" }, }, new EntityPermission { EntityId = eId2, EntityKey = "ek", PermissionKeys = new[] { "pk" }, }, }, }; var pm = new Mock <IPermissionManager>(); pm.Setup(p => p.GetUserPermissions(It.IsAny <string>())).ReturnsAsync(up); var res = await PermissionManagerExtensions.GetPermittedIds(pm.Object, "some-user-id", "ek", "pk"); res.Count().ShouldBe(2); res.Contains(eId1); res.Contains(eId2); }
public async Task GetPermittedIds_HasUserPermissions_ReturnsEmpty(UserPermissions userPermissions) { var pm = new Mock <IPermissionManager>(); pm.Setup(p => p.GetUserPermissions(It.IsAny <string>())).ReturnsAsync(userPermissions); var res = await PermissionManagerExtensions.GetPermittedIds(pm.Object, "uId", "ek", "pk"); res.ShouldBeEmpty(); }
public async Task GetPermittedIds_NotMatch_AllConditions_ReturnsEmpty() { var up = new UserPermissions { EntityPermissions = new[] { new EntityPermission { EntityKey = "ek-not-match" } } }; var pm = new Mock <IPermissionManager>(); pm.Setup(p => p.GetUserPermissions(It.IsAny <string>())).ReturnsAsync(up); var res = await PermissionManagerExtensions.GetPermittedIds(pm.Object, "some-user-id", "ek", "pk"); res.ShouldBeEmpty(); }