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 SaveCommandExecutedWhereSaveCallbackIsNullExpectedNoException() { var config = new Configuration.Settings.Configuration("localhost"); var mainViewModel = new MainViewModel(config.ToXml(), null, null, null); mainViewModel.SaveCommand.Execute(null); }
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 ToXmlExpectedReturnsXml() { var config = new Configuration.Settings.Configuration("localhost"); var result = config.ToXml(); Assert.IsNotNull(result); Assert.IsInstanceOfType(result, typeof(XElement)); }
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."); }
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."); }
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."); }
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."); }
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 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."); }
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 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 ToXmlExpectedReturnsXml() { var config = new Configuration.Settings.Configuration("localhost"); var result = config.ToXml(); Assert.IsNotNull(result); Assert.IsInstanceOfType(result, typeof(XElement)); }
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 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 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"); }