void Verify_OnSearchTypeChanged_IndexOutOfBounds_DoesNothing(int index)
        {
            //------------Setup for test--------------------------
            var items = new List <FindRecordsTO>
            {
                new FindRecordsTO("xxxx", "Equals", 1),
                new FindRecordsTO("yyyy", "Contains", 2)
            };

            var viewModel = new FindRecordsMultipleCriteriaDesignerViewModel(CreateModelItem(items));

            //------------Precondition---------------------------
            foreach (var dto in items)
            {
                Assert.IsFalse(dto.IsSearchCriteriaEnabled);
                Assert.IsFalse(string.IsNullOrEmpty(dto.SearchCriteria));
            }

            //------------Execute Test---------------------------
            viewModel.SearchTypeUpdatedCommand.Execute(index);

            //------------Assert Results-------------------------
            foreach (var dto in items)
            {
                Assert.IsFalse(dto.IsSearchCriteriaEnabled);
                Assert.IsFalse(string.IsNullOrEmpty(dto.SearchCriteria));
            }
        }
        public void FindRecordsMultipleCriteriaDesignerViewModel_ValidateCollectionItem_ValidatesPropertiesOfTO()
        {
            //------------Setup for test--------------------------
            var mi = ModelItemUtils.CreateModelItem(new DsfFindRecordsMultipleCriteriaActivity());

            mi.SetProperty("DisplayName", "Find");
            mi.SetProperty("FieldsToSearch", "a,b");
            mi.SetProperty("Result", "[[a]]");

            var dto1 = new FindRecordsTO("", "Starts With", 0);
            var dto2 = new FindRecordsTO("", "Ends With", 1);
            var dto3 = new FindRecordsTO("", "Doesn't Start With", 2);
            var dto4 = new FindRecordsTO("", "Doesn't End With", 3);
            var dto5 = new FindRecordsTO("", "Is Between", 4);
            var dto6 = new FindRecordsTO("", "Is Not Between", 5);

            // ReSharper disable PossibleNullReferenceException
            var miCollection  = mi.Properties["ResultsCollection"].Collection;
            var dtoModelItem1 = miCollection.Add(dto1);
            var dtoModelItem2 = miCollection.Add(dto2);
            var dtoModelItem3 = miCollection.Add(dto3);
            var dtoModelItem4 = miCollection.Add(dto4);
            var dtoModelItem5 = miCollection.Add(dto5);
            var dtoModelItem6 = miCollection.Add(dto6);
            // ReSharper restore PossibleNullReferenceException

            var viewModel = new FindRecordsMultipleCriteriaDesignerViewModel(mi);

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

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

            StringAssert.Contains(viewModel.Errors[0].Message, "'Match' cannot be empty");
            Verify_IsFocused(dtoModelItem1, viewModel.Errors[0].Do, "IsSearchCriteriaFocused");

            StringAssert.Contains(viewModel.Errors[1].Message, "'Match' cannot be empty");
            Verify_IsFocused(dtoModelItem2, viewModel.Errors[1].Do, "IsSearchCriteriaFocused");

            StringAssert.Contains(viewModel.Errors[2].Message, "'Match' cannot be empty");
            Verify_IsFocused(dtoModelItem3, viewModel.Errors[2].Do, "IsSearchCriteriaFocused");

            StringAssert.Contains(viewModel.Errors[3].Message, "'Match' cannot be empty");
            Verify_IsFocused(dtoModelItem4, viewModel.Errors[3].Do, "IsSearchCriteriaFocused");

            StringAssert.Contains(viewModel.Errors[4].Message, "'From' cannot be empty");
            Verify_IsFocused(dtoModelItem5, viewModel.Errors[4].Do, "IsFromFocused");

            StringAssert.Contains(viewModel.Errors[5].Message, "'To' cannot be empty");
            Verify_IsFocused(dtoModelItem5, viewModel.Errors[5].Do, "IsToFocused");

            StringAssert.Contains(viewModel.Errors[6].Message, "'From' cannot be empty");
            Verify_IsFocused(dtoModelItem6, viewModel.Errors[6].Do, "IsFromFocused");

            StringAssert.Contains(viewModel.Errors[7].Message, "'To' cannot be empty");
            Verify_IsFocused(dtoModelItem6, viewModel.Errors[7].Do, "IsToFocused");
        }
 static void SetDataListString(FindRecordsMultipleCriteriaDesignerViewModel viewModel)
 {
     viewModel.GetDatalistString = () =>
     {
         const string trueString = "True";
         const string noneString = "None";
         var          datalist   = string.Format("<DataList><var Description=\"\" IsEditable=\"{0}\" ColumnIODirection=\"{1}\" /><a Description=\"\" IsEditable=\"{0}\" ColumnIODirection=\"{1}\" /><b Description=\"\" IsEditable=\"{0}\" ColumnIODirection=\"{1}\" /><h Description=\"\" IsEditable=\"{0}\" ColumnIODirection=\"{1}\" /><r Description=\"\" IsEditable=\"{0}\" ColumnIODirection=\"{1}\" /><rec Description=\"\" IsEditable=\"{0}\" ColumnIODirection=\"{1}\" ><set Description=\"\" IsEditable=\"{0}\" ColumnIODirection=\"{1}\" /></rec></DataList>", trueString, noneString);
         return(datalist);
     };
 }
        public void FindRecordsMultipleCriteriaDesignerViewModel_ValidateCollectionItem_ValidatesPropertiesOfTO()
        {
            //------------Setup for test--------------------------
            var mi = ModelItemUtils.CreateModelItem(new DsfFindRecordsMultipleCriteriaActivity());

            mi.SetProperty("DisplayName", "Find");
            mi.SetProperty("FieldsToSearch", "a,b");
            mi.SetProperty("Result", "[[a]]");

            var dto1 = new FindRecordsTO("", "Starts With", 0);
            var dto2 = new FindRecordsTO("", "Ends With", 1);
            var dto3 = new FindRecordsTO("", "Doesn't Start With", 2);
            var dto4 = new FindRecordsTO("", "Doesn't End With", 3);
            var dto5 = new FindRecordsTO("", "Is Between", 4);
            var dto6 = new FindRecordsTO("", "Is Not Between", 5);


            var miCollection  = mi.Properties["ResultsCollection"].Collection;
            var dtoModelItem1 = miCollection.Add(dto1);
            var dtoModelItem2 = miCollection.Add(dto2);
            var dtoModelItem3 = miCollection.Add(dto3);
            var dtoModelItem4 = miCollection.Add(dto4);
            var dtoModelItem5 = miCollection.Add(dto5);
            var dtoModelItem6 = miCollection.Add(dto6);


            var viewModel = new FindRecordsMultipleCriteriaDesignerViewModel(mi);

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

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


            StringAssert.Contains(viewModel.Errors[0].Message, "'In Field(s)' Cannot have any scalars in this field");

            StringAssert.Contains(viewModel.Errors[1].Message, Warewolf.Resource.Errors.ErrorResource.FindRecordsFromNotNullErrorTest);
            Verify_IsFocused(dtoModelItem5, viewModel.Errors[1].Do, "IsFromFocused");

            StringAssert.Contains(viewModel.Errors[2].Message, Warewolf.Resource.Errors.ErrorResource.FindRecordsToNotNullErrorTest);
            Verify_IsFocused(dtoModelItem5, viewModel.Errors[2].Do, "IsToFocused");

            StringAssert.Contains(viewModel.Errors[3].Message, Warewolf.Resource.Errors.ErrorResource.FindRecordsFromNotNullErrorTest);
            Verify_IsFocused(dtoModelItem6, viewModel.Errors[3].Do, "IsFromFocused");

            StringAssert.Contains(viewModel.Errors[4].Message, Warewolf.Resource.Errors.ErrorResource.FindRecordsToNotNullErrorTest);
            Verify_IsFocused(dtoModelItem6, viewModel.Errors[4].Do, "IsToFocused");
        }
        public void FindRecordsMultipleCriteriaDesignerViewModel_GetRuleSet_OnResult_GetsFourRules()
        {
            //------------Setup for test--------------------------
            var items = new List <FindRecordsTO> {
                new FindRecordsTO("", "", 0)
            };
            var mi        = CreateModelItem(items);
            var viewModel = new FindRecordsMultipleCriteriaDesignerViewModel(mi);

            SetDataListString(viewModel);
            //------------Execute Test---------------------------
            var rulesSet = viewModel.GetRuleSet("Result");

            //------------Assert Results-------------------------
            Assert.IsNotNull(rulesSet);
            Assert.IsInstanceOfType(rulesSet.Rules[0], typeof(IsStringEmptyOrWhiteSpaceRule));
            Assert.IsInstanceOfType(rulesSet.Rules[1], typeof(IsValidExpressionRule));
        }
        public void FindRecordsMultipleCriteriaViewModel_Constructor_PropertiesInitialized()
        {
            //------------Setup for test--------------------------
            var items = new List <FindRecordsTO>
            {
                new FindRecordsTO("xxxx", "=", 1),
                new FindRecordsTO("yyyy", "Contains", 2)
            };


            //------------Execute Test---------------------------
            var viewModel = new FindRecordsMultipleCriteriaDesignerViewModel(CreateModelItem(items));

            //------------Assert Results-------------------------
            Assert.IsNotNull(viewModel.ModelItem);
            Assert.IsNotNull(viewModel.ModelItemCollection);
            Assert.AreEqual("ResultsCollection", viewModel.CollectionName);
            Assert.AreEqual(1, viewModel.TitleBarToggles.Count);
        }
        public void FindRecordsMultipleCriteriaDesignerViewModel_ValidateThis_FieldsToSearchIsNotEmptyAndResultNotEmpty_DoesNotHaveErrors()
        {
            //------------Setup for test--------------------------
            var items = new List <FindRecordsTO> {
                new FindRecordsTO("", "", 0)
            };
            var mi = CreateModelItem(items);

            mi.SetProperty("FieldsToSearch", "[[rec().set]]");
            mi.SetProperty("Result", "[[a]]");
            var viewModel = new FindRecordsMultipleCriteriaDesignerViewModel(mi);

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

            //------------Assert Results-------------------------
            Assert.IsNull(viewModel.Errors);
        }
        public void FindRecordsMultipleCriteriaDesignerViewModel_ValidateThis_FieldsToSearchAndResultIsEmptyOrWhiteSpace_DoesHaveErrors()
        {
            //------------Setup for test--------------------------
            var items = new List <FindRecordsTO> {
                new FindRecordsTO("", "", 0)
            };
            var mi = CreateModelItem(items);

            mi.SetProperty("FieldsToSearch", " ");
            mi.SetProperty("Result", " ");
            var viewModel = new FindRecordsMultipleCriteriaDesignerViewModel(mi);

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

            //------------Assert Results-------------------------
            Assert.AreEqual(2, viewModel.Errors.Count);
            StringAssert.Contains(viewModel.Errors[0].Message, "'In Field(s)' cannot be empty or only white space");
            StringAssert.Contains(viewModel.Errors[1].Message, "'Result' cannot be empty or only white space");
        }
        public void FindRecordsMultipleCriteriaDesignerViewModel_ValidateThis_FieldsToSearchAndResultIsEmptyOrWhiteSpace_DoesHaveErrors()
        {
            //------------Setup for test--------------------------
            var items = new List <FindRecordsTO> {
                new FindRecordsTO("", "", 0)
            };
            var mi = CreateModelItem(items);

            mi.SetProperty("FieldsToSearch", " ");
            mi.SetProperty("Result", " ");
            var viewModel = new FindRecordsMultipleCriteriaDesignerViewModel(mi);

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

            //------------Assert Results-------------------------
            Assert.AreEqual(3, viewModel.Errors.Count);
            StringAssert.Contains(viewModel.Errors[0].Message, Warewolf.Resource.Errors.ErrorResource.FindRecordsInFieldsNotNullErrorTest);
            StringAssert.Contains(viewModel.Errors[1].Message, Warewolf.Resource.Errors.ErrorResource.FindRecordsInFieldsScalarNotAllowedErrorTest);
            StringAssert.Contains(viewModel.Errors[2].Message, Warewolf.Resource.Errors.ErrorResource.FindRecordsInFieldsResultNotNullErrorTest);
        }
        void Verify_OnSearchTypeChanged_IsSearchCriteriaEnabled(string searchType, bool isSearchCriteriaEnabled, bool isSearchCriteriaBlank)
        {
            //------------Setup for test--------------------------
            var findRecordsTO = new FindRecordsTO("xxxx", searchType, 1);

            var items = new List <FindRecordsTO>
            {
                findRecordsTO
            };

            var viewModel = new FindRecordsMultipleCriteriaDesignerViewModel(CreateModelItem(items));

            //------------Precondition---------------------------
            Assert.IsFalse(findRecordsTO.IsSearchCriteriaEnabled);

            //------------Execute Test---------------------------
            viewModel.SearchTypeUpdatedCommand.Execute(0);

            //------------Assert Results-------------------------
            Assert.AreEqual(isSearchCriteriaEnabled, findRecordsTO.IsSearchCriteriaEnabled);
            Assert.AreEqual(isSearchCriteriaBlank, string.IsNullOrEmpty(findRecordsTO.SearchCriteria));
        }
        public void FindRecordsMultipleCriteriaViewModel_UpdateHelp_ShouldCallToHelpViewMode()
        {
            //------------Setup for test--------------------------
            var items = new List <FindRecordsTO>
            {
                new FindRecordsTO("xxxx", "Equals", 1),
                new FindRecordsTO("yyyy", "Contains", 2)
            };

            var mockMainViewModel = new Mock <IShellViewModel>();
            var mockHelpViewModel = new Mock <IHelpWindowViewModel>();

            mockHelpViewModel.Setup(model => model.UpdateHelpText(It.IsAny <string>())).Verifiable();
            mockMainViewModel.Setup(model => model.HelpViewModel).Returns(mockHelpViewModel.Object);
            CustomContainer.Register(mockMainViewModel.Object);

            var viewModel = new FindRecordsMultipleCriteriaDesignerViewModel(CreateModelItem(items));

            //------------Execute Test---------------------------
            viewModel.UpdateHelpDescriptor("help");
            //------------Assert Results-------------------------
            mockHelpViewModel.Verify(model => model.UpdateHelpText(It.IsAny <string>()), Times.Once());
        }
        public void FindRecordsMultipleCriteriaDesignerViewModel_ValidateThis_FieldsToSearchIsNotEmptyAndResultNotEmpty_DoesNotHaveErrors()
        {
            //------------Setup for test--------------------------
            var items = new List<FindRecordsTO> { new FindRecordsTO("", "", 0) };
            var mi = CreateModelItem(items);
            mi.SetProperty("FieldsToSearch", "[[rec().set]]");
            mi.SetProperty("Result", "[[a]]");
            var viewModel = new FindRecordsMultipleCriteriaDesignerViewModel(mi);
            SetDataListString(viewModel);
            //------------Execute Test---------------------------
            viewModel.Validate();

            //------------Assert Results-------------------------
            Assert.IsNull(viewModel.Errors);
        }
        void Verify_OnSearchTypeChanged_IndexOutOfBounds_DoesNothing(int index)
        {
            //------------Setup for test--------------------------
            var items = new List<FindRecordsTO>
            {
                new FindRecordsTO("xxxx", "Equals", 1),
                new FindRecordsTO("yyyy", "Contains", 2)
            };

            var viewModel = new FindRecordsMultipleCriteriaDesignerViewModel(CreateModelItem(items));

            //------------Precondition---------------------------     
            foreach(var dto in items)
            {
                Assert.IsFalse(dto.IsSearchCriteriaEnabled);
                Assert.IsFalse(string.IsNullOrEmpty(dto.SearchCriteria));
            }

            //------------Execute Test---------------------------
            viewModel.SearchTypeUpdatedCommand.Execute(index);

            //------------Assert Results-------------------------
            foreach(var dto in items)
            {
                Assert.IsFalse(dto.IsSearchCriteriaEnabled);
                Assert.IsFalse(string.IsNullOrEmpty(dto.SearchCriteria));
            }
        }
        void Verify_OnSearchTypeChanged_IsSearchCriteriaEnabled(string searchType, bool isSearchCriteriaEnabled, bool isSearchCriteriaBlank, int indexObject = 0)
        {
            //------------Setup for test--------------------------
            var findRecordsTO = new FindRecordsTO("xxxx", searchType, 1);

            var items = new List<FindRecordsTO>
            {
                findRecordsTO
            };

            var viewModel = new FindRecordsMultipleCriteriaDesignerViewModel(CreateModelItem(items));

            //------------Precondition---------------------------           
            Assert.IsFalse(findRecordsTO.IsSearchCriteriaEnabled);

            //------------Execute Test---------------------------
            viewModel.SearchTypeUpdatedCommand.Execute(indexObject);
            //viewModel.SearchTypeUpdatedCommand.Execute(0);

            //------------Assert Results-------------------------
            Assert.AreEqual(isSearchCriteriaEnabled, findRecordsTO.IsSearchCriteriaEnabled);
            Assert.AreEqual(isSearchCriteriaBlank, string.IsNullOrEmpty(findRecordsTO.SearchCriteria));
        }
        public void FindRecordsMultipleCriteriaViewModel_Constructor_PropertiesInitialized()
        {
            //------------Setup for test--------------------------
            var items = new List<FindRecordsTO>
            {
                new FindRecordsTO("xxxx", "=", 1),
                new FindRecordsTO("yyyy", "Contains", 2)
            };


            //------------Execute Test---------------------------
            var viewModel = new FindRecordsMultipleCriteriaDesignerViewModel(CreateModelItem(items));

            //------------Assert Results-------------------------
            Assert.IsNotNull(viewModel.ModelItem);
            Assert.IsNotNull(viewModel.ModelItemCollection);
            Assert.AreEqual("ResultsCollection", viewModel.CollectionName);
            Assert.AreEqual(1, viewModel.TitleBarToggles.Count);
        }
 static void SetDataListString(FindRecordsMultipleCriteriaDesignerViewModel viewModel)
 {
     viewModel.GetDatalistString = () =>
     {
         const string trueString = "True";
         const string noneString = "None";
         var datalist = string.Format("<DataList><var Description=\"\" IsEditable=\"{0}\" ColumnIODirection=\"{1}\" /><a Description=\"\" IsEditable=\"{0}\" ColumnIODirection=\"{1}\" /><b Description=\"\" IsEditable=\"{0}\" ColumnIODirection=\"{1}\" /><h Description=\"\" IsEditable=\"{0}\" ColumnIODirection=\"{1}\" /><r Description=\"\" IsEditable=\"{0}\" ColumnIODirection=\"{1}\" /><rec Description=\"\" IsEditable=\"{0}\" ColumnIODirection=\"{1}\" ><set Description=\"\" IsEditable=\"{0}\" ColumnIODirection=\"{1}\" /></rec></DataList>", trueString, noneString);
         return datalist;
     };
 }
        public void FindRecordsMultipleCriteriaDesignerViewModel_ValidateCollectionItem_ValidatesPropertiesOfTO()
        {
            //------------Setup for test--------------------------
            var mi = ModelItemUtils.CreateModelItem(new DsfFindRecordsMultipleCriteriaActivity());
            mi.SetProperty("DisplayName", "Find");
            mi.SetProperty("FieldsToSearch", "a,b");
            mi.SetProperty("Result", "[[a]]");

            var dto1 = new FindRecordsTO("", "Starts With", 0);
            var dto2 = new FindRecordsTO("", "Ends With", 1);
            var dto3 = new FindRecordsTO("", "Doesn't Start With", 2);
            var dto4 = new FindRecordsTO("", "Doesn't End With", 3);
            var dto5 = new FindRecordsTO("", "Is Between", 4);
            var dto6 = new FindRecordsTO("", "Is Not Between", 5);

            // ReSharper disable PossibleNullReferenceException
            var miCollection = mi.Properties["ResultsCollection"].Collection;
            var dtoModelItem1 = miCollection.Add(dto1);
            var dtoModelItem2 = miCollection.Add(dto2);
            var dtoModelItem3 = miCollection.Add(dto3);
            var dtoModelItem4 = miCollection.Add(dto4);
            var dtoModelItem5 = miCollection.Add(dto5);
            var dtoModelItem6 = miCollection.Add(dto6);
            // ReSharper restore PossibleNullReferenceException

            var viewModel = new FindRecordsMultipleCriteriaDesignerViewModel(mi);
            SetDataListString(viewModel);
            //------------Execute Test---------------------------
            viewModel.Validate();

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

            StringAssert.Contains(viewModel.Errors[0].Message, "'Match' cannot be empty");
            Verify_IsFocused(dtoModelItem1, viewModel.Errors[0].Do, "IsSearchCriteriaFocused");

            StringAssert.Contains(viewModel.Errors[1].Message, "'Match' cannot be empty");
            Verify_IsFocused(dtoModelItem2, viewModel.Errors[1].Do, "IsSearchCriteriaFocused");

            StringAssert.Contains(viewModel.Errors[2].Message, "'Match' cannot be empty");
            Verify_IsFocused(dtoModelItem3, viewModel.Errors[2].Do, "IsSearchCriteriaFocused");

            StringAssert.Contains(viewModel.Errors[3].Message, "'Match' cannot be empty");
            Verify_IsFocused(dtoModelItem4, viewModel.Errors[3].Do, "IsSearchCriteriaFocused");

            StringAssert.Contains(viewModel.Errors[4].Message, "'Match' cannot be empty");
            Verify_IsFocused(dtoModelItem5, viewModel.Errors[4].Do, "IsSearchCriteriaFocused");

            StringAssert.Contains(viewModel.Errors[5].Message, "'From' cannot be empty");
            Verify_IsFocused(dtoModelItem5, viewModel.Errors[5].Do, "IsFromFocused");

            StringAssert.Contains(viewModel.Errors[6].Message, "'To' cannot be empty");
            Verify_IsFocused(dtoModelItem5, viewModel.Errors[6].Do, "IsToFocused");

            StringAssert.Contains(viewModel.Errors[7].Message, "'Match' cannot be empty");
            Verify_IsFocused(dtoModelItem6, viewModel.Errors[7].Do, "IsSearchCriteriaFocused");

            StringAssert.Contains(viewModel.Errors[9].Message, "'To' cannot be empty");
            Verify_IsFocused(dtoModelItem6, viewModel.Errors[9].Do, "IsToFocused");




        }
 public void FindRecordsMultipleCriteriaDesignerViewModel_GetRuleSet_OnResult_GetsFourRules()
 {
     //------------Setup for test--------------------------
     var items = new List<FindRecordsTO> { new FindRecordsTO("", "", 0) };
     var mi = CreateModelItem(items);
     var viewModel = new FindRecordsMultipleCriteriaDesignerViewModel(mi);
     SetDataListString(viewModel);
     //------------Execute Test---------------------------
     var rulesSet = viewModel.GetRuleSet("Result");
     //------------Assert Results-------------------------
     Assert.IsNotNull(rulesSet);
     Assert.IsInstanceOfType(rulesSet.Rules[0], typeof(IsStringEmptyOrWhiteSpaceRule));
     Assert.IsInstanceOfType(rulesSet.Rules[1], typeof(IsValidExpressionRule));
 }
        public void FindRecordsMultipleCriteriaDesignerViewModel_ValidateThis_FieldsToSearchAndResultIsEmptyOrWhiteSpace_DoesHaveErrors()
        {
            //------------Setup for test--------------------------
            var items = new List<FindRecordsTO> { new FindRecordsTO("", "", 0) };
            var mi = CreateModelItem(items);
            mi.SetProperty("FieldsToSearch", " ");
            mi.SetProperty("Result", " ");
            var viewModel = new FindRecordsMultipleCriteriaDesignerViewModel(mi);
            SetDataListString(viewModel);
            //------------Execute Test---------------------------
            viewModel.Validate();

            //------------Assert Results-------------------------
            Assert.AreEqual(2, viewModel.Errors.Count);
            StringAssert.Contains(viewModel.Errors[0].Message, "'In Field(s)' cannot be empty or only white space");
            StringAssert.Contains(viewModel.Errors[1].Message, "'Result' cannot be empty or only white space");
        }