Beispiel #1
0
        public void CanAddOneRandomRecord()
        {
            var collection = _db.GetCollection <SquatchTestObject>("TestObjects");
            var item       = new SquatchTestObject()
            {
                Message = "This is a random test: " + Guid.NewGuid().ToString(),
                V       = 1
            };

            var result = collection.Insert(item);

            item.Id.ShouldNotBe(ObjectId.Empty);
        }
Beispiel #2
0
        public void CanCreateUpdateAndDeleteAllInOneMassiveMethod()
        {
            string updateMessage = "This is an update";

            var collection = _db.GetCollection <SquatchTestObject>("TestObjects");
            var item       = new SquatchTestObject()
            {
                Message = "This is a random test: " + Guid.NewGuid().ToString(),
                V       = 1
            };

            // Add
            collection.Insert(item);

            // Find
            var query = Query <SquatchTestObject> .EQ(e => e.Id, item.Id);

            var entity = collection.FindOne(query);

            entity.Message.ShouldBe(item.Message);

            // Update
            var changeMessageUpdate = Update <SquatchTestObject> .Set(e => e.Message, updateMessage).Set(e => e.V, 2);

            collection.Update(query, changeMessageUpdate);

            // Check update was written
            var secondFind = collection.FindOne(query);

            secondFind.Message.ShouldBe(updateMessage);
            secondFind.V.ShouldBe(2);

            // Delete
            collection.Remove(query);
            var gone = collection.FindOne(query);

            Assert.IsNull(gone);
        }