public void CopyToTest()
 {
     for (int y = 1900; y < 2123; y++) {
         var values = CreateZmanim(y);
         var array = new KeyValuePair<DateTime, ZmanimInfo>[values.Length + 33];
         new YearlyZmanimDictionary(y, values).CopyTo(array, 33);
         Assert.IsTrue(array.Skip(33).Select(kvp => kvp.Value).SequenceEqual(values));
         Assert.IsTrue(array.Skip(33).All(kvp => kvp.Key == kvp.Value.Date));
     }
 }
 public void CopyToTest()
 {
     for (int y = 1900; y < 2123; y++)
     {
         var values = CreateZmanim(y);
         var array  = new KeyValuePair <DateTime, ZmanimInfo> [values.Length + 33];
         new YearlyZmanimDictionary(y, values).CopyTo(array, 33);
         Assert.IsTrue(array.Skip(33).Select(kvp => kvp.Value).SequenceEqual(values));
         Assert.IsTrue(array.Skip(33).All(kvp => kvp.Key == kvp.Value.Date));
     }
 }
Ejemplo n.º 3
0
        public void CopyTo_IndexNonZero_ValuesCopied()
        {
            Trie <string, char, int> trie = new Trie <string, char, int>();

            trie.Add("key1", 5);
            trie.Add("key2", 6);

            KeyValuePair <string, int>[] vals = new KeyValuePair <string, int> [4];
            trie.CopyTo(vals, 2);

            Assert.AreEqual(0, vals[0].Value);
            Assert.AreEqual(0, vals[1].Value);
            Assert.IsTrue(vals.Skip(2).Any(k => k.Key == "key1" && k.Value == 5));
            Assert.IsTrue(vals.Skip(2).Any(k => k.Key == "key2" && k.Value == 6));
        }
Ejemplo n.º 4
0
        public void CopyToTest()
        {
            var tree = new ShieldedTree <int, object>();

            ParallelEnumerable.Range(1, 1000).ForAll(
                i => Shield.InTransaction(() => tree.Add(i, new object())));
            Assert.AreEqual(1000, tree.Count);

            var array = new KeyValuePair <int, object> [1100];

            ((ICollection <KeyValuePair <int, object> >)tree).CopyTo(array, 100);

            Shield.InTransaction(() =>
                                 Assert.IsTrue(array.Skip(100).SequenceEqual(tree)));
        }
Ejemplo n.º 5
0
        public void CopyToTest()
        {
            var dict = new ShieldedDict <int, object>(
                Enumerable.Range(1, 1000).Select(i =>
                                                 new KeyValuePair <int, object>(i, new object())).ToArray());

            Assert.AreEqual(1000, dict.Count);

            var array = new KeyValuePair <int, object> [1100];

            // this works out of transaction (and consequently, so do ToArray and ToList), by opening
            // a transaction itself. that could not be done when you do a foreach.
            ((ICollection <KeyValuePair <int, object> >)dict).CopyTo(array, 100);

            Assert.IsTrue(array.Skip(100).OrderBy(kvp => kvp.Key).SequenceEqual(dict.OrderBy(kvp => kvp.Key)));
        }
Ejemplo n.º 6
0
        public void CopyToTest()
        {
            var tree = new ShieldedTree <int, object>();

            ParallelEnumerable.Range(1, 1000).ForAll(
                i => Shield.InTransaction(() => tree.Add(i, new object())));
            Assert.AreEqual(1000, tree.Count);

            var array = new KeyValuePair <int, object> [1100];

            ((ICollection <KeyValuePair <int, object> >)tree).CopyTo(array, 100);
            var expected = 1;

            foreach (var kvp in array.Skip(100))
            {
                Assert.IsTrue(tree.ContainsKey(kvp.Key));
                Assert.AreEqual(expected, kvp.Key);
                Assert.AreEqual(tree[kvp.Key], kvp.Value);
                expected++;
            }
        }
        public void CopyTo_ShouldCopyItemsToArray()
        {
            // Arrange
            var prefix = GetRandomString(3) + ":";
            var data   = MakeRandomData(prefix);
            var offset = GetRandomInt();
            var target = new KeyValuePair <string, object> [data.Count + offset];
            var sut    = Create(data, s => prefix + s, s => s.RegexReplace($"^{prefix}", ""));

            // Pre-Assert

            // Act
            sut.CopyTo(target, offset);

            // Assert
            target.Skip(offset)
            .ForEach(kvp =>
            {
                Expect(sut).To.Contain(kvp);
            });
        }
Ejemplo n.º 8
0
        public void TestCopyToCopiesAllValuesIntoMiddleOfArray()
        {
            var dict = new Dictionary <int, string>()
            {
                { 1, "One" },
                { 2, "Two" },
                { 3, "Three" }
            };

            IDictionary <int, string> toTest = new ReadOnlyDictionary <int, string>(dict);

            Assert.IsTrue(toTest.IsReadOnly);

            var copy = new KeyValuePair <int, string> [7];

            toTest.CopyTo(copy, 2);

            Assert.AreEqual(default(KeyValuePair <int, string>), copy[0]);
            Assert.AreEqual(default(KeyValuePair <int, string>), copy[1]);
            Assert.AreEqual(default(KeyValuePair <int, string>), copy[5]);
            Assert.AreEqual(default(KeyValuePair <int, string>), copy[6]);
            Assert.IsTrue(copy.Skip(2).Take(3).OrderBy(kv => kv.Key).SequenceEqual(dict.OrderBy(kv => kv.Key)));
        }
Ejemplo n.º 9
0
        public void CopyToTest()
        {
            var tree = new ShieldedTree<int, object>();
            ParallelEnumerable.Range(1, 1000).ForAll(
                i => Shield.InTransaction(() => tree.Add(i, new object())));
            Assert.AreEqual(1000, tree.Count);

            var array = new KeyValuePair<int, object>[1100];
            ((ICollection<KeyValuePair<int, object>>)tree).CopyTo(array, 100);
            var expected = 1;
            foreach (var kvp in array.Skip(100))
            {
                Assert.IsTrue(tree.ContainsKey(kvp.Key));
                Assert.AreEqual(expected, kvp.Key);
                Assert.AreEqual(tree[kvp.Key], kvp.Value);
                expected++;
            }
        }
Ejemplo n.º 10
0
        public void CopyToTest()
        {
            var dict = new ShieldedDict<int, object>(
                Enumerable.Range(1, 1000).Select(i =>
                    new KeyValuePair<int, object>(i, new object())).ToArray());
            Assert.AreEqual(1000, dict.Count);

            var array = new KeyValuePair<int, object>[1100];
            // this works out of transaction (and consequently, so do ToArray and ToList), by opening
            // a transaction itself. that could not be done when you do a foreach.
            ((ICollection<KeyValuePair<int, object>>)dict).CopyTo(array, 100);
            var keys = new HashSet<int>();
            foreach (var kvp in array.Skip(100))
            {
                Assert.IsTrue(dict.ContainsKey(kvp.Key));
                Assert.IsTrue(keys.Add(kvp.Key));
                Assert.AreEqual(dict[kvp.Key], kvp.Value);
            }
        }
Ejemplo n.º 11
0
        public void ParametersFacadeTests()
        {
            var testRequest     = new Amazon.DynamoDBv2.Model.ListTablesRequest();
            var testServiceName = "DDB";

            var irequest = new DefaultRequest(testRequest, testServiceName);

            irequest.Parameters.Add("param1", "paramValue1");
            irequest.ParameterCollection.Add("param2", "paramValue2");
            irequest.ParameterCollection.Add("param3", new List <string> {
                "listValue1", "listValue2"
            });
            irequest.ParameterCollection.Add("param4", new List <string> {
                "listValue4", "listValue3"
            });

            var collection = irequest.ParameterCollection;
            var dictionary = irequest.Parameters as ParametersDictionaryFacade;

            Assert.IsNotNull(dictionary);

            // Add (string, string)
            dictionary.Add("newParam1", "newParamValue1");
            TestParamValue(collection, "newParam1", expectString: true, expectedValue: "newParamValue1");

            // Count
            Assert.AreEqual(5, collection.Count);
            Assert.AreEqual(collection.Count, dictionary.Count);

            // ContainsKey
            Assert.IsTrue(dictionary.ContainsKey("newParam1"));
            Assert.IsFalse(dictionary.ContainsKey("newParam2"));

            // Remove (key)
            Assert.IsTrue(dictionary.Remove("newParam1"));
            Assert.IsFalse(dictionary.Remove("newParam2"));

            // index accessor
            Assert.AreEqual("paramValue2", dictionary["param2"]);
            Utils.AssertExceptionExpected(() =>
            {
                var tempValue = dictionary["param99"];
            });
            Assert.AreEqual("[\"listValue1\",\"listValue2\"]", dictionary["param3"]);
            Assert.AreEqual("[\"listValue4\",\"listValue3\"]", dictionary["param4"]);

            // Keys
            CollectionAssert.AreEqual(new List <string> {
                "param1", "param2", "param3", "param4"
            }, dictionary.Keys.ToList());

            // TryGetValue
            string stringValue;

            Assert.IsTrue(dictionary.TryGetValue("param1", out stringValue));
            Assert.AreEqual("paramValue1", stringValue);
            Assert.IsFalse(dictionary.TryGetValue("param99", out stringValue));

            // Remove (KeyValuePair)
            Assert.IsFalse(dictionary.Remove(new KeyValuePair <string, string>("param4", "[\"listValue4\", \"listValue3\"]")));
            Assert.IsTrue(dictionary.Remove(new KeyValuePair <string, string>("param4", "[\"listValue4\",\"listValue3\"]")));

            // Values
            CollectionAssert.AreEqual(new List <string> {
                "paramValue1", "paramValue2", "[\"listValue1\",\"listValue2\"]"
            }, dictionary.Values.ToList());

            // Add (KeyValuePair)
            dictionary.Add(new KeyValuePair <string, string>("newParam3", "newParamValue3"));
            TestParamValue(collection, "newParam3", expectString: true, expectedValue: "newParamValue3");

            // Contains
            Assert.IsTrue(dictionary.Contains(new KeyValuePair <string, string>("param1", "paramValue1")));
            Assert.IsTrue(dictionary.Contains(new KeyValuePair <string, string>("param3", "[\"listValue1\",\"listValue2\"]")));

            // IsReadOnly
            Assert.IsFalse(dictionary.IsReadOnly);

            var currentKeyValuePairs = new List <KeyValuePair <string, string> >
            {
                new KeyValuePair <string, string>("newParam3", "newParamValue3"),
                new KeyValuePair <string, string>("param1", "paramValue1"),
                new KeyValuePair <string, string>("param2", "paramValue2"),
                new KeyValuePair <string, string>("param3", "[\"listValue1\",\"listValue2\"]"),
            };

            // GetEnumerator
            var genericEnumerator = dictionary.GetEnumerator();
            var parameterList     = ToIEnumerable <KeyValuePair <string, string> >(genericEnumerator).ToList();

            CollectionAssert.AreEqual(currentKeyValuePairs, parameterList);

            // System.Collections.IEnumerable.GetEnumerator
            var enumerator = (dictionary as IEnumerable).GetEnumerator();

            parameterList = ToIEnumerable <KeyValuePair <string, string> >(enumerator).ToList();
            CollectionAssert.AreEqual(currentKeyValuePairs, parameterList);

            // CopyTo
            var tooSmallArray = new KeyValuePair <string, string> [1];

            Utils.AssertExceptionExpected(() => dictionary.CopyTo(tooSmallArray, 0));

            var largeArray = new KeyValuePair <string, string> [10];

            dictionary.CopyTo(largeArray, 0);
            CollectionAssert.AreEqual(currentKeyValuePairs, largeArray.Take(4).ToList());

            largeArray = new KeyValuePair <string, string> [10];
            dictionary.CopyTo(largeArray, 3);
            CollectionAssert.AreEqual(currentKeyValuePairs, largeArray.Skip(3).Take(4).ToList());

            // Clear
            dictionary.Clear();
            Assert.AreEqual(0, dictionary.Count);
            Assert.AreEqual(0, collection.Count);
        }
Ejemplo n.º 12
0
        public void CopyTo_IndexNonZero_ValuesCopied()
        {
            Trie<string, char, int> trie = new Trie<string, char, int>();

            trie.Add("key1", 5);
            trie.Add("key2", 6);

            KeyValuePair<string, int>[] vals = new KeyValuePair<string, int>[4];
            trie.CopyTo(vals, 2);

            Assert.AreEqual(0, vals[0].Value);
            Assert.AreEqual(0, vals[1].Value);
            Assert.IsTrue(vals.Skip(2).Any(k => k.Key == "key1" && k.Value == 5));
            Assert.IsTrue(vals.Skip(2).Any(k => k.Key == "key2" && k.Value == 6));
        }