예제 #1
0
        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>();
        }
예제 #2
0
        public async Task GivenDraftFeature_WhenPublishingFeatureUpdatedEvent_ThenWePublishTheEvent()
        {
            var createdAlready = 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> {
                createdAlready
            });

            var updated = new FeatureUpdatedEvent {
                Name    = "bob",
                Path    = "let/me/show/you",
                NewName = "bob2",
                NewPath = "let",
            };

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

            await aggregate
            .WhenPublishing(updated)
            .ThenWePublish(client, updated)
            .ThenFeatureIsUpdated(aggregate, updated);
        }
        public static EventData ToEventData(this FeatureUpdatedEvent featureUpdatedEvent, JsonSerializerOptions settings = null !)
        {
            var contentBytes = JsonSerializer.SerializeToUtf8Bytes(featureUpdatedEvent, settings);

            return(new EventData(
                       eventId: Uuid.NewUuid(),
                       type: featureUpdatedEvent.Type,
                       data: contentBytes
                       ));
        }
예제 #4
0
        public static async Task ThenFeatureIsUpdated(
            this Task task,
            IFeaturesAggregate aggregate,
            FeatureUpdatedEvent updatedEvent)
        {
            await task;

            aggregate.Features.Select(_ => _.Name).Should().BeEquivalentTo(new List <string>
            {
                updatedEvent.NewName
            });

            aggregate.Features.Select(_ => _.Path).Should().BeEquivalentTo(new List <string>
            {
                updatedEvent.NewPath
            });
        }
예제 #5
0
        public async Task <FeatureDTO> Handle(UpdateFeatureCommand request, CancellationToken cancellationToken)
        {
            var feature = await _repository.GetAsync(request.Id);

            feature.SetName(request.Name);
            feature.SetDescription(request.Description);
            feature.SetPrice(request.Price);

            _repository.Update(feature);

            await _repository.UnitOfWork.SaveChangesAsync();

            var featureDTO       = _mapper.Map <FeatureDTO>(feature);
            var integrationEvent = new FeatureUpdatedEvent(featureDTO);
            await _integrationEventService.AddAndSaveEventAsync(integrationEvent);

            return(featureDTO);
        }
예제 #6
0
        public async Task GivenNoFeatures_WhenPublishingFeatureUpdatedEvent_ThenWeThrowFeatureNotFoundExcepion()
        {
            var client = this.GivenIEventStoreClient()
                         .WithAppendToStreamAsync(this._featureStream);

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

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

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

            await aggregate
            .WhenPublishing(updated)
            .ThenExceptionIsThrown <FeatureNotFoundException>();
        }
예제 #7
0
        public static async Task ThenWePublish(
            this Func <Task> funk,
            Mock <IEventStoreClient> mockedClient,
            FeatureUpdatedEvent e)
        {
            await funk();

            mockedClient.Verify(
                _ => _.AppendToStreamAsync(
                    It.IsAny <FeatureStream>(),
                    It.IsAny <StreamState>(),
                    It.Is <IEnumerable <EventData> >(items =>
                                                     items.All(ed =>
                                                               ed.Type.Equals(EventTypes.FeatureUpdated) &&
                                                               JsonSerializer.Deserialize <FeatureUpdatedEvent>(ed.Data.ToArray(), null) !.Name.Equals(e.Name, StringComparison.InvariantCultureIgnoreCase)
                                                               )),
                    It.IsAny <Action <EventStoreClientOperationOptions>?>(),
                    It.IsAny <UserCredentials?>(),
                    It.IsAny <CancellationToken>()),
                Times.Once());
        }
예제 #8
0
        private void Apply(FeatureUpdatedEvent 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 = e.NewName,
                        Path = e.NewPath,
                        UpdatedOn = e.UpdatedOn,
                        CreatedBy = f.CreatedBy,
                        CreatedOn = f.CreatedOn,
                        State = f.State,
                        Strategies = f.Strategies,
                    });
                }

                return(f);
            });

            this.Features = features.ToList();
        }