Exemplo n.º 1
0
        public JsonResult AddLapResultAsString([FromBody] RequestObject.LapResult lapResult)
        {
            _logger.LogInformation("POST /AddLapResultAsString \n\tBODY: ipAddress:" + lapResult.ipAddress + " | lapTime: " + lapResult.lapTime);

            try
            {
                IPAddress ipAddress = IPAddress.Parse(lapResult.ipAddress);
                TimeSpan  lapTime   = TimeSpan.Parse(lapResult.lapTime, CultureInfo.InvariantCulture);
                _raceManager.AddLapResult(ipAddress, lapTime);
                return(Json(new ResponseObject {
                    responseMessage = "success"
                }));
            }
            catch (Exception error)
            {
                _logger.LogError("RaceTimer/AddLapResult Exception: " + error.Message);

                if (error is KeyNotFoundException)
                {
                    return(Json(new ResponseObject
                    {
                        responseMessage = "The given IP address '" + lapResult.ipAddress + "' is not registered."
                    }));
                }

                ResponseObject response = new ResponseObject
                {
                    responseMessage = error.Message,
                };

                return(new JsonResult(response)
                {
                    StatusCode = (int)HttpStatusCode.BadRequest
                });
            }
        }
Exemplo n.º 2
0
 public void AddLapResult_NotRegistered_ThrowsException()
 {
     Assert.Throws <KeyNotFoundException>(() => _raceManager.AddLapResult(IPAddress.Parse("1.1.1.1"), new TimeSpan()));
 }