New() 공개 메소드

Creates a new API client (for backend or user-aware usage) in current instance. Only Admin permission role can create new API clients.
public New ( string description, ApiKeyType type = ApiKeyType.Backend, string roleId = null ) : Task
description string Description of new API client.
type ApiKeyType Type of new API client.
roleId string New API client's permission role id (see role.get()). Not used when creating User API key (type = user)
리턴 Task
        public async Task New_BackendType_CreatesNewApiKey(ApiKeySyncanoClient client)
        {
            //given
            var description = "apiKey description";

            //when
            var apiKey = await client.New(description, ApiKeyType.Backend, TestData.RoleId);

            //then
            apiKey.ShouldNotBeNull();
            apiKey.Description.ShouldEqual(description);

            //cleanup
            await client.Delete(apiKey.Id);
        }
        public async Task Deauthorize_WithSubscribePermission(ApiKeySyncanoClient client)
        {
            //given
            var description = "apiKey description";
            var apiKey = await client.New(description, ApiKeyType.User);
            await client.Authorize(apiKey.Id, ApiKeyPermission.SendNotification);

            //when
            var result = await client.Deauthorize(apiKey.Id, ApiKeyPermission.SendNotification);

            //then
            result.ShouldBeTrue();

            //cleanup
            await client.Delete(apiKey.Id);
        }
        public async Task Delete_UserType_DeletesApiKey(ApiKeySyncanoClient client)
        {
            //given
            var description = "apiKey description";
            var apiKey = await client.New(description, ApiKeyType.User);

            //when
            var result = await client.Delete(apiKey.Id);

            //then
            result.ShouldBeTrue();
        }
        public async Task Authorize_WithAccessSyncPermission(ApiKeySyncanoClient client)
        {
            //given
            var description = "apiKey description";
            var apiKey = await client.New(description, ApiKeyType.User);

            //when
            var result = await client.Authorize(apiKey.Id, ApiKeyPermission.AccessSync);

            //then
            result.ShouldBeTrue();

            //cleanup
            await client.Delete(apiKey.Id);
        }
        public async Task Update_UpdatesApiKey(ApiKeySyncanoClient client)
        {
            //given
            var description = "apiKey description";
            var newDescription = "new apiKey description";
            var apiKey = await client.New(description, ApiKeyType.Backend, TestData.RoleId);

            //when
            apiKey = await client.UpdateDescription(newDescription, apiKey.Id);

            //then
            apiKey.ShouldNotBeNull();
            apiKey.Description.ShouldEqual(newDescription);

            //cleanup
            await client.Delete(apiKey.Id);
        }
 public async Task New_WithInvalidRoleId_ThrowsException(ApiKeySyncanoClient client)
 {
     try
     {
         //when
         await client.New("description", ApiKeyType.Backend, "9999");
         throw new Exception("New should throw an exception");
     }
     catch (Exception e)
     {
         //then
         e.ShouldBeType<SyncanoException>();
     }
 }
 public async Task New_WithRoleIdAndUserType_ThrowsException(ApiKeySyncanoClient client)
 {
     try
     {
         //when
         await client.New("description", ApiKeyType.User, TestData.RoleId);
         throw new Exception("New should throw an exception");
     }
     catch (Exception e)
     {
         //then
         e.ShouldBeType<ArgumentException>();
     }
 }
 public async Task New_WithNullDescription_ThrowsException(ApiKeySyncanoClient client)
 {
     try
     {
         //when
         await client.New(null, roleId: TestData.RoleId);
         throw new Exception("New should throw an exception");
     }
     catch (Exception e)
     {
         //then
         e.ShouldBeType<ArgumentNullException>();
     }
 }