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 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(); }
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 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 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 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); }
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); }