本文整理汇总了C#中MongoDB.Driver.MongoCollectionSettings类的典型用法代码示例。如果您正苦于以下问题:C# MongoCollectionSettings类的具体用法?C# MongoCollectionSettings怎么用?C# MongoCollectionSettings使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
MongoCollectionSettings类属于MongoDB.Driver命名空间,在下文中一共展示了MongoCollectionSettings类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TestConstructorArgumentChecking
public void TestConstructorArgumentChecking()
{
var settings = new MongoCollectionSettings<BsonDocument>(_database, "");
Assert.Throws<ArgumentNullException>(() => { new MongoCollection<BsonDocument>(null, settings); });
Assert.Throws<ArgumentNullException>(() => { new MongoCollection<BsonDocument>(_database, null); });
Assert.Throws<ArgumentOutOfRangeException>(() => { new MongoCollection<BsonDocument>(_database, settings); });
}
示例2: CSharp714Tests
public CSharp714Tests()
{
_database = LegacyTestConfiguration.Database;
var collectionSettings = new MongoCollectionSettings() { GuidRepresentation = GuidRepresentation.Standard };
_collection = _database.GetCollection<C>("csharp714", collectionSettings);
_collection.Drop();
}
示例3: TestEquals
public void TestEquals()
{
var settings = new MongoCollectionSettings();
var clone = settings.Clone();
Assert.IsTrue(clone.Equals(settings));
settings.Freeze();
clone.Freeze();
Assert.IsTrue(clone.Equals(settings));
clone = settings.Clone();
clone.AssignIdOnInsert = !clone.AssignIdOnInsert;
Assert.IsFalse(clone.Equals(settings));
clone = settings.Clone();
clone.GuidRepresentation = GuidRepresentation.PythonLegacy;
Assert.IsFalse(clone.Equals(settings));
clone = settings.Clone();
clone.ReadPreference = ReadPreference.Secondary;
Assert.IsFalse(clone.Equals(settings));
clone = settings.Clone();
clone.WriteConcern = WriteConcern.W2;
Assert.IsFalse(clone.Equals(settings));
}
示例4: CollectionSettings
public static MongoCollectionSettings CollectionSettings()
{
var collectionSettings = new MongoCollectionSettings();
collectionSettings.WriteConcern = WriteConcern.WMajority;
return collectionSettings;
}
示例5: TestAll
public void TestAll()
{
var settings = new MongoCollectionSettings<BsonDocument>(
"collection",
true, // asssignIdOnInsert
SafeMode.Create(5, TimeSpan.FromSeconds(5)),
true // slaveOkd
);
Assert.AreEqual("collection", settings.CollectionName);
Assert.AreEqual(true, settings.AssignIdOnInsert);
Assert.AreEqual(typeof(BsonDocument), settings.DefaultDocumentType);
Assert.AreEqual(SafeMode.Create(5, TimeSpan.FromSeconds(5)), settings.SafeMode);
Assert.AreEqual(true, settings.SlaveOk);
Assert.IsFalse(settings.IsFrozen);
var hashCode = settings.GetHashCode();
var stringRepresentation = settings.ToString();
Assert.AreEqual(settings, settings);
settings.Freeze();
Assert.IsTrue(settings.IsFrozen);
Assert.AreEqual(hashCode, settings.GetHashCode());
Assert.AreEqual(stringRepresentation, settings.ToString());
}
示例6: TestFixtureSetup
public void TestFixtureSetup()
{
_database = Configuration.TestDatabase;
var collectionSettings = new MongoCollectionSettings() { GuidRepresentation = GuidRepresentation.Standard };
_collection = _database.GetCollection<C>("csharp714", collectionSettings);
_collection.Drop();
}
示例7: TestAll
public void TestAll()
{
var server = MongoServer.Create();
var database = server["test"];
var settings = new MongoCollectionSettings<BsonDocument>(database, "collection")
{
AssignIdOnInsert = true,
SafeMode = SafeMode.Create(5, TimeSpan.FromSeconds(5)),
SlaveOk = true
};
Assert.AreEqual("collection", settings.CollectionName);
Assert.AreEqual(true, settings.AssignIdOnInsert);
Assert.AreEqual(typeof(BsonDocument), settings.DefaultDocumentType);
Assert.AreEqual(GuidRepresentation.CSharpLegacy, settings.GuidRepresentation);
Assert.AreEqual(SafeMode.Create(5, TimeSpan.FromSeconds(5)), settings.SafeMode);
Assert.AreEqual(true, settings.SlaveOk);
Assert.IsFalse(settings.IsFrozen);
var hashCode = settings.GetHashCode();
var stringRepresentation = settings.ToString();
Assert.AreEqual(settings, settings);
settings.Freeze();
Assert.IsTrue(settings.IsFrozen);
Assert.AreEqual(hashCode, settings.GetHashCode());
Assert.AreEqual(stringRepresentation, settings.ToString());
}
示例8: TestAll
public void TestAll()
{
var settings = new MongoCollectionSettings();
settings.CollectionName = "collection";
settings.AssignIdOnInsert = false;
settings.SafeMode = SafeMode.Create(5, TimeSpan.FromSeconds(5));
settings.SlaveOk = true;
Assert.AreEqual("collection", settings.CollectionName);
Assert.AreEqual(false, settings.AssignIdOnInsert);
Assert.AreEqual(SafeMode.Create(5, TimeSpan.FromSeconds(5)), settings.SafeMode);
Assert.AreEqual(true, settings.SlaveOk);
Assert.IsFalse(settings.IsFrozen);
var hashCode = settings.GetHashCode();
var stringRepresentation = settings.ToString();
Assert.AreEqual(settings, settings);
settings.Freeze();
Assert.IsTrue(settings.IsFrozen);
Assert.AreEqual(hashCode, settings.GetHashCode());
Assert.AreEqual(stringRepresentation, settings.ToString());
var clone = settings.Clone();
Assert.IsFalse(clone.IsFrozen);
Assert.AreEqual(settings, clone);
}
示例9: MongoEventStore
public MongoEventStore(MongoClient client)
{
if (client == null) throw new ArgumentNullException("client");
this.client = client;
BsonClassMap.RegisterClassMap<MongoEventDocument>();
_commitSettings = new MongoCollectionSettings {AssignIdOnInsert = false, WriteConcern = WriteConcern.Acknowledged};
}
示例10: TestConstructor
public void TestConstructor()
{
var settings = new MongoCollectionSettings();
Assert.AreEqual(false, settings.AssignIdOnInsert);
Assert.AreEqual(GuidRepresentation.Unspecified, settings.GuidRepresentation);
Assert.AreEqual(null, settings.ReadPreference);
Assert.AreEqual(null, settings.WriteConcern);
}
示例11: Init
internal static void Init(string connectionString)
{
var client = new MongoClient(connectionString);
IMongoDatabase database = client.GetDatabase("sqlWithMongo");
var collectionSettings = new MongoCollectionSettings
{
WriteConcern = new WriteConcern(1)
};
_collection = database.GetCollection<NodeLinks>("links", collectionSettings);
}
示例12: MongodbCollection
public MongodbCollection(MongodbDatabase database, Type documentType, String collectionName)
{
if (collectionName == null) throw new ArgumentNullException("collectionName");
_database = database;
_documentType = documentType;
_collectionName = collectionName;
_metadata = _database.UniformDatabase.Metadata;
var mongoSettings = new MongoCollectionSettings {AssignIdOnInsert = false};
_collection = _database.Database.GetCollection(documentType, _collectionName, mongoSettings);
}
示例13: TestFrozenCopy
public void TestFrozenCopy()
{
var server = MongoServer.Create();
var database = server["test"];
var settings = new MongoCollectionSettings<BsonDocument>(database, "collection");
var frozenCopy = settings.FrozenCopy();
var secondFrozenCopy = frozenCopy.FrozenCopy();
Assert.AreNotSame(settings, frozenCopy);
Assert.AreSame(frozenCopy, secondFrozenCopy);
Assert.AreEqual(false, settings.IsFrozen);
Assert.AreEqual(true, frozenCopy.IsFrozen);
}
示例14: TestAssignIdOnInsert
public void TestAssignIdOnInsert()
{
var settings = new MongoCollectionSettings();
Assert.AreEqual(false, settings.AssignIdOnInsert);
var assignIdOnInsert = !settings.AssignIdOnInsert;
settings.AssignIdOnInsert = assignIdOnInsert;
Assert.AreEqual(assignIdOnInsert, settings.AssignIdOnInsert);
settings.Freeze();
Assert.AreEqual(assignIdOnInsert, settings.AssignIdOnInsert);
Assert.Throws<InvalidOperationException>(() => { settings.AssignIdOnInsert = assignIdOnInsert; });
}
示例15: Setup
public void Setup()
{
var settings = new MongoCollectionSettings();
var dbSettings = new MongoDatabaseSettings();
dbSettings.ApplyDefaultValues(new MongoServerSettings());
settings.ApplyDefaultValues(dbSettings);
_operationExecutor = new MockOperationExecutor();
_subject = new MongoCollectionImpl<BsonDocument>(
new CollectionNamespace("foo", "bar"),
settings,
Substitute.For<ICluster>(),
_operationExecutor);
}