public void AddToData_DuplicateKeysHandling_Ignore() { const string key = "flag1"; FeatureFlag initialFeatureFlag = new FeatureFlagBuilder(key).Version(0).Build(); var flagData = new Dictionary <string, ItemDescriptor> { { key, new ItemDescriptor(1, initialFeatureFlag) } }; var segmentData = new Dictionary <string, ItemDescriptor>(); FlagFileData fileData = new FlagFileData { Flags = new Dictionary <string, FeatureFlag> { { key, new FeatureFlagBuilder(key).Version(1).Build() } } }; FlagFileDataMerger merger = new FlagFileDataMerger(FileDataTypes.DuplicateKeysHandling.Ignore); merger.AddToData(fileData, flagData, segmentData); ItemDescriptor postFeatureFlag = flagData[key]; Assert.Same(initialFeatureFlag, postFeatureFlag.Item); Assert.Equal(1, postFeatureFlag.Version); }
private static FlagFileData ParseJson(ref JReader r) { var ret = new FlagFileData { Flags = new Dictionary <string, FeatureFlag>(), FlagValues = new Dictionary <string, LdValue>(), Segments = new Dictionary <string, Segment>() }; for (var obj = r.Object(); obj.Next(ref r);) { switch (obj.Name.ToString()) { case "flags": for (var subObj = r.ObjectOrNull(); subObj.Next(ref r);) { ret.Flags[subObj.Name.ToString()] = FeatureFlagSerialization.Instance.ReadJson(ref r) as FeatureFlag; } break; case "flagValues": for (var subObj = r.ObjectOrNull(); subObj.Next(ref r);) { ret.FlagValues[subObj.Name.ToString()] = LdValueConverter.ReadJsonValue(ref r); } break; case "segments": for (var subObj = r.ObjectOrNull(); subObj.Next(ref r);) { ret.Segments[subObj.Name.ToString()] = SegmentSerialization.Instance.ReadJson(ref r) as Segment; } break; } } return(ret); }
public void AddToData(FlagFileData data, IDictionary <string, ItemDescriptor> flagsOut, IDictionary <string, ItemDescriptor> segmentsOut) { if (data.Flags != null) { foreach (KeyValuePair <string, FeatureFlag> e in data.Flags) { AddItem(DataModel.Features, flagsOut, e.Key, e.Value); } } if (data.FlagValues != null) { foreach (KeyValuePair <string, LdValue> e in data.FlagValues) { AddItem(DataModel.Features, flagsOut, e.Key, FlagFactory.FlagWithValue(e.Key, e.Value)); } } if (data.Segments != null) { foreach (KeyValuePair <string, Segment> e in data.Segments) { AddItem(DataModel.Segments, segmentsOut, e.Key, e.Value); } } }
public void AddToData_DuplicateKeysHandling_Throw() { const string key = "flag1"; FeatureFlag initialFeatureFlag = new FeatureFlagBuilder(key).Version(0).Build(); var flagData = new Dictionary <string, ItemDescriptor> { { key, new ItemDescriptor(1, initialFeatureFlag) } }; var segmentData = new Dictionary <string, ItemDescriptor>(); FlagFileData fileData = new FlagFileData { Flags = new Dictionary <string, FeatureFlag> { { key, new FeatureFlagBuilder(key).Version(1).Build() } } }; FlagFileDataMerger merger = new FlagFileDataMerger(FileDataTypes.DuplicateKeysHandling.Throw); Exception err = Assert.Throws <Exception>(() => { merger.AddToData(fileData, flagData, segmentData); }); Assert.Equal("in \"features\", key \"flag1\" was already defined", err.Message); ItemDescriptor postFeatureFlag = flagData[key]; Assert.Same(initialFeatureFlag, postFeatureFlag.Item); Assert.Equal(1, postFeatureFlag.Version); }