diff --git a/src/MyWebLog.Domain/ViewModels.fs b/src/MyWebLog.Domain/ViewModels.fs
index 20f631e..423f190 100644
--- a/src/MyWebLog.Domain/ViewModels.fs
+++ b/src/MyWebLog.Domain/ViewModels.fs
@@ -442,6 +442,7 @@ type EditCommonModel() =
/// The existing OpenGraph property set
member private this.PopulateOpenGraph(og: OpenGraphProperties) =
this.AssignOpenGraph <- true
+ this.OpenGraphType <- string og.Type
this.OpenGraphImageUrl <- og.Image.Url
this.OpenGraphImageType <- defaultArg og.Image.Type ""
this.OpenGraphImageWidth <- defaultArg (og.Image.Width |> Option.map string) ""
@@ -748,9 +749,10 @@ type EditPageModel() =
///
A post!
" CategoryIds = [ CategoryId "cat-a"; CategoryId "cat-b"; CategoryId "cat-n" ] Tags = [ "demo"; "post" ] + OpenGraph = + Some { Type = MusicAlbum + Image = + { Url = "https://unit.test/it.jpg" + Type = Some "test/jpg" + Width = Some 100 + Height = Some 200 + Alt = Some "it is a jpeg" } + Audio = Some { Url = "https://unit.test/that.mp3"; Type = Some "test/mp3" } + Description = Some "Just a post" + Determiner = Some "a" + Locale = Some "es-MX" + LocaleAlternate = Some [ "es-ES"; "en-EN" ] + Video = + Some { Url = "https://unit.test/that.mp4" + Type = Some "test/mp4" + Width = Some 50 + Height = Some 60 } + Other = Some [ { Name = "an-other"; Value = "a-value" } ] } Metadata = [ { Name = "A Meta"; Value = "A Value" } ] Revisions = [ { AsOf = Noda.epoch + Duration.FromDays 365; Text = Html "A post!
" } @@ -266,9 +304,28 @@ let editCommonModelTests = testList "EditCommonModel" [ Expect.equal model.Template "" "Template not filled properly" Expect.equal model.Source "HTML" "Source not filled properly" Expect.equal model.Text "" "Text not set properly" - Expect.equal model.MetaNames.Length 1 "MetaNames should have one entry" + Expect.isFalse model.AssignOpenGraph "OpenGraph properties should not have been assigned" + Expect.equal model.OpenGraphType "" "OpenGraph type not filled properly" + Expect.equal model.OpenGraphImageUrl "" "OpenGraph image URL not filled properly" + Expect.equal model.OpenGraphImageType "" "OpenGraph image type not filled properly" + Expect.equal model.OpenGraphImageWidth "" "OpenGraph image width not filled properly" + Expect.equal model.OpenGraphImageHeight "" "OpenGraph image height not filled properly" + Expect.equal model.OpenGraphImageAlt "" "OpenGraph image alt text not filled properly" + Expect.equal model.OpenGraphAudioUrl "" "OpenGraph audio URL not filled properly" + Expect.equal model.OpenGraphAudioType "" "OpenGraph audio type not filled properly" + Expect.equal model.OpenGraphDescription "" "OpenGraph description not filled properly" + Expect.equal model.OpenGraphDeterminer "" "OpenGraph determiner not filled properly" + Expect.equal model.OpenGraphLocale "" "OpenGraph locale not filled properly" + Expect.equal model.OpenGraphAlternateLocales "" "OpenGraph alt locales not filled properly" + Expect.equal model.OpenGraphVideoUrl "" "OpenGraph video URL not filled properly" + Expect.equal model.OpenGraphVideoType "" "OpenGraph video type not filled properly" + Expect.equal model.OpenGraphVideoWidth "" "OpenGraph video width not filled properly" + Expect.equal model.OpenGraphVideoHeight "" "OpenGraph video height not filled properly" + Expect.isEmpty model.OpenGraphExtraNames "OpenGraph extra names not filled properly" + Expect.isEmpty model.OpenGraphExtraValues "OpenGraph extra values not filled properly" + Expect.hasLength model.MetaNames 1 "MetaNames should have one entry" Expect.equal model.MetaNames[0] "" "Meta name not set properly" - Expect.equal model.MetaValues.Length 1 "MetaValues should have one entry" + Expect.hasLength model.MetaValues 1 "MetaValues should have one entry" Expect.equal model.MetaValues[0] "" "Meta value not set properly" } test "succeeds for filled page" { @@ -280,10 +337,31 @@ let editCommonModelTests = testList "EditCommonModel" [ Expect.equal model.Template "bork" "Template not filled properly" Expect.equal model.Source "Markdown" "Source not filled properly" Expect.equal model.Text "# Howdy!" "Text not filled properly" - Expect.equal model.MetaNames.Length 2 "MetaNames should have two entries" + Expect.isTrue model.AssignOpenGraph "OpenGraph properties should have been assigned" + Expect.equal model.OpenGraphType "book" "OpenGraph type not filled properly" + Expect.equal model.OpenGraphImageUrl "https://unit.test/it.png" "OpenGraph image URL not filled properly" + Expect.equal model.OpenGraphImageType "test/png" "OpenGraph image type not filled properly" + Expect.equal model.OpenGraphImageWidth "1" "OpenGraph image width not filled properly" + Expect.equal model.OpenGraphImageHeight "2" "OpenGraph image height not filled properly" + Expect.equal model.OpenGraphImageAlt "huh" "OpenGraph image alt text not filled properly" + Expect.equal model.OpenGraphAudioUrl "https://unit.test/it.mp3" "OpenGraph audio URL not filled properly" + Expect.equal model.OpenGraphAudioType "test/mpeg-3" "OpenGraph audio type not filled properly" + Expect.equal model.OpenGraphDescription "This is cool" "OpenGraph description not filled properly" + Expect.equal model.OpenGraphDeterminer "the" "OpenGraph determiner not filled properly" + Expect.equal model.OpenGraphLocale "en-US" "OpenGraph locale not filled properly" + Expect.equal model.OpenGraphAlternateLocales "es-MX, es-ES" "OpenGraph alt locales not filled properly" + Expect.equal model.OpenGraphVideoUrl "https://unit.test/it.mp4" "OpenGraph video URL not filled properly" + Expect.equal model.OpenGraphVideoType "test/mpeg-4" "OpenGraph video type not filled properly" + Expect.equal model.OpenGraphVideoWidth "5" "OpenGraph video width not filled properly" + Expect.equal model.OpenGraphVideoHeight "6" "OpenGraph video height not filled properly" + Expect.hasLength model.OpenGraphExtraNames 1 "OpenGraph extra names should have had 1 entry" + Expect.equal model.OpenGraphExtraNames[0] "the-other" "OpenGraph extra names not filled properly" + Expect.hasLength model.OpenGraphExtraValues 1 "OpenGraph extra values should have had 1 entry" + Expect.equal model.OpenGraphExtraValues[0] "the-value" "OpenGraph extra values not filled properly" + Expect.hasLength model.MetaNames 2 "MetaNames should have two entries" Expect.equal model.MetaNames[0] "Test" "Meta name 0 not set properly" Expect.equal model.MetaNames[1] "Two" "Meta name 1 not set properly" - Expect.equal model.MetaValues.Length 2 "MetaValues should have two entries" + Expect.hasLength model.MetaValues 2 "MetaValues should have two entries" Expect.equal model.MetaValues[0] "me" "Meta value 0 not set properly" Expect.equal model.MetaValues[1] "2" "Meta value 1 not set properly" } @@ -298,9 +376,28 @@ let editCommonModelTests = testList "EditCommonModel" [ Expect.equal model.Source "HTML" "Source not filled properly" Expect.equal model.Text "" "Text not filled properly" Expect.equal model.Template "" "Template not filled properly" - Expect.equal model.MetaNames.Length 1 "MetaNames not filled properly" + Expect.isFalse model.AssignOpenGraph "OpenGraph properties should not have been assigned" + Expect.equal model.OpenGraphType "" "OpenGraph type not filled properly" + Expect.equal model.OpenGraphImageUrl "" "OpenGraph image URL not filled properly" + Expect.equal model.OpenGraphImageType "" "OpenGraph image type not filled properly" + Expect.equal model.OpenGraphImageWidth "" "OpenGraph image width not filled properly" + Expect.equal model.OpenGraphImageHeight "" "OpenGraph image height not filled properly" + Expect.equal model.OpenGraphImageAlt "" "OpenGraph image alt text not filled properly" + Expect.equal model.OpenGraphAudioUrl "" "OpenGraph audio URL not filled properly" + Expect.equal model.OpenGraphAudioType "" "OpenGraph audio type not filled properly" + Expect.equal model.OpenGraphDescription "" "OpenGraph description not filled properly" + Expect.equal model.OpenGraphDeterminer "" "OpenGraph determiner not filled properly" + Expect.equal model.OpenGraphLocale "" "OpenGraph locale not filled properly" + Expect.equal model.OpenGraphAlternateLocales "" "OpenGraph alt locales not filled properly" + Expect.equal model.OpenGraphVideoUrl "" "OpenGraph video URL not filled properly" + Expect.equal model.OpenGraphVideoType "" "OpenGraph video type not filled properly" + Expect.equal model.OpenGraphVideoWidth "" "OpenGraph video width not filled properly" + Expect.equal model.OpenGraphVideoHeight "" "OpenGraph video height not filled properly" + Expect.isEmpty model.OpenGraphExtraNames "OpenGraph extra names not filled properly" + Expect.isEmpty model.OpenGraphExtraValues "OpenGraph extra values not filled properly" + Expect.hasLength model.MetaNames 1 "MetaNames not filled properly" Expect.equal model.MetaNames[0] "" "Meta name 0 not filled properly" - Expect.equal model.MetaValues.Length 1 "MetaValues not filled properly" + Expect.hasLength model.MetaValues 1 "MetaValues not filled properly" Expect.equal model.MetaValues[0] "" "Meta value 0 not filled properly" } test "succeeds for full post with external chapters" { @@ -312,12 +409,130 @@ let editCommonModelTests = testList "EditCommonModel" [ Expect.equal model.Source "HTML" "Source not filled properly" Expect.equal model.Text "A post!
" "Text not filled properly" Expect.equal model.Template "demo" "Template not filled properly" - Expect.equal model.MetaNames.Length 1 "MetaNames not filled properly" + Expect.isTrue model.AssignOpenGraph "OpenGraph properties should have been assigned" + Expect.equal model.OpenGraphType "music.album" "OpenGraph type not filled properly" + Expect.equal model.OpenGraphImageUrl "https://unit.test/it.jpg" "OpenGraph image URL not filled properly" + Expect.equal model.OpenGraphImageType "test/jpg" "OpenGraph image type not filled properly" + Expect.equal model.OpenGraphImageWidth "100" "OpenGraph image width not filled properly" + Expect.equal model.OpenGraphImageHeight "200" "OpenGraph image height not filled properly" + Expect.equal model.OpenGraphImageAlt "it is a jpeg" "OpenGraph image alt text not filled properly" + Expect.equal model.OpenGraphAudioUrl "https://unit.test/that.mp3" "OpenGraph audio URL not filled properly" + Expect.equal model.OpenGraphAudioType "test/mp3" "OpenGraph audio type not filled properly" + Expect.equal model.OpenGraphDescription "Just a post" "OpenGraph description not filled properly" + Expect.equal model.OpenGraphDeterminer "a" "OpenGraph determiner not filled properly" + Expect.equal model.OpenGraphLocale "es-MX" "OpenGraph locale not filled properly" + Expect.equal model.OpenGraphAlternateLocales "es-ES, en-EN" "OpenGraph alt locales not filled properly" + Expect.equal model.OpenGraphVideoUrl "https://unit.test/that.mp4" "OpenGraph video URL not filled properly" + Expect.equal model.OpenGraphVideoType "test/mp4" "OpenGraph video type not filled properly" + Expect.equal model.OpenGraphVideoWidth "50" "OpenGraph video width not filled properly" + Expect.equal model.OpenGraphVideoHeight "60" "OpenGraph video height not filled properly" + Expect.hasLength model.OpenGraphExtraNames 1 "OpenGraph extra names should have had 1 entry" + Expect.equal model.OpenGraphExtraNames[0] "an-other" "OpenGraph extra names not filled properly" + Expect.hasLength model.OpenGraphExtraValues 1 "OpenGraph extra values should have had 1 entry" + Expect.equal model.OpenGraphExtraValues[0] "a-value" "OpenGraph extra values not filled properly" + Expect.hasLength model.MetaNames 1 "MetaNames not filled properly" Expect.equal model.MetaNames[0] "A Meta" "Meta name 0 not filled properly" - Expect.equal model.MetaValues.Length 1 "MetaValues not filled properly" + Expect.hasLength model.MetaValues 1 "MetaValues not filled properly" Expect.equal model.MetaValues[0] "A Value" "Meta value 0 not filled properly" } ] + testList "ToOpenGraph" [ + test "succeeds when OpenGraph properties are not assigned" { + Expect.isNone + (EditCommonModel().ToOpenGraph WebLog.Empty) "No OpenGraph properties should have returned None" + } + test "succeeds when minimal OpenGraph properties are assigned" { + let model = EditCommonModel() + model.AssignOpenGraph <- true + model.OpenGraphType <- string Article + model.OpenGraphImageUrl <- "https://unit.test/img.tiff" + let tryOg = model.ToOpenGraph WebLog.Empty + Expect.isSome tryOg "There should have been a set of OpenGraph properties returned" + let og = tryOg.Value + Expect.equal og.Type Article "OpenGraph type not filled correctly" + Expect.equal og.Image.Url "https://unit.test/img.tiff" "OpenGraph image URL not filled properly" + Expect.isNone og.Image.Type "OpenGraph image type should have been None" + Expect.isNone og.Image.Width "OpenGraph image width should have been None" + Expect.isNone og.Image.Height "OpenGraph image height should have been None" + Expect.isNone og.Image.Alt "OpenGraph image alt text should have been None" + Expect.isNone og.Audio "OpenGraph audio should have been None" + Expect.isNone og.Description "OpenGraph description should have been None" + Expect.isNone og.Determiner "OpenGraph determiner should have been None" + Expect.isNone og.Locale "OpenGraph locale should have been None" + Expect.isNone og.LocaleAlternate "OpenGraph alt locales should have been None" + Expect.isNone og.Video "OpenGraph video should have been None" + Expect.isNone og.Other "OpenGraph other properties should have been None" + } + test "succeeds when all OpenGraph properties are assigned" { + let model = EditCommonModel() + model.AssignOpenGraph <- true + model.OpenGraphType <- string VideoMovie + model.OpenGraphImageUrl <- "https://unit.test/still.jpg" + model.OpenGraphImageType <- "still/jpg" + model.OpenGraphImageWidth <- "17" + model.OpenGraphImageHeight <- "24" + model.OpenGraphImageAlt <- "a still from the film" + model.OpenGraphAudioUrl <- "https://unit.test/movie.mp3" + model.OpenGraphAudioType <- "audio/mp-three" + model.OpenGraphDescription <- "Powerful. Stunning." + model.OpenGraphDeterminer <- "the" + model.OpenGraphLocale <- "en-EN" + model.OpenGraphAlternateLocales <- "es-ES, pt-PT" + model.OpenGraphVideoUrl <- "https://unit.test/movie.avi" + model.OpenGraphVideoType <- "video/outdated" + model.OpenGraphVideoWidth <- "1024" + model.OpenGraphVideoHeight <- "768" + model.OpenGraphExtraNames <- [| "og:duration"; "og:rating" |] + model.OpenGraphExtraValues <- [| "1:30:27"; "G" |] + let tryOg = model.ToOpenGraph WebLog.Empty + Expect.isSome tryOg "There should have been a set of OpenGraph properties returned" + let og = tryOg.Value + Expect.equal og.Type VideoMovie "OpenGraph type not filled correctly" + Expect.equal og.Image.Url "https://unit.test/still.jpg" "OpenGraph image URL not filled properly" + Expect.equal og.Image.Type (Some "still/jpg") "OpenGraph image type not filled properly" + Expect.equal og.Image.Width (Some 17) "OpenGraph image width not filled properly" + Expect.equal og.Image.Height (Some 24) "OpenGraph image height not filled properly" + Expect.equal og.Image.Alt (Some "a still from the film") "OpenGraph image alt text not filled properly" + Expect.isSome og.Audio "OpenGraph audio should have been filled" + Expect.equal og.Audio.Value.Url "https://unit.test/movie.mp3" "OpenGraph audio URL not filled properly" + Expect.equal og.Audio.Value.Type (Some "audio/mp-three") "OpenGraph audio type not filled properly" + Expect.equal og.Description (Some "Powerful. Stunning.") "OpenGraph description not filled properly" + Expect.equal og.Determiner (Some "the") "OpenGraph determiner not filled properly" + Expect.equal og.Locale (Some "en-EN") "OpenGraph locale not filled properly" + Expect.isSome og.LocaleAlternate "OpenGraph alt locales not filled properly" + Expect.hasLength og.LocaleAlternate.Value 2 "There should have been 2 alternate locales" + Expect.equal og.LocaleAlternate.Value [ "es-ES"; "pt-PT" ] "OpenGraph alt locales are incorrect" + Expect.isSome og.Video "OpenGraph video should have been filled" + Expect.equal og.Video.Value.Url "https://unit.test/movie.avi" "OpenGraph video URL not filled properly" + Expect.equal og.Video.Value.Type (Some "video/outdated") "OpenGraph video type not filled properly" + Expect.equal og.Video.Value.Width (Some 1024) "OpenGraph video width not filled properly" + Expect.equal og.Video.Value.Height (Some 768) "OpenGraph video height not filled properly" + Expect.isSome og.Other "OpenGraph other properties should have been filled" + Expect.hasLength og.Other.Value 2 "There should have been 2 extra properties" + Expect.equal + og.Other.Value + [ { Name = "og:duration"; Value = "1:30:27" }; { Name = "og:rating"; Value = "G" } ] + "OpenGraph extra properties not filled properly" + } + test "succeeds when relative URLs are assigned" { + let model = EditCommonModel() + model.AssignOpenGraph <- true + model.OpenGraphType <- string Article + model.OpenGraphImageUrl <- "image.jpg" + model.OpenGraphAudioUrl <- "tunes/sound.ogg" + model.OpenGraphVideoUrl <- "teaser.mp4" + let tryOg = model.ToOpenGraph { WebLog.Empty with UrlBase = "https://test.units/verify" } + Expect.isSome tryOg "There should have been a set of OpenGraph properties returned" + let og = tryOg.Value + Expect.equal og.Image.Url "https://test.units/verify/image.jpg" "OpenGraph image URL not filled properly" + Expect.isSome og.Audio "OpenGraph audio should have been filled" + Expect.equal + og.Audio.Value.Url "https://test.units/verify/tunes/sound.ogg" "OpenGraph audio URL not filled properly" + Expect.isSome og.Video "OpenGraph video should have been filled" + Expect.equal + og.Video.Value.Url "https://test.units/verify/teaser.mp4" "OpenGraph video URL not filled properly" + } + ] ] /// Unit tests for the EditCustomFeedModel type @@ -514,11 +729,13 @@ let editPageModelTests = testList "EditPageModel" [ let model = EditPageModel.FromPage { Page.Empty with Id = PageId "abc" } Expect.equal model.Id "abc" "Parent fields not filled properly" Expect.isFalse model.IsShownInPageList "IsShownInPageList should not have been set" + Expect.isFalse model.AssignOpenGraph "OpenGraph properties should not be assigned" } test "succeeds for filled page" { let model = EditPageModel.FromPage testFullPage Expect.equal model.Id "the-page" "Parent fields not filled properly" Expect.isTrue model.IsShownInPageList "IsShownInPageList should have been set" + Expect.isTrue model.AssignOpenGraph "OpenGraph properties should have been assigned" } ] testList "UpdatePage" [ @@ -526,7 +743,7 @@ let editPageModelTests = testList "EditPageModel" [ let model = EditPageModel.FromPage testFullPage model.Title <- "Updated Page" model.IsShownInPageList <- false - let page = model.UpdatePage testFullPage (Noda.epoch + Duration.FromHours 4) + let page = model.UpdatePage testFullPage WebLog.Empty (Noda.epoch + Duration.FromHours 4) Expect.equal page.Title "Updated Page" "Title not filled properly" Expect.equal page.Permalink (Permalink "blog/page.html") "Permalink not filled properly" Expect.isEmpty page.PriorPermalinks "PriorPermalinks should be empty" @@ -534,13 +751,12 @@ let editPageModelTests = testList "EditPageModel" [ Expect.isFalse page.IsInPageList "IsInPageList should have been unset" Expect.equal page.Template (Some "bork") "Template not filled properly" Expect.equal page.Text "