Ejemplo n.º 1
0
        public void IndexedPathSourceResolutionTest()
        {
            string      rawPath = "AvailableEmployees.Name";
            BindingPath path    = new BindingPath(rawPath, 1);

            var employee1 = new { Name = "Sam" };
            var employee2 = new { Name = "Ben" };
            var employee3 = new { Name = "Ali" };

            var list      = new[] { employee1, employee2, employee3 };
            var viewModel = new { AvailableEmployees = list };

            SourceProperty sourceProperty = path.ResolveAsSource(viewModel);

            Assert.IsNotNull(sourceProperty);
            Assert.IsNotNull(sourceProperty.Descriptor);
            Assert.IsNotNull(sourceProperty.OwningInstance);
            Assert.IsNotNull(sourceProperty.Value);
            Assert.AreEqual("Ben", sourceProperty.Value);
            Assert.AreEqual("Name", sourceProperty.Descriptor.Name);

            //empoyee at the index of 1
            Assert.AreEqual(employee2, sourceProperty.OwningInstance);
            Assert.AreEqual(employee2.Name, sourceProperty.Value);
            Assert.AreEqual("Name", sourceProperty.Descriptor.Name);
        }
Ejemplo n.º 2
0
        public void NestedCollectionAbsolutePathTest()
        {
            /*Arrange*/

            //create a parent binding.
            /*Arrange*/
            Binding.BindingDef parent = new Binding.BindingDef(new WebformControl(new TextBox()), "", new Options {
                Path = ""
            }, controlService);
            string rawPath = "ViewModelID";

            BindingPath path      = new BindingPath(rawPath, parent.SourceExpression, PathMode.Absolute);
            var         viewModel = new { ViewModelID = "viewmodel1" };

            /*Act*/
            SourceProperty sourceProperty = path.ResolveAsSource(viewModel);

            /*Assert*/
            Assert.IsNotNull(sourceProperty);
            Assert.IsNotNull(sourceProperty.Descriptor);
            Assert.IsNotNull(sourceProperty.OwningInstance);
            Assert.IsNotNull(sourceProperty.Value);
            Assert.AreEqual("ViewModelID", sourceProperty.Descriptor.Name);
            Assert.AreEqual(viewModel, sourceProperty.OwningInstance);
            Assert.AreEqual(viewModel.ViewModelID, sourceProperty.Value);
        }
Ejemplo n.º 3
0
        public void SimplePathSourceResolutionTest()
        {
            string      rawPath = "SelectedEmployee.Name";
            BindingPath path    = new BindingPath(rawPath);

            object         selectedEmployee = new { Name = "Sam" };
            SourceProperty sourceProperty   = path.ResolveAsSource(new { SelectedEmployee = selectedEmployee });

            Assert.IsNotNull(sourceProperty);
            Assert.IsNotNull(sourceProperty.Descriptor);
            Assert.IsNotNull(sourceProperty.OwningInstance);
            Assert.IsNotNull(sourceProperty.Value);
            Assert.AreEqual("Sam", sourceProperty.Value);
            Assert.AreEqual("Name", sourceProperty.Descriptor.Name);
            Assert.AreEqual(selectedEmployee, sourceProperty.OwningInstance);
        }
Ejemplo n.º 4
0
        public void NestedAbsolutePathTest()
        {
            /*Arrange*/

            //create a parent binding.
            Binding.BindingDef parent = new Binding.BindingDef(
                new WebformControl(new TextBox())
                , "Text", 0
                , new BindingCollection()
                , new Options {
                Path = "Companies"
            }
                , true, controlService);


            string rawPath = "CompanyName";

            BindingPath path = new BindingPath(rawPath, parent.SourceExpression, PathMode.Absolute);

            var employee1 = new { Name = "Sam" };
            var employee2 = new { Name = "Ben" };
            var employee3 = new { Name = "Ali" };

            var list    = new[] { employee1, employee2, employee3 };
            var company = new { AvailableEmployees = list };

            var companyList = new[] { company };

            var viewModel = new { CompanyName = "Tesco Ltd.", Companies = companyList };

            /*Act*/
            SourceProperty sourceProperty = path.ResolveAsSource(viewModel);

            /*Assert*/
            Assert.IsNotNull(sourceProperty);
            Assert.IsNotNull(sourceProperty.Descriptor);
            Assert.IsNotNull(sourceProperty.OwningInstance);
            Assert.IsNotNull(sourceProperty.Value);
            Assert.AreEqual("CompanyName", sourceProperty.Descriptor.Name);

            Assert.AreEqual(viewModel, sourceProperty.OwningInstance);
            Assert.AreEqual(viewModel.CompanyName, sourceProperty.Value);
        }
Ejemplo n.º 5
0
        public void NestedRelativePathTest()
        {
            /*Arrange*/
            Binding.BindingDef parent = new Binding.BindingDef(
                new WebformControl(new TextBox()),
                "Text",
                new Options()
            {
                Path = "Company"
            },
                controlService);

            string rawPath = "AvailableEmployees.Name";

            BindingPath path = new BindingPath(rawPath, 2, parent.SourceExpression, PathMode.Relative);

            var employee1 = new { Name = "Sam" };
            var employee2 = new { Name = "Ben" };
            var employee3 = new { Name = "Ali" };

            var list    = new[] { employee1, employee2, employee3 };
            var company = new { AvailableEmployees = list };

            var viewModel = new { Company = company };

            /*Act*/
            SourceProperty sourceProperty = path.ResolveAsSource(viewModel);

            /*Assert*/
            Assert.IsNotNull(sourceProperty);
            Assert.IsNotNull(sourceProperty.Descriptor);
            Assert.IsNotNull(sourceProperty.OwningInstance);
            Assert.IsNotNull(sourceProperty.Value);
            Assert.AreEqual("Ali", sourceProperty.Value);
            Assert.AreEqual("Name", sourceProperty.Descriptor.Name);

            //empoyee at the index of 1
            Assert.AreEqual(employee3, sourceProperty.OwningInstance);
            Assert.AreEqual(employee3.Name, sourceProperty.Value);
            Assert.AreEqual("Name", sourceProperty.Descriptor.Name);
        }