Skip to content

Protected mock constructor should chain to base no-op constructor #159

@daviburg

Description

@daviburg

Context

The generated client classes have a protected parameterless constructor intended for mocking, but it chains to a real overload that instantiates a live ManagedIdentityCredential and builds an HTTP pipeline.

Problem

// Current — KustoClient.cs (and all generated clients)
protected KustoClient() : this(new Uri("https://localhost")) { }

This calls KustoClient(Uri)ConnectorClientBase(Uri) → creates new ManagedIdentityCredential(ManagedIdentityId.SystemAssigned) and calls HttpPipelineBuilder.Build(...). In CI/test environments without IMDS:

  • The constructor may block waiting for the metadata endpoint
  • Managed identity calls can introduce latency or throw on misconfigured machines

The base class already has a no-op constructor designed for exactly this case:

// ConnectorClientBase.cs
protected ConnectorClientBase()
{
    this._pipeline = null!;
    this._connectionRuntimeUrl = string.Empty;
}

Proposed change

Chain to the base no-op constructor instead:

// Fix — safe for mocking, no live resources created
protected KustoClient() : base() { }

This is a generator template change — applies to all 90+ generated client classes.

Azure SDK guideline

DO provide a protected no-argument constructor for mocking

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions