Beispiel #1
0
        private bool SetConfiguration(XElement configurationXml)
        {
            // Check for null
            if (configurationXml == null)
            {
                SetError("'configurationXML' of the MainViewModel was null.");
                return(false);
            }

            // Try parse configuration xml
            try
            {
                Configuration = new Settings.Configuration(configurationXml);
                Configuration.PropertyChanged += ConfigurationPropertyChanged;
            }
            catch (Exception)
            {
                SetError(string.Format("Error parsing '{0}' input.", configurationXml));
                return(false);
            }

            // Try create settings graph
            try
            {
                SettingsObjects = SettingsObject.BuildGraph(Configuration);
            }
            catch (Exception)
            {
                SetError(string.Format("Error building settings graph from '{0}'.", configurationXml));
                return(false);
            }

            _initConfigXml = configurationXml;
            return(true);
        }
        public void BuildGraphWhereObjectsContainCircularReferencesExpectedCircularReferencesAreIgnored()
        {
            // Create object graph
            MockSettingsObjectA settingsObjectA = new MockSettingsObjectA
            {
                SettingsC = new MockSettingsObjectC(),
            };

            settingsObjectA.SettingsC.SettingsA = settingsObjectA;

            List <SettingsObject> settingsGraph = SettingsObject.BuildGraph(settingsObjectA);

            Assert.AreEqual(settingsObjectA.SettingsC, settingsGraph[0].Object, "Properties at root level aren't being found.");
            Assert.AreEqual(0, settingsGraph[0].Children.Count, "settingsObjectA.SettingsC should have no children because this would be a circular reference.");
            Assert.AreEqual(1, settingsGraph.Count, "One root node was expected for settingsObjectA.SettingsC.");
        }
        public void BuildGraph()
        {
            // Create object graph
            MockSettingsObjectA settingsObjectA = new MockSettingsObjectA
            {
                SettingsB = new MockSettingsObjectB(),
                SettingsC = new MockSettingsObjectC
                {
                    SettingsA = new MockSettingsObjectA()
                },
            };

            List <SettingsObject> settingsGraph = SettingsObject.BuildGraph(settingsObjectA);

            Assert.AreEqual(settingsObjectA.SettingsB, settingsGraph[0].Object, "Properties at root level aren't being found.");
            Assert.AreEqual(settingsObjectA.SettingsC, settingsGraph[1].Object, "Properties at root level aren't being found.");
            Assert.AreEqual(settingsObjectA.SettingsC.SettingsA, settingsGraph[1].Children[0].Object, "Properties aren't being found in recursive call.");

            Assert.AreEqual(0, settingsGraph[0].Children.Count, "settingsObjectA.SettingsB shouldn't have any children since it's properties are null.");
            Assert.AreEqual(1, settingsGraph[1].Children.Count, "settingsObjectA.SettingsC should only have one child.");
            Assert.AreEqual(0, settingsGraph[1].Children[0].Children.Count, "settingsObjectA.SettingsC.SettingsA shouldn't have any children since it's properties are null.");

            Assert.AreEqual(2, settingsGraph.Count, "Two root nodes were expected, one for settingsObjectA.SettingsB and one for settingsObjectA.SettingsC.");
        }