Example #1
0
        public void GetRelativeRanking()
        {
            var gameBusiness = new GameBusiness();

            var result = gameBusiness.GetRelativeRanking(10, 2);

            Assert.IsNotNull(result);

            Assert.IsNotNull(result.Count == 5);

            Assert.IsNotNull(result.First().Position == 7 &&
                             result.Last().Position == 12);

            Assert.IsNotNull(result.First().Position < result.Last().Position &&
                             result.First().Score >= result.Last().Score);

            result = gameBusiness.GetRelativeRanking(100, 10);

            Assert.IsNotNull(result.Count == 21);

            Assert.IsNotNull(result.First().Position == 89 &&
                             result.Last().Position == 111);

            Assert.IsNotNull(result.First().Position < result.Last().Position &&
                             result.First().Score >= result.Last().Score);
        }
Example #2
0
        public HttpResponseMessage GetRelativeRanking(int atNumber, int quantity)
        {
            HttpResponseMessage response = Request.CreateResponse(HttpStatusCode.InternalServerError);

            try
            {
                GameBusiness gameBusiness = new GameBusiness();

                var result = gameBusiness.GetRelativeRanking(atNumber, quantity);

                if (result != null)
                {
                    response = Request.CreateResponse(HttpStatusCode.OK, result);
                }
                else
                {
                    response = Request.CreateResponse(HttpStatusCode.NotFound, "Not ranking found");
                }
            }
            catch (Exception e)
            {
                Logger.Error("GameController", "Get", e.Message);
                response = Request.CreateResponse(HttpStatusCode.InternalServerError, "Unexpected error");
            }

            return response;
        }