本文整理汇总了C#中CreateCollectionOperation.ExecuteAsync方法的典型用法代码示例。如果您正苦于以下问题:C# CreateCollectionOperation.ExecuteAsync方法的具体用法?C# CreateCollectionOperation.ExecuteAsync怎么用?C# CreateCollectionOperation.ExecuteAsync使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CreateCollectionOperation
的用法示例。
在下文中一共展示了CreateCollectionOperation.ExecuteAsync方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ExecuteOperation
private BsonDocument ExecuteOperation(CreateCollectionOperation subject, IWriteBinding binding, bool async)
{
if (async)
{
return subject.ExecuteAsync(binding, CancellationToken.None).GetAwaiter().GetResult();
}
else
{
return subject.Execute(binding, CancellationToken.None);
}
}
示例2: ExecuteAsync_should_create_collection_when_UsePowerOf2Sizes_is_set
public async Task ExecuteAsync_should_create_collection_when_UsePowerOf2Sizes_is_set(
[Values(false, true)]
bool usePowerOf2Sizes)
{
var subject = new CreateCollectionOperation(_collectionNamespace, _messageEncoderSettings)
{
UsePowerOf2Sizes = usePowerOf2Sizes
};
using (var binding = CoreTestConfiguration.GetReadWriteBinding())
{
var result = await subject.ExecuteAsync(binding, CancellationToken.None);
result["ok"].ToBoolean().Should().BeTrue();
var stats = await GetCollectionStatsAsync(binding);
stats["ns"].ToString().Should().Be(_collectionNamespace.FullName);
stats["userFlags"].ToInt32().Should().Be(usePowerOf2Sizes ? 1 : 0);
}
}
示例3: EnsureCollectionExists
private void EnsureCollectionExists(IWriteBinding binding, CollectionNamespace collectionNamespace)
{
try
{
var operation = new CreateCollectionOperation(collectionNamespace, _messageEncoderSettings);
operation.ExecuteAsync(binding, CancellationToken.None).GetAwaiter().GetResult();
}
catch (MongoCommandException ex)
{
if (ex.Message == "Command create failed: collection already exists.")
{
return;
}
throw;
}
}
示例4: ExecuteAsync_should_create_collection_when_MaxSize_is_set
public async Task ExecuteAsync_should_create_collection_when_MaxSize_is_set()
{
var maxSize = 10000L;
var subject = new CreateCollectionOperation(_collectionNamespace, _messageEncoderSettings)
{
Capped = true,
MaxSize = maxSize
};
using (var binding = CoreTestConfiguration.GetReadWriteBinding())
{
var result = await subject.ExecuteAsync(binding, CancellationToken.None);
result["ok"].ToBoolean().Should().BeTrue();
var stats = await GetCollectionStatsAsync(binding);
stats["ns"].ToString().Should().Be(_collectionNamespace.FullName);
stats["capped"].ToBoolean().Should().BeTrue();
// TODO: not sure how to verify that the maxSize took effect
}
}
示例5: ExecuteAsync_should_create_collection_when_MaxDocuments_is_set
public async Task ExecuteAsync_should_create_collection_when_MaxDocuments_is_set()
{
var maxDocuments = 123L;
var subject = new CreateCollectionOperation(_collectionNamespace, _messageEncoderSettings)
{
Capped = true,
MaxSize = 10000L,
MaxDocuments = maxDocuments
};
using (var binding = CoreTestConfiguration.GetReadWriteBinding())
{
var result = await subject.ExecuteAsync(binding, CancellationToken.None);
result["ok"].ToBoolean().Should().BeTrue();
var stats = await GetCollectionStatsAsync(binding);
stats["ns"].ToString().Should().Be(_collectionNamespace.FullName);
stats["capped"].ToBoolean().Should().BeTrue();
stats["max"].ToInt64().Should().Be(maxDocuments);
}
}
示例6: ExecuteAsync_should_create_collection_when_Capped_is_set
public async Task ExecuteAsync_should_create_collection_when_Capped_is_set(
[Values(false, true)]
bool capped)
{
var maxSize = capped ? (long?)10000 : null;
var subject = new CreateCollectionOperation(_collectionNamespace, _messageEncoderSettings)
{
Capped = capped,
MaxSize = maxSize
};
using (var binding = CoreTestConfiguration.GetReadWriteBinding())
{
var result = await subject.ExecuteAsync(binding, CancellationToken.None);
result["ok"].ToBoolean().Should().BeTrue();
var stats = await GetCollectionStatsAsync(binding);
stats["ns"].ToString().Should().Be(_collectionNamespace.FullName);
stats.GetValue("capped", false).ToBoolean().Should().Be(capped);
}
}
示例7: ExecuteAsync_should_create_collection_when_AutoIndexId_is_set
public async Task ExecuteAsync_should_create_collection_when_AutoIndexId_is_set(
[Values(false, true)]
bool autoIndexId)
{
var subject = new CreateCollectionOperation(_collectionNamespace, _messageEncoderSettings)
{
AutoIndexId = autoIndexId
};
using (var binding = CoreTestConfiguration.GetReadWriteBinding())
{
var result = await subject.ExecuteAsync(binding, CancellationToken.None);
result["ok"].ToBoolean().Should().BeTrue();
var listIndexesOperation = new ListIndexesOperation(_collectionNamespace, _messageEncoderSettings);
var cursor = await listIndexesOperation.ExecuteAsync(binding, CancellationToken.None);
var indexes = await cursor.ToListAsync();
indexes.Count.Should().Be(autoIndexId ? 1 : 0);
}
}
示例8: ExecuteAsync_should_create_collection
public async Task ExecuteAsync_should_create_collection()
{
var subject = new CreateCollectionOperation(_collectionNamespace, _messageEncoderSettings);
using (var binding = CoreTestConfiguration.GetReadWriteBinding())
{
var result = await subject.ExecuteAsync(binding, CancellationToken.None);
result["ok"].ToBoolean().Should().BeTrue();
var stats = await GetCollectionStatsAsync(binding);
stats["ns"].ToString().Should().Be(_collectionNamespace.FullName);
}
}