public async Task <IActionResult> Post(CreateAdvert command) { if (!ModelState.IsValid) { return(BadRequest(command)); } return(await SendAsync(command.BindId(c => c.Id).Bind(c => c.UserId, UserId), resourceId : command.Id, resource : "adverts")); }
public async Task Create_Advert_Command_Should_Create_Entity() { var user = new User(Guid.NewGuid(), "*****@*****.**"); await _dbFixture.InsertAsync(user); var category = new Category(Guid.NewGuid(), user.Id); await _dbFixture.InsertAsync(category); string advertDescription = "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vestibulum bibendum purus et libero vulputate elementum."; var command = new CreateAdvert(Guid.NewGuid(), "Test title", advertDescription, user.Id, category.Id, null); var creationTask = await _rabbitMqFixture.SubscribeAndGetAsync <AdvertCreated, Advert>(_dbFixture.GetEntityTask, command.Id); await _rabbitMqFixture.PublishAsync(command); var createdEntity = await creationTask.Task; createdEntity.ShouldNotBeNull(); createdEntity.Id.ShouldBe(command.Id); createdEntity.Title.ShouldBe(command.Title); createdEntity.Description.ShouldBe(command.Description); createdEntity.Image.ShouldBe(command.Image); createdEntity.Creator.ShouldBe(user.Id); createdEntity.Category.ShouldBe(category.Id); }
public async Task <ActionResult> Post(CreateAdvert command) { await _dispatcher.SendAsync(command.BindId(c => c.Id)); return(Accepted()); }