Skip to content

Commit 5c649e3

Browse files
committed
Add runner tests for thinclient.
1 parent 2cc2ab6 commit 5c649e3

3 files changed

Lines changed: 175 additions & 1 deletion

File tree

Lines changed: 131 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,131 @@
1+
//------------------------------------------------------------
2+
// Copyright (c) Microsoft Corporation. All rights reserved.
3+
//------------------------------------------------------------
4+
5+
namespace Microsoft.Azure.Cosmos.SDK.EmulatorTests
6+
{
7+
using System;
8+
using System.Drawing;
9+
using System.Net;
10+
using System.Text.Json.Serialization;
11+
using System.Text.Json;
12+
using System.Threading.Tasks;
13+
using Microsoft.Azure.Cosmos;
14+
using Microsoft.VisualStudio.TestTools.UnitTesting;
15+
16+
[TestClass]
17+
public class CosmosItemThinClientTests
18+
{
19+
private string connectionString;
20+
private CosmosClient client;
21+
private Database database;
22+
private Container container;
23+
24+
[TestInitialize]
25+
public async Task TestInitAsync()
26+
{
27+
this.connectionString = Environment.GetEnvironmentVariable("COSMOSDB_CONNECTION_STRING");
28+
Environment.SetEnvironmentVariable(ConfigurationManager.ThinClientModeEnabled, "True");
29+
30+
if (string.IsNullOrEmpty(this.connectionString))
31+
{
32+
Assert.Fail("Set environment variable COSMOSDB_CONNECTION_STRING to run the tests");
33+
}
34+
35+
this.client = new CosmosClient(this.connectionString);
36+
this.database = await this.client.CreateDatabaseIfNotExistsAsync("TestDatabase");
37+
this.container = await this.database.CreateContainerIfNotExistsAsync("TestContainer", "/partitionKey");
38+
}
39+
40+
[TestCleanup]
41+
public async Task TestCleanupAsync()
42+
{
43+
Environment.SetEnvironmentVariable(ConfigurationManager.ThinClientModeEnabled, "False");
44+
if (this.database != null)
45+
{
46+
await this.database.DeleteAsync();
47+
}
48+
49+
this.client?.Dispose();
50+
}
51+
52+
[TestMethod]
53+
[TestCategory("ThinClient")]
54+
public async Task CreateItemTest()
55+
{
56+
// Arrange
57+
dynamic testItem = new { id = Guid.NewGuid().ToString(), partitionKey = "pk1", name = "Test Item" };
58+
59+
// Act
60+
ItemResponse<dynamic> response = await this.container.CreateItemAsync(testItem, new PartitionKey(testItem.partitionKey));
61+
62+
// Assert
63+
Assert.AreEqual(HttpStatusCode.Created, response.StatusCode);
64+
Assert.AreEqual(testItem.id, response.Resource.id);
65+
}
66+
67+
[TestMethod]
68+
[TestCategory("ThinClient")]
69+
public async Task ReplaceItemTest()
70+
{
71+
// Arrange
72+
dynamic testItem = new { id = Guid.NewGuid().ToString(), partitionKey = "pk1", name = "Test Item" };
73+
await this.container.CreateItemAsync(testItem, new PartitionKey(testItem.partitionKey));
74+
75+
dynamic updatedItem = new { testItem.id, partitionKey = "pk1", name = "Updated Item" };
76+
77+
// Act
78+
ItemResponse<dynamic> response = await this.container.ReplaceItemAsync(updatedItem, updatedItem.id, new PartitionKey(updatedItem.partitionKey));
79+
80+
// Assert
81+
Assert.AreEqual(HttpStatusCode.OK, response.StatusCode);
82+
Assert.AreEqual(updatedItem.name, response.Resource.name);
83+
}
84+
85+
[TestMethod]
86+
[TestCategory("ThinClient")]
87+
public async Task DeleteItemTest()
88+
{
89+
// Arrange
90+
dynamic testItem = new { id = Guid.NewGuid().ToString(), partitionKey = "pk1", name = "Test Item" };
91+
await this.container.CreateItemAsync(testItem, new PartitionKey(testItem.partitionKey));
92+
93+
// Act
94+
ItemResponse<dynamic> response = await this.container.DeleteItemAsync<dynamic>(testItem.id, new PartitionKey(testItem.partitionKey));
95+
96+
// Assert
97+
Assert.AreEqual(HttpStatusCode.NoContent, response.StatusCode);
98+
}
99+
100+
[TestMethod]
101+
[TestCategory("ThinClient")]
102+
public async Task ReadItemTest()
103+
{
104+
// Arrange
105+
dynamic testItem = new { id = Guid.NewGuid().ToString(), partitionKey = "pk1", name = "Test Item" };
106+
await this.container.CreateItemAsync(testItem, new PartitionKey(testItem.partitionKey));
107+
108+
// Act
109+
ItemResponse<dynamic> response = await this.container.ReadItemAsync<dynamic>(testItem.id, new PartitionKey(testItem.partitionKey));
110+
111+
// Assert
112+
Assert.AreEqual(HttpStatusCode.OK, response.StatusCode);
113+
Assert.AreEqual(testItem.id, response.Resource.id);
114+
}
115+
116+
[TestMethod]
117+
[TestCategory("ThinClient")]
118+
public async Task UpsertItemTest()
119+
{
120+
// Arrange
121+
dynamic testItem = new { id = Guid.NewGuid().ToString(), partitionKey = "pk1", name = "Test Item" };
122+
123+
// Act
124+
ItemResponse<dynamic> response = await this.container.UpsertItemAsync(testItem, new PartitionKey(testItem.partitionKey));
125+
126+
// Assert
127+
Assert.AreEqual(HttpStatusCode.Created, response.StatusCode);
128+
Assert.AreEqual(testItem.id, response.Resource.id);
129+
}
130+
}
131+
}

azure-pipelines.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ jobs:
5252
VmImage: $(VmImage)
5353
MultiRegionConnectionString: $(COSMOSDB_MULTI_REGION)
5454
MultiRegionMultiMasterConnectionString: $(COSMOSDB_MULTIMASTER)
55+
ThinClientConnectionString: $(COSMOSDB_THINCLIENT)
5556
IncludePerformance: true
5657
IncludeCoverage: true
5758

templates/build-test.yml

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ parameters:
1515
EmulatorPipeline4CategoryListName: ' MultiMaster '
1616
MultiRegionConnectionString : ''
1717
MultiRegionMultiMasterConnectionString : ''
18+
ThinClientConnectionString: ''
1819
IncludeEncryption: true
1920
IncludePerformance: true
2021
IncludeCoverage: true
@@ -451,4 +452,45 @@ jobs:
451452
testRunTitle: Microsoft.Azure.Cosmos.EmulatorTests
452453
env:
453454
COSMOSDB_MULTI_REGION: ${{ parameters.MultiRegionMultiMasterConnectionString }}
454-
AZURE_COSMOS_NON_STREAMING_ORDER_BY_FLAG_DISABLED: true
455+
AZURE_COSMOS_NON_STREAMING_ORDER_BY_FLAG_DISABLED: true
456+
457+
- job:
458+
displayName: EmulatorTests ${{ parameters.BuildConfiguration }} - ThinClient
459+
timeoutInMinutes: 60
460+
condition: and(succeeded(), eq('${{ parameters.OS }}', 'Windows'))
461+
pool:
462+
name: 'OneES'
463+
464+
steps:
465+
- checkout: self
466+
clean: true
467+
468+
- task: UseDotNet@2
469+
displayName: Use .NET 6.0
470+
inputs:
471+
packageType: 'runtime'
472+
version: '6.x'
473+
474+
- task: UseDotNet@2
475+
displayName: Use .NET 8.0
476+
inputs:
477+
packageType: 'sdk'
478+
version: '8.x'
479+
480+
- template: emulator-setup.yml
481+
482+
- task: DotNetCoreCLI@2
483+
displayName: Microsoft.Azure.Cosmos.EmulatorTests - ThinClient
484+
condition: succeeded()
485+
retryCountOnTaskFailure: 2
486+
inputs:
487+
command: test
488+
projects: 'Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/*.csproj'
489+
arguments: --filter "TestCategory=ThinClient" --verbosity normal --configuration ${{ parameters.BuildConfiguration }} /p:OS=${{ parameters.OS }}
490+
nugetConfigPath: NuGet.config
491+
publishTestResults: true
492+
testRunTitle: Microsoft.Azure.Cosmos.EmulatorTests - ThinClient
493+
env:
494+
COSMOSDB_THINCLIENT: ${{ parameters.ThinClientConnectionString }}
495+
THINCLIENT_MODE_ENABLED: "True"
496+
AZURE_COSMOS_NON_STREAMING_ORDER_BY_FLAG_DISABLED: true

0 commit comments

Comments
 (0)