Dev2.Activities.Designers2.CommandLine.CommandLineDesignerViewModel.Validate C# (CSharp) Method

Validate() public method

public Validate ( ) : void
return void
        public override void Validate()
        {
            Errors = null;
            var errors = new List<IActionableErrorInfo>();

            Action onError = () => IsCommandFileNameFocused = true;

            string commandValue;
            errors.AddError(CommandFileName.TryParseVariables(out commandValue, onError));

            if(string.IsNullOrWhiteSpace(commandValue))
            {
                errors.Add(new ActionableErrorInfo(onError) { ErrorType = ErrorType.Critical, Message = "Command must have a value" });
            }

            // Always assign property otherwise binding does not update!
            Errors = errors;
        }

Usage Example

        public void CommandLineDesignerViewModel_Validate_CommandFileNameHasInvalidExpression_HasErrors()
        {
            //------------Setup for test--------------------------
            const string CommandFileName = "h]]";
            var viewModel = new CommandLineDesignerViewModel(CreateModelItem(CommandFileName));

            //------------Execute Test---------------------------
            viewModel.Validate();

            //------------Assert Results-------------------------
            Assert.IsNotNull(viewModel.Errors);
            Assert.AreEqual(1, viewModel.Errors.Count);

            var error = viewModel.Errors[0];
            Assert.AreEqual("Invalid expression: opening and closing brackets don't match.", error.Message);
            Assert.AreEqual(ErrorType.Critical, error.ErrorType);

            Assert.IsFalse(viewModel.IsCommandFileNameFocused);
            error.Do();
            Assert.IsTrue(viewModel.IsCommandFileNameFocused);
        }
All Usage Examples Of Dev2.Activities.Designers2.CommandLine.CommandLineDesignerViewModel::Validate