public void HandicapCalculationProcessStartedEvent_CanBeCreated_IsCreated() { HandicapCalculationProcessStartedEvent handicapCalculationProcessStartedEvent = HandicapCalculationProcessStartedEvent.Create(HandicapCalculationProcessTestData.AggregateId, HandicapCalculationProcessTestData.StartedDateTime); handicapCalculationProcessStartedEvent.ShouldNotBeNull(); handicapCalculationProcessStartedEvent.EventId.ShouldNotBe(Guid.Empty); handicapCalculationProcessStartedEvent.EventCreatedDateTime.ShouldNotBe(DateTime.MinValue); handicapCalculationProcessStartedEvent.AggregateId.ShouldBe(HandicapCalculationProcessTestData.AggregateId); handicapCalculationProcessStartedEvent.StartedDateTime.ShouldBe(HandicapCalculationProcessTestData.StartedDateTime); }
/// <summary> /// Starts the handicap calculation process. /// </summary> /// <param name="tournament">The tournament.</param> /// <param name="startedDateTime">The started date time.</param> /// <exception cref="InvalidOperationException">All Tournament scores must be published to run a handicap calculation process /// or /// Tournament must be completed to run a handicap calculation process</exception> public void StartHandicapCalculationProcess(TournamentAggregate tournament, DateTime startedDateTime) { // TODO: Business rules to protect reruns etc // TODO: handle resuming errored processes this.EnsureProcessCanBeStarted(); if (!tournament.HasBeenCompleted) { throw new InvalidOperationException("Tournament must be completed to run a handicap calculation process"); } if (!tournament.GetScores().All(s => s.IsPublished)) { throw new InvalidOperationException("All Tournament scores must be published to run a handicap calculation process"); } HandicapCalculationProcessStartedEvent handicapCalculationProcessStartedEvent = HandicapCalculationProcessStartedEvent.Create(this.AggregateId, startedDateTime); this.ApplyAndPend(handicapCalculationProcessStartedEvent); }
/// <summary> /// Plays the event. /// </summary> /// <param name="domainEvent">The domain event.</param> private void PlayEvent(HandicapCalculationProcessStartedEvent domainEvent) { this.Status = HandicapProcessStatus.Started; this.StartedDateTime = domainEvent.StartedDateTime; }
/// <summary> /// Handles the specific domain event. /// </summary> /// <param name="domainEvent">The domain event.</param> /// <param name="cancellationToken">The cancellation token.</param> /// <returns></returns> private async Task HandleSpecificDomainEvent(HandicapCalculationProcessStartedEvent domainEvent, CancellationToken cancellationToken) { await this.HandicapCalculationProcessor.Start(Guid.NewGuid(), domainEvent.AggregateId, domainEvent.StartedDateTime, cancellationToken); }