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

            Assert.IsTrue(result);
        }
Exemplo n.º 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);
        }
Exemplo n.º 3
0
        public void ReturnTrue_SingleId()
        {
            object str = "5";
            var    attributeInstance = new ValidAscendingOrderRangeOfIntIdsAttribute();
            var    result            = attributeInstance.IsValid(str);

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

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

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

            Assert.IsFalse(result);
        }
Exemplo n.º 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);
        }
Exemplo n.º 8
0
        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);
        }