コード例 #1
0
        public void ItShouldBePossibleToImplicitlyCastNonNegativeIntToNonNegativeDecimal()
        {
            var value = Extensions.GetValue(() => NonNegativeInt.TryCreate(1, (NonEmptyString)"Value"));
            NonNegativeDecimal castResult = value;

            castResult.ShouldBeOfType <NonNegativeDecimal>();
        }
コード例 #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));
        }
コード例 #3
0
ファイル: Paged.cs プロジェクト: tomekjanicki/cgdemo
        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))));
        }
コード例 #4
0
        public void NonNegativeIntCannotBeCreatedFromNegativeOrNullValue([Values(null, -1)] int?value)
        {
            var result = NonNegativeInt.TryCreate(value, (NonEmptyString)"Value");

            result.IsSuccess.ShouldBeFalse();
        }
コード例 #5
0
        public void NonNegativeIntCanBeCreatedFromNonNegativeValue()
        {
            var result = NonNegativeInt.TryCreate(0, (NonEmptyString)"Value");

            result.IsSuccess.ShouldBeTrue();
        }