Beispiel #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));
        }
Beispiel #2
0
        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 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());
        }
Beispiel #4
0
        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 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());
        }
        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 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 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 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 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);
        }
Beispiel #15
0
        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));
        }
Beispiel #16
0
        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));
        }
Beispiel #18
0
        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 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 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);
        }