public void Close_Competition_Returns_OK()
        {
            // Arrange
            var competition = new PostCompetition()
            {
                Answers = new[] { "Man Utd", "Man City", "Chelsea", "Arsenal" },
                ClosingDate = DateTime.Now.AddMonths(-1),
                CompetitionKey = RandomGenerator.GetRandomString(10),
                CorrectAnswerKey = 1,
                Question = "Who won the 2012 Premier League?"
            };

            Assert.AreEqual(
                HttpStatusCode.Created,
                Client.PostAsJsonAsync(Resources.Competitions, competition).Result.StatusCode,
                "POSTCompetition not OK.");

            // Act
            var response =
                Client.PutAsJsonAsync(
                    string.Format("{0}/{1}", Resources.CloseCompetition, competition.CompetitionKey.ToLower()), new { })
                      .Result;

            // Assert
            Assert.AreEqual(HttpStatusCode.OK, response.StatusCode, "PUT CloseCompetition not OK.");
        }
        /// <summary>
        /// The post.
        /// </summary>
        /// <returns>
        /// The <see cref="GetCompetition"/>.
        /// </returns>
        private GetCompetition Post()
        {
            // Arrange
            var competition = new PostCompetition()
                {
                    Answers = new[] {"A", "B", "C", "D"}, 
                    ClosingDate = DateTime.Now.AddMonths(1), 
                    CompetitionKey = RandomGenerator.GetRandomString(10), 
                    CorrectAnswerKey = 1, 
                    Question = "Test Question"
                };

            // Act
            var response = Client.PostAsJsonAsync(Resources.Competitions, competition).Result;

            // Assert
            Assert.AreEqual(HttpStatusCode.Created, response.StatusCode, "POST competition not ok.");

            return response.Content.ReadAsAsync<GetCompetition>().Result;
        }
        public void Enter_Competition_Returns_OK_Status()
        {
            // #1 Create Competition
            var competition = new PostCompetition()
                {
                    Answers = new[] { "Man Utd", "Man City", "Chelsea", "Arsenal" }, 
                    ClosingDate = DateTime.Now.AddMonths(1), 
                    CompetitionKey = RandomGenerator.GetRandomString(10), 
                    CorrectAnswerKey = 1, 
                    Question = "Who won the 2012 Premier League?"
                };

            Assert.AreEqual(
                HttpStatusCode.Created, 
                Client.PostAsJsonAsync(Resources.Competitions, competition).Result.StatusCode, 
                "POSTCompetition not OK.");

            // #2 Enter Competition
            var enterCompetition = new PostEnterCompetition()
                {
                    CompetitionKey = competition.CompetitionKey, 
                    ContactType = "Sms", 
                    Answer = "A", 
                    Contact = "00000111222", 
                    Source = "Sms"
                };

            Assert.AreEqual(
                HttpStatusCode.Created, 
                Client.PostAsJsonAsync(Resources.EnterCompetition, enterCompetition).Result.StatusCode, 
                "POST EnterCompetition not OK.");

            // #3 Close Competition
            var response = Client.PutAsJsonAsync(string.Format("{0}/{1}", Resources.CloseCompetition, competition.CompetitionKey.ToLower()), new { }).Result;

            Assert.AreEqual(HttpStatusCode.OK, response.StatusCode, "PUT CloseCompetition not OK.");
        }
        /// <summary>
        /// Create a new competition.
        /// </summary>
        /// <param name="item">
        /// The item.
        /// </param>
        /// <returns>
        /// The <see cref="HttpResponseMessage"/>.
        /// </returns>
        /// <remarks>
        /// POST competition
        /// </remarks>
        public HttpResponseMessage Post(PostCompetition item)
        {
            var competition = new Competition()
            {
                Question = item.Question,
                ClosingDate = item.ClosingDate,
                CompetitionKey = item.CompetitionKey,
                CreatedBy = _userDataMapper.FindByAuthToken(RequestToken)
            };

            SetAnswers(item.Answers, item.CorrectAnswerKey, competition);

            if (competition.IsValid)
            {
                _competitionDataMapper.Insert(competition);

                var createdItem = _mapper.Map<Competition, GetCompetition>(competition);
                return CreatedHttpResponse(createdItem.Id, createdItem);
            }

            return Request.CreateResponse(HttpStatusCode.BadRequest, competition.ValidationErrors);
        }