5
5
namespace Microsoft . Azure . Cosmos . SDK . EmulatorTests
6
6
{
7
7
using System ;
8
- using System . Collections . Concurrent ;
9
8
using System . Collections . Generic ;
10
- using System . Collections . ObjectModel ;
11
9
using System . Net ;
12
- using System . Net . Http ;
13
- using System . Text ;
14
10
using System . Threading ;
15
11
using System . Threading . Tasks ;
16
12
using Microsoft . Azure . Cosmos . Fluent ;
17
- using Microsoft . Azure . Cosmos . Query . Core ;
18
13
using Microsoft . Azure . Cosmos . Tracing ;
19
14
using Microsoft . VisualStudio . TestTools . UnitTesting ;
20
15
21
16
[ TestClass ]
22
17
public class CosmosReadManyItemsTests : BaseCosmosClientHelper
23
18
{
24
19
private Container Container = null ;
25
- private ContainerProperties containerSettings = null ;
26
20
27
21
[ TestInitialize ]
28
22
public async Task TestInitialize ( )
29
23
{
30
24
await base . TestInit ( ) ;
31
25
string PartitionKey = "/pk" ;
32
- this . containerSettings = new ContainerProperties ( id : Guid . NewGuid ( ) . ToString ( ) , partitionKeyPath : PartitionKey ) ;
26
+ ContainerProperties containerSettings = new ContainerProperties ( id : Guid . NewGuid ( ) . ToString ( ) , partitionKeyPath : PartitionKey ) ;
33
27
ContainerResponse response = await this . database . CreateContainerAsync (
34
- this . containerSettings ,
28
+ containerSettings ,
35
29
throughput : 20000 ,
36
30
cancellationToken : this . cancellationToken ) ;
37
31
Assert . IsNotNull ( response ) ;
@@ -122,23 +116,24 @@ public async Task ReadManyDoesNotFetchQueryPlan()
122
116
[ TestMethod ]
123
117
public async Task ReadManyWithIdasPk ( )
124
118
{
125
- string PartitionKey = "/id" ;
126
- ContainerProperties containerSettings = new ContainerProperties ( id : Guid . NewGuid ( ) . ToString ( ) , partitionKeyPath : PartitionKey ) ;
127
- Container container = await this . database . CreateContainerAsync ( containerSettings ) ;
119
+ Container container = await this . database . CreateContainerAsync ( Guid . NewGuid ( ) . ToString ( ) , "/id" ) ;
128
120
129
121
List < ( string , PartitionKey ) > itemList = new List < ( string , PartitionKey ) > ( ) ;
130
- for ( int i = 0 ; i < 5 ; i ++ )
131
- {
132
- itemList . Add ( ( i . ToString ( ) , new PartitionKey ( i . ToString ( ) ) ) ) ;
133
- }
134
122
135
123
// Create items with different pk values
136
124
for ( int i = 0 ; i < 5 ; i ++ )
137
125
{
138
126
ToDoActivity item = ToDoActivity . CreateRandomToDoActivity ( ) ;
139
- item . id = i . ToString ( ) ;
140
127
ItemResponse < ToDoActivity > itemResponse = await container . CreateItemAsync ( item ) ;
141
128
Assert . AreEqual ( HttpStatusCode . Created , itemResponse . StatusCode ) ;
129
+
130
+ itemList . Add ( ( item . id , new PartitionKey ( item . id ) ) ) ;
131
+
132
+ ToDoActivity itemWithSingleQuotes = ToDoActivity . CreateRandomToDoActivity ( id : item . id + "'singlequote" ) ;
133
+ ItemResponse < ToDoActivity > itemResponseWithSingleQuotes = await container . CreateItemAsync ( itemWithSingleQuotes ) ;
134
+ Assert . AreEqual ( HttpStatusCode . Created , itemResponseWithSingleQuotes . StatusCode ) ;
135
+
136
+ itemList . Add ( ( itemWithSingleQuotes . id , new PartitionKey ( itemWithSingleQuotes . id ) ) ) ;
142
137
}
143
138
144
139
using ( ResponseMessage responseMessage = await container . ReadManyItemsStreamAsync ( itemList ) )
@@ -149,12 +144,12 @@ public async Task ReadManyWithIdasPk()
149
144
150
145
ToDoActivity [ ] items = this . cosmosClient . ClientContext . SerializerCore . FromFeedStream < ToDoActivity > (
151
146
CosmosFeedResponseSerializer . GetStreamWithoutServiceEnvelope ( responseMessage . Content ) ) ;
152
- Assert . AreEqual ( items . Length , 5 ) ;
147
+ Assert . AreEqual ( items . Length , 10 ) ;
153
148
}
154
149
155
150
FeedResponse < ToDoActivity > feedResponse = await container . ReadManyItemsAsync < ToDoActivity > ( itemList ) ;
156
151
Assert . IsNotNull ( feedResponse ) ;
157
- Assert . AreEqual ( feedResponse . Count , 5 ) ;
152
+ Assert . AreEqual ( feedResponse . Count , 10 ) ;
158
153
Assert . IsTrue ( feedResponse . Headers . RequestCharge > 0 ) ;
159
154
Assert . IsNotNull ( feedResponse . Diagnostics ) ;
160
155
}
0 commit comments