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);
        }
        public IHttpActionResult EditAnnouncement(int id, [FromBody] AnnouncementFormData data)
        {
            if (!user_service.IsAuthorizedToEditAnnouncements(id))
            {
                return(Unauthorized());
            }

            // for preflight requests
            if (RequestUtility.IsPreFlightRequest(Request))
            {
                return(Ok());
            }

            var result = data.Validate();

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

            announcement_repository.UpdateAnnouncement(id, data);
            return(Ok());
        }
        public IHttpActionResult Create([FromBody] AnnouncementFormData data)
        {
            if (!user_service.IsAuthorizedToCreateAnnouncements())
            {
                return(Unauthorized());
            }

            // for preflight requests
            if (RequestUtility.IsPreFlightRequest(Request))
            {
                return(Ok());
            }

            var result = data.Validate();

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

            var announcement = announcement_repository.createAnnouncement(data);

            return(Ok(new AnnouncementsResponseData(announcement)));
        }