Пример #1
0
        public void ReadsTheProperFileFromTheFileSystem()
        {
            String rootPath     = "c:\\";
            String expectedPath = System.IO.Path.Combine(rootPath, "SiteSettings.json");

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

            String json = new SiteSettingsFileBuilder()
                          .UseRandomValues()
                          .Build();

            var fileSystem = new MockFileServiceBuilder()
                             .AddSiteSettingsFile(json)
                             .Build(rootPath);

            var target = new ContentRepositoryBuilder()
                         .UseGenericDirectory()
                         .AddFileService(fileSystem.Object)
                         .Build(connectionString);

            var actual = target.GetSiteSettings();

            fileSystem.Verify(f => f.ReadAllText(expectedPath));
        }
        public void RequestTheContentsOfTheCorrectFiles()
        {
            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)
            {
                String filePath = System.IO.Path.Combine(relativePath, file.FileName);
                fileService.Verify(fs => fs.ReadAllBytes(filePath), Times.Once);
            }
        }