コード例 #1
0
ファイル: ConnectionTests.cs プロジェクト: jerriep/auth0.net
        public async Task Test_connection_crud_sequence()
        {
            var scopes = new
            {
                connections = new
                {
                    actions = new string[] { "read", "create", "delete", "update" }
                }
            };
            string token = GenerateToken(scopes);

            var apiClient = new ManagementApiClient(token, new Uri(GetVariable("AUTH0_MANAGEMENT_API_URL")));

            // Get all connections before
            var connectionsBefore = await apiClient.Connections.GetAllAsync("github");

            // Create a new connection
            var newConnectionRequest = new ConnectionCreateRequest
            {
                Name = Guid.NewGuid().ToString("N"),
                Strategy = "github"
            };
            var newConnectionResponse = await apiClient.Connections.CreateAsync(newConnectionRequest);
            newConnectionResponse.Should().NotBeNull();
            newConnectionResponse.Name.Should().Be(newConnectionRequest.Name);
            newConnectionResponse.Strategy.Should().Be(newConnectionRequest.Strategy);

            // Get all connections again
            var connectionsAfter = await apiClient.Connections.GetAllAsync("github");
            connectionsAfter.Count.Should().Be(connectionsBefore.Count + 1);

            // Update a connection
            var updateConnectionRequest = new ConnectionUpdateRequest
            {
                Options = new
                {
                    a = "123"
                }
            };
            var updateConnectionResponse = await apiClient.Connections.UpdateAsync(newConnectionResponse.Id, updateConnectionRequest);
            //updateConnectionResponse.Name.Should().Be(updateConnectionRequest.Name);

            // Get a single connection
            var connection = await apiClient.Connections.GetAsync(newConnectionResponse.Id);
            connection.Should().NotBeNull();
            //connection.Name.Should().Be(updateConnectionResponse.Name);

            // Delete the connection and ensure we get exception when trying to get connection again
            await apiClient.Connections.DeleteAsync(newConnectionResponse.Id);
            Func<Task> getFunc = async () => await apiClient.Connections.GetAsync(newConnectionResponse.Id);
            getFunc.ShouldThrow<ApiException>().And.ApiError.ErrorCode.Should().Be("inexistent_connection");
        }
コード例 #2
0
 /// <summary>
 /// Creates a new connection according to the request.
 /// </summary>
 /// <param name="request">The request containing the properties for the new connection.</param>
 /// <returns>A <see cref="Connection" /> containing the newly created Connection.</returns>
 public Task<Connection> CreateAsync(ConnectionCreateRequest request)
 {
     return Connection.PostAsync<Connection>("connections", request, null, null, null, null, null);
 }
コード例 #3
0
 public Task<Connection> Create(ConnectionCreateRequest request)
 {
     return CreateAsync(request);
 }
コード例 #4
0
ファイル: Program.cs プロジェクト: jerriep/auth0.net
        private static async Task TestConnectionMethods(IManagementApiClient apiClient)
        {
            // Create a new connection
            var newConnectionRequest = new ConnectionCreateRequest
            {
                Name = "jerrie-new-connection",
                Strategy = "github"
            };
            var newConnection = await apiClient.Connections.CreateAsync(newConnectionRequest);

            // Get a single connection
            var connection = await apiClient.Connections.GetAsync(newConnection.Id);

            // Get all GitHub connections
            var connections = await apiClient.Connections.GetAllAsync("github");

            // Update a connection
            var updateConnectionRequest = new ConnectionUpdateRequest
            {
                Name = "jerrie-updated-connection"
            };
            connection = await apiClient.Connections.UpdateAsync(newConnection.Id, updateConnectionRequest);

            // Delete the connection
            await apiClient.Connections.DeleteAsync(newConnection.Id);
        }