예제 #1
0
        public async Task GetAuditsReturnsOnlyLatestAuditAtRequestedDate()
        {
            // Arrange
            await using var context = JosekiTestsDb.CreateUniqueContext();
            var wrapper = new InfraScoreDbWrapper(context);

            // create three audits a day before at 00:00, 08:00, 16:00
            var component = this.GenerateComponent();
            var auditDate = DateTime.UtcNow.Date.AddDays(-1);
            var entities  = Enumerable
                            .Range(0, 3)
                            .Select(i => new AuditEntity {
                Date = auditDate.AddHours(i * 8), ComponentId = component.ComponentId, InfrastructureComponent = component
            });
            await context.Audit.AddRangeAsync(entities);

            await context.SaveChangesAsync();

            // Act
            var audits = await wrapper.GetAudits(auditDate);

            // Assert
            // returned audit should be the latest one at requested day
            audits.Should().ContainSingle(i => i.Date.Hour == 16);
        }
예제 #2
0
        public async Task GetAuditsReturnsOnlyUniqueComponentAudits()
        {
            // Arrange
            await using var context = JosekiTestsDb.CreateUniqueContext();
            var wrapper = new InfraScoreDbWrapper(context);

            var auditDate  = DateTime.UtcNow.Date.AddDays(-1);
            var component1 = this.GenerateComponent();
            var component2 = this.GenerateComponent();
            var component3 = this.GenerateComponent();
            await context.Audit.AddRangeAsync(new[]
            {
                new AuditEntity {
                    Id = 1, Date = auditDate, ComponentId = component1.ComponentId, InfrastructureComponent = component1
                },                                                                                                                        // this one should be ignored
                new AuditEntity {
                    Id = 2, Date = auditDate.AddHours(6), ComponentId = component1.ComponentId, InfrastructureComponent = component1
                },
                new AuditEntity {
                    Id = 3, Date = auditDate.AddHours(12), ComponentId = component2.ComponentId, InfrastructureComponent = component2
                },
                new AuditEntity {
                    Id = 4, Date = auditDate.AddHours(23), ComponentId = component3.ComponentId, InfrastructureComponent = component3
                },
            });

            await context.SaveChangesAsync();

            // Act
            var audits = await wrapper.GetAudits(auditDate);

            // Assert
            audits.Should().HaveCount(3);
            audits.All(i => i.Id > 1).Should().BeTrue();
        }
예제 #3
0
        public async Task GetAuditsReturnsOnlyAuditsAtRequestedDay()
        {
            // Arrange
            await using var context = JosekiTestsDb.CreateUniqueContext();
            var wrapper = new InfraScoreDbWrapper(context);

            var auditDate  = DateTime.UtcNow.Date.AddDays(-1);
            var component1 = this.GenerateComponent();
            var component2 = this.GenerateComponent();
            var component3 = this.GenerateComponent();
            await context.Audit.AddRangeAsync(new[]
            {
                new AuditEntity {
                    Date = auditDate, ComponentId = component1.ComponentId, InfrastructureComponent = component1
                },
                new AuditEntity {
                    Date = auditDate.AddDays(-1), ComponentId = component2.ComponentId, InfrastructureComponent = component2
                },
                new AuditEntity {
                    Date = auditDate.AddDays(1), ComponentId = component3.ComponentId, InfrastructureComponent = component3
                },
            });

            await context.SaveChangesAsync();

            // Act
            var audits = await wrapper.GetAudits(auditDate);

            // Assert
            audits.Should().ContainSingle(i => i.Date == auditDate);
        }