public void AutoExpandToStringIndex() { DBObjectArray l = new DBObjectArray(); l["10"] = "test"; Assert.AreEqual(l["10"], "test"); Assert.AreEqual(l["3"], null); }
public void AutoExpandToIndex() { DBObjectArray l = new DBObjectArray(); l[10] = "test"; Assert.AreEqual(l[10], "test"); Assert.AreEqual(l[3], null); }
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); }
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"); }
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")); }
public void DBObjectArrayConstructorTest4() { int capacity = 3; DBObjectArray target = new DBObjectArray(capacity); target.Capacity.Should().Be(3); target.Count.Should().Be(0); }
public void NegativeStringIndex() { DBObjectArray l = new DBObjectArray(); Assert.That(()=> l["-10"] = "test", Throws.Exception); }
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(); }
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"); }
public void IsSynchronizedTest() { ICollection target = new DBObjectArray() as ICollection; target.IsSynchronized.Should().BeFalse(); }
public void IsReadOnlyTest1() { IList target = new DBObjectArray() as IList; target.IsReadOnly.Should().BeFalse(); }
public void IsFixedSizeTest() { IList target = new DBObjectArray() as IList; target.IsFixedSize.Should().BeFalse(); }
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); }
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); }
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); }
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); }
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); }
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"); }
public void SyncRootTest() { ICollection target = new DBObjectArray() as ICollection; target.SyncRoot.Should().NotBeNull(); }
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"); }
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}); }
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); }
public void AddTest3() { IList target = new DBObjectArray() as IList; DBObject a = new DBObject("add", "me"); target.Add(a); target.Count.Should().Be(1); }
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"); }
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"); }
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); }
public void NonIntegerStringIndex() { DBObjectArray l = new DBObjectArray(); Assert.That(()=> l[".003"] = "test", Throws.Exception); }
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); }
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} }; }
public void DBObjectArrayConstructorTest3() { DBObjectArray target = new DBObjectArray(); target.Count.Should().Be(0,"the default constructor defines no elements"); }