public async Task GetAuditReturnsOnlyAuditAtRequestedDay() { // Arrange await using var context = JosekiTestsDb.CreateUniqueContext(); var wrapper = new InfraScoreDbWrapper(context); var auditDate = DateTime.UtcNow.Date.AddDays(-1); var component = this.GenerateComponent(); await context.Audit.AddRangeAsync(new[] { new AuditEntity { Date = auditDate, ComponentId = component.ComponentId, InfrastructureComponent = component }, new AuditEntity { Date = auditDate.AddDays(-1), ComponentId = component.ComponentId, InfrastructureComponent = component }, }); await context.SaveChangesAsync(); // Act var audit = await wrapper.GetAudit(component.ComponentId, auditDate); // Assert audit.ComponentId.Should().Be(component.ComponentId); audit.Date.Should().Be(auditDate); }
public async Task GetAuditReturnsOnlyLatestAuditAtRequestedDate() { // 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 expectedComponent = 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 = expectedComponent.ComponentId, InfrastructureComponent = expectedComponent }); await context.Audit.AddRangeAsync(entities); await context.SaveChangesAsync(); // Act var audit = await wrapper.GetAudit(expectedComponent.ComponentId, auditDate); // Assert // returned audit should be the latest one at requested day audit.Date.Hour.Should().Be(16); }