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 ReturnTheProperValueInTheContentFieldForAnEmptyPost() { String expected = string.Empty; String json = new MediaPostBuilder() .UseRandomEmptyPost() .Build(); String fieldValueDelegate(ContentItem c) => c.Content; ExecutePropertyTest(expected, fieldValueDelegate, json); }
public void ReturnTheProperValueInTheSlugField(String title, String expected) { String json = new MediaPostBuilder() .UseRandomFlickrPost() .Title(title) .Build(); String fieldValueDelegate(ContentItem c) => c.Slug; ExecutePropertyTest(expected, fieldValueDelegate, json); }
public void ReturnTheProperValueForIsPublishedForAYouTubePost(Boolean expectedValue) { String fieldValueDelegate(ContentItem c) => c.IsPublished.ToString(); String json = new MediaPostBuilder() .UseRandomYouTubePost() .IsPublished(expectedValue) .Build(); String expected = expectedValue.ToString(); ExecutePropertyTest(expected, fieldValueDelegate, json); }
public void ReturnTheProperValueInTheDescriptionField() { String expected = string.Empty.GetRandom(); String json = new MediaPostBuilder() .UseRandomFlickrPost() .Description(expected) .Build(); String fieldValueDelegate(ContentItem c) => c.Description; ExecutePropertyTest(expected, fieldValueDelegate, json); }
public void ReturnAnEmptyStringInTheByLineFieldIfAuthorFieldIsEmpty() { String expected = string.Empty; String json = new MediaPostBuilder() .UseRandomFlickrPost() .Author(expected) .Build(); String fieldValueDelegate(ContentItem c) => c.ByLine; ExecutePropertyTest(expected, fieldValueDelegate, json); }
public void ReturnTheProperValueInThePubDateField() { String fieldValueDelegate(ContentItem c) => c.PublicationDate.ToString(); DateTime expectedValue = DateTime.UtcNow.AddHours(20.GetRandom(10)); String expected = expectedValue.ToString(); String json = new MediaPostBuilder() .UseRandomFlickrPost() .Posted(expectedValue) .Build(); ExecutePropertyTest(expected, fieldValueDelegate, json); }
public void ReturnTheProperValueInTheByLineFieldForAVideoPost() { String author = string.Empty.GetRandom(); String expected = $"Video by {author}"; String json = new MediaPostBuilder() .UseRandomYouTubePost() .Author(author) .Build(); String fieldValueDelegate(ContentItem c) => c.ByLine; ExecutePropertyTest(expected, fieldValueDelegate, json); }
public void ReturnAnEmptyContentPropertyIfTheMediaTypeNodeIsNull() { String fieldValueDelegate(ContentItem c) => c.Content; String expectedValue = String.Empty; String expected = expectedValue.ToString(); String json = new MediaPostBuilder() .UseRandomFlickrPost() .MediaType(null) .Build(); ExecutePropertyTest(expected, fieldValueDelegate, json); }
public void ThrowAnInvalidOperationExceptionIfTheMediaTypeIsInvalid() { String fieldValueDelegate(ContentItem c) => c.Content; String expectedValue = String.Empty; String expected = expectedValue.ToString(); String json = new MediaPostBuilder() .UseRandomFlickrPost() .MediaType(String.Empty.GetRandom()) .Build(); Assert.Throws <InvalidOperationException>(() => ExecutePropertyTest(expected, fieldValueDelegate, json)); }
public void ReturnTheProperVideoUrlInTheContentFieldForAYouTubePost() { var video = new YouTubeMediaItemBuilder() .UseRandom() .Build(); String json = new MediaPostBuilder() .AddYouTubeVideo(video.Title, video.DisplayWidth, video.DisplayHeight, video.CreateDate, video.VideoUrl) .Build(); String expected = video.VideoUrl; var actual = ExecutePropertyTest(json); Assert.Contains(expected, actual.Content); }
public void ReturnTheProperValueInTheContentFieldForAFlickrPost() { var post = new FlickrMediaItemBuilder() .UseRandom() .Build(); String json = new MediaPostBuilder() .AddFlickrImage(post.Title, post.DisplayWidth, post.DisplayHeight, post.CreateDate, post.FlickrListUrl, post.ImageUrl) .Build(); String expected = $"<a data-flickr-embed=\"true\" href=\"{post.FlickrListUrl}\" title=\"{post.Title}\"><img class=\"img-responsive\" src=\"{post.ImageUrl}\" alt=\"{post.Title}\"></a>"; String fieldValueDelegate(ContentItem c) => c.Content; ExecutePropertyTest(expected, fieldValueDelegate, json); }
public void ReturnTheProperHeightInTheContentFieldForAYouTubePostIfAValueIsSupplied() { var video = new YouTubeMediaItemBuilder() .UseRandom() .Build(); String json = new MediaPostBuilder() .AddYouTubeVideo(video.Title, video.DisplayWidth, video.DisplayHeight, video.CreateDate, video.VideoUrl) .Build(); String expected = $"height=\"{video.DisplayHeight}\""; var actual = ExecutePropertyTest(json); Assert.True(video.DisplayHeight > 0, "Test is not valid if DisplayHeight is Zero or less"); Assert.Contains(expected, actual.Content); }
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 static MediaPostBuilder UseRandomYouTubePost(this MediaPostBuilder builder) { var tags = new List <string>(); for (Int32 i = 0; i < _maxTags.GetRandom(); i++) { tags.Add(string.Empty.GetRandom()); } var youTubeVideo = new YouTubeMediaItemBuilder() .UseRandom() .Build(); return(builder .AddYouTubeVideo(youTubeVideo) .Author(string.Empty.GetRandom()) .Description(string.Empty.GetRandom()) .IsPublished(true.GetRandom()) .Posted(DateTime.Now.AddYears(30).GetRandom(DateTime.Now.AddYears(-10))) .AddTags(tags) .Title(string.Empty.GetRandom())); }
public static MediaPostBuilder UseRandomEmptyPost(this MediaPostBuilder builder) { var tags = new List <string>(); for (Int32 i = 0; i < _maxTags.GetRandom(); i++) { tags.Add(string.Empty.GetRandom()); } var emptyPost = new EmptyMediaItemBuilder() .UseRandom() .Build(); return(builder .AddEmptyPost(emptyPost.Title, emptyPost.DisplayWidth, emptyPost.DisplayHeight, emptyPost.CreateDate) .Author(string.Empty.GetRandom()) .Description(string.Empty.GetRandom()) .IsPublished(true.GetRandom()) .Posted(DateTime.Now.AddYears(30).GetRandom(DateTime.Now.AddYears(-10))) .AddTags(tags) .Title(string.Empty.GetRandom())); }
public void ReturnTheProperValueInTheLastModifiedDateField() { // LastModifiedDate should be set to the // create date of the Media Item String fieldValueDelegate(ContentItem c) => c.LastModificationDate.ToString(); DateTime expectedValue = DateTime.UtcNow.AddHours(20.GetRandom(10)); String expected = expectedValue.ToString(); var flickrItem = new FlickrMediaItemBuilder() .UseRandom() .CreateDate(expectedValue) .Build(); String json = new MediaPostBuilder() .UseRandomFlickrPost() .AddFlickrImage(flickrItem) .Build(); ExecutePropertyTest(expected, fieldValueDelegate, json); }
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); }