Skip to content

Commit 169ae39

Browse files
CSHARP-2834: Collection and index creation in multi-doc txns
1 parent 1bf7f53 commit 169ae39

13 files changed

+1294
-12
lines changed
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
/* Copyright 2020-present MongoDB Inc.
2+
*
3+
* Licensed under the Apache License, Version 2.0 (the "License");
4+
* you may not use this file except in compliance with the License.
5+
* You may obtain a copy of the License at
6+
*
7+
* http://www.apache.org/licenses/LICENSE-2.0
8+
*
9+
* Unless required by applicable law or agreed to in writing, software
10+
* distributed under the License is distributed on an "AS IS" BASIS,
11+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
* See the License for the specific language governing permissions and
13+
* limitations under the License.
14+
*/
15+
16+
using System.Collections.Generic;
17+
using System.Threading;
18+
using System.Threading.Tasks;
19+
using FluentAssertions;
20+
using MongoDB.Bson;
21+
using MongoDB.Bson.TestHelpers.JsonDrivenTests;
22+
23+
namespace MongoDB.Driver.Tests.JsonDrivenTests
24+
{
25+
public class JsonDrivenAssertCollectionExists : JsonDrivenTestRunnerTest
26+
{
27+
// private fields
28+
private string _collectionName;
29+
private string _databaseName;
30+
31+
// public constructors
32+
public JsonDrivenAssertCollectionExists(IJsonDrivenTestRunner testRunner, Dictionary<string, object> objectMap)
33+
: base(testRunner, objectMap)
34+
{
35+
}
36+
37+
// public methods
38+
public override void Act(CancellationToken cancellationToken)
39+
{
40+
// do nothing
41+
}
42+
43+
public override Task ActAsync(CancellationToken cancellationToken)
44+
{
45+
// do nothing
46+
return Task.FromResult(true);
47+
}
48+
49+
public override void Arrange(BsonDocument document)
50+
{
51+
JsonDrivenHelper.EnsureAllFieldsAreValid(document, "name", "object", "arguments");
52+
base.Arrange(document);
53+
}
54+
55+
public override void Assert()
56+
{
57+
var client = DriverTestConfiguration.Client;
58+
var collectionNames = client.GetDatabase(_databaseName).ListCollectionNames().ToList();
59+
collectionNames.Should().Contain(_collectionName);
60+
}
61+
62+
// protected methods
63+
protected override void SetArgument(string name, BsonValue value)
64+
{
65+
switch (name)
66+
{
67+
case "collection":
68+
_collectionName = value.AsString;
69+
return;
70+
case "database":
71+
_databaseName = value.AsString;
72+
return;
73+
}
74+
75+
base.SetArgument(name, value);
76+
}
77+
}
78+
}
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
/* Copyright 2020-present MongoDB Inc.
2+
*
3+
* Licensed under the Apache License, Version 2.0 (the "License");
4+
* you may not use this file except in compliance with the License.
5+
* You may obtain a copy of the License at
6+
*
7+
* http://www.apache.org/licenses/LICENSE-2.0
8+
*
9+
* Unless required by applicable law or agreed to in writing, software
10+
* distributed under the License is distributed on an "AS IS" BASIS,
11+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
* See the License for the specific language governing permissions and
13+
* limitations under the License.
14+
*/
15+
16+
using System.Collections.Generic;
17+
using System.Threading;
18+
using System.Threading.Tasks;
19+
using FluentAssertions;
20+
using MongoDB.Bson;
21+
using MongoDB.Bson.TestHelpers.JsonDrivenTests;
22+
23+
namespace MongoDB.Driver.Tests.JsonDrivenTests
24+
{
25+
public class JsonDrivenAssertCollectionNotExists : JsonDrivenTestRunnerTest
26+
{
27+
// private fields
28+
private string _collectionName;
29+
private string _databaseName;
30+
31+
// public constructors
32+
public JsonDrivenAssertCollectionNotExists(IJsonDrivenTestRunner testRunner, Dictionary<string, object> objectMap)
33+
: base(testRunner, objectMap)
34+
{
35+
}
36+
37+
// public methods
38+
public override void Act(CancellationToken cancellationToken)
39+
{
40+
// do nothing
41+
}
42+
43+
public override Task ActAsync(CancellationToken cancellationToken)
44+
{
45+
// do nothing
46+
return Task.FromResult(true);
47+
}
48+
49+
public override void Arrange(BsonDocument document)
50+
{
51+
JsonDrivenHelper.EnsureAllFieldsAreValid(document, "name", "object", "arguments");
52+
base.Arrange(document);
53+
}
54+
55+
public override void Assert()
56+
{
57+
var client = DriverTestConfiguration.Client;
58+
var collectionNames = client.GetDatabase(_databaseName).ListCollectionNames().ToList();
59+
collectionNames.Should().NotContain(_collectionName);
60+
}
61+
62+
// protected methods
63+
protected override void SetArgument(string name, BsonValue value)
64+
{
65+
switch (name)
66+
{
67+
case "collection":
68+
_collectionName = value.AsString;
69+
return;
70+
case "database":
71+
_databaseName = value.AsString;
72+
return;
73+
}
74+
75+
base.SetArgument(name, value);
76+
}
77+
}
78+
}
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
/* Copyright 2020-present MongoDB Inc.
2+
*
3+
* Licensed under the Apache License, Version 2.0 (the "License");
4+
* you may not use this file except in compliance with the License.
5+
* You may obtain a copy of the License at
6+
*
7+
* http://www.apache.org/licenses/LICENSE-2.0
8+
*
9+
* Unless required by applicable law or agreed to in writing, software
10+
* distributed under the License is distributed on an "AS IS" BASIS,
11+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
* See the License for the specific language governing permissions and
13+
* limitations under the License.
14+
*/
15+
16+
using System.Collections.Generic;
17+
using System.Linq;
18+
using System.Threading;
19+
using System.Threading.Tasks;
20+
using FluentAssertions;
21+
using MongoDB.Bson;
22+
using MongoDB.Bson.TestHelpers.JsonDrivenTests;
23+
24+
namespace MongoDB.Driver.Tests.JsonDrivenTests
25+
{
26+
public class JsonDrivenAssertIndexExists : JsonDrivenTestRunnerTest
27+
{
28+
// private fields
29+
private string _collectionName;
30+
private string _databaseName;
31+
private string _indexName;
32+
33+
// public constructors
34+
public JsonDrivenAssertIndexExists(IJsonDrivenTestRunner testRunner, Dictionary<string, object> objectMap)
35+
: base(testRunner, objectMap)
36+
{
37+
}
38+
39+
// public methods
40+
public override void Act(CancellationToken cancellationToken)
41+
{
42+
// do nothing
43+
}
44+
45+
public override Task ActAsync(CancellationToken cancellationToken)
46+
{
47+
// do nothing
48+
return Task.FromResult(true);
49+
}
50+
51+
public override void Arrange(BsonDocument document)
52+
{
53+
JsonDrivenHelper.EnsureAllFieldsAreValid(document, "name", "object", "arguments");
54+
base.Arrange(document);
55+
}
56+
57+
public override void Assert()
58+
{
59+
var client = DriverTestConfiguration.Client;
60+
var indexes = client.GetDatabase(_databaseName).GetCollection<BsonDocument>(_collectionName).Indexes.List().ToList();
61+
var indexNames = indexes.Select(i => i["name"].AsString);
62+
indexNames.Should().Contain(_indexName);
63+
}
64+
65+
// protected methods
66+
protected override void SetArgument(string name, BsonValue value)
67+
{
68+
switch (name)
69+
{
70+
case "collection":
71+
_collectionName = value.AsString;
72+
return;
73+
case "database":
74+
_databaseName = value.AsString;
75+
return;
76+
case "index":
77+
_indexName = value.AsString;
78+
return;
79+
}
80+
81+
base.SetArgument(name, value);
82+
}
83+
}
84+
}
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
/* Copyright 2020-present MongoDB Inc.
2+
*
3+
* Licensed under the Apache License, Version 2.0 (the "License");
4+
* you may not use this file except in compliance with the License.
5+
* You may obtain a copy of the License at
6+
*
7+
* http://www.apache.org/licenses/LICENSE-2.0
8+
*
9+
* Unless required by applicable law or agreed to in writing, software
10+
* distributed under the License is distributed on an "AS IS" BASIS,
11+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
* See the License for the specific language governing permissions and
13+
* limitations under the License.
14+
*/
15+
16+
using System.Collections.Generic;
17+
using System.Linq;
18+
using System.Threading;
19+
using System.Threading.Tasks;
20+
using FluentAssertions;
21+
using MongoDB.Bson;
22+
using MongoDB.Bson.TestHelpers.JsonDrivenTests;
23+
24+
namespace MongoDB.Driver.Tests.JsonDrivenTests
25+
{
26+
public class JsonDrivenAssertIndexNotExists : JsonDrivenTestRunnerTest
27+
{
28+
// private fields
29+
private string _collectionName;
30+
private string _databaseName;
31+
private string _indexName;
32+
33+
// public constructors
34+
public JsonDrivenAssertIndexNotExists(IJsonDrivenTestRunner testRunner, Dictionary<string, object> objectMap)
35+
: base(testRunner, objectMap)
36+
{
37+
}
38+
39+
// public methods
40+
public override void Act(CancellationToken cancellationToken)
41+
{
42+
// do nothing
43+
}
44+
45+
public override Task ActAsync(CancellationToken cancellationToken)
46+
{
47+
// do nothing
48+
return Task.FromResult(true);
49+
}
50+
51+
public override void Arrange(BsonDocument document)
52+
{
53+
JsonDrivenHelper.EnsureAllFieldsAreValid(document, "name", "object", "arguments");
54+
base.Arrange(document);
55+
}
56+
57+
public override void Assert()
58+
{
59+
var client = DriverTestConfiguration.Client;
60+
var indexes = client.GetDatabase(_databaseName).GetCollection<BsonDocument>(_collectionName).Indexes.List().ToList();
61+
var indexNames = indexes.Select(i => i["name"].AsString);
62+
indexNames.Should().NotContain(_indexName);
63+
}
64+
65+
// protected methods
66+
protected override void SetArgument(string name, BsonValue value)
67+
{
68+
switch (name)
69+
{
70+
case "collection":
71+
_collectionName = value.AsString;
72+
return;
73+
case "database":
74+
_databaseName = value.AsString;
75+
return;
76+
case "index":
77+
_indexName = value.AsString;
78+
return;
79+
}
80+
81+
base.SetArgument(name, value);
82+
}
83+
}
84+
}

0 commit comments

Comments
 (0)