Esempio n. 1
0
        public void TestContextPath()
        {
            using (FormContextInstance context = FluentFormContext.SpecifyArray("test", new object()))
            {
                Assert.AreEqual(context.Path, FluentFormContext.Path);
            }

            Assert.AreEqual(string.Empty, FluentFormContext.Path);
        }
Esempio n. 2
0
 public void TestArrayTreeModify()
 {
     using (FluentFormContext.SpecifyArray("test", new object()))
     {
         var tree = FluentFormContext.GetTree();
         tree.test[0].Name = "My test name";
         Assert.AreEqual("My test name", tree.test[0].Name);
     }
 }
Esempio n. 3
0
        public void TestArrayPaths()
        {
            IList <TestNameClass> test = GetTestNameList();

            using (FluentFormContext.SpecifyArray("test", new object()))
            {
                Assert.AreEqual("test[0]", FluentFormContext.Path);
                Assert.AreEqual("test[0].Name", FluentFormContext.PathFor <TestNameClass, string>(m => m.Name));
                Assert.AreEqual("test[0].test[0].Name", FluentFormContext.PathFor <TestNameClass, string>(m => test[0].Name));
            }
        }
Esempio n. 4
0
        public void TestForgetArrayContextPath()
        {
            Assert.AreEqual(string.Empty, FluentFormContext.Path);

            FluentFormContext.SpecifyArray("Test", new object());
            Assert.AreEqual("Test[0]", FluentFormContext.Path);

            FormContextInstance context = FluentFormContext.SpecifyArray("Test", new object(), true);

            Assert.AreEqual("Test[0].Test[0]", FluentFormContext.Path);

            context.Dispose();
            Assert.AreEqual("Test[0]", FluentFormContext.Path);

            FluentFormContext.Clear();
            Assert.AreEqual(string.Empty, FluentFormContext.Path);
        }
Esempio n. 5
0
        public void TestNestedContextPath()
        {
            using (FormContextInstance context = FluentFormContext.SpecifyArray("test", new object()))
            {
                Assert.AreEqual(context.Path, FluentFormContext.Path);

                using (FormContextInstance objectContext = FluentFormContext.SpecifyObject("object"))
                {
                    // TODO: context.Path to be relative to when it was created not the current path
                    Assert.AreEqual(objectContext.Path, FluentFormContext.Path);
                }

                Assert.AreEqual(context.Path, FluentFormContext.Path);
            }

            Assert.AreEqual(string.Empty, FluentFormContext.Path);
        }
Esempio n. 6
0
        public void TestArrayNoReuseSameKeys()
        {
            const int iterations = 10;

            IList <TestNameClass> test = GetTestNameList();

            for (int i = 0; i < iterations; i++)
            {
                using (FormContextInstance context = FluentFormContext.SpecifyArray("test", test))
                {
                    Assert.AreEqual(context.Path, FluentFormContext.Path);

                    Assert.AreEqual("test[0]", FluentFormContext.Path);
                    Assert.AreEqual("test[0].Name", FluentFormContext.PathFor <TestNameClass, string>(m => m.Name));
                    Assert.AreEqual("test[0].test[0].Name", FluentFormContext.PathFor <TestNameClass, string>(m => test[0].Name));
                }
            }
        }
Esempio n. 7
0
        public void TestArrayReuse()
        {
            const int iterations = 10;

            IList <TestNameClass> test = GetTestNameList();

            for (int i = 0; i < iterations; i++)
            {
                // True must be used here to ensure "test" is overwritten
                using (FormContextInstance context = FluentFormContext.SpecifyArray("test", test, true))
                {
                    Assert.AreEqual(context.Path, FluentFormContext.Path);

                    Assert.AreEqual("test[0]", FluentFormContext.Path);
                    Assert.AreEqual("test[0].Name", FluentFormContext.PathFor <TestNameClass, string>(m => m.Name));
                    Assert.AreEqual("test[0].test[0].Name", FluentFormContext.PathFor <TestNameClass, string>(m => test[0].Name));
                }
            }
        }