[Fact] //problem with rabbitmq queue  //http://localhost:15672
        public async Task add_game_event_source_command_should_add_document_with_given_id_to_database()
        {
            var command = new AddGameEventSource(Guid.NewGuid(), 10, true, Guid.NewGuid());

            //we have 2 scenario here:

            //1.Subscribe to the message and wait for this message (Task.Delay(500)) and then publish our message and
            //in the next line we should subscribe and get this data. the issue is here because we have eventually
            //consistency we need some trigger to know when can I actually look to the database and get data. we need
            //some mechanism for this like bellow but it is slow

            // await Act(command);
            // await Task.Delay(5000)

            //2.after publishing integration event we can subscribe to integration event. event means something already happened,
            //here GameEventSourceAdded integration event so once we get this event we go to mongodb look for data and get it
            //we can do this with special method inside our rabbitmq fixture.

            var tcs = _rabbitMqFixture.SubscribeAndGet <AddGameEventSource, GameEventSource>(Exchange,
                                                                                             _mongoDbFixture.GetAsync, command.Id); //use task completion source (tcs)

            await Act(command);

            var document = await tcs.Task;

            document.ShouldNotBeNull();
            document.Id.ShouldBe(command.Id);
            document.IsWin.ShouldBe(command.IsWin);
            document.Score.ShouldBe(command.Score);
        }
        public async Task add_game_event_source_endpoint_should_return_location_header_with_correct_id()
        {
            var command = new AddGameEventSource(Guid.NewGuid(), 10, true, Guid.NewGuid());

            var response = await Act(command);

            var locationHeader = response.Headers.FirstOrDefault(h => h.Key == "Location").Value.First();

            locationHeader.ShouldNotBeNull();
            locationHeader.ShouldBe($"game-event-sources/{command.Id}");
        }
        public async Task add_game_event_source_endpoint_should_return_http_status_code_created()
        {
            var command = new AddGameEventSource(Guid.NewGuid(), 10, true, Guid.NewGuid());

            var response = await Act(command);

            response.ShouldNotBeNull();
            response.StatusCode.ShouldBe(HttpStatusCode.Created);
            response.Headers.Location.ShouldNotBeNull();
            response.Headers.Location.ToString().ShouldBe($"game-event-sources/{command.Id}");
        }
        public async Task add_game_event_source_endpoint_should_add_document_with_given_id_to_database()
        {
            var command = new AddGameEventSource(Guid.NewGuid(), 10, true, Guid.NewGuid());

            await Act(command);

            var document = await _mongoDbFixture.GetAsync(command.Id);

            document.ShouldNotBeNull();
            document.Id.ShouldBe(command.Id);
            document.IsWin.ShouldBe(command.IsWin);
            document.Score.ShouldBe(command.Score);
        }
        public async Task <ActionResult> Post(AddGameEventSource command)
        {
            await SendAsync(command.Bind(c => c.Id, command.Id == default ? Guid.NewGuid() : command.Id));

            return(Accepted());
        }
 public async Task <IActionResult> Post(AddGameEventSource command)
 => await SendAsync(command.Bind(c => c.Id, command.Id == default ? Guid.NewGuid() : command.Id),
Esempio n. 7
0
 public async Task Post(AddGameEventSource command)
 {
     await SendAsync(command.Bind(c => c.Id, command.Id == default ? Guid.NewGuid() : command.Id));
 }
 private Task Act(AddGameEventSource command) => _rabbitMqFixture.PublishAsync(command, Exchange);
Esempio n. 9
0
        public async Task <ActionResult> Post(AddGameEventSource command)
        {
            await SendAsync(command.BindId(c => c.Id));

            return(Accepted());
        }
        public async Task <ActionResult> Post(AddGameEventSource command)
        {
            await SendAsync(command.Bind(c => c.Id, command.Id == Guid.Empty ? Guid.NewGuid() : command.Id));

            return(Created($"game-event-sources/{command.Id}", command));
        }
 private Task <HttpResponseMessage> Act(AddGameEventSource command)
 => _httpClient.PostAsJsonAsync("game-event-sources", command);     //send request to our web api
Esempio n. 12
0
 public async Task <IActionResult> Post(AddGameEventSource command)
 => await SendAsync(command.BindId(c => c.Id),
                    resourceId : command.Id, resource : "game-event-sources");