示例#1
0
        protected virtual async Task AssertGetDataAsync <TObject, TId>(IBulkExpandableClient <TObject, TId> client, string file, string idName = "id")
            where TObject : IApiV2Object, IIdentifiable <TId>
        {
            (string data, var expected) = this.GetTestData(file);
            var id = this.GetId <TId>(expected.RootElement.GetProperty(idName));

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

                this.AssertRequest(callInfo, client, $"/{idString}");
                this.AssertAuthenticatedRequest(callInfo, client);
                this.AssertLocalizedRequest(callInfo, client);
                this.AssertSchemaVersionRequest(callInfo, client);
                return(new WebApiResponse(data, HttpStatusCode.OK, null));
            });

            var actual = await client.GetAsync(id);

            this.AssertJsonObject(expected.RootElement, actual);
        }
示例#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>
        {
            (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);
        }
示例#3
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);
        }
示例#4
0
        protected virtual async Task AssertIdsDataAsync <TObject, TId>(IBulkExpandableClient <TObject, TId> client, string file)
            where TObject : IApiV2Object, IIdentifiable <TId>
        {
            (string data, var expected) = this.GetTestData(file);

            this.BaseClient.Connection.HttpClient.RequestAsync(Arg.Any <IWebApiRequest>(), CancellationToken.None).Returns(callInfo =>
            {
                this.AssertRequest(callInfo, client, string.Empty);
                this.AssertAuthenticatedRequest(callInfo, client);
                this.AssertLocalizedRequest(callInfo, client);
                this.AssertSchemaVersionRequest(callInfo, client);
                return(new WebApiResponse(data, HttpStatusCode.OK, null));
            });

            var actual = await client.IdsAsync();

            this.AssertJsonObject(expected.RootElement, actual);
        }