1+ /* Copyright 2010-2012 10gen 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 ;
17+ using System . Collections . Generic ;
18+ using System . Linq ;
19+ using System . Text ;
20+ using NUnit . Framework ;
21+
22+ using MongoDB . Bson ;
23+ using MongoDB . Driver ;
24+ using MongoDB . Driver . Linq ;
25+ using MongoDB . Bson . Serialization . Attributes ;
26+ using MongoDB . Driver . Builders ;
27+
28+ namespace MongoDB . DriverUnitTests . Jira . CSharp598
29+ {
30+ [ TestFixture ]
31+ public class CSharp598Tests
32+ {
33+ [ Test ]
34+ public void TestVariableWorksForQuery ( )
35+ {
36+ int index = 10 ;
37+ IMongoQuery query = null ;
38+ Assert . DoesNotThrow ( ( ) =>
39+ {
40+ query = Query < TestClass > . EQ ( x => x . List [ index ] . Name , "Blah" ) ;
41+ } ) ;
42+
43+ Assert . AreEqual ( "{ \" List.10.Name\" : \" Blah\" }" , query . ToString ( ) ) ;
44+ }
45+
46+ [ Test ]
47+ public void TestVariableWorksForUpdate ( )
48+ {
49+ int index = 10 ;
50+ IMongoUpdate update = null ;
51+ Assert . DoesNotThrow ( ( ) =>
52+ {
53+ update = Update < TestClass > . Set ( x => x . List [ index ] . Name , "Blah" ) ;
54+ } ) ;
55+
56+ Assert . AreEqual ( "{ \" $set\" : { \" List.10.Name\" : \" Blah\" } }" , update . ToString ( ) ) ;
57+ }
58+
59+ [ Test ]
60+ public void TestVariableWorksForQueryWithVariableChange ( )
61+ {
62+ int index = 10 ;
63+ IMongoQuery query = null ;
64+ var queryBuilder = new QueryBuilder < TestClass > ( ) ;
65+ Assert . DoesNotThrow ( ( ) =>
66+ {
67+ query = queryBuilder . EQ ( x => x . List [ index ] . Name , "Blah" ) ;
68+ index = 11 ;
69+ query = queryBuilder . EQ ( x => x . List [ index ] . Name , "Blah" ) ;
70+ } ) ;
71+
72+ Assert . AreEqual ( "{ \" List.11.Name\" : \" Blah\" }" , query . ToString ( ) ) ;
73+ }
74+
75+ private class TestClass
76+ {
77+ public ObjectId Id { get ; set ; }
78+
79+ public List < SubTestClass > List { get ; set ; }
80+ }
81+ private class SubTestClass
82+ {
83+ public string Name { get ; set ; }
84+ }
85+ }
86+ }
0 commit comments