public async Task <ActionResult> AddParticipant(int id, AddProjectParticipantCommand command) { if (id != command.ProjectId) { return(BadRequest()); } await Mediator.Send(command); return(NoContent()); }
public async Task ShouldRemoveProjectParticipant() { const string participantEmail = "participant@local"; var participantUserId = await RunAsUserAsync(participantEmail, "Testing1234!", new string[] { }); var participant = new Participant(participantUserId, "participant firstName", "participant lastName"); var ownerUserId = await RunAsUserAsync("owner@local", "Testing1234!", new string[] { }); var owner = new Participant(ownerUserId, "owner firstName", "owner lastName"); var entity = new Project(owner, "Project Name", "Key"); await AddAsync(entity); await AddAsync(participant); var command = new AddProjectParticipantCommand { ProjectId = entity.Id, ParticipantEmail = participantEmail }; var id = await SendAsync(command); await SendAsync(new RemoveProjectParticipantCommand { ProjectId = entity.Id, ParticipantEmail = participantEmail }); using var scope = _scopeFactory.CreateScope(); var context = scope.ServiceProvider.GetService <ApplicationDbContext>(); var project = await context.Projects.Include(x => x.Participants).SingleOrDefaultAsync(x => x.Id == entity.Id); project.Should().NotBeNull(); project.Participants.Should().NotBeEmpty().And.HaveCount(1); project.Participants.First().FirstName.Should().Be(owner.FirstName); project.Participants.First().LastName.Should().Be(owner.LastName); project.CreatedBy.Should().Be(ownerUserId); project.Created.Should().BeCloseTo(DateTime.Now, 10000); }
public void ShouldRequireMinimumFields() { var command = new AddProjectParticipantCommand(); FluentActions.Invoking(() => SendAsync(command)).Should().Throw <ValidationException>(); }