Inheritance: System.Windows.DependencyObject, IClosable, IValidator, IErrorsSource
        public void QuickVariableInputViewModel_ValidationErrors_InvalidCharsInPrefix_ContainsError()
        {
            var qviViewModel = new QuickVariableInputViewModel((source, overwrite) => { })
            {
                Suffix = "",
                Prefix = "Cust<>omer().",
                VariableListString = "Fname,LName,TelNo",
                SplitType = "Chars",
                SplitToken = ",",
                Overwrite = false
            };

            VerifyValidationErrors(qviViewModel, "Prefix contains invalid characters");
            Assert.IsTrue(qviViewModel.IsPrefixFocused);

            qviViewModel.Prefix = "Cust(";
            qviViewModel.IsPrefixFocused = false;
            VerifyValidationErrors(qviViewModel, "Prefix contains invalid characters");
            Assert.IsTrue(qviViewModel.IsPrefixFocused);

            qviViewModel.Prefix = "Cust()";
            qviViewModel.IsPrefixFocused = false;
            VerifyValidationErrors(qviViewModel, "Prefix contains invalid characters");
            Assert.IsTrue(qviViewModel.IsPrefixFocused);

            qviViewModel.Prefix = "Customer(x).";
            qviViewModel.IsPrefixFocused = false;
            VerifyValidationErrors(qviViewModel, "Prefix contains invalid characters");
            Assert.IsTrue(qviViewModel.IsPrefixFocused);

            qviViewModel.Prefix = "Customer(-1).";
            qviViewModel.IsPrefixFocused = false;
            VerifyValidationErrors(qviViewModel, "Prefix contains invalid characters");
            Assert.IsTrue(qviViewModel.IsPrefixFocused);
        }
        public void QuickVariableInputViewModel_Constructor_NullAddToCollectionArguments_ExceptionThrown()
        {
            //------------Setup for test--------------------------
            //------------Execute Test---------------------------
#pragma warning disable 168
            var qviViewModel = new QuickVariableInputViewModel(null);
#pragma warning restore 168
            //------------Assert Results-------------------------
        }
        public void QuickVariableInputViewModel_PreviewRequested_ValidationErrorsReturnsEmpty_PreviewRequestedArgsOutputIsEmpty()
        {
            //------------Setup for test--------------------------
            var qviViewModel = new QuickVariableInputViewModel((source, overwrite) => {} );

            //------------Execute Test---------------------------
            qviViewModel.PreviewViewModel.PreviewCommand.Execute(null);

            //------------Assert Results-------------------------
            //Assert.IsTrue(string.IsNullOrEmpty(qviViewModel.OnPreviewRequestedArgs.Output));
        }
        protected ActivityCollectionDesignerViewModel(ModelItem modelItem)
            : base(modelItem)
        {
            QuickVariableInputViewModel = new QuickVariableInputViewModel(AddToCollection);

            BindingOperations.SetBinding(QuickVariableInputViewModel, QuickVariableInputViewModel.IsClosedProperty, new Binding(ShowQuickVariableInputProperty.Name)
            {
                Source = this,
                Mode = BindingMode.TwoWay,
                Converter = new NegateBooleanConverter()
            });

            BindingOperations.SetBinding(this, ErrorsProperty, new Binding(QuickVariableInputViewModel.ErrorsProperty.Name)
            {
                Source = QuickVariableInputViewModel,
                Mode = BindingMode.TwoWay
            });
        }
        public void QuickVariableInputViewModel_Constructor_WithParameter_SetsDefaultPropertyValues()
        {
            //------------Setup for test--------------------------
            //------------Execute Test---------------------------
            var qviViewModel = new QuickVariableInputViewModel((source, overwrite) => { });

            //------------Assert Results-------------------------
            Assert.IsNotNull(qviViewModel);
            Assert.IsInstanceOfType(qviViewModel, typeof(DependencyObject));
            Assert.AreEqual(string.Empty, qviViewModel.SplitToken);
            Assert.AreEqual(string.Empty, qviViewModel.VariableListString);
            Assert.AreEqual(string.Empty, qviViewModel.Prefix);
            Assert.AreEqual(string.Empty, qviViewModel.Suffix);

            // The following 3 are related - SplitType determines the value of the other 2 properties
            Assert.AreEqual("Chars", qviViewModel.SplitType);
            Assert.IsFalse(qviViewModel.CanAdd);
            Assert.IsTrue(qviViewModel.IsSplitTokenEnabled);
            Assert.IsTrue(qviViewModel.IsOverwriteEnabled);
            Assert.IsTrue(qviViewModel.RemoveEmptyEntries);

            Assert.AreEqual(5, qviViewModel.SplitTypeList.Count);
            CollectionAssert.Contains(qviViewModel.SplitTypeList, QuickVariableInputViewModel.SplitTypeIndex);
            CollectionAssert.Contains(qviViewModel.SplitTypeList, QuickVariableInputViewModel.SplitTypeChars);
            CollectionAssert.Contains(qviViewModel.SplitTypeList, QuickVariableInputViewModel.SplitTypeNewLine);
            CollectionAssert.Contains(qviViewModel.SplitTypeList, QuickVariableInputViewModel.SplitTypeSpace);
            CollectionAssert.Contains(qviViewModel.SplitTypeList, QuickVariableInputViewModel.SplitTypeTab);

            Assert.IsNotNull(qviViewModel.ClearCommand);
            Assert.IsInstanceOfType(qviViewModel.ClearCommand, typeof(DelegateCommand));
            Assert.IsTrue(qviViewModel.ClearCommand.CanExecute(null));

            Assert.IsNotNull(qviViewModel.AddCommand);
            Assert.IsInstanceOfType(qviViewModel.AddCommand, typeof(RelayCommand));
            Assert.IsFalse(qviViewModel.AddCommand.CanExecute(null));

            Assert.IsNotNull(qviViewModel.PreviewViewModel);
            Assert.IsInstanceOfType(qviViewModel.PreviewViewModel, typeof(PreviewViewModel));
            Assert.AreEqual(Visibility.Collapsed, qviViewModel.PreviewViewModel.InputsVisibility);
        }
        static void VerifyValidationErrors(QuickVariableInputViewModel qviViewModel, string message)
        {
            qviViewModel.Validate();
            var errors = qviViewModel.Errors;
            Assert.AreEqual(1, errors.Count);

            var error = errors[0];
            Assert.AreEqual(message, error.Message);
            error.Do();
        }
        public void QuickVariableInputViewModel_ValidationErrors_SetsHelpErrors()
        {
            var qviViewModel = new QuickVariableInputViewModel((source, overwrite) => { })
            {
                Suffix = "",
                Prefix = "Customer().Other<>text",
                VariableListString = "Fname,LName,TelNo",
                SplitType = "Chars",
                SplitToken = ",",
                Overwrite = false
            };

            qviViewModel.Validate();
            Assert.IsNotNull(qviViewModel.Errors);
        }
        public void QuickVariableInputViewModel_ValidationErrors_FunnyRecordsetNotationInPrefix_ContainsError()
        {
            var qviViewModel = new QuickVariableInputViewModel((source, overwrite) => { })
            {
                Suffix = "",
                Prefix = "Customer().Other<>text",
                VariableListString = "Fname,LName,TelNo",
                SplitType = "Chars",
                SplitToken = ",",
                Overwrite = false
            };

            VerifyValidationErrors(qviViewModel, "Prefix contains invalid characters");
            Assert.IsTrue(qviViewModel.IsPrefixFocused);
        }
        public void QuickVariableInputViewModel_ValidationErrors_BlankValueInVariableList_ContainsError()
        {
            var qviViewModel = new QuickVariableInputViewModel((source, overwrite) => { })
            {
                Suffix = "",
                Prefix = "Customer().",
                VariableListString = "",
                SplitType = "Chars",
                SplitToken = ",",
                Overwrite = false
            };

            VerifyValidationErrors(qviViewModel, "Variable List String can not be blank/empty");
            Assert.IsTrue(qviViewModel.IsVariableListFocused);
        }
        public void QuickVariableInputViewModel_ValidationErrors_BlankValueForCharSplit_ContainsError()
        {
            var qviViewModel = new QuickVariableInputViewModel((source, overwrite) => { })
            {
                Suffix = "",
                Prefix = "Customer().",
                VariableListString = "Fname,LName,TelNo",
                SplitType = "Chars",
                SplitToken = "",
                Overwrite = false
            };

            VerifyValidationErrors(qviViewModel, "Please supply a value for a Character split");
            Assert.IsTrue(qviViewModel.IsSplitOnFocused);
        }
        public void QuickVariableInputViewModel_ValidationErrors_TextForIndexSplit_ContainsError()
        {
            var qviViewModel = new QuickVariableInputViewModel((source, overwrite) => { })
            {
                Suffix = "",
                Prefix = "Customer().",
                VariableListString = "Fname,LName,TelNo",
                SplitType = "Index",
                SplitToken = "text",
                Overwrite = false
            };

            VerifyValidationErrors(qviViewModel, "Please supply a whole positive number for an Index split");
            Assert.IsTrue(qviViewModel.IsSplitOnFocused);
        }
        public void QuickVariableInputViewModel_PreviewRequested_AllFieldsPopulatedOverWriteFalse_CorrectPreviewOutput()
        {
            const string Expected = @"1 [[Customer().Fname]]
2 [[Customer().LName]]
3 [[Customer().TelNo]]";

            var qviViewModel = new QuickVariableInputViewModel((source, overwrite) => {} )
            {
                Suffix = "",
                Prefix = "Customer().",
                VariableListString = "Fname,LName,TelNo",
                SplitType = "Chars",
                SplitToken = ",",
                Overwrite = false
            };

            qviViewModel.PreviewViewModel.PreviewCommand.Execute(null);

            Assert.AreEqual(Expected, qviViewModel.PreviewViewModel.Output);
        }
        public void QuickVariableInputViewModel_PreviewRequested_MoreThenThreeItemsBeingAdded_CorrectPreviewOutput()
        {
            const string Expected = @"1 [[Customer().Fname]]
2 [[Customer().LName]]
3 [[Customer().TelNo]]
...";

            var qviViewModel = new QuickVariableInputViewModel((source, overwrite) => {} )
            {
                Suffix = "",
                Prefix = "Customer().",
                VariableListString = "Fname,LName,TelNo,Email",
                SplitType = "Chars",
                SplitToken = ",",
                Overwrite = true
            };

            qviViewModel.PreviewViewModel.PreviewCommand.Execute(null);

            Assert.AreEqual(Expected, qviViewModel.PreviewViewModel.Output);
        }