示例#1
0
        private Page FindOrCreateKeyValuePage(string collectionName)
        {
            var headerPage = this.DatabaseData.ReadFromDb(0);
            var pageId     = 0;

            GetWriteStore(headerPage, (store) =>
            {
                var locationKey = collectionName + "_location";
                if (!store.ContainsKey(locationKey))
                {
                    var newPage = new Page(PageKind.KeyValue);
                    this.DatabaseData.WriteToDb(newPage);

                    store[locationKey] = new BsonInteger(newPage.PageId);
                    pageId             = newPage.PageId;
                }
                else
                {
                    var entry = store[locationKey] as BsonInteger;
                    if (entry != null)
                    {
                        pageId = entry.Value;
                    }
                    else
                    {
                        throw new InvalidOperationException("Unexpected value type");
                    }
                }
            });

            return(this.DatabaseData.ReadFromDb(pageId));
        }
示例#2
0
        public void ToDictionary_WithElements_NotSameReferenceToValue()
        {
            var intValue = new BsonInteger(42);
            var doc      = new BsonDocument(
                new Element("foo", intValue));

            var actual = doc.ToDictionary();

            Assert.Single(actual);

            Assert.Equal(42, ((BsonInteger)actual["foo"]).Value);
        }
示例#3
0
        public void Constructor_CreatesElementsFromStringBsonValue()
        {
            var firstValue = new BsonString("bar");
            var secValue   = new BsonInteger(42);
            var doc        = new BsonDocument(new Dictionary <string, BsonValue> {
                { "foo", firstValue },
                { "2nd", secValue }
            });

            Assert.Equal(2, doc.Elements.Count);

            var dict = doc.ToDictionary();

            Assert.Equal(firstValue, dict["foo"]);
            Assert.Equal(secValue, dict["2nd"]);
        }
示例#4
0
 public void EqualOperator_EqualObjects_ReturnsExpectedValue(BsonInteger lhs, BsonInteger rhs, bool expectedValue)
 => Assert.Equal(expectedValue, lhs == rhs);