Skip to content

Commit 6e88f01

Browse files
author
Jamil Maqdis Anton
committed
add read from stream test
1 parent ca302cf commit 6e88f01

File tree

2 files changed

+51
-0
lines changed

2 files changed

+51
-0
lines changed

tests/ReadTests.fs

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
module SqlStreamStore.FSharp.Tests.ReadTests
2+
3+
open Expecto
4+
open SqlStreamStore.FSharp
5+
open SqlStreamStore.FSharp.Tests
6+
open SqlStreamStore.Streams
7+
8+
9+
[<Tests>]
10+
let tests =
11+
testList
12+
"Read Tests"
13+
[ testAsync "Should read forward from specific stream." {
14+
let inMemStore = new SqlStreamStore.InMemoryStreamStore()
15+
16+
let appendStreamDetails: AppendStreamDetails =
17+
{ streamName = "test"
18+
version = AppendVersion.NoStream }
19+
20+
let guidString1 = "11111111-1111-1111-1111-111111111111"
21+
22+
let guidString2 = "22222222-2222-2222-2222-222222222222"
23+
24+
let msg1 =
25+
{ id = StreamMessageId.Custom(System.Guid.Parse(guidString1))
26+
type_ = "testing"
27+
jsonData = "{}"
28+
jsonMetadata = "{}" }
29+
30+
let msg2 =
31+
{ id = StreamMessageId.Custom(System.Guid.Parse(guidString2))
32+
type_ = "testing"
33+
jsonData = "{}"
34+
jsonMetadata = "{}" }
35+
36+
let msgList = [ msg1; msg2 ]
37+
38+
do! Append.appendNewMessages inMemStore appendStreamDetails msgList
39+
|> Async.Ignore
40+
41+
let readStreamDetails: ReadStreamDetails = { streamName = "test"; version = 0u }
42+
43+
let! readResult = Read.readFromStreamAsync inMemStore ReadingDirection.Forward readStreamDetails 10
44+
45+
readResult.Messages
46+
|> Array.sortBy (fun msg -> msg.MessageId)
47+
|> fun sorted ->
48+
ExpectExtra.equal guidString1 (sorted.[0].MessageId.ToString())
49+
ExpectExtra.equal guidString2 (sorted.[1].MessageId.ToString())
50+
} ]

tests/SqlStreamStore.FSharp.Tests.fsproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
<ItemGroup>
1010
<Compile Include="ExpectoExtra.fs" />
1111
<Compile Include="AppendTests.fs" />
12+
<Compile Include="ReadTests.fs" />
1213
<Compile Include="Program.fs" />
1314
</ItemGroup>
1415

0 commit comments

Comments
 (0)