Ejemplo n.º 1
0
        public async Task CanListRoleDefinitions()
        {
            RoleAssignmentsClient assignmentsClient = CreateAssignmentClient();
            RoleDefinitionsClient definitionsClient = CreateDefinitionsClient();

            await using DisposableClientRole role = await DisposableClientRole.Create(assignmentsClient, definitionsClient, TestEnvironment);

            // TODO: This will change to pageable with next (Data Plane) client generator update
            Response listReponse = await definitionsClient.GetRoleDefinitionsAsync(new());

            var listContent = listReponse.Content;

            using var roleDefinitionsJson = JsonDocument.Parse(listContent.ToMemory());

            foreach (var expectedRoleDefinitionJson in roleDefinitionsJson.RootElement.EnumerateArray())
            {
                string id = expectedRoleDefinitionJson.GetProperty("id").ToString();

                var roleDefinitionResponse = await definitionsClient.GetRoleDefinitionByIdAsync(id, new());

                var roleDefinitionContent = roleDefinitionResponse.Content;
                using var actualRoleDefinitionJson = JsonDocument.Parse(roleDefinitionContent.ToMemory());

                Assert.AreEqual(expectedRoleDefinitionJson.GetProperty("id").ToString(), actualRoleDefinitionJson.RootElement.GetProperty("id").ToString());
                Assert.AreEqual(expectedRoleDefinitionJson.GetProperty("name").ToString(), actualRoleDefinitionJson.RootElement.GetProperty("name").ToString());
            }

            Assert.GreaterOrEqual(roleDefinitionsJson.RootElement.GetArrayLength(), 1);
        }
        public async Task ListRoleAssignments()
        {
            RoleAssignmentsClient assignmentsClient = CreateAssignmentClient();
            RoleDefinitionsClient definitionsClient = CreateDefinitionsClient();

            await using DisposableClientRole role = await DisposableClientRole.Create(assignmentsClient, definitionsClient, TestEnvironment);

            Response <IReadOnlyList <SynapseRoleDefinition> > roleAssignments = await definitionsClient.ListRoleDefinitionsAsync();

            foreach (SynapseRoleDefinition expected in roleAssignments.Value)
            {
                SynapseRoleDefinition actual = await definitionsClient.GetRoleDefinitionByIdAsync(expected.Id.ToString());

                Assert.AreEqual(expected.Id, actual.Id);
                Assert.AreEqual(expected.Name, actual.Name);
            }
            Assert.GreaterOrEqual(roleAssignments.Value.Count, 1);
        }