public HttpResponseMessage Save(string endpoint, DateTime timestamp, MatchInfo results) { try { serverService.Get(endpoint); Match match = new Match(endpoint, timestamp, results); matchService.Save(match); statisticController.RecalculateStatsByAdditionalMatch(match); return(new HttpResponseMessage(HttpStatusCode.OK)); } catch (NullReferenceException ex) { var response = new HttpResponseMessage(HttpStatusCode.BadRequest); if (Request != null) { response.RequestMessage = Request; } response.Content = new StringContent(ex.Message); throw new HttpResponseException(response); } catch (ArgumentException ex) { var response = new HttpResponseMessage(HttpStatusCode.BadRequest); if (Request != null) { response.RequestMessage = Request; } response.Content = new StringContent(ex.Message); throw new HttpResponseException(response); } }
public void PutMatchInRepository_WhenCorrectData() { var endpointString = "192.168.0.1-80"; var timestamp = new DateTime(2017, 01, 01); var matchInfo = new MatchInfo("TestMapA", "TestModeA", 20, 20, 12.345, new List <Score> { new Score("PlayerA", 20, 3, 1), new Score("PlayerB", 3, 1, 3) }); var match = new Match(endpointString, timestamp, matchInfo); _controller.Save(endpointString, timestamp, matchInfo); A.CallTo(() => _matchRepository.Save(match)).MustHaveHappened(); A.CallTo(() => _statisticController.RecalculateStatsByAdditionalMatch(match)).MustHaveHappened(); }