public void UpsertDefaultConfigValue(string planeName, string key, string value) { ValidateKeyRegistraion(key); IConfigPlane configPlane = GetOrCreateConfigPlane(planeName); configPlane.UpsertDefaultConfigValue(key, value); }
// NB Priority might mention planes that dont exist protected virtual void PrioritisePlanes() { if (Priority != null) { IConfigPlane previousPlane = null; foreach (var plane in _planes) //reset child links { plane.Value.Child = null; } foreach (var priority in Priority) { IConfigPlane currentPlane; //Dont throw exception as priorities might be set before config values //And hence the plane may not exist yet . Hence why we redo priority on a new plane if (!TryGetPlane(priority, out currentPlane)) { continue; } if (previousPlane == null) { _entryPoint = previousPlane = currentPlane; } else { previousPlane.Child = currentPlane; previousPlane = currentPlane; } } } }
public void PrioritisePlanes_SetsOrderAsExpectedIfSetBeforePlanesAdded(string firstPlane, string secondPlane, string thirdPlane, string fourthPlane) { ConfigControllerTestHelper sut = new ConfigControllerTestHelper(); Queue <string> priority = new Queue <string>(); priority.Enqueue(firstPlane); priority.Enqueue(secondPlane); priority.Enqueue(thirdPlane); priority.Enqueue(fourthPlane); sut.Priority = priority; sut.UpsertConfigValue("FirstPlane", "MyConfigContext", "ConfigKey", "ConfigValueFirstPlane"); sut.UpsertConfigValue("SecondPlane", "MyConfigContext", "ConfigKey", "ConfigValueSecondPlane"); sut.UpsertConfigValue("ThirdPlane", "MyConfigContext", "ConfigKey", "ConfigValueThirdPlane"); sut.UpsertConfigValue("FourthPlane", "MyConfigContext", "ConfigKey", "ConfigValueFourthPlane"); IConfigPlane planePointer = sut.GetEntryPoint(); Assert.That(planePointer.PlaneDescriptor.Key.Equals(firstPlane, StringComparison.InvariantCulture)); Assert.That(planePointer.Child.PlaneDescriptor.Key.Equals(secondPlane, StringComparison.InvariantCulture)); Assert.That(planePointer.Child.Child.PlaneDescriptor.Key.Equals(thirdPlane, StringComparison.InvariantCulture)); Assert.That(planePointer.Child.Child.Child.PlaneDescriptor.Key.Equals(fourthPlane, StringComparison.InvariantCulture)); Assert.IsNull(planePointer.Child.Child.Child.Child); }
private bool TryGetPlane(string planeName, out IConfigPlane plane) { IConfigPlane controlledPlane; if (_planes.TryGetValue(planeName, out controlledPlane)) { plane = controlledPlane; return(true); } plane = null; return(false); }