Exemplo n.º 1
0
        public void ComplexTest()
        {
            var form                   = creator.form;
            var context                = creator.context;
            var field                  = creator.fields[0];
            Func <Form, bool> allow    = (f => true);
            Func <Form, bool> disallow = (f => false);

            // create
            FField input = new FField {
                SectionId    = form.Sections.First().Id,
                Column       = "bb",
                ParentId     = field.Id,
                FieldType    = FieldType.BuiltIn,
                InputStyle   = InputStyle.Input,
                Position     = 0,
                DefaultValue = "",
            };
            var newFieldId = FieldsServices <Form, Field> .Create(context, form.Id, input, allow);

            var newField = context.FormCoreFields.Find(newFieldId);

            creator.UpdateNewID(newField);
            Assert.AreEqual(field.Label, newField.Label);

            // update
            TestBase.CalcVirtualAttributes(context);
            try {
                input = new FField {
                    Position = 1, ParentId = newField.Id
                };
                FieldsServices <Form, Field> .Update(context, form.Id, newField.Id, input, allow);

                Assert.Fail();
            }catch (Exception e) {
                Assert.IsTrue(e is AccessDenied);
            }
            input = new FField {
                Position = 1, ParentId = creator.fields[1].Id
            };
            FieldsServices <Form, Field> .Update(context, form.Id, newField.Id, input, allow);

            newField = context.FormCoreFields.Find(newField.Id);
            Assert.AreEqual(1, newField.Position);
        }
Exemplo n.º 2
0
        public void ComplexTest()
        {
            var context = creator.context;
            var form    = creator.form;
            var form1   = creator.form1;


            var input = new FForm {
                Title     = form.Title,
                ParentIds = new int[] { form.Id },
            };

            Action            before   = null;
            Action <Form>     after    = null;
            Func <Form, bool> allow    = (f => true);
            Func <Form, bool> disallow = (f => false);

            // disallow create
            try {
                FormsServices <Form, OForm> .Create(context, input, before, disallow, after);

                Assert.Fail();
            } catch (Exception e) {
                Assert.IsTrue(e is AccessDenied);
            }

            // allow create
            var newFormId = FormsServices <Form, OForm> .Create(context, input, before, allow, after);

            var newForm = Form.Load(context, newFormId);

            creator.UpdateNewID(newForm, parents: input.ParentIds);
            Assert.AreEqual(form.Id, newForm.Parents.First().Id);
            Assert.AreEqual(form.Title, newForm.Title);

            // show this form
            var newOForm = FormsServices <Form, OForm> .Show(context, newForm.Id, allow, f => new OForm(context, f));

            var actualSectionIds   = newOForm.Sections.Select(s => s.Id).ToArray();
            var expectedSectionIds = form.Sections.Select(s => s.Id).ToArray();

            Assert.IsTrue(actualSectionIds.SequenceEqual(expectedSectionIds));

            // parentid cannot be itself
            try {
                input = new FForm {
                    ParentIds = new [] { newForm.Id }
                };
                FormsServices <Form, OForm> .Update(context, newForm.Id, new FForm { ParentIds = new [] { newForm.Id } }, allow);

                Assert.Fail();
            } catch (Exception e) {
                Assert.IsTrue(e is AccessDenied);
            }

            // allow update, parent form#1 will have no fields
            newForm.InvokeMethod <Form>("ClearCache");
            form1.InvokeMethod <Form>("ClearCache");
            form.InvokeMethod <Form>("ClearCache");
            FormsServices <Form, OForm> .Update(context, newForm.Id, new FForm { ParentIds = new [] { form1.Id } }, allow);

            newForm = Form.Load(context, newForm.Id);
            CollectionAssert.AreEqual(new int[] { form1.Id }, newForm.Parents.Select(f => f.Id).ToArray());
            Assert.AreEqual(form.Title, newForm.Title);

            // show this form
            newOForm = FormsServices <Form, OForm> .Show(context, newForm.Id, allow, f => new OForm(context, f));

            actualSectionIds   = newOForm.Sections.Select(s => s.Id).ToArray();
            expectedSectionIds = form1.Sections.Select(s => s.Id).ToArray();
            Assert.IsTrue(actualSectionIds.SequenceEqual(expectedSectionIds));

            // allow delete
            // TODO delete not working on mock-test
            //Base.CalcVirtualAttributes(context);
            //try {
            //  FormsServices<Form, OForm>.Delete(context, newForm.Id, allow);
            //  Assert.Fail();
            //} catch (Exception e) {
            //  Assert.IsTrue(e is Exception);
            //}
            //FormsServices<Form, OForm>.Index(context,
            //  () => {
            //    return context.FormCoreForms.ToList().Select(f => Form.Load(context, f.Id)).ToList();
            //  },
            //  f => new OForm(context, f));
        }
Exemplo n.º 3
0
        public void ComplexTest()
        {
            var context = creator.context;
            var form    = creator.form;
            var form1   = creator.form1;


            var input = new FForm {
                Title     = form.Title,
                ParentIds = new[] { form.Id }
            };

            Action            before   = null;
            Action <Form>     after    = null;
            Func <Form, bool> allow    = f => true;
            Func <Form, bool> disallow = f => false;

            // disallow create
            try {
                FormsServices <Form, OForm> .Create(context, input, before, disallow, after);

                Assert.Fail();
            } catch (Exception e) {
                Assert.IsTrue(e is AccessDenied);
            }

            // allow create
            var newFormId = FormsServices <Form, OForm> .Create(context, input, before, allow, after);

            var newForm = Form.Load(context, newFormId);

            creator.UpdateNewID(newForm, input.ParentIds);
            Assert.AreEqual(form.Id, newForm.Parents.First().Id);
            Assert.AreEqual(form.Title, newForm.Title);

            // show this form
            var newOForm = FormsServices <Form, OForm> .Show(context, newForm.Id, allow, f => new OForm(context, f));

            var actualSectionIds   = newOForm.Sections.Select(s => s.Id).ToArray();
            var expectedSectionIds = form.Sections.Select(s => s.Id).ToArray();

            Assert.IsTrue(actualSectionIds.SequenceEqual(expectedSectionIds));

            // parentid cannot be itself
            try {
                input = new FForm {
                    ParentIds = new[] { newForm.Id }
                };
                FormsServices <Form, OForm> .Update(context, newForm.Id, new FForm { ParentIds = new[] { newForm.Id } }, allow);

                Assert.Fail();
            } catch (Exception e) {
                Assert.IsTrue(e is AccessDenied);
            }

            // allow update, parent form#1 will have no fields
            newForm.InvokeMethod("ClearCache");
            form1.InvokeMethod("ClearCache");
            form.InvokeMethod("ClearCache");
            FormsServices <Form, OForm> .Update(context, newForm.Id, new FForm { ParentIds = new[] { form1.Id } }, allow);

            newForm = Form.Load(context, newForm.Id);
            CollectionAssert.AreEqual(new[] { form1.Id }, newForm.Parents.Select(f => f.Id).ToArray());
            Assert.AreEqual(form.Title, newForm.Title);

            // show this form
            newOForm = FormsServices <Form, OForm> .Show(context, newForm.Id, allow, f => new OForm(context, f));

            actualSectionIds   = newOForm.Sections.Select(s => s.Id).ToArray();
            expectedSectionIds = form1.Sections.Select(s => s.Id).ToArray();
            Assert.IsTrue(actualSectionIds.SequenceEqual(expectedSectionIds));
        }