コード例 #1
0
        public async Task GetAuditedComponentsWithHistoryReturnsOnlyOneMonthData()
        {
            // Arrange
            await using var context = JosekiTestsDb.CreateUniqueContext();

            var parser = new ConfigurationParser("config.sample.yaml");
            var db     = new MssqlJosekiDatabase(context, parser);

            var componentId = Guid.NewGuid().ToString();
            var today       = DateTime.UtcNow;

            // create more than 31 entries, which the oldest ones would be filtered-out
            var entities = Enumerable.Range(0, 35)
                           .Select(i => today.AddDays(-i)).Select(i => new AuditEntity
            {
                Date                    = i,
                ComponentId             = componentId,
                InfrastructureComponent = new InfrastructureComponentEntity(),
            });

            context.AddRange(entities);
            await context.SaveChangesAsync();

            // Act & Assert
            var audits = await db.GetAuditedComponentsWithHistory(today);

            audits.Should().HaveCount(31);
            audits.All(i => i.Date >= today.AddDays(-30)).Should().BeTrue("All audits should be not earlier than 30 days ago");
        }
コード例 #2
0
        public async Task GetAuditedComponentsWithHistoryReturnsEmptyArrayIfNoAudits()
        {
            // Arrange
            await using var context = JosekiTestsDb.CreateUniqueContext();

            var parser = new ConfigurationParser("config.sample.yaml");
            var db     = new MssqlJosekiDatabase(context, parser);

            // Act & Assert
            var audits = await db.GetAuditedComponentsWithHistory(DateTime.UtcNow);

            audits.Should().BeEmpty();
        }
コード例 #3
0
        public async Task GetAuditedComponentsWithHistoryReturnsOnlyOneAuditPerDay()
        {
            // Arrange
            await using var context = JosekiTestsDb.CreateUniqueContext();

            var parser = new ConfigurationParser("config.sample.yaml");
            var db     = new MssqlJosekiDatabase(context, parser);

            // Create two audits at each day during the last month: at 3am and 10am
            var componentId = Guid.NewGuid().ToString();
            var today3am    = DateTime.UtcNow.Date.AddHours(3);
            var today10am   = today3am.AddHours(7);
            var entries3am  = Enumerable.Range(0, 31)
                              .Select(i => new AuditEntity
            {
                Date                    = today3am.AddDays(-i),
                ComponentId             = componentId,
                InfrastructureComponent = new InfrastructureComponentEntity(),
            });
            var entries10am = Enumerable.Range(0, 31)
                              .Select(i => new AuditEntity
            {
                Date                    = today10am.AddDays(-i),
                ComponentId             = componentId,
                InfrastructureComponent = new InfrastructureComponentEntity(),
            });

            context.AddRange(entries3am);
            context.AddRange(entries10am);
            context.Add(new InfrastructureComponentEntity {
                ComponentId = componentId
            });
            await context.SaveChangesAsync();

            // Act & Assert
            // DB object should choose only one latest audit at each day (e.g. discard all 3am items, but leave 10am ones)
            var audits = await db.GetAuditedComponentsWithHistory(today10am.AddHours(2));

            audits.Should().HaveCount(31);
            audits.All(i => i.Date.Hour == 10).Should().BeTrue("All audits should be at 10 am");
        }