public Wallet[] GetWallets() { var resultText = _requestExecutor.Execute("listreceivedbyaddress", new Dictionary <string, string>()); var resultValue = JObject.Parse(resultText); var result = JsonConvert.DeserializeObject <Wallet[]>(resultValue["result"].ToString()); return(result); }
public void NotThrow_When_SingleRequestFails() { A.CallTo(() => requestsExecutor.Execute(A <RequestProcessorProcessArgs <object> > .Ignored)) .Throws(_ => new Exception()); new Action(() => requestsCollection.TryStartExecuteNew("stub")) .Should() .NotThrow(); }
public async Task <Models.Channel> JoinDirectMessageChannel(string slackKey, string user) { var request = new RestRequest(JOIN_DM_PATH); request.AddParameter("token", slackKey); request.AddParameter("user", user); var response = await _requestExecutor.Execute <JoinChannelResponse>(request); return(response.Channel); }
public async Task PostFile(string slackKey, string channel, string file) { var request = new RestRequest(FILE_UPLOAD_PATH); request.AddParameter("token", slackKey); request.AddParameter("channels", channel); request.AddParameter("filename", Path.GetFileName(file)); request.AddFile("file", file); await _requestExecutor.Execute <StandardResponse>(request); }
public static IExecutionResult Execute( this IRequestExecutor executor, string query, IReadOnlyDictionary <string, object?> variableValues) { if (executor is null) { throw new ArgumentNullException(nameof(executor)); } if (string.IsNullOrEmpty(query)) { throw new ArgumentException( ExecutionRequestExecutorExtensions_ExecuteAsync_QueryCannotBeNullOrEmpty, nameof(query)); } if (variableValues is null) { throw new ArgumentNullException(nameof(variableValues)); } return(executor.Execute( QueryRequestBuilder.New() .SetQuery(query) .SetVariableValues(variableValues) .Create())); }
public static IExecutionResult Execute( this IRequestExecutor executor, string query, IReadOnlyDictionary <string, object> variableValues) { if (executor is null) { throw new ArgumentNullException(nameof(executor)); } if (string.IsNullOrEmpty(query)) { throw new ArgumentException( "The query mustn't be null or empty.", nameof(query)); } if (variableValues is null) { throw new ArgumentNullException(nameof(variableValues)); } return(executor.Execute( QueryRequestBuilder.New() .SetQuery(query) .SetVariableValues(variableValues) .Create())); }
public virtual void Execute_SelectionMultiple_ShouldThrowOnMultiple() { // arrange IServiceCollection services; Func <IResolverContext, IEnumerable <Foo> > resolver; (services, resolver) = _provider.CreateResolver( Foo.Create("aa", 1, false), Foo.Create("bb", 2, false)); ISchema schema = SchemaBuilder.New() .AddServices(services.BuildServiceProvider()) .AddQueryType <Query>(d => d.Field(t => t.FoosMultiple) .Resolver(resolver)) .Create(); IRequestExecutor executor = schema.MakeExecutable(); // act IExecutionResult result = executor.Execute( "{ foosMultiple { bar baz } }"); // assert result.ToJson().MatchSnapshot(); }
public virtual void Execute_Selection_MultipleScalarShouldReturnOne() { // arrange IServiceCollection services; Func <IResolverContext, IEnumerable <Foo> > resolver; (services, resolver) = _provider.CreateResolver( Foo.Create("aa", 1, false)); Foo resultCtx = null; ISchema schema = SchemaBuilder.New() .AddServices(services.BuildServiceProvider()) .AddQueryType <Query>(d => d.Field(t => t.Foos) .Resolver(resolver) .Use(next => async ctx => { await next(ctx).ConfigureAwait(false); resultCtx = ctx.Result as Foo; })) .Create(); IRequestExecutor executor = schema.MakeExecutable(); // act executor.Execute( "{ foos { bar baz } }"); // assert Assert.NotNull(resultCtx); Assert.Equal("aa", resultCtx.Bar); Assert.Equal(1, resultCtx.Baz); Assert.Null(resultCtx.Nested); Assert.Null(resultCtx.NestedCollection); }
public void TestSetAnswerMutation() { QuestionService questionService = new QuestionService(_context); string questionId = questionService.GetAll().First().Id; IRequestExecutor executor = MakeExecutor(); IServiceProvider serviceProvider = BuildServiceProvider(); IReadOnlyQueryRequest request = QueryRequestBuilder.New() .SetQuery(@" mutation( $questionId: String!, $severity: Severity! ) { setAnswer( questionId: $questionId, severity: $severity, text: ""New answer text!"" ){ id } } ") .SetVariableValue("questionId", questionId) .SetVariableValue("severity", Severity.High) .SetServices(serviceProvider) .Create(); IExecutionResult result = executor.Execute(request); IReadOnlyList <IError> errors = result.Errors ?? new List <IError>(); foreach (IError err in errors) { throw err.Exception; } }
public void Convert_Parts_Of_The_Input_Graph() { // arrange var services = new ServiceCollection() .AddSingleton <ITypeConverter, DefaultTypeConverter>() .AddTypeConverter <Baz, Bar>(from => new Bar { Text = from.Text }) .AddTypeConverter <Bar, Baz>(from => new Baz { Text = from.Text }) .BuildServiceProvider(); ISchema schema = SchemaBuilder.New() .AddQueryType <QueryType>() .AddServices(services) .Create(); IRequestExecutor executor = schema.MakeExecutable(); // act IExecutionResult result = executor.Execute( "{ foo(a: { bar: { text: \"abc\" } }) }"); // assert result.ToJson().MatchSnapshot(); }
public virtual void Execute_Single_PureCodeFirst() { // arrange IServiceCollection services; Func <IResolverContext, IEnumerable <Foo> > resolver; (services, resolver) = _provider.CreateResolver(Sample); Foo resultCtx = null; ISchema schema = SchemaBuilder.New() .AddServices(services.BuildServiceProvider()) .AddQueryType <Query>( d => d.Field(t => t.Foos) .Resolver(resolver) .Use(next => async ctx => { await next(ctx).ConfigureAwait(false); resultCtx = ctx.Result as Foo; }) .UseSingleOrDefault() .UseSelection()) .Create(); IRequestExecutor executor = schema.MakeExecutable(); // act executor.Execute("{ foos { bar } }"); // assert // assert Assert.NotNull(resultCtx); Assert.Equal("aa", resultCtx.Bar); Assert.Equal(0, resultCtx.Baz); }
public virtual void Execute_Single_ShouldThrowWhenMoreThanOne() { // arrange IServiceCollection services; Func <IResolverContext, IEnumerable <Foo> > resolver; (services, resolver) = _provider.CreateResolver( new[] { Foo.Create("aa", 1), Foo.Create("aa", 2) }); ISchema schema = SchemaBuilder.New() .AddServices(services.BuildServiceProvider()) .AddQueryType <Query>( d => d.Field(t => t.Foos) .Resolver(resolver) .UseSingleOrDefault() .UseSelection()) .Create(); IRequestExecutor executor = schema.MakeExecutable(); // act IExecutionResult result = executor.Execute("{ foos { bar baz} }"); // assert result.ToJson().MatchSnapshot(); }
public void Execute_Filter_As_Variable() { // arrange ISchema schema = SchemaBuilder.New() .AddQueryType <QueryType>() .Create(); IRequestExecutor executor = schema.MakeExecutable(); IReadOnlyQueryRequest request = QueryRequestBuilder.New() .SetQuery( @"query filter($a: FooFilter) { foos(where: $a) { bar } }") .SetVariableValue("a", new ObjectValueNode( new ObjectFieldNode("bar_starts_with", "a"))) .Create(); // act IExecutionResult result = executor.Execute(request); // assert result.ToJson().MatchSnapshot(); }
public void Execute_Filter_With_Variables() { // arrange ISchema schema = SchemaBuilder.New() .AddQueryType <QueryType>() .Create(); IRequestExecutor executor = schema.MakeExecutable(); IReadOnlyQueryRequest request = QueryRequestBuilder.New() .SetQuery( @"query filter($a: String) { foos(where: { bar_starts_with: $a }) { bar } }") .SetVariableValue("a", "a") .Create(); // act IExecutionResult result = executor.Execute(request); // assert result.MatchSnapshot(); }
public virtual void Execute_Single_OverrideListType() { // arrange IServiceCollection services; Func <IResolverContext, IEnumerable <Foo> > resolver; (services, resolver) = _provider.CreateResolver(Sample); Foo resultCtx = null; ISchema schema = SchemaBuilder.New() .AddServices(services.BuildServiceProvider()) .AddQueryType <Query>( d => d.Field(t => t.Foos) .Resolver(resolver) .Use(next => async ctx => { await next(ctx).ConfigureAwait(false); resultCtx = ctx.Result as Foo; }) .Type <ListType <FooType> >() .UseSingleOrDefault() .UseSelection()) .Create(); IRequestExecutor executor = schema.MakeExecutable(); // act IExecutionResult executionResult = executor.Execute("{ foos { fakeBar } }"); // assert Assert.NotNull(resultCtx); Assert.Equal("aa", resultCtx.Bar); Assert.Equal(0, resultCtx.Baz); Snapshot.Match(executionResult, "execute_single_overrides_results"); Snapshot.Match(schema.ToString(), "execute_single_overrides_schema"); }
public virtual void ExecuteAsync_SelectionMultiple_ShouldThrowOnMultiple() { // arrange IServiceCollection services; Func <IResolverContext, IAsyncEnumerable <Foo> > resolver; (services, resolver) = _provider.CreateAsyncResolver( Foo.Create("aa", 1, false), Foo.Create("bb", 2, false)); Foo resultCtx = null; ISchema schema = SchemaBuilder.New() .AddServices(services.BuildServiceProvider()) .AddQueryType <Query>(d => d.Field(t => t.FoosMultipleAsync) .Resolver(resolver) .Use(next => async ctx => { await next(ctx).ConfigureAwait(false); resultCtx = ctx.Result as Foo; })) .Create(); IRequestExecutor executor = schema.MakeExecutable(); // act IExecutionResult result = executor.Execute( "{ foosMultipleAsync { bar baz } }"); // assert result.ToJson().MatchSnapshot(); }
public async Task PostMessage(string slackKey, string channel, string text, IList <SlackAttachment> attachments) { var request = new RestRequest(SEND_MESSAGE_PATH); request.AddParameter("token", slackKey); request.AddParameter("channel", channel); request.AddParameter("text", text); request.AddParameter("as_user", "true"); if (attachments != null && attachments.Any()) { request.AddParameter("attachments", JsonConvert.SerializeObject(attachments)); } await _requestExecutor.Execute <StandardResponse>(request); }
public async Task <HandshakeResponse> FirmShake(string slackKey) { var request = new RestRequest(HANDSHAKE_PATH); request.AddParameter("token", slackKey); return(await _requestExecutor.Execute <HandshakeResponse>(request)); }
private void Execute(TRequestParams parameters, IUserMessagePrinter requestUserMessagePrinter) { var processArgs = new RequestProcessorProcessArgs <TRequestParams> { RequestParams = parameters, UserMessagePrinter = requestUserMessagePrinter }; requestExecutor.Execute(processArgs); }
public virtual void Execute_Selection_ObjectDeep() { // arrange IServiceCollection services; Func <IResolverContext, IEnumerable <Foo> > resolver; (services, resolver) = _provider.CreateResolver(SAMPLE); IQueryable <Foo> resultCtx = null; ISchema schema = SchemaBuilder.New() .AddServices(services.BuildServiceProvider()) .AddQueryType <Query>( d => d.Field(t => t.Foos) .Resolver(resolver) .Use(next => async ctx => { await next(ctx).ConfigureAwait(false); resultCtx = ctx.Result as IQueryable <Foo>; }) .UseSelection()) .Create(); IRequestExecutor executor = schema.MakeExecutable(); // act executor.Execute( "{ foos { nested { nested { nested { nested { bar } } } } } }"); // assert Assert.NotNull(resultCtx); Assert.Collection(resultCtx.ToArray(), x => { Assert.Null(x.Bar); Assert.Equal(0, x.Baz); Assert.NotNull(x.Nested); Assert.Equal(0, x.Nested.Baz); Assert.Null(x.ObjectArray); Assert.Null(x.Nested.ObjectArray); Assert.Null(x.Nested.Nested.Bar); Assert.Null(x.Nested.Nested.Nested.Bar); Assert.Equal("recursiveaa", x.Nested.Nested.Nested.Nested.Bar); }, x => { Assert.Null(x.Bar); Assert.Equal(0, x.Baz); Assert.NotNull(x.Nested); Assert.Equal(0, x.Nested.Baz); Assert.Null(x.ObjectArray); Assert.Null(x.Nested.ObjectArray); Assert.Null(x.Nested.Nested.Bar); Assert.Null(x.Nested.Nested.Nested.Bar); Assert.Equal("recursivebb", x.Nested.Nested.Nested.Nested.Bar); }); }
public IResponse Execute(IRequest request) { try { return(requestExecutor.Execute(request)); } catch (Exception e) { log.Error(String.Format("Error while executing a certain {0}", request.GetType()), e); return(null); } }
public virtual void Execute_Selection_Object_Paging_Combined() { // arrange IServiceCollection services; Func <IResolverContext, IEnumerable <Foo> > resolver; (services, resolver) = _provider.CreateResolver(SAMPLE); Connection <Foo> resultCtx = null; ISchema schema = SchemaBuilder.New() .AddServices(services.BuildServiceProvider()) .AddQueryType <Query>( d => d.Field(t => t.Foos) .Resolver(resolver) .Use(next => async ctx => { await next(ctx).ConfigureAwait(false); resultCtx = ctx.Result as Connection <Foo>; }) .UsePaging <ObjectType <Foo> >() .UseFiltering() .UseSorting() .UseSelection()) .Create(); IRequestExecutor executor = schema.MakeExecutable(); // act IExecutionResult result = executor.Execute( "{ foos { nodes { nested { bar } } edges { node { bar }} } }"); // assert Assert.NotNull(resultCtx); Assert.Collection(resultCtx.Edges.ToArray(), x => { Assert.Equal("aa", x.Node.Bar); Assert.Equal(0, x.Node.Baz); Assert.NotNull(x.Node.Nested); Assert.Equal("nestedaa", x.Node.Nested.Bar); Assert.Equal(0, x.Node.Nested.Baz); Assert.Null(x.Node.ObjectArray); }, x => { Assert.Equal("bb", x.Node.Bar); Assert.Equal(0, x.Node.Baz); Assert.NotNull(x.Node.Nested); Assert.Equal("nestedbb", x.Node.Nested.Bar); Assert.Equal(0, x.Node.Nested.Baz); Assert.Null(x.Node.ObjectArray); }); }
public Task OnPublish(DateTime simulatedDate) { var matchingRequests = _simulatedRequests.ContainsKey(simulatedDate) ? _simulatedRequests[simulatedDate] : new ISimulatedRequest[0]; //Console.WriteLine($"[RequestDelegator]: Found {matchingRequests.Count} matching requests for {simulatedDate}"); foreach (var request in matchingRequests) { _requestExecutor.Execute(request); } return(Task.CompletedTask); }
public async Task <T> SendRequest <T>(string slackKey, ApiRequest <T> apiRequest) where T : ApiResponceBase { RequestPath path = RequestPath.GetRequestPath <T>(); var request = new RestRequest(SendMessagePath + path.Path); request.AddParameter("token", slackKey); foreach (var parameter in apiRequest.Parameters) { request.AddParameter(parameter.Key, parameter.Value); } var response = await _requestExecutor.Execute <T>(request); return(response); }
public void Execute_Filter_Comparable_In() { // arrange ISchema schema = SchemaBuilder.New() .AddQueryType <Query>(d => d.Field(t => t.Foos).UseFiltering()) .Create(); IRequestExecutor executor = schema.MakeExecutable(); // act IExecutionResult result = executor.Execute( "{ foos(where: { baz_in: [ 1 0 ] }) { bar } }"); // assert result.MatchSnapshot(); }
public void Infer_Filter_From_Field() { // arrange ISchema schema = SchemaBuilder.New() .AddQueryType <Query>(d => d.Field(t => t.Foos).UseFiltering()) .Create(); IRequestExecutor executor = schema.MakeExecutable(); // act IExecutionResult result = executor.Execute( "{ foos(where: { bar_starts_with: \"a\" }) { bar } }"); // assert result.MatchSnapshot(); }
public void Execute_Filter_Is_Null() { // arrange ISchema schema = SchemaBuilder.New() .AddQueryType <QueryType>() .Create(); IRequestExecutor executor = schema.MakeExecutable(); // act IExecutionResult result = executor.Execute( "{ foos { bar } }"); // assert result.MatchSnapshot(); }
public void Execute_Filter() { // arrange ISchema schema = SchemaBuilder.New() .AddQueryType <QueryType>() .Create(); IRequestExecutor executor = schema.MakeExecutable(); // act IExecutionResult result = executor.Execute( "{ foos(where: { bar_starts_with: \"a\" }) { bar } }"); // assert result.MatchSnapshot(); }
public void Execute_Filter_Nullable_Equals_Null() { // arrange ISchema schema = SchemaBuilder.New() .AddQueryType <Query>(d => d.Field(t => t.Foos).UseFiltering()) .Create(); IRequestExecutor executor = schema.MakeExecutable(); // act IExecutionResult result = executor.Execute( "{ foos(where: { qux: null }) { bar qux } }"); // assert result.MatchSnapshot(); }
public void Execute_Filter_Equals_Or() { // arrange ISchema schema = SchemaBuilder.New() .AddQueryType <Query>(d => d.Field(t => t.Foos).UseFiltering()) .Create(); IRequestExecutor executor = schema.MakeExecutable(); // act IExecutionResult result = executor.Execute( "{ foos(where: { OR: [ { bar: \"aa\" } { bar: \"ba\" } ] })" + " { bar } }"); // assert result.MatchSnapshot(); }