public void ReturnOneEntityForEachItemInTheFolder()
        {
            Int32  count        = 25.GetRandom(10);
            String rootPath     = $"c:\\{string.Empty.GetRandom()}";
            String relativePath = string.Empty.GetRandom();
            String folderPath   = Path.Combine(rootPath, relativePath);

            var connectionString = new ConnectionStringBuilder("this")
                                   .AddFilePath(rootPath)
                                   .Build();

            var files = new SourceFileCollectionBuilder()
                        .AddRandomFiles(count, relativePath)
                        .Build();

            var fileService = new MockFileServiceBuilder()
                              .AddSourceFiles(files)
                              .Build();

            var directoryService = new MockDirectoryServiceBuilder()
                                   .AddSourceFiles(files)
                                   .Build(rootPath);

            var target = new ContentRepositoryBuilder()
                         .AddFileService(fileService.Object)
                         .AddDirectoryService(directoryService.Object)
                         .Build(connectionString);

            var actual = target.GetFolderContents(relativePath);

            Assert.Equal(count, actual.Count());
        }
        public void ReturnTheCorrectContentsForEachItem()
        {
            Int32  count        = 25.GetRandom(10);
            String rootPath     = $"c:\\{string.Empty.GetRandom()}";
            String relativePath = string.Empty.GetRandom();
            String folderPath   = Path.Combine(rootPath, relativePath);

            var connectionString = new ConnectionStringBuilder("this")
                                   .AddFilePath(rootPath)
                                   .Build();

            var files = new SourceFileCollectionBuilder()
                        .AddRandomFiles(count, relativePath)
                        .Build();

            var fileService = new MockFileServiceBuilder()
                              .AddSourceFiles(files)
                              .Build();

            var directoryService = new MockDirectoryServiceBuilder()
                                   .AddSourceFiles(files)
                                   .Build(rootPath);

            var target = new ContentRepositoryBuilder()
                         .AddFileService(fileService.Object)
                         .AddDirectoryService(directoryService.Object)
                         .Build(connectionString);

            var actual = target.GetFolderContents(relativePath);

            foreach (var file in files)
            {
                Assert.Equal(file.Contents, actual.Single(a => a.FileName == file.FileName).Contents);
            }
        }
        public void RequestTheContentsOfTheCorrectFolderPath()
        {
            Int32  count        = 25.GetRandom(10);
            String rootPath     = $"c:\\{string.Empty.GetRandom()}";
            String relativePath = string.Empty.GetRandom();
            String folderPath   = Path.Combine(rootPath, relativePath);

            var connectionString = new ConnectionStringBuilder("this")
                                   .AddFilePath(rootPath)
                                   .Build();

            var files = new SourceFileCollectionBuilder()
                        .AddRandomFiles(count, relativePath)
                        .Build();

            var fileService = new MockFileServiceBuilder()
                              .AddSourceFiles(files)
                              .Build();

            var directoryService = new MockDirectoryServiceBuilder()
                                   .AddSourceFiles(files)
                                   .Build(rootPath);

            var target = new ContentRepositoryBuilder()
                         .AddFileService(fileService.Object)
                         .AddDirectoryService(directoryService.Object)
                         .Build(connectionString);

            var actual = target.GetFolderContents(relativePath);

            directoryService.Verify(fs => fs.EnumerateFiles(folderPath), Times.Once);
        }
        public void SkipItemsThatRequireAuthorizationToAccess()
        {
            Int32  count        = 35.GetRandom(20);
            String rootPath     = $"c:\\{string.Empty.GetRandom()}";
            String relativePath = string.Empty.GetRandom();
            String folderPath   = Path.Combine(rootPath, relativePath);

            String fakeFolder = String.Empty.GetRandom();
            String fakePath   = Path.Combine(rootPath, fakeFolder);

            var connectionString = new ConnectionStringBuilder("this")
                                   .AddFilePath(rootPath)
                                   .Build();

            var files = new SourceFileCollectionBuilder()
                        .AddRandomFiles(count, relativePath)
                        .Build();

            var directoryService = new MockDirectoryServiceBuilder()
                                   .AddSourceFiles(files)
                                   .Build(rootPath);

            var fileServiceBuilder = new MockFileServiceBuilder();

            Int32 expected = 0;

            foreach (var file in files)
            {
                bool secured = true.GetRandom();
                fileServiceBuilder.AddSecuredSourceFile(file, secured);
                if (!secured)
                {
                    expected++;
                }
            }

            var fileService = fileServiceBuilder.Build();

            var target = new ContentRepositoryBuilder()
                         .AddFileService(fileService.Object)
                         .AddDirectoryService(directoryService.Object)
                         .Build(connectionString);

            var actual = target.GetFolderContents(relativePath);

            Assert.Equal(expected, actual.Count());
        }
        public void ReturnAnEmptyCollectionIfTheFolderDoesNotExist()
        {
            Int32  count        = 25.GetRandom(10);
            String rootPath     = $"c:\\{string.Empty.GetRandom()}";
            String relativePath = string.Empty.GetRandom();
            String folderPath   = Path.Combine(rootPath, relativePath);

            String fakeFolder = String.Empty.GetRandom();
            String fakePath   = Path.Combine(rootPath, fakeFolder);

            var connectionString = new ConnectionStringBuilder("this")
                                   .AddFilePath(rootPath)
                                   .Build();

            var files = new SourceFileCollectionBuilder()
                        .AddRandomFiles(count, relativePath)
                        .Build();

            var fileService = new MockFileServiceBuilder()
                              .AddSourceFiles(files)
                              .Build();

            var directoryService = new MockDirectoryServiceBuilder()
                                   .AddSourceFiles(files)
                                   .Build(rootPath);

            directoryService.Setup(fs => fs.Exists(fakePath)).Returns(false);
            directoryService.Setup(fs => fs.EnumerateFiles(fakeFolder))
            .Throws(new System.IO.DirectoryNotFoundException());

            var target = new ContentRepositoryBuilder()
                         .AddFileService(fileService.Object)
                         .AddDirectoryService(directoryService.Object)
                         .Build(connectionString);

            var actual = target.GetFolderContents(fakePath);

            Assert.Empty(actual);
        }