Skip to content

Commit ae99a7c

Browse files
authored
replace commented Live tests (Azure#24802)
* replace commented Live tests
1 parent 44f593e commit ae99a7c

File tree

7 files changed

+526
-842
lines changed

7 files changed

+526
-842
lines changed

sdk/confidentialledger/Azure.Security.ConfidentialLedger/tests/ConfidentialLedgerClientLiveTests.cs

Lines changed: 97 additions & 86 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// Copyright (c) Microsoft Corporation. All rights reserved.
22
// Licensed under the MIT License.
33

4+
using System;
45
using System.Collections.Generic;
56
using System.IO;
67
using System.Net;
@@ -58,83 +59,59 @@ public async Task GetUser(string objId)
5859
Assert.That(stringResult, Does.Contain(objId));
5960
}
6061

61-
//[RecordedTest]
62-
//public async Task GetLedgerEntries()
63-
//{
64-
// await PostLedgerEntry();
65-
66-
// var result = await Client.GetLedgerEntriesAsync();
67-
68-
// var nextLinkDetails = GetNextLinkDetails(result);
69-
// while (nextLinkDetails != null)
70-
// {
71-
// var fromId = nextLinkDetails["fromTransactionId"];
72-
// var subId = nextLinkDetails["subLedgerId"];
73-
// result = await Client.GetLedgerEntriesAsync(subId, fromId).ConfigureAwait(false);
74-
// Assert.AreEqual((int)HttpStatusCode.OK, result.Status);
75-
// nextLinkDetails = GetNextLinkDetails(result);
76-
// }
77-
//}
78-
79-
//[RecordedTest]
80-
//public async Task GetLedgerEntry()
81-
//{
82-
// await PostLedgerEntry();
83-
84-
// var result = await Client.GetLedgerEntriesAsync();
85-
// var stringResult = new StreamReader(result.ContentStream).ReadToEnd();
86-
87-
// while (stringResult.Contains("Loading"))
88-
// {
89-
// result = await Client.GetLedgerEntriesAsync().ConfigureAwait(false);
90-
// stringResult = new StreamReader(result.ContentStream).ReadToEnd();
91-
// }
92-
// var transactionId = GetFirstTransactionId(result);
93-
// result = await Client.GetLedgerEntryAsync(transactionId).ConfigureAwait(false);
94-
95-
// Assert.AreEqual((int)HttpStatusCode.OK, result.Status);
96-
// Assert.That(stringResult, Does.Contain(transactionId));
97-
//}
98-
99-
//[RecordedTest]
100-
//public async Task GetReceipt()
101-
//{
102-
// await PostLedgerEntry();
103-
104-
// var result = await Client.GetLedgerEntriesAsync();
105-
// var stringResult = new StreamReader(result.ContentStream).ReadToEnd();
106-
107-
// while (stringResult.Contains("Loading"))
108-
// {
109-
// result = await Client.GetLedgerEntriesAsync().ConfigureAwait(false);
110-
// stringResult = new StreamReader(result.ContentStream).ReadToEnd();
111-
// }
112-
// var transactionId = GetFirstTransactionId(result);
113-
// result = await Client.GetReceiptAsync(transactionId).ConfigureAwait(false);
114-
115-
// Assert.AreEqual((int)HttpStatusCode.OK, result.Status);
116-
// Assert.That(stringResult, Does.Contain(transactionId));
117-
//}
118-
119-
//[RecordedTest]
120-
//public async Task GetTransactionStatus()
121-
//{
122-
// await PostLedgerEntry();
123-
124-
// var result = await Client.GetLedgerEntriesAsync();
125-
// var stringResult = new StreamReader(result.ContentStream).ReadToEnd();
126-
127-
// while (stringResult.Contains("Loading"))
128-
// {
129-
// result = await Client.GetLedgerEntriesAsync().ConfigureAwait(false);
130-
// stringResult = new StreamReader(result.ContentStream).ReadToEnd();
131-
// }
132-
// var transactionId = GetFirstTransactionId(result);
133-
// result = await Client.GetTransactionStatusAsync(transactionId).ConfigureAwait(false);
134-
135-
// Assert.AreEqual((int)HttpStatusCode.OK, result.Status);
136-
// Assert.That(stringResult, Does.Contain(transactionId));
137-
//}
62+
[RecordedTest]
63+
public async Task GetLedgerEntries()
64+
{
65+
await PostLedgerEntry();
66+
67+
await foreach (var entry in Client.GetLedgerEntriesAsync(new RequestOptions()))
68+
{
69+
Assert.NotNull(entry);
70+
}
71+
}
72+
73+
[RecordedTest]
74+
public async Task GetLedgerEntry()
75+
{
76+
await PostLedgerEntry();
77+
var tuple = await GetFirstTransactionIdFromGetEntries();
78+
string transactionId = tuple.TransactionId;
79+
string stringResult = tuple.StringResult;
80+
Response response = await Client.GetLedgerEntryAsync(transactionId, new RequestOptions());
81+
82+
Assert.AreEqual((int)HttpStatusCode.OK, response.Status);
83+
Assert.That(stringResult, Does.Contain(transactionId));
84+
}
85+
86+
[RecordedTest]
87+
public async Task GetReceipt()
88+
{
89+
await PostLedgerEntry();
90+
91+
var tuple = await GetFirstTransactionIdFromGetEntries();
92+
string transactionId = tuple.TransactionId;
93+
string stringResult = tuple.StringResult;
94+
95+
var result = await Client.GetReceiptAsync(transactionId, new RequestOptions()).ConfigureAwait(false);
96+
97+
Assert.AreEqual((int)HttpStatusCode.OK, result.Status);
98+
Assert.That(stringResult, Does.Contain(transactionId));
99+
}
100+
101+
[RecordedTest]
102+
public async Task GetTransactionStatus()
103+
{
104+
await PostLedgerEntry();
105+
106+
var tuple = await GetFirstTransactionIdFromGetEntries();
107+
string transactionId = tuple.TransactionId;
108+
string stringResult = tuple.StringResult;
109+
110+
var result = await Client.GetTransactionStatusAsync(transactionId, new RequestOptions()).ConfigureAwait(false);
111+
112+
Assert.AreEqual((int)HttpStatusCode.OK, result.Status);
113+
Assert.That(stringResult, Does.Contain(transactionId));
114+
}
138115

139116
[RecordedTest]
140117
public async Task GetConstitution()
@@ -231,22 +208,56 @@ private Dictionary<string, string> GetQueryStringKvps(string s)
231208
return result;
232209
}
233210

234-
private string GetFirstTransactionId(Response response)
211+
private async Task<(string TransactionId, string StringResult)> GetFirstTransactionIdFromGetEntries()
235212
{
236-
response.ContentStream.Position = 0;
237-
var stringResult = new StreamReader(response.ContentStream).ReadToEnd();
238-
var doc = JsonDocument.Parse(stringResult);
239-
if (doc.RootElement.TryGetProperty("entries", out var prop))
213+
string stringResult = "Loading";
214+
var result = Client.GetLedgerEntriesAsync(new RequestOptions());
215+
bool first = true;
216+
Response response = null;
217+
218+
await foreach (var page in result.AsPages())
219+
{
220+
if (first)
221+
{
222+
response = page.GetRawResponse();
223+
}
224+
foreach (var entry in page.Values)
225+
{
226+
stringResult = new StreamReader(entry.ToStream()).ReadToEnd();
227+
break;
228+
}
229+
first = false;
230+
}
231+
232+
while (stringResult.Contains("Loading"))
240233
{
241-
foreach (JsonElement entry in prop.EnumerateArray())
234+
first = true;
235+
result = Client.GetLedgerEntriesAsync(new RequestOptions());
236+
await foreach (var page in result.AsPages())
242237
{
243-
if (entry.TryGetProperty("transactionId", out var tid))
238+
if (first)
244239
{
245-
return tid.GetString();
240+
response = page.GetRawResponse();
246241
}
242+
foreach (var entry in page.Values)
243+
{
244+
stringResult = new StreamReader(entry.ToStream()).ReadToEnd();
245+
break;
246+
}
247+
first = false;
247248
}
248249
}
249-
return default;
250+
return (GetFirstTransactionId(stringResult), stringResult);
251+
}
252+
253+
private string GetFirstTransactionId(string stringResult)
254+
{
255+
var doc = JsonDocument.Parse(stringResult);
256+
if (doc.RootElement.TryGetProperty("transactionId", out var tid))
257+
{
258+
return tid.GetString();
259+
}
260+
throw new Exception($"Could not parse transationId from response:\n{stringResult}");
250261
}
251262

252263
private Dictionary<string, string> GetNextLinkDetails(Response response)

0 commit comments

Comments
 (0)