public void GivenACommandIsNull_WhenValidating_ThenArgumentNullIsThrown()
        {
            PublishFeatureCommand command = null;

            command
            .WhenValidating()
            .ThenExceptionIsThrown <ArgumentValidationException>();
        }
        public static async Task ThenWeDontPublish(
            this Func <Task> funk,
            Mock <IFeaturesAggregate> featuresAggregate,
            PublishFeatureCommand command)
        {
            await funk();

            featuresAggregate.Verify(_ => _.Publish(
                                         It.Is <FeaturePublishedEvent>(e => e.Name.Equals(
                                                                           command.Name,
                                                                           StringComparison.InvariantCultureIgnoreCase))),
                                     Times.Never);
        }
        public async Task GivenAValidCommand_WhenPublishingAFeature_ThenWePublishPathAndFeature()
        {
            var featuresAggregate = this.GivenIFeaturesAggregate();

            var command = new PublishFeatureCommand
            {
                PublishedBy = "meeee",
                Name        = "bob",
                Path        = "let/me/show/you",
            };

            await this.GivenCommandHandler(featuresAggregate.Object)
            .WhenPublishingAFeature(command)
            .ThenWePublish(featuresAggregate, command);
        }
        public async Task GivenACommand_WhenPublishingThrows_ThenWeThrow()
        {
            var featuresAggregate = this.GivenIFeaturesAggregate()
                                    .WithPublishingThrows <NotImplementedException>();

            var command = new PublishFeatureCommand
            {
                PublishedBy = "😎",
                Name        = "🌲/🦝",
            };

            await this.GivenCommandHandler(featuresAggregate.Object)
            .WhenPublishingAFeature(command)
            .ThenExceptionIsThrown <NotImplementedException>();
        }
        public async Task GivenAnInvalidCommand_WhenPublishingAFeature_ThenWeThrow()
        {
            var featuresAggregate = this.GivenIFeaturesAggregate()
                                    .WithPublishing();

            var command = new PublishFeatureCommand
            {
                PublishedBy = "😎",
                Path        = "🌲/🦝",
            };

            await this.GivenCommandHandler(featuresAggregate.Object)
            .WhenPublishingAFeature(command)
            .ThenExceptionIsThrown <ArgumentValidationException>();
        }
        public async Task GivenACommand_WhenPublishingAFeatureThatDoesNotExist_ThenWeDoNotThrow()
        {
            var featuresAggregate = this.GivenIFeaturesAggregate()
                                    .WithPublishing();

            var command = new PublishFeatureCommand
            {
                PublishedBy = "meeee",
                Name        = "bob",
                Path        = "let/me/show/you",
            };

            await this.GivenCommandHandler(featuresAggregate.Object)
            .WhenPublishingAFeature(command)
            .ThenWePublish(featuresAggregate, command);
        }
 public static Func <Task> WhenPublishingAFeature(
     this IHandleCommand <PublishFeatureCommand> handler,
     PublishFeatureCommand command)
 {
     return(() => handler.Handle(command));
 }
        public static void ThenWeGetAFeaturePublishedEvent(this Func <FeaturePublishedEvent> featFunc, PublishFeatureCommand command, ISystemClock clock)
        {
            var feat = featFunc();

            feat.PublishedBy.Should().Be(command.PublishedBy);
            feat.PublishedOn.Should().Be(clock.UtcNow);
            feat.Name.Should().Be(command.Name);
            feat.Path.Should().Be(command.Path);
        }
 public static Func <FeaturePublishedEvent> WhenExtractingFeaturePublishedEvent(this PublishFeatureCommand command, ISystemClock clock)
 {
     return(() => command.ExtractFeaturePublishedEvent(clock));
 }
 public static Action WhenValidating(this PublishFeatureCommand command)
 {
     return(() => command.Validate());
 }