示例#1
0
        public async Task JoinGameAsync()
        {
            var host = await hostBuilder.StartAsync();

            var client = host.GetTestClient();

            //Given
            var gameId = Guid.NewGuid();

            context.Given(
                EventEnvelope.Create(
                    gameId.ToString(),
                    new GameCreated(GameId: gameId, PlayerId: "*****@*****.**", Rounds: 1, Title: "test game", Created: DateTime.UtcNow))
                .AddTestMetaData <GameState>(new AggregateId(gameId)));

            //When
            await context.WhenAsync(async() =>
            {
                var cmd = new JoinGame {
                    GameId = gameId, PlayerId = "*****@*****.**"
                };
                var response = await client.PostAsync($"/games/{gameId}/join", new FormUrlEncodedContent(
                                                          new[] {
                    KeyValuePair.Create(nameof(cmd.GameId), cmd.GameId.ToString()),
                    KeyValuePair.Create(nameof(cmd.PlayerId), cmd.PlayerId),
                }
                                                          ), CancellationToken.None);

                Assert.Equal(System.Net.HttpStatusCode.Found, response.StatusCode);
            });

            //Then
            context.Then((events, visual) =>
            {
                this.helper.WriteLine(visual);
                Assert.True(events.AsEnvelopes().Happened <GameStarted>());
                Assert.True(events.AsEnvelopes().Happened <RoundStarted>());
            });
        }
示例#2
0
 public static void Given <TState>(this ITestContext context, IAggregateId id, params IEvent[] events)
 => context.Given(events.Select(e => e.AddTestMetaData <TState>(id)).ToArray());
示例#3
0
 public static void Given <TState>(this ITestContext context, IAggregateId id, params EventRecord[] events)
 => context.Given(events.Select(e => EventEnvelope.Create(id.Id, e).AddTestMetaData <TState>(id)).ToArray());