Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.Security.Cryptography;
using System.Text;
using AzureAppConfigurationEmulator.Common;
using OpenTelemetry.Trace;

namespace AzureAppConfigurationEmulator.ConfigurationSettings;

Expand Down Expand Up @@ -41,11 +42,21 @@ public ConfigurationSetting Create(
string? value = null,
IDictionary<string, string>? tags = null)
{
using var activity = Telemetry.ActivitySource.StartActivity($"{nameof(ConfigurationSettingFactory)}.{nameof(Create)}");
activity?.SetTag(Telemetry.ConfigurationSettingEtag, etag);
activity?.SetTag(Telemetry.ConfigurationSettingKey, key);
activity?.SetTag(Telemetry.ConfigurationSettingLabel, label);
activity?.SetTag(Telemetry.ConfigurationSettingContentType, contentType);
activity?.SetTag(Telemetry.ConfigurationSettingValue, value);
activity?.SetTag(Telemetry.ConfigurationSettingLastModified, lastModified);
activity?.SetTag(Telemetry.ConfigurationSettingLocked, locked);

if (!string.IsNullOrEmpty(contentType) && !string.IsNullOrEmpty(value))
{
switch (new ContentType(contentType).MediaType)
try
{
case MediaType.FeatureFlag:
if (new ContentType(contentType).MediaType is MediaType.FeatureFlag)
{
return new FeatureFlagConfigurationSetting(
etag,
key,
Expand All @@ -55,6 +66,11 @@ public ConfigurationSetting Create(
label,
contentType,
tags);
}
}
catch (Exception e)
{
activity?.RecordException(e);
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
using AzureAppConfigurationEmulator.ConfigurationSettings;
using NUnit.Framework;

namespace AzureAppConfigurationEmulator.Tests.ConfigurationSettings;

public class ConfigurationSettingFactoryTests
{
private ConfigurationSettingFactory Factory { get; set; }

[SetUp]
public void SetUp()
{
Factory = new ConfigurationSettingFactory();
}

[TestCase("application/json", typeof(ConfigurationSetting))]
[TestCase("application/json;charset=utf-8", typeof(ConfigurationSetting))]
[TestCase("application/vnd.microsoft.appconfig.ff+json", typeof(FeatureFlagConfigurationSetting))]
[TestCase("application/vnd.microsoft.appconfig.ff+json;charset=utf-8", typeof(FeatureFlagConfigurationSetting))]
[TestCase("Invalid.Content.Type", typeof(ConfigurationSetting))]
[TestCase(null, typeof(ConfigurationSetting))]
public void Create_ConfigurationSetting_ContentType(string? contentType, Type expected)
{
// Arrange
const string key = "TestKey";
const string label = "TestLabel";
const string value = "{\"id\":\"TestId\",\"enabled\":true}";

// Act
var setting = Factory.Create(key, label, contentType, value);

// Assert
Assert.That(setting, Is.TypeOf(expected));
}
}
Loading