Beispiel #1
0
        public async Task GetClubById()
        {
            try
            {
                // Arrange
                ClubController controller = new ClubController();
                controller.Request = new HttpRequestMessage();
                controller.Request.Properties.Add(HttpPropertyKeys.HttpConfigurationKey, new HttpConfiguration());
                // Act
                ClubProvider _ClubProvider = new ClubProvider();
                var          testClub      = await _ClubProvider.GetById(1) as Club;

                // Act
                var response = await controller.GetClub(1) as HttpResponseMessage;

                ObjectContent objContent = response.Content as ObjectContent;
                var           pickClub   = objContent.Value as Club;
                // Assert
                Assert.IsNotNull(response);
                Assert.AreEqual(testClub, pickClub);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        // GET: api/Club/5
        public async Task <HttpResponseMessage> GetClub(int id)
        {
            try
            {
                var entity = await _ClubProvider.GetById(id);

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