Skip to content

Commit

Permalink
Revert "get settings by correct way (#436)" (#455)
Browse files Browse the repository at this point in the history
This reverts commit 9207741.

Co-authored-by: Basil Kotov <[email protected]>
  • Loading branch information
ilyawzrd and basilkot authored Jul 2, 2020
1 parent 72a9010 commit c7c85ad
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -518,7 +518,7 @@ public bool IsFeatureActive(string featureName)
var compositeChangeToken = new CompositeChangeToken(tokens);
cacheEntry.AddExpirationToken(compositeChangeToken);

var settingJObject = GetSettings();
var settingJObject = InnerGetAllSettings(_themeBlobProvider, CurrentThemeSettingPath);
var result = _featuresAgent.IsActive(featureName, settingJObject);
return result;
});
Expand Down
12 changes: 7 additions & 5 deletions VirtoCommerce.Storefront.Model/Features/FeaturesAgent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ namespace VirtoCommerce.Storefront.Model.Features
{
using System;
using System.Collections.Generic;

using Newtonsoft.Json.Linq;

using VirtoCommerce.Storefront.Model.Features.Exceptions;

public class FeaturesAgent : IFeaturesAgent
Expand All @@ -14,9 +16,9 @@ public FeaturesAgent(string featuresBranchToken = "features")
_featuresBranchToken = featuresBranchToken;
}

public bool IsActive(string featureName, IDictionary<string, object> settings)
public bool IsActive(string featureName, JObject jObject)
{
var features = GetFeatures(settings);
var features = GetFeatures(jObject);

var feature = features.GetFeature(featureName);

Expand All @@ -42,17 +44,17 @@ public bool IsActive(string featureName, IDictionary<string, object> settings)
return result;
}

private List<Feature> GetFeatures(IDictionary<string, object> settings)
private List<Feature> GetFeatures(JObject jObject)
{
List<Feature> result;

try
{
var featuresJson = settings[_featuresBranchToken] as JArray;
var featuresJson = jObject[_featuresBranchToken];

if (featuresJson == null)
{
throw new FeaturesException($"Can't find \"{_featuresBranchToken}\" section ");
throw new FeaturesException($"Can' find \"{_featuresBranchToken}\" section ");
}

result = featuresJson.ToObject<List<Feature>>();
Expand Down
6 changes: 3 additions & 3 deletions VirtoCommerce.Storefront.Model/Features/IFeaturesAgent.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
using System.Collections.Generic;

namespace VirtoCommerce.Storefront.Model.Features
{
using Newtonsoft.Json.Linq;

public interface IFeaturesAgent
{
bool IsActive(string featureName, IDictionary<string, object> settings);
bool IsActive(string featureName, JObject jObject);
}
}
5 changes: 2 additions & 3 deletions VirtoCommerce.Storefront.Tests/Features/FeaturesAgentTests.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
namespace VirtoCommerce.Storefront.Tests.Features
{
using System;
using System.Collections.Generic;
using System.IO;

using Microsoft.Extensions.DependencyInjection;
Expand Down Expand Up @@ -115,7 +114,7 @@ public void IsActive_OrdersBrowsing_ShouldBeInactive()
}
}

private static IDictionary<string, object> ReadSettingsFile(string defaultFileName = "test_data.json")
private static JObject ReadSettingsFile(string defaultFileName = "test_data.json")
{
var currentDirectory = Environment.CurrentDirectory;
var path = Path.Combine(currentDirectory, "Features", "Samples", defaultFileName);
Expand All @@ -124,7 +123,7 @@ private static IDictionary<string, object> ReadSettingsFile(string defaultFileNa
try
{
var text = File.ReadAllText(fileInfo.FullName);
return JObject.Parse(text).ToObject<Dictionary<string, object>>();
return JObject.Parse(text);
}
catch (Exception e)
{
Expand Down

0 comments on commit c7c85ad

Please sign in to comment.