public void TestCopyTo_CopiesPairs()
        {
            ICollection <KeyValuePair <int, int> > dictionary = new ReadOnlyDictionary <int, int>(new Dictionary <int, int>()
            {
                { 1, 2 }, { 2, 3 }
            });

            KeyValuePair <int, int>[] array = new KeyValuePair <int, int> [2];
            dictionary.CopyTo(array, 0);
            Assert.IsTrue(array.Contains(new KeyValuePair <int, int>(1, 2)), "The pair (1, 2) was not copied.");
            Assert.IsTrue(array.Contains(new KeyValuePair <int, int>(2, 3)), "The pair (2, 3) was not copied.");
        }
Exemplo n.º 2
0
        public void CopyTo_Copies_To_Array()
        {
            var a = new KeyValuePair <string, int?>("a", 1);
            var b = new KeyValuePair <string, int?>("b", 1);

            _Dictionary.Add(a);
            _Dictionary.Add(b);
            var array = new KeyValuePair <string, int?> [2];

            _Dictionary.CopyTo(array, 0);
            Assert.IsTrue(array.Contains(a));
            Assert.IsTrue(array.Contains(b));
        }
        public void GetEnumerator_GetAllElements_GetTrue()
        {
            CustomHashTable <int, string> hashTable = new CustomHashTable <int, string>
            {
                { 1, "1" },
                { 2, "2" },
                { 3, "3" },
                { 4, "4" },
                { 5, "5" },
                { 6, "6" }
            };

            KeyValuePair <int, string>[] sameElements = new KeyValuePair <int, string>[] {
                new KeyValuePair <int, string>(1, "1"),
                new KeyValuePair <int, string>(2, "2"),
                new KeyValuePair <int, string>(3, "3"),
                new KeyValuePair <int, string>(4, "4"),
                new KeyValuePair <int, string>(5, "5"),
                new KeyValuePair <int, string>(6, "6")
            };

            foreach (var element in hashTable)
            {
                Assert.IsTrue(sameElements.Contains(element));
            }
        }
        public void TestCopyTo_Explicit()
        {
            var instance = new
            {
                Name = "Bob",
                Age  = 23
            };
            ICollection <KeyValuePair <string, object> > collection = new PropertyDictionary(instance);

            KeyValuePair <string, object>[] array = new KeyValuePair <string, object> [collection.Count];
            int arrayIndex = 0;

            collection.CopyTo(array, arrayIndex);

            Assert.IsTrue(array.Contains(new KeyValuePair <string, object>("Name", "Bob")), "The name property was not found.");
            Assert.IsTrue(array.Contains(new KeyValuePair <string, object>("Age", 23)), "The age property was not found.");
        }
Exemplo n.º 5
0
        /// <summary>
        /// Expect that each item behaves as collection.
        /// </summary>
        public void expect_that_each_item_behaves_as_collection()
        {
            Console.WriteLine("Expect that each item behaves as collection.");
            foreach (ICollection <KeyValuePair <string, string> > item in this.ReadResult)
            {
                var newColumn = new KeyValuePair <string, string>(NewColumnName, NewColumnDefaultValue);
                item.Add(newColumn);
                Assert.IsTrue(item.Contains(newColumn));
                Assert.IsTrue(item.Remove(newColumn));
                Assert.IsFalse(item.Contains(newColumn));

                item.Clear();
                item.Add(newColumn);
                var destination = new KeyValuePair <string, string> [1];
                item.CopyTo(destination, 0);
                Assert.IsTrue(destination.Contains(newColumn));

                Assert.AreEqual(1, item.Count);
                Assert.IsFalse(item.IsReadOnly);
            }
        }
Exemplo n.º 6
0
        public int Compare(KeyValuePair <StorefrontEntry, BitmapData> x, KeyValuePair <StorefrontEntry, BitmapData> y)
        {
            if (x.Key.Categories.Contains(x => x.Contains("zDaily")) || y.Key.Categories.Contains(x => x.Contains("zDaily")))
            {
                int xDaily = 0;
                int yDaily = 0;

                if (x.Key.Categories.Contains(x => x.Contains("zDaily")))
                {
                    xDaily = int.Parse(x.Key.Categories.First(
                                           predicate: x => x.Contains("zDaily")).Replace("zDaily ", ""));
                }
                if (y.Key.Categories.Contains(x => x.Contains("zDaily")))
                {
                    yDaily = int.Parse(y.Key.Categories.First(
                                           predicate: x => x.Contains("zDaily")).Replace("zDaily ", ""));
                }

                if (xDaily < yDaily)
                {
                    return(-1);
                }
                if (xDaily == yDaily)
                {
                    return(x.Key.IsBundle ? -1 : y.Key.IsBundle ? 1 :
                           x.Key.SortPriority > y.Key.SortPriority ? -1 :
                           x.Key.SortPriority == y.Key.SortPriority ? 0 : 1);
                }

                /*x.Key.IsBundle ? -1 : y.Key.IsBundle ? 1 :
                 * x.Key.Items[0].TypeEnum > y.Key.Items[0].TypeEnum ? 1 :
                 * x.Key.Items[0].TypeEnum == y.Key.Items[0].TypeEnum ? 0 : -1;*/
                if (xDaily > yDaily)
                {
                    return(1);
                }
            }
            else
            {
                int xPanel = 0;
                int yPanel = 0;

                if (x.Key.Categories.Contains(x => x.Contains("Panel")))
                {
                    xPanel = int.Parse(x.Key.Categories.First(
                                           predicate: x => x.Contains("Panel")).Replace("Panel ", ""));
                }
                if (y.Key.Categories.Contains(x => x.Contains("Panel")))
                {
                    yPanel = int.Parse(y.Key.Categories.First(
                                           predicate: x => x.Contains("Panel")).Replace("Panel ", ""));
                }

                if (xPanel < yPanel)
                {
                    return(-1);
                }
                if (xPanel == yPanel)
                {
                    return(x.Key.IsBundle ? -1 : y.Key.IsBundle ? 1 :
                           x.Key.SortPriority > y.Key.SortPriority ? -1 :
                           x.Key.SortPriority == y.Key.SortPriority ? 0 : 1);
                }
                if (xPanel > yPanel)
                {
                    return(1);
                }
            }

            return(0);
        }