Inheritance: Dev2.TO.ValidatedObject, IDev2TOFn, IOutputTOConvert
 public void DataSplitDTO_Ctor_CreateWithSplitTypeOfSpace_EnabledAtFalse()
 {
     //------------Execute Test---------------------------
     var dataSplitDTO = new DataSplitDTO("[[var]]", "Space", "", 0);
     //------------Assert Results-------------------------
     Assert.IsFalse(dataSplitDTO.EnableAt);
 }
Esempio n. 2
0
        private void InsertToCollection(IEnumerable <string> listToAdd, ModelItem modelItem)
        {
            var modelProperty = modelItem.Properties["ResultsCollection"];

            if (modelProperty != null)
            {
                ModelItemCollection mic = modelProperty.Collection;

                if (mic != null)
                {
                    List <DataSplitDTO> listOfValidRows = ResultsCollection.Where(c => !c.CanRemove()).ToList();
                    if (listOfValidRows.Count > 0)
                    {
                        DataSplitDTO dataSplitDto = ResultsCollection.Last(c => !c.CanRemove());
                        int          startIndex   = ResultsCollection.IndexOf(dataSplitDto) + 1;
                        foreach (string s in listToAdd)
                        {
                            mic.Insert(startIndex, new DataSplitDTO(s, ResultsCollection[startIndex - 1].SplitType, ResultsCollection[startIndex - 1].At, startIndex + 1));
                            startIndex++;
                        }
                        CleanUpCollection(mic, modelItem, startIndex);
                    }
                    else
                    {
                        AddToCollection(listToAdd, modelItem);
                    }
                }
            }
        }
Esempio n. 3
0
 public void DataSplitDTO_CanAdd_WithNewLineSplitTypeAndNoOtherValues_ReturnTrue()
 {
     //------------Setup for test--------------------------
     //------------Execute Test---------------------------
     var dataSplitDTO = new DataSplitDTO(string.Empty, "NewLine", null, 1);
     //------------Assert Results-------------------------
     Assert.IsTrue(dataSplitDTO.CanAdd());
 }
Esempio n. 4
0
 public void DataSplitDTO_CanAdd_WithNoInputVarButValueForAt_ReturnTrue()
 {
     //------------Setup for test--------------------------
     //------------Execute Test---------------------------
     var dataSplitDTO = new DataSplitDTO(string.Empty, null, "|", 1);
     //------------Assert Results-------------------------
     Assert.IsTrue(dataSplitDTO.CanAdd());
 }
Esempio n. 5
0
 public void DataSplitDTO_CanAdd_WithNoInputVarAndNoAt_ReturnFalse()
 {
     //------------Setup for test--------------------------
     //------------Execute Test---------------------------
     var dataSplitDTO = new DataSplitDTO(string.Empty, null, null, 1);
     //------------Assert Results-------------------------
     Assert.IsFalse(dataSplitDTO.CanAdd());
 }
Esempio n. 6
0
        public static IDev2TOFn CreateNewDTO(IDev2TOFn dto, int index = 0, bool inserted = false, string initializeWith = "")
        {
            IDev2TOFn toReturn = null;

            TypeSwitch.Do(dto,
                          // ReSharper disable ImplicitlyCapturedClosure
                          TypeSwitch.Case <ActivityDTO>(x => toReturn = new ActivityDTO(initializeWith, "", index, inserted)),
                          // ReSharper restore ImplicitlyCapturedClosure
                          TypeSwitch.Case <DataSplitDTO>(x =>
            {
                var dataSplitDto = dto as DataSplitDTO;
                if (dataSplitDto != null)
                {
                    toReturn = new DataSplitDTO(initializeWith, dataSplitDto.SplitType, dataSplitDto.At, index, false, inserted);
                }
            }),
                          TypeSwitch.Case <DataMergeDTO>(x =>
            {
                var dataMergeDto = dto as DataMergeDTO;
                if (dataMergeDto != null)
                {
                    toReturn = new DataMergeDTO(initializeWith, dataMergeDto.MergeType, dataMergeDto.At, index, dataMergeDto.Padding, dataMergeDto.Alignment, inserted);
                }
            }),
                          TypeSwitch.Case <CaseConvertTO>(x =>
            {
                var caseConvertTO = dto as CaseConvertTO;
                if (caseConvertTO != null)
                {
                    toReturn = CaseConverterFactory.CreateCaseConverterTO(initializeWith, caseConvertTO.ConvertType, caseConvertTO.Result, index);
                }
            }),
                          TypeSwitch.Case <BaseConvertTO>(x =>
            {
                var baseConvertTO = dto as BaseConvertTO;
                if (baseConvertTO != null)
                {
                    toReturn = new BaseConvertTO(initializeWith, baseConvertTO.FromType, baseConvertTO.ToType, baseConvertTO.ToExpression, index, inserted);
                }
            }),
                          // ReSharper disable ImplicitlyCapturedClosure
                          TypeSwitch.Case <GatherSystemInformationTO>(x => toReturn =
                                                                          // ReSharper restore ImplicitlyCapturedClosure
                                                                          new GatherSystemInformationTO(enTypeOfSystemInformationToGather.FullDateTime,
                                                                                                        initializeWith, index, inserted)),
                          // ReSharper disable ImplicitlyCapturedClosure
                          TypeSwitch.Case <XPathDTO>(x => toReturn = new XPathDTO(initializeWith, "", index, inserted)),
                          // ReSharper restore ImplicitlyCapturedClosure
                          // ReSharper disable ImplicitlyCapturedClosure
                          TypeSwitch.Case <FindRecordsTO>(() => toReturn = new FindRecordsTO("", "", index, inserted)),
                          // ReSharper restore ImplicitlyCapturedClosure
                          // ReSharper disable ImplicitlyCapturedClosure
                          TypeSwitch.Default(() => toReturn = null));
            // ReSharper restore ImplicitlyCapturedClosure

            return(toReturn);
        }
Esempio n. 7
0
        public static IDev2TOFn CreateNewDTO(IDev2TOFn dto, int index = 0, bool inserted = false, string initializeWith = "")
        {
            IDev2TOFn toReturn = null;

            TypeSwitch.Do(dto,
                // ReSharper disable ImplicitlyCapturedClosure
            TypeSwitch.Case<ActivityDTO>(x => toReturn = new ActivityDTO(initializeWith, "", index, inserted)),
                // ReSharper restore ImplicitlyCapturedClosure
            TypeSwitch.Case<DataSplitDTO>(x =>
                {
                    var dataSplitDto = dto as DataSplitDTO;
                    if(dataSplitDto != null)
                    {
                        toReturn = new DataSplitDTO(initializeWith, dataSplitDto.SplitType, dataSplitDto.At, index, false, inserted);
                    }
                }),
            TypeSwitch.Case<DataMergeDTO>(x =>
                {
                    var dataMergeDto = dto as DataMergeDTO;
                    if(dataMergeDto != null)
                    {
                        toReturn = new DataMergeDTO(initializeWith, dataMergeDto.MergeType, dataMergeDto.At, index, dataMergeDto.Padding, dataMergeDto.Alignment, inserted);
                    }
                }),
            TypeSwitch.Case<CaseConvertTO>(x =>
                {
                    var caseConvertTO = dto as CaseConvertTO;
                    if(caseConvertTO != null)
                    {
                        toReturn = CaseConverterFactory.CreateCaseConverterTO(initializeWith, caseConvertTO.ConvertType, caseConvertTO.Result, index);
                    }
                }),
            TypeSwitch.Case<BaseConvertTO>(x =>
                {
                    var baseConvertTO = dto as BaseConvertTO;
                    if(baseConvertTO != null)
                    {
                        toReturn = new BaseConvertTO(initializeWith, baseConvertTO.FromType, baseConvertTO.ToType, baseConvertTO.ToExpression, index, inserted);
                    }
                }),
                // ReSharper disable ImplicitlyCapturedClosure
            TypeSwitch.Case<GatherSystemInformationTO>(x => toReturn =
                // ReSharper restore ImplicitlyCapturedClosure
                new GatherSystemInformationTO(enTypeOfSystemInformationToGather.FullDateTime,
                    initializeWith, index, inserted)),
                // ReSharper disable ImplicitlyCapturedClosure
            TypeSwitch.Case<XPathDTO>(x => toReturn = new XPathDTO(initializeWith, "", index,  inserted)),
                // ReSharper restore ImplicitlyCapturedClosure
                // ReSharper disable ImplicitlyCapturedClosure
            TypeSwitch.Case<FindRecordsTO>(() => toReturn = new FindRecordsTO("", "", index, inserted)),
                // ReSharper restore ImplicitlyCapturedClosure
                // ReSharper disable ImplicitlyCapturedClosure
            TypeSwitch.Default(() => toReturn = null));
            // ReSharper restore ImplicitlyCapturedClosure

            return toReturn;
        }
Esempio n. 8
0
        public static IDev2TOFn CreateNewDTO(IDev2TOFn dto, int index, bool inserted, string initializeWith)
        {
            IDev2TOFn toReturn = null;

            TypeSwitch.Do(dto,

                          TypeSwitch.Case <ActivityDTO>(x => toReturn = new ActivityDTO(initializeWith, "", index, inserted)),

                          TypeSwitch.Case <DataSplitDTO>(x =>
            {
                if (dto is DataSplitDTO dataSplitDto)
                {
                    toReturn = new DataSplitDTO(initializeWith, dataSplitDto.SplitType, dataSplitDto.At, index, false, inserted);
                }
            }),
                          TypeSwitch.Case <DataMergeDTO>(x =>
            {
                if (dto is DataMergeDTO dataMergeDto)
                {
                    toReturn = new DataMergeDTO(initializeWith, dataMergeDto.MergeType, dataMergeDto.At, index, dataMergeDto.Padding, dataMergeDto.Alignment, inserted);
                }
            }),
                          TypeSwitch.Case <CaseConvertTO>(x =>
            {
                if (dto is CaseConvertTO caseConvertTO)
                {
                    toReturn = CaseConverterFactory.CreateCaseConverterTO(initializeWith, caseConvertTO.ConvertType, caseConvertTO.Result, index);
                }
            }),
                          TypeSwitch.Case <BaseConvertTO>(x =>
            {
                if (dto is BaseConvertTO baseConvertTO)
                {
                    toReturn = new BaseConvertTO(initializeWith, baseConvertTO.FromType, baseConvertTO.ToType, baseConvertTO.ToExpression, index, inserted);
                }
            }),

                          TypeSwitch.Case <GatherSystemInformationTO>(x => toReturn =
                                                                          new GatherSystemInformationTO(enTypeOfSystemInformationToGather.FullDateTime,
                                                                                                        initializeWith, index, inserted)),
                          TypeSwitch.Case <XPathDTO>(x => toReturn              = new XPathDTO(initializeWith, "", index, inserted)),
                          TypeSwitch.Case <FindRecordsTO>(() => toReturn        = new FindRecordsTO("", "", index, inserted)),
                          TypeSwitch.Case <DecisionTO>(() => toReturn           = new DecisionTO(initializeWith, "", "", index, inserted)),
                          TypeSwitch.Case <JsonMappingTo>(() => toReturn        = new JsonMappingTo(initializeWith, index, inserted)),
                          TypeSwitch.Case <SharepointSearchTo>(() => toReturn   = new SharepointSearchTo(initializeWith, "=", "", index, inserted)),
                          TypeSwitch.Case <SharepointReadListTo>(() => toReturn = new SharepointReadListTo("", initializeWith, "", "")),
                          TypeSwitch.Case <AssignObjectDTO>(x => toReturn       = new AssignObjectDTO(initializeWith, "", index, inserted)),
                          TypeSwitch.Default(() => toReturn = null));

            return(toReturn);
        }
        public void DataSplitDTO_Constructor_FullConstructor_PropertiesInitializedCorrectly()
        {
            //------------Setup for test--------------------------

            //------------Execute Test---------------------------
            var dto = new DataSplitDTO(string.Empty, null, null, 1);

            //------------Assert Results-------------------------
            Assert.AreEqual(DataSplitDTO.SplitTypeIndex, dto.SplitType);
            Assert.AreEqual(string.Empty, dto.At);
            Assert.AreEqual(false, dto.EnableAt);
            Assert.AreEqual(true, dto.IsEscapeCharEnabled);
            Assert.AreEqual(1, dto.IndexNumber);
            Assert.IsNull(dto.EscapeChar);
            Assert.AreEqual(false, dto.Include);
            Assert.IsNotNull(dto.Errors);
            Assert.AreEqual(false, dto.IsAtFocused);
            Assert.AreEqual(false, dto.IsOutputVariableFocused);
            Assert.AreEqual(false, dto.IsEscapeCharFocused);
        }
 public void DataSplitDTO_CanRemove_WithNewLineInputTypeAndVar_ReturnFalse()
 {
     //------------Setup for test--------------------------
     //------------Execute Test---------------------------
     var dataSplitDTO = new DataSplitDTO("s", "NewLine", null, 1);
     //------------Assert Results-------------------------
     Assert.IsFalse(dataSplitDTO.CanRemove());
 }
        static void Verify_RuleSet(DataSplitDTO dto, string propertyName, string expectedErrorMessage)
        {
            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);
            //------------Execute Test---------------------------
            var ruleSet = dto.GetRuleSet(propertyName, datalist);
            var errors = ruleSet.ValidateRules(null, null);

            //------------Assert Results-------------------------
            if(expectedErrorMessage == null)
            {
                Assert.AreEqual(0, errors.Count);
            }
            else
            {
                var err = errors.FirstOrDefault(e => e.Message.Contains(expectedErrorMessage));
                Assert.IsNotNull(err);
            }
        }
        public void DataSplitDTO_GetRuleSetAt_SplitTypeIsIndexAndIsLessThan0_ValidateRulesReturnsTrue()
        {
            //------------Setup for test--------------------------
            var dto = new DataSplitDTO { OutputVariable = "[[a]]", At = "-1", SplitType = DataSplitDTO.SplitTypeIndex };

            //------------Execute Test---------------------------
            Verify_RuleSet(dto, "At", " must be a real number");
        }
        public void DataSplitDTO_GetRuleSetAt_SplitTypeIsIndexAndIs0_ValidateRulesReturnsTrue()
        {
            //------------Setup for test--------------------------
            var dto = new DataSplitDTO { OutputVariable = "[[a]]", At = "0", SplitType = DataSplitDTO.SplitTypeIndex };

            //------------Execute Test---------------------------
            Verify_RuleSet(dto, "At", null);
        }
        static DataSplitDesignerViewModel CreateViewModel()
        {
            var mi = ModelItemUtils.CreateModelItem(new DsfDataSplitActivity());
            mi.SetProperty("DisplayName", "Split");
            mi.SetProperty("SourceString", "a,b");

            var dto = new DataSplitDTO("a]]", DataSplitDTO.SplitTypeIndex, "a", 0);

            // ReSharper disable PossibleNullReferenceException
            var miCollection = mi.Properties["ResultsCollection"].Collection;
            miCollection.Add(dto);
            // ReSharper restore PossibleNullReferenceException

            var viewModel = new DataSplitDesignerViewModel(mi);
            return viewModel;
        }
        public void DataSplitDTO_ConvertToOutputTO_OutputTOPropertiesInitialized()
        {
            //------------Setup for test--------------------------
            var dto = new DataSplitDTO { OutputVariable = "[[h]]", OutList = new List<string>(new[] { "hello" }) };

            //------------Execute Test---------------------------
            var outputTO = dto.ConvertToOutputTO();

            //------------Assert Results-------------------------
            Assert.IsNotNull(outputTO);
            Assert.AreEqual("[[h]]", outputTO.OutPutDescription);
            Assert.AreSame(dto.OutList, outputTO.OutputStrings);
        }
        public void DataSplitDTO_GetRuleSetOutputVariable_IsNotNullOrEmpty_ValidateRulesReturnsFalse()
        {
            //------------Setup for test--------------------------
            var dto = new DataSplitDTO { OutputVariable = "[[h&]]", At = "1" };

            //------------Execute Test---------------------------
            Verify_RuleSet(dto, "OutputVariable", "Variable name [[h&]] contains invalid character(s)");
        }
        public void DataSplitDTO_GetRuleSetAt_SplitTypeIsCharsAndExpressionIsInvalid_ValidateRulesReturnsFalse()
        {
            //------------Setup for test--------------------------
            var dto = new DataSplitDTO { OutputVariable = "[[a]]", At = "h]]", SplitType = DataSplitDTO.SplitTypeChars };

            //------------Execute Test---------------------------
            Verify_RuleSet(dto, "At", "Invalid expression: opening and closing brackets don't match");
        }
        public void DataSplitDTO_IsEmpty_PropertiesAreNotEmpty_False()
        {
            //------------Setup for test--------------------------
            var dto = new DataSplitDTO { OutputVariable = "xxx" };

            //------------Execute Test---------------------------
            var actual = dto.IsEmpty();

            //------------Assert Results-------------------------
            Assert.IsFalse(actual);
        }
        void Verify_IsEmpty(string splitType)
        {
            //------------Setup for test--------------------------
            var dto = new DataSplitDTO { SplitType = splitType };

            //------------Execute Test---------------------------
            var actual = dto.IsEmpty();

            //------------Assert Results-------------------------
            Assert.IsTrue(actual);
        }
        public void DataSplitDTO_GetRuleSetOutputVariable_ExpressionIsValid_ValidateRulesReturnsTrue()
        {
            //------------Setup for test--------------------------
            var dto = new DataSplitDTO { OutputVariable = "[[h]]" };

            //------------Execute Test---------------------------
            Verify_RuleSet(dto, "OutputVariable", null);
        }
        public void DataSplitDTO_GetRuleSetOutputVariable_ExpressionIsInvalid_ValidateRulesReturnsFalse()
        {
            //------------Setup for test--------------------------
            var dto = new DataSplitDTO { OutputVariable = "h]]" };

            //------------Execute Test---------------------------
            Verify_RuleSet(dto, "OutputVariable", "Invalid expression: opening and closing brackets don't match");
        }
        public void DataSplitDTO_GetRuleSet_IsEmptyIsTrue_ValidateRulesReturnsTrue()
        {
            //------------Setup for test--------------------------
            var dto = new DataSplitDTO();

            //------------Execute Test---------------------------
            Verify_RuleSet(dto, "OutputVariable", null);
            Verify_RuleSet(dto, "At", null);
        }
Esempio n. 23
0
        static void AddVariables(string variable, string splitType, string splitAt, bool include = false, string escape = "")
        {
            List<Tuple<string, string>> variableList;
            ScenarioContext.Current.TryGetValue("variableList", out variableList);

            if(variableList == null)
            {
                variableList = new List<Tuple<string, string>>();
                ScenarioContext.Current.Add("variableList", variableList);
            }
           // variableList.Add(new Tuple<string, string>(variable, ""));

            List<DataSplitDTO> splitCollection;
            ScenarioContext.Current.TryGetValue("splitCollection", out splitCollection);

            if(splitCollection == null)
            {
                splitCollection = new List<DataSplitDTO>();
                ScenarioContext.Current.Add("splitCollection", splitCollection);
            }
            DataSplitDTO dto = new DataSplitDTO { OutputVariable = variable, SplitType = splitType, At = splitAt, EscapeChar = escape, Include = include };
            splitCollection.Add(dto);
        }
        public void DataSplitDTO_GetRuleSetAt_SplitTypeIsCharsAndExpressionIsValid_ValidateRulesReturnsTrue()
        {
            //------------Setup for test--------------------------
            var dto = new DataSplitDTO { OutputVariable = "[[a]]", At = "[[h]]", SplitType = DataSplitDTO.SplitTypeChars };

            //------------Execute Test---------------------------
            Verify_RuleSet(dto, "At", null);
        }
        public void DataSplitDesignerViewModel_ValidateCollectionItem_ValidatesPropertiesOfDTO()
        {
            //------------Setup for test--------------------------
            var mi = ModelItemUtils.CreateModelItem(new DsfDataSplitActivity());
            mi.SetProperty("DisplayName", "Split");
            mi.SetProperty("SourceString", "a,b");

            var dto = new DataSplitDTO("a]]", DataSplitDTO.SplitTypeIndex, "a", 0);

            // ReSharper disable PossibleNullReferenceException
            var miCollection = mi.Properties["ResultsCollection"].Collection;
            var dtoModelItem = miCollection.Add(dto);
            // ReSharper restore PossibleNullReferenceException

            var viewModel = new DataSplitDesignerViewModel(mi);
            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;
            };

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

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

            StringAssert.Contains(viewModel.Errors[0].Message, "'Results' - Invalid expression: opening and closing brackets don't match");
            Verify_IsFocused(dtoModelItem, viewModel.Errors[0].Do, "IsOutputVariableFocused");

            StringAssert.Contains(viewModel.Errors[1].Message, "'Using' must be a real number");
            Verify_IsFocused(dtoModelItem, viewModel.Errors[1].Do, "IsAtFocused");
        }
        public void DataSplitDTO_GetRuleSetAt_SplitTypeIsCharsAndIsEmpty_ValidateRulesReturnsFalse()
        {
            //------------Setup for test--------------------------
            var dto = new DataSplitDTO { OutputVariable = "[[a]]", At = "", SplitType = DataSplitDTO.SplitTypeChars };

            //------------Execute Test---------------------------
            Verify_RuleSet(dto, "At", "cannot be empty");
        }
        public void DataSplitDTO_GetRuleSetOutputVariable_IsNotNullOrEmpty_ValidateRulesReturnsTrue()
        {
            //------------Setup for test--------------------------
            var dto = new DataSplitDTO { OutputVariable = "[[h]]", At = "1" };

            //------------Execute Test---------------------------
            Verify_RuleSet(dto, "OutputVariable", null);
        }
        public void DataSplitDTO_ClearRow_PropertiesAreEmpty()
        {
            //------------Setup for test--------------------------
            var dto = new DataSplitDTO { OutputVariable = "xxx", SplitType = DataSplitDTO.SplitTypeNone, Include = true, EscapeChar = "'" };

            Assert.IsFalse(dto.IsEmpty());

            //------------Execute Test---------------------------
            dto.ClearRow();

            //------------Assert Results-------------------------
            Assert.IsTrue(dto.IsEmpty());
        }