public async Task <IActionResult> AddVote([FromRoute] long id, [FromBody] AddVoteDto addVoteDto) { // TODO Add validation that the dates are in valid format var eventModified = await Events.AddVotesAsync(addVoteDto.ToEventEntity(id)).ConfigureAwait(false); return(Ok(eventModified.ToEventShowDto())); }
public async Task AddVotes_Event_ReturnsCorrectResult() { const string nameToBeTestedWith = "TEST_NAME"; const string dateToBeTestedWith = "2010-01-01"; const string personVotingToBeTestedWith = "TEST_PERSON"; await WithTestDatabase.Run(async context => { var repository = new EventRepository(context); var entityToBeAdded = new EventEntity { Name = nameToBeTestedWith, DateEntities = new List <DateEntity> { new DateEntity { Date = dateToBeTestedWith } } }; var addedId = await repository.CreateEventAsync(entityToBeAdded); var addedEntity = await repository.GetAsync(addedId); Assert.Empty(DomainLogic.GetAllEventParticipants(addedEntity)); var votes = new AddVoteDto { Name = personVotingToBeTestedWith, Votes = new List <string> { dateToBeTestedWith } }; var modifiedEvent = await repository.AddVotesAsync(votes.ToEventEntity(addedId)); Assert.Single(DomainLogic.GetAllEventParticipants(modifiedEvent)); var suitableDates = DomainLogic.CalculateSuitableDatesForEvent(modifiedEvent.DateEntities, DomainLogic.GetAllEventParticipants(modifiedEvent)); Assert.Single(suitableDates); Assert.Equal(suitableDates.Select(s => s.Date).Single(), dateToBeTestedWith); }); }