public void GivenACommandIsNUll_WhenValidating_ThenArgumentNullIsThrown()
        {
            ArchiveFeatureCommand command = null;

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

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

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

            await this.GivenCommandHandler(featuresAggregate.Object)
            .WhenArchiveingAFeature(command)
            .ThenWeArchive(featuresAggregate, command);
        }
        public async Task GivenACommand_WhenArchiveingThrows_ThenWeThrow()
        {
            var featuresAggregate = this.GivenIFeaturesAggregate()
                                    .WithPublishingThrows <NotImplementedException>();

            var command = new ArchiveFeatureCommand
            {
                ArchivedBy = "😎",
                Name       = "🌲/🦝",
            };

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

            var command = new ArchiveFeatureCommand
            {
                ArchivedBy = "😎",
                Path       = "🌲/🦝",
            };

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

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

            await this.GivenCommandHandler(featuresAggregate.Object)
            .WhenArchiveingAFeature(command)
            .ThenWeArchive(featuresAggregate, command);
        }
 public static Func <Task> WhenArchiveingAFeature(
     this IHandleCommand <ArchiveFeatureCommand> handler,
     ArchiveFeatureCommand command)
 {
     return(() => handler.Handle(command));
 }
        public static void ThenWeGetAFeatureArchivedEvent(this Func <FeatureArchivedEvent> featFunc, ArchiveFeatureCommand command, ISystemClock clock)
        {
            var feat = featFunc();

            feat.ArchivedBy.Should().Be(command.ArchivedBy);
            feat.ArchivedOn.Should().Be(clock.UtcNow);
            feat.Name.Should().Be(command.Name);
            feat.Path.Should().Be(command.Path);
        }
 public static Func <FeatureArchivedEvent> WhenExtractingFeatureArchivedEvent(this ArchiveFeatureCommand command, ISystemClock clock)
 {
     return(() => command.ExtractFeatureArchivedEvent(clock));
 }
 public static Action WhenValidating(this ArchiveFeatureCommand command)
 {
     return(() => command.Validate());
 }