Esempio n. 1
0
        public async void CreateFormShouldCreateNewEntityAndReturnCreated()
        {
            var allForms = await _fixture.GetHttpResult(UrlPath);

            var currentNumberOfForms =
                JsonConvert.DeserializeObject <List <FormListDto> >(allForms.Content.ReadAsStringAsync().Result).Count;

            _styles.Add(DataSeeder.StyleId1);
            _validations.Add(DataSeeder.ValidationId1);

            _fields.Append(new FieldCreateDto()
            {
                Name          = "TestField",
                ContentType   = "string",
                Label         = "label",
                Placeholder   = "placeholder",
                Value         = "value",
                Required      = true,
                OptionsJson   = "{\"id\":42 , \"name\":\"Rolando\"}",
                FieldType     = DataSeeder.FieldTypeId1,
                StyleIds      = _styles,
                ValidationIds = _validations
            });

            _fields.Append(new FieldCreateDto()
            {
                Name          = "FieldTest",
                ContentType   = "integer",
                Label         = "bezeichnung",
                Placeholder   = "platz",
                Value         = "Wert",
                Required      = false,
                OptionsJson   = "{\"id\":69 , \"name\":\"Messi\"}",
                FieldType     = DataSeeder.FieldTypeId1,
                ValidationIds = _validations
            });

            var newForm = new FormCreateDto()
            {
                Title            = "NewTest Form",
                IsPublic         = true,
                RestrictedAccess = false,
                FormHasField     = _fields
            };

            var serializedForm = JsonConvert.SerializeObject(newForm);

            var result = await _fixture.PostHttpResult(UrlPath, serializedForm);

            result.Should().NotBeNull();
            result.StatusCode.Should().Be(HttpStatusCode.Created);


            allForms = await _fixture.GetHttpResult(UrlPath);

            var newNumberOfForms = JsonConvert.DeserializeObject <List <FormListDto> >(allForms.Content.ReadAsStringAsync().Result).Count;

            newNumberOfForms.Should().Be(currentNumberOfForms + 1);
        }
Esempio n. 2
0
        public virtual IActionResult UpdateFormById([FromRoute] Guid formId,
                                                    [FromBody] FormCreateDto formCreateDto)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest());
            }

            return(_formRepository.UpdateFormById(formId, formCreateDto));
        }
Esempio n. 3
0
 public static Form ToModel(this FormCreateDto response)
 {
     return(new Form()
     {
         Id = Guid.NewGuid(),
         Title = response.Title,
         Created = DateTime.UtcNow,
         Deprecated = false,
         IsPublic = response.IsPublic,
         RestrictedAccess = response.RestrictedAccess
     });
 }
Esempio n. 4
0
        // updates a specific form
        // sets the old form to deprecated
        // the new form references the old one
        // returns the updated form as a DTO
        public IActionResult UpdateFormById(Guid formId, FormCreateDto formCreateDto)
        {
            // Set updated Form Deprecated true
            var formToUpdate = _applicationDbContext.Form.SingleOrDefault(form => form.Id == formId);

            formToUpdate.Deprecated = true;

            Save();

            // Create new Form.
            var newForm = CreateNewForm(formCreateDto, formToUpdate.Id);

            return(new OkObjectResult(newForm));
        }
Esempio n. 5
0
        public virtual IActionResult AddForm([FromBody] FormCreateDto form)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var newForm = _formRepository.CreateNewForm(form, null);

            _formRepository.Save();

            var location = "/forms/" + newForm.Id;

            return(Created(location, newForm));
        }
Esempio n. 6
0
        // creates a new form and returns the created object as a DTO
        public FormDetailDto CreateNewForm(FormCreateDto formToCreate, Guid?previousVerison)
        {
            var fieldIndex = 1;
            var newForm    = formToCreate.ToModel();

            if (previousVerison != null)
            {
                newForm.PreviousVersion = previousVerison;
            }
            _applicationDbContext.Form.Add(newForm);

            Save();
            foreach (var field in formToCreate.FormHasField)
            {
                CreateNewField(newForm.Id, field, fieldIndex);
                fieldIndex++;
            }
            return(GetFormById(newForm.Id));
        }
Esempio n. 7
0
        public async void CreateNewFormWithInvalidModelStateShouldReturnBadRequest()
        {
            _fields.Append(new FieldCreateDto()
            {
                Name        = "TestField",
                OptionsJson = "{\"id\":42 , \"name\":\"Rolando\"}",
                FieldType   = DataSeeder.FieldTypeId1,
            });

            var newForm = new FormCreateDto()
            {
                IsPublic         = true,
                RestrictedAccess = false,
                FormHasField     = _fields
            };

            var serializedForm = JsonConvert.SerializeObject(newForm);
            var result         = await _fixture.PostHttpResult(UrlPath, serializedForm);

            result.Should().NotBeNull();
            result.StatusCode.Should().Be(HttpStatusCode.BadRequest);
        }