|
| 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 | +} |
0 commit comments