private void Apply(FeaturePublishedEvent e) { var pathAndName = PathHelper.CombineNameAndPath(e.Path, e.Name); var exists = this.Features.Any(_ => PathHelper.CombineNameAndPath(_.Path, _.Name).Equals(pathAndName)); if (!exists) { throw new FeatureNotFoundException(e.Path, e.Name); } var features = this.Features .Select(f => { if (PathHelper.CombineNameAndPath(f.Path, f.Name).Equals(pathAndName)) { return(new Feature { Name = f.Name, CreatedBy = f.CreatedBy, CreatedOn = f.CreatedOn, UpdatedOn = e.PublishedOn, Path = f.Path, State = FeatureState.Published, Strategies = f.Strategies, }); } return(f); }); this.Features = features.ToList(); }
public async Task GivenNoMatchingPublishedFeatures_WhenLoading_ThenWeTHrowFeatureNotFoundException() { var created = new FeatureCreatedEvent { Name = "🦝", Path = "let/me/show/you", }; var published = new FeaturePublishedEvent { Name = "bob", Path = "let/me/show/you", }; var reader = this.GivenIReadStreamedEvents <FeatureStream>() .WithEvents(new List <IEvent> { created, published }); var client = this.GivenIEventStoreClient() .WithAppendToStreamAsync(this._featureStream); await this .GivenAggregate(reader.Object, client.Object) .WithLoad() .ThenExceptionIsThrown <FeatureNotFoundException>(); }
public async Task GivenFeaturePublishedBefore_WhenPublishingFeatureUpdatedEvent_ThenWeThrowFeatureWasPublishedBefoeException() { var createdAlready = new FeatureCreatedEvent { Name = "bob", Path = "let/me/show/you", }; var publishedAlready = new FeaturePublishedEvent { Name = createdAlready.Name, Path = createdAlready.Path, PublishedBy = "moua", }; var client = this.GivenIEventStoreClient() .WithAppendToStreamAsync(this._featureStream); var reader = this.GivenIReadStreamedEvents <FeatureStream>() .WithEvents(new List <IEvent> { createdAlready, publishedAlready }); var updated = new FeatureUpdatedEvent { Name = createdAlready.Name, Path = createdAlready.Path, NewName = "bob2", NewPath = "let", }; var aggregate = await this .GivenAggregate(reader.Object, client.Object) .WithLoad()(); await aggregate .WhenPublishing(updated) .ThenExceptionIsThrown <FeatureIsNotInDraftException>(); }
public async Task GivenAPublishedFeature_WhenAssigningAStrategy_ThenWeThrow() { var created = new FeatureCreatedEvent { Name = "bob", Path = "let/me/show/you", }; var published = new FeaturePublishedEvent { Name = created.Name, Path = created.Path, }; var assigned = new StrategyAssignedEvent { Name = created.Name, Path = created.Path, StrategyName = "yolo", Settings = "settings", }; var client = this.GivenIEventStoreClient() .WithAppendToStreamAsync(this._featureStream); var reader = this.GivenIReadStreamedEvents <FeatureStream>() .WithEvents(new List <IEvent> { created, published, assigned, }); await this .GivenAggregate(reader.Object, client.Object) .WithLoad() .ThenExceptionIsThrown <FeatureIsNotInDraftException>(); }
public static EventData ToEventData(this FeaturePublishedEvent featurePublishedEvent, JsonSerializerOptions settings = null !) { var contentBytes = JsonSerializer.SerializeToUtf8Bytes(featurePublishedEvent, settings); return(new EventData( eventId: Uuid.NewUuid(), type: featurePublishedEvent.Type, data: contentBytes )); }
public async Task GivenAMatchingFeature_WhenPublishingFeaturePublishedEvent_ThenWePublishTheFeature() { var notMe = new FeatureCreatedEvent { Name = "🌲", Path = "let/me/show/you", }; var created = new FeatureCreatedEvent { Name = "bob", Path = "let/me/show/you", }; var client = this.GivenIEventStoreClient() .WithAppendToStreamAsync(this._featureStream); var reader = this.GivenIReadStreamedEvents <FeatureStream>() .WithEvents(new List <IEvent> { created, notMe }); var published = new FeaturePublishedEvent { Name = "bob", Path = "let/me/show/you", }; var aggregate = await this .GivenAggregate(reader.Object, client.Object) .WithLoad()(); await aggregate .WhenPublishing(published) .ThenWePublish(client, published); var features = aggregate.Features.ToList(); features.Select(_ => _.Name).Should() .BeEquivalentTo(new List <string> { created.Name, notMe.Name }); features.Where(_ => _.Name == published.Name).Select(_ => _.State) .Should() .BeEquivalentTo(new List <FeatureState> { FeatureState.Published }); features.Where(_ => _.Name != published.Name).Select(_ => _.State) .Should() .BeEquivalentTo(new List <FeatureState> { FeatureState.Draft }); }
public async Task GivenAMatchingFeature_WhenLoading_ThenWeGetAPublishedFeature() { var createdNotMatching = new FeatureCreatedEvent { Name = "🤚", Path = "🌲/", }; var created = new FeatureCreatedEvent { Name = "🦝", Path = "🌲/", }; var published = new FeaturePublishedEvent { Name = "🦝", Path = "🌲/", }; var reader = this.GivenIReadStreamedEvents <FeatureStream>() .WithEvents(new List <IEvent> { created, createdNotMatching, published }); var client = this.GivenIEventStoreClient() .WithAppendToStreamAsync(this._featureStream); var aggregate = await this .GivenAggregate(reader.Object, client.Object) .WithLoad()(); var features = aggregate.Features.ToList(); features.Select(_ => _.Name).Should() .BeEquivalentTo(new List <string> { created.Name, createdNotMatching.Name }); features.Where(_ => _.Name == published.Name).Select(_ => _.State) .Should() .BeEquivalentTo(new List <FeatureState> { FeatureState.Published }); features.Where(_ => _.Name != published.Name).Select(_ => _.State) .Should() .BeEquivalentTo(new List <FeatureState> { FeatureState.Draft }); }
public static async Task ThenWePublish( this Func <Task> funk, Mock <IEventStoreClient> mockedClient, FeaturePublishedEvent e) { await funk(); mockedClient.Verify( _ => _.AppendToStreamAsync( It.IsAny <FeatureStream>(), It.IsAny <StreamState>(), It.Is <IEnumerable <EventData> >(items => items.All(ed => ed.Type.Equals(EventTypes.FeaturePublished) && JsonSerializer.Deserialize <FeaturePublishedEvent>(ed.Data.ToArray(), null) !.Name.Equals(e.Name, StringComparison.InvariantCultureIgnoreCase) )), It.IsAny <Action <EventStoreClientOperationOptions>?>(), It.IsAny <UserCredentials?>(), It.IsAny <CancellationToken>()), Times.Once()); }