Exemplo n.º 1
0
        public async void can_generate_form_url()
        {
            FormUrlOptions preFill = new FormUrlOptions(
                formId: 475
                );
            FormsClient   formsClient = new FormsClient(ACCESS_KEY, SECRET_KEY, TenantName.ONEBLINK_TEST);
            FormUrlResult result      = await formsClient.GenerateFormUrl(
                new FormUrlOptions(
                    formId : 475,
                    username : "******",
                    secret : "secret",
                    preFillData : preFill,
                    externalId : "myExternalId"

                    )
                );

            Assert.Contains("?access_key=", result.formUrl);
            Assert.Contains("&externalId=myExternalId", result.formUrl);
            Assert.Contains("&userToken=", result.formUrl);
            Assert.Contains("&preFillFormDataId=", result.formUrl);
            Assert.NotNull(result.expiry);
        }
Exemplo n.º 2
0
        public async void can_create_with_defaults()
        {
            Form newForm = new Form(
                "name",
                "description",
                organisationId,
                formsAppEnvironmentId
                );
            FormsClient formsClient = new FormsClient(ACCESS_KEY, SECRET_KEY, TenantName.ONEBLINK_TEST);
            Form        savedForm   = await formsClient.Create(newForm);

            savedForm.elements = new List <FormElement>()
            {
                FormElement.CreateTextElement(
                    label: "Text",
                    name: "Text"
                    ),
                FormElement.CreateTextElement(
                    label: "Text2",
                    name: "Text2"
                    )
            };
            Form updatedForm = await formsClient.Update(savedForm);
        }
Exemplo n.º 3
0
        public void can_be_constructed()
        {
            FormsClient forms = new FormsClient(ACCESS_KEY, SECRET_KEY);

            Assert.NotNull(forms);
        }
Exemplo n.º 4
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);
            }
        }