Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Task982443 #10

Merged
merged 2 commits into from
Jun 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 35 additions & 16 deletions SQLiteConnector/BL.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,29 @@ public void Dispose()
_sqLite.Dispose();
}
}


public void OpenDatabase(string filePath)
public void OpenDatabase(string filePath, bool dbCheck)
{
_sqLite = new DAL_SQLite();
_sqLite.OpenDatabase(filePath);
if (dbCheck)
{
DBCheck("TestResults", "TestCaseDescription", "TEXT");
}
}

private void DBCheck(string tableName, string fieldName, string fieldType)
{
string sql = "select count(*)"
+ $"\r\nfrom pragma_table_info({DAL_SQLite.SQLText(tableName)})"
+ $"\r\nwhere name={DAL_SQLite.SQLText(fieldName)}";
var fieldExists = _sqLite.ExecuteCommandValue(sql);

if (fieldExists.HasValue && fieldExists.Value == 0)
{
sql = $"ALTER TABLE {tableName}"
+ $"\r\nADD COLUMN {fieldName} {fieldType}";
_sqLite.ExecuteCommand(sql);
}
}

public void TestPlanSave(TestPlan testPlan)
Expand Down Expand Up @@ -239,7 +256,7 @@ public void TestResultsDelete()
}
public void TestResultInsert(TestStepResult testResult)
{
string sql = "INSERT INTO TestResults (RunId,ResultId,StartedDate,CompletedDate,Revision,State,Outcome,TestCaseId,TestCaseRevision,TestCaseTitle,TestCaseState,TestCaseStepsXML,TestPointId,BuildId,BuildName,RunBy)"
string sql = "INSERT INTO TestResults (RunId,ResultId,StartedDate,CompletedDate,Revision,State,Outcome,TestCaseId,TestCaseRevision,TestCaseTitle,TestCaseState,TestCaseStepsXML,TestCaseDescription,TestPointId,BuildId,BuildName,RunBy)"
+ "\r\nValues"
+ "(" + DAL_SQLite.SQLInt(testResult.RunId)
+ "," + DAL_SQLite.SQLInt(testResult.ResultId)
Expand All @@ -253,6 +270,7 @@ public void TestResultInsert(TestStepResult testResult)
+ "," + DAL_SQLite.SQLText(testResult.TestCaseTitle)
+ "," + DAL_SQLite.SQLText(testResult.TestCaseState)
+ "," + DAL_SQLite.SQLText(testResult.TestCaseStepsXML)
+ "," + DAL_SQLite.SQLText(testResult.TestCaseDescription)
+ "," + DAL_SQLite.SQLInt(testResult.TestPointId)
+ "," + DAL_SQLite.SQLInt(testResult.BuildId)
+ "," + DAL_SQLite.SQLText(testResult.BuildName)
Expand Down Expand Up @@ -293,7 +311,7 @@ public void TestResultInsert(TestStepResult testResult)

public List<TestStepResult> TestResultsRead(TestPoint testPoint, int? runId)
{
string sql = "SELECT tres.Id,tres.RunId,tres.ResultId,tres.StartedDate,tres.CompletedDate,tres.State,tres.Outcome,tres.TestCaseId,tres.TestCaseStepsXML,tres.BuildName,tres.RunBy,tres.TestCaseState"
string sql = "SELECT tres.Id,tres.RunId,tres.ResultId,tres.StartedDate,tres.CompletedDate,tres.State,tres.Outcome,tres.TestCaseId,tres.TestCaseStepsXML,tres.TestCaseDescription,tres.BuildName,tres.RunBy,tres.TestCaseState"
+ ",tr.Id,tr.OwnerDisplayName,tr.StartedDate,tr.CompletedDate,tr.State"
+ ",(exists(select * from TestResultSharedSteps st where st.TestResultId=tres.Id)) SharedSteps"
+ ",tres.Comment"
Expand Down Expand Up @@ -326,24 +344,25 @@ public List<TestStepResult> TestResultsRead(TestPoint testPoint, int? runId)
Outcome = _sqLite.Rdr_DataFieldStr(6),
TestCaseId = _sqLite.Rdr_DataFieldInt(7),
TestCaseStepsXML = _sqLite.Rdr_DataFieldStr(8),
BuildName = _sqLite.Rdr_DataFieldStr(9),
RunBy = _sqLite.Rdr_DataFieldStr(10),
TestCaseState = _sqLite.Rdr_DataFieldStr(11),
HasSharedSteps = _sqLite.Rdr_DataFieldInt(17) > 0,
Comment=(_sqLite.Rdr_DataFieldIsNull(18)?"": _sqLite.Rdr_DataFieldStr(18))
TestCaseDescription = _sqLite.Rdr_DataFieldStr(9),
BuildName = _sqLite.Rdr_DataFieldStr(10),
RunBy = _sqLite.Rdr_DataFieldStr(11),
TestCaseState = _sqLite.Rdr_DataFieldStr(12),
HasSharedSteps = _sqLite.Rdr_DataFieldInt(18) > 0,
Comment=(_sqLite.Rdr_DataFieldIsNull(19)?"": _sqLite.Rdr_DataFieldStr(19))
};
if (!dbIds.Contains(testResult.DBId))
dbIds.Add(testResult.DBId);

if (!_sqLite.Rdr_DataFieldIsNull(12))
if (!_sqLite.Rdr_DataFieldIsNull(13))
{
testResult.TestRun = new TestRun()
{
Id = _sqLite.Rdr_DataFieldInt(12),
OwnerDisplayName = _sqLite.Rdr_DataFieldStr(13),
StartedDate = _sqLite.Rdr_DataFieldDateTime(14),
CompletedDate = _sqLite.Rdr_DataFieldDateTime(15),
State = _sqLite.Rdr_DataFieldStr(16),
Id = _sqLite.Rdr_DataFieldInt(13),
OwnerDisplayName = _sqLite.Rdr_DataFieldStr(14),
StartedDate = _sqLite.Rdr_DataFieldDateTime(15),
CompletedDate = _sqLite.Rdr_DataFieldDateTime(16),
State = _sqLite.Rdr_DataFieldStr(17),
};
}

Expand Down
59 changes: 59 additions & 0 deletions SQLiteConnector/BusinessObjects/HTML.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
using System;
using System.Collections.Generic;
using System.Text;

namespace SQLite.BusinessObjects
{
internal static class HTML
{
public static string HtmlDecode(string html)
{
if (html == null)
return string.Empty;
string attribute = null; System.Text.StringBuilder result = new System.Text.StringBuilder();
for (int i = 0; i < html.Length; i++)
{
char c = html[i];
switch (c)
{
case '<': attribute = ""; break;
case '>':
if (attribute == null)
result.Append('>');
else
{
if (attribute.StartsWith("br", System.StringComparison.CurrentCultureIgnoreCase)) result.Append('\n');
if (attribute.StartsWith("p ", System.StringComparison.CurrentCultureIgnoreCase) && result.Length > 0) result.Append('\n');
}
attribute = null; break;
case '&':
if (attribute == null)
{
if (html.Length >= i + 4 && html.Substring(i, 4) == "&gt;")
{ result.Append('>'); i += 4 - 1; }
else if (html.Length >= i + 4 && html.Substring(i, 4) == "&lt;")
{ result.Append('<'); i += 4 - 1; }
else if (html.Length >= i + 6 && html.Substring(i, 6) == "&nbsp;")
{ result.Append(' '); i += 6 - 1; }
}
else
attribute += c;
break;

default:
if (attribute == null)
{
result.Append(c);
}
else
{
attribute += c;
}
break;
}
}

return result.ToString();
}
}
}
93 changes: 63 additions & 30 deletions SQLiteConnector/BusinessObjects/TestStepResult.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ public class TestStepResult
public int TestPointId { get; set; }
public string TestCaseStepsXML { get; set; }
public string TestCaseState { get; set; }
public string TestCaseDescription { get; set; }
public string TestCaseDescriptionText { get { return HTML.HtmlDecode(TestCaseDescription); } }
public bool HasSharedSteps { get; set; }
public string Comment { get; set; }

Expand Down Expand Up @@ -77,7 +79,8 @@ public List<Step> GetTestCaseSteps()
try
{
var result = new List<Step>();
Step currentStep = null; string currentElement = null;
Step currentStep = null;
var nodeHierarchy = new List<string>();

using (TextReader xmlReader = new StringReader(TestCaseStepsXML))
using (var reader = System.Xml.XmlReader.Create(xmlReader))
Expand All @@ -87,7 +90,11 @@ public List<Step> GetTestCaseSteps()
switch (reader.NodeType)
{
case System.Xml.XmlNodeType.Element:
currentElement = reader.Name;

while (nodeHierarchy.Count>0 && nodeHierarchy.Count > reader.Depth)
nodeHierarchy.RemoveAt(nodeHierarchy.Count - 1);
nodeHierarchy.Add(reader.Name);

if (string.Compare(reader.Name, "Step", true) == 0)
{
currentStep = new Step(); result.Add(currentStep);
Expand All @@ -114,31 +121,42 @@ public List<Step> GetTestCaseSteps()
currentStep.TypeOfStep = Step.TypesOfStep.SharedStepsRef;
}
}
else if (string.Compare(reader.Name, "ParameterizedString", true)==0 && nodeHierarchy.Count() == 3 && currentStep != null)
{
currentStep.PSNumber++;

switch (currentStep.PSNumber)
{
case 1:
if (!string.IsNullOrEmpty(reader.Value))
currentStep.Instructions = reader.Value;
break;
case 2:
if (!string.IsNullOrEmpty(reader.Value))
currentStep.ExpectedResult = reader.Value;
break;
}
}
break;


case System.Xml.XmlNodeType.Text:
if (currentStep != null && string.Compare(currentElement, "ParameterizedString", true) == 0)
if ( nodeHierarchy.Count > 2 && string.Compare(nodeHierarchy[2], "ParameterizedString", true) == 0 && currentStep != null)
{
switch (currentStep.PSNumber)
{
case 0:
currentStep.Instructions = reader.Value;
currentStep.PSNumber++;
break;
case 1:
currentStep.ExpectedResult = reader.Value;
currentStep.PSNumber++;
if (!string.IsNullOrEmpty(reader.Value))
currentStep.Instructions = reader.Value;
break;

case 2:
if (!string.IsNullOrEmpty(reader.Value))
currentStep.ExpectedResult = reader.Value;
break;
default:
throw new NotImplementedException($"Step has {currentStep.PSNumber} paramaterized strings (more than 2)");
}
}
break;

case System.Xml.XmlNodeType.EndElement:
currentElement = null;
break;
}
}
}
Expand Down Expand Up @@ -166,7 +184,8 @@ public List<Step> GetSteps(Step sharedStepRef)
try
{
var result = new List<Step>();
Step currentStep = null; string currentElement = null;
Step currentStep = null;
var nodeHierarchy = new List<string>();

using (TextReader xmlReader = new StringReader(SharedStepsXML))
using (var reader = System.Xml.XmlReader.Create(xmlReader))
Expand All @@ -176,7 +195,10 @@ public List<Step> GetSteps(Step sharedStepRef)
switch (reader.NodeType)
{
case System.Xml.XmlNodeType.Element:
currentElement = reader.Name;
while (nodeHierarchy.Count > 0 && nodeHierarchy.Count > reader.Depth)
nodeHierarchy.RemoveAt(nodeHierarchy.Count - 1);
nodeHierarchy.Add(reader.Name);

if (string.Compare(reader.Name, "Step", true) == 0)
{
currentStep = new Step() { TypeOfStep = Step.TypesOfStep.TestStepInSharedSteps, StepNumber = sharedStepRef.StepNumber, Id = sharedStepRef.Id }; result.Add(currentStep);
Expand All @@ -188,31 +210,42 @@ public List<Step> GetSteps(Step sharedStepRef)
currentStep.SharedStepsId = sharedStepsId;
}
}
else if (string.Compare(reader.Name, "ParameterizedString", true) == 0 && nodeHierarchy.Count() == 3 && currentStep != null)
{
currentStep.PSNumber++;

switch (currentStep.PSNumber)
{
case 1:
if (!string.IsNullOrEmpty(reader.Value))
currentStep.Instructions = reader.Value;
break;
case 2:
if (!string.IsNullOrEmpty(reader.Value))
currentStep.ExpectedResult = reader.Value;
break;
}
}
break;


case System.Xml.XmlNodeType.Text:
if (currentStep != null && string.Compare(currentElement, "ParameterizedString", true) == 0)
if (nodeHierarchy.Count > 2 && string.Compare(nodeHierarchy[2], "ParameterizedString", true) == 0 && currentStep != null)
{
switch (currentStep.PSNumber)
{
case 0:
currentStep.Instructions = reader.Value;
currentStep.PSNumber++;
break;
case 1:
currentStep.ExpectedResult = reader.Value;
currentStep.PSNumber++;
if (!string.IsNullOrEmpty(reader.Value))
currentStep.Instructions = reader.Value;
break;

case 2:
if (!string.IsNullOrEmpty(reader.Value))
currentStep.ExpectedResult = reader.Value;
break;
default:
throw new NotImplementedException($"Step has {currentStep.PSNumber} paramaterized strings (more than 2)");
}
}
break;

case System.Xml.XmlNodeType.EndElement:
currentElement = null;
break;
}
}
}
Expand Down
4 changes: 0 additions & 4 deletions SQLiteConnector/SQLiteConnector.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,6 @@
<TargetFramework>netcoreapp3.1</TargetFramework>
</PropertyGroup>

<ItemGroup>
<Folder Include="BusinessObjects\" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
<PackageReference Include="System.Data.SQLite.Core" Version="1.0.115.5" />
Expand Down
Loading
Loading