public async Task PostSingleUsage()
        {
            var sut = this.InstrumentClient(this.GetMarketplaceMeteringClient());

            var usageEvent = new Metering.Models.UsageEvent {
                ResourceUri        = "/subscriptions/bf7adf12-c3a8-426c-9976-29f145eba70f/resourceGroups/ercmngd/providers/Microsoft.Solutions/applications/ercuserassigned",
                Quantity           = 15,
                Dimension          = "dim1",
                EffectiveStartTime = DateTime.Now.AddHours(-65),
                PlanId             = "userassigned",
            };

            var result = await sut.Metering.PostUsageEventAsync(usageEvent);
        }
Esempio n. 2
0
        public async Task PostSingleUsageWithResourceUri()
        {
            var sut = this.InstrumentClient(this.GetMarketplaceMeteringClient());

            var usageEvent = new Metering.Models.UsageEvent {
                ResourceUri = "/subscriptions/bf7adf12-c3a8-426c-9976-29f145eba70f/resourceGroups/ercmngd/providers/Microsoft.Solutions/applications/ercmdngd2231",
                Quantity    = 20.5,
                Dimension   = "dim1",
                // The time passed to Parse method should be the same as the recording
                EffectiveStartTime = this.Mode == RecordedTestMode.Playback ? DateTime.Parse("2021-03-15T22:01:05.0821551Z").ToUniversalTime() : DateTime.UtcNow.AddMinutes(-65),
                PlanId             = "userassigned",
            };

            var result = await sut.Metering.PostUsageEventAsync(usageEvent);

            Assert.AreEqual(result.Value.Status, UsageEventStatusEnum.Accepted);
            Assert.AreEqual(result.Value.Quantity, 20.5);
        }
Esempio n. 3
0
        //[Ignore("Run locally only, ignore in GitHub actions.")]
        public async Task PostSingleUsageWithResourceId()
        {
            var sut = this.InstrumentClient(this.GetMarketplaceMeteringClient());

            var usageEvent = new Metering.Models.UsageEvent
            {
                ResourceId = Guid.Parse("da8dc4ae-4cdf-ed6b-e12e-9d0219306842"),
                Quantity   = 20.5,
                Dimension  = "dim1",
                // The time passed to Parse method should be the same as the recording
                EffectiveStartTime = this.Mode == RecordedTestMode.Playback ? DateTime.Parse("2021-03-15T22:01:04.4810279Z").ToUniversalTime() : DateTime.UtcNow.AddMinutes(-65),
                PlanId             = "silver",
            };

            var result = await sut.Metering.PostUsageEventAsync(usageEvent);

            Assert.AreEqual(result.Value.Status, UsageEventStatusEnum.Accepted);
            Assert.AreEqual(result.Value.Quantity, 20.5);
        }
Esempio n. 4
0
        public async Task PostBatchUsage()
        {
            var sut = this.InstrumentClient(this.GetMarketplaceMeteringClient());

            var usageEvent1 = new Metering.Models.UsageEvent
            {
                ResourceId = Guid.Parse("da8dc4ae-4cdf-ed6b-e12e-9d0219306842"),
                Quantity   = 20.5,
                Dimension  = "dim1",
                // The time passed to Parse method should be the same as the recording
                EffectiveStartTime = this.Mode == RecordedTestMode.Playback ? DateTime.Parse("2021-03-15T18:06:00.4578027Z").ToUniversalTime() : DateTime.UtcNow.AddMinutes(-300),
                PlanId             = "silver",
            };

            var usageEvent2 = new Metering.Models.UsageEvent
            {
                ResourceUri = "/subscriptions/bf7adf12-c3a8-426c-9976-29f145eba70f/resourceGroups/ercmngd/providers/Microsoft.Solutions/applications/ercmdngd2231",
                Quantity    = 20.5,
                Dimension   = "dim1",
                // The time passed to Parse method should be the same as the recording
                EffectiveStartTime = this.Mode == RecordedTestMode.Playback ? DateTime.Parse("2021-03-15T18:06:00.4580942Z").ToUniversalTime() : DateTime.UtcNow.AddMinutes(-300),
                PlanId             = "userassigned",
            };

            var usageBatch = new BatchUsageEvent {
                Request = { usageEvent1, usageEvent2 }
            };

            var result = await sut.Metering.PostBatchUsageEventAsync(usageBatch);

            Assert.IsTrue(result.Value.Result.All(r => r.Status == UsageEventStatusEnum.Accepted));
            Assert.IsTrue(result.Value.Result.All(r => r.Quantity == 20.5));
            Assert.AreEqual(result.Value.Count, 2);
            Assert.IsTrue(result.Value.Result.All(r => r.Error == default));

            // Now get duplicates
            result = await sut.Metering.PostBatchUsageEventAsync(usageBatch);

            Assert.IsTrue(result.Value.Result.All(r => r.Status == UsageEventStatusEnum.Duplicate));
            Assert.IsTrue(result.Value.Result.All(r => r.Error != default));
            Assert.IsTrue(result.Value.Result.All(r => r.UsageEventId == default));
        }