/// <summary> /// Initializes a new instance of the <see cref="CommandMapper"/> class. /// </summary> /// <param name="createSpaceCommand">The command to create a space.</param> /// <param name="listSpacesCommand">The command to list all spaces.</param> /// <param name="createPageCommand">The command to create a page.</param> public CommandMapper( CreateSpaceCommand createSpaceCommand, ListSpacesCommand listSpacesCommand, CreatePageCommand createPageCommand) { #region Spaces Commands Command createSpace = new Command("create-space") { new Argument <SpaceName>("name"), }; createSpace.Description = "Creates a new space."; createSpace.Handler = CommandHandler.Create <SpaceName>(createSpaceCommand.CreateSpace); Command listSpaces = new Command("list-spaces"); listSpaces.Description = "Shows a list of all currently existing spaces."; listSpaces.Handler = CommandHandler.Create(listSpacesCommand.ListSpaces); #endregion #region Pages Command Command createPage = new Command("create-page") { new Argument <SpaceName>("space") { Description = "parent space for the new page", }, new Argument <PageName>("page") { Description = "page name", }, new Argument <FileInfo>("file") { Description = "file to read the content from", }, }; createPage.Description = "Creates a new page within a space."; createPage.Handler = CommandHandler.Create <SpaceName, PageName, FileInfo>(createPageCommand.CreatePage); #endregion _rootCommand = new RootCommand() { // spaces createSpace, listSpaces, // pages createPage, }; }
public async Task CreateSpace_IsSuccessful() { var request = new CreateSpaceCommand { Name = "Family 2", BackgroundImage = "https://img.microsoft.com", Visibility = Visibility.Private }; var spaceId = await _fixture.Mediator.Send(request); var space = await _spaceQuery.GetSpaceAsync(spaceId); Assert.Equal(request.Name, space.Name); Assert.Equal(request.BackgroundImage, space.BackgroundImage); Assert.Equal(request.Visibility, space.Visibility); }
public async Task <Guid> GetOrCreateDefaultSpaceAsync() { var command = new CreateSpaceCommand { Name = "Default", BackgroundImage = "https://img.microsoft.com", Visibility = Visibility.Public }; var space = await GetService <IReadModelRepository>().Query <SpaceDetail>() .FirstOrDefaultAsync(s => s.Name == command.Name); if (space != null) { return(space.Id); } return(await GetService <IMediator>().Send(command)); }
public async Task <IActionResult> CreateAsync([FromBody] CreateSpaceCommand request) { return(Ok(await _mediator.Send(request))); }