示例#1
0
        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));
            }
        }
        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));
        }
示例#4
0
        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"));
        }