Ejemplo n.º 1
0
        public async Task GetAllComponentsIdsReturnsOnlyUniqueIds()
        {
            // Arrange
            await using var context = JosekiTestsDb.CreateUniqueContext();
            var wrapper = new InfraScoreDbWrapper(context);

            var today       = DateTime.UtcNow.Date;
            var componentId = Guid.NewGuid().ToString();
            var audits      = new[]
            {
                new AuditEntity {
                    Date = today, ComponentId = componentId
                },
                new AuditEntity {
                    Date = today.AddDays(-1), ComponentId = componentId
                },
            };
            await context.Audit.AddRangeAsync(audits);

            await context.SaveChangesAsync();

            // Act & Assert
            var allComponentsIds = await wrapper.GetAllComponentsIds();

            // returned array should have the only one componentId
            allComponentsIds.Should().ContainSingle(componentId);
        }
Ejemplo n.º 2
0
        public async Task GetAllComponentsIdsReturnsIdsForLast31Days()
        {
            // Arrange
            await using var context = JosekiTestsDb.CreateUniqueContext();
            var wrapper = new InfraScoreDbWrapper(context);

            // create two audits, that satisfy the criteria ...
            var today         = DateTime.UtcNow.Date;
            var correctAudits = new[]
            {
                new AuditEntity {
                    Date = today, ComponentId = Guid.NewGuid().ToString()
                },
                new AuditEntity {
                    Date = today.AddDays(-30), ComponentId = Guid.NewGuid().ToString()
                },
            };
            await context.Audit.AddRangeAsync(correctAudits);

            // ... and three audits, that do not
            var incorrectAudits = new[]
            {
                new AuditEntity {
                    Date = today.AddDays(-31), ComponentId = Guid.NewGuid().ToString()
                },
                new AuditEntity {
                    Date = today.AddDays(-60), ComponentId = Guid.NewGuid().ToString()
                },
                new AuditEntity {
                    Date = today.AddDays(-90), ComponentId = Guid.NewGuid().ToString()
                },
            };
            await context.Audit.AddRangeAsync(incorrectAudits);

            await context.SaveChangesAsync();

            // Act & Assert
            var allComponentsIds = await wrapper.GetAllComponentsIds();

            // returned array should have only items from correctAudits variable
            allComponentsIds.Should().HaveCount(correctAudits.Length);
            allComponentsIds.Should().Contain(correctAudits.Select(i => i.ComponentId));
        }