Skip to content

Commit 7e18b2e

Browse files
committed
CSHARP-1524: Added tests and fixed an additional bug.
1 parent 25e8af1 commit 7e18b2e

File tree

2 files changed

+81
-3
lines changed

2 files changed

+81
-3
lines changed

src/MongoDB.Driver.Tests/MongoDatabaseImplTests.cs

Lines changed: 79 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,15 +68,15 @@ public void Settings_should_be_set()
6868
}
6969

7070
[Test]
71-
public void CreateCollection_should_execute_the_CreateCollectionOperation(
71+
public void CreateCollection_should_execute_the_CreateCollectionOperation_when_options_is_generic(
7272
[Values(false, true)] bool async)
7373
{
7474
var storageEngine = new BsonDocument("awesome", true);
7575
var options = new CreateCollectionOptions<BsonDocument>
7676
{
7777
AutoIndexId = false,
7878
Capped = true,
79-
IndexOptionDefaults = new IndexOptionDefaults { StorageEngine = new BsonDocument("x", 1) },
79+
IndexOptionDefaults = new IndexOptionDefaults { StorageEngine = new BsonDocument("x", 1) },
8080
MaxDocuments = 10,
8181
MaxSize = 11,
8282
StorageEngine = storageEngine,
@@ -115,6 +115,83 @@ public void CreateCollection_should_execute_the_CreateCollectionOperation(
115115
op.Validator.Should().Be(renderedValidator);
116116
}
117117

118+
[Test]
119+
public void CreateCollection_should_execute_the_CreateCollectionOperation_when_options_is_not_generic(
120+
[Values(false, true)] bool async)
121+
{
122+
var storageEngine = new BsonDocument("awesome", true);
123+
var options = new CreateCollectionOptions
124+
{
125+
AutoIndexId = false,
126+
Capped = true,
127+
IndexOptionDefaults = new IndexOptionDefaults { StorageEngine = new BsonDocument("x", 1) },
128+
MaxDocuments = 10,
129+
MaxSize = 11,
130+
StorageEngine = storageEngine,
131+
UsePowerOf2Sizes = false,
132+
ValidationAction = DocumentValidationAction.Warn,
133+
ValidationLevel = DocumentValidationLevel.Off
134+
};
135+
136+
if (async)
137+
{
138+
_subject.CreateCollectionAsync("bar", options, CancellationToken.None).GetAwaiter().GetResult();
139+
}
140+
else
141+
{
142+
_subject.CreateCollection("bar", options, CancellationToken.None);
143+
}
144+
145+
var call = _operationExecutor.GetWriteCall<BsonDocument>();
146+
147+
call.Operation.Should().BeOfType<CreateCollectionOperation>();
148+
var op = (CreateCollectionOperation)call.Operation;
149+
op.CollectionNamespace.Should().Be(new CollectionNamespace(new DatabaseNamespace("foo"), "bar"));
150+
op.AutoIndexId.Should().Be(options.AutoIndexId);
151+
op.Capped.Should().Be(options.Capped);
152+
op.IndexOptionDefaults.ToBsonDocument().Should().Be(options.IndexOptionDefaults.ToBsonDocument());
153+
op.MaxDocuments.Should().Be(options.MaxDocuments);
154+
op.MaxSize.Should().Be(options.MaxSize);
155+
op.StorageEngine.Should().Be(storageEngine);
156+
op.UsePowerOf2Sizes.Should().Be(options.UsePowerOf2Sizes);
157+
op.ValidationAction.Should().Be(options.ValidationAction);
158+
op.ValidationLevel.Should().Be(options.ValidationLevel);
159+
op.Validator.Should().BeNull();
160+
}
161+
162+
[Test]
163+
public void CreateCollection_should_execute_the_CreateCollectionOperation_when_options_is_null(
164+
[Values(false, true)] bool async)
165+
{
166+
var storageEngine = new BsonDocument("awesome", true);
167+
CreateCollectionOptions options = null;
168+
169+
if (async)
170+
{
171+
_subject.CreateCollectionAsync("bar", options, CancellationToken.None).GetAwaiter().GetResult();
172+
}
173+
else
174+
{
175+
_subject.CreateCollection("bar", options, CancellationToken.None);
176+
}
177+
178+
var call = _operationExecutor.GetWriteCall<BsonDocument>();
179+
180+
call.Operation.Should().BeOfType<CreateCollectionOperation>();
181+
var op = (CreateCollectionOperation)call.Operation;
182+
op.CollectionNamespace.Should().Be(new CollectionNamespace(new DatabaseNamespace("foo"), "bar"));
183+
op.AutoIndexId.Should().NotHaveValue();
184+
op.Capped.Should().NotHaveValue();
185+
op.IndexOptionDefaults.Should().BeNull();
186+
op.MaxDocuments.Should().NotHaveValue();
187+
op.MaxSize.Should().NotHaveValue();
188+
op.StorageEngine.Should().BeNull();
189+
op.UsePowerOf2Sizes.Should().NotHaveValue();
190+
op.ValidationAction.Should().BeNull();
191+
op.ValidationLevel.Should().BeNull();
192+
op.Validator.Should().BeNull();
193+
}
194+
118195
[Test]
119196
public void DropCollection_should_execute_the_DropCollectionOperation(
120197
[Values(false, true)] bool async)

src/MongoDB.Driver/CreateCollectionOptions.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,13 +162,14 @@ internal static CreateCollectionOptions<TDocument> CoercedFrom(CreateCollectionO
162162
{
163163
AutoIndexId = options.AutoIndexId,
164164
Capped = options.Capped,
165+
IndexOptionDefaults = options.IndexOptionDefaults,
165166
MaxDocuments = options.MaxDocuments,
166167
MaxSize = options.MaxSize,
167168
SerializerRegistry = options.SerializerRegistry,
168169
StorageEngine = options.StorageEngine,
169170
UsePowerOf2Sizes = options.UsePowerOf2Sizes,
170171
ValidationAction = options.ValidationAction,
171-
ValidationLevel = options.ValidationLevel
172+
ValidationLevel = options.ValidationLevel
172173
};
173174
}
174175

0 commit comments

Comments
 (0)