Beispiel #1
0
        public async Task GetAllChallenge()
        {
            try
            {
                // Arrange
                ChallengeController controller = new ChallengeController();
                controller.Request = new HttpRequestMessage();
                controller.Request.Properties.Add(HttpPropertyKeys.HttpConfigurationKey, new HttpConfiguration());
                // Act
                ChallengeProvider _ChallengeProvider = new ChallengeProvider();
                var testProducts = await _ChallengeProvider.GetAll() as List <Challenge>;

                int testproduct = testProducts.Count;
                // Act
                var response = await controller.GetChallenges() as HttpResponseMessage;

                ObjectContent    objContent   = response.Content as ObjectContent;
                List <Challenge> picklistItem = objContent.Value as List <Challenge>;
                int icount = picklistItem.Count;

                var response1 = await controller.GetChallengesByCategoryClub(1, 5) as HttpResponseMessage;

                ObjectContent    objContent1   = response1.Content as ObjectContent;
                List <Challenge> picklistItem1 = objContent1.Value as List <Challenge>;


                // Assert
                Assert.IsNotNull(response);
                Assert.AreEqual(testproduct, icount);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Beispiel #2
0
        // GET: api/Challenge
        public async Task <HttpResponseMessage> GetChallenges()
        {
            try
            {
                var entity = await _ChallengeProvider.GetAll();

                if (entity != null)
                {
                    return(Request.CreateResponse(HttpStatusCode.OK, entity));
                }
                else
                {
                    return(Request.CreateErrorResponse(HttpStatusCode.NotFound, "Challenge not found"));
                }
            }
            catch (Exception ex)
            {
                return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ex));
            }
        }