public async Task HourShifter_ShiftsDateTakenExifValue()
        {
            Options options = new Options
            {
                Hours = 1,
                CurrentDirectoryOnly = false,
                Quiet = true
            };

            IFileLoader      fileLoader       = new FileLoader(options, Directory.GetCurrentDirectory());
            IHourShifter     hourShifter      = new HourShifter.HourShifter(options, fileLoader);
            ProgramBootstrap programBootstrap = new ProgramBootstrap(hourShifter);

            DateTime originalDateTime = await getJpgDateTaken(sampleJpgFile);

            Assert.Multiple(async() =>
            {
                int?exitCode = null;

                Assert.That(async() =>
                {
                    exitCode = await programBootstrap.Run();
                }, Throws.Nothing);

                DateTime newDateTime = await getJpgDateTaken(sampleJpgFile);

                Assert.That(originalDateTime != newDateTime);
                Assert.That(originalDateTime.AddHours(1) == newDateTime);

                Assert.That(exitCode.HasValue);
                Assert.That(exitCode.Value, Is.Zero);
            });
        }
Exemple #2
0
        public void HourShifter_Shift_DoesntShiftAnything(Options options)
        {
            Mock <IFileLoader> mockFileLoader = new Mock <IFileLoader>();

            mockFileLoader
            .Setup(m => m.FindAllPaths())
            .Returns(new List <string>())
            .Verifiable();

            mockFileLoader
            .Setup(m => m.LoadImage(It.IsAny <string>()))
            .ThrowsAsync(new Exception());

            HourShifter.HourShifter hourShifter = new HourShifter.HourShifter(options, mockFileLoader.Object);

            Assert.Multiple(() =>
            {
                int?shiftedFiles = null;

                Assert.That(async() =>
                {
                    shiftedFiles = await hourShifter.Shift();
                }, Throws.Nothing);

                Assert.That(shiftedFiles.HasValue);
                Assert.That(shiftedFiles.Value, Is.Zero);
                mockFileLoader.Verify(m => m.FindAllPaths(), Times.Once);
                mockFileLoader.Verify(m => m.LoadImage(It.IsAny <string>()), Times.Never);
            });
        }
Exemple #3
0
        static async Task <int> Main(string[] args)
        {
            int exitCode = Constants.SUCCESS_EXIT_CODE;

            ParserResult <Options> parserResult = Parser.Default.ParseArguments <Options>(args);

            parserResult
            .WithNotParsed((errors) =>
            {
                exitCode = Constants.FAILURE_EXIT_CODE;
            });

            await parserResult
            .WithParsedAsync(async (options) =>
            {
                if (!options.Quiet)
                {
                    if (Enum.TryParse(options.LogLevel, out LogLevel logLevel))
                    {
                        LoggingContext.Current.SetLogLevel(logLevel);
                    }
                }
                else
                {
                    LoggingContext.Current.SetLogLevel(LogLevel.Silent);
                }

                if (!options.Hours.HasValue || options.Hours == 0)
                {
                    LoggingContext.Current.Debug($"Using the default number of hours ({Constants.DEFAULT_HOURS})");
                    options.Hours = Constants.DEFAULT_HOURS;
                }

                // Composition root
                string currentDirectory = Directory.GetCurrentDirectory();
                LoggingContext.Current.Debug($"The current working directory is {currentDirectory}.");

                IFileLoader fileLoader     = new FileLoader(options, currentDirectory);
                IHourShifter hourShifter   = new HourShifter(options, fileLoader);
                ProgramBootstrap bootstrap = new ProgramBootstrap(hourShifter);

                exitCode = await bootstrap.Run();
                LoggingContext.Current.Debug($"Returning exit code {exitCode}.");

                if (!options.Quiet)
                {
                    Console.Write("Press any key to exit...");
                    Console.ReadKey();
                }
            });

            LoggingContext.Current.Debug($"Returning exit code: {exitCode}");
            return(exitCode);
        }
Exemple #4
0
        public async Task HourShifter_Shift_ShiftsJpgFile(Options options)
        {
            Mock <IFileLoader> mockFileLoader = await createMockFileLoader();

            HourShifter.HourShifter hourShifter = new HourShifter.HourShifter(options, mockFileLoader.Object);

            Assert.Multiple(() =>
            {
                int?shiftedFiles = null;

                Assert.That(async() =>
                {
                    shiftedFiles = await hourShifter.Shift();
                }, Throws.Nothing);

                Assert.That(shiftedFiles.HasValue);
                Assert.That(shiftedFiles.Value, Is.EqualTo(1));
                mockFileLoader.Verify(m => m.FindAllPaths(), Times.Once);
                mockFileLoader.Verify(m => m.LoadImage(It.IsAny <string>()), Times.Once);
            });
        }
Exemple #5
0
        public async Task HourShifter_Shift_IgnoresJpgWithInvalidExif(Options options)
        {
            Mock <IFileLoader> mockFileLoader =
                await createMockFileLoader(sampleJpgInvalidTimeList, sampleJpgInvalidTime);

            HourShifter.HourShifter hourShifter = new HourShifter.HourShifter(options, mockFileLoader.Object);

            Assert.Multiple(() =>
            {
                int?shiftedFiles = null;

                Assert.That(async() =>
                {
                    shiftedFiles = await hourShifter.Shift();
                }, Throws.Nothing);

                Assert.That(shiftedFiles.HasValue);
                Assert.That(shiftedFiles.Value, Is.Zero);
                mockFileLoader.Verify(m => m.FindAllPaths(), Times.Once);
                mockFileLoader.Verify(m => m.LoadImage(It.IsAny <string>()), Times.Once);
            });
        }