Version 2.1 #41

Merged
danieljsummers merged 123 commits from version-2.1 into main 2024-03-27 00:13:28 +00:00
4 changed files with 269 additions and 0 deletions
Showing only changes of commit cfb3c3a287 - Show all commits

View File

@ -0,0 +1,265 @@
module ConvertersTests
open Expecto
open MyWebLog
open MyWebLog.Converters.Json
open Newtonsoft.Json
/// Unit tests for the CategoryIdConverter type
let categoryIdConverterTests = testList "CategoryIdConverter" [
let opts = JsonSerializerSettings()
opts.Converters.Add(CategoryIdConverter())
test "succeeds when serializing" {
let after = JsonConvert.SerializeObject(CategoryId "test-cat-id", opts)
Expect.equal after "\"test-cat-id\"" "Category ID serialized incorrectly"
}
test "succeeds when deserializing" {
let after = JsonConvert.DeserializeObject<CategoryId>("\"test-cat-id\"", opts)
Expect.equal after (CategoryId "test-cat-id") "Category ID not serialized incorrectly"
}
]
/// Unit tests for the CommentIdConverter type
let commentIdConverterTests = testList "CommentIdConverter" [
let opts = JsonSerializerSettings()
opts.Converters.Add(CommentIdConverter())
test "succeeds when serializing" {
let after = JsonConvert.SerializeObject(CommentId "test-id", opts)
Expect.equal after "\"test-id\"" "Comment ID serialized incorrectly"
}
test "succeeds when deserializing" {
let after = JsonConvert.DeserializeObject<CommentId>("\"my-test\"", opts)
Expect.equal after (CommentId "my-test") "Comment ID deserialized incorrectly"
}
]
/// Unit tests for the CommentStatusConverter type
let commentStatusConverterTests = testList "CommentStatusConverter" [
let opts = JsonSerializerSettings()
opts.Converters.Add(CommentStatusConverter())
test "succeeds when serializing" {
let after = JsonConvert.SerializeObject(Approved, opts)
Expect.equal after "\"Approved\"" "Comment status serialized incorrectly"
}
test "succeeds when deserializing" {
let after = JsonConvert.DeserializeObject<CommentStatus>("\"Spam\"", opts)
Expect.equal after Spam "Comment status deserialized incorrectly"
}
]
/// Unit tests for the CustomFeedIdConverter type
let customFeedIdConverterTests = testList "CustomFeedIdConverter" [
let opts = JsonSerializerSettings()
opts.Converters.Add(CustomFeedIdConverter())
test "succeeds when serializing" {
let after = JsonConvert.SerializeObject(CustomFeedId "my-feed", opts)
Expect.equal after "\"my-feed\"" "Custom feed ID serialized incorrectly"
}
test "succeeds when deserializing" {
let after = JsonConvert.DeserializeObject<CustomFeedId>("\"feed-me\"", opts)
Expect.equal after (CustomFeedId "feed-me") "Custom feed ID deserialized incorrectly"
}
]
/// Unit tests for the CustomFeedSourceConverter type
let customFeedSourceConverterTests = testList "CustomFeedSourceConverter" [
let opts = JsonSerializerSettings()
opts.Converters.Add(CustomFeedSourceConverter())
test "succeeds when serializing" {
let after = JsonConvert.SerializeObject(Category (CategoryId "abc-123"), opts)
Expect.equal after "\"category:abc-123\"" "Custom feed source serialized incorrectly"
}
test "succeeds when deserializing" {
let after = JsonConvert.DeserializeObject<CustomFeedSource>("\"tag:testing\"", opts)
Expect.equal after (Tag "testing") "Custom feed source deserialized incorrectly"
}
]
/// Unit tests for the ExplicitRating type
let explicitRatingConverterTests = testList "ExplicitRatingConverter" [
let opts = JsonSerializerSettings()
opts.Converters.Add(ExplicitRatingConverter())
test "succeeds when serializing" {
let after = JsonConvert.SerializeObject(Yes, opts)
Expect.equal after "\"yes\"" "Explicit rating serialized incorrectly"
}
test "succeeds when deserializing" {
let after = JsonConvert.DeserializeObject<ExplicitRating>("\"clean\"", opts)
Expect.equal after Clean "Explicit rating deserialized incorrectly"
}
]
/// Unit tests for the MarkupText type
let markupTextConverterTests = testList "MarkupTextConverter" [
let opts = JsonSerializerSettings()
opts.Converters.Add(MarkupTextConverter())
test "succeeds when serializing" {
let after = JsonConvert.SerializeObject(Html "<h4>test</h4>", opts)
Expect.equal after "\"HTML: <h4>test</h4>\"" "Markup text serialized incorrectly"
}
test "succeeds when deserializing" {
let after = JsonConvert.DeserializeObject<MarkupText>("\"Markdown: #### test\"", opts)
Expect.equal after (Markdown "#### test") "Markup text deserialized incorrectly"
}
]
/// Unit tests for the PermalinkConverter type
let permalinkConverterTests = testList "PermalinkConverter" [
let opts = JsonSerializerSettings()
opts.Converters.Add(PermalinkConverter())
test "succeeds when serializing" {
let after = JsonConvert.SerializeObject(Permalink "2022/test", opts)
Expect.equal after "\"2022/test\"" "Permalink serialized incorrectly"
}
test "succeeds when deserializing" {
let after = JsonConvert.DeserializeObject<Permalink>("\"2023/unit.html\"", opts)
Expect.equal after (Permalink "2023/unit.html") "Permalink deserialized incorrectly"
}
]
/// Unit tests for the PageIdConverter type
let pageIdConverterTests = testList "PageIdConverter" [
let opts = JsonSerializerSettings()
opts.Converters.Add(PageIdConverter())
test "succeeds when serializing" {
let after = JsonConvert.SerializeObject(PageId "test-page", opts)
Expect.equal after "\"test-page\"" "Page ID serialized incorrectly"
}
test "succeeds when deserializing" {
let after = JsonConvert.DeserializeObject<PageId>("\"page-test\"", opts)
Expect.equal after (PageId "page-test") "Page ID deserialized incorrectly"
}
]
/// Unit tests for the PodcastMedium type
let podcastMediumConverterTests = testList "PodcastMediumConverter" [
let opts = JsonSerializerSettings()
opts.Converters.Add(PodcastMediumConverter())
test "succeeds when serializing" {
let after = JsonConvert.SerializeObject(Audiobook, opts)
Expect.equal after "\"audiobook\"" "Podcast medium serialized incorrectly"
}
test "succeeds when deserializing" {
let after = JsonConvert.DeserializeObject<PodcastMedium>("\"newsletter\"", opts)
Expect.equal after Newsletter "Podcast medium deserialized incorrectly"
}
]
/// Unit tests for the PostIdConverter type
let postIdConverterTests = testList "PostIdConverter" [
let opts = JsonSerializerSettings()
opts.Converters.Add(PostIdConverter())
test "succeeds when serializing" {
let after = JsonConvert.SerializeObject(PostId "test-post", opts)
Expect.equal after "\"test-post\"" "Post ID serialized incorrectly"
}
test "succeeds when deserializing" {
let after = JsonConvert.DeserializeObject<PostId>("\"post-test\"", opts)
Expect.equal after (PostId "post-test") "Post ID deserialized incorrectly"
}
]
/// Unit tests for the TagMapIdConverter type
let tagMapIdConverterTests = testList "TagMapIdConverter" [
let opts = JsonSerializerSettings()
opts.Converters.Add(TagMapIdConverter())
test "succeeds when serializing" {
let after = JsonConvert.SerializeObject(TagMapId "test-map", opts)
Expect.equal after "\"test-map\"" "Tag map ID serialized incorrectly"
}
test "succeeds when deserializing" {
let after = JsonConvert.DeserializeObject<TagMapId>("\"map-test\"", opts)
Expect.equal after (TagMapId "map-test") "Tag map ID deserialized incorrectly"
}
]
/// Unit tests for the ThemeAssetIdConverter type
let themeAssetIdConverterTests = testList "ThemeAssetIdConverter" [
let opts = JsonSerializerSettings()
opts.Converters.Add(ThemeAssetIdConverter())
test "succeeds when serializing" {
let after = JsonConvert.SerializeObject(ThemeAssetId (ThemeId "test", "unit.jpg"), opts)
Expect.equal after "\"test/unit.jpg\"" "Theme asset ID serialized incorrectly"
}
test "succeeds when deserializing" {
let after = JsonConvert.DeserializeObject<ThemeAssetId>("\"theme/test.png\"", opts)
Expect.equal after (ThemeAssetId (ThemeId "theme", "test.png")) "Theme asset ID deserialized incorrectly"
}
]
/// Unit tests for the ThemeIdConverter type
let themeIdConverterTests = testList "ThemeIdConverter" [
let opts = JsonSerializerSettings()
opts.Converters.Add(ThemeIdConverter())
test "succeeds when serializing" {
let after = JsonConvert.SerializeObject(ThemeId "test-theme", opts)
Expect.equal after "\"test-theme\"" "Theme ID serialized incorrectly"
}
test "succeeds when deserializing" {
let after = JsonConvert.DeserializeObject<ThemeId>("\"theme-test\"", opts)
Expect.equal after (ThemeId "theme-test") "Theme ID deserialized incorrectly"
}
]
/// Unit tests for the UploadIdConverter type
let uploadIdConverterTests = testList "UploadIdConverter" [
let opts = JsonSerializerSettings()
opts.Converters.Add(UploadIdConverter())
test "succeeds when serializing" {
let after = JsonConvert.SerializeObject(UploadId "test-up", opts)
Expect.equal after "\"test-up\"" "Upload ID serialized incorrectly"
}
test "succeeds when deserializing" {
let after = JsonConvert.DeserializeObject<UploadId>("\"up-test\"", opts)
Expect.equal after (UploadId "up-test") "Upload ID deserialized incorrectly"
}
]
/// Unit tests for the WebLogIdConverter type
let webLogIdConverterTests = testList "WebLogIdConverter" [
let opts = JsonSerializerSettings()
opts.Converters.Add(WebLogIdConverter())
test "succeeds when serializing" {
let after = JsonConvert.SerializeObject(WebLogId "test-web", opts)
Expect.equal after "\"test-web\"" "Web log ID serialized incorrectly"
}
test "succeeds when deserializing" {
let after = JsonConvert.DeserializeObject<WebLogId>("\"web-test\"", opts)
Expect.equal after (WebLogId "web-test") "Web log ID deserialized incorrectly"
}
]
/// Unit tests for the WebLogUserIdConverter type
let webLogUserIdConverterTests = testList "WebLogUserIdConverter" [
let opts = JsonSerializerSettings()
opts.Converters.Add(WebLogUserIdConverter())
test "succeeds when serializing" {
let after = JsonConvert.SerializeObject(WebLogUserId "test-user", opts)
Expect.equal after "\"test-user\"" "Web log user ID serialized incorrectly"
}
test "succeeds when deserializing" {
let after = JsonConvert.DeserializeObject<WebLogUserId>("\"user-test\"", opts)
Expect.equal after (WebLogUserId "user-test") "Web log user ID deserialized incorrectly"
}
]
/// All tests for the Data.Converters file
let all = testList "Converters" [
categoryIdConverterTests
commentIdConverterTests
commentStatusConverterTests
customFeedIdConverterTests
customFeedSourceConverterTests
explicitRatingConverterTests
markupTextConverterTests
permalinkConverterTests
pageIdConverterTests
podcastMediumConverterTests
postIdConverterTests
tagMapIdConverterTests
themeAssetIdConverterTests
themeIdConverterTests
uploadIdConverterTests
webLogIdConverterTests
webLogUserIdConverterTests
]

View File

@ -8,7 +8,9 @@
<Compile Include="SupportTypesTests.fs" />
<Compile Include="DataTypesTests.fs" />
<Compile Include="ViewModelsTests.fs" />
<Compile Include="ConvertersTests.fs" />
<Compile Include="Program.fs" />
<Content Include="root-weblog.json" />
</ItemGroup>
<ItemGroup>

View File

@ -2,6 +2,7 @@
let allTests = testList "MyWebLog" [
testList "Domain" [ SupportTypesTests.all; DataTypesTests.all; ViewModelsTests.all ]
testList "Data" [ ConvertersTests.all ]
]
[<EntryPoint>]

File diff suppressed because one or more lines are too long