Example #1
0
        public void ReturnTrue_ForNullString()
        {
            object str = null;
            var    attributeInstance = new ValidAscendingOrderRangeOfIntIdsAttribute();
            var    result            = attributeInstance.IsValid(str);

            Assert.IsTrue(result);
        }
Example #2
0
        public void ReturnTrue_ForCorrectComplexString()
        {
            object str = "1,2-5,6-10";
            var    attributeInstance = new ValidAscendingOrderRangeOfIntIdsAttribute();
            var    result            = attributeInstance.IsValid(str);

            Assert.IsTrue(result);
        }
Example #3
0
        public void ReturnTrue_SingleId()
        {
            object str = "5";
            var    attributeInstance = new ValidAscendingOrderRangeOfIntIdsAttribute();
            var    result            = attributeInstance.IsValid(str);

            Assert.IsTrue(result);
        }
Example #4
0
        public void ReturnFalse_ForTrailingHyphen()
        {
            object str = "1-";
            var    attributeInstance = new ValidAscendingOrderRangeOfIntIdsAttribute();
            var    result            = attributeInstance.IsValid(str);

            Assert.IsFalse(result);
        }
Example #5
0
        public void ReturnFalse_ForWronglySyntaxedStringDoubleComma()
        {
            object str = "1,,3";
            var    attributeInstance = new ValidAscendingOrderRangeOfIntIdsAttribute();
            var    result            = attributeInstance.IsValid(str);

            Assert.IsFalse(result);
        }
Example #6
0
        public void ReturnFalse_ForStringThatContainsASingleLetter()
        {
            object str = "a";
            var    attributeInstance = new ValidAscendingOrderRangeOfIntIdsAttribute();
            var    result            = attributeInstance.IsValid(str);

            Assert.IsFalse(result);
        }
Example #7
0
        public void ReturnFalse_ForUnparsableFirstCharater()
        {
            object str = "a,b,c,1,2,3";
            var    attributeInstance = new ValidAscendingOrderRangeOfIntIdsAttribute();
            var    result            = attributeInstance.IsValid(str);

            Assert.IsFalse(result);
        }
        public async Task <OfmForGetCollectionQueryResult <TOfmForGet> > ValidateResourceParameters(OfmForGetCollectionQueryResult <TOfmForGet> ofmForGetCollectionQueryResult, OfmResourceParametersBase resourceParameters)
        {
            await Task.Run(() =>
            {
                var errorMessages = new List <string>();

                var idsAreCorrectlySyntaxed = new ValidRegExRangeOfIntIdsAttribute(FittifyRegularExpressions.RangeOfIntIds);
                if (!idsAreCorrectlySyntaxed.IsValid(resourceParameters.Ids))
                {
                    ofmForGetCollectionQueryResult.ErrorMessages.Add(idsAreCorrectlySyntaxed.FormatErrorMessage(null));
                }

                var idsInAscendingOrderValidation = new ValidAscendingOrderRangeOfIntIdsAttribute();
                if (!idsInAscendingOrderValidation.IsValid(resourceParameters.Ids))
                {
                    ofmForGetCollectionQueryResult.ErrorMessages.Add(idsInAscendingOrderValidation.FormatErrorMessage(null));
                }

                errorMessages = new List <string>();
                if (!_typeHelperService.TypeHasProperties <TOfmForGet>(resourceParameters.OrderBy, ref errorMessages))
                {
                    ofmForGetCollectionQueryResult.ErrorMessages.AddRange(errorMessages);
                }

                errorMessages = new List <string>();
                if (!_typeHelperService.TypeHasProperties <TOfmForGet>(resourceParameters.Fields, ref errorMessages))
                {
                    ofmForGetCollectionQueryResult.ErrorMessages.AddRange(errorMessages);
                }

                ofmForGetCollectionQueryResult.ErrorMessages =
                    ofmForGetCollectionQueryResult.ErrorMessages.Distinct().ToList();
            });

            return(ofmForGetCollectionQueryResult);
        }