public void TestAdds()
        {
            BsonDocument doc = new BsonDocument();
            for(int i = 1; i < 6; i++){
                BsonElement be = new BsonElement(Convert.ToString(i),new BsonInteger(i));
                doc.Add(be.Name, be);
            }
            Assert.AreEqual(5,doc.Count,"Not all elements there");

            doc.Add(new BsonElement("6", new BsonInteger(6)));
            Assert.AreEqual(6,doc.Count,"Not all elements there");

            doc.Add("7", new BsonInteger(7));
            Assert.AreEqual(7,doc.Count,"Not all elements there");
        }
        public void TestOnlyNumericKeys()
        {
            bool thrown = false;
            BsonArray ba = new BsonArray();
            ba.Add("1","A");
            Assert.IsNotNull(ba["1"]);
            try {
                ba.Add("A","A");
            } catch (ArgumentOutOfRangeException) {
                thrown = true;
            }
            if(thrown != true) Assert.Fail("Exception should have been thrown");

            thrown = false;
            try {
                ba["A"] = new BsonElement("A", new BsonString("A"));
            } catch (ArgumentOutOfRangeException) {
                thrown = true;
            }
            if(thrown != true) Assert.Fail("Exception should have been thrown");
        }
 public void Add(BsonElement value)
 {
     this.Add(value.Name, value);
 }
 public virtual void Add( String key, BsonElement value )
 {
     if(orderedKeys.Contains(key)) throw new ArgumentException("Key already exists");
     this[key] = value;
 }
        public int Read(BsonReader reader)
        {
            int size = reader.ReadInt32();
            int bytesRead = 4;

            while(bytesRead + 1 < size){
                BsonElement be = new BsonElement();
                bytesRead += be.Read(reader);
                this.Add(be);
            }
            byte eoo = reader.ReadByte();
            bytesRead++;
            if(eoo != (byte)0) throw new System.IO.InvalidDataException("Document not null terminated");
            if(size != bytesRead) {
                throw new System.IO.InvalidDataException(string.Format("Should have read {0} bytes from stream but only read {1}]", size, bytesRead));
            }
            return bytesRead;
        }
 public BsonDocument Append(String key, BsonElement value)
 {
     this.Add(key,value);
     return this;
 }
Exemple #7
0
 public BsonDocument Append(int key, BsonElement value)
 {
     this.Add(key.ToString(),value);
     return this;
 }
Exemple #8
0
 public void Add(int key, BsonElement value)
 {
     this.Add(key.ToString(),value);
 }