private void EnsureReferenceInitialized(bool refresh) { EnsureScopeInitialized(); if (!elementScope.IsScopeResolved) { return; } if (referenceInitialized && !refresh) { return; } if (reference != null) { reference.Dispose(); } reference = lookup.CreateReference(elementScope.ScopePath, referenceAttribute.TargetType, (string)base.GetValue()); reference.ElementFound += ReferenceElementFound; reference.ElementDeleted += ReferenceElementDeleted; reference.NameChanged += ReferenceNameChanged; referenceInitialized = true; }
public void then_reference_can_be_fixed_by_loading_section() { ElementLookup elementLookup = Container.Resolve<ElementLookup>(); var reference = elementLookup.CreateReference("/configuration/" + ExceptionHandlingSettings.SectionName); var sourceModel = Container.Resolve<ConfigurationSourceModel>(); sourceModel.AddSection(ExceptionHandlingSettings.SectionName, base.Section); Assert.IsNotNull(reference.Element); }
public void then_element_reference_signals_name_change() { var anyHandler = ehabModel.DescendentElements().Where(x => typeof(ExceptionHandlerData).IsAssignableFrom(x.ConfigurationType)).First(); ElementReference reference = lookup.CreateReference(anyHandler.Path); string newName = string.Empty; reference.NameChanged += (sender, args) => { newName = args.Value; }; anyHandler.Property("Name").Value = "new name"; Assert.IsFalse(string.IsNullOrEmpty(newName)); Assert.IsTrue(newName.Equals("new name")); }
public void then_reference_signals_event_if_reference_is_fixed() { bool elementFoundSignalled = false; ElementLookup elementLookup = Container.Resolve<ElementLookup>(); var reference = elementLookup.CreateReference("/configuration/" + ExceptionHandlingSettings.SectionName); reference.ElementFound += (s, a) => elementFoundSignalled = true; var sourceModel = Container.Resolve<ConfigurationSourceModel>(); sourceModel.AddSection(ExceptionHandlingSettings.SectionName, base.Section); Assert.IsTrue(elementFoundSignalled); }
private void InitializeElementReference(string elementPath) { elementViewModelReference = lookup.CreateReference(elementPath); elementViewModelReference.ElementDeleted += ElementViewModelReferenceElementDeleted; elementViewModelReference.PathChanged += ElementViewModelReferencePathChanged; if (elementViewModelReference.Element != null) { this.elementViewModel = elementViewModelReference.Element; } else { elementViewModelReference.ElementFound += ElementViewModelReferenceElementFound; } }
public void then_has_no_element_if_reference_cannot_be_found() { ElementReference reference = lookup.CreateReference("/path/to/unknown/element"); Assert.IsNull(reference.Element); }
public void then_has_no_element_if_reference_cannot_be_found() { ElementReference reference = lookup.CreateReference("/path/to/unknown/collection", typeof(ConfigurationElement), "element"); Assert.IsNull(reference.Element); }