public void ItShouldBePossibleToImplicitlyCastNonNegativeIntToNonNegativeDecimal()
        {
            var value = Extensions.GetValue(() => NonNegativeInt.TryCreate(1, (NonEmptyString)"Value"));
            NonNegativeDecimal castResult = value;

            castResult.ShouldBeOfType <NonNegativeDecimal>();
        }
Beispiel #2
0
        public static IResult<TopSkip, NonEmptyString> TryCreate(int skip, int top, NonEmptyString topField, NonEmptyString skipField)
        {
            var skipResult = NonNegativeInt.TryCreate(skip, skipField);

            var topResult = PositiveInt.TryCreate(top, topField);

            var result = new IResult<NonEmptyString>[]
            {
                skipResult,
                topResult
            }.IfAtLeastOneFailCombineElseReturnOk();

            if (result.IsFailure)
            {
                return GetFailResult(result.Error);
            }

            return topResult.Value > Const.MaxTopSize ? GetFailResult((NonEmptyString)$"{{0}} can't be greater than {Const.MaxTopSize}", topField) : GetOkResult(new TopSkip(skipResult.Value, topResult.Value));
        }
Beispiel #3
0
        public static IResult <Paged <T>, NonEmptyString> TryCreate(int count, ImmutableList <T> items)
        {
            var countResult = NonNegativeInt.TryCreate(count, (NonEmptyString)nameof(Count));

            return(countResult.OnSuccess(() => GetOkResult(Create(countResult.Value, items))));
        }
        public void NonNegativeIntCannotBeCreatedFromNegativeOrNullValue([Values(null, -1)] int?value)
        {
            var result = NonNegativeInt.TryCreate(value, (NonEmptyString)"Value");

            result.IsSuccess.ShouldBeFalse();
        }
        public void NonNegativeIntCanBeCreatedFromNonNegativeValue()
        {
            var result = NonNegativeInt.TryCreate(0, (NonEmptyString)"Value");

            result.IsSuccess.ShouldBeTrue();
        }