private void ValidatePollResponseAddRequest(PollResponseAddRequest req, int position) { var entryText = req.ResponseText; var prefix = $"Error in entry at position {position + 1}: "; if (string.IsNullOrWhiteSpace(entryText)) { throw new BadRequestException(prefix + "entryText cannot be missing or whitespace."); } if (entryText.Length > TimeLogEntry.MaxEntryTextLength) { throw new BadRequestException(prefix + $"entryText cannot be longer than {TimeLogEntry.MaxEntryTextLength} characters."); } var timeZone = req.TimeZone; if (timeZone != null && timeZone.Length > TimeLogEntry.MaxTimeZoneLength) { throw new BadRequestException(prefix + $"timeZone cannot be longer than {TimeLogEntry.MaxTimeZoneLength} characters."); } var timeBlockLength = req.TimeBlockLength; if (timeBlockLength.TotalMilliseconds <= 0) { throw new BadRequestException(prefix + $"timeBlockLength must be positive; was: {timeBlockLength}."); } if (timeBlockLength > MaxAllowedTimeBlockLength) { throw new BadRequestException(prefix + $"timeBlockLength cannot be longer than {MaxAllowedTimeBlockLength.TotalDays} days. " + $"Was: {timeBlockLength}"); } }
public async Task <IActionResult> Post([FromBody] PollResponseAddRequest msg) { var poll = await GetDefaultPollAsync(); await _timeLogService.Add(Db, poll.Id, new[] { msg }); return(NoContent()); }
public async void Should_set_all_message_fields_in_DB() { var msg = new PollResponseAddRequest { ResponseText = "1", TimeBlockLength = TimeSpan.FromMinutes(10), TimeCollected = TestFromTime, TimeZone = "ABC", TimeZoneOffset = TimeSpan.FromHours(-2), SubmissionType = "something" }; // Act await _service.Add(Db, _poll.Id, new[] { msg }); // Assert Db.WasSaveChangesCalled.Should().BeTrue(); var addedEntries = Db.Mock.TimeLogEntries.Added; var entry = addedEntries.First(e => e.EntryText == "1"); entry.Id.Should().NotBe(default);