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)); }
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); }
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)); } }
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(); }
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); }
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); }
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); }
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>(); }
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>(); }
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); }
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); }
public void AddNewItem(CreateFeatureCommand command) { commandSender.Send(command); }
public static Func <PathCreatedEvent> WhenExtractingPathCreatedEvent(this CreateFeatureCommand command, ISystemClock clock) { return(() => command.ExtractPathCreatedEvent(clock)); }
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); }
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))); }
public static Func <Task> WhenCreatingAFeature( this IHandleCommand <CreateFeatureCommand> handler, CreateFeatureCommand command) { return(() => handler.Handle(command)); }
public static Action WhenValidating(this CreateFeatureCommand command) { return(() => command.Validate()); }