예제 #1
0
        public async void can_crud_form()
        {
            List <string> tags = new List <string>()
            {
                "Unit", "Test"
            };
            // Need to use Today instead of Now so the time is a whole number of seconds,
            // otherwise js rounds seconds and C# does not, resulting in different times
            DateTime startDate = DateTime.Today.AddDays(5);
            DateTime endDate   = DateTime.Today.AddDays(10);
            Form     newForm   = new Form();

            newForm.name                  = "Unit test";
            newForm.description           = "Created via unit test";
            newForm.organisationId        = organisationId;
            newForm.isAuthenticated       = false;
            newForm.isMultiPage           = false;
            newForm.formsAppEnvironmentId = formsAppEnvironmentId;
            newForm.postSubmissionAction  = "FORMS_LIBRARY";
            newForm.tags                  = tags;
            newForm.publishStartDate      = startDate;
            newForm.publishEndDate        = endDate;

            List <long> formsAppIds = new List <long>();

            formsAppIds.Add(formsAppId);
            newForm.formsAppIds = formsAppIds;

            FormElement textElement = FormElement.CreateTextElement(
                "Unit_test_element",
                "Unit test element",
                Guid.NewGuid(),
                false,
                false,
                null,
                true,
                false,
                "default",
                "placeholder value",
                minLength: 2,
                maxLength: 10
                );

            FormElement summaryElement = FormElement.CreateSummaryElement(
                "Summary_test_element",
                "Summary test element",
                new List <Guid>()
            {
                textElement.id
            },
                Guid.NewGuid(),
                false,
                false,
                null
                );

            FormElement geoscapeElement = FormElement.CreateGeoscapeAddressElement(
                "geoscapeElement",
                "Geoscape Element",
                Guid.NewGuid(),
                false,
                false,
                null,
                true,
                false,
                "default",
                "placeholder value",
                "hint value"
                );
            FormElementOption option = new FormElementOption();

            option.id    = Guid.NewGuid();
            option.value = "A";
            option.label = "A";
            FormElement complianceElement = FormElement.CreateComplianceElement(
                "Compliance_test_element",
                "Compliance_test_element",
                new List <FormElementOption>()
            {
                option
            }
                );

            newForm.elements = new List <FormElement>()
            {
                textElement, summaryElement, geoscapeElement, complianceElement
            };

            FormsClient formsClient = new FormsClient(ACCESS_KEY, SECRET_KEY, TenantName.ONEBLINK_TEST);
            Form        savedForm   = await formsClient.Create(newForm);

            Assert.NotNull(savedForm);
            Form retrievedForm = await formsClient.Get(savedForm.id, true);

            Assert.NotNull(retrievedForm);
            Assert.Equal(tags, retrievedForm.tags);
            // Need to convert these to UTC time as that is what comes from api, and these dates are in local time
            Assert.Equal(startDate.ToUniversalTime(), retrievedForm.publishStartDate);
            Assert.Equal(endDate.ToUniversalTime(), retrievedForm.publishEndDate);
            String updatedDescription = "Updated via unit test";

            retrievedForm.description = updatedDescription;
            Form updatedForm = await formsClient.Update(retrievedForm);

            Assert.Equal(updatedDescription, updatedForm.description);
            await formsClient.Delete(updatedForm.id);

            try
            {
                Form deletedForm = await formsClient.Get(updatedForm.id, true);

                throw new Exception("Form was able to be retrieved after being deleted!");
            }
            catch (OneBlink.SDK.OneBlinkAPIException ex)
            {
                Assert.Equal("Form not found", ex.Message);
            }
        }