Inheritance: Dev2.TO.ValidatedObject, IDev2TOFn
Ejemplo n.º 1
0
        private void InsertToCollection(IEnumerable <string> listToAdd, ModelItem modelItem)
        {
            var modelProperty = modelItem.Properties["MergeCollection"];

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

                if (mic != null)
                {
                    List <DataMergeDTO> listOfValidRows = MergeCollection.Where(c => !c.CanRemove()).ToList();
                    if (listOfValidRows.Count > 0)
                    {
                        DataMergeDTO dataMergeDto = MergeCollection.Last(c => !c.CanRemove());
                        int          startIndex   = MergeCollection.IndexOf(dataMergeDto) + 1;
                        foreach (string s in listToAdd)
                        {
                            mic.Insert(startIndex, new DataMergeDTO(s, MergeCollection[startIndex - 1].MergeType, MergeCollection[startIndex - 1].At, startIndex + 1, MergeCollection[startIndex - 1].Padding, MergeCollection[startIndex - 1].Alignment));
                            startIndex++;
                        }
                        CleanUpCollection(mic, modelItem, startIndex);
                    }
                    else
                    {
                        AddToCollection(listToAdd, modelItem);
                    }
                }
            }
        }
 public void DataMergeDTO_CanAdd_WithNewLineMergeTypeAndNoOtherValues_ReturnTrue()
 {
     //------------Setup for test--------------------------
     //------------Execute Test---------------------------
     var dataMergeDTO = new DataMergeDTO(string.Empty, "NewLine", null, 1, null, null);
     //------------Assert Results-------------------------
     Assert.IsTrue(dataMergeDTO.CanAdd());
 }
 public void DataMergeDTO_CanAdd_WithNoInputVarButValueForAt_ReturnTrue()
 {
     //------------Setup for test--------------------------
     //------------Execute Test---------------------------
     var dataMergeDTO = new DataMergeDTO(string.Empty, null, "|", 1, null, null);
     //------------Assert Results-------------------------
     Assert.IsTrue(dataMergeDTO.CanAdd());
 }
 public void DataMergeDTO_CanAdd_WithNoInputVarAndNoAt_ReturnFalse()
 {
     //------------Setup for test--------------------------
     //------------Execute Test---------------------------
     var dataMergeDTO = new DataMergeDTO(string.Empty, null, null, 1, null, null);
     //------------Assert Results-------------------------
     Assert.IsFalse(dataMergeDTO.CanAdd());
 }
Ejemplo n.º 5
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);
        }
Ejemplo 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;
        }
 public void DataMergeDTO_Constructor_FullConstructor_DefaultValues()
 {
     //------------Setup for test--------------------------
     //------------Execute Test---------------------------
     var dataMergeDTO = new DataMergeDTO(string.Empty, null, null, 1, null, null);
     //------------Assert Results-------------------------
     Assert.AreEqual("Index", dataMergeDTO.MergeType);
     Assert.AreEqual(string.Empty, dataMergeDTO.At);
     Assert.AreEqual(1, dataMergeDTO.IndexNumber);
     Assert.AreEqual(string.Empty, dataMergeDTO.Padding);
     Assert.AreEqual("Left", dataMergeDTO.Alignment);
     Assert.IsNotNull(dataMergeDTO.Errors);
 }
Ejemplo 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 DataMergeDTO_GetRuleSet_AtExpressionIsInvalid_ValidateRulesReturnsFalse()
        {
            //------------Setup for test--------------------------
            var dto = new DataMergeDTO { InputVariable = "[[a]]", At = "h]]" };

            //------------Execute Test---------------------------
            Verify_RuleSet(dto, "At", "Invalid expression: opening and closing brackets don't match");
        }
Ejemplo n.º 10
0
 public void DataMergeDTO_CanRemove_WithNewLineInputTypeAndVar_ReturnFalse()
 {
     //------------Setup for test--------------------------
     //------------Execute Test---------------------------
     var dataMergeDTO = new DataMergeDTO("s", "NewLine", null, 1, null, null);
     //------------Assert Results-------------------------
     Assert.IsFalse(dataMergeDTO.CanRemove());
 }
        public void DataMergeDesignerViewModel_ValidateCollectionItem_ValidatesPropertiesOfDTO()
        {
            //------------Setup for test--------------------------
            var mi = ModelItemUtils.CreateModelItem(new DsfDataMergeActivity());
            mi.SetProperty("DisplayName", "Merge");

            var dto = new DataMergeDTO("a&]]", DataMergeDTO.MergeTypeIndex, "", 0, "ab", "Left");

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

            var viewModel = new DataMergeDesignerViewModel(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(4, viewModel.Errors.Count);

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

            StringAssert.Contains(viewModel.Errors[1].Message, "'Using' cannot be empty");
            Verify_IsFocused(dtoModelItem, viewModel.Errors[1].Do, "IsAtFocused");
        }
Ejemplo n.º 12
0
        public void DataMergeDTO_GetRuleSetOutputVariable_ExpressionIsInvalid_ValidateRulesReturnsFalse()
        {
            //------------Setup for test--------------------------
            var dto = new DataMergeDTO { InputVariable = "[[ddd&]]", MergeType = DataMergeDTO.MergeTypeNone, Alignment = "Right", At = "1", Padding = " " };

            //------------Execute Test---------------------------
            Verify_RuleSet(dto, "Input", "Variable name [[ddd&]] contains invalid character(s)");

        }
Ejemplo n.º 13
0
        void Verify_IsEmpty(string mergeType)
        {
            //------------Setup for test--------------------------
            var dto = new DataMergeDTO { MergeType = mergeType };

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

            //------------Assert Results-------------------------
            Assert.IsTrue(actual);
        }
Ejemplo n.º 14
0
        static void Verify_RuleSet(DataMergeDTO 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);
            }
        }
Ejemplo n.º 15
0
        public void DataMergeDTO_IsEmpty_PropertiesAreNotEmpty_False()
        {
            //------------Setup for test--------------------------
            var dto = new DataMergeDTO { InputVariable = "xxx" };

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

            //------------Assert Results-------------------------
            Assert.IsFalse(actual);
        }
Ejemplo n.º 16
0
        public void DataMergeDTO_GetRuleSet_AtIsNotPositiveNumber_ValidateRulesReturnsFalse()
        {
            //------------Setup for test--------------------------
            var dto = new DataMergeDTO { InputVariable = "[[a]]", At = "-1" };

            //------------Execute Test---------------------------
            Verify_RuleSet(dto, "At", "must be a real number");
        }
Ejemplo n.º 17
0
        public void DataMergeDTO_GetRuleSet_AtIsPositiveNumber_ValidateRulesReturnsTrue()
        {
            //------------Setup for test--------------------------
            var dto = new DataMergeDTO { InputVariable = "[[a]]", At = "1" };

            //------------Execute Test---------------------------
            Verify_RuleSet(dto, "At", null);
        }
Ejemplo n.º 18
0
        public void DataMergeDTO_GetRuleSet_AtExpressionIsValid_ValidateRulesReturnsTrue()
        {
            //------------Setup for test--------------------------
            var dto = new DataMergeDTO { InputVariable = "[[a]]", At = "[[h]]" };

            //------------Execute Test---------------------------
            Verify_RuleSet(dto, "At", null);
        }
Ejemplo n.º 19
0
        public void DataMergeDTO_GetRuleSet_AtIsNullOrEmpty_ValidateRulesReturnsFalse()
        {
            //------------Setup for test--------------------------
            var dto = new DataMergeDTO { InputVariable = "[[a]]", At = "" };

            //------------Execute Test---------------------------
            Verify_RuleSet(dto, "At", "cannot be empty");
        }
Ejemplo n.º 20
0
        public void DataMergeDTO_ClearRow_PropertiesAreEmpty()
        {
            //------------Setup for test--------------------------
            var dto = new DataMergeDTO { InputVariable = "xxx", MergeType = DataMergeDTO.MergeTypeNone, Alignment = "Right", At = "1", Padding = " " };

            Assert.IsFalse(dto.IsEmpty());

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

            //------------Assert Results-------------------------
            Assert.IsTrue(dto.IsEmpty());
        }
Ejemplo n.º 21
0
        public void DataMergeDTO_GetRuleSet_IsEmptyIsTrue_ValidateRulesReturnsTrue()
        {
            //------------Setup for test--------------------------
            var dto = new DataMergeDTO();

            //------------Execute Test---------------------------
            Verify_RuleSet(dto, "Padding", null);
            Verify_RuleSet(dto, "At", null);
        }
Ejemplo n.º 22
0
        public void DataMergeDTO_GetRuleSet_PaddingIsEmpty_ValidateRulesReturnsTrue()
        {
            //------------Setup for test--------------------------
            var dto = new DataMergeDTO { Padding = "", At = "1" };

            //------------Execute Test---------------------------
            Verify_RuleSet(dto, "Padding", null);
        }
Ejemplo n.º 23
0
        public void DataMergeDTO_GetRuleSet_PaddingIsNotSingleChar_ValidateRulesReturnsFalse()
        {
            //------------Setup for test--------------------------
            var dto = new DataMergeDTO { Padding = "aa", At = "1" };

            //------------Execute Test---------------------------
            Verify_RuleSet(dto, "Padding", "must be a single character");
        }
Ejemplo n.º 24
0
        public void DataMergeDTO_GetRuleSet_PaddingExpressionIsInvalid_ValidateRulesReturnsFalse()
        {
            //------------Setup for test--------------------------
            var dto = new DataMergeDTO { Padding = "h]]", At = "1" };

            //------------Execute Test---------------------------
            Verify_RuleSet(dto, "Padding", "Invalid expression: opening and closing brackets don't match");
        }