1+ /* Copyright 2010-2013 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 MongoDB . Bson ;
19+ using MongoDB . Bson . Serialization . Attributes ;
20+ using MongoDB . Driver . Builders ;
21+ using NUnit . Framework ;
22+
23+ namespace MongoDB . DriverUnitTests . Jira
24+ {
25+ [ TestFixture ]
26+ public class CSharp779
27+ {
28+ public class RepresentationExample
29+ {
30+ [ BsonRepresentation ( BsonType . String ) ]
31+ public Guid [ ] MultipleEntry { get ; set ; }
32+
33+ [ BsonRepresentation ( BsonType . String ) ]
34+ public Guid SingleEntry { get ; set ; }
35+ }
36+
37+ [ Test ]
38+ public void InRepresentationIssue ( )
39+ {
40+ var guid = Guid . NewGuid ( ) ;
41+
42+ var singleUpdate = Query < RepresentationExample >
43+ . In ( x => x . SingleEntry , new [ ] { guid } ) ;
44+
45+ Assert . That ( singleUpdate . ToJson ( ) . Contains ( guid . ToString ( ) ) ) ;
46+ Assert . That ( ! singleUpdate . ToJson ( ) . Contains ( "CSUUID" ) ) ;
47+
48+ var multipleUpdate = Query < RepresentationExample >
49+ . In ( x => x . MultipleEntry , new [ ] { guid } ) ;
50+
51+ Assert . That ( multipleUpdate . ToJson ( ) , Contains . Substring ( guid . ToString ( ) ) ) ;
52+ Assert . That ( ! multipleUpdate . ToJson ( ) . Contains ( "CSUUID" ) ) ;
53+ }
54+
55+ [ Test ]
56+ public void UpdateRepresentationIssue ( )
57+ {
58+ var guid = Guid . NewGuid ( ) ;
59+
60+ var singleUpdate = Update < RepresentationExample >
61+ . Set ( x => x . SingleEntry , guid ) ;
62+
63+ Assert . That ( singleUpdate . ToJson ( ) . Contains ( guid . ToString ( ) ) ) ;
64+ Assert . That ( ! singleUpdate . ToJson ( ) . Contains ( "CSUUID" ) ) ;
65+
66+ var multipleUpdate = Update < RepresentationExample >
67+ . PullAll ( x => x . MultipleEntry , new [ ] { guid } ) ;
68+
69+ Assert . That ( multipleUpdate . ToJson ( ) , Contains . Substring ( guid . ToString ( ) ) ) ;
70+ Assert . That ( ! multipleUpdate . ToJson ( ) . Contains ( "CSUUID" ) ) ;
71+ }
72+ }
73+ }
0 commit comments