public async Task GivenNoMatchingArchivedFeatures_WhenLoading_ThenWeThrowFeatureNotFoundException() { var created = new FeatureCreatedEvent { Name = "🦝", Path = "let/me/show/you", }; var archived = new FeatureArchivedEvent { Name = "bob", Path = "let/me/show/you", }; var reader = this.GivenIReadStreamedEvents <FeatureStream>() .WithEvents(new List <IEvent> { created, archived }); var client = this.GivenIEventStoreClient() .WithAppendToStreamAsync(this._featureStream); await this .GivenAggregate(reader.Object, client.Object) .WithLoad() .ThenExceptionIsThrown <FeatureNotFoundException>(); }
private void Apply(FeatureArchivedEvent 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.ArchivedOn, Path = f.Path, State = FeatureState.Archived, Strategies = f.Strategies, }); } return(f); }); this.Features = features.ToList(); }
public static EventData ToEventData(this FeatureArchivedEvent featureArchivedEvent, JsonSerializerOptions settings = null !) { var contentBytes = JsonSerializer.SerializeToUtf8Bytes(featureArchivedEvent, settings); return(new EventData( eventId: Uuid.NewUuid(), type: featureArchivedEvent.Type, data: contentBytes )); }
public async Task GivenAMatchingFeature_WhenPublishingFeatureArchivedEvent_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 aggregate = await this .GivenAggregate(reader.Object, client.Object) .WithLoad()(); var archived = new FeatureArchivedEvent { Name = "bob", Path = "let/me/show/you", }; await aggregate .WhenPublishing(archived) .ThenWePublish(client, archived); var features = aggregate.Features.ToList(); features.Select(_ => _.Name).Should() .BeEquivalentTo(new List <string> { created.Name, notMe.Name }); features.Where(_ => _.Name == archived.Name).Select(_ => _.State) .Should() .BeEquivalentTo(new List <FeatureState> { FeatureState.Archived }); features.Where(_ => _.Name != archived.Name).Select(_ => _.State) .Should() .BeEquivalentTo(new List <FeatureState> { FeatureState.Draft }); }
public async Task GivenAMatchingFeature_WhenLoading_ThenWeGetAArchivedFeature() { var createdNotMatching = new FeatureCreatedEvent { Name = "🤚", Path = "🌲/", }; var created = new FeatureCreatedEvent { Name = "🦝", Path = "🌲/", }; var archived = new FeatureArchivedEvent { Name = "🦝", Path = "🌲/", }; var reader = this.GivenIReadStreamedEvents <FeatureStream>() .WithEvents(new List <IEvent> { created, createdNotMatching, archived }); 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 == archived.Name).Select(_ => _.State) .Should() .BeEquivalentTo(new List <FeatureState> { FeatureState.Archived }); features.Where(_ => _.Name != archived.Name).Select(_ => _.State) .Should() .BeEquivalentTo(new List <FeatureState> { FeatureState.Draft }); }
public static async Task ThenWePublish( this Func <Task> funk, Mock <IEventStoreClient> mockedClient, FeatureArchivedEvent e) { await funk(); mockedClient.Verify( _ => _.AppendToStreamAsync( It.IsAny <FeatureStream>(), It.IsAny <StreamState>(), It.Is <IEnumerable <EventData> >(items => items.All(ed => ed.Type.Equals(EventTypes.FeatureArchived) && JsonSerializer.Deserialize <FeatureArchivedEvent>(ed.Data.ToArray(), null) !.Name.Equals(e.Name, StringComparison.InvariantCultureIgnoreCase) )), It.IsAny <Action <EventStoreClientOperationOptions>?>(), It.IsAny <UserCredentials?>(), It.IsAny <CancellationToken>()), Times.Once()); }