Skip to content

Instantly share code, notes, and snippets.

@manoj-choudhari-git
manoj-choudhari-git / Test.cs
Created March 2, 2023 14:49
.NET Test Projects - Ignore and Skip the tests in MSTest and xUnit Frameworks
// =======================================================================
// MSTest Test Example To Ignore A Test
// =======================================================================
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Prime.Services;
namespace Prime.UnitTests.Services
{
[TestClass]
@manoj-choudhari-git
manoj-choudhari-git / dotnet-cli.sh
Last active March 2, 2023 15:19
DOTNET CLI - Commands to Filter Tests
## Run all tests where the fully qualified test name contains the word "Repository"
dotnet test --filter FullyQualifiedName~Repository
## Run all tests where the fully qualified test name does not contain the word "Business"
dotnet test --filter FullyQualifiedName!~Business
## Run all tests where
## the fully qualified test name does not contain the word "Business"
## OR DisplayName is equal to "SomeTest"
dotnet test --filter FullyQualifiedName!~Business|DisplayName=SomeTest
@manoj-choudhari-git
manoj-choudhari-git / commands.sh
Created December 30, 2022 17:40
Demo - Commands to Install Azure App Configuration Client Library
## NPM Install - App Configuration Client Library
npm install @azure/app-configuration
## PowerShell Script to Set Environment Variable
$Env:AZURE_APP_CONFIG_CONNECTION_STRING = "{app-config-store-connection-string}"
## Command Line (Windows) to set Environment Variable
setx AZURE_APP_CONFIG_CONNECTION_STRING "{app-config-store-connection-string}"
## MacOS - Set Environment Variable
@manoj-choudhari-git
manoj-choudhari-git / javascript-demo.js
Last active December 30, 2022 17:49
JavaScript - Azure App Configuration Service - Read key-value pairs from JavaScript code
// ------------------------------------------------------------------
// To Make a new directory
// md javascript-demo
// ------------------------------------------------------------------
// Create a new file: javascript-demo.js
// contents of that file are:
async function run() {
let retrievedSetting = await client.getConfigurationSetting({
@manoj-choudhari-git
manoj-choudhari-git / SettingsController.cs
Created December 30, 2022 14:36
Demo - Azure App Configuration - API Method to read the settings
[Route("api/[controller]")]
[ApiController]
public class SettingsController : ControllerBase
{
private readonly IConfiguration _configuration;
public SettingsController(IConfiguration configuration)
{
this._configuration = configuration;
}
@manoj-choudhari-git
manoj-choudhari-git / Program.cs
Created December 30, 2022 14:34
Demo - Azure App Configuration - Read Environment Specific Key-Value Pairs
using Microsoft.Extensions.Configuration.AzureAppConfiguration;
using TestApi.Configurations;
public static void Main(string[] args)
{
var builder = WebApplication.CreateBuilder(args);
Console.WriteLine($"Environment: {builder.Environment.EnvironmentName}");
@manoj-choudhari-git
manoj-choudhari-git / commands.sh
Created December 30, 2022 10:32
Azure CLI - App Configuration Service - Export Key Value Pairs to a JSON file
## Export the key-value pairs from App Configuration to JSON file using Connection String
az appconfig kv export --destination file
--format json
--path "./exported-settings.json"
--separator :
--connection-string "{app-config-connection-string}"
## Export the key-value pairs from App Configuration to JSON file using app config store name
az appconfig kv export --destination file
--format json
@manoj-choudhari-git
manoj-choudhari-git / commands.sh
Last active December 30, 2022 09:57
Azure App Configuration Service - Import JSON content as key value pairs
## Import JSON content as key value pairs using connection string of app config store
az appconfig kv import -s file --format json --path "./settings.json"
--content-type "application/json"
--separator :
--depth 2
--connection-string "{app-config-connection-string}"
## Import JSON content as key value pairs using app confit store name
az appconfig kv import -s file --format json --path "./settings.json"
@manoj-choudhari-git
manoj-choudhari-git / settings.json5
Created December 29, 2022 22:32
Sample JSON Setting File
{
"Settings": {
"BackgroundColor": "Green",
"BlockedUsers": null,
"FontSize": 24,
"Logging": {"Test":{"Level":"Debug"},"Prod":{"Level":"Warning"}},
"ReleaseDate": "2020-08-04T12:34:56.789Z",
"RolloutPercentage": [25,50,75,100],
"UseDefaultRouting": false
}
@manoj-choudhari-git
manoj-choudhari-git / Program.cs
Last active December 29, 2022 21:12
Demo - App Configuration Service - To verify percentage filter applied on feature flag
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.FeatureManagement;
using Microsoft.FeatureManagement.FeatureFilters;
static async Task Main(string[] args)
{
var connectionString = Environment.GetEnvironmentVariable("ConnectionString");
IConfigurationRoot configuration =
new ConfigurationBuilder()