public IActionResult Post(CreateFeatureRequest request)
        {
            var command = new CreateFeatureCommand(request.Label, request.Description, request.Action, request.Controller,
                                                   request.ControllerActionName, request.CreatedBy);
            Result result = _dispatcher.Dispatch(command);

            return(FromResult(result));
        }
Example #2
0
        public void GivenACommandIsNUll_WhenValidating_ThenArgumentNullIsThrown()
        {
            CreateFeatureCommand command = null;

            command
            .WhenValidating()
            .ThenExceptionIsThrown <ArgumentValidationException>();
        }
        public override async Task InitializeAsync()
        {
            await base.DisposeAsync();

            createProjectCommand = new CreateProjectCommand("project1", true);
            createProjectDto     = await SendAsync(createProjectCommand);

            createFeatureCommand = new CreateFeatureCommand("feature1", createProjectDto.Id);
            createFeatureDto     = await SendAsync(createFeatureCommand);
        }
Example #4
0
        public async Task <ActionResult <Guid> > NewFeature(CreateFeatureCommand createFeatureCommand)
        {
            var vm = await mediator.Send(createFeatureCommand);

            if (vm.Id != Guid.Empty)
            {
                var link = Url.Link(nameof(GetProjectFeature), new { featureId = vm.Id });
                return(Created(link, vm));
            }
            else
            {
                return(BadRequest(vm));
            }
        }
Example #5
0
        public async Task ShouldDeleteFeature()
        {
            var createFeatureCommand = new CreateFeatureCommand("feature1", createProjectDto.Id);
            var createFeatureDto     = await SendAsync(createFeatureCommand);

            var deleteFeatureCommand = new DeleteFeatureCommand(createFeatureDto.Id, createProjectDto.Id);

            await SendAsync(deleteFeatureCommand);

            var featureEntity = await ExecuteDbContextAsync(db => db.Features
                                                            .SingleOrDefaultAsync(p => p.Id.Equals(createFeatureDto.Id))
                                                            );

            featureEntity.ShouldBeNull();
        }
Example #6
0
        public async Task GivenAValidCommand_WhenCreatingAFeature_ThenWePublishPathAndFeature()
        {
            var featuresAggregate = this.GivenIFeaturesAggregate();
            var pathsAggregate    = this.GivenIPathsAggregate();

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

            await this.GivenCommandHandler(featuresAggregate.Object, pathsAggregate.Object)
            .WhenCreatingAFeature(command)
            .ThenWePublish(featuresAggregate, pathsAggregate, command);
        }
Example #7
0
        public async Task ShouldGetFeature()
        {
            var createFeatureCommand = new CreateFeatureCommand("feature1", createProjectDto.Id);
            var createFeatureDto     = await SendAsync(createFeatureCommand);

            var getFeatureCommand = new GetFeatureQuery(createFeatureDto.Id, createProjectDto.Id);
            var getFeatureDto     = await SendAsync(getFeatureCommand);

            getFeatureDto.ShouldNotBeNull();
            getFeatureDto.Description.ShouldBeNull();
            getFeatureDto.Name.ShouldBe("feature1");
            getFeatureDto.ProjectId.ShouldBe(createProjectDto.Id);

            var deleteFeatureCommand = new DeleteFeatureCommand(createFeatureDto.Id, createProjectDto.Id);

            await SendAsync(deleteFeatureCommand);
        }
Example #8
0
        public async Task ShouldGetFeatureList()
        {
            var createFeatureCommand = new CreateFeatureCommand("feature1", createProjectDto.Id);
            var createFeatureDto     = await SendAsync(createFeatureCommand);

            var getFeatureListCommand = new GetFeatureListQuery(createProjectDto.Id);
            var getFeatureListDto     = await SendAsync(getFeatureListCommand);

            getFeatureListDto.ShouldNotBeNull();
            getFeatureListDto.Data.ShouldNotBeNull();
            getFeatureListDto.Count.ShouldNotBe(0);
            getFeatureListDto.Data.ShouldBeOfType <List <GetFeatureDto> >();

            var deleteFeatureCommand = new DeleteFeatureCommand(createFeatureDto.Id, createProjectDto.Id);

            await SendAsync(deleteFeatureCommand);
        }
Example #9
0
        public async Task GivenAnInvalidCommand_WhenCreatingAFeature_ThenWeThrow()
        {
            var featuresAggregate = this.GivenIFeaturesAggregate()
                                    .WithPublishing();
            var pathsAggregate = this.GivenIPathsAggregate()
                                 .WithPublishing();

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

            await this.GivenCommandHandler(featuresAggregate.Object, pathsAggregate.Object)
            .WhenCreatingAFeature(command)
            .ThenExceptionIsThrown <ArgumentValidationException>();
        }
Example #10
0
        public async Task GivenACommand_WhenCreatingAFeatureThrowsInFeatures_ThenWeThrow()
        {
            var featuresAggregate = this.GivenIFeaturesAggregate()
                                    .WithPublishingThrows <FeatureAlreadyExistsException>();
            var pathsAggregate = this.GivenIPathsAggregate()
                                 .WithPublishing();

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

            await this.GivenCommandHandler(featuresAggregate.Object, pathsAggregate.Object)
            .WhenCreatingAFeature(command)
            .ThenExceptionIsThrown <FeatureAlreadyExistsException>();
        }
Example #11
0
        public static async Task ThenWePublish(
            this Func <Task> funk,
            Mock <IFeaturesAggregate> featuresAggregate,
            Mock <IPathsAggregate> pathsAggregate,
            CreateFeatureCommand command)
        {
            await funk();

            featuresAggregate.Verify(_ => _.Publish(
                                         It.Is <FeatureCreatedEvent>(e => e.Name.Equals(
                                                                         command.Name,
                                                                         StringComparison.InvariantCultureIgnoreCase))),
                                     Times.Once);
            pathsAggregate.Verify(_ => _.Publish(
                                      It.Is <PathCreatedEvent>(e => e.Path.Equals(
                                                                   command.Path,
                                                                   StringComparison.InvariantCultureIgnoreCase))),
                                  Times.Once);
        }
Example #12
0
        public async Task ShouldUpdateFeature()
        {
            var createFeatureCommand = new CreateFeatureCommand("feature1", createProjectDto.Id);
            var createFeatureDto     = await SendAsync(createFeatureCommand);


            var updateFeatureCommand = new UpdateFeatureInfoCommand(createFeatureDto.Id, createProjectDto.Id, "update feature1", "description");

            await SendAsync(updateFeatureCommand);


            var featureEntity = await ExecuteDbContextAsync(db => db.Features
                                                            .SingleOrDefaultAsync(p => p.Id.Equals(createFeatureDto.Id))
                                                            );

            featureEntity.ShouldNotBeNull();
            featureEntity.Name.ShouldBe("update feature1");
            featureEntity.Description.ShouldBe("description");

            var deleteFeatureCommand = new DeleteFeatureCommand(createFeatureDto.Id, createProjectDto.Id);

            await SendAsync(deleteFeatureCommand);
        }
Example #13
0
 public void AddNewItem(CreateFeatureCommand command)
 {
     commandSender.Send(command);
 }
Example #14
0
 public static Func <PathCreatedEvent> WhenExtractingPathCreatedEvent(this CreateFeatureCommand command, ISystemClock clock)
 {
     return(() => command.ExtractPathCreatedEvent(clock));
 }
Example #15
0
        public static void ThenWeGetAPathCreatedEvent(this Func <PathCreatedEvent> pathFunc, CreateFeatureCommand command, ISystemClock clock)
        {
            var paths = pathFunc();

            paths.CreatedBy.Should().Be(command.CreatedBy);
            paths.CreatedOn.Should().Be(clock.UtcNow);
            paths.FeatureAdded.Should().Be(command.Name);
            paths.Path.Should().Be(command.Path);
        }
Example #16
0
        public static void ThenWeGetAFeatureCreatedEvent(this Func <FeatureCreatedEvent> featFunc, CreateFeatureCommand command, ISystemClock clock)
        {
            var feat = featFunc();

            feat.CreatedBy.Should().Be(command.CreatedBy);
            feat.CreatedOn.Should().Be(clock.UtcNow);
            feat.Name.Should().Be(command.Name);
            feat.Path.Should().Be(command.Path);
        }
 public async Task <ActionResult> AddAsync([FromBody] CreateFeatureCommand command)
 {
     return(Ok(await _mediator.Send(command)));
 }
Example #18
0
 public static Func <Task> WhenCreatingAFeature(
     this IHandleCommand <CreateFeatureCommand> handler,
     CreateFeatureCommand command)
 {
     return(() => handler.Handle(command));
 }
Example #19
0
 public static Action WhenValidating(this CreateFeatureCommand command)
 {
     return(() => command.Validate());
 }