Exemple #1
0
        public async Task Handle(HttpRequest request, HttpResponse response, RouteData routeData)
        {
            var orderId = ObjectId.GenerateNewId().ToString();

            response.Headers.Add("Content-Type", "application/json");
            response.Headers.Add("Location", $"{request.Scheme}://{request.Host}{request.Path}/{orderId}");

            var futureEvent = observable.FirstOfType <OrderFulfilled, OrderDiscarded>(orderId);
            var command     = await request.Body.ReadAs <PlaceOrder>();

            command.OrderId = orderId;

            await handler.Handle(command);

            try
            {
                await futureEvent;
                response.StatusCode = (int)HttpStatusCode.Created;
            }
            catch (TimeoutException)
            {
                response.StatusCode = (int)HttpStatusCode.Accepted;
            }

            var order = await orders.Find(o => o.Id == orderId).FirstAsync();

            await response.Body.Write(order);
        }
        public async Task EmitEventOnCreate()
        {
            // Arrange
            var calculation = new Calculation(calculationId);

            calculation.Add(42);
            var futureEvent = observable.FirstOfType <NumberAdded>(calculationId);

            // Act
            await calculations.Create(calculation);

            // Assert
            calculation.Events.Should().BeEmpty();
            var @event = await futureEvent;

            @event.SourceId.Should().Be(calculationId);
            @event.Result.Should().Be(42);
        }