public void NonWriteableLikertRevertToDefault()
        {
            const string formId = "19";
            const string userId = "008";
            ControlList controls = this.GetControlList(formId);
            List<ControlAccess> controlsAccess = this.GetControlAccess(formId, userId);

            ApplicationData appData = new ApplicationData();
            appData["likert-field"] = new Dictionary<string, string> { { "Question_one", "foo bar" } };

            ApplicationDataVerifier verifier = new ApplicationDataVerifier(controls, controlsAccess);
            appData = verifier.VerifyApplicationData(appData, null);

            Dictionary<string, string> verifiedLikert = appData["likert-field"] as Dictionary<string, string>;
            Assert.AreEqual(string.Empty, verifiedLikert["Question_one"]);
        }
        public void SaveEmptyExistingRepeater()
        {
            const string formId = "11";
            const string userId = "007";
            ControlList controls = this.GetControlList(formId);
            List<ControlAccess> controlsAccess = this.GetControlAccess(formId, userId);

            ApplicationData appData = new ApplicationData();
            appData["read-repeater"] = new object[0];

            ApplicationData previousAppData = new ApplicationData();
            previousAppData["read-repeater"] = new object[0];

            ApplicationDataVerifier verifier = new ApplicationDataVerifier(controls, controlsAccess);
            verifier.VerifyApplicationData(appData, previousAppData);
        }
        public void SaveNonExistantField()
        {
            const string formId = "10";
            const string userId = "007";
            ControlList controls = this.GetControlList(formId);
            List<ControlAccess> controlsAccess = this.GetControlAccess(formId, userId);

            ApplicationData input = new ApplicationData();
            input["bad-field"] = "my legal value";

            ApplicationDataVerifier verifier = new ApplicationDataVerifier(controls, controlsAccess);
            ApplicationData output = verifier.VerifyApplicationData(input, null);

            Assert.IsTrue(input.ContainsKey("bad-field"));
            Assert.IsNotNull(input.GetValue<string>("bad-field"));

            Assert.IsFalse(output.ContainsKey("bad-field"));
        }
        public void SaveWriteableRepeaterChild()
        {
            const string formId = "11";
            const string userId = "007";
            ControlList controls = this.GetControlList(formId);
            List<ControlAccess> controlsAccess = this.GetControlAccess(formId, userId);

            ApplicationData appData = new ApplicationData();
            Dictionary<string, object>[] repeater = new Dictionary<string, object>[1];
            appData["write-repeater"] = repeater;
            repeater[0] = new Dictionary<string, object>();
            repeater[0]["write-field"] = "this field is writeable!";

            ApplicationDataVerifier verifier = new ApplicationDataVerifier(controls, controlsAccess);
            appData = verifier.VerifyApplicationData(appData, null);
            Assert.AreEqual("this field is writeable!", appData.GetValue<string>("write-repeater[0].write-field"));
        }
        public void SaveWriteableFieldDoesNotRevert()
        {
            const string formId = "10";
            const string userId = "007";
            ControlList controls = this.GetControlList(formId);
            List<ControlAccess> controlsAccess = this.GetControlAccess(formId, userId);

            ApplicationData appData = new ApplicationData();
            appData["write-field"] = "my new legal value";

            ApplicationData previousAppData = new ApplicationData();
            previousAppData["write-field"] = "my old legal value";

            ApplicationDataVerifier verifier = new ApplicationDataVerifier(controls, controlsAccess);
            appData = verifier.VerifyApplicationData(appData, previousAppData);
            Assert.AreEqual("my new legal value", appData["write-field"]);
        }
        public void SaveReadOnlyRepeaterRevertRowToPrevious()
        {
            const string formId = "11";
            const string userId = "007";
            ControlList controls = this.GetControlList(formId);
            List<ControlAccess> controlsAccess = this.GetControlAccess(formId, userId);

            ApplicationData appData = new ApplicationData();
            Dictionary<string, object>[] repeater = new Dictionary<string, object>[1];
            appData["read-repeater"] = repeater;
            repeater[0] = new Dictionary<string, object>();
            repeater[0]["write-field-2"] = "this row has been updated";

            ApplicationData previousAppData = new ApplicationData();
            Dictionary<string, object>[] previousRepeater = new Dictionary<string, object>[1];
            previousAppData["read-repeater"] = previousRepeater;
            previousRepeater[0] = new Dictionary<string, object>();
            previousRepeater[0]["write-field-2"] = "this row can not be updated";

            ApplicationDataVerifier verifier = new ApplicationDataVerifier(controls, controlsAccess);
            appData = verifier.VerifyApplicationData(appData, previousAppData);
            Assert.AreEqual("this row can not be updated", appData.GetValue<string>("read-repeater[0].write-field-2"));
        }
        public void SaveReadOnlyRepeaterRevertRowToEmpty()
        {
            const string formId = "11";
            const string userId = "007";
            ControlList controls = this.GetControlList(formId);
            List<ControlAccess> controlsAccess = this.GetControlAccess(formId, userId);

            ApplicationData appData = new ApplicationData();
            Dictionary<string, object>[] repeater = new Dictionary<string, object>[1];
            appData["read-repeater"] = repeater;
            repeater[0] = new Dictionary<string, object>();
            repeater[0]["write-field-2"] = "this row has been added";

            ApplicationDataVerifier verifier = new ApplicationDataVerifier(controls, controlsAccess);
            appData = verifier.VerifyApplicationData(appData, null);
            Assert.AreEqual(0, appData.GetValue<Dictionary<string, object>[]>("read-repeater").Length);
        }
        public void SaveReadOnlyRepeaterRemoveRow()
        {
            const string formId = "11";
            const string userId = "007";
            ControlList controls = this.GetControlList(formId);
            List<ControlAccess> controlsAccess = this.GetControlAccess(formId, userId);

            ApplicationData appData = new ApplicationData();
            appData["read-repeater"] = new Dictionary<string, object>[0];

            ApplicationData previousAppData = new ApplicationData();
            Dictionary<string, object>[] previousRepeater = new Dictionary<string, object>[1];
            previousAppData["read-repeater"] = previousRepeater;
            previousRepeater[0] = new Dictionary<string, object>();
            previousRepeater[0]["write-field-2"] = "this row can not be removed 1";
            previousRepeater[0]["read-field-with-default-2"] = "this row can not be removed 2";
            previousRepeater[0]["read-field-no-default-2"] = "this row can not be removed 3";

            ApplicationDataVerifier verifier = new ApplicationDataVerifier(controls, controlsAccess);
            appData = verifier.VerifyApplicationData(appData, previousAppData);
            Assert.AreEqual(1, appData.GetValue<Dictionary<string, object>[]>("read-repeater").Length);
        }
        public void SaveReadOnlyRepeaterChildRevertToPrevious()
        {
            const string formId = "11";
            const string userId = "007";
            ControlList controls = this.GetControlList(formId);
            List<ControlAccess> controlsAccess = this.GetControlAccess(formId, userId);

            ApplicationData appData = new ApplicationData();
            Dictionary<string, object>[] repeater = new Dictionary<string, object>[1];
            appData["write-repeater"] = repeater;
            repeater[0] = new Dictionary<string, object>();
            repeater[0]["read-field-no-default"] = "this field is not writeable!";

            ApplicationData previousAppData = new ApplicationData();
            Dictionary<string, object>[] previousRepeater = new Dictionary<string, object>[1];
            previousAppData["write-repeater"] = previousRepeater;
            previousRepeater[0] = new Dictionary<string, object>();
            previousRepeater[0]["read-field-no-default"] = "this is the previous value!";

            ApplicationDataVerifier verifier = new ApplicationDataVerifier(controls, controlsAccess);
            appData = verifier.VerifyApplicationData(appData, previousAppData);
            Assert.AreEqual("this is the previous value!", appData.GetValue<string>("write-repeater[0].read-field-no-default"));
        }
        public void SaveReadOnlyRepeaterAddRow()
        {
            const string formId = "11";
            const string userId = "007";
            ControlList controls = this.GetControlList(formId);
            List<ControlAccess> controlsAccess = this.GetControlAccess(formId, userId);

            ApplicationData appData = new ApplicationData();
            Dictionary<string, object>[] repeater = new Dictionary<string, object>[2];
            appData["read-repeater"] = repeater;
            repeater[0] = new Dictionary<string, object>();
            repeater[0]["write-field-2"] = "this row was always there";
            repeater[1] = new Dictionary<string, object>();
            repeater[1]["write-field-2"] = "there is no row";

            ApplicationData previousAppData = new ApplicationData();
            Dictionary<string, object>[] previousRepeater = new Dictionary<string, object>[1];
            previousAppData["read-repeater"] = previousRepeater;
            previousRepeater[0] = new Dictionary<string, object>();
            previousRepeater[0]["write-field-2"] = "this row was always there";

            ApplicationDataVerifier verifier = new ApplicationDataVerifier(controls, controlsAccess);
            appData = verifier.VerifyApplicationData(appData, previousAppData);
            Assert.AreEqual(1, appData.GetValue<Dictionary<string, object>[]>("read-repeater").Length);
        }
        public void SaveReadOnlyRepeaterChildRevertToDefault()
        {
            const string formId = "11";
            const string userId = "007";
            ControlList controls = this.GetControlList(formId);
            List<ControlAccess> controlsAccess = this.GetControlAccess(formId, userId);

            ApplicationData appData = new ApplicationData();
            Dictionary<string, object>[] repeater = new Dictionary<string, object>[1];
            appData["write-repeater"] = repeater;
            repeater[0] = new Dictionary<string, object>();
            repeater[0]["read-field-with-default"] = "this field is not writeable!";

            ApplicationDataVerifier verifier = new ApplicationDataVerifier(controls, controlsAccess);
            appData = verifier.VerifyApplicationData(appData, null);
            Assert.AreEqual("the two sweetest words in the english language", appData.GetValue<string>("write-repeater[0].read-field-with-default"));
        }
        public void SaveReadOnlyFieldRevertToPrevious()
        {
            const string formId = "10";
            const string userId = "007";
            ControlList controls = this.GetControlList(formId);
            List<ControlAccess> controlsAccess = this.GetControlAccess(formId, userId);

            ApplicationData appData = new ApplicationData();
            appData["read-field-with-default"] = "my ILLEGAL 4@X0R value";

            ApplicationData previousAppData = new ApplicationData();
            previousAppData["read-field-with-default"] = "the old legal value";

            ApplicationDataVerifier verifier = new ApplicationDataVerifier(controls, controlsAccess);
            appData = verifier.VerifyApplicationData(appData, previousAppData);
            Assert.AreEqual("the old legal value", appData["read-field-with-default"]);
        }
        public void SaveReadOnlyFieldRevertToEmpty()
        {
            const string formId = "10";
            const string userId = "007";
            ControlList controls = this.GetControlList(formId);
            List<ControlAccess> controlsAccess = this.GetControlAccess(formId, userId);

            ApplicationData appData = new ApplicationData();
            appData["read-field-no-default"] = "my ILLEGAL 4@X0R value";

            ApplicationDataVerifier verifier = new ApplicationDataVerifier(controls, controlsAccess);
            appData = verifier.VerifyApplicationData(appData, null);
            Assert.AreEqual(string.Empty, appData["read-field-no-default"]);
        }
        public void SaveReadOnlyFieldRevertToDefault()
        {
            const string formId = "10";
            const string userId = "007";
            ControlList controls = this.GetControlList(formId);
            List<ControlAccess> controlsAccess = this.GetControlAccess(formId, userId);

            ApplicationData appData = new ApplicationData();
            appData["read-field-with-default"] = "my ILLEGAL 4@X0R value";

            ApplicationDataVerifier verifier = new ApplicationDataVerifier(controls, controlsAccess);
            appData = verifier.VerifyApplicationData(appData, null);
            Assert.AreEqual("the two sweetest words in the english language", appData["read-field-with-default"]);
        }
        public void SaveNonExistantRepeaterData()
        {
            const string formId = "11";
            const string userId = "007";
            ControlList controls = this.GetControlList(formId);
            List<ControlAccess> controlsAccess = this.GetControlAccess(formId, userId);

            ApplicationData input = new ApplicationData();
            input["bad-repeater"] = new object[0];

            ApplicationData previousAppData = new ApplicationData();
            previousAppData["bad-repeater"] = new object[0];

            ApplicationDataVerifier verifier = new ApplicationDataVerifier(controls, controlsAccess);
            ApplicationData output = verifier.VerifyApplicationData(input, previousAppData);

            Assert.IsTrue(input.ContainsKey("bad-repeater"));
            Assert.IsFalse(output.ContainsKey("bad-repeater"));
        }
        public void SaveNonExistantRepeaterChild()
        {
            const string formId = "11";
            const string userId = "007";
            ControlList controls = this.GetControlList(formId);
            List<ControlAccess> controlsAccess = this.GetControlAccess(formId, userId);

            ApplicationData input = new ApplicationData();
            Dictionary<string, object>[] repeater = new Dictionary<string, object>[1];
            input["write-repeater"] = repeater;
            repeater[0] = new Dictionary<string, object>();
            repeater[0]["bad-field"] = "this field is writeable!";

            ApplicationDataVerifier verifier = new ApplicationDataVerifier(controls, controlsAccess);
            ApplicationData output = verifier.VerifyApplicationData(input, null);

            Assert.IsTrue(input.ContainsKey("write-repeater"));
            Assert.IsNotNull(input.GetValue<string>("write-repeater[0].bad-field"));

            Assert.IsTrue(output.ContainsKey("write-repeater"));
            Assert.IsNull(output.GetValue<string>("write-repeater[0].bad-field"));
        }