Skip to content

Commit 9535fe7

Browse files
committed
task 5 completed
1 parent f8cd68f commit 9535fe7

3 files changed

Lines changed: 70 additions & 1 deletion

File tree

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,9 @@ Add some tests for the commands and queries by creating an instance of Twitter,
6868
## Task 5: Integration tests
6969
Repeat the tests from task 4 but running through the Memstate engine. The test setup should:
7070
```
71-
Config.Current.UseInMemoryFileSystem().AppendRandomSuffixToStreamName();
71+
var cfg = Config.Current;cfg.UseInMemoryFileSystem();
72+
var settings = cfg.GetSettings<EngineSettings>();
73+
settings.WithRandomSuffixAppendedToStreamName();
7274
var engine = Engine.Start<Twitter>();
7375
```
7476

Twitter.Test/IntegrationTests.cs

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
using System;
2+
using System.Threading.Tasks;
3+
using Memstate;
4+
using Memstate.Configuration;
5+
using Twitter.Core;
6+
using Xunit;
7+
8+
namespace Twitter.Test
9+
{
10+
public class IntegrationTests
11+
{
12+
Engine<TwitterModel> _engine;
13+
14+
public IntegrationTests()
15+
{
16+
Task.Run( async () =>
17+
{
18+
var cfg = Config.Current;
19+
cfg.UseInMemoryFileSystem();
20+
21+
var settings = cfg.GetSettings<EngineSettings>();
22+
settings.WithRandomSuffixAppendedToStreamName();
23+
24+
_engine = await Engine.Start<TwitterModel>();
25+
26+
var cmd1 = new PostTweet("bart", "This is the worst day of my life", DateTime.Now);
27+
await _engine.Execute(cmd1);
28+
29+
var cmd2 = new PostTweet("homer", "@bart the worst day yet", DateTime.Now);
30+
await _engine.Execute(cmd2);
31+
32+
var cmd3 = new PostTweet("bart", ". @homer Eat my shorts", DateTime.Now);
33+
await _engine.Execute(cmd3);
34+
}).Wait();
35+
}
36+
37+
[Fact]
38+
public async Task Tweets_are_added_to_users_sequence_of_tweets()
39+
{
40+
var cmd = new UsersTweets("bart");
41+
var bartsTweets = await _engine.Execute(cmd);
42+
43+
Assert.Equal(2, bartsTweets.Length);
44+
Assert.Equal(3, bartsTweets[1].Id);
45+
}
46+
47+
[Fact]
48+
public async Task Tweets_can_be_retrieved_and_have_increasing_ids()
49+
{
50+
var cmd = new AllTweets(take: 5);
51+
var tweets = await _engine.Execute(cmd);
52+
53+
Assert.Equal(3, tweets.Length);
54+
Assert.Equal(1, tweets[0].Id);
55+
Assert.Equal("bart", tweets[0].UserName);
56+
Assert.Equal("This is the worst day of my life", tweets[0].Message);
57+
58+
Assert.Equal(2, tweets[1].Id);
59+
Assert.Equal("homer", tweets[1].UserName);
60+
61+
Assert.Equal(3, tweets[2].Id);
62+
Assert.Equal("bart", tweets[0].UserName);
63+
}
64+
65+
}
66+
}

Twitter.Test/TransactionTests.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
namespace Twitter.Test
66
{
7+
78
public class TransactionTests
89
{
910
readonly TwitterModel _twitter;

0 commit comments

Comments
 (0)