public void It_should_recache_cache_miss()
        {
            // Arrange
            string filePath = MD_SLASH_TEST_DOT_MD;
            var    ioProxy  = new Mock <IIOProxy>();

            ioProxy.Setup(x => x.FileExists(filePath)).Returns(true);
            ioProxy.Setup(x => x.GetLastWriteTimeUtc(filePath)).Returns(new DateTime(2017, 1, 1));
            ioProxy.Setup(x => x.ReadAllText(filePath)).Returns("# Test");
            ioProxy.Setup(x => x.DirectoryExists(SLASH_MD)).Returns(true);

            var cacheService = new Mock <IFileCacheService>();

            cacheService.Setup(x => x.HasKey("test")).Returns(true);
            cacheService.Setup(x => x.Get("test")).Returns(FileCacheResult.Empty());

            var service = new FileFetcherService(_options.Object, _logger.Object, ioProxy.Object, cacheService.Object);

            // Act
            FileFetchResult actual = service.GetFileContent("test");

            // Assert
            Assert.True(actual.IsFound);
            Assert.Equal("# Test", actual.FileData.Content);
        }
        public void It_should_return_not_found_directory_not_found()
        {
            // Arrange
            var cacheService = new Mock <IFileCacheService>();
            var ioProxy      = new Mock <IIOProxy>();

            ioProxy.Setup(x => x.DirectoryExists(SLASH_MD)).Returns(false);
            var service = new FileFetcherService(_options.Object, _logger.Object, ioProxy.Object, cacheService.Object);

            // Act
            FileFetchResult actual = service.GetFileContent("test");

            // Assert
            Assert.False(actual.IsFound);
        }
        public void It_should_return_not_found_directory_null()
        {
            // Arrange
            var badOptions = new Mock <IOptions <MdFileOptions> >();

            badOptions.SetupGet(x => x.Value).Returns(new MdFileOptions {
                MDSSourceDirectory = null
            });
            var cacheService = new Mock <IFileCacheService>();
            var ioProxy      = new Mock <IIOProxy>();
            var service      = new FileFetcherService(badOptions.Object, _logger.Object, ioProxy.Object, cacheService.Object);

            // Act
            FileFetchResult actual = service.GetFileContent("test");

            // Assert
            Assert.False(actual.IsFound);
        }
        public void It_should_return_not_found_file_doesnt_exist()
        {
            // Arrange
            string filePath = MD_SLASH_TEST_DOT_MD;
            var    ioProxy  = new Mock <IIOProxy>();

            ioProxy.Setup(x => x.FileExists(filePath)).Returns(false);
            ioProxy.Setup(x => x.GetLastWriteTimeUtc(filePath)).Throws(new FileNotFoundException());
            ioProxy.Setup(x => x.ReadAllText(filePath)).Throws(new FileNotFoundException());
            ioProxy.Setup(x => x.DirectoryExists(SLASH_MD)).Returns(true);

            var cacheService = new Mock <IFileCacheService>();
            var service      = new FileFetcherService(_options.Object, _logger.Object, ioProxy.Object, cacheService.Object);

            // Act
            FileFetchResult actual = service.GetFileContent("test");

            // Assert
            Assert.False(actual.IsFound);
        }