public static EventData ToEventData(this StrategyUnAssignedEvent unAssignedEvent, JsonSerializerOptions settings = null !)
        {
            var contentBytes = JsonSerializer.SerializeToUtf8Bytes(unAssignedEvent, settings);

            return(new EventData(
                       eventId: Uuid.NewUuid(),
                       type: unAssignedEvent.Type,
                       data: contentBytes
                       ));
        }
        public async Task GivenAMatchingFeatureButNOMatchingStrategy_WhenLoadingStrategyUnassigned_ThenWeChangeNothing()
        {
            var notMe = new FeatureCreatedEvent {
                Name = "🌲",
                Path = "let/me/show/you",
            };

            var created = new FeatureCreatedEvent {
                Name = "bob",
                Path = "let/me/show/you",
            };

            var assigned = new StrategyAssignedEvent {
                Name         = created.Name,
                Path         = created.Path,
                StrategyName = "yolo",
                Settings     = "settings",
            };

            var unassigned = new StrategyUnAssignedEvent {
                Name         = created.Name,
                Path         = created.Path,
                StrategyName = StrategyNames.IsOn,
            };

            var reader = this.GivenIReadStreamedEvents <FeatureStream>()
                         .WithEvents(new List <IEvent> {
                created, notMe, assigned, unassigned
            });

            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, notMe.Name
            });

            features.Where(_ => _.Name == unassigned.Name)
            .SelectMany(_ => _.Strategies.Select(s => s.Name))
            .Should()
            .BeEquivalentTo(new List <string>
            {
                "yolo",
            });
        }
        public async Task GivenAPublishedFeature_WhenUnassigningAStrategy_ThenWeThrow()
        {
            var created = new FeatureCreatedEvent {
                Name = "bob",
                Path = "let/me/show/you",
            };

            var assigned = new StrategyAssignedEvent {
                Name         = created.Name,
                Path         = created.Path,
                StrategyName = "yolo",
                Settings     = "settings",
            };

            var published = new FeaturePublishedEvent {
                Name = created.Name,
                Path = created.Path,
            };

            var unassigned = new StrategyUnAssignedEvent {
                Name         = created.Name,
                Path         = created.Path,
                StrategyName = StrategyNames.IsOn,
            };

            var client = this.GivenIEventStoreClient()
                         .WithAppendToStreamAsync(this._featureStream);

            var reader = this.GivenIReadStreamedEvents <FeatureStream>()
                         .WithEvents(new List <IEvent> {
                created,
                assigned,
                published,
                unassigned,
            });

            await this
            .GivenAggregate(reader.Object, client.Object)
            .WithLoad()
            .ThenExceptionIsThrown <FeatureIsNotInDraftException>();
        }
        public static async Task ThenWePublish(
            this Func <Task> funk,
            Mock <IEventStoreClient> mockedClient,
            StrategyUnAssignedEvent e)
        {
            await funk();

            mockedClient.Verify(
                _ => _.AppendToStreamAsync(
                    It.IsAny <FeatureStream>(),
                    It.IsAny <StreamState>(),
                    It.Is <IEnumerable <EventData> >(items =>
                                                     items.All(ed =>
                                                               ed.Type.Equals(EventTypes.StrategyAssigned) &&
                                                               JsonSerializer.Deserialize <StrategyUnAssignedEvent>(ed.Data.ToArray(), null) !.Name.Equals(e.Name, StringComparison.InvariantCultureIgnoreCase)
                                                               )),
                    It.IsAny <Action <EventStoreClientOperationOptions>?>(),
                    It.IsAny <UserCredentials?>(),
                    It.IsAny <CancellationToken>()),
                Times.Once());
        }
        public async Task GivenNoFeatures_WhenPublishingStrategyAssignedEvent_ThenWePublishEventThoguhIDontExist()
        {
            var client = this.GivenIEventStoreClient()
                         .WithAppendToStreamAsync(this._featureStream);

            var reader = this.GivenIReadStreamedEvents <FeatureStream>()
                         .WithEvents(Enumerable.Empty <IEvent>());

            var unassigned = new StrategyUnAssignedEvent {
                Name         = "bob",
                Path         = "let/me/show/you",
                StrategyName = StrategyNames.IsOn,
            };

            var aggregate = await this
                            .GivenAggregate(reader.Object, client.Object)
                            .WithLoad()();

            await aggregate
            .WhenPublishing(unassigned)
            .ThenExceptionIsThrown <FeatureNotFoundException>();
        }
예제 #6
0
        private void Apply(StrategyUnAssignedEvent 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))
                {
                    if (f.State != FeatureState.Draft)
                    {
                        throw new FeatureIsNotInDraftException();
                    }

                    return(new Feature
                    {
                        Name = f.Name,
                        CreatedBy = f.CreatedBy,
                        CreatedOn = f.CreatedOn,
                        UpdatedOn = e.UnassignedOn,
                        Path = f.Path,
                        State = f.State,
                        Strategies = f.Strategies.Where(_ => !_.Name.Equals(e.StrategyName, StringComparison.InvariantCultureIgnoreCase)),
                    });
                }

                return(f);
            });

            this.Features = features.ToList();
        }