protected AvalancheRepositoryTestBase(bool testMode)
        {
            _logger = Substitute.For <ILogger <AvalancheRepository> >();

            // If this test class gets much more complex, this base class
            // should probably be abandoned and the test-mode vs. non-test-mode
            // classes can just diverge entirely
            if (testMode)
            {
                var command = Substitute.For <IDbCommand>();
                // The methods that read will be tested with 0-count results
                command.ExecuteScalar().Returns(0L);

                _db = Substitute.For <IDbConnection>();
                _db.CreateCommand().Returns(command);
            }
            else
            {
                // In-memory sqlite db
                _db = new SqliteConnection("Data Source=:memory:");
                _db.Open();
            }

            _sut = new AvalancheRepository(_logger, _db, testMode);
        }
        public void OnStartup_GivenPopulatedDatabase_DoesNotReCreateTables()
        {
            // The schema will already be populated by the constructor, so
            // just creating a new test object will trigger this test condition.
            var duplicate = new AvalancheRepository(_logger, _db, false);

            // xunit doesn't have an Assert.DoesNotThrow(), so there's no actual
            // assertion in this test. The failure condition is an exception.
        }
Пример #3
0
        public static void Main(string[] args)
        {
            var parameters = ExecutionParameters.GetParametersFromArgs(args);

            if (parameters == null)
            {
                _log.Fatal("No config file could be found in the default location (my documents) and none was specified in the parameters.");
                Environment.Exit(0);
            }

            var errors = parameters.GetValidationErrors();

            if (errors.Any())
            {
                _log.Fatal("Configuration/parameter errors occurredt:");
                foreach (var e in errors)
                {
                    _log.Fatal(e);
                }
                Environment.Exit(0);
            }

            using (var insomniac = new Insomniac())
            {
                var lightroomRepo = new LightroomRepository(parameters.Avalanche.CatalongFilePath);
                var avalancheRepo = new AvalancheRepository(parameters.Avalanche.AvalancheFilePath);
                var gateway       = new GlacierGateway(parameters.Glacier);

                var catalogId        = lightroomRepo.GetUniqueId();
                var allPictures      = lightroomRepo.GetAllPictures();
                var filteredPictures = allPictures.Where(a => a.LibraryCount > 0 && !avalancheRepo.FileIsArchived(a.FileId)).ToList();

                _log.InfoFormat("Backing up {0} images", filteredPictures.Count);

                var index = 0;
                foreach (var f in filteredPictures)
                {
                    _log.InfoFormat("Archiving {0}/{1}: {2}", ++index, filteredPictures.Count, Path.Combine(f.AbsolutePath, f.FileName));

                    // Try three times
                    ArchivedPictureModel archive = null;
                    for (var i = 0; i < 3; ++i)
                    {
                        try
                        {
                            archive = gateway.SaveImage(f, parameters.Glacier.VaultName);
                        }
                        catch (Exception ex)
                        {
                            _log.ErrorFormat("Error!!! {0}", ex);
                            continue;
                        }
                        break;
                    }

                    if (archive == null)
                    {
                        continue;
                    }

                    avalancheRepo.MarkFileAsArchived(archive, parameters.Glacier.VaultName, parameters.Glacier.Region, parameters.Avalanche.CatalongFilePath, catalogId.ToString());
                }

                _log.Info("Done");
            }
        }