当前位置: 首页>>代码示例>>C#>>正文


C# ExpectedWriteConcernResult类代码示例

本文整理汇总了C#中ExpectedWriteConcernResult的典型用法代码示例。如果您正苦于以下问题:C# ExpectedWriteConcernResult类的具体用法?C# ExpectedWriteConcernResult怎么用?C# ExpectedWriteConcernResult使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


ExpectedWriteConcernResult类属于命名空间,在下文中一共展示了ExpectedWriteConcernResult类的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: TestCreateIndexTimeToLive

        public void TestCreateIndexTimeToLive()
        {
            if (_server.BuildInfo.Version >= new Version(2, 2))
            {
                _collection.DropAllIndexes();
                Assert.AreEqual(1, _collection.GetIndexes().Count());

                var keys = IndexKeys.Ascending("ts");
                var options = IndexOptions.SetTimeToLive(TimeSpan.FromHours(1));
                var result = _collection.CreateIndex(keys, options);

                var expectedResult = new ExpectedWriteConcernResult();
                CheckExpectedResult(expectedResult, result);

                var indexes = _collection.GetIndexes();
                Assert.AreEqual("_id_", indexes[0].Name);
                Assert.AreEqual("ts_1", indexes[1].Name);
                Assert.AreEqual(TimeSpan.FromHours(1), indexes[1].TimeToLive);
            }
        }
开发者ID:RepoCorp,项目名称:mongo-csharp-driver,代码行数:20,代码来源:MongoCollectionTests.cs

示例2: CheckExpectedResult

 // private methods
 private void CheckExpectedResult(ExpectedWriteConcernResult expectedResult, WriteConcernResult result)
 {
     Assert.AreEqual(expectedResult.DocumentsAffected ?? 0, result.DocumentsAffected);
     Assert.AreEqual(expectedResult.HasLastErrorMessage ?? false, result.HasLastErrorMessage);
     if (expectedResult.LastErrorMessage != null)
     {
         Assert.AreEqual(expectedResult.LastErrorMessage, result.LastErrorMessage);
     }
     Assert.AreEqual(expectedResult.Upserted, result.Upserted);
     Assert.AreEqual(expectedResult.UpdatedExisting ?? false, result.UpdatedExisting);
 }
开发者ID:RepoCorp,项目名称:mongo-csharp-driver,代码行数:12,代码来源:MongoCollectionTests.cs

示例3: TestCreateIndex

        public void TestCreateIndex()
        {
            var expectedIndexVersion = (_server.BuildInfo.Version >= new Version(2, 0, 0)) ? 1 : 0;

            _collection.Insert(new BsonDocument("x", 1));
            _collection.DropAllIndexes(); // doesn't drop the index on _id

            var indexes = _collection.GetIndexes().ToList();
            Assert.AreEqual(1, indexes.Count);
            Assert.AreEqual(false, indexes[0].DroppedDups);
            Assert.AreEqual(false, indexes[0].IsBackground);
            Assert.AreEqual(false, indexes[0].IsSparse);
            Assert.AreEqual(false, indexes[0].IsUnique);
            Assert.AreEqual(new BsonDocument("_id", 1), indexes[0].Key);
            Assert.AreEqual("_id_", indexes[0].Name);
            Assert.AreEqual(_collection.FullName, indexes[0].Namespace);
            Assert.AreEqual(expectedIndexVersion, indexes[0].Version);

            _collection.DropAllIndexes();
            var result = _collection.CreateIndex("x");

            var expectedResult = new ExpectedWriteConcernResult();
            CheckExpectedResult(expectedResult, result);

            indexes = _collection.GetIndexes().OrderBy(x => x.Name).ToList();
            Assert.AreEqual(2, indexes.Count);
            Assert.AreEqual(false, indexes[0].DroppedDups);
            Assert.AreEqual(false, indexes[0].IsBackground);
            Assert.AreEqual(false, indexes[0].IsSparse);
            Assert.AreEqual(false, indexes[0].IsUnique);
            Assert.AreEqual(new BsonDocument("_id", 1), indexes[0].Key);
            Assert.AreEqual("_id_", indexes[0].Name);
            Assert.AreEqual(_collection.FullName, indexes[0].Namespace);
            Assert.AreEqual(expectedIndexVersion, indexes[0].Version);
            Assert.AreEqual(false, indexes[1].DroppedDups);
            Assert.AreEqual(false, indexes[1].IsBackground);
            Assert.AreEqual(false, indexes[1].IsSparse);
            Assert.AreEqual(false, indexes[1].IsUnique);
            Assert.AreEqual(new BsonDocument("x", 1), indexes[1].Key);
            Assert.AreEqual("x_1", indexes[1].Name);
            Assert.AreEqual(_collection.FullName, indexes[1].Namespace);
            Assert.AreEqual(expectedIndexVersion, indexes[1].Version);

            _collection.DropAllIndexes();
            var options = IndexOptions.SetBackground(true).SetDropDups(true).SetSparse(true).SetUnique(true);
            result = _collection.CreateIndex(IndexKeys.Ascending("x").Descending("y"), options);

            expectedResult = new ExpectedWriteConcernResult();
            CheckExpectedResult(expectedResult, result);

            indexes = _collection.GetIndexes().OrderBy(x => x.Name).ToList();
            Assert.AreEqual(2, indexes.Count);
            Assert.AreEqual(false, indexes[0].DroppedDups);
            Assert.AreEqual(false, indexes[0].IsBackground);
            Assert.AreEqual(false, indexes[0].IsSparse);
            Assert.AreEqual(false, indexes[0].IsUnique);
            Assert.AreEqual(new BsonDocument("_id", 1), indexes[0].Key);
            Assert.AreEqual("_id_", indexes[0].Name);
            Assert.AreEqual(_collection.FullName, indexes[0].Namespace);
            Assert.AreEqual(expectedIndexVersion, indexes[0].Version);
            Assert.AreEqual(true, indexes[1].DroppedDups);
            Assert.AreEqual(true, indexes[1].IsBackground);
            Assert.AreEqual(true, indexes[1].IsSparse);
            Assert.AreEqual(true, indexes[1].IsUnique);
            Assert.AreEqual(new BsonDocument { { "x", 1 }, { "y", -1 } }, indexes[1].Key);
            Assert.AreEqual("x_1_y_-1", indexes[1].Name);
            Assert.AreEqual(_collection.FullName, indexes[1].Namespace);
            Assert.AreEqual(expectedIndexVersion, indexes[1].Version);
        }
开发者ID:RepoCorp,项目名称:mongo-csharp-driver,代码行数:69,代码来源:MongoCollectionTests.cs

示例4: TestUpsertExisting

        public void TestUpsertExisting()
        {
            _collection.Drop();
            _collection.Insert(new BsonDocument("x", 1));
            var result = _collection.Update(Query.EQ("x", 1), Update.Set("x", 2), UpdateFlags.Upsert);

            var expectedResult = new ExpectedWriteConcernResult
            {
                DocumentsAffected = 1,
                UpdatedExisting = true
            };
            CheckExpectedResult(expectedResult, result);

            var document = _collection.FindOne();
            Assert.AreEqual(2, document["x"].AsInt32);
            Assert.AreEqual(1, _collection.Count());
        }
开发者ID:RepoCorp,项目名称:mongo-csharp-driver,代码行数:17,代码来源:MongoCollectionTests.cs

示例5: TestUpsertInsert

        public void TestUpsertInsert()
        {
            _collection.Drop();
            var id = new BsonObjectId(ObjectId.GenerateNewId());
            var result = _collection.Update(Query.EQ("_id", id), Update.Set("x", 2), UpdateFlags.Upsert);

            var expectedResult = new ExpectedWriteConcernResult
            {
                DocumentsAffected = 1,
                Upserted = id
            };
            CheckExpectedResult(expectedResult, result);

            var document = _collection.FindOne();
            Assert.AreEqual(2, document["x"].AsInt32);
            Assert.AreEqual(1, _collection.Count());
        }
开发者ID:RepoCorp,项目名称:mongo-csharp-driver,代码行数:17,代码来源:MongoCollectionTests.cs

示例6: TestRemoveNoMatchingDocument

        public void TestRemoveNoMatchingDocument()
        {
            _collection.Drop();
            var result = _collection.Remove(Query.EQ("x", 1));

            var expectedResult = new ExpectedWriteConcernResult
            {
                UpdatedExisting = false
            };
            CheckExpectedResult(expectedResult, result);

            Assert.AreEqual(0, _collection.Count());
        }
开发者ID:RepoCorp,项目名称:mongo-csharp-driver,代码行数:13,代码来源:MongoCollectionTests.cs

示例7: TestUpdateNoMatchingDocument

        public void TestUpdateNoMatchingDocument()
        {
            _collection.Drop();
            var result = _collection.Update(Query.EQ("x", 1), Update.Set("x", 2));

            var expectedResult = new ExpectedWriteConcernResult
            {
                DocumentsAffected = 0
            };
            CheckExpectedResult(expectedResult, result);

            Assert.AreEqual(0, _collection.Count());
        }
开发者ID:RepoCorp,项目名称:mongo-csharp-driver,代码行数:13,代码来源:MongoCollectionTests.cs

示例8: TestLenientWrite

        public void TestLenientWrite()
        {
            var settings = new MongoCollectionSettings { WriteEncoding = new UTF8Encoding(false, false) };
            var collection = _database.GetCollection(Configuration.TestCollection.Name, settings);

            var document = new BsonDocument("x", "\udc00"); // invalid lone low surrogate
            var result = collection.Save(document);

            var expectedResult = new ExpectedWriteConcernResult();
            CheckExpectedResult(expectedResult, result);

            var rehydrated = collection.FindOne(Query.EQ("_id", document["_id"]));
            Assert.AreEqual("\ufffd", rehydrated["x"].AsString);
        }
开发者ID:RepoCorp,项目名称:mongo-csharp-driver,代码行数:14,代码来源:MongoCollectionTests.cs

示例9: TestRemove

        public void TestRemove()
        {
            _collection.Drop();
            _collection.Insert(new BsonDocument("x", 1));
            var result = _collection.Remove(Query.EQ("x", 1));

            var expectedResult = new ExpectedWriteConcernResult
            {
                DocumentsAffected = 1
            };
            CheckExpectedResult(expectedResult, result);

            Assert.AreEqual(0, _collection.Count());
        }
开发者ID:RepoCorp,项目名称:mongo-csharp-driver,代码行数:14,代码来源:MongoCollectionTests.cs

示例10: TestInsertDuplicateKey

        public void TestInsertDuplicateKey()
        {
            var collection = _database.GetCollection("duplicatekeys");
            collection.Drop();

            var result = collection.Insert(new BsonDocument("_id", 1));
            var expectedResult = new ExpectedWriteConcernResult();
            CheckExpectedResult(expectedResult, result);

            var exception = Assert.Throws<MongoDuplicateKeyException>(() => { collection.Insert(new BsonDocument("_id", 1)); });
            result = exception.WriteConcernResult;
            expectedResult = new ExpectedWriteConcernResult
            {
                HasLastErrorMessage = true
            };
            CheckExpectedResult(expectedResult, result);
        }
开发者ID:RepoCorp,项目名称:mongo-csharp-driver,代码行数:17,代码来源:MongoCollectionTests.cs

示例11: TestInsertBatchZeroDocuments

        public void TestInsertBatchZeroDocuments()
        {
            if (_primary.BuildInfo.Version >= new Version(2, 5, 5))
            {
                _collection.Drop();
                var results = _collection.InsertBatch(new BsonDocument[0]);
                var expectedResult = new ExpectedWriteConcernResult();
                CheckExpectedResult(expectedResult, results.Single());

                Assert.AreEqual(0, _collection.Count());
            }
        }
开发者ID:RepoCorp,项目名称:mongo-csharp-driver,代码行数:12,代码来源:MongoCollectionTests.cs

示例12: TestInsertBatchMultipleBatchesWriteConcernEnabledContinueOnErrorTrue

        public void TestInsertBatchMultipleBatchesWriteConcernEnabledContinueOnErrorTrue()
        {
            var collectionName = Configuration.TestCollection.Name;
            var collectionSettings = new MongoCollectionSettings { WriteConcern = WriteConcern.Acknowledged };
            var collection = Configuration.TestDatabase.GetCollection<BsonDocument>(collectionName, collectionSettings);
            if (collection.Exists()) { collection.Drop(); }

            using (Configuration.TestDatabase.RequestStart())
            {
                var maxMessageLength = Configuration.TestServer.RequestConnection.ServerInstance.MaxMessageLength;

                var filler = new string('x', maxMessageLength / 3); // after overhead results in two documents per sub-batch
                var documents = new BsonDocument[]
                {
                    // first sub-batch
                    new BsonDocument { { "_id", 1 }, { "filler", filler } },
                    new BsonDocument { { "_id", 2 }, { "filler", filler } },
                    // second sub-batch
                    new BsonDocument { { "_id", 3 }, { "filler", filler } },
                    new BsonDocument { { "_id", 3 }, { "filler", filler } }, // duplicate _id error
                    // third sub-batch
                    new BsonDocument { { "_id", 4 }, { "filler", filler } },
                    new BsonDocument { { "_id", 5 }, { "filler", filler } },
                };

                var options = new MongoInsertOptions { Flags = InsertFlags.ContinueOnError };
                var exception = Assert.Throws<MongoDuplicateKeyException>(() => { collection.InsertBatch(documents, options); });
                var result = exception.WriteConcernResult;

                var expectedResult = new ExpectedWriteConcernResult()
                {
                    HasLastErrorMessage = true
                };
                CheckExpectedResult(expectedResult, result);

                var results = ((IEnumerable<WriteConcernResult>)exception.Data["results"]).ToArray();
                if (results.Length == 3)
                {
                    Assert.AreEqual(false, results[0].HasLastErrorMessage);
                    Assert.AreEqual(true, results[1].HasLastErrorMessage);
                    Assert.AreEqual(false, results[2].HasLastErrorMessage);
                }
                else
                {
                    // it the opcode was emulated there will just be one synthesized result
                    Assert.AreEqual(1, results.Length);
                    Assert.AreEqual(true, results[0].HasLastErrorMessage);
                }

                Assert.AreEqual(1, collection.Count(Query.EQ("_id", 1)));
                Assert.AreEqual(1, collection.Count(Query.EQ("_id", 2)));
                Assert.AreEqual(1, collection.Count(Query.EQ("_id", 3)));
                Assert.AreEqual(1, collection.Count(Query.EQ("_id", 4)));
                Assert.AreEqual(1, collection.Count(Query.EQ("_id", 5)));
            }
        }
开发者ID:RepoCorp,项目名称:mongo-csharp-driver,代码行数:56,代码来源:MongoCollectionTests.cs

示例13: TestInsertBatchContinueOnError

        public void TestInsertBatchContinueOnError()
        {
            var collection = Configuration.TestCollection;
            collection.Drop();
            collection.CreateIndex(IndexKeys.Ascending("x"), IndexOptions.SetUnique(true));

            var batch = new BsonDocument[]
            {
                new BsonDocument("x", 1),
                new BsonDocument("x", 1), // duplicate
                new BsonDocument("x", 2),
                new BsonDocument("x", 2), // duplicate
                new BsonDocument("x", 3),
                new BsonDocument("x", 3) // duplicate
            };

            // try the batch without ContinueOnError
            var exception = Assert.Throws<MongoDuplicateKeyException>(() => collection.InsertBatch(batch));
            var result = exception.WriteConcernResult;

            var expectedResult = new ExpectedWriteConcernResult
            {
                HasLastErrorMessage = true
            };
            CheckExpectedResult(expectedResult, result);

            Assert.AreEqual(1, collection.Count());
            Assert.AreEqual(1, collection.FindOne()["x"].AsInt32);

            // try the batch again with ContinueOnError
            if (_server.BuildInfo.Version >= new Version(2, 0, 0))
            {
                var options = new MongoInsertOptions { Flags = InsertFlags.ContinueOnError };
                exception = Assert.Throws<MongoDuplicateKeyException>(() => collection.InsertBatch(batch, options));
                result = exception.WriteConcernResult;

                expectedResult = new ExpectedWriteConcernResult
                {
                    HasLastErrorMessage = true
                };
                CheckExpectedResult(expectedResult, result);

                Assert.AreEqual(3, collection.Count());
            }
        }
开发者ID:RepoCorp,项目名称:mongo-csharp-driver,代码行数:45,代码来源:MongoCollectionTests.cs

示例14: TestUpdate

        public void TestUpdate()
        {
            _collection.Drop();
            _collection.Insert(new BsonDocument("x", 1));
            var options = new MongoUpdateOptions { BypassDocumentValidation = true };

            var result = _collection.Update(Query.EQ("x", 1), Update.Set("x", 2), options);

            var expectedResult = new ExpectedWriteConcernResult
            {
                DocumentsAffected = 1,
                UpdatedExisting = true
            };
            CheckExpectedResult(expectedResult, result);

            var document = _collection.FindOne();
            Assert.Equal(2, document["x"].AsInt32);
            Assert.Equal(1, _collection.Count());
        }
开发者ID:RavenZZ,项目名称:MDRelation,代码行数:19,代码来源:MongoCollectionTests.cs


注:本文中的ExpectedWriteConcernResult类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。