/// <summary> /// Creates the <see cref="Person"/> object. /// </summary> /// <param name="value">The <see cref="Person"/> object.</param> /// <param name="requestOptions">The optional <see cref="WebApiRequestOptions"/>.</param> /// <returns>A <see cref="WebApiAgentResult"/>.</returns> public Task <WebApiAgentResult <Person> > CreateAsync(Person value, WebApiRequestOptions requestOptions = null) { if (value == null) { throw new ArgumentNullException("value"); } return(PersonServiceAgent.CreateAsync(value, requestOptions)); }
/// <summary> /// Updates the <see cref="Robot"/> object. /// </summary> /// <param name="value">The <see cref="Robot"/> object.</param> /// <param name="id">The <see cref="Robot"/> identifier.</param> /// <param name="requestOptions">The optional <see cref="WebApiRequestOptions"/>.</param> /// <returns>A <see cref="WebApiAgentResult"/>.</returns> public Task <WebApiAgentResult <Robot> > UpdateAsync(Robot value, Guid id, WebApiRequestOptions requestOptions = null) { if (value == null) { throw new ArgumentNullException("value"); } return(RobotServiceAgent.UpdateAsync(value, id, requestOptions)); }
/// <summary> /// Creates the <see cref="Gender"/> object. /// </summary> /// <param name="value">The <see cref="Gender"/> object.</param> /// <param name="requestOptions">The optional <see cref="WebApiRequestOptions"/>.</param> /// <returns>A <see cref="WebApiAgentResult"/>.</returns> public Task <WebApiAgentResult <Gender> > CreateAsync(Gender value, WebApiRequestOptions requestOptions = null) { if (value == null) { throw new ArgumentNullException("value"); } return(base.PostAsync <Gender>("api/v1/demo/ref/genders", value, requestOptions: requestOptions, args: new WebApiArg[] { })); }
/// <summary> /// Updates the <see cref="Gender"/> object. /// </summary> /// <param name="value">The <see cref="Gender"/> object.</param> /// <param name="id">The <see cref="Gender"/> identifier.</param> /// <param name="requestOptions">The optional <see cref="WebApiRequestOptions"/>.</param> /// <returns>A <see cref="WebApiAgentResult"/>.</returns> public Task <WebApiAgentResult <Gender> > UpdateAsync(Gender value, Guid id, WebApiRequestOptions requestOptions = null) { if (value == null) { throw new ArgumentNullException("value"); } return(base.PutAsync <Gender>("api/v1/demo/ref/genders/{id}", value, requestOptions: requestOptions, args: new WebApiArg[] { new WebApiArg <Guid>("id", id) })); }
/// <summary> /// Creates the <see cref="Robot"/> object. /// </summary> /// <param name="value">The <see cref="Robot"/> object.</param> /// <param name="requestOptions">The optional <see cref="WebApiRequestOptions"/>.</param> /// <returns>A <see cref="WebApiAgentResult"/>.</returns> public Task <WebApiAgentResult <Robot> > CreateAsync(Robot value, WebApiRequestOptions requestOptions = null) { if (value == null) { throw new ArgumentNullException("value"); } return(base.PostAsync <Robot>("api/v1/robots", value, requestOptions: requestOptions, args: new WebApiArg[] { })); }
/// <summary> /// Creates the <see cref="Person"/> object. /// </summary> /// <param name="value">The <see cref="Person"/> object.</param> /// <param name="requestOptions">The optional <see cref="WebApiRequestOptions"/>.</param> /// <returns>A <see cref="WebApiAgentResult"/>.</returns> public Task <WebApiAgentResult <Person> > CreateWithEfAsync(Person value, WebApiRequestOptions requestOptions = null) { if (value == null) { throw new ArgumentNullException("value"); } return(base.PostAsync <Person>("api/v1/persons/ef", value, requestOptions: requestOptions, args: new WebApiArg[] { })); }
/// <summary> /// Gets the reference data entries for the specified entities and codes from the query string; e.g: api/v1/demo/ref?entity=codeX,codeY&entity2=codeZ&entity3 /// </summary> /// <param name="names">The list of reference data names.</param> /// <param name="requestOptions">The optional <see cref="WebApiRequestOptions"/>.</param> /// <returns>A <see cref="WebApiAgentResult"/>.</returns> /// <remarks>The reference data objects will need to be manually extracted from the corresponding response content.</remarks> public Task <WebApiAgentResult> GetNamedAsync(string[] names, WebApiRequestOptions requestOptions = null) { var ro = requestOptions ?? new WebApiRequestOptions(); if (names != null) { ro.UrlQueryString += string.Join("&", names); } return(base.GetAsync("api/v1/demo/ref", requestOptions: ro)); }
private static WebApiRequestOptions CreateRequestOptions(string queryParams = null) { var options = new WebApiRequestOptions { EndpointPath = "/some/endpoint" }; if (!string.IsNullOrWhiteSpace(queryParams)) { options.EndpointQuery = queryParams.Split('&').Select(x => x.Split('=')).ToDictionary(x => x[0], x => x.Skip(1).FirstOrDefault()); } return(options); }
public void C120_GetAll_PagingAndFieldFiltering() { var pa = PagingArgs.CreateSkipAndTake(1, 2); var ro = new WebApiRequestOptions().Include("lastName", "firstName"); var pcr = AgentTester.Create <PersonAgent, PersonCollectionResult>() .ExpectStatusCode(HttpStatusCode.OK) .Run((a) => a.Agent.GetAllAsync(pa, ro)); // Check only 2 are returned in the sorted order. Assert.AreEqual(2, pcr?.Value?.Result?.Count); Assert.AreEqual(new string[] { "Jones", "Smith", }, pcr.Value.Result.Select(x => x.LastName).ToArray()); Assert.IsFalse(pcr.Value.Result.Any(x => x.Id != Guid.Empty)); }
public void CreatesCorrectUrl(string baseUrl, string endpointPath, string pathSuffix, IDictionary <string, string>?endpointQuery) { endpointQuery ??= new Dictionary <string, string>(); string expected = Uri.EscapeUriString($"{baseUrl}{endpointPath}{pathSuffix}") + (endpointQuery.Count > 0 ? "?" + string.Join("&", endpointQuery.Select(x => $"{Uri.EscapeDataString(x.Key)}{(x.Value != null ? $"={Uri.EscapeDataString(x.Value)}" : string.Empty)}")) : string.Empty); string actual = new WebApiRequestOptions { BaseUrl = baseUrl, EndpointPath = endpointPath, PathSuffix = pathSuffix, EndpointQuery = endpointQuery }.Url.AbsoluteUri; actual.Should().BeEquivalentTo(expected); }
public async Task RequestIsNotSplitIfLessThanOrEqualToMaxTest(int maxRequestSize, [Frozen] MiddlewareContext context) { var options = new WebApiRequestOptions { BulkQueryParameterIdsName = "ids", EndpointPath = "/some/endpoint", EndpointQuery = new Dictionary <string, string> { ["ids"] = "K1,K2,K3" } }; context.Request.Options.Returns(options); var elements = new[] { new Element { Id = "K1", Value = "V1" }, new Element { Id = "K2", Value = "V2" }, new Element { Id = "K3", Value = "V3" } }; var middleware = new RequestSplitterMiddleware { MaxRequestSize = maxRequestSize }; var response = await middleware.OnRequestAsync(context, (c, t) => { var ids = c.Request.Options.EndpointQuery["ids"].Split(','); ids.Should().HaveCountLessOrEqualTo(middleware.MaxRequestSize); ids.Should().BeEquivalentTo(elements.Select(x => x.Id)); IWebApiResponse innerResponse = new WebApiResponse(JsonSerializer.Serialize(elements)); return(Task.FromResult(innerResponse)); }); var actual = JsonSerializer.Deserialize <IList <Element> >(response.Content); actual.Should().BeEquivalentTo(elements); }
public async Task RequestIsNotSplitNotBulkTest([Frozen] MiddlewareContext context, [Frozen] IWebApiResponse response, Element element) { var options = new WebApiRequestOptions { BulkQueryParameterIdsName = "ids", EndpointPath = "/some/endpoint", EndpointQuery = new Dictionary <string, string>() }; context.Request.Options.Returns(options); string rawResponse = JsonSerializer.Serialize(element); response.Content.Returns(rawResponse); var middleware = new RequestSplitterMiddleware(); var finalResponse = await middleware.OnRequestAsync(context, (c, t) => Task.FromResult(response)); finalResponse.Should().BeEquivalentTo(response); }
/// <summary> /// Gets the <see cref="Product"/> object that matches the selection criteria. /// </summary> /// <param name="id">The <see cref="Product"/> identifier.</param> /// <param name="requestOptions">The optional <see cref="WebApiRequestOptions"/>.</param> /// <returns>A <see cref="WebApiAgentResult"/>.</returns> public Task <WebApiAgentResult <Product> > GetAsync(int id, WebApiRequestOptions requestOptions = null) { return(base.GetAsync <Product>("api/v1/products/{id}", requestOptions: requestOptions, args: new WebApiArg[] { new WebApiArg <int>("id", id) })); }
/// <summary> /// Updates the <see cref="Person"/> object. /// </summary> /// <param name="value">The <see cref="Person"/> object.</param> /// <param name="id">The <see cref="Person"/> identifier.</param> /// <param name="requestOptions">The optional <see cref="WebApiRequestOptions"/>.</param> /// <returns>A <see cref="WebApiAgentResult"/>.</returns> public Task <WebApiAgentResult <Person> > UpdateWithEfAsync(Person value, Guid id, WebApiRequestOptions requestOptions = null) { if (value == null) { throw new ArgumentNullException("value"); } return(PersonServiceAgent.UpdateWithEfAsync(value, id, requestOptions)); }
/// <summary> /// Gets the <see cref="Person"/> object that matches the selection criteria. /// </summary> /// <param name="id">The <see cref="Person"/> identifier.</param> /// <param name="requestOptions">The optional <see cref="WebApiRequestOptions"/>.</param> /// <returns>A <see cref="WebApiAgentResult"/>.</returns> public Task <WebApiAgentResult <Person> > GetWithEfAsync(Guid id, WebApiRequestOptions requestOptions = null) { return(PersonServiceAgent.GetWithEfAsync(id, requestOptions)); }
/// <summary> /// Gets the <see cref="Person"/> collection object that matches the selection criteria. /// </summary> /// <param name="args">The Args (see <see cref="PersonArgs"/>).</param> /// <param name="paging">The <see cref="PagingArgs"/>.</param> /// <param name="requestOptions">The optional <see cref="WebApiRequestOptions"/>.</param> /// <returns>A <see cref="WebApiAgentResult"/>.</returns> public Task <WebApiAgentResult <PersonCollectionResult> > GetByArgsWithEfAsync(PersonArgs args, PagingArgs paging = null, WebApiRequestOptions requestOptions = null) { return(PersonServiceAgent.GetByArgsWithEfAsync(args, paging, requestOptions)); }
/// <summary> /// Actually validating the FromBody parameter generation. /// </summary> /// <param name="person">The Person (see <see cref="Person"/>).</param> /// <param name="requestOptions">The optional <see cref="WebApiRequestOptions"/>.</param> /// <returns>A <see cref="WebApiAgentResult"/>.</returns> public Task <WebApiAgentResult> AddAsync(Person person, WebApiRequestOptions requestOptions = null) { return(PersonServiceAgent.AddAsync(person, requestOptions)); }
/// <summary> /// Patches the <see cref="Person"/> object. /// </summary> /// <param name="patchOption">The <see cref="WebApiPatchOption"/>.</param> /// <param name="value">The JSON patch value.</param> /// <param name="id">The <see cref="Person"/> identifier.</param> /// <param name="requestOptions">The optional <see cref="WebApiRequestOptions"/>.</param> /// <returns>A <see cref="WebApiAgentResult"/>.</returns> public Task <WebApiAgentResult <PersonDetail> > PatchDetailAsync(WebApiPatchOption patchOption, JToken value, Guid id, WebApiRequestOptions requestOptions = null) { return(PersonServiceAgent.PatchDetailAsync(patchOption, value, id, requestOptions)); }
/// <summary> /// Mark <see cref="Person"/>. /// </summary> /// <param name="requestOptions">The optional <see cref="WebApiRequestOptions"/>.</param> /// <returns>A <see cref="WebApiAgentResult"/>.</returns> public Task <WebApiAgentResult> MarkAsync(WebApiRequestOptions requestOptions = null) { return(PersonServiceAgent.MarkAsync(requestOptions)); }
/// <summary> /// Merge first <see cref="Person"/> into second. /// </summary> /// <param name="fromId">The from <see cref="Person"/> identifier.</param> /// <param name="toId">The to <see cref="Person"/> identifier.</param> /// <param name="requestOptions">The optional <see cref="WebApiRequestOptions"/>.</param> /// <returns>A <see cref="WebApiAgentResult"/>.</returns> public Task <WebApiAgentResult <Person> > MergeAsync(Guid fromId, Guid toId, WebApiRequestOptions requestOptions = null) { return(PersonServiceAgent.MergeAsync(fromId, toId, requestOptions)); }
/// <summary> /// Updates the <see cref="CustomerGroup"/> object. /// </summary> /// <param name="value">The <see cref="CustomerGroup"/> object.</param> /// <param name="id">The <see cref="CustomerGroup"/> identifier.</param> /// <param name="company">The Company (see <see cref="RefDataNamespace.Company"/>).</param> /// <param name="requestOptions">The optional <see cref="WebApiRequestOptions"/>.</param> /// <returns>A <see cref="WebApiAgentResult"/>.</returns> public Task <WebApiAgentResult <CustomerGroup> > UpdateAsync(CustomerGroup value, string id, RefDataNamespace.Company company, WebApiRequestOptions requestOptions = null) { if (value == null) { throw new ArgumentNullException("value"); } return(CustomerGroupServiceAgent.UpdateAsync(value, id, company, requestOptions)); }
/// <summary> /// Gets all of the <see cref="RefDataNamespace.Gender"/> objects that match the filter arguments. /// </summary> /// <param name="args">The optional <see cref="ReferenceDataFilter"/> arguments.</param> /// <param name="requestOptions">The optional <see cref="WebApiRequestOptions"/>.</param> /// <returns>A <see cref="WebApiAgentResult"/>.</returns> public Task <WebApiAgentResult <RefDataNamespace.GenderCollection> > GenderGetAllAsync(ReferenceDataFilter args = null, WebApiRequestOptions requestOptions = null) => base.GetAsync <RefDataNamespace.GenderCollection>("api/v1/demo/ref/genders", requestOptions: requestOptions, args: new WebApiArg[] { new WebApiArg <ReferenceDataFilter>("args", args, WebApiArgType.FromUriUseProperties) });
/// <summary> /// Raises a <see cref="Robot.PowerSource"/> change event. /// </summary> /// <param name="id">The <see cref="Robot"/> identifier.</param> /// <param name="powerSource">The Power Source (see <see cref="RefDataNamespace.PowerSource"/>).</param> /// <param name="requestOptions">The optional <see cref="WebApiRequestOptions"/>.</param> /// <returns>A <see cref="WebApiAgentResult"/>.</returns> public Task <WebApiAgentResult> RaisePowerSourceChangeAsync(Guid id, RefDataNamespace.PowerSource powerSource, WebApiRequestOptions requestOptions = null) { return(RobotServiceAgent.RaisePowerSourceChangeAsync(id, powerSource, requestOptions)); }
/// <summary> /// Deletes the <see cref="Person"/> object that matches the selection criteria. /// </summary> /// <param name="id">The <see cref="Person"/> identifier.</param> /// <param name="requestOptions">The optional <see cref="WebApiRequestOptions"/>.</param> /// <returns>A <see cref="WebApiAgentResult"/>.</returns> public Task <WebApiAgentResult> DeleteAsync(Guid id, WebApiRequestOptions requestOptions = null) { return(PersonServiceAgent.DeleteAsync(id, requestOptions)); }
/// <summary> /// Gets the <see cref="Robot"/> collection object that matches the selection criteria. /// </summary> /// <param name="args">The Args (see <see cref="RobotArgs"/>).</param> /// <param name="paging">The <see cref="PagingArgs"/>.</param> /// <param name="requestOptions">The optional <see cref="WebApiRequestOptions"/>.</param> /// <returns>A <see cref="WebApiAgentResult"/>.</returns> public Task <WebApiAgentResult <RobotCollectionResult> > GetByArgsAsync(RobotArgs args, PagingArgs paging = null, WebApiRequestOptions requestOptions = null) { return(RobotServiceAgent.GetByArgsAsync(args, paging, requestOptions)); }
/// <summary> /// Gets the <see cref="Product"/> collection object that matches the selection criteria. /// </summary> /// <param name="args">The Args (see <see cref="ProductArgs"/>).</param> /// <param name="paging">The <see cref="PagingArgs"/>.</param> /// <param name="requestOptions">The optional <see cref="WebApiRequestOptions"/>.</param> /// <returns>A <see cref="WebApiAgentResult"/>.</returns> public Task <WebApiAgentResult <ProductCollectionResult> > GetByArgsAsync(ProductArgs args, PagingArgs paging = null, WebApiRequestOptions requestOptions = null) { return(base.GetCollectionResultAsync <ProductCollectionResult, ProductCollection, Product>("api/v1/products", requestOptions: requestOptions, args: new WebApiArg[] { new WebApiArg <ProductArgs>("args", args, WebApiArgType.FromUriUseProperties), new WebApiPagingArgsArg("paging", paging) })); }
/// <summary> /// Gets the <see cref="Robot"/> object that matches the selection criteria. /// </summary> /// <param name="id">The <see cref="Robot"/> identifier.</param> /// <param name="requestOptions">The optional <see cref="WebApiRequestOptions"/>.</param> /// <returns>A <see cref="WebApiAgentResult"/>.</returns> public Task <WebApiAgentResult <Robot> > GetAsync(Guid id, WebApiRequestOptions requestOptions = null) { return(RobotServiceAgent.GetAsync(id, requestOptions)); }
/// <summary> /// Gets the <see cref="Person"/> collection object that matches the selection criteria. /// </summary> /// <param name="paging">The <see cref="PagingArgs"/>.</param> /// <param name="requestOptions">The optional <see cref="WebApiRequestOptions"/>.</param> /// <returns>A <see cref="WebApiAgentResult"/>.</returns> public Task <WebApiAgentResult <PersonCollectionResult> > GetAllAsync(PagingArgs paging = null, WebApiRequestOptions requestOptions = null) { return(PersonServiceAgent.GetAllAsync(paging, requestOptions)); }
/// <summary> /// Patches the <see cref="Robot"/> object. /// </summary> /// <param name="patchOption">The <see cref="WebApiPatchOption"/>.</param> /// <param name="value">The JSON patch value.</param> /// <param name="id">The <see cref="Robot"/> identifier.</param> /// <param name="requestOptions">The optional <see cref="WebApiRequestOptions"/>.</param> /// <returns>A <see cref="WebApiAgentResult"/>.</returns> public Task <WebApiAgentResult <Robot> > PatchAsync(WebApiPatchOption patchOption, JToken value, Guid id, WebApiRequestOptions requestOptions = null) { return(RobotServiceAgent.PatchAsync(patchOption, value, id, requestOptions)); }
/// <summary> /// Gets the <see cref="Person"/> collection object that matches the selection criteria. /// </summary> /// <param name="requestOptions">The optional <see cref="WebApiRequestOptions"/>.</param> /// <returns>A <see cref="WebApiAgentResult"/>.</returns> public Task <WebApiAgentResult <PersonCollectionResult> > GetAll2Async(WebApiRequestOptions requestOptions = null) { return(PersonServiceAgent.GetAll2Async(requestOptions)); }