AgainstNegative() публичный статический Метод

public static AgainstNegative ( string argumentName, int value ) : void
argumentName string
value int
Результат void
Пример #1
0
        public void AddNavigationConnectionField <TSource, TReturn>(
            ComplexGraphType <TSource> graph,
            string name,
            Func <ResolveEfFieldContext <TDbContext, TSource>, IEnumerable <TReturn> >?resolve = null,
            Type?itemGraphType = null,
            IEnumerable <QueryArgument>?arguments = null,
            IEnumerable <string>?includeNames     = null,
            int pageSize       = 10,
            string?description = null)
            where TReturn : class
        {
            Guard.AgainstNull(nameof(graph), graph);

            Guard.AgainstNullWhiteSpace(nameof(name), name);
            Guard.AgainstNegative(nameof(pageSize), pageSize);

            itemGraphType ??= GraphTypeFinder.FindGraphType <TReturn>();
            var fieldType = GetFieldType <TSource>(name, itemGraphType);

            var builder = ConnectionBuilder <TSource> .Create <FakeGraph>(name);

            if (description != null)
            {
                builder.Description(description);
            }

            builder.PageSize(pageSize).Bidirectional();
            SetField(builder, fieldType);
            IncludeAppender.SetIncludeMetadata(builder.FieldType, name, includeNames);

            var hasId = keyNames.ContainsKey(typeof(TReturn));

            if (resolve != null)
            {
                builder.ResolveAsync(async context =>
                {
                    var efFieldContext = BuildContext(context);

                    var enumerable = resolve(efFieldContext);


                    enumerable = enumerable.ApplyGraphQlArguments(hasId, context);
                    enumerable = await efFieldContext.Filters.ApplyFilter(enumerable, context.UserContext);
                    var page   = enumerable.ToList();

                    return(ConnectionConverter.ApplyConnectionContext(
                               page,
                               context.First,
                               context.After,
                               context.Last,
                               context.Before));
                });
            }

            var connection = builder;

            var field = graph.AddField(connection.FieldType);

            field.AddWhereArgument(hasId, arguments);
        }
Пример #2
0
        ConnectionBuilder <FakeGraph, TSource> BuildQueryConnectionField <TSource, TReturn>(
            string name,
            Func <ResolveFieldContext <TSource>, IQueryable <TReturn> > resolve,
            int pageSize,
            Type graphType)
            where TReturn : class
        {
            Guard.AgainstNullWhiteSpace(nameof(name), name);
            Guard.AgainstNull(nameof(resolve), resolve);
            Guard.AgainstNegative(nameof(pageSize), pageSize);

            graphType = GraphTypeFinder.FindGraphType <TReturn>(graphType);
            var fieldType = GetFieldType <TSource>(name, graphType);
            var builder   = ConnectionBuilder <FakeGraph, TSource> .Create(name);

            builder.PageSize(pageSize);
            SetField(builder, fieldType);

            builder.Resolve(
                context =>
            {
                var withIncludes  = includeAppender.AddIncludes(resolve(context), context);
                var withArguments = withIncludes.ApplyGraphQlArguments(context);
                return(withArguments
                       .ApplyConnectionContext(
                           context.First,
                           context.After,
                           context.Last,
                           context.Before,
                           context,
                           context.CancellationToken,
                           filters));
            });
            return(builder);
        }
Пример #3
0
        ConnectionBuilder <TGraph, TSource> BuildQueryConnectionField <TSource, TGraph, TReturn>(
            string name,
            Func <ResolveFieldContext <TSource>, IQueryable <TReturn> > resolve,
            int pageSize)
            where TGraph : ObjectGraphType <TReturn>, IGraphType
            where TReturn : class
        {
            Guard.AgainstNullWhiteSpace(nameof(name), name);
            Guard.AgainstNull(nameof(resolve), resolve);
            Guard.AgainstNegative(nameof(pageSize), pageSize);
            var builder = ConnectionBuilder.Create <TGraph, TSource>();

            builder.PageSize(pageSize);
            //todo:
            //builder.Bidirectional();
            builder.Name(name);
            builder.Resolve(context =>
            {
                var withIncludes  = includeAppender.AddIncludes(resolve(context), context);
                var withArguments = withIncludes.ApplyGraphQlArguments(context);
                return(withArguments
                       .ApplyConnectionContext(
                           context.First,
                           context.After,
                           context.Last,
                           context.Before,
                           context,
                           context.CancellationToken));
            });
            return(builder);
        }
Пример #4
0
        ConnectionBuilder <TGraph, TSource> BuildListConnectionField <TSource, TGraph, TReturn>(
            string name,
            Func <ResolveFieldContext <TSource>, IEnumerable <TReturn> > resolve,
            IEnumerable <string> includeName,
            int pageSize)
            where TGraph : ObjectGraphType <TReturn>, IGraphType
            where TReturn : class
        {
            Guard.AgainstNullWhiteSpace(nameof(name), name);
            Guard.AgainstNull(nameof(resolve), resolve);
            Guard.AgainstNegative(nameof(pageSize), pageSize);
            var builder = ConnectionBuilder.Create <TGraph, TSource>();

            builder.PageSize(pageSize);
            builder.Name(name);
            IncludeAppender.SetIncludeMetadata(builder.FieldType, name, includeName);
            builder.Resolve(context =>
            {
                var enumerable = resolve(context);
                enumerable     = enumerable.ApplyGraphQlArguments(context);
                enumerable     = enumerable.Where(item => GlobalFilters.ShouldInclude(context.UserContext, item));
                var page       = enumerable.ToList();

                return(ConnectionConverter.ApplyConnectionContext(
                           page,
                           context.First,
                           context.After,
                           context.Last,
                           context.Before));
            });
            return(builder);
        }
Пример #5
0
        ConnectionBuilder <FakeGraph, TSource> BuildListConnectionField <TSource, TReturn>(
            string name,
            Func <ResolveFieldContext <TSource>, IEnumerable <TReturn> > resolve,
            IEnumerable <string> includeName,
            int pageSize,
            Type graphType)
            where TReturn : class
        {
            Guard.AgainstNullWhiteSpace(nameof(name), name);
            Guard.AgainstNull(nameof(resolve), resolve);
            Guard.AgainstNegative(nameof(pageSize), pageSize);
            graphType = GraphTypeFinder.FindGraphType <TReturn>(graphType);
            var fieldType = GetFieldType <TSource>(name, graphType);
            var builder   = ConnectionBuilder <FakeGraph, TSource> .Create(name);

            builder.PageSize(pageSize);
            SetField(builder, fieldType);
            IncludeAppender.SetIncludeMetadata(builder.FieldType, name, includeName);
            builder.ResolveAsync(async context =>
            {
                var enumerable = resolve(context);
                enumerable     = enumerable.ApplyGraphQlArguments(context);
                enumerable     = await filters.ApplyFilter(enumerable, context.UserContext);
                var page       = enumerable.ToList();

                return(ConnectionConverter.ApplyConnectionContext(
                           page,
                           context.First,
                           context.After,
                           context.Last,
                           context.Before));
            });
            return(builder);
        }
Пример #6
0
 /// <summary>
 ///  Strings which can call system commands within Ruby/Rails applications
 /// </summary>
 public IEnumerable <string> CommandInjectionRuby(int num = 1)
 {
     Guard.AgainstNegative(num, nameof(num));
     for (var i = 0; i < num; i++)
     {
         yield return(CommandInjectionRuby());
     }
 }
Пример #7
0
 /// <summary>
 ///  Strings which contain text that should be rendered RTL if possible (e.g. Arabic, Hebrew)
 /// </summary>
 public IEnumerable <string> RightToLeftStrings(int num = 1)
 {
     Guard.AgainstNegative(num, nameof(num));
     for (var i = 0; i < num; i++)
     {
         yield return(RightToLeftStrings());
     }
 }
Пример #8
0
 /// <summary>
 ///  Strings which consists of Japanese-style emoticons which are popular on the web
 /// </summary>
 public IEnumerable <string> JapaneseEmoticons(int num = 1)
 {
     Guard.AgainstNegative(num, nameof(num));
     for (var i = 0; i < num; i++)
     {
         yield return(JapaneseEmoticons());
     }
 }
Пример #9
0
 /// <summary>
 ///  Characters which increase in length (2 to 3 bytes) when lowercased Credit: https://twitter.com/jifa/status/625776454479970304
 /// </summary>
 public IEnumerable <string> Changinglengthwhenlowercased(int num = 1)
 {
     Guard.AgainstNegative(num, nameof(num));
     for (var i = 0; i < num; i++)
     {
         yield return(Changinglengthwhenlowercased());
     }
 }
Пример #10
0
 /// <summary>
 ///  Strings which contain unicode subscripts/superscripts; can cause rendering issues
 /// </summary>
 public IEnumerable <string> UnicodeSubscriptSuperscriptAccents(int num = 1)
 {
     Guard.AgainstNegative(num, nameof(num));
     for (var i = 0; i < num; i++)
     {
         yield return(UnicodeSubscriptSuperscriptAccents());
     }
 }
Пример #11
0
 public IEnumerable <Member> Member(int num = 1)
 {
     Guard.AgainstNegative(num, nameof(num));
     for (var i = 0; i < num; i++)
     {
         yield return(Member());
     }
 }
Пример #12
0
 public IEnumerable <Electorate> Electorate(int num = 1)
 {
     Guard.AgainstNegative(num, nameof(num));
     for (var i = 0; i < num; i++)
     {
         yield return(Electorate());
     }
 }
Пример #13
0
 /// <summary>
 ///  Strings which can be accidentally expanded into different strings if evaluated in the wrong context, e.g. used as a printf format string or via Perl or shell eval. Might expose sensitive data from the program doing the interpolation, or might just represent the wrong string.
 /// </summary>
 public IEnumerable <string> UnwantedInterpolation(int num = 1)
 {
     Guard.AgainstNegative(num, nameof(num));
     for (var i = 0; i < num; i++)
     {
         yield return(UnwantedInterpolation());
     }
 }
Пример #14
0
 /// <summary>
 ///  Strings which can cause user to pull in files that should not be a part of a web server
 /// </summary>
 public IEnumerable <string> FileInclusion(int num = 1)
 {
     Guard.AgainstNegative(num, nameof(num));
     for (var i = 0; i < num; i++)
     {
         yield return(FileInclusion());
     }
 }
Пример #15
0
 public IEnumerable <string> Isos(int num = 1)
 {
     Guard.AgainstNegative(num, nameof(num));
     for (var i = 0; i < num; i++)
     {
         yield return(Iso());
     }
 }
Пример #16
0
 public IEnumerable <string> CurrencyCodes(int num = 1)
 {
     Guard.AgainstNegative(num, nameof(num));
     for (var i = 0; i < num; i++)
     {
         yield return(CurrencyCode());
     }
 }
Пример #17
0
 /// <summary>
 ///
 /// </summary>
 public IEnumerable <string> Stringswhichcontaintwobyteletters(int num = 1)
 {
     Guard.AgainstNegative(num, nameof(num));
     for (var i = 0; i < num; i++)
     {
         yield return(Stringswhichcontaintwobyteletters());
     }
 }
Пример #18
0
 public IEnumerable <ushort> IsoNumerics(int num = 1)
 {
     Guard.AgainstNegative(num, nameof(num));
     for (var i = 0; i < num; i++)
     {
         yield return(IsoNumeric());
     }
 }
Пример #19
0
 public IEnumerable <ICountryInfo> CountryInfo(int num = 1)
 {
     Guard.AgainstNegative(num, nameof(num));
     for (var i = 0; i < num; i++)
     {
         yield return(CountryInfo());
     }
 }
Пример #20
0
 public IEnumerable <string> PostCodeRegexs(int num = 1)
 {
     Guard.AgainstNegative(num, nameof(num));
     for (var i = 0; i < num; i++)
     {
         yield return(PostCodeRegex());
     }
 }
Пример #21
0
 public IEnumerable <string> TopLevelDomains(int num = 1)
 {
     Guard.AgainstNegative(num, nameof(num));
     for (var i = 0; i < num; i++)
     {
         yield return(TopLevelDomain());
     }
 }
Пример #22
0
 /// <summary>
 ///  Strings which contain common unicode symbols (e.g. smart quotes)
 /// </summary>
 public IEnumerable <string> UnicodeSymbols(int num = 1)
 {
     Guard.AgainstNegative(num, nameof(num));
     for (var i = 0; i < num; i++)
     {
         yield return(UnicodeSymbols());
     }
 }
Пример #23
0
 /// <summary>
 ///  Strings which crashed iMessage in various versions of iOS
 /// </summary>
 public IEnumerable <string> iOSVulnerabilities(int num = 1)
 {
     Guard.AgainstNegative(num, nameof(num));
     for (var i = 0; i < num; i++)
     {
         yield return(iOSVulnerabilities());
     }
 }
Пример #24
0
 /// <summary>
 ///  ASCII punctuation.  All of these characters may need to be escaped in some contexts.  Divided into three groups based on (US-layout) keyboard position.
 /// </summary>
 public IEnumerable <string> SpecialCharacters(int num = 1)
 {
     Guard.AgainstNegative(num, nameof(num));
     for (var i = 0; i < num; i++)
     {
         yield return(SpecialCharacters());
     }
 }
Пример #25
0
 /// <summary>
 ///  Strings which punish the fools who use cat/type on this file
 /// </summary>
 public IEnumerable <string> Terminalescapecodes(int num = 1)
 {
     Guard.AgainstNegative(num, nameof(num));
     for (var i = 0; i < num; i++)
     {
         yield return(Terminalescapecodes());
     }
 }
Пример #26
0
 /// <summary>
 ///  Strings which may cause human to reinterpret worldview
 /// </summary>
 public IEnumerable <string> Humaninjection(int num = 1)
 {
     Guard.AgainstNegative(num, nameof(num));
     for (var i = 0; i < num; i++)
     {
         yield return(Humaninjection());
     }
 }
Пример #27
0
 /// <summary>
 ///  Innocuous strings which may be blocked by profanity filters (https://en.wikipedia.org/wiki/Scunthorpe_problem)
 /// </summary>
 public IEnumerable <string> ScunthorpeProblem(int num = 1)
 {
     Guard.AgainstNegative(num, nameof(num));
     for (var i = 0; i < num; i++)
     {
         yield return(ScunthorpeProblem());
     }
 }
Пример #28
0
 /// <summary>
 ///  Strings which are reserved characters in MSDOS/Windows
 /// </summary>
 public IEnumerable <string> MSDOSWindowsSpecialFilenames(int num = 1)
 {
     Guard.AgainstNegative(num, nameof(num));
     for (var i = 0; i < num; i++)
     {
         yield return(MSDOSWindowsSpecialFilenames());
     }
 }
Пример #29
0
 public static string Truncate(this string value, int maxLength)
 {
     Guard.AgainstNegative(nameof(maxLength), maxLength);
     if (string.IsNullOrEmpty(value))
     {
         return(value);
     }
     return(value.Length <= maxLength ? value : value.Substring(0, maxLength));
 }
Пример #30
0
        public HostAvailability(INetwork network,
                                IEnumerable <EvidenceProvider> dependencies, int timeout, IEnumerable <string> hosts) : base(dependencies)
        {
            Guard.AgainstNegative(nameof(timeout), timeout);
            Guard.AgainstNull(nameof(hosts), hosts);

            _network = network;
            _timeout = timeout;
            _hosts   = hosts;
        }