public void Politician_PrepareToBackup_ActualCheck()
        {
            var politician = new Politician(BackupRecords.ActualBackups, BackupRecords.CurrentDate);

            var idsToRemove = politician.GetIdsToRemove();
            var actualIds   = BackupRecords.ActualBackups
                              .Select(x => x.Id)
                              .Except(idsToRemove)
                              .ToArray();

            var expected = new[]
            {
                // 0 gen
                new Guid("53afa98d-c280-4ee3-8228-79dcd4c3dd18"),
                new Guid("53afa98d-c280-4ee3-8228-79dcd4c3dd20"),
                new Guid("53afa98d-c280-4ee3-8228-79dcd4c3dd21"),

                // 1st gen
                new Guid("53afa98d-c280-4ee3-8228-79dcd4c3dd26"),
                new Guid("53afa98d-c280-4ee3-8228-79dcd4c3dd28"),
                new Guid("53afa98d-c280-4ee3-8228-79dcd4c3dd29"),

                // 2nd gen
                new Guid("53afa98d-c280-4ee3-8228-79dcd4c3dd34"),
                new Guid("53afa98d-c280-4ee3-8228-79dcd4c3dd36"),
                new Guid("53afa98d-c280-4ee3-8228-79dcd4c3dd37"),

                // 3th gen
                new Guid("53afa98d-c280-4ee3-8228-79dcd4c3dd48")
            };

            actualIds.Should().BeEquivalentTo(expected);
        }
Exemplo n.º 2
0
        private void ApplyPolicies()
        {
            var backups = _client.Get();

            if (backups == null || !backups.Any())
            {
                _logger.LogWarning("Backups not found.");
                return;
            }

            var currentDate = _clock.Now;
            var politician  = new Politician(backups, currentDate);

            var idsToRemove = politician.GetIdsToRemove();

            if (!idsToRemove.Any())
            {
                _logger.LogDebug($"Backups in actual state");
                return;
            }

            foreach (var id in idsToRemove)
            {
                _client.Remove(id);
                _logger.LogDebug($"Backup {id} was removed");
            }
        }
        public void Politician_ObsoleteRemoved()
        {
            var politician = new Politician(BackupRecords.TwoWeekBackups, BackupRecords.CurrentDate);

            var idsToRemove = politician.GetIdsToRemove();
            var actualIds   = BackupRecords.TwoWeekBackups
                              .Select(x => x.Id)
                              .Except(idsToRemove)
                              .ToArray();

            idsToRemove.Should().HaveCount(22);
            actualIds.Should().HaveCount(10);
        }
        public void Politician_PrepareToBackup()
        {
            var politician = new Politician(BackupRecords.ActualBackups, BackupRecords.CurrentDate);

            var idsToRemove = politician.GetIdsToRemove();
            var actualIds   = BackupRecords.ActualBackups
                              .Select(x => x.Id)
                              .Except(idsToRemove)
                              .ToArray();

            idsToRemove.Should().HaveCount(3);
            actualIds.Should().HaveCount(10);
        }
        public void Politician_PrepareToBackup_RemovedCheck()
        {
            var politician = new Politician(BackupRecords.ActualBackups, BackupRecords.CurrentDate);

            var idsToRemove = politician.GetIdsToRemove();

            var expected = new[]
            {
                // 0 gen
                new Guid("53afa98d-c280-4ee3-8228-79dcd4c3dd19"),

                // 1st gen
                new Guid("53afa98d-c280-4ee3-8228-79dcd4c3dd27"),

                // 2nd gen
                new Guid("53afa98d-c280-4ee3-8228-79dcd4c3dd35"),
            };

            idsToRemove.Should().BeEquivalentTo(expected);
        }
        public void Politician_ObsoleteRemoved_RemovedCheck()
        {
            var politician = new Politician(BackupRecords.TwoWeekBackups, BackupRecords.CurrentDate);

            var idsToRemove = politician.GetIdsToRemove();

            var expected = new[]
            {
                new Guid("53afa98d-c280-4ee3-8228-79dcd4c3dd19"),
                new Guid("53afa98d-c280-4ee3-8228-79dcd4c3dd20"),
                new Guid("53afa98d-c280-4ee3-8228-79dcd4c3dd21"),
                new Guid("53afa98d-c280-4ee3-8228-79dcd4c3dd22"),
                new Guid("53afa98d-c280-4ee3-8228-79dcd4c3dd23"),

                new Guid("53afa98d-c280-4ee3-8228-79dcd4c3dd27"),
                new Guid("53afa98d-c280-4ee3-8228-79dcd4c3dd28"),
                new Guid("53afa98d-c280-4ee3-8228-79dcd4c3dd29"),
                new Guid("53afa98d-c280-4ee3-8228-79dcd4c3dd30"),
                new Guid("53afa98d-c280-4ee3-8228-79dcd4c3dd31"),

                new Guid("53afa98d-c280-4ee3-8228-79dcd4c3dd35"),
                new Guid("53afa98d-c280-4ee3-8228-79dcd4c3dd36"),
                new Guid("53afa98d-c280-4ee3-8228-79dcd4c3dd37"),
                new Guid("53afa98d-c280-4ee3-8228-79dcd4c3dd38"),
                new Guid("53afa98d-c280-4ee3-8228-79dcd4c3dd39"),
                new Guid("53afa98d-c280-4ee3-8228-79dcd4c3dd40"),
                new Guid("53afa98d-c280-4ee3-8228-79dcd4c3dd41"),
                new Guid("53afa98d-c280-4ee3-8228-79dcd4c3dd42"),
                new Guid("53afa98d-c280-4ee3-8228-79dcd4c3dd43"),
                new Guid("53afa98d-c280-4ee3-8228-79dcd4c3dd44"),
                new Guid("53afa98d-c280-4ee3-8228-79dcd4c3dd45"),

                new Guid("53afa98d-c280-4ee3-8228-79dcd4c3dd49")
            };

            idsToRemove.Should().BeEquivalentTo(expected);
        }