Skip to content

Commit 0c4a062

Browse files
committed
ToString override in query results model, tracing query results in integration test
1 parent f5629fa commit 0c4a062

File tree

2 files changed

+47
-19
lines changed

2 files changed

+47
-19
lines changed

Scripts/Services/Discovery/v1/DataModels.cs

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
*/
1717

1818
using FullSerializer;
19+
using System.Text;
1920

2021
namespace IBM.Watson.DeveloperCloud.Services.Discovery.v1
2122
{
@@ -340,6 +341,36 @@ public class QueryResponse
340341
public double matching_results { get; set; }
341342
public QueryResult[] results { get; set; }
342343
public QueryAggregation aggregations { get; set; }
344+
345+
public override string ToString()
346+
{
347+
StringBuilder stringBuilder = new StringBuilder();
348+
349+
if (!string.IsNullOrEmpty(matching_results.ToString()))
350+
stringBuilder.Append(string.Format("matching_results: {0}", matching_results.ToString()));
351+
352+
foreach(QueryResult result in results)
353+
{
354+
if(!string.IsNullOrEmpty(result.id))
355+
stringBuilder.Append(string.Format("result id: {0}", result.id) + "\n\t");
356+
357+
if(!string.IsNullOrEmpty(result.score.ToString()))
358+
stringBuilder.Append(string.Format("result score: {0}", result.score) + "\n\t");
359+
}
360+
361+
stringBuilder.Append("\n");
362+
363+
if (aggregations != null && aggregations.term != null && aggregations.term.results != null)
364+
{
365+
if (!string.IsNullOrEmpty(aggregations.term.results.key))
366+
stringBuilder.Append(string.Format("key: {0}", aggregations.term.results.key));
367+
368+
if (!string.IsNullOrEmpty(aggregations.term.results.matching_results.ToString()))
369+
stringBuilder.Append(string.Format("key: {0}", aggregations.term.results.matching_results.ToString()));
370+
}
371+
372+
return string.Format("{0}", stringBuilder.ToString());
373+
}
343374
}
344375

345376
[fsObject]

Scripts/UnitTests/TestDiscovery.cs

Lines changed: 16 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -350,21 +350,21 @@ public override IEnumerator RunTest()
350350

351351
#region Fields
352352
Log.Debug("ExampleDiscoveryV1", "Attempting to get fields");
353-
if(!m_Discovery.GetFields((GetFieldsResponse resp, string customData) =>
354-
{
355-
if(resp != null)
356-
{
357-
foreach (Field field in resp.fields)
358-
Log.Debug("ExampleDiscoveryV1", "Field: {0}, type: {1}", field.field, field.type);
359-
}
360-
else
361-
{
362-
Log.Debug("ExampleDiscoveryV1", "Discovery.GetFields(); resp is null");
363-
}
364-
365-
Test(resp != null);
366-
m_GetFieldsTested = true;
367-
}, m_CreatedEnvironmentID, m_CreatedCollectionID))
353+
if (!m_Discovery.GetFields((GetFieldsResponse resp, string customData) =>
354+
{
355+
if (resp != null)
356+
{
357+
foreach (Field field in resp.fields)
358+
Log.Debug("ExampleDiscoveryV1", "Field: {0}, type: {1}", field.field, field.type);
359+
}
360+
else
361+
{
362+
Log.Debug("ExampleDiscoveryV1", "Discovery.GetFields(); resp is null");
363+
}
364+
365+
Test(resp != null);
366+
m_GetFieldsTested = true;
367+
}, m_CreatedEnvironmentID, m_CreatedCollectionID))
368368
Log.Debug("ExampleDiscoveryV1", "Failed to get fields");
369369

370370
while (!m_GetFieldsTested)
@@ -445,10 +445,7 @@ public override IEnumerator RunTest()
445445
{
446446
if (resp != null)
447447
{
448-
//Log.Debug("ExampleDiscoveryV1", "key: {0}, matching results: {1}", resp.aggregations.term.results.key, resp.aggregations.term.results.matching_results);
449-
450-
foreach (QueryResult result in resp.results)
451-
Log.Debug("ExampleDiscoveryV1", "Query response: id: {0}, score: {1}", result.id, result.score);
448+
Log.Debug("ExampleDiscoveryV1", resp.ToString());
452449
}
453450
else
454451
{

0 commit comments

Comments
 (0)