/// <summary>
        /// Ensures the group Exists
        /// </summary>
        /// <param name="groupName"></param>
        private async Task <string> EnsureAzureADGroupExists(string groupName)
        {
            string groupId;

            var client = RestClient
                         .Configure()
                         .WithEnvironment(AzureEnvironment.AzureGlobalCloud)
                         .WithLogLevel(HttpLoggingDelegatingHandler.Level.None)
                         .WithCredentials(_authenticationHelper.GetAzureCrendentials())
                         .Build();

            GraphRbacManager graphRbacManager = new GraphRbacManager(client, _appSettings.TenantId);

            IActiveDirectoryGroup group = await graphRbacManager.Groups.GetByNameAsync(groupName);

            if (group == null)
            {
                GroupCreateParameters parameters = new GroupCreateParameters()
                {
                    DisplayName = groupName, MailNickname = groupName
                };

                ADGroupInner groupInner = await graphRbacManager.Groups.Inner.CreateAsync(parameters);

                groupId = groupInner.ObjectId;
            }
            else
            {
                groupId = group.Id;
            }

            return(groupId);
        }
示例#2
0
 /// <summary>
 /// Create a group in the directory.  (see
 /// http://msdn.microsoft.com/en-us/library/azure/dn151614.aspx for
 /// more information)
 /// </summary>
 /// <param name='operations'>
 /// Reference to the Microsoft.Azure.Graph.RBAC.IGroupOperations.
 /// </param>
 /// <param name='parameters'>
 /// Required. Parameters to create a group
 /// </param>
 /// <returns>
 /// Server response for Get group information API call
 /// </returns>
 public static GroupGetResult Create(this IGroupOperations operations, GroupCreateParameters parameters)
 {
     return(Task.Factory.StartNew((object s) =>
     {
         return ((IGroupOperations)s).CreateAsync(parameters);
     }
                                  , operations, CancellationToken.None, TaskCreationOptions.None, TaskScheduler.Default).Unwrap().GetAwaiter().GetResult());
 }
示例#3
0
        public ADGroup CreateGroup(MockContext context, string groupname)
        {
            string mailNickName = groupname + "tester";
            GroupCreateParameters parameters = new GroupCreateParameters();

            parameters.DisplayName  = groupname;
            parameters.MailNickname = mailNickName;

            return(GetGraphClient(context).Groups.Create(parameters));
        }
        private ADGroup CreateNewAdGroup(ResourcesController controllerAdmin)
        {
            var parameter = new GroupCreateParameters
            {
                DisplayName  = TestUtilities.GenerateName("adgroup"),
                MailNickname = TestUtilities.GenerateName("adgroupmail")
            };

            return(controllerAdmin.GraphClient.Groups.Create(parameter));
        }
        private Group CreateNewAdGroup(ResourcesController controllerAdmin)
        {
            var parameter = new GroupCreateParameters
            {
                DisplayName     = TestUtilities.GenerateName("adgroup"),
                MailNickname    = TestUtilities.GenerateName("adgroupmail"),
                SecurityEnabled = true
            };

            return(controllerAdmin.GraphClient.Group.Create(parameter).Group);
        }
 internal ActiveDirectoryGroupImpl(ADGroupInner innerModel, GraphRbacManager manager)
     : base(innerModel.DisplayName, innerModel)
 {
     this.manager          = manager;
     this.createParameters = new GroupCreateParameters
     {
         DisplayName = innerModel.DisplayName
     };
     membersToAdd    = new HashSet <string>();
     membersToRemove = new HashSet <string>();
 }
示例#7
0
        public ADGroup CreateGroup(MockContext context)
        {
            string groupname    = TestUtilities.GenerateName("adgroup");
            string mailNickName = groupname + "tester";
            GroupCreateParameters parameters = new GroupCreateParameters();

            parameters.DisplayName  = groupname;
            parameters.MailNickname = mailNickName;

            return(GetGraphClient(context).Groups.Create(parameters));
        }
        public Group CreateGroup()
        {
            string groupname    = TestUtilities.GenerateName("adgroup");
            string mailNickName = groupname + "tester";
            GroupCreateParameters parameters = new GroupCreateParameters();

            parameters.DisplayName     = groupname;
            parameters.MailEnabled     = false;
            parameters.SecurityEnabled = true;
            parameters.MailNickname    = mailNickName;

            return(GraphClient.Group.Create(parameters).Group);
        }
示例#9
0
 public virtual Response <ADGroup> Create(GroupCreateParameters parameters, CancellationToken cancellationToken = default)
 {
     using var scope = _clientDiagnostics.CreateScope("GroupsOperations.Create");
     scope.Start();
     try
     {
         return(RestClient.Create(parameters, cancellationToken));
     }
     catch (Exception e)
     {
         scope.Failed(e);
         throw;
     }
 }
示例#10
0
 public virtual async Task <Response <ADGroup> > CreateAsync(GroupCreateParameters parameters, CancellationToken cancellationToken = default)
 {
     using var scope = _clientDiagnostics.CreateScope("GroupsOperations.Create");
     scope.Start();
     try
     {
         return(await RestClient.CreateAsync(parameters, cancellationToken).ConfigureAwait(false));
     }
     catch (Exception e)
     {
         scope.Failed(e);
         throw;
     }
 }
示例#11
0
        public override void ExecuteCmdlet()
        {
            var groupCreateParams = new GroupCreateParameters()
            {
                DisplayName  = DisplayName,
                MailNickname = MailNickname
            };

            ExecutionBlock(() =>
            {
                if (ShouldProcess(target: DisplayName, action: string.Format("Creating a new AD group with display name '{0}'", DisplayName)))
                {
                    WriteObject(ActiveDirectoryClient.CreateGroup(groupCreateParams));
                }
            });
        }
示例#12
0
        public override void ExecuteCmdlet()
        {
            var groupCreateParams = new GroupCreateParameters()
            {
                DisplayName          = DisplayName,
                MailNickname         = MailNickname,
                AdditionalProperties = new System.Collections.Generic.Dictionary <string, object>()
            };

            if (!string.IsNullOrEmpty(Description))
            {
                groupCreateParams.AdditionalProperties.Add("description", Description);
            }

            ExecutionBlock(() =>
            {
                if (ShouldProcess(target: DisplayName, action: string.Format("Creating a new AD group with display name '{0}'", DisplayName)))
                {
                    WriteObject(ActiveDirectoryClient.CreateGroup(groupCreateParams));
                }
            });
        }
 /// <summary>
 /// Create a group in the directory.
 /// </summary>
 /// <param name='operations'>
 /// The operations group for this extension method.
 /// </param>
 /// <param name='parameters'>
 /// The parameters for the group to create.
 /// </param>
 /// <param name='cancellationToken'>
 /// The cancellation token.
 /// </param>
 public static async Task <ADGroup> CreateAsync(this IGroupsOperations operations, GroupCreateParameters parameters, CancellationToken cancellationToken = default(CancellationToken))
 {
     using (var _result = await operations.CreateWithHttpMessagesAsync(parameters, null, cancellationToken).ConfigureAwait(false))
     {
         return(_result.Body);
     }
 }
 /// <summary>
 /// Creates or Updates a group.
 /// </summary>
 /// <param name='operations'>
 /// The operations group for this extension method.
 /// </param>
 /// <param name='resourceGroupName'>
 /// The name of the resource group.
 /// </param>
 /// <param name='serviceName'>
 /// The name of the API Management service.
 /// </param>
 /// <param name='groupId'>
 /// Group identifier. Must be unique in the current API Management service
 /// instance.
 /// </param>
 /// <param name='parameters'>
 /// Create parameters.
 /// </param>
 /// <param name='ifMatch'>
 /// ETag of the Entity. Not required when creating an entity, but required when
 /// updating an entity.
 /// </param>
 /// <param name='cancellationToken'>
 /// The cancellation token.
 /// </param>
 public static async Task <GroupContract> CreateOrUpdateAsync(this IGroupOperations operations, string resourceGroupName, string serviceName, string groupId, GroupCreateParameters parameters, string ifMatch = default(string), CancellationToken cancellationToken = default(CancellationToken))
 {
     using (var _result = await operations.CreateOrUpdateWithHttpMessagesAsync(resourceGroupName, serviceName, groupId, parameters, ifMatch, null, cancellationToken).ConfigureAwait(false))
     {
         return(_result.Body);
     }
 }
 /// <summary>
 /// Creates or Updates a group.
 /// </summary>
 /// <param name='operations'>
 /// The operations group for this extension method.
 /// </param>
 /// <param name='resourceGroupName'>
 /// The name of the resource group.
 /// </param>
 /// <param name='serviceName'>
 /// The name of the API Management service.
 /// </param>
 /// <param name='groupId'>
 /// Group identifier. Must be unique in the current API Management service
 /// instance.
 /// </param>
 /// <param name='parameters'>
 /// Create parameters.
 /// </param>
 /// <param name='ifMatch'>
 /// ETag of the Entity. Not required when creating an entity, but required when
 /// updating an entity.
 /// </param>
 public static GroupContract CreateOrUpdate(this IGroupOperations operations, string resourceGroupName, string serviceName, string groupId, GroupCreateParameters parameters, string ifMatch = default(string))
 {
     return(operations.CreateOrUpdateAsync(resourceGroupName, serviceName, groupId, parameters, ifMatch).GetAwaiter().GetResult());
 }
 public PSADGroup CreateGroup(GroupCreateParameters groupCreateParams)
 {
     return(GraphClient.Groups.Create(groupCreateParams).ToPSADGroup());
 }
示例#17
0
        public void GroupsListAddRemove()
        {
            Environment.SetEnvironmentVariable("AZURE_TEST_MODE", "Playback");
            using (MockContext context = MockContext.Start(this.GetType().FullName))
            {
                var testBase = new ApiManagementTestBase(context);
                testBase.TryCreateApiManagementService();

                // create new group
                string gid = TestUtilities.GenerateName("groupId");

                try
                {
                    var createGroupParams = new GroupCreateParameters
                    {
                        DisplayName = TestUtilities.GenerateName("groupName"),
                        Type        = GroupType.Custom,
                    };

                    testBase.client.Group.CreateOrUpdate(
                        testBase.rgName,
                        testBase.serviceName,
                        gid,
                        createGroupParams);

                    // get the group
                    var getGroupResponse = testBase.client.Group.Get(
                        testBase.rgName,
                        testBase.serviceName,
                        gid);

                    // create new user and add it to the group
                    string userId = TestUtilities.GenerateName("userId");
                    try
                    {
                        var creteUserParameters = new UserCreateParameters
                        {
                            FirstName = TestUtilities.GenerateName("Ivan"),
                            LastName  = TestUtilities.GenerateName("Ivanov"),
                            Email     = TestUtilities.GenerateName("ivan.ivanov") + "@contoso.com",
                            Password  = TestUtilities.GenerateName("pwd"),
                            State     = UserState.Active,
                            Note      = TestUtilities.GenerateName("note")
                        };

                        testBase.client.User.CreateOrUpdate(
                            testBase.rgName,
                            testBase.serviceName,
                            userId,
                            creteUserParameters);

                        // list user groups
                        var listUserGroupsResponse = testBase.client.UserGroup.List(
                            testBase.rgName,
                            testBase.serviceName,
                            userId,
                            null);

                        Assert.NotNull(listUserGroupsResponse);

                        // there should be 'Developers' group by default
                        Assert.Single(listUserGroupsResponse);
                        var group = listUserGroupsResponse.First();

                        // add the user to the group
                        var addResponse = testBase.client.GroupUser.Create(
                            testBase.rgName,
                            testBase.serviceName,
                            gid,
                            userId);

                        Assert.NotNull(addResponse);

                        // list user groups
                        listUserGroupsResponse = testBase.client.UserGroup.List(
                            testBase.rgName,
                            testBase.serviceName,
                            userId,
                            null);

                        Assert.NotNull(listUserGroupsResponse);
                        // there should be two groups now
                        Assert.Equal(2, listUserGroupsResponse.Count());

                        var userGroup = listUserGroupsResponse.Single(g => g.Name == group.Name);
                        Assert.Equal(group.Id, userGroup.Id);
                        Assert.Equal(group.Name, userGroup.Name);
                        Assert.Equal(group.Description, userGroup.Description);
                        Assert.Equal(group.ExternalId, userGroup.ExternalId);
                        Assert.Equal(group.GroupContractType, userGroup.GroupContractType);

                        // remove the user from the group
                        testBase.client.GroupUser.Delete(
                            testBase.rgName,
                            testBase.serviceName,
                            gid,
                            userId);

                        // list to make sure it was removed
                        listUserGroupsResponse = testBase.client.UserGroup.List(
                            testBase.rgName,
                            testBase.serviceName,
                            userId,
                            null);

                        Assert.NotNull(listUserGroupsResponse);

                        // there should be default 'Developers' group
                        Assert.Single(listUserGroupsResponse);
                        Assert.Equal("developers", listUserGroupsResponse.Single().Name);
                    }
                    finally
                    {
                        // delete the user
                        testBase.client.User.Delete(testBase.rgName, testBase.serviceName, userId, "*", true);
                    }
                }
                finally
                {
                    testBase.client.Group.Delete(testBase.rgName, testBase.serviceName, gid, "*");
                }
            }
        }
示例#18
0
        public void GroupsCreateListUpdateDelete()
        {
            TestUtilities.StartTest("SmapiFunctionalTests", "GroupsCreateListUpdateDelete");

            try
            {
                // list all groups: there should be at least 3 groups: Administrators, Developers, Guests
                var listResponse = ApiManagementClient.Groups.List(ResourceGroupName, ApiManagementServiceName, null);

                Assert.NotNull(listResponse);
                Assert.NotNull(listResponse.Result);
                Assert.True(listResponse.Result.TotalCount >= 3);
                Assert.True(listResponse.Result.Values.Count >= 3);

                // list paged
                listResponse = ApiManagementClient.Groups.List(
                    ResourceGroupName,
                    ApiManagementServiceName,
                    new QueryParameters {
                    Top = 1
                });

                Assert.NotNull(listResponse);
                Assert.NotNull(listResponse.Result);
                Assert.True(listResponse.Result.TotalCount >= 3);
                Assert.Equal(1, listResponse.Result.Values.Count);

                // create new group with default parameters
                string newGroupId            = TestUtilities.GenerateName("newGroupId");
                string newGroupName          = TestUtilities.GenerateName("newGroupName");
                var    groupCreateParameters = new GroupCreateParameters(newGroupName);

                var createResponse = ApiManagementClient.Groups.Create(
                    ResourceGroupName,
                    ApiManagementServiceName,
                    newGroupId,
                    groupCreateParameters);

                Assert.NotNull(createResponse);
                Assert.Equal(HttpStatusCode.Created, createResponse.StatusCode);

                // get to check it was created
                var getResponse = ApiManagementClient.Groups.Get(ResourceGroupName, ApiManagementServiceName, newGroupId);

                Assert.NotNull(getResponse);
                Assert.NotNull(getResponse.Value);

                Assert.Equal(newGroupId, getResponse.Value.Id);
                Assert.Equal(newGroupName, getResponse.Value.Name);
                Assert.Null(getResponse.Value.Description);
                Assert.Null(getResponse.Value.ExternalId);
                Assert.Equal(GroupTypeContract.Custom, getResponse.Value.Type);
                Assert.Equal(false, getResponse.Value.System);

                // delete the group
                ApiManagementClient.Groups.Delete(ResourceGroupName, ApiManagementServiceName, newGroupId, getResponse.ETag);

                // create a gruop with other parameters
                string newGroupDescription = TestUtilities.GenerateName("newGroupDescription");
                var    newGroupType        = GroupTypeContract.Custom;

                groupCreateParameters = new GroupCreateParameters
                {
                    Description = newGroupDescription,
                    Name        = newGroupName,
                    Type        = newGroupType
                };

                createResponse = ApiManagementClient.Groups.Create(
                    ResourceGroupName,
                    ApiManagementServiceName,
                    newGroupId,
                    groupCreateParameters);

                Assert.NotNull(createResponse);
                Assert.Equal(HttpStatusCode.Created, createResponse.StatusCode);

                // get to check it was created
                getResponse = ApiManagementClient.Groups.Get(ResourceGroupName, ApiManagementServiceName, newGroupId);

                Assert.NotNull(getResponse);
                Assert.NotNull(getResponse.Value);

                Assert.Equal(newGroupId, getResponse.Value.Id);
                Assert.Equal(newGroupName, getResponse.Value.Name);
                Assert.Equal(newGroupDescription, getResponse.Value.Description);
                //Assert.Equal(newGroupExternalId, getResponse.Value.ExternalId);
                Assert.Equal(newGroupType, getResponse.Value.Type);
                Assert.Equal(false, getResponse.Value.System);

                // patch group
                string patchedDescription = TestUtilities.GenerateName("patchedDescription");
                var    patchResponse      = ApiManagementClient.Groups.Update(
                    ResourceGroupName,
                    ApiManagementServiceName,
                    newGroupId,
                    new GroupUpdateParameters
                {
                    Description = patchedDescription
                },
                    getResponse.ETag);

                Assert.NotNull(patchResponse);

                // get to check it was patched
                getResponse = ApiManagementClient.Groups.Get(ResourceGroupName, ApiManagementServiceName, newGroupId);

                Assert.NotNull(getResponse);
                Assert.NotNull(getResponse.Value);

                Assert.Equal(newGroupId, getResponse.Value.Id);
                Assert.Equal(newGroupName, getResponse.Value.Name);
                Assert.Equal(patchedDescription, getResponse.Value.Description);
                //Assert.Equal(newGroupExternalId, getResponse.Value.ExternalId);
                Assert.Equal(newGroupType, getResponse.Value.Type);
                Assert.Equal(false, getResponse.Value.System);

                // delete the group
                var deleteResponse = ApiManagementClient.Groups.Delete(
                    ResourceGroupName,
                    ApiManagementServiceName,
                    newGroupId,
                    getResponse.ETag);

                Assert.NotNull(deleteResponse);
                Assert.Equal(HttpStatusCode.NoContent, deleteResponse.StatusCode);

                // get the deleted api to make sure it was deleted
                try
                {
                    ApiManagementClient.Groups.Get(ResourceGroupName, ApiManagementServiceName, newGroupId);
                    throw new Exception("This code should not have been executed.");
                }
                catch (CloudException ex)
                {
                    Assert.Equal(HttpStatusCode.NotFound, ex.Response.StatusCode);
                }
            }
            finally
            {
                TestUtilities.EndTest();
            }
        }
示例#19
0
        public async Task CreateListUpdateDelete()
        {
            Environment.SetEnvironmentVariable("AZURE_TEST_MODE", "Playback");
            using (MockContext context = MockContext.Start(this.GetType()))
            {
                var testBase = new ApiManagementTestBase(context);
                testBase.TryCreateApiManagementService();

                var userId     = TestUtilities.GenerateName("sdkUserId");
                var newGroupId = TestUtilities.GenerateName("sdkGroupId");

                try
                {
                    // create a new group
                    var newGroupDisplayName = TestUtilities.GenerateName("sdkGroup");
                    var parameters          = new GroupCreateParameters()
                    {
                        DisplayName = newGroupDisplayName,
                        Description = "Group created from Sdk client"
                    };

                    var groupContract = await testBase.client.Group.CreateOrUpdateAsync(
                        testBase.rgName,
                        testBase.serviceName,
                        newGroupId,
                        parameters);

                    Assert.NotNull(groupContract);
                    Assert.Equal(newGroupDisplayName, groupContract.DisplayName);
                    Assert.False(groupContract.BuiltIn);
                    Assert.NotNull(groupContract.Description);
                    Assert.Equal(GroupType.Custom, groupContract.GroupContractType);

                    // list all group users
                    var listResponse = testBase.client.GroupUser.List(
                        testBase.rgName,
                        testBase.serviceName,
                        newGroupId,
                        null);
                    Assert.NotNull(listResponse);
                    Assert.Empty(listResponse);

                    // create a new user and add to the group
                    var createParameters = new UserCreateParameters()
                    {
                        FirstName = TestUtilities.GenerateName("sdkFirst"),
                        LastName  = TestUtilities.GenerateName("sdkLast"),
                        Email     = TestUtilities.GenerateName("sdkFirst.Last") + "@contoso.com",
                        State     = UserState.Active,
                        Note      = "dummy note"
                    };

                    var userContract = testBase.client.User.CreateOrUpdate(
                        testBase.rgName,
                        testBase.serviceName,
                        userId,
                        createParameters);
                    Assert.NotNull(userContract);

                    // add user to group
                    var addUserContract = testBase.client.GroupUser.Create(
                        testBase.rgName,
                        testBase.serviceName,
                        newGroupId,
                        userId);
                    Assert.NotNull(addUserContract);
                    Assert.Equal(userContract.Email, addUserContract.Email);
                    Assert.Equal(userContract.FirstName, addUserContract.FirstName);

                    // list group user
                    var listgroupResponse = testBase.client.GroupUser.List(
                        testBase.rgName,
                        testBase.serviceName,
                        newGroupId);
                    Assert.NotNull(listgroupResponse);
                    Assert.Single(listgroupResponse);
                    Assert.Equal(addUserContract.Email, listgroupResponse.GetEnumerator().ToIEnumerable().First().Email);

                    // check entity exists
                    var entityStatus = await testBase.client.GroupUser.CheckEntityExistsAsync(
                        testBase.rgName,
                        testBase.serviceName,
                        newGroupId,
                        userId);

                    Assert.True(entityStatus);

                    // remove user from group
                    testBase.client.GroupUser.Delete(
                        testBase.rgName,
                        testBase.serviceName,
                        newGroupId,
                        userId);

                    // make sure user is removed
                    entityStatus = await testBase.client.GroupUser.CheckEntityExistsAsync(
                        testBase.rgName,
                        testBase.serviceName,
                        newGroupId,
                        userId);

                    Assert.False(entityStatus);
                }
                finally
                {
                    // delete the user
                    testBase.client.User.Delete(
                        testBase.rgName,
                        testBase.serviceName,
                        userId,
                        "*",
                        deleteSubscriptions: true);

                    // delete the group
                    testBase.client.Group.Delete(
                        testBase.rgName,
                        testBase.serviceName,
                        newGroupId,
                        "*");
                }
            }
        }
 /// <summary>
 /// Creates new group.
 /// </summary>
 /// <param name='operations'>
 /// Reference to the
 /// Microsoft.Azure.Management.ApiManagement.IGroupsOperations.
 /// </param>
 /// <param name='resourceGroupName'>
 /// Required. The name of the resource group.
 /// </param>
 /// <param name='serviceName'>
 /// Required. The name of the Api Management service.
 /// </param>
 /// <param name='gid'>
 /// Required. Identifier of the group.
 /// </param>
 /// <param name='parameters'>
 /// Required. Create parameters.
 /// </param>
 /// <returns>
 /// A standard service response including an HTTP status code and
 /// request ID.
 /// </returns>
 public static AzureOperationResponse Create(this IGroupsOperations operations, string resourceGroupName, string serviceName, string gid, GroupCreateParameters parameters)
 {
     return(Task.Factory.StartNew((object s) =>
     {
         return ((IGroupsOperations)s).CreateAsync(resourceGroupName, serviceName, gid, parameters);
     }
                                  , operations, CancellationToken.None, TaskCreationOptions.None, TaskScheduler.Default).Unwrap().GetAwaiter().GetResult());
 }
示例#21
0
        public void GroupUsersListAddRemove()
        {
            TestUtilities.StartTest("SmapiFunctionalTests", "GroupUsersListAddRemove");

            try
            {
                // create new group
                string gid = TestUtilities.GenerateName("groupId");

                try
                {
                    var createGroupParams = new GroupCreateParameters
                    {
                        Name = TestUtilities.GenerateName("groupName"),
                        Type = GroupTypeContract.Custom,
                    };

                    ApiManagementClient.Groups.Create(
                        ResourceGroupName,
                        ApiManagementServiceName,
                        gid,
                        createGroupParams);

                    // get the group
                    var getGroupResponse = ApiManagementClient.Groups.Get(
                        ResourceGroupName,
                        ApiManagementServiceName,
                        gid);

                    var group = getGroupResponse.Value;

                    // list all group users
                    var listGroupUsersResponse = ApiManagementClient.GroupUsers.List(
                        ResourceGroupName,
                        ApiManagementServiceName,
                        group.Id,
                        null);

                    Assert.NotNull(listGroupUsersResponse);
                    Assert.NotNull(listGroupUsersResponse.Result);
                    Assert.NotNull(listGroupUsersResponse.Result.Values);

                    // there should be no users in the group
                    Assert.Equal(0, listGroupUsersResponse.Result.TotalCount);
                    Assert.Equal(0, listGroupUsersResponse.Result.Values.Count);

                    // create new user and add it to the group
                    string userId = TestUtilities.GenerateName("userId");
                    try
                    {
                        var creteUserParameters = new UserCreateParameters
                        {
                            FirstName = TestUtilities.GenerateName("Ivan"),
                            LastName  = TestUtilities.GenerateName("Ivanov"),
                            Email     = TestUtilities.GenerateName("ivan.ivanov") + "@contoso.com",
                            Password  = TestUtilities.GenerateName("pwd"),
                            State     = UserStateContract.Active,
                            Note      = TestUtilities.GenerateName("note")
                        };

                        ApiManagementClient.Users.Create(
                            ResourceGroupName,
                            ApiManagementServiceName,
                            userId,
                            creteUserParameters);

                        // add the user to the group
                        var addResponse = ApiManagementClient.GroupUsers.Add(
                            ResourceGroupName,
                            ApiManagementServiceName,
                            group.Id,
                            userId);

                        Assert.NotNull(addResponse);

                        // list group users
                        listGroupUsersResponse = ApiManagementClient.GroupUsers.List(
                            ResourceGroupName,
                            ApiManagementServiceName,
                            group.Id,
                            null);

                        Assert.NotNull(listGroupUsersResponse);
                        Assert.NotNull(listGroupUsersResponse.Result);
                        Assert.NotNull(listGroupUsersResponse.Result.Values);

                        // there should be one user
                        Assert.Equal(1, listGroupUsersResponse.Result.TotalCount);
                        Assert.Equal(1, listGroupUsersResponse.Result.Values.Count);

                        var user = listGroupUsersResponse.Result.Values.Single();
                        Assert.Equal(userId, user.Id);
                        Assert.Equal(creteUserParameters.FirstName, user.FirstName);
                        Assert.Equal(creteUserParameters.LastName, user.LastName);
                        Assert.Equal(creteUserParameters.Email, user.Email);
                        Assert.Equal(creteUserParameters.Note, user.Note);
                        Assert.Equal(creteUserParameters.State, user.State);

                        // remove the user from the group
                        var removeReponse = ApiManagementClient.GroupUsers.Remove(
                            ResourceGroupName,
                            ApiManagementServiceName,
                            group.Id,
                            userId);

                        Assert.NotNull(removeReponse);

                        // list to make sure it was removed
                        listGroupUsersResponse = ApiManagementClient.GroupUsers.List(
                            ResourceGroupName,
                            ApiManagementServiceName,
                            group.Id,
                            null);

                        Assert.NotNull(listGroupUsersResponse);
                        Assert.NotNull(listGroupUsersResponse.Result);
                        Assert.NotNull(listGroupUsersResponse.Result.Values);

                        // there should be no users
                        Assert.Equal(0, listGroupUsersResponse.Result.TotalCount);
                        Assert.Equal(0, listGroupUsersResponse.Result.Values.Count);
                    }
                    finally
                    {
                        // delete the user
                        ApiManagementClient.Users.Delete(ResourceGroupName, ApiManagementServiceName, userId, "*", true);
                    }
                }
                finally
                {
                    // delete the group
                    ApiManagementClient.Groups.Delete(ResourceGroupName, ApiManagementServiceName, gid, "*");
                }
            }
            finally
            {
                TestUtilities.EndTest();
            }
        }
示例#22
0
        public async Task CreateListUpdateDelete()
        {
            Environment.SetEnvironmentVariable("AZURE_TEST_MODE", "Playback");
            using (MockContext context = MockContext.Start(this.GetType()))
            {
                var testBase = new ApiManagementTestBase(context);
                testBase.TryCreateApiManagementService();

                // list all groups
                var groupsList = testBase.client.Group.ListByService(
                    testBase.rgName,
                    testBase.serviceName,
                    null);

                Assert.NotEmpty(groupsList);
                Assert.Equal(3, groupsList.GetEnumerator().ToIEnumerable().Count());
                Assert.Null(groupsList.NextPageLink);

                // list by paging using ODATA query
                groupsList = testBase.client.Group.ListByService(
                    testBase.rgName,
                    testBase.serviceName,
                    new Microsoft.Rest.Azure.OData.ODataQuery <GroupContract>()
                {
                    Top = 1
                });

                Assert.NotNull(groupsList);
                Assert.Single(groupsList);
                Assert.NotNull(groupsList.NextPageLink);

                // create a new group
                var newGroupId = TestUtilities.GenerateName("sdkGroupId");
                try
                {
                    var newGroupDisplayName = TestUtilities.GenerateName("sdkGroup");
                    var parameters          = new GroupCreateParameters()
                    {
                        DisplayName = newGroupDisplayName,
                        Description = "Group created from Sdk client"
                    };

                    var groupContract = testBase.client.Group.CreateOrUpdate(
                        testBase.rgName,
                        testBase.serviceName,
                        newGroupId,
                        parameters);
                    Assert.NotNull(groupContract);
                    Assert.Equal(newGroupDisplayName, groupContract.DisplayName);
                    Assert.False(groupContract.BuiltIn);
                    Assert.NotNull(groupContract.Description);
                    Assert.Equal(GroupType.Custom, groupContract.GroupContractType);

                    // get the group tag
                    var groupTag = await testBase.client.Group.GetEntityTagAsync(
                        testBase.rgName,
                        testBase.serviceName,
                        newGroupId);

                    Assert.NotNull(groupTag);
                    Assert.NotNull(groupTag.ETag);

                    // update the group
                    var updateParameters = new GroupUpdateParameters()
                    {
                        Description = "Updating the description of the Sdk"
                    };

                    testBase.client.Group.Update(
                        testBase.rgName,
                        testBase.serviceName,
                        newGroupId,
                        updateParameters,
                        groupTag.ETag);

                    // get the updatedGroup
                    var updatedResponse = await testBase.client.Group.GetAsync(
                        testBase.rgName,
                        testBase.serviceName,
                        newGroupId);

                    Assert.NotNull(updatedResponse);
                    Assert.Equal(newGroupDisplayName, updatedResponse.DisplayName);
                    Assert.False(updatedResponse.BuiltIn);
                    Assert.NotNull(updatedResponse.Description);
                    Assert.Equal(updateParameters.Description, updatedResponse.Description);
                    Assert.Equal(GroupType.Custom, updatedResponse.GroupContractType);

                    groupTag = await testBase.client.Group.GetEntityTagAsync(
                        testBase.rgName,
                        testBase.serviceName,
                        newGroupId);

                    Assert.NotNull(groupTag);
                    Assert.NotNull(groupTag.ETag);

                    // delete the group
                    testBase.client.Group.Delete(
                        testBase.rgName,
                        testBase.serviceName,
                        newGroupId,
                        groupTag.ETag);

                    Assert.Throws <ErrorResponseException>(() =>
                    {
                        testBase.client.Group.Get(
                            testBase.rgName,
                            testBase.serviceName,
                            newGroupId);
                    });
                }
                finally
                {
                    testBase.client.Group.Delete(testBase.rgName, testBase.serviceName, newGroupId, "*");
                }
            }
        }
 /// <summary>
 /// Creates new group.
 /// </summary>
 /// <param name='operations'>
 /// Reference to the
 /// Microsoft.Azure.Management.ApiManagement.IGroupsOperations.
 /// </param>
 /// <param name='resourceGroupName'>
 /// Required. The name of the resource group.
 /// </param>
 /// <param name='serviceName'>
 /// Required. The name of the Api Management service.
 /// </param>
 /// <param name='gid'>
 /// Required. Identifier of the group.
 /// </param>
 /// <param name='parameters'>
 /// Required. Create parameters.
 /// </param>
 /// <returns>
 /// A standard service response including an HTTP status code and
 /// request ID.
 /// </returns>
 public static Task <AzureOperationResponse> CreateAsync(this IGroupsOperations operations, string resourceGroupName, string serviceName, string gid, GroupCreateParameters parameters)
 {
     return(operations.CreateAsync(resourceGroupName, serviceName, gid, parameters, CancellationToken.None));
 }
示例#24
0
 /// <summary>
 /// Create a group in the directory.  (see
 /// http://msdn.microsoft.com/en-us/library/azure/dn151614.aspx for
 /// more information)
 /// </summary>
 /// <param name='operations'>
 /// Reference to the Microsoft.Azure.Graph.RBAC.IGroupOperations.
 /// </param>
 /// <param name='parameters'>
 /// Required. Parameters to create a group
 /// </param>
 /// <returns>
 /// Server response for Get group information API call
 /// </returns>
 public static Task <GroupGetResult> CreateAsync(this IGroupOperations operations, GroupCreateParameters parameters)
 {
     return(operations.CreateAsync(parameters, CancellationToken.None));
 }
 /// <summary>
 /// Create a group in the directory.
 /// </summary>
 /// <param name='operations'>
 /// The operations group for this extension method.
 /// </param>
 /// <param name='parameters'>
 /// The parameters for the group to create.
 /// </param>
 public static ADGroup Create(this IGroupsOperations operations, GroupCreateParameters parameters)
 {
     return(operations.CreateAsync(parameters).GetAwaiter().GetResult());
 }
        public void UserGroupsListAddRemove()
        {
            TestUtilities.StartTest("SmapiFunctionalTests", "UserGroupsListAddRemove");

            try
            {
                // create new group
                string gid = TestUtilities.GenerateName("groupId");

                try
                {
                    var createGroupParams = new GroupCreateParameters
                    {
                        Name = TestUtilities.GenerateName("groupName"),
                        Type = GroupTypeContract.Custom,
                    };

                    ApiManagementClient.Groups.Create(
                        ResourceGroupName,
                        ApiManagementServiceName,
                        gid,
                        createGroupParams);

                    // get the group
                    var getGroupResponse = ApiManagementClient.Groups.Get(
                        ResourceGroupName,
                        ApiManagementServiceName,
                        gid);

                    var group = getGroupResponse.Value;

                    // create new user and add it to the group
                    string userId = TestUtilities.GenerateName("userId");
                    try
                    {
                        var creteUserParameters = new UserCreateParameters
                        {
                            FirstName = TestUtilities.GenerateName("Ivan"),
                            LastName  = TestUtilities.GenerateName("Ivanov"),
                            Email     = TestUtilities.GenerateName("ivan.ivanov") + "@contoso.com",
                            Password  = TestUtilities.GenerateName("pwd"),
                            State     = UserStateContract.Active,
                            Note      = TestUtilities.GenerateName("note")
                        };

                        ApiManagementClient.Users.Create(
                            ResourceGroupName,
                            ApiManagementServiceName,
                            userId,
                            creteUserParameters);

                        // list user groups
                        var listUserGroupsResponse = ApiManagementClient.UserGroups.List(
                            ResourceGroupName,
                            ApiManagementServiceName,
                            userId,
                            null);

                        Assert.NotNull(listUserGroupsResponse);
                        Assert.NotNull(listUserGroupsResponse.Result);
                        Assert.NotNull(listUserGroupsResponse.Result.Values);

                        // there should be 'Developers' group by default
                        Assert.Equal(1, listUserGroupsResponse.Result.TotalCount);
                        Assert.Equal(1, listUserGroupsResponse.Result.Values.Count);

                        // add the user to the group
                        var addResponse = ApiManagementClient.UserGroups.AddToGroup(
                            ResourceGroupName,
                            ApiManagementServiceName,
                            userId,
                            group.Id);

                        Assert.NotNull(addResponse);

                        // list user groups
                        listUserGroupsResponse = ApiManagementClient.UserGroups.List(
                            ResourceGroupName,
                            ApiManagementServiceName,
                            userId,
                            null);

                        Assert.NotNull(listUserGroupsResponse);
                        Assert.NotNull(listUserGroupsResponse.Result);
                        Assert.NotNull(listUserGroupsResponse.Result.Values);

                        // there should be two groups now
                        Assert.Equal(2, listUserGroupsResponse.Result.TotalCount);
                        Assert.Equal(2, listUserGroupsResponse.Result.Values.Count);

                        var userGroup = listUserGroupsResponse.Result.Values.Single(g => g.Name == group.Name);
                        Assert.Equal(group.Id, userGroup.Id);
                        Assert.Equal(group.IdPath, userGroup.IdPath);
                        Assert.Equal(group.Name, userGroup.Name);
                        Assert.Equal(group.Description, userGroup.Description);
                        Assert.Equal(group.ExternalId, userGroup.ExternalId);
                        Assert.Equal(group.System, userGroup.System);
                        Assert.Equal(group.Type, userGroup.Type);

                        // remove the user from the group
                        var removeReponse = ApiManagementClient.UserGroups.RemoveFromGroup(
                            ResourceGroupName,
                            ApiManagementServiceName,
                            userId,
                            group.Id);

                        Assert.NotNull(removeReponse);

                        // list to make sure it was removed
                        listUserGroupsResponse = ApiManagementClient.UserGroups.List(
                            ResourceGroupName,
                            ApiManagementServiceName,
                            userId,
                            null);

                        Assert.NotNull(listUserGroupsResponse);
                        Assert.NotNull(listUserGroupsResponse.Result);
                        Assert.NotNull(listUserGroupsResponse.Result.Values);

                        // there should be default 'Developers' group
                        Assert.Equal(1, listUserGroupsResponse.Result.TotalCount);
                        Assert.Equal(1, listUserGroupsResponse.Result.Values.Count);
                        Assert.Equal("Developers", listUserGroupsResponse.Result.Values.Single().Name);
                    }
                    finally
                    {
                        // delete the user
                        ApiManagementClient.Users.Delete(ResourceGroupName, ApiManagementServiceName, userId, "*", true);
                    }
                }
                finally
                {
                    // delete the group
                    ApiManagementClient.Groups.Delete(ResourceGroupName, ApiManagementServiceName, gid, "*");
                }
            }
            finally
            {
                TestUtilities.EndTest();
            }
        }