13
13
* limitations under the License.
14
14
*/
15
15
16
+ using System . Collections . Generic ;
16
17
using System . Linq ;
17
18
using FluentAssertions ;
18
- using MongoDB . Driver . Linq ;
19
+ using MongoDB . Driver . TestHelpers ;
19
20
using Xunit ;
20
21
21
22
namespace MongoDB . Driver . Tests . Linq . Linq3Implementation . Jira
22
23
{
23
- public class CSharp4316Tests : Linq3IntegrationTest
24
+ public class CSharp4316Tests : LinqIntegrationTest < CSharp4316Tests . ClassFixture >
24
25
{
26
+ public CSharp4316Tests ( ClassFixture fixture ) : base ( fixture )
27
+ {
28
+ }
29
+
25
30
[ Fact ]
26
31
public void Value_and_HasValue_should_work_when_properties_on_Nullable_type ( )
27
32
{
28
- var collection = CreateCollection ( ) ;
33
+ var collection = Fixture . Collection ;
29
34
var matchStage = "{ $match : { 'ActualNullable' : { $ne : null } } }" ;
30
35
var projectStage = "{ $project : { _id : '$_id', Value : '$ActualNullable', HasValue : { $ne : ['$ActualNullable', null] } } }" ;
31
36
@@ -43,7 +48,7 @@ public void Value_and_HasValue_should_work_when_properties_on_Nullable_type()
43
48
[ Fact ]
44
49
public void Value_and_HasValue_should_work_when_properties_not_on_Nullable_type ( )
45
50
{
46
- var collection = CreateCollection ( ) ;
51
+ var collection = Fixture . Collection ;
47
52
var matchStage = "{ $match : { 'OnlyLooksLikeNullable.HasValue' : true } }" ;
48
53
var projectStage = "{ $project : { _id : '$_id', Value : '$OnlyLooksLikeNullable.Value', HasValue : '$OnlyLooksLikeNullable.HasValue' } }" ;
49
54
@@ -59,29 +64,26 @@ public void Value_and_HasValue_should_work_when_properties_not_on_Nullable_type(
59
64
results . Select ( r => r . Id ) . Should ( ) . Equal ( 1 ) ;
60
65
}
61
66
62
- private IMongoCollection < C > CreateCollection ( )
63
- {
64
- var collection = GetCollection < C > ( "C" ) ;
65
-
66
- CreateCollection (
67
- collection ,
68
- new C { Id = 1 , OnlyLooksLikeNullable = new OnlyLooksLikeNullable { Value = "SomeValue" , HasValue = true } , ActualNullable = null } ,
69
- new C { Id = 2 , OnlyLooksLikeNullable = new OnlyLooksLikeNullable { Value = null , HasValue = false } , ActualNullable = true } ) ;
70
-
71
- return collection ;
72
- }
73
-
74
- private class C
67
+ public class C
75
68
{
76
69
public int Id { get ; set ; }
77
70
public OnlyLooksLikeNullable OnlyLooksLikeNullable { get ; set ; }
78
71
public bool ? ActualNullable { get ; set ; }
79
72
}
80
73
81
- private class OnlyLooksLikeNullable
74
+ public class OnlyLooksLikeNullable
82
75
{
83
76
public string Value { get ; set ; }
84
77
public bool HasValue { get ; set ; }
85
78
}
79
+
80
+ public sealed class ClassFixture : MongoCollectionFixture < C >
81
+ {
82
+ protected override IEnumerable < C > InitialData =>
83
+ [
84
+ new C { Id = 1 , OnlyLooksLikeNullable = new OnlyLooksLikeNullable { Value = "SomeValue" , HasValue = true } , ActualNullable = null } ,
85
+ new C { Id = 2 , OnlyLooksLikeNullable = new OnlyLooksLikeNullable { Value = null , HasValue = false } , ActualNullable = true }
86
+ ] ;
87
+ }
86
88
}
87
89
}
0 commit comments