当前位置: 首页>>代码示例>>C#>>正文


C# DataBinding类代码示例

本文整理汇总了C#中DataBinding的典型用法代码示例。如果您正苦于以下问题:C# DataBinding类的具体用法?C# DataBinding怎么用?C# DataBinding使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


DataBinding类属于命名空间,在下文中一共展示了DataBinding类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: HandlesDegenerateCaseWithOneProvider

        public void HandlesDegenerateCaseWithOneProvider()
        {
            DataBinding[] bindings = new DataBinding[] {
                new DataBinding(0, null)
            };
            IDataProvider[] providers = new IDataProvider[] {
                Mocks.StrictMock<IDataProvider>()
            };

            using (Mocks.Record())
            {
                Expect.Call(providers[0].GetItems(bindings, true)).Return(new IDataItem[] {
                    new ScalarDataItem<int>(1, null, true),
                    new ScalarDataItem<int>(2, null, false),
                    new ScalarDataItem<int>(3, null, true)
                });
            }

            using (Mocks.Playback())
            {
                List<IDataItem> items = new List<IDataItem>(IntersectionMergeStrategy.Instance.Merge(providers, bindings, true));
                Assert.Count(3, items);

                Assert.AreEqual(1, items[0].GetValue(bindings[0]));
                Assert.IsTrue(items[0].IsDynamic);

                Assert.AreEqual(2, items[1].GetValue(bindings[0]));
                Assert.IsFalse(items[1].IsDynamic);

                Assert.AreEqual(3, items[2].GetValue(bindings[0]));
                Assert.IsTrue(items[2].IsDynamic);
            }
        }
开发者ID:dougrathbone,项目名称:mbunit-v3,代码行数:33,代码来源:IntersectionMergeStrategyTest.cs

示例2: GetValue

        /// <inheritdoc />
        public object GetValue(DataBinding binding)
        {
            if (binding == null)
                throw new ArgumentNullException("binding");

            return GetValueImpl(binding);
        }
开发者ID:dougrathbone,项目名称:mbunit-v3,代码行数:8,代码来源:BaseDataItem.cs

示例3: HandlesDegenerateCaseWithMoreThanOneProviderButOneIsEmpty

        public void HandlesDegenerateCaseWithMoreThanOneProviderButOneIsEmpty()
        {
            DataBinding[][] bindingsPerProvider = new DataBinding[][] {
                new DataBinding[] { new DataBinding(0, null) },
                new DataBinding[] { new DataBinding(0, null) },
            };

            IDataProvider[] providers = new IDataProvider[] {
                Mocks.StrictMock<IDataProvider>(),
                Mocks.StrictMock<IDataProvider>()
            };

            IDataItem[][] itemsPerProvider = new IDataItem[][] {
                new IDataItem[] {
                    new ScalarDataItem<int>(1, null, true),
                    new ScalarDataItem<int>(2, null, false)
                },
                new IDataItem[0]
            };

            using (Mocks.Record())
            {
                SetupResult.For(providers[0].GetItems(bindingsPerProvider[0], true)).Return(itemsPerProvider[0]);
                SetupResult.For(providers[1].GetItems(bindingsPerProvider[1], true)).Return(itemsPerProvider[1]);
            }

            using (Mocks.Playback())
            {
                List<IList<IDataItem>> items = new List<IList<IDataItem>>(PairwiseJoinStrategy.Instance.Join(providers, bindingsPerProvider, true));
                Assert.Count(0, items);
            }
        }
开发者ID:dougrathbone,项目名称:mbunit-v3,代码行数:32,代码来源:PairwiseJoinStrategyTest.cs

示例4: BoundDataAccessor

        /// <summary>
        /// Creates a bound data accessor.
        /// </summary>
        /// <param name="binding">The binding to query.</param>
        /// <exception cref="ArgumentNullException">Thrown if <paramref name="binding"/> is null.</exception>
        public BoundDataAccessor(DataBinding binding)
        {
            if (binding == null)
                throw new ArgumentNullException("binding");

            this.binding = binding;
        }
开发者ID:dougrathbone,项目名称:mbunit-v3,代码行数:12,代码来源:BoundDataAccessor.cs

示例5: CanBind

        /// <inheritdoc />
        public bool CanBind(DataBinding binding)
        {
            if (binding == null)
                throw new ArgumentNullException("binding");

            return CanBindImpl(binding);
        }
开发者ID:dougrathbone,项目名称:mbunit-v3,代码行数:8,代码来源:BaseDataSet.cs

示例6: ConstructorWithPathAndIndex

        public void ConstructorWithPathAndIndex()
        {
            DataBinding binding = new DataBinding(42, "path");

            Assert.AreEqual("path", binding.Path);
            Assert.AreEqual(42, binding.Index);
        }
开发者ID:dougrathbone,项目名称:mbunit-v3,代码行数:7,代码来源:DataBindingTest.cs

示例7: AccessorObtainsAValueFromTheRow

        public void AccessorObtainsAValueFromTheRow()
        {
            DataBinding binding = new DataBinding(0, null);
            ScalarDataBinder binder = new ScalarDataBinder(binding, "name");

            IDataSourceResolver resolver = Mocks.StrictMock<IDataSourceResolver>();
            DataBindingContext context = new DataBindingContext(new NullConverter());

            DataSource source = new DataSource("name");
            source.AddDataSet(new ItemSequenceDataSet(new IDataItem[]
            {
                new ScalarDataItem<int>(42, null, false),
                new ScalarDataItem<string>("42", null, false)
            }, 1));

            using (Mocks.Record())
            {
                Expect.Call(resolver.ResolveDataSource("name")).Return(source);
            }

            using (Mocks.Playback())
            {
                IDataAccessor accessor = binder.Register(context, resolver);
                Assert.IsTrue(context.DataSets.Contains(source), "The data sets list should contain the source that was resolved during binder registration.");

                List<IDataItem> items = new List<IDataItem>(context.GetItems(true));
                Assert.Count(2, items);

                Assert.AreEqual(42, accessor.GetValue(items[0]));
                Assert.AreEqual("42", accessor.GetValue(items[1]));
            }
        }
开发者ID:dougrathbone,项目名称:mbunit-v3,代码行数:32,代码来源:ScalarDataBinderTest.cs

示例8: JoinsItemsCombinatorially

        public void JoinsItemsCombinatorially()
        {
            DataBinding[][] bindingsPerProvider = new DataBinding[][] {
                new DataBinding[] { new DataBinding(0, null) },
                new DataBinding[] { },
                new DataBinding[] { new DataBinding(0, null) },
            };

            IDataProvider[] providers = new IDataProvider[] {
                Mocks.StrictMock<IDataProvider>(),
                Mocks.StrictMock<IDataProvider>(),
                Mocks.StrictMock<IDataProvider>()
            };

            IDataItem[][] itemsPerProvider = new IDataItem[][] {
                new IDataItem[] {
                    new ScalarDataItem<int>(1, null, false),
                    new ScalarDataItem<int>(2, null, true)
                },
                new IDataItem[] {
                    new ScalarDataItem<int>(1, null, false),
                    new ScalarDataItem<int>(2, null, false),
                    new ScalarDataItem<int>(3, null, false)
                },
                new IDataItem[] {
                    new ScalarDataItem<int>(1, null, false),
                    new ScalarDataItem<int>(2, null, true)
                }
            };

            using (Mocks.Record())
            {
                Expect.Call(providers[0].GetItems(bindingsPerProvider[0], true)).Return(itemsPerProvider[0]);
                Expect.Call(providers[1].GetItems(bindingsPerProvider[1], true)).Return(itemsPerProvider[1]);
                Expect.Call(providers[2].GetItems(bindingsPerProvider[2], true)).Return(itemsPerProvider[2]);
            }

            using (Mocks.Playback())
            {
                List<IList<IDataItem>> items = new List<IList<IDataItem>>(CombinatorialJoinStrategy.Instance.Join(providers, bindingsPerProvider, true));
                Assert.Count(12, items);

                int index = 0;
                for (int i = 0; i < itemsPerProvider[0].Length; i++)
                {
                    for (int j = 0; j < itemsPerProvider[1].Length; j++)
                    {
                        for (int k = 0; k < itemsPerProvider[2].Length; k++)
                        {
                            Assert.AreSame(itemsPerProvider[0][i], items[index][0]);
                            Assert.AreSame(itemsPerProvider[1][j], items[index][1]);
                            Assert.AreSame(itemsPerProvider[2][k], items[index][2]);

                            index += 1;
                        }
                    }
                }
            }
        }
开发者ID:dougrathbone,项目名称:mbunit-v3,代码行数:59,代码来源:CombinatorialJoinStrategyTest.cs

示例9: HandlesDegenerateCaseWithZeroProviders

        public void HandlesDegenerateCaseWithZeroProviders()
        {
            DataBinding[][] bindingsPerProvider = new DataBinding[0][];
            IDataProvider[] providers = new IDataProvider[0];

            List<IList<IDataItem>> items = new List<IList<IDataItem>>(PairwiseJoinStrategy.Instance.Join(providers, bindingsPerProvider, true));
            Assert.Count(0, items);
        }
开发者ID:dougrathbone,项目名称:mbunit-v3,代码行数:8,代码来源:PairwiseJoinStrategyTest.cs

示例10: KeepsOnlyIntersectionIncludingRightNumberOfDuplicatesAndExcludesBadItems

        public void KeepsOnlyIntersectionIncludingRightNumberOfDuplicatesAndExcludesBadItems()
        {
            DataBinding[] bindings = new DataBinding[] {
                new DataBinding(0, null)
            };
            IDataProvider[] providers = new IDataProvider[] {
                Mocks.StrictMock<IDataProvider>(),
                Mocks.StrictMock<IDataProvider>(),
                Mocks.StrictMock<IDataProvider>()
            };

            using (Mocks.Record())
            {
                IDataItem badItem = Mocks.StrictMock<IDataItem>();
                Expect.Call(badItem.GetValue(bindings[0])).Throw(new InvalidOperationException("Test exception"));

                Expect.Call(providers[0].GetItems(bindings, true)).Return(new IDataItem[] {
                    new ScalarDataItem<int>(1, null, false),
                    new ScalarDataItem<int>(2, null, true),
                    new ScalarDataItem<int>(1, null, false),
                    new ScalarDataItem<int>(3, null, false),
                    new ScalarDataItem<int>(6, null, false),
                });

                Expect.Call(providers[1].GetItems(bindings, true)).Return(new IDataItem[] {
                    new ScalarDataItem<int>(1, null, false),
                    new ScalarDataItem<int>(1, null, false),
                    badItem,
                    new ScalarDataItem<int>(2, null, true),
                    new ScalarDataItem<int>(6, null, false),
                    new ScalarDataItem<int>(1, null, false),
                    new ScalarDataItem<int>(4, null, false),
                });

                Expect.Call(providers[2].GetItems(bindings, true)).Return(new IDataItem[] {
                    new ScalarDataItem<int>(1, null, false),
                    new ScalarDataItem<int>(1, null, false),
                    new ScalarDataItem<int>(5, null, false),
                    new ScalarDataItem<int>(3, null, false),
                    new ScalarDataItem<int>(2, null, true)
                });
            }

            using (Mocks.Playback())
            {
                List<IDataItem> items = new List<IDataItem>(IntersectionMergeStrategy.Instance.Merge(providers, bindings, true));
                Assert.Count(3, items);

                Assert.AreEqual(1, items[0].GetValue(bindings[0]));
                Assert.IsFalse(items[0].IsDynamic);

                Assert.AreEqual(1, items[1].GetValue(bindings[0]));
                Assert.IsFalse(items[1].IsDynamic);

                Assert.AreEqual(2, items[2].GetValue(bindings[0]));
                Assert.IsTrue(items[2].IsDynamic);
            }
        }
开发者ID:dougrathbone,项目名称:mbunit-v3,代码行数:58,代码来源:IntersectionMergeStrategyTest.cs

示例11: ScalarDataBinder

        /// <summary>
        /// Creates a scalar data binder.
        /// </summary>
        /// <param name="binding">The data binding.</param>
        /// <param name="sourceName">The data source name to query, or an empty string if it is anonymous.</param>
        public ScalarDataBinder(DataBinding binding, string sourceName)
        {
            if (binding == null)
                throw new ArgumentNullException("binding");
            if (sourceName == null)
                throw new ArgumentNullException("sourceName");

            this.binding = binding;
            this.sourceName = sourceName;
        }
开发者ID:dougrathbone,项目名称:mbunit-v3,代码行数:15,代码来源:ScalarDataBinder.cs

示例12: HandlesDegenerateCaseWithZeroProviders

        public void HandlesDegenerateCaseWithZeroProviders()
        {
            DataBinding[] bindings = new DataBinding[] {
                new DataBinding(0, null)
            };
            IDataProvider[] providers = new IDataProvider[0];

            List<IDataItem> items = new List<IDataItem>(IntersectionMergeStrategy.Instance.Merge(providers, bindings, true));
            Assert.Count(0, items);
        }
开发者ID:dougrathbone,项目名称:mbunit-v3,代码行数:10,代码来源:IntersectionMergeStrategyTest.cs

示例13: ReplaceIndexCreatesANewInstanceWithTheNewIndex

        public void ReplaceIndexCreatesANewInstanceWithTheNewIndex()
        {
            DataBinding oldBinding = new DataBinding(42, "path");
            DataBinding newBinding = oldBinding.ReplaceIndex(23);

            Assert.AreNotSame(oldBinding, newBinding);

            Assert.AreEqual("path", newBinding.Path);
            Assert.AreEqual(23, newBinding.Index);
        }
开发者ID:dougrathbone,项目名称:mbunit-v3,代码行数:10,代码来源:DataBindingTest.cs

示例14: CanBindImpl

        /// <inheritdoc />
        protected override bool CanBindImpl(DataBinding binding)
        {
            foreach (IDataSet dataSet in DataSets)
            {
                if (!dataSet.CanBind(binding))
                    return false;
            }

            return true;
        }
开发者ID:dougrathbone,项目名称:mbunit-v3,代码行数:11,代码来源:MergedDataSet.cs

示例15: JoinsItemsSequentiallyAndPadsWithNullsUntilExhausted

        public void JoinsItemsSequentiallyAndPadsWithNullsUntilExhausted()
        {
            DataBinding[][] bindingsPerProvider = new DataBinding[][] {
                new DataBinding[] { new DataBinding(0, null) },
                new DataBinding[] { },
                new DataBinding[] { new DataBinding(0, null) },
            };

            IDataProvider[] providers = new IDataProvider[] {
                Mocks.StrictMock<IDataProvider>(),
                Mocks.StrictMock<IDataProvider>(),
                Mocks.StrictMock<IDataProvider>()
            };

            IDataItem[][] itemsPerProvider = new IDataItem[][] {
                new IDataItem[] {
                    new ScalarDataItem<int>(1, null, true),
                    new ScalarDataItem<int>(2, null, false)
                },
                new IDataItem[] { },
                new IDataItem[] {
                    new ScalarDataItem<int>(1, null, false),
                    new ScalarDataItem<int>(2, null, false),
                    new ScalarDataItem<int>(3, null, false)
                }
            };

            using (Mocks.Record())
            {
                Expect.Call(providers[0].GetItems(bindingsPerProvider[0], true)).Return(itemsPerProvider[0]);
                Expect.Call(providers[1].GetItems(bindingsPerProvider[1], true)).Return(itemsPerProvider[1]);
                Expect.Call(providers[2].GetItems(bindingsPerProvider[2], true)).Return(itemsPerProvider[2]);
            }

            using (Mocks.Playback())
            {
                List<IList<IDataItem>> items = new List<IList<IDataItem>>(SequentialJoinStrategy.Instance.Join(providers, bindingsPerProvider, true));
                Assert.Count(3, items);

                Assert.AreSame(itemsPerProvider[0][0], items[0][0]);
                Assert.AreSame(NullDataItem.Instance, items[0][1]);
                Assert.AreSame(itemsPerProvider[2][0], items[0][2]);

                Assert.AreSame(itemsPerProvider[0][1], items[1][0]);
                Assert.AreSame(NullDataItem.Instance, items[1][1]);
                Assert.AreSame(itemsPerProvider[2][1], items[1][2]);

                Assert.AreSame(NullDataItem.Instance, items[2][0]);
                Assert.AreSame(NullDataItem.Instance, items[2][1]);
                Assert.AreSame(itemsPerProvider[2][2], items[2][2]);
            }
        }
开发者ID:dougrathbone,项目名称:mbunit-v3,代码行数:52,代码来源:SequentialJoinStrategyTest.cs


注:本文中的DataBinding类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。