using System; using System.Collections.Generic; using Centron.BusinessLogic; using Centron.BusinessLogic.Telemetry; using Centron.Data.Entities.Telemetry; using Centron.Tests.EndToEnd.Infrastructure; using Xunit; using Xunit.Abstractions; namespace Centron.Tests.EndToEnd.Tests.Telemetry { public class TelemetryUpsertApiCall_IncrementExisting : EndToEndTest { public TelemetryUpsertApiCall_IncrementExisting(ITestOutputHelper testOutputHelper) : base(testOutputHelper) { } public override void Execute() { int methodI3D = 0; this.WithSession(session => { var resolve = session.GetBL().ResolveApiMethodNameI3Ds(new[] { "GetSomething" }); Assert.True(resolve.IsSuccess); methodI3D = resolve.Data["GetSomething"]; }); this.Sql($@" INSERT INTO dbo.ApiCallTelemetry (UserID, UserKind, LicenseKind, MethodNameI3D, HardwareIDI3D, BucketStartUtc, [Count]) VALUES (11, 0, {(short)TelemetryLicenseKind.Centron}, {methodI3D}, 0, '2026-05-02T12:15:00', 6)"); var bucket = new DateTime(2026, 5, 2, 12, 15, 0, DateTimeKind.Utc); var increments = new List { new() { UserID = 11, UserKind = TelemetryUserKind.User, LicenseKind = TelemetryLicenseKind.Centron, MethodNameI3D = methodI3D, BucketStartUtc = bucket, Increment = 5 } }; this.WithSession(session => { var result = session.GetBL().UpsertApiCallBatch(increments); Assert.True(result.IsSuccess); }); var rowCount = this.Sql( $"SELECT COUNT(*) FROM dbo.ApiCallTelemetry WHERE UserID = 11 AND UserKind = 0 AND LicenseKind = {(short)TelemetryLicenseKind.Centron} AND MethodNameI3D = {methodI3D} AND BucketStartUtc = '2026-05-02T12:15:00'"); var count = this.Sql( $"SELECT [Count] FROM dbo.ApiCallTelemetry WHERE UserID = 11 AND UserKind = 0 AND LicenseKind = {(short)TelemetryLicenseKind.Centron} AND MethodNameI3D = {methodI3D} AND BucketStartUtc = '2026-05-02T12:15:00'"); Assert.Equal(1, rowCount); Assert.Equal(11, count); } } }