public static CompetitionReadModel Query(IRootResolver resolver, CompetitionId exampleId) { // Resolve the query handler and use the built-in query for fetching // read models by identity to get our read model representing the // state of our aggregate root var queryProcessor = resolver.Resolve <IQueryProcessor>(); return(queryProcessor.Process(new ReadModelByIdQuery <CompetitionReadModel>(exampleId), CancellationToken.None)); }
internal CreateCareerCommand(string name, CompetitionId competitionId, SeasonId seasonId, Manager manager, ClubId clubId, Date date) { Ensure.IsNotNullOrEmpty(name); Ensure.IsNotNull(competitionId); Ensure.IsNotNull(seasonId); Ensure.IsNotNull(manager); Ensure.IsNotNull(clubId); this.Name = name; this.CompetitionId = competitionId; this.SeasonId = seasonId; this.Manager = manager; this.ClubId = clubId; this.Date = date; }
protected IDomainEvent <CompetitionAggregate, CompetitionId> ToDomainEvent( CompetitionId competitionId, IAggregateEvent aggregateEvent, int aggregateSequenceNumber = 1) { var metadata = new Metadata { Timestamp = A <DateTimeOffset>(), SourceId = A <SourceId>(), }; return(DomainEventFactory.Create <CompetitionAggregate, CompetitionId>( aggregateEvent, metadata, competitionId, aggregateSequenceNumber)); }
public async Task <IActionResult> Put( [HttpTrigger(AuthorizationLevel.Function, "put", Route = "entry/{id}")] HttpRequest req, ILogger log, string id) { EntryDTO data = await GetEntryData(req); if (data == null) { return(new BadRequestObjectResult("Must provide Entry details in POST body.")); } var competitionId = CompetitionId.With(data.CompetitionId); var entryId = EntryId.With(id); CorrectEntryTimeCommand correctEntryTimeCommand = new CorrectEntryTimeCommand(competitionId, entryId, data.TimeInMillis); var result = await _eventFlow.PublishAsync(correctEntryTimeCommand, CancellationToken.None); return(result?.IsSuccess == true ? (ActionResult) new OkObjectResult($"{JsonConvert.SerializeObject(correctEntryTimeCommand)}") : new BadRequestObjectResult($"Cannot or did not update entry {id}")); }
public async Task <IActionResult> Post( [HttpTrigger(AuthorizationLevel.Function, "post", Route = "entry")] HttpRequest req, ILogger log) { EntryDTO data = await GetEntryData(req); if (data == null) { return(new BadRequestObjectResult("Must provide Entry details in POST body.")); } var competitionId = CompetitionId.With(data.CompetitionId); var entryId = EntryId.New; RecordEntryCommand recordEntryCommand = new RecordEntryCommand(competitionId, entryId, data.Discipline, data.Name, data.TimeInMillis); var result = await _eventFlow.PublishAsync(recordEntryCommand, CancellationToken.None); return(result?.IsSuccess == true ? (ActionResult) new OkObjectResult($"{recordEntryCommand.EntryId}") : new BadRequestObjectResult("Cannot create new entry")); }
public CreateCareerCommandBuilder WithCompetitionId(CompetitionId competitionId) { this.competitionId = competitionId; return(this); }
private static CompetitionId PrepareCompetition(EventFlow.Configuration.IRootResolver resolver, string name, string user, CompetitionId competitionId = null) { var domainId = competitionId ?? CompetitionId.New; // Define some important value // Resolve the command bus and use it to publish a command var commandBus = resolver.Resolve <ICommandBus>(); // Create var executionResult = commandBus.PublishAsync(new RegisterCompetitionCommand(domainId, user, name), CancellationToken.None).Result; executionResult.IsSuccess.Should().BeTrue(); // Resolve the query handler and use the built-in query for fetching // read models by identity to get our read model representing the // state of our aggregate root var queryProcessor = resolver.Resolve <IQueryProcessor>(); // Verify that the read model has the expected value var readModel1 = queryProcessor.ProcessAsync(new ReadModelByIdQuery <CompetitionReadModel>(domainId), CancellationToken.None).Result; readModel1.Should().NotBeNull(); readModel1.AggregateId.Should().Be(domainId.Value); readModel1.Competitionname.Should().Be(name); readModel1.Username.Should().Be(user); return(domainId); }
private EntryId[] RegisterCompetitionWithEntries(IRootResolver resolver, int amount, CompetitionId competitionId = null) { var domainId = PrepareCompetition(resolver, "test-competition", "test-user", competitionId); // Resolve the command bus and use it to publish a command var commandBus = resolver.Resolve <ICommandBus>(); // Resolve the query handler and use the built-in query for fetching // read models by identity to get our read model representing the // state of our aggregate root var queryProcessor = resolver.Resolve <IQueryProcessor>(); const string discipline = "Discipline"; EntryId[] ids = new EntryId[amount]; for (int x = 0; x < amount; x++) { var entryId = EntryId.New; ids[x] = entryId; string competitor = string.Format("Competitor {0}", x + 1); int time = 12300 + x; // Add var executionResult = commandBus.PublishAsync(new RecordEntryCommand(domainId, entryId, discipline, competitor, time + 1), CancellationToken.None).Result; executionResult.IsSuccess.Should().BeTrue(); // Change time executionResult = commandBus.PublishAsync(new CorrectEntryTimeCommand(domainId, entryId, time), CancellationToken.None).Result; executionResult.IsSuccess.Should().BeTrue(); // Verify that the read model has the expected value var readModel2 = queryProcessor.ProcessAsync(new ReadModelByIdQuery <EntryReadModel>(entryId), CancellationToken.None).Result; readModel2.Should().NotBeNull(); readModel2.AggregateId.Should().Be(entryId.Value); readModel2.Discipline.Should().Be(discipline); readModel2.Competitor.Should().Be(competitor); readModel2.TimeInMillis.Should().Be(time); } return(ids); }
protected IReadOnlyCollection <IDomainEvent> ToDomainEvents(CompetitionId competitionId, int sequenceNumber, params IAggregateEvent[] events) { return(new ReadOnlyCollection <IDomainEvent>(events.Select((e, x) => ToDomainEvent(competitionId, e, sequenceNumber + x) as IDomainEvent).ToList())); }
protected IReadOnlyCollection <IDomainEvent> ToDomainEvents(CompetitionId competitionId, params IAggregateEvent[] events) { return(ToDomainEvents(competitionId, 1, events)); }