Skip to content

Commit

Permalink
Merge pull request #7 from RalfVio/TaskTemplates
Browse files Browse the repository at this point in the history
Fix Incomplete Test Runs and Database Time Format
  • Loading branch information
RalfVio authored Dec 20, 2023
2 parents 0b861cf + f2bf588 commit 6473c5a
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 27 deletions.
26 changes: 12 additions & 14 deletions SQLiteConnector/DAL_SQLite.cs
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,8 @@ public static string SQLDate(DateTime? dDate, bool withTime)
if (!dDate.HasValue)
return "Null";

string formatDate = "yyyy-MM-dd";
string formatTime = "yyyy-MM-dd\\THH:mm:ss";
string formatDate = "yyyy\\-MM\\-dd";
string formatTime = "yyyy\\-MM\\-dd\\THH\\:mm\\:ss";

return SQLText(dDate.Value.ToString(withTime ? formatTime : formatDate));
}
Expand Down Expand Up @@ -246,22 +246,20 @@ public void Rdr_Close()
public byte Rdr_DataFieldByte(int col, byte nullValue) { return Rdr_DataFieldIsNull(col) ? nullValue : _dataReader.GetByte(col); }
public bool Rdr_DataFieldBool(int col, bool nullValue) { return Rdr_DataFieldIsNull(col) ? nullValue : _dataReader.GetInt32(col)>0; }
public Guid Rdr_DataFieldGuid(int col, Guid NullValue) { return Rdr_DataFieldIsNull(col) ? NullValue : _dataReader.GetGuid(col); }
public DateTime? Rdr_DataFieldDateTime(int col)
public DateTime? Rdr_DataFieldDateTime(int col)
{
if (Rdr_DataFieldIsNull(col)) return null;

if(System.Text.RegularExpressions.Regex.IsMatch(_dataReader.GetString(col), "^\\d{4}-\\d{2}-\\d{2}T"))
{
var formatedDateString = _dataReader.GetString(col).Replace("-", "/").Replace("T", " ").Replace(".", ":");
return DateTime.Parse(formatedDateString);
}
return _dataReader.GetDateTime(col);
}
if (Rdr_DataFieldIsNull(col)) return null;

#endregion
var value = Rdr_DataFieldStr(col);

#endregion
//temporary fix for time records containing '.' as separator
if(DateTime.TryParse(value.Replace('.',':'),out DateTime result))
return result;

throw new FormatException($"Unable to read date or time '{value}'");
}
#endregion

#endregion
}
}
8 changes: 4 additions & 4 deletions STI Test Report/ReadReportData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ private async Task ReadTestPoints(SQLite.BusinessObjects.TestPlan testPlan, List

private async Task ReadTestRuns(SQLite.BusinessObjects.TestPlan testPlan, ADORest.RestTestPlan adoRest, SQLiteConnector.BL sqlLiteBL)
{
const int top = 100;
const int batchSize = 100;

var startTime = DateTime.Now;
var startServiceCalls = adoRest.GetServiceCalls();
Expand All @@ -155,15 +155,15 @@ private async Task ReadTestRuns(SQLite.BusinessObjects.TestPlan testPlan, ADORes
{
batchNumber++;
WriteLog?.Invoke(this, new LogEventArgs() { Message = $"Test runs, batch {batchNumber}" });
var testRuns = await adoRest.GetTestRuns(testPlan, skip, top);
var testRuns = await adoRest.GetTestRuns(testPlan, skip, batchSize);

testRunsCount = testRuns.Count;
skip += testRunsCount;

foreach (var testRun in testRuns)
foreach (var testRun in testRuns.Runs)
sqlLiteBL.TestRunInsert(testRun);
}
while (testRunsCount == top);
while (testRunsCount > 0);

sqlLiteBL.StatsSave("TestRuns", startTime, DateTime.Now, adoRest.GetServiceCalls() - startServiceCalls);

Expand Down
24 changes: 17 additions & 7 deletions STI Test Report/Rest/RestTestPlan.cs
Original file line number Diff line number Diff line change
Expand Up @@ -230,12 +230,18 @@ public async Task<List<TestPoint>> GetTestPoints(TestSuite suite, int testPlanId

// return result;
//}
public async Task<List<TestRun>> GetTestRuns(TestPlan testPlan, int skip, int top)

public class TestRuns
{
public List<TestRun> Runs { get; set; }
public int Count { get; set; }
}
public async Task<TestRuns> GetTestRuns(TestPlan testPlan, int skip, int top)
{
//https://docs.microsoft.com/en-us/rest/api/azure/devops/test/runs/list?view=azure-devops-rest-7.1
string restUri = $"{_collectionUrl}/{_teamProject}/_apis/test/runs?planId={testPlan.Id}&includeRunDetails=true&$skip={skip}&$top={top}&api-version=7.1-preview.3";

List<TestRun> result = null;
TestRuns result = null;
try
{
if (_httpClient == null)
Expand All @@ -251,14 +257,18 @@ public async Task<List<TestRun>> GetTestRuns(TestPlan testPlan, int skip, int to
string responseString = await response.Content.ReadAsStringAsync();
dynamic resultJObject = JObject.Parse(responseString);
dynamic dataItemsJObject = resultJObject.value;
int count = resultJObject.count;
result = new List<TestRun>();
for (int i = 0; i < count; i++)
result = new TestRuns()
{

Runs = new List<TestRun>(),
Count = resultJObject.count,
};
for (int i = 0; i < result.Count; i++)
{
int id = dataItemsJObject[i].id;
string state = dataItemsJObject[i].state;
if (string.Compare(state, "255") != 0)
result.Add(new TestRun()
if (state != "255")
result.Runs.Add(new TestRun()
{
Id = dataItemsJObject[i].id,
Revision = dataItemsJObject[i].revision,
Expand Down
4 changes: 2 additions & 2 deletions STI Test Report/STI Test Report.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
<Company>Philips</Company>
<ProductName>STI Test Report</ProductName>
<StartupObject>STI_Test_Report.Program</StartupObject>
<Version>1.0.1.3</Version>
<FileVersion>1.0.1.3</FileVersion>
<Version>1.0.1.4</Version>
<FileVersion>1.0.1.4</FileVersion>
</PropertyGroup>

<ItemGroup>
Expand Down

0 comments on commit 6473c5a

Please sign in to comment.