public static Func <StrategyAssignedEvent> WhenExtractingEvent(
     this AssignIsGreaterThanStrategyToFeatureCommand command,
     ISystemClock clock,
     IStrategySettingsSerializer serializer)
 {
     return(() => command.ExtractStrategyAssignedEvent(
                clock,
                serializer));
 }
        public static async Task ThenWePublish(
            this Func <Task> funk,
            Mock <IFeaturesAggregate> featuresAggregate,
            AssignIsGreaterThanStrategyToFeatureCommand command)
        {
            await funk();

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

            var command = new AssignIsGreaterThanStrategyToFeatureCommand
            {
                AssignedBy = "meeee",
                Name       = "bob",
                Path       = "let/me/show/you",
                Value      = 09
            };

            await this.GivenCommandHandler(featuresAggregate.Object)
            .WhenPublishingAFeature(command)
            .ThenWePublish(featuresAggregate, command);
        }
        public async Task GivenACommand_WhenPublishingAFeatureThatDoesNotExist_ThenWeDoNotThrow()
        {
            var featuresAggregate = this.GivenIFeaturesAggregate()
                                    .WithPublishing();

            var command = new AssignIsGreaterThanStrategyToFeatureCommand
            {
                AssignedBy = "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 AssignIsGreaterThanStrategyToFeatureCommand
            {
                AssignedBy = "😎",
                Name       = "🌲/🦝",
                Value      = 91L
            };

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

            var command = new AssignIsGreaterThanStrategyToFeatureCommand
            {
                AssignedBy = "😎",
                Path       = "🌲/🦝"
            };

            await this.GivenCommandHandler(featuresAggregate.Object)
            .WhenPublishingAFeature(command)
            .ThenExceptionIsThrown <ArgumentValidationException>();
        }
        public static void ThenWeGetAFeaturePublishedEvent(this Func <StrategyAssignedEvent> featFunc, AssignIsGreaterThanStrategyToFeatureCommand command, ISystemClock clock)
        {
            var feat = featFunc();

            feat.AssignedBy.Should().Be(command.AssignedBy);
            feat.AssignedOn.Should().Be(clock.UtcNow);
            feat.Name.Should().Be(command.Name);
            feat.Path.Should().Be(command.Path);
            feat.StrategyName.Should().Be(StrategyNames.IsGreaterThan);
            feat.Settings.Should().Be(JsonSerializer.Serialize(new NumericalStrategySettings()
            {
                Value = command.Value
            }));
        }
 public static Action WhenValidating(this AssignIsGreaterThanStrategyToFeatureCommand command)
 {
     return(() => command.Validate());
 }
 public static Func <Task> WhenPublishingAFeature(
     this IHandleCommand <AssignIsGreaterThanStrategyToFeatureCommand> handler,
     AssignIsGreaterThanStrategyToFeatureCommand command)
 {
     return(() => handler.Handle(command));
 }