Example #1
0
        public void SaveCommandExecutedWhereSaveCallbackIsNullExpectedNoException()
        {
            var config        = new Configuration.Settings.Configuration("localhost");
            var mainViewModel = new MainViewModel(config.ToXml(), null, null, null);

            mainViewModel.SaveCommand.Execute(null);
        }
Example #2
0
        public void SaveCommandExecutedWhereSaveCallbackIsNullExpectedNoException()
        {
            Configuration.Settings.Configuration config = new Configuration.Settings.Configuration("localhost");
            MainViewModel mainViewModel = new MainViewModel(config.ToXml(), null, null, null);

            mainViewModel.SaveCommand.Execute(null);
        }
        public void HasErrorReturnsTrueWhenBackupError()
        {
            var config = new Configuration.Settings.Configuration(XmlResource.Fetch("Settings"));

            config.Backup.Error = "Error";
            Assert.IsTrue(config.HasError);
        }
        public void LoggingSettingChangedExpectsHasChangesTrueWhenNotInitializating()
        {
            var config = new Configuration.Settings.Configuration(XmlResource.Fetch("Settings"));

            config.Logging.IsDataAndTimeLogged = true;
            Assert.IsTrue(config.HasChanges);
        }
        public void ToXmlExpectedInvokesToXmlForEachProperty()
        {
            var config = new Configuration.Settings.Configuration("localhost");
            var result = config.ToXml();

            var properties = config.GetType().GetProperties();

            foreach (var property in properties)
            {
                var value = property.GetValue(config);

                Version      version;
                SettingsBase settings;

                if ((settings = value as SettingsBase) != null)
                {
                    var expected = settings.ToXml().ToString(SaveOptions.DisableFormatting);

                    var actual = result.Element(settings.SettingName).ToString(SaveOptions.DisableFormatting);

                    Assert.AreEqual(expected, actual);
                }
                else if ((version = value as Version) != null)
                {
                    var actual   = result.AttributeSafe(property.Name);
                    var expected = version.ToString(2);
                    Assert.AreEqual(expected, actual);
                }
            }
        }
        public void ToXmlExpectedReturnsXml()
        {
            var config = new Configuration.Settings.Configuration("localhost");
            var result = config.ToXml();

            Assert.IsNotNull(result);
            Assert.IsInstanceOfType(result, typeof(XElement));
        }
        //
        // Static helpers
        //


        #region ValidateInitializesAllProperties

        static void ValidateInitializesAllProperties(Configuration.Settings.Configuration config)
        {
            var properties = config.GetType().GetProperties();

            foreach (var value in properties.Select(property => property.GetValue(config)))
            {
                Assert.IsNotNull(value);
            }
        }
        public void LoggingSettingsConstructionWithPostWorkflowExpectSettingsSet()
        {
            var config  = new Configuration.Settings.Configuration(XmlResource.Fetch("SettingsWithPostWorkflow"));
            var logging = config.Logging;

            Assert.IsTrue(logging.RunPostWorkflow);
            Assert.IsNotNull(logging.PostWorkflow);
            Assert.IsTrue(logging.Workflows.Any(wf => wf.ResourceID == logging.PostWorkflow.ResourceID));
            Assert.IsFalse(logging.IsInitializing);
        }
Example #9
0
        public void LoggingSettingsConstructionWithPostWorkflowExpectSettingsSet()
        {
            var config = new Configuration.Settings.Configuration(XmlResource.Fetch("SettingsWithPostWorkflow"));
            var logging = config.Logging;

            Assert.IsTrue(logging.RunPostWorkflow);
            Assert.IsNotNull(logging.PostWorkflow);
            Assert.IsTrue(logging.Workflows.Any(wf => wf.ResourceID == logging.PostWorkflow.ResourceID));
            Assert.IsFalse(logging.IsInitializing);
        }
Example #10
0
        public void SaveCommandExecutedWhereSaveCallbackThrowsExceptionExpectedErrorInErrorsCollection()
        {
            var config = new Configuration.Settings.Configuration("localhost");

            var mainViewModel = new MainViewModel(config.ToXml(), x =>
            {
                throw new Exception();
            }, null, null);

            mainViewModel.SaveCommand.Execute(null);

            Assert.AreEqual(1, mainViewModel.Errors.Count, "When the save callback throws an exception an error is expected.");
            Assert.AreEqual(Visibility.Visible, mainViewModel.ErrorsVisible, "When there are errors the ErrorsVisible property should have a value of visible.");
        }
Example #11
0
        public void CancelCommandExecutedExpectedCancelCallbackInvoked()
        {
            var callbackExecuted = false;
            var config           = new Configuration.Settings.Configuration("localhost");

            var mainViewModel = new MainViewModel(config.ToXml(), null, () =>
            {
                callbackExecuted = true;
            }, null);

            mainViewModel.CancelCommand.Execute(null);

            Assert.IsTrue(callbackExecuted, "The cancel callback was not invoked.");
        }
Example #12
0
        public void SaveCommandExecutedWhereSaveCallbackThrowsExceptionExpectedErrorInErrorsCollection()
        {
            Configuration.Settings.Configuration config = new Configuration.Settings.Configuration("localhost");

            MainViewModel mainViewModel = new MainViewModel(config.ToXml(), x =>
            {
                throw new Exception();
            }, null, null);

            mainViewModel.SaveCommand.Execute(null);

            Assert.AreEqual(1, mainViewModel.Errors.Count, "When the save callback throws an exception an error is expected.");
            Assert.AreEqual(Visibility.Visible, mainViewModel.ErrorsVisible, "When there are errors the ErrorsVisible property should have a value of visible.");
        }
        public void LoggingSettingsConstructionEmptyExpectEmptyWorkflowsAndFalseSettings()
        {
            var config  = new Configuration.Settings.Configuration(XmlResource.Fetch("Settings"));
            var logging = config.Logging;

            Assert.IsTrue(logging.ServiceInput == "");
            Assert.IsTrue(logging.LogFileDirectory == "");
            Assert.IsFalse(logging.LogAll);
            Assert.IsTrue(logging.NestedLevelCount == 0);
            Assert.IsFalse(logging.IsOutputLogged);
            Assert.IsFalse(logging.IsInputLogged);
            Assert.IsFalse(logging.IsDataAndTimeLogged);
            Assert.IsFalse(logging.IsDurationLogged);
            Assert.IsFalse(logging.IsTypeLogged);
            Assert.IsFalse(logging.IsVersionLogged);
            Assert.IsFalse(logging.IsLoggingEnabled);
            Assert.IsTrue(logging.Workflows.Count == 0);
        }
Example #14
0
        public void LoggingSettingsConstructionEmptyExpectEmptyWorkflowsAndFalseSettings()
        {
            var config = new Configuration.Settings.Configuration(XmlResource.Fetch("Settings"));
            var logging = config.Logging;

            Assert.IsTrue(logging.ServiceInput == "");
            Assert.IsTrue(logging.LogFileDirectory == "");
            Assert.IsFalse(logging.LogAll);
            Assert.IsTrue(logging.NestedLevelCount == 0);
            Assert.IsFalse(logging.IsOutputLogged);
            Assert.IsFalse(logging.IsInputLogged);
            Assert.IsFalse(logging.IsDataAndTimeLogged);
            Assert.IsFalse(logging.IsDurationLogged);
            Assert.IsFalse(logging.IsTypeLogged);
            Assert.IsFalse(logging.IsVersionLogged);
            Assert.IsFalse(logging.IsLoggingEnabled);
            Assert.IsTrue(logging.Workflows.Count == 0);
        }
Example #15
0
        public void ClearErrorsCommandWhenThereAreErrorsExpectedErrorsCleared()
        {
            var config = new Configuration.Settings.Configuration("localhost");

            var mainViewModel = new MainViewModel(config.ToXml(), null, () =>
            {
                throw new Exception();
            }, null);

            mainViewModel.CancelCommand.Execute(null);

            Assert.AreEqual(1, mainViewModel.Errors.Count, "When the cancel callback throws an exception an error is expected.");

            mainViewModel.ClearErrorsCommand.Execute(null);

            Assert.AreEqual(0, mainViewModel.Errors.Count, "After clear errors is called there shouldn't be any errors.");
            Assert.AreEqual(Visibility.Collapsed, mainViewModel.ErrorsVisible, "When there are no errors the ErrorsVisible property should have a value of collapsed.");
        }
Example #16
0
        public void SaveCommandExecutedExpectedSaveCallbackInvokedWithCorrectData()
        {
            bool callbackExecuted = false;
            Configuration.Settings.Configuration config = new Configuration.Settings.Configuration("localhost");
            string expected = config.ToXml().ToString();
            string actual = "";

            MainViewModel mainViewModel = new MainViewModel(config.ToXml(), x =>
            {
                actual = x.ToString();
                callbackExecuted = true;
                return config.ToXml();
            }, null, null);

            mainViewModel.SaveCommand.Execute(null);

            Assert.IsTrue(callbackExecuted, "The save callback was not invoked.");
            Assert.AreEqual(expected, actual, "The data coming through in the save callback isn't thedata from the configuration object.");
        }
Example #17
0
        public void SaveCommandExecutedExpectedSaveCallbackInvokedWithCorrectData()
        {
            var callbackExecuted = false;
            var config           = new Configuration.Settings.Configuration("localhost");
            var expected         = config.ToXml().ToString();
            var actual           = "";

            var mainViewModel = new MainViewModel(config.ToXml(), x =>
            {
                actual           = x.ToString();
                callbackExecuted = true;
                return(config.ToXml());
            }, null, null);

            mainViewModel.SaveCommand.Execute(null);

            Assert.IsTrue(callbackExecuted, "The save callback was not invoked.");
            Assert.AreEqual(expected, actual, "The data coming through in the save callback isn't thedata from the configuration object.");
        }
Example #18
0
        public void LoggingSettingsConstructionWithoutPostWorkflowExpectWorkflowsAndSettingsSet()
        {
            var config = new Configuration.Settings.Configuration(XmlResource.Fetch("NonEmptySettings"));
            var logging = config.Logging;

            Assert.IsTrue(logging.ServiceInput == "TestInput");
            Assert.IsTrue(logging.LogFileDirectory == "TestDir");
            Assert.IsFalse(logging.LogAll);
            Assert.IsTrue(logging.NestedLevelCount == 2);
            Assert.IsTrue(logging.IsOutputLogged);
            Assert.IsTrue(logging.IsInputLogged);
            Assert.IsTrue(logging.IsDataAndTimeLogged);
            Assert.IsTrue(logging.IsDurationLogged);
            Assert.IsTrue(logging.IsTypeLogged);
            Assert.IsTrue(logging.IsVersionLogged);
            Assert.IsTrue(logging.IsLoggingEnabled);
            Assert.IsTrue(logging.Workflows.Count == 1);
            Assert.IsFalse(logging.RunPostWorkflow);
            Assert.IsNull(logging.PostWorkflow);
        }
        public void LoggingSettingsConstructionWithoutPostWorkflowExpectWorkflowsAndSettingsSet()
        {
            var config  = new Configuration.Settings.Configuration(XmlResource.Fetch("NonEmptySettings"));
            var logging = config.Logging;

            Assert.IsTrue(logging.ServiceInput == "TestInput");
            Assert.IsTrue(logging.LogFileDirectory == "TestDir");
            Assert.IsFalse(logging.LogAll);
            Assert.IsTrue(logging.NestedLevelCount == 2);
            Assert.IsTrue(logging.IsOutputLogged);
            Assert.IsTrue(logging.IsInputLogged);
            Assert.IsTrue(logging.IsDataAndTimeLogged);
            Assert.IsTrue(logging.IsDurationLogged);
            Assert.IsTrue(logging.IsTypeLogged);
            Assert.IsTrue(logging.IsVersionLogged);
            Assert.IsTrue(logging.IsLoggingEnabled);
            Assert.IsTrue(logging.Workflows.Count == 1);
            Assert.IsFalse(logging.RunPostWorkflow);
            Assert.IsNull(logging.PostWorkflow);
        }
        public void SetSelectedSettingsObjectsExpectedSettingsViewModelActivated()
        {
            Configuration.Settings.Configuration config = new Configuration.Settings.Configuration("localhost");
            MainViewModel mainViewModel = new MainViewModel(config.ToXml(), null, null, null);

            var commService = new Mock <ICommunicationService>();

            commService.Setup(s => s.GetResources(It.IsAny <string>())).Returns(new List <WorkflowDescriptor>());
            commService.Setup(s => s.GetDataListInputs(It.IsAny <string>(), It.IsAny <string>()))
            .Returns(new List <DataListVariable> {
                new DataListVariable {
                    Name = "TestInput"
                }
            });

            mainViewModel.CommunicationService = commService.Object;

            mainViewModel.SelectedSettingsObjects = mainViewModel.SettingsObjects[0];

            Assert.IsNotNull(mainViewModel.ActiveItem, "When a settings object is selected the viewmodel isnt activated");
        }
 public void ToXmlExpectedReturnsXml()
 {
     var config = new Configuration.Settings.Configuration("localhost");
     var result = config.ToXml();
     Assert.IsNotNull(result);
     Assert.IsInstanceOfType(result, typeof(XElement));
 }
        public void LoggingSettingChangedExpectsHasChangesFalseWhenInitializating()
        {
            var config = new Configuration.Settings.Configuration(XmlResource.Fetch("Settings"));

            Assert.IsFalse(config.HasChanges);
        }
 public void ConstructorWithValidXmlNullWebServerUriArgumentExpectedThrowsArgumentNullException()
 {
     var config = new Configuration.Settings.Configuration(XmlResource.Fetch("Settings"));
     ValidateInitializesAllProperties(config);
 }
 public void HasErrorReturnsFalse()
 {
     var config = new Configuration.Settings.Configuration(XmlResource.Fetch("Settings"));
     Assert.IsFalse(config.HasError);
 }
 public void ConstructorWithInvalidXmlVersionExpectedThrowsArgumentException()
 {
     var config = new Configuration.Settings.Configuration(new XElement("x", new XElement("y"), new XElement("z")));
 }
 public void ConstructorWithInvalidXmlExpectedThrowsArgumentNullException()
 {
     // ReSharper disable UnusedVariable  
     var config = new Configuration.Settings.Configuration(new XElement("x", new XAttribute("Version", "1.0"), new XElement("y"), new XElement("z")));
     // ReSharper restore UnusedVariable
 }
Example #27
0
 public void ConstructorWithInvalidXmlExpectedThrowsArgumentNullException()
 {
     // ReSharper disable UnusedVariable
     var config = new Configuration.Settings.Configuration(new XElement("x", new XAttribute("Version", "1.0"), new XElement("y"), new XElement("z")));
     // ReSharper restore UnusedVariable
 }
 public void ConstructorWithNullXmlExpectedThrowsArgumentNullException()
 {
     var config = new Configuration.Settings.Configuration((XElement)null);
 }
 public void LoggingSettingChangedExpectsHasChangesFalseWhenInitializating()
 {
     var config = new Configuration.Settings.Configuration(XmlResource.Fetch("Settings"));
     Assert.IsFalse(config.HasChanges);
 }
Example #30
0
 public void ConstructorWithNullWebServerUriExpectedThrowsArgumentNullException()
 {
     // ReSharper disable UnusedVariable
     var config = new Configuration.Settings.Configuration((string)null);
     // ReSharper restore UnusedVariable
 }
 public void ConstructorWithDefaultExpectedInitializesAllProperties()
 {
     var config = new Configuration.Settings.Configuration("localhost");
     ValidateInitializesAllProperties(config);
 }
 public void ConstructorWithNullWebServerUriExpectedThrowsArgumentNullException()
 {
     // ReSharper disable UnusedVariable
     var config = new Configuration.Settings.Configuration((string)null);
     // ReSharper restore UnusedVariable
 }
Example #33
0
        public void SetSelectedSettingsObjectsExpectedSettingsViewModelActivated()
        {
            Configuration.Settings.Configuration config = new Configuration.Settings.Configuration("localhost");
            MainViewModel mainViewModel = new MainViewModel(config.ToXml(), null, null, null);

            var commService = new Mock<ICommunicationService>();

            commService.Setup(s => s.GetResources(It.IsAny<string>())).Returns(new List<WorkflowDescriptor>());
            commService.Setup(s => s.GetDataListInputs(It.IsAny<string>(), It.IsAny<string>()))
                .Returns(new List<DataListVariable> { new DataListVariable { Name = "TestInput" } });

            mainViewModel.CommunicationService = commService.Object;

            mainViewModel.SelectedSettingsObjects = mainViewModel.SettingsObjects[0];

            Assert.IsNotNull(mainViewModel.ActiveItem, "When a settings object is selected the viewmodel isnt activated");
        }
Example #34
0
        public void CancelCommandExecutedExpectedCancelCallbackInvoked()
        {
            bool callbackExecuted = false;
            Configuration.Settings.Configuration config = new Configuration.Settings.Configuration("localhost");

            MainViewModel mainViewModel = new MainViewModel(config.ToXml(), null, () =>
            {
                callbackExecuted = true;
            }, null);

            mainViewModel.CancelCommand.Execute(null);

            Assert.IsTrue(callbackExecuted, "The cancel callback was not invoked.");
        }
 public void LoggingSettingChangedExpectsHasChangesTrueWhenNotInitializating()
 {
     var config = new Configuration.Settings.Configuration(XmlResource.Fetch("Settings"));
     config.Logging.IsDataAndTimeLogged = true;
     Assert.IsTrue(config.HasChanges);
 }
        public void ConstructorWithDefaultExpectedInitializesAllProperties()
        {
            var config = new Configuration.Settings.Configuration("localhost");

            ValidateInitializesAllProperties(config);
        }
        public void ConstructorWithValidXmlArgumentExpectedInitializesAllProperties()
        {
            var config = new Configuration.Settings.Configuration(XmlResource.Fetch("Settings"));

            ValidateInitializesAllProperties(config);
        }
 public void ConstructorWithNullWebServerUriExpectedThrowsArgumentNullException()
 {
     var config = new Configuration.Settings.Configuration((string)null);
 }
Example #39
0
        public void ClearErrorsCommandWhenThereAreErrorsExpectedErrorsCleared()
        {
            Configuration.Settings.Configuration config = new Configuration.Settings.Configuration("localhost");

            MainViewModel mainViewModel = new MainViewModel(config.ToXml(), null, () =>
            {
                throw new Exception();
            }, null);

            mainViewModel.CancelCommand.Execute(null);

            Assert.AreEqual(1, mainViewModel.Errors.Count, "When the cancel callback throws an exception an error is expected.");

            mainViewModel.ClearErrorsCommand.Execute(null);

            Assert.AreEqual(0, mainViewModel.Errors.Count, "After clear errors is called there shouldn't be any errors.");
            Assert.AreEqual(Visibility.Collapsed, mainViewModel.ErrorsVisible, "When there are no errors the ErrorsVisible property should have a value of collapsed.");
        }
 public void ConstructorWithInvalidXmlExpectedThrowsArgumentNullException()
 {
     var config = new Configuration.Settings.Configuration(new XElement("x", new XAttribute("Version", "1.0"), new XElement("y"), new XElement("z")));
 }
        public void ToXmlExpectedInvokesToXmlForEachProperty()
        {
            var config = new Configuration.Settings.Configuration("localhost");
            var result = config.ToXml();

            var properties = config.GetType().GetProperties();
            foreach(var property in properties)
            {
                var value = property.GetValue(config);

                Version version;
                Configuration.Settings.SettingsBase settings;

                if((settings = value as Configuration.Settings.SettingsBase) != null)
                {
                    var expected = settings.ToXml().ToString(SaveOptions.DisableFormatting);
                    // ReSharper disable PossibleNullReferenceException
                    var actual = result.Element(settings.SettingName).ToString(SaveOptions.DisableFormatting);
                    // ReSharper restore PossibleNullReferenceException
                    Assert.AreEqual(expected, actual);
                }
                else if((version = value as Version) != null)
                {
                    var actual = result.AttributeSafe(property.Name);
                    var expected = version.ToString(2);
                    Assert.AreEqual(expected, actual);
                }
            }
        }
        public void ConstructorWithValidXmlNullWebServerUriArgumentExpectedThrowsArgumentNullException()
        {
            var config = new Configuration.Settings.Configuration(XmlResource.Fetch("Settings"));

            ValidateInitializesAllProperties(config);
        }
 public void HasErrorReturnsTrueWhenBackupError()
 {
     var config = new Configuration.Settings.Configuration(XmlResource.Fetch("Settings"));
     config.Backup.Error = "Error";
     Assert.IsTrue(config.HasError);
 }
        public void HasErrorReturnsFalse()
        {
            var config = new Configuration.Settings.Configuration(XmlResource.Fetch("Settings"));

            Assert.IsFalse(config.HasError);
        }
 public void ConstructorWithValidXmlArgumentExpectedInitializesAllProperties()
 {
     var config = new Configuration.Settings.Configuration(XmlResource.Fetch("Settings"));
     ValidateInitializesAllProperties(config);
 }