コード例 #1
0
 public void AutoExpandToStringIndex()
 {
     DBObjectArray l = new DBObjectArray();
     l["10"] = "test";
     Assert.AreEqual(l["10"], "test");
     Assert.AreEqual(l["3"], null);
 }
コード例 #2
0
 public void AutoExpandToIndex()
 {
     DBObjectArray l = new DBObjectArray();
     l[10] = "test";
     Assert.AreEqual(l[10], "test");
     Assert.AreEqual(l[3], null);
 }
コード例 #3
0
 public void AddTest2()
 {
     DBObjectArray target = new DBObjectArray();
     DBObject a = new DBObject("add", "me");
     target.Add(new KeyValuePair<string, object>("0", a));
     new Action(() => target.Add(new KeyValuePair<string, object>("a", a))).ShouldThrow<Exception>();
     target.Count.Should().Be(1);
 }
コード例 #4
0
 public void AddTest1()
 {
     DBObjectArray target = new DBObjectArray();
     DBObject a = new DBObject("add", "me");
     target.Add("0", a);
     target.Count.Should().Be(1);
     new Action(() => target.Add("a", a)).ShouldThrow<ArgumentException>("index/key must be numeric");
 }
コード例 #5
0
        public void RoundTrip()
        {
            IDBCollection c = Mongo.DefaultDatabase.GetCollection("dblist");
            c.Drop();

            DBObjectArray l = new DBObjectArray();
            l[0] = "a";
            l[1] = "b";
            l[2] = "c";

            c.Insert(new Document() { { "array", l } });
            IDBObject obj = c.FindOne();
            Assert.That(obj.GetAsIDBObject("array")["0"], Is.EqualTo("a"));
            Assert.That(obj.GetAsIDBObject("array")["1"], Is.EqualTo("b"));
            Assert.That(obj.GetAsIDBObject("array")["2"], Is.EqualTo("c"));
        }
コード例 #6
0
 public void DBObjectArrayConstructorTest4()
 {
     int capacity = 3;
     DBObjectArray target = new DBObjectArray(capacity);
     target.Capacity.Should().Be(3);
     target.Count.Should().Be(0);
 }
コード例 #7
0
 public void NegativeStringIndex()
 {
     DBObjectArray l = new DBObjectArray();
     Assert.That(()=> l["-10"] = "test", Throws.Exception);
 }
コード例 #8
0
        public void TryGetValueTest()
        {
            DBObject a = new DBObject();
            DBObject b = new DBObject("a", 7);
            DBObject c = new DBObject("78", "car");
            DBObjectArray target = new DBObjectArray(a, b, c);

            object result = null;
            target.TryGetValue("0", out result).Should().BeTrue();
            result.Should().Be(a);
            target.TryGetValue("30", out result).Should().BeFalse();
            target.TryGetValue("a", out result).Should().BeFalse();
        }
コード例 #9
0
        public void RoundTrip()
        {
            IDBCollection c = Mongo.DefaultDatabase.GetCollection("dblist");
            c.Drop();

            DBObjectArray l = new DBObjectArray();
            l[0] = "a";
            l[1] = "b";
            l[2] = "c";

            c.Insert(new Document() { { "array", l } });
            IDBObject obj = c.FindOne();
            obj.Should().NotBeNull("we added a document");
            obj.GetAsIDBObject("array").Should().NotBeNull("we sent a nested array");
            obj.GetAsIDBObject("array")["0"].Should().Be("a");
            obj.GetAsIDBObject("array")["1"].Should().Be("b");
            obj.GetAsIDBObject("array")["2"].Should().Be("c");
        }
コード例 #10
0
 public void IsSynchronizedTest()
 {
     ICollection target = new DBObjectArray() as ICollection;
     target.IsSynchronized.Should().BeFalse();
 }
コード例 #11
0
 public void IsReadOnlyTest1()
 {
     IList target = new DBObjectArray() as IList;
     target.IsReadOnly.Should().BeFalse();
 }
コード例 #12
0
 public void IsFixedSizeTest()
 {
     IList target = new DBObjectArray() as IList;
     target.IsFixedSize.Should().BeFalse();
 }
コード例 #13
0
 public void InsertTest1()
 {
     DBObject a = new DBObject();
     DBObject b = new DBObject("a", 7);
     DBObject c = new DBObject("78", "car");
     IList target = new DBObjectArray(a, c) as IList;
     target.Insert(1, b);
     target.IndexOf(b).Should().Be(1);
 }
コード例 #14
0
 public void InsertTest()
 {
     DBObject a = new DBObject();
     DBObject b = new DBObject("a", 7);
     DBObject c = new DBObject("78", "car");
     DBObjectArray target = new DBObjectArray(a, c);
     target.IndexOf(a).Should().Be(0);
     target.IndexOf(c).Should().Be(1);
     target.Insert(1, b);
     target.IndexOf(a).Should().Be(0);
     target.IndexOf(b).Should().Be(1);
     target.IndexOf(c).Should().Be(2);
     target.Count.Should().Be(3);
 }
コード例 #15
0
 public void GetEnumeratorTest1()
 {
     DBObject a = new DBObject();
     DBObject b = new DBObject("a", 7);
     DBObject c = new DBObject("78", "car");
     DBObjectArray target = new DBObjectArray(a, b, c);
     //Use enumerator to fill list
     List<object> list = new List<object>(target);
     list[0].Should().Be(a);
     list[1].Should().Be(b);
     list[2].Should().Be(c);
 }
コード例 #16
0
 public void DBObjectArrayConstructorTest5()
 {
     DBObject a = new DBObject();
     DBObject b = new DBObject("a", 7);
     DBObject c = new DBObject("78", "car");
     DBObjectArray target = new DBObjectArray(a, b, c);
     target.IndexOf(a).Should().Be(0);
     target.IndexOf(b).Should().Be(1);
     target.IndexOf(c).Should().Be(2);
     target.Count.Should().Be(3);
 }
コード例 #17
0
 public void RemoveTest3()
 {
     DBObject a = new DBObject();
     DBObject b = new DBObject("a", 7);
     DBObject c = new DBObject("78", "car");
     IList target = new DBObjectArray(a, b, c) as IList;
     target.Remove(b);
     target.IndexOf(c).Should().Be(1);
     target.Count.Should().Be(2);
 }
コード例 #18
0
        public void ItemTest()
        {
            DBObjectArray l = new DBObjectArray();
            l["0"] = "zero";
            l["0"].Should().Be("zero", "we just set it");
            l["10"] = "test";
            l["10"].Should().Be("test", "we just set it");
            l["3"].Should().BeNull("we expanded to a size of 10, and size was 0. All inbetween should be null.");

            Action<string> accessor = s => new DBObjectArray()[s] = "test";

            "-10".Invoking(accessor).ShouldThrow<Exception>("string index is negative");
            ".003".Invoking(accessor).ShouldThrow<Exception>("string index is not an integer");
        }
コード例 #19
0
 public void SyncRootTest()
 {
     ICollection target = new DBObjectArray() as ICollection;
     target.SyncRoot.Should().NotBeNull();
 }
コード例 #20
0
        public void ItemTest1()
        {
            DBObjectArray l = new DBObjectArray();
            l[0] = "zero";
            l[0].Should().Be("zero", "we just set it");
            l[10] = "test";
            l[10].Should().Be("test", "we just set it");
            l[1].Should().BeNull("we expanded to a size of 10, and size was 0. All inbetween should be null.");

            Action<int> accessor = i => new DBObjectArray()[i] = "test";

            ((Int32)(-10)).Invoking(accessor).ShouldThrow<Exception>("string index is negative");
        }
コード例 #21
0
 public void ValuesTest()
 {
     DBObject a = new DBObject();
     DBObject b = new DBObject("a", 7);
     DBObject c = new DBObject("78", "car");
     DBObjectArray target = new DBObjectArray(a,b,c);
     target.Values.Should().ContainInOrder(new object[] {a, b, c});
 }
コード例 #22
0
 public void ItemTest2()
 {
     DBObject a = new DBObject();
     DBObject b = new DBObject("a", 7);
     DBObject c = new DBObject("78", "car");
     IList target = new DBObjectArray(a) as IList;
     target[2] = c;
     target[1] = b;
     target[0].Should().Be(a);
     target[1].Should().Be(b);
     target[2].Should().Be(c);
 }
コード例 #23
0
 public void AddTest3()
 {
     IList target = new DBObjectArray() as IList;
     DBObject a = new DBObject("add", "me");
     target.Add(a);
     target.Count.Should().Be(1);
 }
コード例 #24
0
 public void KeysTest()
 {
     DBObject a = new DBObject();
     DBObject b = new DBObject("a", 7);
     DBObject c = new DBObject("78", "car");
     DBObjectArray target = new DBObjectArray(a, b, c);
     target.Keys.Should().Contain("0", "1", "2");
 }
コード例 #25
0
        public void PutAllTest()
        {
            DBObject a = new DBObject();
            DBObject b = new DBObject("a", 7);
            DBObject c = new DBObject("78", "car");
            DBObjectArray target = new DBObjectArray();
            IDictionary<string, object> map = new Dictionary<string, object>() { { "0", a }, { "1", b }, { "2", c } };
            target.PutAll(map);
            target.IndexOf(a).Should().Be(0);
            target.IndexOf(b).Should().Be(1);
            target.IndexOf(c).Should().Be(2);
            target.Count.Should().Be(3);

            new Action(() => target.PutAll(new Dictionary<string, object>() { { "a", a } })).ShouldThrow<Exception>("index/key must be an integer");
        }
コード例 #26
0
 public void RemoveTest1()
 {
     DBObject a = new DBObject();
     DBObject b = new DBObject("a", 7);
     DBObject c = new DBObject("78", "car");
     DBObjectArray target = new DBObjectArray(a, b, c);
     target.IndexOf(a).Should().Be(0);
     target.IndexOf(b).Should().Be(1);
     target.IndexOf(c).Should().Be(2);
     target.Count.Should().Be(3);
     target.Remove("1");
     target.IndexOf(a).Should().Be(0);
     target.IndexOf(c).Should().Be(1);
     target.Count.Should().Be(2);
 }
コード例 #27
0
 public void NonIntegerStringIndex()
 {
     DBObjectArray l = new DBObjectArray();
     Assert.That(()=> l[".003"] = "test", Throws.Exception);
 }
コード例 #28
0
 public void RemoveTest2()
 {
     DBObject a = new DBObject();
     DBObject b = new DBObject("a", 7);
     DBObject c = new DBObject("78", "car");
     DBObjectArray target = new DBObjectArray(a, b, c);
     target.IndexOf(a).Should().Be(0);
     target.IndexOf(b).Should().Be(1);
     target.IndexOf(c).Should().Be(2);
     target.Count.Should().Be(3);
     target.Remove(new KeyValuePair<string, object>("1",b));
     target.IndexOf(a).Should().Be(0);
     target.IndexOf(c).Should().Be(1);
     target.Count.Should().Be(2);
 }
コード例 #29
0
        private static void setup()
        {
            small = new DBObject();

            DBObjectArray a = new DBObjectArray();
            a["0"] = "test";
            a["1"] = "benchmark";
            medium = new DBObject() {
                {"integer", 5},
                {"number", 5.05},
                {"bool", false},
                {"array", a},
                };

            DBObjectArray harvest = new DBObjectArray();
            for (int test = 0; test < 20; test++)
            {
                harvest[test * 14 + 0] = "10gen";
                harvest[test * 14 + 1] = "web";
                harvest[test * 14 + 2] = "open";
                harvest[test * 14 + 3] = "source";
                harvest[test * 14 + 4] = "application";
                harvest[test * 14 + 5] = "paas";
                harvest[test * 14 + 6] = "platform-as-a-service";
                harvest[test * 14 + 7] = "technology";
                harvest[test * 14 + 8] = "helps";
                harvest[test * 14 + 9] = "developers";
                harvest[test * 14 + 10] = "focus";
                harvest[test * 14 + 11] = "building";
                harvest[test * 14 + 12] = "mongodb";
                harvest[test * 14 + 13] = "mongo";
            }
            large = new DBObject()
            {
                {"base_url", "http://www.example.com/test-me"},
                {"total_word_count", 6743},
                {"access_time", new DateTime()},
                {"meta_tags", new DBObject() {
                     {"description", "test am a long description string"},
                     {"author", "Holly Man"},
                     {"dynamically_created_meta_tag", "who know\n what"}}},
                {"page_structure", new DBObject() {
                     {"counted_tags", 3450},
                     {"no_of_js_attached", 10},
                     {"no_of_images", 6}}},
                {"harvested_words", harvest}
            };
        }
コード例 #30
0
 public void DBObjectArrayConstructorTest3()
 {
     DBObjectArray target = new DBObjectArray();
     target.Count.Should().Be(0,"the default constructor defines no elements");
 }