コード例 #1
0
        public void RowEnumerationIsFilteredWhenNotIncludingDynamicRows()
        {
            List<IDataItem> items = new List<IDataItem>();
            items.Add(new ScalarDataItem<int>(42, null, true));
            items.Add(new ScalarDataItem<int>(53, null, false));

            ItemSequenceDataSet dataSet = new ItemSequenceDataSet(items, 5);

            List<IDataItem> result = new List<IDataItem>(dataSet.GetItems(EmptyArray<DataBinding>.Instance, false));
            Assert.Count(1, result);
            Assert.AreSame(items[1], result[0]);
        }
コード例 #2
0
 public void RowEnumerationIsSameAsSpecifiedInConstructorWhenIncludingDynamicRows()
 {
     List<IDataItem> items = new List<IDataItem>();
     ItemSequenceDataSet dataSet = new ItemSequenceDataSet(items, 5);
     Assert.AreSame(items, dataSet.GetItems(EmptyArray<DataBinding>.Instance, true));
 }
コード例 #3
0
        public void GetItemsDelegatesToTheStrategy()
        {
            JoinedDataSet dataSet = new JoinedDataSet();

            IList<KeyValuePair<string, string>> metadata1 = new KeyValuePair<string, string>[]
            {
                new KeyValuePair<string, string>("abc", "123"),
                new KeyValuePair<string, string>("def", "456")
            };
            IList<KeyValuePair<string, string>> metadata2 = new KeyValuePair<string, string>[]
            {
                new KeyValuePair<string, string>("ghi", "789"),
            };

            DataSource dataSet1 = new DataSource("");
            dataSet1.AddIndexAlias("path", 1);
            dataSet1.AddDataSet(new ItemSequenceDataSet(new IDataItem[]
            {
                new ListDataItem<int>(new int[] { 1, 2, 3 }, metadata1, false),
                new ListDataItem<int>(new int[] { -1, -2, -3 }, metadata2, false)
            }, 3));
            dataSet.AddDataSet(dataSet1);

            IDataSet dataSet2 = new ItemSequenceDataSet(new IDataItem[]
            {
                new ListDataItem<int>(new int[] { 4, 5 }, metadata2, false),
                new ListDataItem<int>(new int[] { -4, -5 }, null, true)
            }, 2);
            dataSet.AddDataSet(dataSet2);

            List<IDataItem> dataSet1Items = new List<IDataItem>(dataSet1.GetItems(EmptyArray<DataBinding>.Instance, true));
            List<IDataItem> dataSet2Items = new List<IDataItem>(dataSet2.GetItems(EmptyArray<DataBinding>.Instance, true));

            List<IList<IDataItem>> results = new List<IList<IDataItem>>();
            results.Add(new IDataItem[] { dataSet1Items[0], dataSet2Items[0] });
            results.Add(new IDataItem[] { dataSet1Items[1], dataSet2Items[1] });

            IJoinStrategy strategy = Mocks.StrictMock<IJoinStrategy>();
            dataSet.Strategy = strategy;

            DataBinding pathBinding = new DataBinding(null, "path");
            DataBinding indexZeroBinding = new DataBinding(0, null);
            DataBinding indexOneBinding = new DataBinding(1, null);
            DataBinding indexThreeBinding = new DataBinding(3, null);

            DataBinding[] bindings = new DataBinding[]
            {
                new DataBinding(null, null), // unresolvable binding because no data sets can claim it
                pathBinding, // claimed by dataSet1
                indexZeroBinding, // claimed by dataSet1
                indexThreeBinding, // claimed by dataSet2
                dataSet.TranslateBinding(dataSet1, pathBinding), // scoped by dataSet1
                dataSet.TranslateBinding(dataSet2, indexOneBinding), // scoped by dataSet2
            };

            using (Mocks.Record())
            {
                Expect.Call(strategy.Join(null, null, true)).IgnoreArguments().Do((JoinDelegate)delegate(IList<IDataProvider> joinProviders, IList<ICollection<DataBinding>> joinBindingsPerProvider,
                    bool includeDynamicItems)
                {
                    Assert.IsTrue(includeDynamicItems);
                    Assert.AreElementsEqual(new IDataProvider[] { dataSet1, dataSet2 }, joinProviders);

                    Assert.Count(2, joinBindingsPerProvider);

                    Assert.AreElementsEqual(new DataBinding[] { pathBinding, indexZeroBinding, pathBinding }, joinBindingsPerProvider[0]);
                    Assert.AreElementsEqual(new DataBinding[] { indexZeroBinding, indexOneBinding }, joinBindingsPerProvider[1]);

                    return results;
                });
            }

            using (Mocks.Playback())
            {
                List<IDataItem> items = new List<IDataItem>(dataSet.GetItems(bindings, true));
                Assert.Count(2, items);

                Assert.Throws<ArgumentNullException>(delegate { items[0].GetValue(null); });

                Assert.Throws<DataBindingException>(delegate { items[0].GetValue(bindings[0]); });
                Assert.AreEqual(2, items[0].GetValue(bindings[1]));
                Assert.AreEqual(1, items[0].GetValue(bindings[2]));
                Assert.AreEqual(4, items[0].GetValue(bindings[3]));
                Assert.AreEqual(2, items[0].GetValue(bindings[4]));
                Assert.AreEqual(5, items[0].GetValue(bindings[5]));

                PropertyBag map = DataItemUtils.GetMetadata(items[0]);
                Assert.Count(3, map);
                Assert.AreEqual("123", map.GetValue("abc"));
                Assert.AreEqual("456", map.GetValue("def"));
                Assert.AreEqual("789", map.GetValue("ghi"));

                Assert.IsFalse(items[0].IsDynamic);

                Assert.Throws<DataBindingException>(delegate { items[1].GetValue(bindings[0]); });
                Assert.AreEqual(-2, items[1].GetValue(bindings[1]));
                Assert.AreEqual(-1, items[1].GetValue(bindings[2]));
                Assert.AreEqual(-4, items[1].GetValue(bindings[3]));
                Assert.AreEqual(-2, items[1].GetValue(bindings[4]));
                Assert.AreEqual(-5, items[1].GetValue(bindings[5]));

                map = DataItemUtils.GetMetadata(items[1]);
                Assert.Count(1, map);
                Assert.AreEqual("789", map.GetValue("ghi"));

                Assert.IsTrue(items[1].IsDynamic);
            }
        }