コード例 #1
0
        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);
        }
コード例 #2
0
        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();
        }
コード例 #3
0
        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();
        }