public async Task GivenOtherPaths_WhenPublishingPathRemovedEvent_ThenWePublish() { var created = new PathRemovedEvent { FeatureRemoved = "derpy", Path = "derpy/wants/muffins", }; var client = this.GivenIEventStoreClient() .WithAppendToStreamAsync(this._pathStream); var reader = this.GivenIReadStreamedEvents <PathStream>() .WithEvents(new List <IEvent> { created }); var removing = new PathRemovedEvent { FeatureRemoved = "bob", Path = "let.me" }; var aggregate = await this .GivenAggregate(reader.Object, client.Object) .WithLoad(); await aggregate .WhenPublishing(removing) .ThenWePublish(client, removing); }
public async Task GivenNoPreviousPaths_WhenPublishingPathRemovedEvent_ThenWePublish() { var client = this.GivenIEventStoreClient() .WithAppendToStreamAsync(this._pathStream); var reader = this.GivenIReadStreamedEvents <PathStream>() .WithEvents(Enumerable.Empty <IEvent>()); var removed = new PathRemovedEvent { FeatureRemoved = "bob", Path = "let/me/show/you" }; var aggregate = await this .GivenAggregate(reader.Object, client.Object) .WithLoad(); await aggregate .WhenPublishing(removed) .ThenWePublish(client, removed); aggregate.Paths.Select(_ => _.Name) .Should() .BeEquivalentTo(Enumerable.Empty <string>()); }
public async Task GivenOnePreExistingPath_WhenRemovingThePath_ThenThePathsAreEmptied() { var created = new PathCreatedEvent { FeatureAdded = "bob", Path = "let/me/show/you" }; var removed = new PathRemovedEvent { FeatureRemoved = "bob", Path = "let/me/show/you" }; var client = this.GivenIEventStoreClient() .WithAppendToStreamAsync(this._pathStream); var reader = this.GivenIReadStreamedEvents <PathStream>() .WithEvents(new List <IEvent> { created, removed }); var aggregate = await this .GivenAggregate(reader.Object, client.Object) .WithLoad(); aggregate.Paths.Should().BeEmpty(); }
private void Apply(PathRemovedEvent e) { if (this.Paths.Any(_ => _.Name.Equals(e.Path, StringComparison.InvariantCultureIgnoreCase))) { var sections = PathHelper.TranformToPathLevels(e.Path); var existingPaths = this.Paths .Where(_ => sections.Contains(_.Name)) .Select(_ => _.Name) .ToList(); if (existingPaths.Any()) { this.Paths = this.Paths .Select(p => { if (sections.Contains(p.Name)) { return(new Domain.Path { Name = p.Name, TotalFeatures = p.TotalFeatures - 1, }); } return(p); }) .Where(_ => _.TotalFeatures > 0) .ToList(); } } }
public async Task GivenPreExistingPaths_WhenRemovingThePath_ThenThePathsAreUpdated() { var created = new PathCreatedEvent { FeatureAdded = "bob", Path = "let/me/show/you" }; var createdSecond = new PathCreatedEvent { FeatureAdded = "bob", Path = "let/me/show" }; var createdThird = new PathCreatedEvent { FeatureAdded = "bob", Path = "let/me" }; var client = this.GivenIEventStoreClient() .WithAppendToStreamAsync(this._pathStream); var reader = this.GivenIReadStreamedEvents <PathStream>() .WithEvents(new List <IEvent> { created, createdSecond, createdThird }); var removed = new PathRemovedEvent { FeatureRemoved = "bob", Path = "let/me/show/you" }; var aggregate = await this .GivenAggregate(reader.Object, client.Object) .WithLoad(); await aggregate .WhenPublishing(removed) .ThenWePublish(client, removed); aggregate.Paths.Should() .BeEquivalentTo(new List <Path> { new Path { Name = "let", TotalFeatures = 2 }, new Path { Name = "let/me", TotalFeatures = 2 }, new Path { Name = "let/me/show", TotalFeatures = 1 } }); }
public static EventData ToEventData(this PathRemovedEvent pathRemovedEvent, JsonSerializerOptions settings = null !) { var contentBytes = JsonSerializer.SerializeToUtf8Bytes(pathRemovedEvent, settings); return(new EventData( eventId: Uuid.NewUuid(), type: pathRemovedEvent.Type, data: contentBytes )); }
public async Task GivenOnePreExistingPath_WhenRemovingAnUnknownPath_ThenThePathIsUntouched() { var created = new PathCreatedEvent { FeatureAdded = "bob", Path = "let/me/show/you" }; var removed = new PathRemovedEvent { FeatureRemoved = "bob", Path = "let/me/show/arrrrgh" }; var client = this.GivenIEventStoreClient() .WithAppendToStreamAsync(this._pathStream); var reader = this.GivenIReadStreamedEvents <PathStream>() .WithEvents(new List <IEvent> { created, removed }); var aggregate = await this .GivenAggregate(reader.Object, client.Object) .WithLoad(); aggregate.Paths.Should() .BeEquivalentTo(new List <Path> { new Path { Name = "let", TotalFeatures = 1 }, new Path { Name = "let/me", TotalFeatures = 1 }, new Path { Name = "let/me/show", TotalFeatures = 1 }, new Path { Name = "let/me/show/you", TotalFeatures = 1 } }); }
public static async Task ThenWePublish( this Func <Task> funk, Mock <IEventStoreClient> mockedClient, PathRemovedEvent e) { await funk(); mockedClient.Verify( _ => _.AppendToStreamAsync( It.IsAny <PathStream>(), It.IsAny <StreamState>(), It.Is <IEnumerable <EventData> >(items => items.All(ed => ed.Type.Equals(EventTypes.PathRemoved) && JsonSerializer.Deserialize <PathRemovedEvent>(ed.Data.ToArray(), null) !.Path.Equals(e.Path, StringComparison.InvariantCultureIgnoreCase) )), It.IsAny <Action <EventStoreClientOperationOptions>?>(), It.IsAny <UserCredentials?>(), It.IsAny <CancellationToken>()), Times.Once()); }