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

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

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

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

            var command = new AssignIsInListStrategyToFeatureCommand
            {
                AssignedBy = "meeee",
                Name       = "bob",
                Path       = "let/me/show/you",
                Items      = new List <string> {
                    "a"
                },
            };

            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 AssignIsInListStrategyToFeatureCommand
            {
                AssignedBy = "😎",
                Name       = "🌲/🦝",
                Items      = new List <string> {
                    "a"
                },
            };

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

            var command = new AssignIsInListStrategyToFeatureCommand
            {
                AssignedBy = "😎",
                Path       = "🌲/🦝",
                Items      = new List <string> {
                    "a"
                },
            };

            await this.GivenCommandHandler(featuresAggregate.Object)
            .WhenPublishingAFeature(command)
            .ThenExceptionIsThrown <ArgumentValidationException>();
        }
 public static Func <Task> WhenPublishingAFeature(
     this IHandleCommand <AssignIsInListStrategyToFeatureCommand> handler,
     AssignIsInListStrategyToFeatureCommand command)
 {
     return(() => handler.Handle(command));
 }
        public static void ThenWeGetAFeaturePublishedEvent(this Func <StrategyAssignedEvent> featFunc, AssignIsInListStrategyToFeatureCommand 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.IsInList);
            feat.Settings.Should().Be(JsonSerializer.Serialize(new IsInListStrategySettings
            {
                Items    = command.Items,
                ListName = command.ListName
            }));
        }
 public static Action WhenValidating(this AssignIsInListStrategyToFeatureCommand command)
 {
     return(() => command.Validate());
 }