Version 2.1 #41

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

View File

@ -10,7 +10,6 @@ let rootId = WebLogId "uSitJEuD3UyzWC9jgOHc8g"
/// The ID of the Favorites category /// The ID of the Favorites category
let favoritesId = CategoryId "S5JflPsJ9EG7gA2LD4m92A" let favoritesId = CategoryId "S5JflPsJ9EG7gA2LD4m92A"
/// Tests for the Add method
let ``Add succeeds`` (data: IData) = task { let ``Add succeeds`` (data: IData) = task {
let category = let category =
{ Category.Empty with Id = CategoryId "added-cat"; WebLogId = WebLogId "test"; Name = "Added"; Slug = "added" } { Category.Empty with Id = CategoryId "added-cat"; WebLogId = WebLogId "test"; Name = "Added"; Slug = "added" }

View File

@ -0,0 +1,45 @@
module PageDataTests
open Expecto
open MyWebLog
open MyWebLog.Data
open NodaTime
let ``Add succeeds`` (data: IData) = task {
let page =
{ Id = PageId "added-page"
WebLogId = WebLogId "test"
AuthorId = WebLogUserId "the-author"
Title = "A New Page"
Permalink = Permalink "2024/the-page.htm"
PublishedOn = Noda.epoch + Duration.FromDays 3
UpdatedOn = Noda.epoch + Duration.FromDays 3 + Duration.FromMinutes 2L
IsInPageList = true
Template = Some "new-page-template"
Text = "<h1>A new page</h1>"
Metadata = [ { Name = "Meta Item"; Value = "Meta Value" } ]
PriorPermalinks = [ Permalink "2024/the-new-page.htm" ]
Revisions = [ { AsOf = Noda.epoch + Duration.FromDays 3; Text = Html "<h1>A new page</h1>" } ] }
do! data.Page.Add page
let! stored = data.Page.FindFullById (PageId "added-page") (WebLogId "test")
Expect.isSome stored "The page should have been added"
let pg = stored.Value
Expect.equal pg.Id page.Id "ID not saved properly"
Expect.equal pg.WebLogId page.WebLogId "Web log ID not saved properly"
Expect.equal pg.AuthorId page.AuthorId "Author ID not saved properly"
Expect.equal pg.Title page.Title "Title not saved properly"
Expect.equal pg.Permalink page.Permalink "Permalink not saved properly"
Expect.equal pg.PublishedOn page.PublishedOn "Published On not saved properly"
Expect.equal pg.UpdatedOn page.UpdatedOn "Updated On not saved properly"
Expect.equal pg.IsInPageList page.IsInPageList "Is in page list flag not saved properly"
Expect.equal pg.Template page.Template "Template not saved properly"
Expect.equal pg.Text page.Text "Text not saved properly"
Expect.hasLength pg.Metadata 1 "There should have been one meta item properly"
Expect.equal pg.Metadata[0].Name page.Metadata[0].Name "Metadata name not saved properly"
Expect.equal pg.Metadata[0].Value page.Metadata[0].Value "Metadata value not saved properly"
Expect.hasLength pg.PriorPermalinks 1 "There should have been one prior permalink"
Expect.equal pg.PriorPermalinks[0] page.PriorPermalinks[0] "Prior permalink not saved properly"
Expect.hasLength pg.Revisions 1 "There should have been one revision"
Expect.equal pg.Revisions[0].AsOf page.Revisions[0].AsOf "Revision as of not saved properly"
Expect.equal pg.Revisions[0].Text page.Revisions[0].Text "Revision text not saved properly"
}

View File

@ -38,7 +38,7 @@ let environmentSetUp = testTask "creating database" {
do! freshEnvironment () do! freshEnvironment ()
} }
/// Integration tests for the Category implementation in SQLite /// Integration tests for the Category implementation in PostgreSQL
let categoryTests = testList "Category" [ let categoryTests = testList "Category" [
testTask "Add succeeds" { testTask "Add succeeds" {
do! CategoryDataTests.``Add succeeds`` (mkData ()) do! CategoryDataTests.``Add succeeds`` (mkData ())
@ -100,6 +100,13 @@ let categoryTests = testList "Category" [
] ]
] ]
/// Integration tests for the Page implementation in PostgreSQL
let pageTests = testList "Page" [
testTask "Add succeeds" {
do! PageDataTests.``Add succeeds`` (mkData ())
}
]
/// Drop the throwaway PostgreSQL database /// Drop the throwaway PostgreSQL database
let environmentCleanUp = test "Clean Up" { let environmentCleanUp = test "Clean Up" {
if db.IsSome then db.Value.Dispose() if db.IsSome then db.Value.Dispose()
@ -110,5 +117,6 @@ let all =
testList "PostgresData" testList "PostgresData"
[ environmentSetUp [ environmentSetUp
categoryTests categoryTests
pageTests
environmentCleanUp ] environmentCleanUp ]
|> testSequenced |> testSequenced

View File

@ -141,6 +141,14 @@ let categoryTests = testList "Category" [
] ]
] ]
/// Integration tests for the Page implementation in SQLite
let pageTests = testList "Page" [
testTask "Add succeeds" {
let data = mkData ()
try do! PageDataTests.``Add succeeds`` data
finally dispose data
}
]
/// Delete the SQLite database /// Delete the SQLite database
let environmentCleanUp = test "Clean Up" { let environmentCleanUp = test "Clean Up" {
@ -153,5 +161,6 @@ let all =
testList "SQLiteData" testList "SQLiteData"
[ environmentSetUp [ environmentSetUp
categoryTests categoryTests
pageTests
environmentCleanUp ] environmentCleanUp ]
|> testSequenced |> testSequenced

View File

@ -11,6 +11,7 @@
<Compile Include="Data\ConvertersTests.fs" /> <Compile Include="Data\ConvertersTests.fs" />
<Compile Include="Data\UtilsTests.fs" /> <Compile Include="Data\UtilsTests.fs" />
<Compile Include="Data\CategoryDataTests.fs" /> <Compile Include="Data\CategoryDataTests.fs" />
<Compile Include="Data\PageDataTests.fs" />
<Compile Include="Data\SQLiteDataTests.fs" /> <Compile Include="Data\SQLiteDataTests.fs" />
<Compile Include="Data\PostgresDataTests.fs" /> <Compile Include="Data\PostgresDataTests.fs" />
<Compile Include="Program.fs" /> <Compile Include="Program.fs" />