Ejemplo n.º 1
0
        public void AnnounementFormDataValidation_IsInvalid_ForInvalidData()
        {
            var data = new AnnouncementFormData()
            {
                Title       = "",
                Description = null
            };

            FormDataValidationResult result = data.Validate();

            // data should be considered invalid
            Assert.False(result.IsValid);

            // two error messages should be set
            Assert.Equal(2, result.ErrorMessages.Count);
        }
Ejemplo n.º 2
0
        public void AnnounementFormDataValidation_IsValid_ForValidData()
        {
            var data = new AnnouncementFormData()
            {
                Title       = "Hello there",
                Description = "Testing 1 2 3"
            };


            FormDataValidationResult result = data.Validate();

            // data should be considered valid
            Assert.True(result.IsValid);

            // no error message should be set
            Assert.Empty(result.ErrorMessages);
        }
Ejemplo n.º 3
0
        public async Task <IHttpActionResult> UpdateProblem(int id)
        {
            if (!user_service.IsAuthorizedToEditProblem(id))
            {
                return(Unauthorized());
            }

            // request contain must be of type multipart/form-data.
            if (!Request.Content.IsMimeMultipartContent())
            {
                throw new HttpResponseException(HttpStatusCode.UnsupportedMediaType);
            }

            string root     = HttpContext.Current.Server.MapPath("~/App_Data");
            var    provider = new MultipartFormDataStreamProvider(root);

            try{
                // Read the form data.
                await Request.Content.ReadAsMultipartAsync(provider);
            }
            catch (Exception e) {
                return(InternalServerError(e));
            }

            var problem_form = new ProblemCreationForm(provider.FormData, provider.FileData);

            FormDataValidationResult result = problem_form.Validate();

            if (!result.IsValid)
            {
                return(new BadHttpRequest(result.ErrorMessages));
            }

            try{
                problem_repository.UpdateProblem(id, problem_form);
            }
            catch (ObjectNotFoundException e) {
                return(InternalServerError(e));
            }
            return(Ok());
        }