Exemplo n.º 1
0
        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}");
            }
        }
Exemplo n.º 2
0
        public async Task <IActionResult> Post([FromBody] PollResponseAddRequest msg)
        {
            var poll = await GetDefaultPollAsync();

            await _timeLogService.Add(Db, poll.Id, new[] { msg });

            return(NoContent());
        }
Exemplo n.º 3
0
        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);