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

            castResult.ShouldBeOfType <NonNegativeDecimal>();
        }
コード例 #2
0
        public static IResult <IdVersion, NonEmptyString> TryCreate(int id, string version, NonEmptyString idField, NonEmptyString versionField)
        {
            var idResult      = PositiveInt.TryCreate(id, idField);
            var versionResult = NonEmptyString.TryCreate(version, versionField);

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

            return(result.OnSuccess(() => GetOkResult(new IdVersion(idResult.Value, versionResult.Value))));
        }
コード例 #3
0
ファイル: Command.cs プロジェクト: tomekjanicki/fpdemo
        public static IResult <Command, NonEmptyString> TryCreate(int id, string name, int?size)
        {
            var idResult   = PositiveInt.TryCreate(id, (NonEmptyString)nameof(Id));
            var nameResult = Name.TryCreate(name, (NonEmptyString)nameof(Name));
            var sizeResult = PositiveInt.TryCreate(size, (NonEmptyString)nameof(Size));

            var result = new IResult <NonEmptyString>[]
            {
                idResult,
                nameResult,
                sizeResult
            }.IfAtLeastOneFailCombineElseReturnOk();

            return(result.OnSuccess(() => GetOkResult(new Command(idResult.Value, nameResult.Value, sizeResult.Value))));
        }
コード例 #4
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));
        }
コード例 #5
0
ファイル: Query.cs プロジェクト: tomekjanicki/fpdemo
        public static IResult <Query, NonEmptyString> TryCreate(int id)
        {
            var result = PositiveInt.TryCreate(id, (NonEmptyString)nameof(Id));

            return(result.OnSuccess(positiveIntId => GetOkResult(new Query(positiveIntId))));
        }
コード例 #6
0
ファイル: Query.cs プロジェクト: tomekjanicki/cgdemo
        public static IResult <Query, NonEmptyString> TryCreate(int id, Guid commandId)
        {
            var result = PositiveInt.TryCreate(id, (NonEmptyString)nameof(Id));

            return(result.OnSuccess(() => GetOkResult(new Query(result.Value, commandId))));
        }
コード例 #7
0
        public void PositiveIntCannotBeCreatedFromZeroOrNegativeOrNullValue([Values(null, -1, 0)] int?value)
        {
            var result = PositiveInt.TryCreate(value, (NonEmptyString)"Value");

            result.IsSuccess.ShouldBeFalse();
        }
コード例 #8
0
        public void PositiveIntCanBeCreatedFromPosititiveValue()
        {
            var result = PositiveInt.TryCreate(1, (NonEmptyString)"Value");

            result.IsSuccess.ShouldBeTrue();
        }