This commit is contained in:
SANTHOSH B 2024-01-18 22:15:02 -08:00
Родитель 2f2d3e5ba9
Коммит c801c3adb3
7 изменённых файлов: 78 добавлений и 84 удалений

Просмотреть файл

@ -6,6 +6,7 @@
#nullable disable
using System;
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
using Azure;
@ -127,7 +128,7 @@ namespace Microsoft.Marketplace.Metering
/// <param name="requestId"> A unique string value for tracking the request from the client, preferably a GUID. If this value isn&apos;t provided, one will be generated and provided in the response headers. </param>
/// <param name="correlationId"> A unique string value for operation on the client. This parameter correlates all events from client operation with events on the server side. If this value isn&apos;t provided, one will be generated and provided in the response headers. </param>
/// <param name="cancellationToken"> The cancellation token to use. </param>
public virtual async Task<Response<GetUsageEventOkResponse>> GetUsageEventAsync(DateTimeOffset usageStartDate, DateTimeOffset? usageEndDate = null, string offerId = null, string planId = null, string dimension = null, Guid? azureSubscriptionId = null, ReconStatusEnum? reconStatus = null, Guid? requestId = null, Guid? correlationId = null, CancellationToken cancellationToken = default)
public virtual async Task<Response<IReadOnlyList<GetUsageEvent>>> GetUsageEventAsync(DateTimeOffset usageStartDate, DateTimeOffset? usageEndDate = null, string offerId = null, string planId = null, string dimension = null, Guid? azureSubscriptionId = null, ReconStatusEnum? reconStatus = null, Guid? requestId = null, Guid? correlationId = null, CancellationToken cancellationToken = default)
{
using var scope = _clientDiagnostics.CreateScope("MeteringOperations.GetUsageEvent");
scope.Start();
@ -153,7 +154,7 @@ namespace Microsoft.Marketplace.Metering
/// <param name="requestId"> A unique string value for tracking the request from the client, preferably a GUID. If this value isn&apos;t provided, one will be generated and provided in the response headers. </param>
/// <param name="correlationId"> A unique string value for operation on the client. This parameter correlates all events from client operation with events on the server side. If this value isn&apos;t provided, one will be generated and provided in the response headers. </param>
/// <param name="cancellationToken"> The cancellation token to use. </param>
public virtual Response<GetUsageEventOkResponse> GetUsageEvent(DateTimeOffset usageStartDate, DateTimeOffset? usageEndDate = null, string offerId = null, string planId = null, string dimension = null, Guid? azureSubscriptionId = null, ReconStatusEnum? reconStatus = null, Guid? requestId = null, Guid? correlationId = null, CancellationToken cancellationToken = default)
public virtual Response<IReadOnlyList<GetUsageEvent>> GetUsageEvent(DateTimeOffset usageStartDate, DateTimeOffset? usageEndDate = null, string offerId = null, string planId = null, string dimension = null, Guid? azureSubscriptionId = null, ReconStatusEnum? reconStatus = null, Guid? requestId = null, Guid? correlationId = null, CancellationToken cancellationToken = default)
{
using var scope = _clientDiagnostics.CreateScope("MeteringOperations.GetUsageEvent");
scope.Start();

Просмотреть файл

@ -6,6 +6,7 @@
#nullable disable
using System;
using System.Collections.Generic;
using System.Text.Json;
using System.Threading;
using System.Threading.Tasks;
@ -215,7 +216,7 @@ namespace Microsoft.Marketplace.Metering
{
var message = _pipeline.CreateMessage();
var request = message.Request;
request.Method = RequestMethod.Post;
request.Method = RequestMethod.Get;
var uri = new RawRequestUriBuilder();
uri.Reset(endpoint);
uri.AppendPath("/usageEvents", false);
@ -269,7 +270,7 @@ namespace Microsoft.Marketplace.Metering
/// <param name="requestId"> A unique string value for tracking the request from the client, preferably a GUID. If this value isn&apos;t provided, one will be generated and provided in the response headers. </param>
/// <param name="correlationId"> A unique string value for operation on the client. This parameter correlates all events from client operation with events on the server side. If this value isn&apos;t provided, one will be generated and provided in the response headers. </param>
/// <param name="cancellationToken"> The cancellation token to use. </param>
public async Task<Response<GetUsageEventOkResponse>> GetUsageEventAsync(DateTimeOffset usageStartDate, DateTimeOffset? usageEndDate = null, string offerId = null, string planId = null, string dimension = null, Guid? azureSubscriptionId = null, ReconStatusEnum? reconStatus = null, Guid? requestId = null, Guid? correlationId = null, CancellationToken cancellationToken = default)
public async Task<Response<IReadOnlyList<GetUsageEvent>>> GetUsageEventAsync(DateTimeOffset usageStartDate, DateTimeOffset? usageEndDate = null, string offerId = null, string planId = null, string dimension = null, Guid? azureSubscriptionId = null, ReconStatusEnum? reconStatus = null, Guid? requestId = null, Guid? correlationId = null, CancellationToken cancellationToken = default)
{
using var message = CreateGetUsageEventRequest(usageStartDate, usageEndDate, offerId, planId, dimension, azureSubscriptionId, reconStatus, requestId, correlationId);
await _pipeline.SendAsync(message, cancellationToken).ConfigureAwait(false);
@ -277,9 +278,14 @@ namespace Microsoft.Marketplace.Metering
{
case 200:
{
GetUsageEventOkResponse value = default;
IReadOnlyList<GetUsageEvent> value = default;
using var document = await JsonDocument.ParseAsync(message.Response.ContentStream, default, cancellationToken).ConfigureAwait(false);
value = GetUsageEventOkResponse.DeserializeGetUsageEventOkResponse(document.RootElement);
List<GetUsageEvent> array = new List<GetUsageEvent>();
foreach (var item in document.RootElement.EnumerateArray())
{
array.Add(Models.GetUsageEvent.DeserializeGetUsageEvent(item));
}
value = array;
return Response.FromValue(value, message.Response);
}
default:
@ -298,7 +304,7 @@ namespace Microsoft.Marketplace.Metering
/// <param name="requestId"> A unique string value for tracking the request from the client, preferably a GUID. If this value isn&apos;t provided, one will be generated and provided in the response headers. </param>
/// <param name="correlationId"> A unique string value for operation on the client. This parameter correlates all events from client operation with events on the server side. If this value isn&apos;t provided, one will be generated and provided in the response headers. </param>
/// <param name="cancellationToken"> The cancellation token to use. </param>
public Response<GetUsageEventOkResponse> GetUsageEvent(DateTimeOffset usageStartDate, DateTimeOffset? usageEndDate = null, string offerId = null, string planId = null, string dimension = null, Guid? azureSubscriptionId = null, ReconStatusEnum? reconStatus = null, Guid? requestId = null, Guid? correlationId = null, CancellationToken cancellationToken = default)
public Response<IReadOnlyList<GetUsageEvent>> GetUsageEvent(DateTimeOffset usageStartDate, DateTimeOffset? usageEndDate = null, string offerId = null, string planId = null, string dimension = null, Guid? azureSubscriptionId = null, ReconStatusEnum? reconStatus = null, Guid? requestId = null, Guid? correlationId = null, CancellationToken cancellationToken = default)
{
using var message = CreateGetUsageEventRequest(usageStartDate, usageEndDate, offerId, planId, dimension, azureSubscriptionId, reconStatus, requestId, correlationId);
_pipeline.Send(message, cancellationToken);
@ -306,9 +312,14 @@ namespace Microsoft.Marketplace.Metering
{
case 200:
{
GetUsageEventOkResponse value = default;
IReadOnlyList<GetUsageEvent> value = default;
using var document = JsonDocument.Parse(message.Response.ContentStream);
value = GetUsageEventOkResponse.DeserializeGetUsageEventOkResponse(document.RootElement);
List<GetUsageEvent> array = new List<GetUsageEvent>();
foreach (var item in document.RootElement.EnumerateArray())
{
array.Add(Models.GetUsageEvent.DeserializeGetUsageEvent(item));
}
value = array;
return Response.FromValue(value, message.Response);
}
default:

Просмотреть файл

@ -1,40 +0,0 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
// <auto-generated/>
#nullable disable
using System.Collections.Generic;
using System.Text.Json;
using Azure.Core;
namespace Microsoft.Marketplace.Metering.Models
{
public partial class GetUsageEventOkResponse
{
internal static GetUsageEventOkResponse DeserializeGetUsageEventOkResponse(JsonElement element)
{
Optional<IReadOnlyList<GetUsageEvent>> request = default;
foreach (var property in element.EnumerateObject())
{
if (property.NameEquals("request"))
{
if (property.Value.ValueKind == JsonValueKind.Null)
{
property.ThrowNonNullablePropertyIsNull();
continue;
}
List<GetUsageEvent> array = new List<GetUsageEvent>();
foreach (var item in property.Value.EnumerateArray())
{
array.Add(GetUsageEvent.DeserializeGetUsageEvent(item));
}
request = array;
continue;
}
}
return new GetUsageEventOkResponse(Optional.ToList(request));
}
}
}

Просмотреть файл

@ -1,31 +0,0 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
// <auto-generated/>
#nullable disable
using System.Collections.Generic;
using Azure.Core;
namespace Microsoft.Marketplace.Metering.Models
{
/// <summary> The GetUsageEventOkResponse. </summary>
public partial class GetUsageEventOkResponse
{
/// <summary> Initializes a new instance of GetUsageEventOkResponse. </summary>
internal GetUsageEventOkResponse()
{
Request = new ChangeTrackingList<GetUsageEvent>();
}
/// <summary> Initializes a new instance of GetUsageEventOkResponse. </summary>
/// <param name="request"> . </param>
internal GetUsageEventOkResponse(IReadOnlyList<GetUsageEvent> request)
{
Request = request;
}
public IReadOnlyList<GetUsageEvent> Request { get; }
}
}

Просмотреть файл

@ -19,5 +19,9 @@ namespace Microsoft.Marketplace.Metering
Response<UsageEventOkResponse> PostUsageEvent(UsageEvent body, Guid? requestId = null, Guid? correlationId = null, CancellationToken cancellationToken = default);
Task<Response<UsageEventOkResponse>> PostUsageEventAsync(UsageEvent body, Guid? requestId = null, Guid? correlationId = null, CancellationToken cancellationToken = default);
Response<IReadOnlyList<GetUsageEvent>> GetUsageEvent(DateTimeOffset usageStartDate, DateTimeOffset? usageEndDate = null, string offerId = null, string planId = null, string dimension = null, Guid? azureSubscriptionId = null, ReconStatusEnum? reconStatus = null, Guid? requestId = null, Guid? correlationId = null, CancellationToken cancellationToken = default);
Task<Response<IReadOnlyList<GetUsageEvent>>> GetUsageEventAsync(DateTimeOffset usageStartDate, DateTimeOffset? usageEndDate = null, string offerId = null, string planId = null, string dimension = null, Guid? azureSubscriptionId = null, ReconStatusEnum? reconStatus = null, Guid? requestId = null, Guid? correlationId = null, CancellationToken cancellationToken = default);
}
}

Просмотреть файл

@ -6,7 +6,6 @@ using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Net.Http;
using System.Security;
using System.Security.Cryptography.X509Certificates;
using System.Threading.Tasks;
using Azure.Core;
@ -36,9 +35,9 @@ namespace Microsoft.Marketplace.Tests
#pragma warning disable SA1600 // Elements should be documented
public FulfillmentTests()
// Uncomment following to record
// : base(true, RecordedTestMode.Record)
: base(true, RecordedTestMode.Playback)
// Uncomment following to record
// : base(true, RecordedTestMode.Record)
: base(true, RecordedTestMode.Playback)
#pragma warning restore SA1600 // Elements should be documented
{
this.config = new ConfigurationBuilder()
@ -265,6 +264,16 @@ namespace Microsoft.Marketplace.Tests
ClassicAssert.IsTrue(result.Value.Result.All(r => r.UsageEventId == default));
}
[RecordedTest]
public async Task GetMeterUsage()
{
var sut = this.InstrumentClient(this.GetMarketplaceMeteringClient());
var yesterday = this.Mode == RecordedTestMode.Playback ? DateTime.Parse("2024-01-18T06:12:40.0746760Z").ToUniversalTime() : DateTime.UtcNow.AddDays(-1);
var result = await sut.Metering.GetUsageEventAsync(yesterday);
ClassicAssert.IsTrue(result.Value.Any());
}
private MarketplaceSaaSClient GetMarketplaceSaaSClient(bool useCert = false)
{
TokenCredential creds;

Просмотреть файл

@ -0,0 +1,40 @@
{
"Entries": [
{
"RequestUri": "https://marketplaceapi.microsoft.com/api/usageEvents?api-version=2018-08-31\u0026usageStartDate=2024-01-18T06%3A12%3A40.0746760Z",
"RequestMethod": "GET",
"RequestHeaders": {
"Accept": "application/json",
"Authorization": "Sanitized",
"traceparent": "00-742831eb8c8e7c22ccf8d19be01f4fb9-ec7ee813bfee1b56-00",
"User-Agent": "azsdk-net-Microsoft.Marketplace/1.0.0 (.NET 6.0.26; Microsoft Windows 10.0.22621)",
"x-ms-client-request-id": "18f5ce3e-6790-a548-91fc-0cb06c94a724",
"x-ms-return-client-request-id": "true"
},
"RequestBody": null,
"StatusCode": 200,
"ResponseHeaders": {
"Accept-Ranges": "bytes",
"Connection": "keep-alive",
"Content-Length": "1089",
"Content-Type": "application/json; charset=utf-8",
"Date": "Fri, 19 Jan 2024 06:12:41 GMT",
"mise-correlation-id": "b4714cb7-fd04-4dd0-a4e6-002d20236d47",
"Set-Cookie": [
"ARRAffinity=3b465a6a7ecf1050cba96e08bdd73408f917882519717f0e1456eda9f6b61aee;Path=/;HttpOnly;Secure;Domain=saasapi.azure.com",
"ARRAffinitySameSite=3b465a6a7ecf1050cba96e08bdd73408f917882519717f0e1456eda9f6b61aee;Path=/;HttpOnly;SameSite=None;Secure;Domain=saasapi.azure.com"
],
"x-azure-ref": "20240119T061241Z-sptutmqcg11cx8k9v1edm5p8x800000000m000000001t892",
"X-Cache": "CONFIG_NOCACHE",
"X-Content-Type-Options": "nosniff",
"x-ms-correlationid": "bda7fccc-a3b8-4d9b-bc70-7cc49b15f4b1",
"x-ms-requestid": "bda7fccc-a3b8-4d9b-bc70-7cc49b15f4b1",
"X-Powered-By": "ASP.NET"
},
"ResponseBody": "[{\u0022usageDate\u0022:\u00222024-01-19T00:00:00Z\u0022,\u0022usageResourceId\u0022:\u002218c51f6e-4d1b-48da-da96-23c9f3558cfc\u0022,\u0022dimension\u0022:\u0022q2\u0022,\u0022planId\u0022:\u0022milestone\u0022,\u0022planName\u0022:\u0022\u0022,\u0022offerId\u0022:\u0022sb-test-preview\u0022,\u0022offerName\u0022:\u0022\u0022,\u0022offerType\u0022:\u0022SaaS\u0022,\u0022azureSubscriptionId\u0022:\u00226791bfbb-5494-4eca-ae6f-e60a7c01077c\u0022,\u0022reconStatus\u0022:\u0022Submitted\u0022,\u0022submittedQuantity\u0022:6.0,\u0022processedQuantity\u0022:0.0,\u0022submittedCount\u0022:6},{\u0022usageDate\u0022:\u00222024-01-18T00:00:00Z\u0022,\u0022usageResourceId\u0022:\u002218c51f6e-4d1b-48da-da96-23c9f3558cfc\u0022,\u0022dimension\u0022:\u0022q2\u0022,\u0022planId\u0022:\u0022milestone\u0022,\u0022planName\u0022:\u0022\u0022,\u0022offerId\u0022:\u0022sb-test-preview\u0022,\u0022offerName\u0022:\u0022\u0022,\u0022offerType\u0022:\u0022SaaS\u0022,\u0022azureSubscriptionId\u0022:\u00226791bfbb-5494-4eca-ae6f-e60a7c01077c\u0022,\u0022reconStatus\u0022:\u0022Submitted\u0022,\u0022submittedQuantity\u0022:17.0,\u0022processedQuantity\u0022:0.0,\u0022submittedCount\u0022:17},{\u0022usageDate\u0022:\u00222024-01-18T00:00:00Z\u0022,\u0022usageResourceId\u0022:\u002248e4f71a-35de-48ec-d602-b748a986587f\u0022,\u0022dimension\u0022:\u0022q2\u0022,\u0022planId\u0022:\u0022milestone\u0022,\u0022planName\u0022:\u0022\u0022,\u0022offerId\u0022:\u0022sb-test-preview\u0022,\u0022offerName\u0022:\u0022\u0022,\u0022offerType\u0022:\u0022SaaS\u0022,\u0022azureSubscriptionId\u0022:\u00226791bfbb-5494-4eca-ae6f-e60a7c01077c\u0022,\u0022reconStatus\u0022:\u0022Submitted\u0022,\u0022submittedQuantity\u0022:1.0,\u0022processedQuantity\u0022:0.0,\u0022submittedCount\u0022:1}]"
}
],
"Variables": {
"RandomSeed": "25035204"
}
}