コード例 #1
0
        public void AnyWithNullCheckTest1()
        {
            //create a new null list that we will use to check
            List<int> ListToTestWith = null;

            //check the null list
            Assert.False(ListToTestWith.AnyWithNullCheck());

            //create a new list
            ListToTestWith = new List<int>();

            //check if the object instance has any items
            Assert.False(ListToTestWith.AnyWithNullCheck());

            //add an item to the list
            ListToTestWith.Add(1);

            //do we see the 1 number
            Assert.True(ListToTestWith.AnyWithNullCheck());

            //add another item
            ListToTestWith.Add(2);

            //should see the 2 items
            Assert.True(ListToTestWith.AnyWithNullCheck());

            //clear all the items
            ListToTestWith.Clear();

            //should resolve to false
            Assert.False(ListToTestWith.AnyWithNullCheck());
        }
コード例 #2
0
        public List <ActionErrorMessage> Execute <T>(List <ParallelAction <T> > actions = null)
        {
            if (!actions.AnyWithNullCheck())
            {
                throw new ArgumentNullException();
            }
            var nonParallels = actions.Where(x => !x.IsParallel);

            foreach (var action in nonParallels)
            {
                var actionErrorMessage = action.Action.Invoke(action.Request);
                if (actionErrorMessage.AnyWithNullCheck())
                {
                    return(actionErrorMessage);
                }
            }

            var parallelActions             = actions.Where(x => x.IsParallel);
            var parallelActionErrorMessages = new List <ActionErrorMessage>();

            Parallel.ForEach(parallelActions, (parallelAction) =>
            {
                var errorMessages = parallelAction.Action.Invoke(parallelAction.Request);
                if (errorMessages.AnyWithNullCheck())
                {
                    parallelActionErrorMessages.AddRange(errorMessages);
                }
            });
            return(parallelActionErrorMessages);
        }
 public static Status ToStatus(this List <ErrorMessage> value)
 {
     if (value.AnyWithNullCheck())
     {
         return(Status.Fail);
     }
     return(Status.Success);
 }
        public ContactApiResponseModel MapContactApiResponseModel(List <ErrorMessage> errorMessage, CreateContactMsgEntity createContactMsgEntity)
        {
            var contactApiResponseModel = new ContactApiResponseModel();

            if (errorMessage.AnyWithNullCheck())
            {
                contactApiResponseModel.ErrorMessages = errorMessage.ToApiErrorMessage();
            }
            contactApiResponseModel.Id = createContactMsgEntity.ContactId;
            return(contactApiResponseModel);
        }
コード例 #5
0
        public HttpClient GetHttpClient(List <KeyValuePair> headers)
        {
            var httpClient = new HttpClient();

            if (!headers.AnyWithNullCheck())
            {
                return(httpClient);
            }
            foreach (var header in headers)
            {
                httpClient.DefaultRequestHeaders.Add(header.Key, header.Value);
            }
            return(httpClient);
        }
コード例 #6
0
        public ResultMessageEntity IsPartnerValid(AuthenticationReqMsgEntity authenticationReqMsgEntity)
        {
            PartnerKeyDetailsDAO        partnerKeyDetailsDAO      = authenticationServiceMapper.MapPartnerKeyDetailsDAO(authenticationReqMsgEntity);
            List <PartnerKeyDetailsDAO> validPartnerKeyDetailsDAO = authenticationServiceRepository.GetPartnerDetail(partnerKeyDetailsDAO);

            if (!validPartnerKeyDetailsDAO.AnyWithNullCheck())
            {
                return(ColdFishServiceOpenApiUtility.GetResultMessageEntity(ResultStatus.Fail, "Partner is Invalid", authenticationServiceErrorCodes.PartnerNotFound));
            }
            if (validPartnerKeyDetailsDAO.Count > 1)
            {
                return(ColdFishServiceOpenApiUtility.GetResultMessageEntity(ResultStatus.Fail, "To Many partners", authenticationServiceErrorCodes.PartnerNotFound));
            }
            return(new ResultMessageEntity {
                ResultStatus = ResultStatus.Success
            });
        }
        public static List <ApiErrorMessage> ToApiErrorMessage(this List <ErrorMessage> errorMessages)
        {
            if (!errorMessages.AnyWithNullCheck())
            {
                return(null);
            }
            var apiErrorMessages = new List <ApiErrorMessage>();

            foreach (var errorMessage in errorMessages)
            {
                apiErrorMessages.Add(new ApiErrorMessage
                {
                    ErrorCode = errorMessage.ErrorCode
                });
            }
            return(apiErrorMessages);
        }
        public static List <ErrorMessage> ToErrorMessages(this List <ActionErrorMessage> value)
        {
            if (!value.AnyWithNullCheck())
            {
                return(null);
            }
            var errorMessages = new List <ErrorMessage>();

            foreach (var actionErrorMessage in value)
            {
                errorMessages.Add(new ErrorMessage()
                {
                    ErrorCode = actionErrorMessage.ErrorCode
                });
            }
            return(errorMessages);
        }
コード例 #9
0
        public static List <ResultMessage> ToResultMsgEntity(this List <ResultMessageAPI> value)
        {
            if (value.AnyWithNullCheck())
            {
                return(null);
            }
            List <ResultMessage> resultMessages = new List <ResultMessage>();

            foreach (ResultMessageAPI resultMessageAPI in value)
            {
                resultMessages.Add(new ResultMessage()
                {
                    ErrorCode = resultMessageAPI.errorCode,
                    Message   = resultMessageAPI.errorMsg
                });
            }
            return(resultMessages);
        }
コード例 #10
0
        public static List <ResultMessageApiModel> ToResultMessageAPIModel(this List <ResultMessage> value)
        {
            if (!value.AnyWithNullCheck())
            {
                return(null);
            }
            List <ResultMessageApiModel> resultMessageApiModel = new List <ResultMessageApiModel>();

            foreach (ResultMessage resultMessage in value)
            {
                resultMessageApiModel.Add(new ResultMessageApiModel()
                {
                    ErrorCode = resultMessage.ErrorCode,
                    Message   = resultMessage.Message
                });
            }
            return(resultMessageApiModel);
        }
コード例 #11
0
        public void AnyWithNullCheckPredicateTest1()
        {
            //create a new null list that we will use to check
            List<int> ListToTestWith = null;

            //should return false since we don't have an instance of an object
            Assert.False(ListToTestWith.AnyWithNullCheck(x => x == 5));

            //create an instance of the list now
            ListToTestWith = new List<int>();

            //we still don't have any items in the list
            Assert.False(ListToTestWith.AnyWithNullCheck(x => x == 5));

            //add an item now
            ListToTestWith.Add(1);

            //we should be able to find the == 1
            Assert.True(ListToTestWith.AnyWithNullCheck(x => x == 1));

            //we don't have anything greater then 5
            Assert.False(ListToTestWith.AnyWithNullCheck(x => x > 5));

            //add 2
            ListToTestWith.Add(2);

            //should be able to find the 2
            Assert.True(ListToTestWith.AnyWithNullCheck(x => x == 2));

            //shouldn't be able to find any numbers greater then 5
            Assert.False(ListToTestWith.AnyWithNullCheck(x => x > 5));

            //clear the list
            ListToTestWith.Clear();

            //we have no items because we just cleared the list
            Assert.False(ListToTestWith.AnyWithNullCheck(x => x <= 5));
        }