public void DeletePart_WhenPositionOutOfRange_ShouldThrowException(int position)
        {
            var    multiIndexArray = new int[] { 1, 2, 3, 4, 5 };
            Action action          = () => ArrayUtility <int> .DeletePart(position, multiIndexArray);

            action.Should().Throw <ArgumentOutOfRangeException>();
        }
        public void DeletePart_WhenValidPositionWithMultiIndexArray_ShouldReturnDeletedArray()
        {
            var expectResult = new int[] { 1, 2, 4, 5 };

            var position        = 3;
            var multiIndexArray = new int[] { 1, 2, 3, 4, 5 };
            var result          = ArrayUtility <int> .DeletePart(position, multiIndexArray);

            result.Should().BeEquivalentTo(expectResult);
        }
        public void DeletePart_WhenValidPositionWithSingleIndexArray_ShouldReturnEmptyArray()
        {
            var expectResult = new int[] { };

            var position         = 1;
            var singleIndexArray = new int[] { 1 };
            var result           = ArrayUtility <int> .DeletePart(position, singleIndexArray);

            result.Should().BeEquivalentTo(expectResult);
        }
Exemple #4
0
        public IHttpActionResult DeletePart([FromUri] int?position, [FromUri] int[] productIds)
        {
            try
            {
                if (!position.HasValue)
                {
                    return(BadRequest(ErrorMessage.INVALID_MISSING_POSITION));
                }

                if (productIds == null || productIds.Length == 0)
                {
                    return(BadRequest(ErrorMessage.INVALID_MISSING_PRODUCT_IDS));
                }

                return(Ok(ArrayUtility <int> .DeletePart(position.Value, productIds)));
            }
            catch (ArgumentOutOfRangeException)
            {
                return(BadRequest(ErrorMessage.INVALID_POSITION_VALUE_RANGE));
            }
        }