Ejemplo n.º 1
0
        protected virtual async Task AssertBulkDataAsync <TObject, TId>(IBulkExpandableClient <TObject, TId> client, string file, string idName = "id", string idsName = "ids")
            where TObject : IApiV2Object, IIdentifiable <TId>
        {
            (string data, var expected) = this.GetTestData(file);
            var ids = this.GetIds <TId>(expected.RootElement.EnumerateArray().Select(i => i.GetProperty(idName)));

            this.BaseClient.Connection.HttpClient.RequestAsync(Arg.Any <IWebApiRequest>(), CancellationToken.None).Returns(callInfo =>
            {
                var idStrings = ids.Select(i =>
                {
                    string idString = i !.ToString() !;
                    if (i is Guid)
                    {
                        idString = idString.ToUpperInvariant();
                    }
                    return(idString);
                });

                this.AssertRequest(callInfo, client, $"?{Uri.EscapeDataString(idsName)}={Uri.EscapeDataString(string.Join(",", idStrings))}");
                this.AssertAuthenticatedRequest(callInfo, client);
                this.AssertLocalizedRequest(callInfo, client);
                this.AssertSchemaVersionRequest(callInfo, client);
                return(new WebApiResponse(data, HttpStatusCode.OK, null));
            });

            var actual = await client.ManyAsync(ids);

            this.AssertJsonObject(expected.RootElement, actual);
        }
Ejemplo n.º 2
0
        protected virtual async Task AssertBulkDataAsync <TObject, TId>(IBulkExpandableClient <TObject, TId> client, string file, string idName = "id", string idsName = "ids")
            where TObject : IApiV2Object, IIdentifiable <TId>
        {
            var(data, expected) = this.GetTestData(file);
            var ids = this.GetIds <TId>(expected.Select(i =>
            {
                return(i is JProperty prop ? prop.Value[idName] : i[idName]);
            }));

            ((IClientInternal)this.Client).Connection.HttpClient.RequestAsync(Arg.Any <IHttpRequest>(), CancellationToken.None).Returns(callInfo =>
            {
                var idStrings = ids.Select(i =>
                {
                    string idString = i !.ToString() !;
                    if (i is Guid)
                    {
                        idString = idString.ToUpperInvariant();
                    }
                    return(idString);
                });

                this.AssertRequest(callInfo, client, $"?{idsName}={string.Join(",", idStrings)}");
                this.AssertAuthenticatedRequest(callInfo, client);
                this.AssertLocalizedRequest(callInfo, client);
                this.AssertSchemaVersionRequest(callInfo, client);
                return(new HttpResponse(data, HttpStatusCode.OK, null, null));
            });

            var actual = await client.ManyAsync(ids);

            this.AssertJsonObject(expected, actual);
        }