diff --git a/ManagedCode.FeatureChecker.Tests/ManagedCode.FeatureChecker.Tests.csproj b/ManagedCode.FeatureChecker.Tests/ManagedCode.FeatureChecker.Tests.csproj
index 223c60a..d569dd4 100644
--- a/ManagedCode.FeatureChecker.Tests/ManagedCode.FeatureChecker.Tests.csproj
+++ b/ManagedCode.FeatureChecker.Tests/ManagedCode.FeatureChecker.Tests.csproj
@@ -8,8 +8,9 @@
-
-
+
+
+
runtime; build; native; contentfiles; analyzers; buildtransitive
all
@@ -21,7 +22,7 @@
-
+
diff --git a/ManagedCode.FeatureChecker.Tests/MyEnum.cs b/ManagedCode.FeatureChecker.Tests/MyEnum.cs
new file mode 100644
index 0000000..51f2550
--- /dev/null
+++ b/ManagedCode.FeatureChecker.Tests/MyEnum.cs
@@ -0,0 +1,10 @@
+namespace ManagedCode.FeatureChecker.Tests;
+
+internal enum MyEnum
+{
+ feature1,
+ feature2,
+ feature3,
+ feature4,
+ feature5
+}
\ No newline at end of file
diff --git a/ManagedCode.FeatureChecker.Tests/Tests.cs b/ManagedCode.FeatureChecker.Tests/Tests.cs
index a55cf97..4f4bdcd 100644
--- a/ManagedCode.FeatureChecker.Tests/Tests.cs
+++ b/ManagedCode.FeatureChecker.Tests/Tests.cs
@@ -1,4 +1,4 @@
-using ManagedCode.FeatureChecker;
+using FluentAssertions;
using Xunit;
namespace ManagedCode.FeatureChecker.Tests;
@@ -8,7 +8,24 @@ public class Tests
[Fact]
public void TestDetectorTest()
{
+ var holder = new FeatureHolder();
+ holder.Add(MyEnum.feature1, FeatureStatus.Enabled);
+ holder.Add(MyEnum.feature2, FeatureStatus.Disabled);
+ holder.Add(MyEnum.feature3, FeatureStatus.Enabled);
+ holder.Add(MyEnum.feature4, FeatureStatus.Disabled);
+ holder.Add(MyEnum.feature5, FeatureStatus.Debug);
+ var checker = new FeatureChecker(holder);
+
+ checker.IsDebug(MyEnum.feature5).Should().BeTrue();
+ checker.IsDebug(MyEnum.feature1).Should().BeFalse();
+
+ checker.IsEnabled(MyEnum.feature1).Should().BeTrue();
+ checker.IsEnabled(MyEnum.feature5).Should().BeFalse();
+ checker.IsEnabled(MyEnum.feature2).Should().BeFalse();
+
+ checker.IsDisabled(MyEnum.feature2).Should().BeTrue();
+ checker.IsDisabled(MyEnum.feature3).Should().BeFalse();
+ checker.IsDisabled(MyEnum.feature5).Should().BeFalse();
}
-
}
\ No newline at end of file
diff --git a/ManagedCode.FeatureChecker/FeatureChecker.cs b/ManagedCode.FeatureChecker/FeatureChecker.cs
index 79569d3..bf52e7d 100644
--- a/ManagedCode.FeatureChecker/FeatureChecker.cs
+++ b/ManagedCode.FeatureChecker/FeatureChecker.cs
@@ -2,45 +2,57 @@
namespace ManagedCode.FeatureChecker;
-public class FeatureChecker
+public class FeatureChecker : IFeatureChecker
{
- private readonly ImmutableDictionary _features;
+ private readonly ImmutableDictionary _features;
+
+ public FeatureChecker(IDictionary featureHolder)
+ {
+ _features = featureHolder.ToImmutableDictionary();
+ }
public int Count => _features.Count;
- public FeatureChecker(FeatureHolder featureHolder)
+ public bool IsFeatureExists(Enum feature)
{
- _features = featureHolder.Features;
+ return _features.ContainsKey(feature);
}
- public bool IsFeatureExists(string name)
+ public bool IsEnabled(Enum feature)
{
- return ValidateFeatureName(name)
- ? _features.ContainsKey(name)
- : false;
+ if (_features.TryGetValue(feature, out var status))
+ return status == FeatureStatus.Enabled;
+
+ return false;
}
- public bool TryGetFeatureStatus(string name, out FeatureStatus status)
+ public bool IsDisabled(Enum feature)
{
- status = default;
+ if (_features.TryGetValue(feature, out var status))
+ return status == FeatureStatus.Disabled;
- return ValidateFeatureName(name)
- ? _features.TryGetValue(name, out status)
- : false;
+ return false;
}
- public List GetFeaturesByStatus(FeatureStatus status)
+ public bool IsDebug(Enum feature)
{
- return _features
- .Where(x => x.Value == status)
- .Select(x => x.Key)
- .ToList();
- }
+ if (_features.TryGetValue(feature, out var status))
+ return status == FeatureStatus.Debug;
+ return false;
+ }
- private bool ValidateFeatureName(string featureName)
+ public bool TryGetFeatureStatus(Enum feature, out FeatureStatus status)
{
- return !string.IsNullOrWhiteSpace(featureName);
+ status = default;
+ return _features.TryGetValue(feature, out status);
}
-}
+ public List GetFeaturesByStatus(FeatureStatus status)
+ {
+ return _features
+ .Where(x => x.Value == status)
+ .Select(x => x.Key)
+ .ToList();
+ }
+}
\ No newline at end of file
diff --git a/ManagedCode.FeatureChecker/FeatureHolder.cs b/ManagedCode.FeatureChecker/FeatureHolder.cs
index a11ed60..588f1f0 100644
--- a/ManagedCode.FeatureChecker/FeatureHolder.cs
+++ b/ManagedCode.FeatureChecker/FeatureHolder.cs
@@ -1,61 +1,5 @@
-using System.Collections.Immutable;
-using System.Text.Json.Serialization;
+namespace ManagedCode.FeatureChecker;
-namespace ManagedCode.FeatureChecker;
-public class FeatureHolder
+public class FeatureHolder : Dictionary
{
- private Dictionary _features;
-
- [JsonInclude]
- public ImmutableDictionary Features
- {
- get => _features.ToImmutableDictionary();
- private set => _features = new Dictionary(value);
- }
-
-
- public FeatureHolder()
- {
- _features = new Dictionary();
- }
-
- public bool TryAddFeature(string featureName, FeatureStatus status)
- {
- return ValidateFeatureName(featureName)
- ? _features.TryAdd(featureName, status)
- : false;
- }
-
- public bool TryGetFeatureStatus(string featureName, out FeatureStatus status)
- {
- status = default;
-
- return ValidateFeatureName(featureName)
- ? _features.TryGetValue(featureName, out status)
- : false;
- }
-
- public void RemoveFeature(string featureName)
- {
- if(ValidateFeatureName(featureName))
- {
- _features.Remove(featureName);
- }
- }
-
- public void UpdateFeatureStatus(string featureName, FeatureStatus status)
- {
- if(!ValidateFeatureName(featureName))
- {
- return;
- }
-
- _features[featureName] = status;
- }
-
-
- private bool ValidateFeatureName(string featureName)
- {
- return !string.IsNullOrWhiteSpace(featureName);
- }
-}
+}
\ No newline at end of file
diff --git a/ManagedCode.FeatureChecker/FeatureStatus.cs b/ManagedCode.FeatureChecker/FeatureStatus.cs
index 00bfba5..4556355 100644
--- a/ManagedCode.FeatureChecker/FeatureStatus.cs
+++ b/ManagedCode.FeatureChecker/FeatureStatus.cs
@@ -4,5 +4,5 @@ public enum FeatureStatus
{
Disabled,
Enabled,
- Debug,
-}
+ Debug
+}
\ No newline at end of file
diff --git a/ManagedCode.FeatureChecker/IFeatureChecker.cs b/ManagedCode.FeatureChecker/IFeatureChecker.cs
new file mode 100644
index 0000000..21e176b
--- /dev/null
+++ b/ManagedCode.FeatureChecker/IFeatureChecker.cs
@@ -0,0 +1,12 @@
+namespace ManagedCode.FeatureChecker;
+
+public interface IFeatureChecker
+{
+ int Count { get; }
+ bool IsFeatureExists(Enum feature);
+ bool IsEnabled(Enum feature);
+ bool IsDisabled(Enum feature);
+ bool IsDebug(Enum feature);
+ bool TryGetFeatureStatus(Enum feature, out FeatureStatus status);
+ List GetFeaturesByStatus(FeatureStatus status);
+}
\ No newline at end of file
diff --git a/ManagedCode.FeatureChecker/ManagedCode.FeatureChecker.csproj b/ManagedCode.FeatureChecker/ManagedCode.FeatureChecker.csproj
index f2075a7..f2ad97b 100644
--- a/ManagedCode.FeatureChecker/ManagedCode.FeatureChecker.csproj
+++ b/ManagedCode.FeatureChecker/ManagedCode.FeatureChecker.csproj
@@ -15,9 +15,9 @@
managedcode, Tests, Detector, TestsDetector, unit tests
-
-
-
+
+
+
-
+