Example #1
0
        /// <summary>
        /// The put.
        /// </summary>
        /// <param name="competition">
        /// The competition.
        /// </param>
        private void Put(GetCompetition competition)
        {
            // Arrange
            var putCompetition = new PutCompetition()
            {
                Answers          = new[] { "A", "B", "C", "D" },
                ClosingDate      = DateTime.Now.AddMonths(1),
                CorrectAnswerKey = 1,
                Question         = "Test Question"
            };

            // Act
            var response = Client.PutAsJsonAsync(GetUrRequestUri(competition), putCompetition).Result;

            // Assert
            Assert.AreEqual(HttpStatusCode.OK, response.StatusCode, "PUT Competition not OK.");
            Assert.AreEqual(putCompetition.Question, Get(competition).Question, "PUT Competition not updated.");
        }
        /// <summary>
        /// Update an existing competition.
        /// </summary>
        /// <param name="id">
        /// The id.
        /// </param>
        /// <param name="item">
        /// The item.
        /// </param>
        /// <returns>
        /// The <see cref="HttpResponseMessage"/>.
        /// </returns>
        /// <exception cref="NotFoundException">
        /// Raised when id is invalid.
        /// </exception>
        /// <remarks>
        /// PUT competition/B5608F8E-F449-E211-BB40-1040F3A7A3B1
        /// </remarks>
        public HttpResponseMessage Put(Guid id, PutCompetition item)
        {
            var competition = _competitionDataMapper.FindById(id);

            if (competition == null)
            {
                throw new NotFoundException();
            }

            competition.ClosingDate = item.ClosingDate;
            competition.Question    = item.Question;

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

            if (competition.IsValid)
            {
                _competitionDataMapper.Update(competition);
                return(Request.CreateResponse(HttpStatusCode.OK));
            }

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