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 ReturnAllTagListWidgets() { Int32 widgetCount = 20.GetRandom(6); string rootPath = $"C:\\{string.Empty.GetRandom()}"; var connectionString = new ConnectionStringBuilder("this") .AddFilePath(rootPath) .Build(); var widgets = new WidgetFileBuilder() .AddTagListWidgets(widgetCount) .Build(); Int32 expected = widgets.Count(w => w.Active); var fileSystem = new MockFileServiceBuilder() .AddWidgets(widgets) .Build(rootPath); var target = new ContentRepositoryBuilder() .AddFileService(fileSystem.Object) .UseGenericDirectory() .Build(connectionString); var actual = target.GetAllWidgets(); Assert.Equal(expected, actual.Count()); }
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 IgnoreFilesWithoutJsonExtension() { var files = new List <string> { "82B52DBC-9D33-4C9E-A933-AF515E4FF140", "28C65CCD-D504-44D3-A54B-9E3DBB163D43.json", "0F716B73-9A2F-46D9-A576-3CA03EB10327.ppt", "8EE89C80-760E-4980-B980-5A4B70A563E2.json", "39836B5E-C330-4670-9897-1CBF0851AB5B.txt", "68AA2FE5-58F9-421A-9C1B-02254B953BC5.json", "86F29FA4-29CD-4292-8000-CEAFEA7A2315.com" }; var fileSystem = new Mock <IFile>(); var directoryProvider = new Mock <IDirectory>(); directoryProvider.Setup(f => f.EnumerateFiles(It.IsAny <string>())) .Returns(files); foreach (var file in files) { fileSystem.Setup(f => f.ReadAllText(It.IsAny <string>())) .Returns("{}"); } var target = new ContentRepositoryBuilder() .AddDirectoryService(directoryProvider.Object) .AddFileService(fileSystem.Object) .Build(_defaultConnection); var pages = target.GetAllPages(); Assert.Equal(3, pages.Count()); }
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 ThrowWithProperSettingNameIfSettingsCannotBeLoaded() { String expected = typeof(SiteSettings).Name; String invalidJson = "<xml/>"; string rootPath = $"c:\\{String.Empty.GetRandom()}"; var connectionString = new ConnectionStringBuilder("this") .AddFilePath(rootPath) .Build(); var fileService = new MockFileServiceBuilder() .AddSiteSettingsFile(invalidJson) .Build(rootPath); var target = new ContentRepositoryBuilder() .UseGenericDirectory() .AddFileService(fileService.Object) .Build(connectionString); try { var actual = target.GetSiteSettings(); } catch (SettingNotFoundException ex) { Assert.Equal(expected, ex.SettingName); } }
public void RequestFilesFromThePostsFolder() { String rootPath = $"c:\\{string.Empty.GetRandom()}"; var connectionString = new ConnectionStringBuilder("this") .AddFilePath(rootPath) .Build(); var postFiles = new MockMediaFileCollectionBuilder() .AddRandomPosts(1) .Build(rootPath); var directoryProvider = new MockDirectoryServiceBuilder() .AddPostFiles(postFiles.Select(f => f.GetFilename())) .Build(rootPath); var fileSystem = new MockFileServiceBuilder() .AddPosts(postFiles) .Build(); var target = new ContentRepositoryBuilder() .AddFileService(fileSystem.Object) .AddDirectoryService(directoryProvider.Object) .Build(connectionString); var posts = target.GetAllPosts(); directoryProvider.VerifyAll(); }
private static void ExecutePropertyTest(String expected, Func <ContentItem, string> fieldValueDelegate, String json) { var files = new List <string> { "68AA2FE5-58F9-421A-9C1B-02254B953BC5.json" }; var fileSystem = new Mock <IFile>(); var directoryProvider = new Mock <IDirectory>(); directoryProvider.Setup(f => f.EnumerateFiles(It.IsAny <string>())) .Returns(files); foreach (var file in files) { fileSystem.Setup(f => f.ReadAllText(It.IsAny <string>())) .Returns(json); } var target = new ContentRepositoryBuilder() .AddDirectoryService(directoryProvider.Object) .AddFileService(fileSystem.Object) .Build(_defaultConnection); var pages = target.GetAllPages(); var actual = pages.ToArray()[0]; Assert.Equal(expected, fieldValueDelegate(actual)); }
private static ContentItem ExecutePropertyTest(String postFileContent) { String rootPath = $"c:\\{string.Empty.GetRandom()}"; var connectionString = new ConnectionStringBuilder("this") .AddFilePath(rootPath) .Build(); var postFiles = new MockMediaFileCollectionBuilder() .AddPost(postFileContent) .Build(rootPath); var directoryProvider = new MockDirectoryServiceBuilder() .AddPostFiles(postFiles.Select(f => f.GetFilename())) .Build(rootPath); var fileSystem = new MockFileServiceBuilder() .AddPosts(postFiles) .Build(); var target = new ContentRepositoryBuilder() .AddFileService(fileSystem.Object) .AddDirectoryService(directoryProvider.Object) .Build(connectionString); var pages = target.GetAllPosts(); return(pages.ToArray()[0]); }
public void RequestFilesFromThePagesFolder() { var files = new List <string> { "68AA2FE5-58F9-421A-9C1B-02254B953BC5.json" }; String rootPath = $"c:\\{string.Empty.GetRandom()}"; String expectedPath = System.IO.Path.Combine(rootPath, "pages"); var fileSystem = new Mock <IFile>(); var directoryProvider = new Mock <IDirectory>(); directoryProvider.Setup(f => f.EnumerateFiles(expectedPath)) .Returns(files).Verifiable(); foreach (var file in files) { fileSystem.Setup(f => f.ReadAllText(It.IsAny <string>())) .Returns("{}"); } var target = new ContentRepositoryBuilder() .AddDirectoryService(directoryProvider.Object) .AddFileService(fileSystem.Object) .Build($"Provider=this;{_connectionStringFilepathKey}={rootPath}"); var pages = target.GetAllPages(); fileSystem.VerifyAll(); }
public void ReturnAllPostsIfAllAreValid() { Int32 postCount = 3; String rootPath = $"c:\\{string.Empty.GetRandom()}"; var connectionString = new ConnectionStringBuilder("this") .AddFilePath(rootPath) .Build(); var postFiles = new MockMediaFileCollectionBuilder() .AddRandomPosts(postCount) .Build(rootPath); var directoryProvider = new MockDirectoryServiceBuilder() .AddPostFiles(postFiles.Select(f => f.GetFilename())) .Build(rootPath); var fileSystem = new MockFileServiceBuilder() .AddPosts(postFiles) .Build(); var target = new ContentRepositoryBuilder() .AddFileService(fileSystem.Object) .AddDirectoryService(directoryProvider.Object) .Build(connectionString); var posts = target.GetAllPosts(); Assert.Equal(postCount, posts.Count()); }
public void IgnoreFilesWithoutJsonExtension() { String rootPath = $"c:\\{string.Empty.GetRandom()}"; var connectionString = new ConnectionStringBuilder("this") .AddFilePath(rootPath) .Build(); var postFiles = new MockMediaFileCollectionBuilder() .AddRandomPosts(7) .Build(rootPath) .ToArray(); // Setup some bad file extensions postFiles[0].Extension = string.Empty; postFiles[2].Extension = ".ppt"; postFiles[4].Extension = ".txt"; postFiles[5].Extension = ".com"; var directoryProvider = new MockDirectoryServiceBuilder() .AddPostFiles(postFiles.Select(f => f.GetFilename())) .Build(rootPath); var fileSystem = new MockFileServiceBuilder() .AddPosts(postFiles) .Build(); var target = new ContentRepositoryBuilder() .AddFileService(fileSystem.Object) .AddDirectoryService(directoryProvider.Object) .Build(connectionString); var posts = target.GetAllPosts(); Assert.Equal(3, posts.Count()); }
public void ReturnTheProperNameForEachCategory() { string rootPath = $"C:\\{string.Empty.GetRandom()}"; var connectionString = new ConnectionStringBuilder("this") .AddFilePath(rootPath) .Build(); var categories = new CategoryCollectionBuilder() .AddRandomCategories(20.GetRandom(5)) .Build(); var fileSystem = new MockFileServiceBuilder() .AddCategories(categories) .Build(rootPath); var target = new ContentRepositoryBuilder() .AddFileService(fileSystem.Object) .UseGenericDirectory() .Build(connectionString); var actual = target.GetCategories(); foreach (var category in categories) { var actualCategory = actual.SingleOrDefault(c => c.Id == category.Id); Assert.Equal(category.Name, actualCategory.Name); } }
public void ReturnAllPagesIfAllAreValid() { var files = new List <string> { "28C65CCD-D504-44D3-A54B-9E3DBB163D43.json", "8EE89C80-760E-4980-B980-5A4B70A563E2.json", "68AA2FE5-58F9-421A-9C1B-02254B953BC5.json" }; var directoryProvider = new Mock <IDirectory>(); directoryProvider.Setup(f => f.EnumerateFiles(It.IsAny <string>())) .Returns(files); var fileSystem = new Mock <IFile>(); foreach (var file in files) { fileSystem.Setup(f => f.ReadAllText(It.IsAny <string>())) .Returns("{}"); } var target = new ContentRepositoryBuilder() .AddDirectoryService(directoryProvider.Object) .AddFileService(fileSystem.Object) .Build(_defaultConnection); var pages = target.GetAllPages(); Assert.Equal(files.Count(), pages.Count()); }
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 ReturnTheCorrectNumberOfTagsEvenIfAddedAtDifferentTimes() { var expected1 = 30.GetRandom(3); var expected2 = 30.GetRandom(3); var expected = expected1 + expected2; var tags1 = new List <string>(); for (Int32 i = 0; i < expected1; i++) { tags1.Add(string.Empty.GetRandom()); } var tags2 = new List <string>(); for (Int32 i = 0; i < expected2; i++) { tags2.Add(string.Empty.GetRandom()); } String rootPath = $"c:\\{string.Empty.GetRandom()}"; var connectionString = new ConnectionStringBuilder("this") .AddFilePath(rootPath) .Build(); var postJson = new MediaPostBuilder() .UseRandomFlickrPost() .ClearTags() .AddTags(tags1) .AddTags(tags2) .Build(); var postFiles = new MockMediaFileCollectionBuilder() .AddPost(postJson) .Build(rootPath); var directoryProvider = new MockDirectoryServiceBuilder() .AddPostFiles(postFiles.Select(f => f.GetFilename())) .Build(rootPath); var fileSystem = new MockFileServiceBuilder() .AddPosts(postFiles) .Build(); var target = new ContentRepositoryBuilder() .AddFileService(fileSystem.Object) .AddDirectoryService(directoryProvider.Object) .Build(connectionString); var pages = target.GetAllPosts(); var actual = pages.Single().Tags.Count(); Assert.Equal(expected, actual); }
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 ReturnTheCorrectTagsFromAMultiTagPost() { var expectedCount = 30.GetRandom(3); var tags = new List <string>(); for (Int32 i = 0; i < expectedCount; i++) { tags.Add(string.Empty.GetRandom()); } String expected = tags.AsHash(); String rootPath = $"c:\\{string.Empty.GetRandom()}"; var connectionString = new ConnectionStringBuilder("this") .AddFilePath(rootPath) .Build(); var postJson = new MediaPostBuilder() .UseRandomFlickrPost() .ClearTags() .AddTags(tags) .Build(); var postFiles = new MockMediaFileCollectionBuilder() .AddPost(postJson) .Build(rootPath); var directoryProvider = new MockDirectoryServiceBuilder() .AddPostFiles(postFiles.Select(f => f.GetFilename())) .Build(rootPath); var fileSystem = new MockFileServiceBuilder() .AddPosts(postFiles) .Build(); var target = new ContentRepositoryBuilder() .AddFileService(fileSystem.Object) .AddDirectoryService(directoryProvider.Object) .Build(connectionString); var pages = target.GetAllPosts(); var actual = pages.Single().Tags.AsHash(); Assert.Equal(expected, actual); }
private static void ExecutePropertyTest(SiteSettings siteSettings, String expected, Func <SiteSettings, String> fieldValueDelegate) { string rootPath = $"c:\\{String.Empty.GetRandom()}"; var connectionString = new ConnectionStringBuilder("this") .AddFilePath(rootPath) .Build(); var fileSystem = new MockFileServiceBuilder() .AddSiteSettings(siteSettings) .Build(rootPath); var target = new ContentRepositoryBuilder() .UseGenericDirectory() .AddFileService(fileSystem.Object) .Build(connectionString); var actual = target.GetSiteSettings(); Assert.Equal(expected, fieldValueDelegate(actual)); }
public void ThrowSettingNotFoundExceptionIfSettingsContentIsInvalid() { String invalidJson = "<xml/>"; string rootPath = $"c:\\{String.Empty.GetRandom()}"; var connectionString = new ConnectionStringBuilder("this") .AddFilePath(rootPath) .Build(); var fileService = new MockFileServiceBuilder() .AddSiteSettingsFile(invalidJson) .Build(rootPath); var target = new ContentRepositoryBuilder() .UseGenericDirectory() .AddFileService(fileService.Object) .Build(connectionString); Assert.Throws <SettingNotFoundException>(() => target.GetSiteSettings()); }
private static void ExecutePropertyTest(WidgetZone widget, String expected, Func <Widget, string> fieldValueDelegate) { string rootPath = $"C:\\{string.Empty.GetRandom()}"; var connectionString = new ConnectionStringBuilder("this") .AddFilePath(rootPath) .Build(); var fileSystem = new MockFileServiceBuilder() .AddWidget(widget) .Build(rootPath); var target = new ContentRepositoryBuilder() .AddFileService(fileSystem.Object) .UseGenericDirectory() .Build(connectionString); var actualWidgets = target.GetAllWidgets(); var actual = actualWidgets.Single(); Assert.Equal(expected, fieldValueDelegate(actual)); }
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); }
public void ReturnAllCategories() { Int32 categoryCount = 20.GetRandom(5); string rootPath = $"C:\\{string.Empty.GetRandom()}"; var connectionString = new ConnectionStringBuilder("this") .AddFilePath(rootPath) .Build(); var fileSystem = new MockFileServiceBuilder() .AddRandomCategories(categoryCount) .Build(rootPath); var target = new ContentRepositoryBuilder() .AddFileService(fileSystem.Object) .UseGenericDirectory() .Build(connectionString); var actual = target.GetCategories(); Assert.Equal(categoryCount, actual.Count()); }
public void ReturnTheTagFromASingleTagPost() { String expected = string.Empty.GetRandom(); String rootPath = $"c:\\{string.Empty.GetRandom()}"; var connectionString = new ConnectionStringBuilder("this") .AddFilePath(rootPath) .Build(); var postJson = new MediaPostBuilder() .UseRandomFlickrPost() .ClearTags() .AddTag(expected) .Build(); var postFiles = new MockMediaFileCollectionBuilder() .AddPost(postJson) .Build(rootPath); var directoryProvider = new MockDirectoryServiceBuilder() .AddPostFiles(postFiles.Select(f => f.GetFilename())) .Build(rootPath); var fileSystem = new MockFileServiceBuilder() .AddPosts(postFiles) .Build(); var target = new ContentRepositoryBuilder() .AddFileService(fileSystem.Object) .AddDirectoryService(directoryProvider.Object) .Build(connectionString); var pages = target.GetAllPosts(); var actual = pages.Single().Tags.Single(); Assert.Equal(expected, actual); }