Exemplo n.º 1
0
        private static async Task LoadMovieAsync()
        {
            Console.Write("ObjectId: ");
            var id = Guid.Parse(Console.ReadLine() ?? "");

            var movie = await _store.LoadAsync <Movie>(id).ConfigureAwait(false);

            ObjectDumper.Write(movie);
        }
Exemplo n.º 2
0
        private async Task ValidateScheduleHappens(Func <IJob, IJobScheduler, Task <IJobId> > schedule)
        {
            // Arrange
            var testId            = ThingyId.New;
            var pingId            = PingId.New;
            var executeCommandJob = PublishCommandJob.Create(new ThingyPingCommand(testId, pingId), Resolver);

            // Act
            var jobId = await schedule(executeCommandJob, _jobScheduler).ConfigureAwait(false);

            // Assert
            var start = DateTimeOffset.Now;

            while (DateTimeOffset.Now < start + TimeSpan.FromSeconds(20))
            {
                var testAggregate = await AggregateStore.LoadAsync <ThingyAggregate, ThingyId>(testId, CancellationToken.None).ConfigureAwait(false);

                if (!testAggregate.IsNew)
                {
                    await AssertJobIsSuccessfullAsync(jobId).ConfigureAwait(false);

                    Assert.Pass();
                }

                await Task.Delay(TimeSpan.FromSeconds(0.2)).ConfigureAwait(false);
            }

            Assert.Fail("Aggregate did not receive the command as expected");
        }
Exemplo n.º 3
0
        private Task <ThingySaga> LoadSagaAsync(ThingyId thingyId)
        {
            // This is specified in the ThingySagaLocator
            var expectedThingySagaId = new ThingySagaId($"saga-{thingyId.Value}");

            return(AggregateStore.LoadAsync <ThingySaga, ThingySagaId>(
                       expectedThingySagaId,
                       CancellationToken.None));
        }
Exemplo n.º 4
0
        public async Task AfterSelectedJourneysShouldHaveJourneys()
        {
            //Arrange
            var flight = new FlightBuilder().Build();

            //Act
            await UpdateAsync(FlightAvailabilityId, (FlightAvailability x) => x.AddFlight(flight));

            //Assert
            var flightAvailability = await AggregateStore.LoadAsync <FlightAvailability, FlightAvailabilityId>(FlightAvailabilityId, CancellationToken.None);

            flightAvailability.Flights.Count.Should().Be(1);
        }
Exemplo n.º 5
0
        public async Task AfterSelectedJourneysShouldHaveJourneys()
        {
            //Arrange
            _journeys = new JourneysBuilder().BuildJourneys();
            void SelectJourney(Booking.Booking b) => b.SelectJourneys(_journeys);

            //Act
            await UpdateAsync(BookingId, (Action <Booking.Booking>) SelectJourney);

            //Assert
            var booking = await AggregateStore.LoadAsync <Booking.Booking, BookingId>(BookingId, CancellationToken.None);

            booking.Journeys.Should().NotBeEmpty();
        }
        public async Task WhenSendSelectJourneysCommandShouldAddJourneys()
        {
            //Arrange
            var journeys = new JourneysBuilder().BuildJourneys();
            var selectJourneysCommand = new SelectJourneysCommand(_bookingId, journeys);

            //Act
            await CommandBus.PublishAsync(selectJourneysCommand, CancellationToken.None);

            //Assert
            var booking = await AggregateStore.LoadAsync <Booking, BookingId>(_bookingId, CancellationToken.None);

            booking.Journeys.Should().NotBeEmpty();
        }
Exemplo n.º 7
0
        public async Task WhenSendAddFlightCommandShouldAddFlight()
        {
            //Arrange
            var scenario = new AddFlightScenario(CommandBus);

            //Act
            await scenario.Execute();

            //Assert
            var id = scenario.Id;

            var flightAvailability = await AggregateStore.LoadAsync <Domain.FlightAvailability, FlightAvailabilityId>(id, CancellationToken.None);

            flightAvailability.Flights.Count.Should().Be(1);
        }
Exemplo n.º 8
0
        public async Task ExecutionResultShouldControlEventStore(bool isSuccess, int expectedAggregateVersion)
        {
            // Arrange
            var pingId   = PingId.New;
            var thingyId = ThingyId.New;

            // Act
            var executionResult = await CommandBus.PublishAsync(
                new ThingyMaybePingCommand(thingyId, pingId, isSuccess),
                CancellationToken.None)
                                  .ConfigureAwait(false);

            executionResult.IsSuccess.Should().Be(isSuccess);

            // Assert
            var thingyAggregate = await AggregateStore.LoadAsync <ThingyAggregate, ThingyId>(
                thingyId,
                CancellationToken.None)
                                  .ConfigureAwait(false);

            thingyAggregate.Version.Should().Be(expectedAggregateVersion);
        }
Exemplo n.º 9
0
 protected Task <ThingyAggregate> LoadAggregateAsync(ThingyId thingyId)
 {
     return(AggregateStore.LoadAsync <ThingyAggregate, ThingyId>(thingyId));
 }