Ejemplo n.º 1
0
        public async Task Should_sum_up_when_getting_monthly_calls()
        {
            var dateFrom = new DateTime(date.Year, date.Month, 1);
            var dateTo   = dateFrom.AddMonths(1).AddDays(-1);

            var originalData = new List <StoredUsage>
            {
                new StoredUsage("category1", date.AddDays(1), Counters(a: 10, b: 15)),
                new StoredUsage("category1", date.AddDays(3), Counters(a: 13, b: 18)),
                new StoredUsage("category2", date.AddDays(5), Counters(a: 15)),
                new StoredUsage("category2", date.AddDays(7), Counters(b: 22))
            };

            A.CallTo(() => usageStore.QueryAsync(key, dateFrom, dateTo))
            .Returns(originalData);

            var result1 = await sut.GetForMonthAsync(key, date, null);

            var result2 = await sut.GetForMonthAsync(key, date, "category2");

            Assert.Equal(38, result1["A"]);
            Assert.Equal(55, result1["B"]);

            Assert.Equal(22, result2["B"]);
        }
Ejemplo n.º 2
0
        public async Task <long> GetTotalSizeAsync(Guid appId)
        {
            var key = GetKey(appId);

            var entries = await usageStore.QueryAsync(key, SummaryDate, SummaryDate);

            return((long)entries.Select(x => x.Counters.Get(CounterTotalSize)).FirstOrDefault());
        }
Ejemplo n.º 3
0
        public async Task Should_sum_up_when_getting_monthly_calls()
        {
            var date = new DateTime(2016, 1, 15);

            IReadOnlyList <StoredUsage> originalData = new List <StoredUsage>
            {
                new StoredUsage("category1", date.AddDays(1), Counters(10, 15)),
                new StoredUsage("category1", date.AddDays(3), Counters(13, 18)),
                new StoredUsage("category1", date.AddDays(5), Counters(15, 20)),
                new StoredUsage("category1", date.AddDays(7), Counters(17, 22))
            };

            A.CallTo(() => usageStore.QueryAsync($"{key}_API", new DateTime(2016, 1, 1), new DateTime(2016, 1, 15)))
            .Returns(originalData);

            var result = await sut.GetMonthlyCallsAsync(key, date);

            Assert.Equal(55, result);
        }