Beispiel #1
0
    static async Task RunLoop(IEndpointInstance endpointInstance)
    {
        while (true)
        {
            Console.WriteLine("Press A to notify subscribers that an aircraft has changed");
            Console.WriteLine("Press C to cancel a rebooking request");
            Console.WriteLine("Press Q to quit");
            var key = Console.ReadKey();
            Console.WriteLine();

            switch (key.Key)
            {
            case ConsoleKey.A:
                var aircraftTypeHasChanged = new AircraftTypeHasChanged("B38M", "B739", "AA4079", DateTime.Today);
                await endpointInstance.Publish(aircraftTypeHasChanged).ConfigureAwait(false);

                break;

            case ConsoleKey.C:
                var bookingWasCancelled = new BookingWasCancelled("QAZ123");
                await endpointInstance.Publish(bookingWasCancelled).ConfigureAwait(false);

                break;

            case ConsoleKey.Q:
                return;

            default:
                Console.WriteLine("Invalid input. Please try again.");
                break;
            }
        }
    }
    public Task Handle(BookingWasCancelled message, IMessageHandlerContext context)
    {
        Data.IsCancelled = true;

        if (Data.CanCompleteSaga())
        {
            MarkAsComplete();
        }

        return(Task.CompletedTask);
    }
Beispiel #3
0
    public async Task ShouldNotAcceptTheRebooking()
    {
        await saga.Handle(rebookingWasProposed, context);

        var bookingWasCancelled = new BookingWasCancelled(bookingReferenceId);

        await saga.Handle(bookingWasCancelled, context);

        Assert.IsTrue(saga.Completed);
        Assert.AreEqual(0, context.PublishedMessages.Length);
    }
    public Task Handle(BookingWasCancelled message, IMessageHandlerContext context)
    {
        logger.Info("Received BookingWasCancelled event");
        Data.IsBookingCancelled = true;

        if (Data.CanCompleteSaga())
        {
            logger.Info("Saga is now complete");
            MarkAsComplete();
        }

        return(Task.CompletedTask);
    }
    public async Task ShouldNotConfirmTheBooking()
    {
        await saga.Handle(bookedFlightWasChanged, context);

        var bookingWasCancelled = new BookingWasCancelled
        {
            BookingReferenceId = bookingReferenceId,
            CancellationReason = "Aircraft type was changed from Boeing 787 to Boeing 777"
        };

        await saga.Handle(bookingWasCancelled, context);

        Assert.IsTrue(saga.Completed);
        Assert.AreEqual(0, context.PublishedMessages.Length);
    }