public static async Task ThenWePublish(
            this Func <Task> funk,
            Mock <IFeaturesAggregate> featuresAggregate,
            Mock <IPathsAggregate> pathsAggregate,
            UpdateFeatureCommand command)
        {
            await funk();

            featuresAggregate.Verify(_ => _.Publish(
                                         It.Is <FeatureUpdatedEvent>(e => e.NewName.Equals(
                                                                         command.NewName,
                                                                         StringComparison.InvariantCultureIgnoreCase))),
                                     Times.Once);

            pathsAggregate.Verify(_ => _.Publish(
                                      It.Is <PathRemovedEvent>(e => e.Path.Equals(
                                                                   command.Path,
                                                                   StringComparison.InvariantCultureIgnoreCase))),
                                  Times.Once);
            pathsAggregate.Verify(_ => _.Publish(
                                      It.Is <PathCreatedEvent>(e => e.Path.Equals(
                                                                   command.NewPath,
                                                                   StringComparison.InvariantCultureIgnoreCase))),
                                  Times.Once);
        }
Beispiel #2
0
        public void GivenACommandIsNUll_WhenValidating_ThenWeThrow()
        {
            UpdateFeatureCommand command = null;

            command
            .WhenValidating()
            .ThenExceptionIsThrown <ArgumentValidationException>();
        }
        public async Task GivenAnInvalidCommand_WhenCreatingAFeature_ThenWeThrow()
        {
            var featuresAggregate = this.GivenIFeaturesAggregate()
                                    .WithPublishing();
            var pathsAggregate = this.GivenIPathsAggregate()
                                 .WithPublishing();

            var command = new UpdateFeatureCommand
            {
                UpdatedBy = "meeee",
                Path      = "let/me/show/you",
            };

            await this.GivenCommandHandler(featuresAggregate.Object, pathsAggregate.Object)
            .WhenCreatingAFeature(command)
            .ThenExceptionIsThrown <ArgumentValidationException>();
        }
        public async Task GivenAValidCommand_WhenCreatingAFeature_ThenWePublishPathAndFeature()
        {
            var featuresAggregate = this.GivenIFeaturesAggregate();
            var pathsAggregate    = this.GivenIPathsAggregate();

            var command = new UpdateFeatureCommand
            {
                UpdatedBy = "meeee",
                Name      = "bob",
                Path      = "let/me/show/you",
                NewName   = "new",
                NewPath   = "road",
            };

            await this.GivenCommandHandler(featuresAggregate.Object, pathsAggregate.Object)
            .WhenCreatingAFeature(command)
            .ThenWePublish(featuresAggregate, pathsAggregate, command);
        }
        public async Task GivenACommand_WhenCreatingAFeatureThrowsInPaths_ThenWeThrow()
        {
            var featuresAggregate = this.GivenIFeaturesAggregate()
                                    .WithPublishing();
            var pathsAggregate = this.GivenIPathsAggregate()
                                 .WithPublishingThrows <ArgumentNullException>();

            var command = new UpdateFeatureCommand
            {
                UpdatedBy = "meeee",
                Name      = "bob",
                Path      = "let/me/show/you",
                NewName   = "new",
                NewPath   = "road",
            };

            await this.GivenCommandHandler(featuresAggregate.Object, pathsAggregate.Object)
            .WhenCreatingAFeature(command)
            .ThenExceptionIsThrown <ArgumentNullException>();
        }
 public static Func <Task> WhenCreatingAFeature(
     this IHandleCommand <UpdateFeatureCommand> handler,
     UpdateFeatureCommand command)
 {
     return(() => handler.Handle(command));
 }
Beispiel #7
0
        public static void ThenWeGetAFeatureUpdatedEvent(this Func <FeatureUpdatedEvent> featFunc, UpdateFeatureCommand command, ISystemClock clock)
        {
            var feat = featFunc();

            feat.UpdatedBy.Should().Be(command.UpdatedBy);
            feat.UpdatedOn.Should().Be(clock.UtcNow);
            feat.Name.Should().Be(command.Name);
            feat.Path.Should().Be(command.Path);
        }
Beispiel #8
0
        public static void ThenWeGetAPathRemovedEvent(this Func <PathRemovedEvent> pathFunc, UpdateFeatureCommand command, ISystemClock clock)
        {
            var paths = pathFunc();

            paths.RemovedBy.Should().Be(command.UpdatedBy);
            paths.RemovedOn.Should().Be(clock.UtcNow);
            paths.FeatureRemoved.Should().Be(command.Name);
        }
Beispiel #9
0
 public static Func <PathCreatedEvent> WhenExtractingPathCreatedEvent(this UpdateFeatureCommand command, ISystemClock clock)
 {
     return(() => command.ExtractPathCreatedEvent(clock));
 }
Beispiel #10
0
 public static Action WhenValidating(this UpdateFeatureCommand command)
 {
     return(() => command.Validate());
 }
 public async Task <ActionResult> Update([FromBody] UpdateFeatureCommand command)
 {
     return(Ok(await _mediator.Send(command)));
 }