public void GivenViewModelAndCalculationThrowsKernelCalculationException_WhenCalculating_ThenErrorMessagesLogged() { // Given var viewModel = new MainViewModel(); using (new BalancedFieldLengthCalculationModuleFactoryConfig()) { var instance = (TestBalancedFieldLengthCalculationModuleFactory) BalancedFieldLengthCalculationModuleFactory.Instance; TestBalancedFieldLengthCalculationModule testModule = instance.TestModule; testModule.ThrowKernelCalculationException = true; // Precondition MessageWindowViewModel messageWindowViewModel = viewModel.MessageWindowViewModel; ReadOnlyObservableCollection <MessageContext> logMessages = messageWindowViewModel.Messages; Assert.That(logMessages, Is.Empty); // When viewModel.CalculateCommand.Execute(null); // Then Assert.That(viewModel.OutputViewModel, Is.Null); Assert.That(logMessages, Has.Count.EqualTo(2)); Assert.That(logMessages.Select(m => m.MessageType), Is.All.EqualTo(MessageType.Error)); Assert.That(logMessages[0].MessageType, Is.EqualTo(MessageType.Error)); Assert.That(logMessages[0].Message, Is.EqualTo("Calculation failed.")); Assert.That(logMessages[1].MessageType, Is.EqualTo(MessageType.Error)); Assert.That(logMessages[1].Message, Is.EqualTo("Exception")); } }
public void Setup() { _translator = Substitute.For <ITranslator>(); _translator.GetTranslation(Arg.Any <string>(), Arg.Any <string>()).Returns(info => info.ArgAt <string>(1)); _soundPlayer = Substitute.For <ISoundPlayer>(); _viewModel = new MessageWindowViewModel(_translator, _soundPlayer); }
public void GivenViewModelAndCalculationSuccessful_WhenCalculating_ThenOutputGenerated() { // Given var random = new Random(21); var calculatedOutput = new BalancedFieldLengthOutput(random.NextDouble(), random.NextDouble()); var viewModel = new MainViewModel(); using (new BalancedFieldLengthCalculationModuleFactoryConfig()) { var instance = (TestBalancedFieldLengthCalculationModuleFactory) BalancedFieldLengthCalculationModuleFactory.Instance; TestBalancedFieldLengthCalculationModule testModule = instance.TestModule; testModule.Output = calculatedOutput; // Precondition MessageWindowViewModel messageWindowViewModel = viewModel.MessageWindowViewModel; Assert.That(messageWindowViewModel.Messages, Is.Empty); // When viewModel.CalculateCommand.Execute(null); // Then OutputViewModel outputViewModel = viewModel.OutputViewModel; Assert.That(outputViewModel, Is.Not.Null); Assert.That(outputViewModel.BalancedFieldLengthDistance, Is.EqualTo(calculatedOutput.Distance)); Assert.That(outputViewModel.BalancedFieldLengthVelocity, Is.EqualTo(calculatedOutput.Velocity)); Assert.That(messageWindowViewModel.Messages, Has.Count.EqualTo(1)); MessageContext message = messageWindowViewModel.Messages.Single(); Assert.That(message.MessageType, Is.EqualTo(MessageType.Info)); Assert.That(message.Message, Is.EqualTo("Calculation completed.")); } }
public void GivenViewModelWithMessages_WhenAddingNewMessage_ThenMessageAddedAtHead() { // Given var messageOne = new MessageContext(MessageType.Warning, "Message1"); var viewModel = new MessageWindowViewModel(); viewModel.AddMessage(messageOne); // Precondition CollectionAssert.AreEqual(new[] { messageOne }, viewModel.Messages); var messageTwo = new MessageContext(MessageType.Warning, "Message2"); // When viewModel.AddMessage(messageTwo); // Then CollectionAssert.AreEqual(new[] { messageTwo, messageOne }, viewModel.Messages); }
private void Calculate() { DataModelValidatorResult validationResult = GetValidationResult(); if (validationResult != DataModelValidatorResult.ValidResult) { LogValidationResultMessages(validationResult); return; } try { IBalancedFieldLengthCalculationModuleFactory factory = BalancedFieldLengthCalculationModuleFactory.Instance; IBalancedFieldLengthCalculationModule calculationModule = factory.CreateModule(); BalancedFieldLengthOutput output = calculationModule.Calculate(calculation); OutputViewModel = new OutputViewModel(output); MessageWindowViewModel.AddMessage(new MessageContext(MessageType.Info, Resources.MainViewModel_Calculate_Calculation_completed)); } catch (Exception e) when(e is CreateKernelDataException || e is KernelCalculationException) { MessageWindowViewModel.AddMessage(new MessageContext(MessageType.Error, e.Message)); MessageWindowViewModel.AddMessage(new MessageContext(MessageType.Error, Resources.MainViewModel_Calculate_Calculation_failed)); } }
public static void Constructor_ExpectedValues() { // Call var viewModel = new MessageWindowViewModel(); // Assert Assert.That(viewModel.Messages, Is.Not.Null.And.Empty); }
private static DialogResult MessageBox(MessageViewModel messageViewModel, BottomPanelButtons buttons) { var viewModel = new MessageWindowViewModel(messageViewModel, buttons); var window = new MessageWindow(viewModel); window.ShowDialog(); return(viewModel.DialogResult); }
private void LogValidationResultMessages(DataModelValidatorResult validationResult) { foreach (string validationMessage in validationResult.ValidationMessages) { MessageWindowViewModel.AddMessage(new MessageContext(MessageType.Error, validationMessage)); } MessageWindowViewModel.AddMessage(new MessageContext(MessageType.Error, Resources.MainViewModel_Calculate_Calculation_failed)); }
public static MessageDialogResultButton Show(Window owner, String content, String titile, String icon, MessageDialogButtons buttons) { MessageWindowViewModel vm = new MessageWindowViewModel(titile, content, icon, buttons); var dialog = new MessageWindow() { DataContext = vm, Owner = owner }; dialog.ShowDialog(); return vm.ResultButton; }
public MessageWindow(string message, string caption, MessageWindowButtons buttons, MessageWindowIcon icon) { InitializeComponent(); MessageText.Text = message; Title = caption; SetButtons(buttons); SetIcon(icon); _messageWindowVM = new MessageWindowViewModel(buttons); _messageWindowVM.CloseViewAction = delegate(bool?result) { DialogResult = result; }; DataContext = _messageWindowVM; }
public void GivenViewModelWithInvalidCalculation_WhenCalculationPressed_ThenErrorLoggedAndInputNotSent() { // Given var random = new Random(21); var viewModel = new MainViewModel(); TabControlViewModel tabControlViewModel = viewModel.TabControlViewModel; ObservableCollection <ITabViewModel> tabs = tabControlViewModel.Tabs; // Precondition Assert.That(tabs, Has.Count.EqualTo(3)); Assert.That(tabs[0], Is.TypeOf <GeneralSimulationSettingsTabViewModel>()); Assert.That(tabs[1], Is.TypeOf <EngineSettingsTabViewModel>()); Assert.That(tabs[2], Is.TypeOf <AircraftDataTabViewModel>()); var generalSimulationSettingsViewModel = (GeneralSimulationSettingsTabViewModel)tabs[0]; var engineSettingsViewModel = (EngineSettingsTabViewModel)tabs[1]; var aircraftDataViewModel = (AircraftDataTabViewModel)tabs[2]; SetGeneralSettings(generalSimulationSettingsViewModel, random.Next()); SetEngineData(engineSettingsViewModel, random.Next()); SetAircraftData(aircraftDataViewModel, random.Next()); aircraftDataViewModel.TakeOffWeight = double.NaN; // Set an invalid value using (new BalancedFieldLengthCalculationModuleFactoryConfig()) { var instance = (TestBalancedFieldLengthCalculationModuleFactory) BalancedFieldLengthCalculationModuleFactory.Instance; TestBalancedFieldLengthCalculationModule testModule = instance.TestModule; // Precondition MessageWindowViewModel messageWindowViewModel = viewModel.MessageWindowViewModel; Assert.That(messageWindowViewModel.Messages, Is.Empty); // When viewModel.CalculateCommand.Execute(null); // Then Assert.That(testModule.InputCalculation, Is.Null); OutputViewModel outputViewModel = viewModel.OutputViewModel; Assert.That(outputViewModel, Is.Null); IEnumerable <MessageType> messageTypes = messageWindowViewModel.Messages.Select(m => m.MessageType); Assert.That(messageTypes, Is.All.EqualTo(MessageType.Error)); MessageContext firstMessage = messageWindowViewModel.Messages.First(); Assert.That(firstMessage.Message, Is.EqualTo("Calculation failed.")); } }
public void AddMessage_MessageNull_ThrowsArgumentNullException() { // Setup var viewModel = new MessageWindowViewModel(); // Call TestDelegate call = () => viewModel.AddMessage(null); // Assert Assert.That(call, Throws.ArgumentNullException .With.Property(nameof(ArgumentNullException.ParamName)) .EqualTo("message")); }
public void ButtonsOkTest() { var model = new MessageWindowViewModel(MessageWindowButtons.OK); model.CloseViewAction = CloseAction; Assert.IsFalse(model.ButtonLeftCommand.IsExecutable); Assert.IsFalse(model.ButtonMiddleCommand.IsExecutable); Assert.IsTrue(model.ButtonRightCommand.IsExecutable); model.ButtonRightCommand.Execute(null); Assert.AreEqual(MessageWindowResponse.OK, model.Response); Assert.AreEqual(true, _closeDialogResult); }
/// <summary> /// Creates a new instance of <see cref="MainViewModel"/>. /// </summary> public MainViewModel() { calculation = new BalancedFieldLengthCalculation(); #if DEBUG ConfigureSimulationSettings(calculation.SimulationSettings); ConfigureAircraftData(calculation.AircraftData); ConfigureEngineData(calculation.EngineData); #endif InitializeValidationRuleProviders(); TabControlViewModel tabControlViewModel = CreateTabControlViewModel(); TabControlViewModel = tabControlViewModel; MessageWindowViewModel = new MessageWindowViewModel(); OutputViewModel = null; CalculateCommand = new RelayCommand(Calculate); }
public void Setup() { _soundPlayer = Substitute.For <ISoundPlayer>(); _viewModel = new MessageWindowViewModel(new MessageWindowTranslation(), _soundPlayer); }
public MessageWindow(MessageWindowViewModel viewModel) { DataContext = viewModel; InitializeComponent(); }
public void InitTest() { var model = new MessageWindowViewModel(); Assert.AreEqual(MessageWindowResponse.Cancel, model.Response); }