public async Task RunAsync() { // Commands var decoratedCommand = new FooCommand { Name = "Decorated command" }; await _executor.ExecuteAsync(decoratedCommand); await _writer.WriteLineAsync("----------------"); var regularCommand = new BarCommand { Name = "Regular command" }; var regularCommandResult = await _executor.ExecuteAsync(regularCommand); await _writer.WriteLineAsync("----------------"); var syncCommand = new BazCommand(); var syncCommandResult = await _executor.ExecuteAsync(syncCommand); await _writer.WriteLineAsync($"Sync command result is `{syncCommandResult}`"); await _writer.WriteLineAsync("----------------"); // Queries var regularQuery = new FooQuery { Number1 = 3, Number2 = 4 }; var regularQueryResult = await _executor.ExecuteAsync(regularQuery); await _writer.WriteLineAsync("----------------"); }
private static FooResult FooStub(FooQuery query) { var rand = new Random(); var result = Enumerable.Range(0, 50) .Select(i => string.Format("{0}:{1}", query.Bar, rand.Next())) .Select(fooBar => new FooBar(fooBar)); return(new FooResult(result)); }
public async void GetFoo_WhenThereIsAMatch_ReturnsTheFoo() { // arrange const string expectedId = "some-foo-id"; const string expectedName = "some-foo-name"; const string expectedDescription = "some-foo-description"; var expectedFoos = new[] { new Foo( expectedId, expectedName, expectedDescription ) }; var fooQuery = new FooQuery(expectedName); _mockProviderService .Given("There is a foo with some-foo-name") .UponReceiving("A GET request to retrieve foo") .With(new ProviderServiceRequest { Method = HttpVerb.Get, Path = "/foos", Query = "name=some-foo-name", Headers = new Dictionary <string, object> { { "Accept", "application/json" } } }) .WillRespondWith(new ProviderServiceResponse { Status = 200, Headers = new Dictionary <string, object> { { "Content-Type", "application/json; charset=utf-8" } }, Body = Match.MinType(new { id = Match.Type(expectedId), name = Match.Type(expectedName), description = Match.Type(expectedDescription) }, 1) }); var fooApiClient = new FooApiClient(_mockProviderServiceBaseUri); // act Foo[] actualFoos = await fooApiClient.GetFoo(fooQuery); //assert _mockProviderService.VerifyInteractions(); actualFoos.Should().BeEquivalentTo(expectedFoos.Cast <object>()); }
public async Task <Foo[]> GetFoo(FooQuery fooQuery) { NameValueCollection queryString = HttpUtility.ParseQueryString(string.Empty); queryString["name"] = fooQuery.Name; var uriBuilder = new UriBuilder(_baseUri) { Path = "/foos", Query = queryString.ToString() ?? string.Empty }; using var request = new HttpRequestMessage { Method = HttpMethod.Get, RequestUri = uriBuilder.Uri }; request.Headers.Add("Accept", "application/json"); using var httpClient = new HttpClient(); using HttpResponseMessage response = await httpClient.SendAsync(request); HttpStatusCode status = response.StatusCode; if (status != HttpStatusCode.OK) { throw new Exception(response.ReasonPhrase); } await using Stream stream = await response.Content.ReadAsStreamAsync(); var options = new JsonSerializerOptions { PropertyNameCaseInsensitive = true, }; return(await JsonSerializer.DeserializeAsync <Foo[]>(stream, options)); }
/// <summary> /// Required method for Designer support - do not modify /// the contents of this method with the code editor. /// </summary> private void InitializeComponent() { this.button1 = new System.Windows.Forms.Button(); this.button2 = new System.Windows.Forms.Button(); this.button3 = new System.Windows.Forms.Button(); this.button4 = new System.Windows.Forms.Button(); this.button5 = new System.Windows.Forms.Button(); this.button6 = new System.Windows.Forms.Button(); this.fooQuery1 = new MicroORMTest.FooQuery(); this.SuspendLayout(); // // button1 // this.button1.BackColor = System.Drawing.Color.WhiteSmoke; this.button1.FlatStyle = System.Windows.Forms.FlatStyle.Flat; this.button1.Location = new System.Drawing.Point(12, 50); this.button1.Name = "button1"; this.button1.Size = new System.Drawing.Size(75, 23); this.button1.TabIndex = 0; this.button1.Text = "Read"; this.button1.UseVisualStyleBackColor = false; this.button1.Click += new System.EventHandler(this.button1_Click); // // button2 // this.button2.BackColor = System.Drawing.Color.WhiteSmoke; this.button2.FlatStyle = System.Windows.Forms.FlatStyle.Flat; this.button2.Location = new System.Drawing.Point(12, 12); this.button2.Name = "button2"; this.button2.Size = new System.Drawing.Size(75, 23); this.button2.TabIndex = 1; this.button2.Text = "Create"; this.button2.UseVisualStyleBackColor = false; this.button2.Click += new System.EventHandler(this.button2_Click); // // button3 // this.button3.BackColor = System.Drawing.Color.WhiteSmoke; this.button3.FlatStyle = System.Windows.Forms.FlatStyle.Flat; this.button3.Location = new System.Drawing.Point(12, 93); this.button3.Name = "button3"; this.button3.Size = new System.Drawing.Size(75, 23); this.button3.TabIndex = 2; this.button3.Text = "Update"; this.button3.UseVisualStyleBackColor = false; this.button3.Click += new System.EventHandler(this.button3_Click); // // button4 // this.button4.BackColor = System.Drawing.Color.WhiteSmoke; this.button4.FlatStyle = System.Windows.Forms.FlatStyle.Flat; this.button4.Location = new System.Drawing.Point(12, 133); this.button4.Name = "button4"; this.button4.Size = new System.Drawing.Size(75, 23); this.button4.TabIndex = 3; this.button4.Text = "Delete"; this.button4.UseVisualStyleBackColor = false; this.button4.Click += new System.EventHandler(this.button4_Click); // // button5 // this.button5.BackColor = System.Drawing.Color.WhiteSmoke; this.button5.FlatStyle = System.Windows.Forms.FlatStyle.Flat; this.button5.Location = new System.Drawing.Point(114, 12); this.button5.Name = "button5"; this.button5.Size = new System.Drawing.Size(121, 23); this.button5.TabIndex = 4; this.button5.Text = "Bulk Create"; this.button5.UseVisualStyleBackColor = false; this.button5.Click += new System.EventHandler(this.button5_Click); // // button6 // this.button6.BackColor = System.Drawing.Color.WhiteSmoke; this.button6.FlatStyle = System.Windows.Forms.FlatStyle.Flat; this.button6.Location = new System.Drawing.Point(114, 50); this.button6.Name = "button6"; this.button6.Size = new System.Drawing.Size(121, 23); this.button6.TabIndex = 5; this.button6.Text = "Bulk Read"; this.button6.UseVisualStyleBackColor = false; this.button6.Click += new System.EventHandler(this.button6_Click); // // fooQuery1 // this.fooQuery1.Location = new System.Drawing.Point(3, 173); this.fooQuery1.Name = "fooQuery1"; this.fooQuery1.Size = new System.Drawing.Size(279, 149); this.fooQuery1.TabIndex = 6; this.fooQuery1.Load += new System.EventHandler(this.OnLoad); // // PetaPocoForm // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.BackColor = System.Drawing.SystemColors.ActiveCaption; this.ClientSize = new System.Drawing.Size(284, 334); this.Controls.Add(this.fooQuery1); this.Controls.Add(this.button6); this.Controls.Add(this.button5); this.Controls.Add(this.button4); this.Controls.Add(this.button3); this.Controls.Add(this.button2); this.Controls.Add(this.button1); this.Name = "PetaPocoForm"; this.Text = "PetaPoco"; this.ResumeLayout(false); }
public FooResponse Foo(FooQuery foo) => Execute(foo, query => _wsClient.Foo(query));