kmanjt
kmanjt
CC#
Created by kmanjt on 6/30/2024 in #help
DefaultAzureCredential Saying AZ CLI is not installed when it is
can anyone please help me fix DefaultAzureCredential not using the AZ CLI locally? its saying its not installed when I run in Visual Studio reason for that is the Visual Studio Credential is not working for me because I login to the Azure Portal through GitHub
3 replies
CC#
Created by kmanjt on 6/22/2024 in #help
Azure DevOps Pipelines: Environment Variables Not Available in dotnet test Command
I'm using Azure DevOps and have an AzureCLI task set up to run integration tests with the dotnet test command. I'm encountering an issue where environment variables set in the task do not seem to be available when dotnet test is executed. Here is the relevant part of my pipeline configuration:
- task: AzureCLI@2
displayName: 'Run Integration Tests Inside AZ CLI'
inputs:
azureSubscription: ${{ parameters.azureServiceConnection }}
scriptType: pscore
scriptLocation: 'inlineScript'
addSpnToEnvironment: true
inlineScript: |
# Commands to set environment variables
Write-Host "##vso[task.setvariable variable=TENANT_ID;issecret=true]$(tenantId)"
...

$env:TENANT_ID = "$(tenantId)"
...

# Running dotnet test
dotnet test --configuration $(buildConfiguration) ...
- task: AzureCLI@2
displayName: 'Run Integration Tests Inside AZ CLI'
inputs:
azureSubscription: ${{ parameters.azureServiceConnection }}
scriptType: pscore
scriptLocation: 'inlineScript'
addSpnToEnvironment: true
inlineScript: |
# Commands to set environment variables
Write-Host "##vso[task.setvariable variable=TENANT_ID;issecret=true]$(tenantId)"
...

$env:TENANT_ID = "$(tenantId)"
...

# Running dotnet test
dotnet test --configuration $(buildConfiguration) ...
The variables like TENANT_ID are set using ##vso[task.setvariable] and also attempted to be set in the script's session scope using $env: for use in the same script. However, these variables do not seem to be accessible or correctly passed to the dotnet test command. What could be causing this issue, and how can I ensure that these environment variables are correctly passed to and accessible by the dotnet test command within the same Azure CLI task?
3 replies
CC#
Created by kmanjt on 5/14/2024 in #help
How to Override CosmosClient Configuration in WebApplicationFactory for Integration Testing
Hi everyone, I'm trying to override the CosmosClient configuration in my Program.cs for my integration tests using WebApplicationFactory, but I'm running into issues. Here's the relevant code from Program.cs:
clientsBuilder.AddClient<CosmosClient, CosmosClientOptions>(options =>
{
options.Serializer = new CosmosJsonSerializer();
options.ApplicationRegion = cosmosConfig.ApplicationRegion;
return new CosmosClient(cosmosConfig.ConnectionString, options);
})
clientsBuilder.AddClient<CosmosClient, CosmosClientOptions>(options =>
{
options.Serializer = new CosmosJsonSerializer();
options.ApplicationRegion = cosmosConfig.ApplicationRegion;
return new CosmosClient(cosmosConfig.ConnectionString, options);
})
I tried removing the existing CosmosClient service like this, but it doesn't seem to work:
services.RemoveAll(typeof(CosmosClient));
services.RemoveAll(typeof(CosmosClient));
1 replies
CC#
Created by kmanjt on 5/13/2024 in #help
Testcontainers CosmosDB / WebApplication Factory ConnectionString Not Working
anyone familiar with WebApplicationFactory / Testcontainers? The below is giving me System.ArgumentException: Format of the initialization string does not conform to specification starting at index 0.
public abstract class IntegrationTest
{
protected readonly HttpClient TestClient;
protected CosmosDbContainer cosmosDbContainer;

protected IntegrationTest()
{
cosmosDbContainer = new CosmosDbBuilder()
.WithImage("mcr.microsoft.com/cosmosdb/linux/azure-cosmos-emulator:latest")
.Build();
cosmosDbContainer.StartAsync().GetAwaiter().GetResult();

var appFactory = new WebApplicationFactory<Program>()
.WithWebHostBuilder(builder =>
{
builder.ConfigureServices(services =>
{
var connectionString = cosmosDbContainer.GetConnectionString();
var cosmosOptions = new CosmosClientOptions()
{
Serializer = new CosmosJsonSerializer()
};
services.RemoveAll(typeof(CosmosClient));
services.AddSingleton(new CosmosClient(connectionString, cosmosOptions));
});

builder.UseEnvironment("Development");
});

TestClient = appFactory.CreateClient();
}

public void Dispose()
{
cosmosDbContainer.DisposeAsync();
}
}
public abstract class IntegrationTest
{
protected readonly HttpClient TestClient;
protected CosmosDbContainer cosmosDbContainer;

protected IntegrationTest()
{
cosmosDbContainer = new CosmosDbBuilder()
.WithImage("mcr.microsoft.com/cosmosdb/linux/azure-cosmos-emulator:latest")
.Build();
cosmosDbContainer.StartAsync().GetAwaiter().GetResult();

var appFactory = new WebApplicationFactory<Program>()
.WithWebHostBuilder(builder =>
{
builder.ConfigureServices(services =>
{
var connectionString = cosmosDbContainer.GetConnectionString();
var cosmosOptions = new CosmosClientOptions()
{
Serializer = new CosmosJsonSerializer()
};
services.RemoveAll(typeof(CosmosClient));
services.AddSingleton(new CosmosClient(connectionString, cosmosOptions));
});

builder.UseEnvironment("Development");
});

TestClient = appFactory.CreateClient();
}

public void Dispose()
{
cosmosDbContainer.DisposeAsync();
}
}
someone mentioned ports earlier?
29 replies
CC#
Created by kmanjt on 5/10/2024 in #help
Resolving External $ref Paths With Nested Refs in NSwag for OpenAPI Specification in C#
When attempting to generate the C# client, I encounter errors like System.InvalidOperationException: Could not resolve the path '#/components/schemas/SomeSchema'. This error suggests that NSwag cannot resolve the external references, even though the paths are correctly specified. Here is what the ref looks like:
components:
schemas:
SomeSchema:
$ref: './external_definitions.yml#/components/schemas/SomeSchema'
components:
schemas:
SomeSchema:
$ref: './external_definitions.yml#/components/schemas/SomeSchema'
EDIT: Here is an example of the SomeSchema definition - the issue are the nested references I believe:
SomeSchema:
type: object
properties:
Identifier:
$ref: '#/components/schemas/UniqueIdentifier'
nullable: true
Status:
$ref: '#/components/schemas/StatusType'
nullable: true
Calculations:
type: array
items:
$ref: '#/components/schemas/CalculationType'
nullable: true
DataSources:
type: array
items:
$ref: '#/components/schemas/DataSourceType'
nullable: true
Dimensions:
type: array
items:
$ref: '#/components/schemas/DimensionFilterType'
nullable: true
Conditions:
type: array
items:
$ref: '#/components/schemas/ConditionType'
nullable: true
Outputs:
type: array
items:
$ref: '#/components/schemas/OutputType'
nullable: true
ExtendedConfig:
$ref: '#/components/schemas/AdvancedConfigType'
nullable: true
AutoAdjustmentConfig:
$ref: '#/components/schemas/AdjustmentConfigType'
nullable: true
EnrichmentConfig:
$ref: '#/components/schemas/EnrichmentConfigType'
nullable: true
Metadata:
type: object
additionalProperties:
type: string
nullable: true
DeploymentMetadata:
$ref: '#/components/schemas/DeploymentMetadataType'
nullable: true
SomeSchema:
type: object
properties:
Identifier:
$ref: '#/components/schemas/UniqueIdentifier'
nullable: true
Status:
$ref: '#/components/schemas/StatusType'
nullable: true
Calculations:
type: array
items:
$ref: '#/components/schemas/CalculationType'
nullable: true
DataSources:
type: array
items:
$ref: '#/components/schemas/DataSourceType'
nullable: true
Dimensions:
type: array
items:
$ref: '#/components/schemas/DimensionFilterType'
nullable: true
Conditions:
type: array
items:
$ref: '#/components/schemas/ConditionType'
nullable: true
Outputs:
type: array
items:
$ref: '#/components/schemas/OutputType'
nullable: true
ExtendedConfig:
$ref: '#/components/schemas/AdvancedConfigType'
nullable: true
AutoAdjustmentConfig:
$ref: '#/components/schemas/AdjustmentConfigType'
nullable: true
EnrichmentConfig:
$ref: '#/components/schemas/EnrichmentConfigType'
nullable: true
Metadata:
type: object
additionalProperties:
type: string
nullable: true
DeploymentMetadata:
$ref: '#/components/schemas/DeploymentMetadataType'
nullable: true
Has anyone successfully resolved external $ref paths with nested schemas using NSwag?
2 replies
CC#
Created by kmanjt on 5/9/2024 in #help
NetArchTests Not Detecting Project References
anyone here familiar with netarchtests? I am trying to enforce clean architecture, and for some reason, it is not detecting project references:
[TestMethod]
public void Application_ShouldNotHave_DependencyOnOtherProjects()
{
var assembly = typeof(Application.AssemblyReference).Assembly;
var otherProjects = new[] { CoreNamespace, InfrastructureNamespace, ContractsNamespace, ApiNamespace, ArpNamespace };

var test = Types.InAssembly(assembly)
.ShouldNot()
.HaveDependencyOnAny(otherProjects)
.GetResult();

Assert.IsTrue(test.IsSuccessful, GenerateErrorMessage(test));
}
[TestMethod]
public void Application_ShouldNotHave_DependencyOnOtherProjects()
{
var assembly = typeof(Application.AssemblyReference).Assembly;
var otherProjects = new[] { CoreNamespace, InfrastructureNamespace, ContractsNamespace, ApiNamespace, ArpNamespace };

var test = Types.InAssembly(assembly)
.ShouldNot()
.HaveDependencyOnAny(otherProjects)
.GetResult();

Assert.IsTrue(test.IsSuccessful, GenerateErrorMessage(test));
}
The above test should fail, but isnt -- note: assume namespace strings are correct
2 replies
CC#
Created by kmanjt on 5/8/2024 in #help
Resolving External Components with Nested Components in NSwag for OpenAPI specs
I am using NSwag to generate a C# client from an OpenAPI spec I want this spec to reference an external component schema which has nested references in its own file, but I have not been able to resolve the nested components The paths are correct, and when I simplify the ref to not have nested references that does work Please help thank you
2 replies
CC#
Created by kmanjt on 2/23/2024 in #help
.runsettings Coverage Pattern Not Working
Hello can someone please help me fix my runsettings to only collect from the "Controllers" folder:
<?xml version="1.0" encoding="utf-8"?>
<RunSettings>
<!-- Configurations for data collectors -->
<DataCollectionRunSettings>
<DataCollectors>
<DataCollector friendlyName="XPlat code coverage">
<Configuration>
<CodeCoverage>
<!-- Include anything in the project Controllers folder -->
<Functions>
<Include>
<Function>^Controllers[/\\].*</Function>
</Include>
</Functions>
</CodeCoverage>
</Configuration>
</DataCollector>
</DataCollectors>
</DataCollectionRunSettings>
</RunSettings>
<?xml version="1.0" encoding="utf-8"?>
<RunSettings>
<!-- Configurations for data collectors -->
<DataCollectionRunSettings>
<DataCollectors>
<DataCollector friendlyName="XPlat code coverage">
<Configuration>
<CodeCoverage>
<!-- Include anything in the project Controllers folder -->
<Functions>
<Include>
<Function>^Controllers[/\\].*</Function>
</Include>
</Functions>
</CodeCoverage>
</Configuration>
</DataCollector>
</DataCollectors>
</DataCollectionRunSettings>
</RunSettings>
Currently this is collecting for everything and I am running it like so:
dotnet test --settings .runsettings
dotnet test --settings .runsettings
1 replies
CC#
Created by kmanjt on 2/8/2024 in #help
Programmatically issue API Management Subscription Keys
Hello, does anyone know how (or where I can learn about) programmatically issuing / managing Azure API management subscription keys in .NET? My current idea is that users authenticated via JWT can hit an endpoint to receive a subscription key to interact with the APIs programmatically Thank you
6 replies
CC#
Created by kmanjt on 2/7/2024 in #help
situation where the response to an InfluxDB query can be huge (10+ MB easily)
hello I have a situation where the response to an InfluxDB query can be huge (10+ MB easily), which is going into a single list object like so: List<Metric> metrics = await _influxDBService.MachineRead(sql, "metrics"); - this is creating a memory leak and memory fragmentation please what approach could I take to mitigate this
22 replies