using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Threading;
using System.Windows;
using System.Windows.Forms;
using System.Xml.Serialization;
using QC.QsprShared.Trace;
using QC.QsprTestObjects.Loops;
using QC.QsprTestObjects.Parameters;
using QC.QsprTestObjects.Registry;
using QC.QsprTestObjects.TestConditions;
using QC.QsprTestObjects.Tests.Base;
using QC.QsprTestObjects.Tests.DotNet;
using QC.QsprTestObjects.Tests.TestCase;
using QC.QTMInterface;
using QC.QTMInterface.Business_Objects;
using QsprMiscShared.Utilities;

namespace QC.QTMApplication;

public class TestCaseDragDrop
{
	private delegate bool AddFolder(BaseTest root, Position pos);

	private delegate FolderTest AddTestCaseDelegate(TestCaseMaster testCaseMaster, BaseTest dropNode, bool retainTestCaseIndex = false, string nodePath = "");

	private TTDWpfTreeView _treeView;

	private Action<long> OnTestCaseAddedToTree;

	private static Dictionary<string, string> _originalIndexToNewIndexMap;

	private BaseTest _dropNode;

	private static XmlSerializer _testCaseSerializer = new XmlSerializer(typeof(TestCaseTest));

	private TestCasesPlugin _testCasesPlugin => _treeView.TestCasesPlugin;

	public TestCaseDragDrop(TTDWpfTreeView treeView)
	{
		_treeView = treeView;
	}

	public void HandleTestCaseDrop(System.Windows.DragEventArgs e, BaseTest DropNode)
	{
		List<TestCaseMaster> list = null;
		if (list == null)
		{
			list = (List<TestCaseMaster>)e.Data.GetData(typeof(List<TestCaseMaster>));
		}
		if (list != null)
		{
			HandleOldTestCaseDragDrop(DropNode, list);
			_treeView.ResetTestTreeUsingRootNode();
			return;
		}
		List<long> list2 = (List<long>)e.Data.GetData(typeof(List<long>));
		if (list2 == null || list2.Count == 0)
		{
			System.Windows.Forms.MessageBox.Show("You dropped something that's not a testcase.  Please try again.");
		}
		else
		{
			RequestTestCaseFromPluginThenInsertIntoTree(DropNode, list2);
		}
	}

	private void RequestTestCaseFromPluginThenInsertIntoTree(BaseTest DropNode, List<long> testCaseIds)
	{
		_dropNode = DropNode;
		_testCasesPlugin.OnRequestTestCasesByIdResult = OnRequestTestCasesByIdResult;
		ThreadPool.QueueUserWorkItem(delegate
		{
			_testCasesPlugin.RequestTestCasesByVersionIds(testCaseIds);
		});
	}

	public bool AddFolderToTree(BaseTest root, Position pos)
	{
		FolderTest folderTest = new FolderTest("Manual");
		folderTest.Properties.CheckStateTest = CheckState.Checked;
		return _treeView.AddNewNode(root, folderTest, pos);
	}

	public bool AddStartupFolderToTree(BaseTest root, Position pos)
	{
		FolderTest folderTest = new FolderTest("StartUp");
		folderTest.Properties.CheckStateTest = CheckState.Checked;
		return _treeView.AddNewNode(root, folderTest, pos);
	}

	public bool AddShutdownFolderToTree(BaseTest root, Position pos)
	{
		FolderTest folderTest = new FolderTest("ShutDown");
		folderTest.Properties.CheckStateTest = CheckState.Checked;
		return _treeView.AddNewNode(root, folderTest, pos);
	}

	private void OnRequestTestCasesByIdResult(List<TestCaseMaster> testCases)
	{
		HandleOldTestCaseDragDrop(_dropNode, Enumerable.Reverse(testCases).ToList());
	}

	public void OnRequestTestCasesByIdResultAutomation(List<TestCaseMaster> testCases)
	{
		_dropNode = null;
		if (_treeView.Root.TestList.Count == 0)
		{
			if (_treeView.InvokeRequired())
			{
				AddFolder function = AddStartupFolderToTree;
				_treeView.Invoke(function, new object[2]
				{
					_treeView.Root,
					Position.Last
				});
				AddTestInfo newTestInfo = default(AddTestInfo);
				newTestInfo.realName = "TestPlanStartup";
				newTestInfo.newTestName = "TestPlanStartup";
				newTestInfo.destinationIndex = (from T in _treeView.Root.TestList.ToList()
					where T.Properties.TestName.Equals("StartUp")
					select T).FirstOrDefault().Index;
				newTestInfo.position = Position.Last;
				_treeView.AddTestExcelUpload(newTestInfo, (from T in _treeView.Root.TestList.ToList()
					where T.Properties.TestName.Equals("StartUp")
					select T).FirstOrDefault());
			}
			if (_treeView.InvokeRequired())
			{
				AddFolder function2 = AddFolderToTree;
				_treeView.Invoke(function2, new object[2]
				{
					_treeView.Root,
					Position.Last
				});
			}
			if (_treeView.InvokeRequired())
			{
				AddFolder function3 = AddShutdownFolderToTree;
				_treeView.Invoke(function3, new object[2]
				{
					_treeView.Root,
					Position.Last
				});
				AddTestInfo newTestInfo2 = default(AddTestInfo);
				newTestInfo2.realName = "TestPlanShutdown";
				newTestInfo2.newTestName = "TestPlanShutdown";
				newTestInfo2.destinationIndex = (from T in _treeView.Root.TestList.ToList()
					where T.Properties.TestName.Equals("ShutDown")
					select T).FirstOrDefault().Index;
				newTestInfo2.position = Position.Last;
				_treeView.AddTestExcelUpload(newTestInfo2, (from T in _treeView.Root.TestList.ToList()
					where T.Properties.TestName.Equals("ShutDown")
					select T).FirstOrDefault());
			}
			_dropNode = (from T in _treeView.Root.TestList.ToList()
				where T.Properties.TestName.Equals("Manual")
				select T).FirstOrDefault();
		}
		else
		{
			if (_treeView.Root.TestList != null && _treeView.Root.TestList.Count > 0)
			{
				_dropNode = (from T in _treeView.Root.TestList.ToList()
					where T.Properties.TestName.Equals("Manual")
					select T).FirstOrDefault();
			}
			if (_dropNode == null)
			{
				BaseTest baseTest = _treeView.Root.FindTestFromTestName("TestPlanShutdown", isPartialName: false);
				if (baseTest != null && baseTest.Parent != null && baseTest.Parent.Parent != null)
				{
					if (_treeView.InvokeRequired())
					{
						int num = _treeView.Root.TestList.IndexOf(baseTest.Parent);
						BaseTest baseTest2 = _treeView.Root.TestList[num - 1];
						((FolderTest)baseTest2).Properties.Expanded = false;
						AddFolder function4 = AddFolderToTree;
						_treeView.Invoke(function4, new object[2]
						{
							baseTest2,
							Position.Last
						});
					}
				}
				else if (_treeView.InvokeRequired())
				{
					AddFolder function5 = AddFolderToTree;
					_treeView.Invoke(function5, new object[2]
					{
						_treeView.Root,
						Position.Last
					});
				}
				_dropNode = (from T in _treeView.Root.TestList.ToList()
					where T.Properties.TestName.Equals("Manual")
					select T).FirstOrDefault();
			}
			else
			{
				((FolderTest)_dropNode).Properties.Expanded = true;
			}
		}
		HandleOldTestCaseDragDrop(_dropNode, Enumerable.Reverse(testCases).ToList());
		_dropNode = null;
	}

	private void HandleOldTestCaseDragDrop(BaseTest DropNode, List<TestCaseMaster> testCaseDataList)
	{
		FolderTest folderTest = null;
		FolderTest folderTest2 = null;
		if (testCaseDataList != null)
		{
			foreach (TestCaseMaster testCaseData in testCaseDataList)
			{
				folderTest = AddTestCase(testCaseData, DropNode);
				if (folderTest2 == null)
				{
					folderTest2 = folderTest;
				}
				if (OnTestCaseAddedToTree != null)
				{
					OnTestCaseAddedToTree(testCaseData.Id);
				}
			}
		}
		if (folderTest2 != null)
		{
			_treeView.TestTreeSelectionManager.SelectTest(folderTest2);
		}
	}

	private TestCaseMaster GetTestCase(long id, uint version)
	{
		using (Dictionary<string, TestCasesPlugin>.ValueCollection.Enumerator enumerator = _treeView.TestCasesPluginsColl.Values.GetEnumerator())
		{
			if (enumerator.MoveNext())
			{
				TestCasesPlugin current = enumerator.Current;
				return current.GetTestCase(id, version);
			}
		}
		return null;
	}

	public FolderTest AddTestCase(TestCaseMaster testCaseMaster, BaseTest dropNode, bool retainTestCaseIndex = false, string nodePath = "")
	{
		if (_treeView.InvokeRequired())
		{
			AddTestCaseDelegate function = AddTestCase;
			return _treeView.Invoke(function, new object[4] { testCaseMaster, dropNode, retainTestCaseIndex, "" }) as FolderTest;
		}
		if (testCaseMaster.LatestVersion.TestCaseType == TestCaseTypes.Automated && string.IsNullOrWhiteSpace(testCaseMaster.LatestVersion.XmlData))
		{
			System.Windows.Forms.MessageBox.Show("Invalid TestCase being added.  Data is NULL\nTestcase Name: " + testCaseMaster.Name);
			return null;
		}
		FolderTest FolderNode = null;
		_treeView.TestTreeSelectionManager.SelectTest(dropNode);
		Position insertPosition = ((!(dropNode is FolderTest)) ? Position.NextSibling : Position.First);
		if (_treeView.AddFolder(insertPosition, out FolderNode, dropNode, isTestCaseFolder: true))
		{
			InitializeNodeAsTestCase(testCaseMaster, FolderNode, _treeView, dropNode, retainTestCaseIndex, nodePath);
			if (_treeView.Root.RootProperties.TreeType != TreeTypes.TestPlan)
			{
				System.Windows.Forms.MessageBox.Show("This tree is converting into testplan format because you have added a test case to it.");
				_treeView.SetTreeType(TreeTypes.TestPlan);
			}
		}
		AddTestDLLsToRegistry(testCaseMaster);
		_treeView.TestTreeSelectionManager.SelectTest(FolderNode);
		return FolderNode;
	}

	private void AddTestDLLsToRegistry(TestCaseMaster testCaseMaster)
	{
		List<string> list = new List<string>();
		foreach (TestCaseStep step in testCaseMaster.LatestVersion.Steps)
		{
			if (!string.IsNullOrWhiteSpace(step.DLLPath) && !list.Contains(step.DLLPath))
			{
				list.Add(step.DLLPath);
			}
		}
		foreach (string item in list)
		{
			_treeView.AddContainer(QC.QsprTestObjects.Tests.Base.QTMTestTypes.DotNetTest, new string[1] { item });
		}
	}

	public static void InitializeNodeAsTestCase(TestCaseMaster testCaseMaster, FolderTest testCaseFolderNode, TTDWpfTreeView treeView, BaseTest dropNode = null, bool retainTestCaseIndex = false, string nodePath = "")
	{
		_originalIndexToNewIndexMap = new Dictionary<string, string>();
		TestCaseTest testCaseTest = (TestCaseTest)DeserializeTestCaseMaster(testCaseMaster);
		string text = ((testCaseFolderNode as TestCaseTest).Index = testCaseTest.OriginalIndex);
		string key = text;
		string empty = string.Empty;
		empty = ((dropNode != null && dropNode is TestCaseTest && (dropNode as TestCaseTest).Index.Length > 0 && retainTestCaseIndex) ? ((string.IsNullOrWhiteSpace(nodePath) || string.Compare((dropNode as TestCaseTest).Index, nodePath, ignoreCase: true) == 0) ? (dropNode as TestCaseTest).Index : nodePath) : ((!retainTestCaseIndex || string.IsNullOrWhiteSpace(nodePath)) ? Guid.NewGuid().ToString() : nodePath));
		_originalIndexToNewIndexMap.Add(key, empty);
		TestCaseTest obj = testCaseFolderNode as TestCaseTest;
		string index = ((testCaseFolderNode as TestCaseTest).OriginalIndex = empty);
		obj.Index = index;
		(testCaseFolderNode as TestCaseTest).TestCaseProperties.DisplayID = testCaseMaster.DisplayId;
		(testCaseFolderNode as TestCaseTest).TestCaseProperties.TestCaseID = testCaseMaster.LatestVersion.Id;
		(testCaseFolderNode as TestCaseTest).TestCaseProperties.TestCaseMasterID = testCaseMaster.Id;
		(testCaseFolderNode as TestCaseTest).TestCaseProperties.TestCaseDescription = testCaseMaster.LatestVersion.Description;
		(testCaseFolderNode as TestCaseTest).TestCaseProperties.Status = testCaseMaster.LatestVersion.ApprovalState;
		(testCaseFolderNode as TestCaseTest).TestCaseProperties.Version = (uint)testCaseMaster.LatestVersion.VersionNumber;
		(testCaseFolderNode as TestCaseTest).TestCaseProperties.ModifiedDate = testCaseMaster.LatestVersion.ModifiedDate;
		(testCaseFolderNode as TestCaseTest).Properties.TestName = testCaseMaster.Name;
		testCaseFolderNode.ConfigureNodeImage("/QSPR;component/Icons/TestTreeTestCase.png", "/QSPR;component/Icons/TestTreeTestCase.png");
		treeView.TestTreeEditor.EndTestNameEdit(testCaseFolderNode, commit: true);
		testCaseFolderNode.TestList = testCaseTest.TestList;
		treeView.ConstructNodesFromFolder(testCaseFolderNode as TestCaseTest);
		testCaseFolderNode.Properties.CheckStateTest = CheckState.Checked;
		testCaseFolderNode.TestList[0].TestUserInterfaceProperties.Visible = treeView._scheduler.QTMData.WConfig.ShowSingleStepTestCaseSteps || testCaseMaster.LatestVersion.Steps.Count > 1;
		SetupNodeAsTestStepIncludingChildren(testCaseFolderNode, testCaseMaster.LatestVersion);
		testCaseFolderNode.Properties.Expanded = true;
		GenerateStepGuids(testCaseFolderNode);
		UpdateIndexReferences(testCaseFolderNode);
		treeView.RefreshTreeViewList(treeView.Root.TestList.ToList());
	}

	private static void UpdateIndexReferences(BaseTest node)
	{
		if (node.Properties.Scenarios != null)
		{
			foreach (LoopCondition loopCondition in node.Properties.Scenarios.LoopConditions)
			{
				if (!string.IsNullOrWhiteSpace(loopCondition.TestIndex))
				{
					loopCondition.TestIndex = ReplaceOldIndexWithNewIndex(loopCondition.TestIndex);
				}
			}
			if (node.Properties.Scenarios != null && node.Properties.Scenarios.Condition != null && node.Properties.Scenarios.Condition.Conditions != null)
			{
				foreach (BaseCondition condition in node.Properties.Scenarios.Condition.Conditions)
				{
					if (condition is ScenarioCondition)
					{
						(condition as ScenarioCondition).TestIndex = ReplaceOldIndexWithNewIndex((condition as ScenarioCondition).TestIndex);
					}
				}
			}
		}
		if (node.Properties.PreCondition != null)
		{
			node.Properties.PreCondition.BranchTestIndex = ReplaceOldIndexWithNewIndex(node.Properties.PreCondition.BranchTestIndex);
			for (int i = 0; i < node.Properties.PreCondition.Conditions.Count; i++)
			{
				((TestPreCondition)node.Properties.PreCondition.Conditions[i]).TestIndex = ReplaceOldIndexWithNewIndex(((TestPreCondition)node.Properties.PreCondition.Conditions[i]).TestIndex);
			}
		}
		if (node.Properties.PostCondition != null)
		{
			node.Properties.PostCondition.BranchTestIndex = ReplaceOldIndexWithNewIndex(node.Properties.PostCondition.BranchTestIndex);
		}
		if (!(node is FolderTest))
		{
			return;
		}
		foreach (BaseTest test in (node as FolderTest).TestList)
		{
			UpdateIndexReferences(test);
		}
	}

	private static string ReplaceOldIndexWithNewIndex(string index)
	{
		foreach (string key in _originalIndexToNewIndexMap.Keys)
		{
			index = index.Replace(key, _originalIndexToNewIndexMap[key]);
		}
		return index;
	}

	private static void GenerateStepGuids(FolderTest node)
	{
		foreach (BaseTest test in node.TestList)
		{
			string text = Guid.NewGuid().ToString();
			_originalIndexToNewIndexMap.Add(test.Index, text);
			test.Index = text;
			if (test is FolderTest)
			{
				GenerateStepGuids(test as FolderTest);
			}
		}
	}

	private static void SetupNodeAsTestStepIncludingChildren(FolderTest testCaseFolderNode, TestCaseVersion testCaseVersion)
	{
		foreach (BaseTest test in testCaseFolderNode.TestList)
		{
			BaseTest baseTest = test;
			baseTest.IsTestStep = true;
			if (baseTest is DotNetTest)
			{
				DotNetTest dotNetTest = baseTest as DotNetTest;
				if (!string.IsNullOrWhiteSpace(dotNetTest.DotNetProperties.DllName))
				{
					TestCaseStep testCaseStep = testCaseVersion.Steps.FirstOrDefault((TestCaseStep t) => t.DLLPath.EndsWith(dotNetTest.DotNetProperties.DllName) && t.Name == dotNetTest.DotNetProperties.TestName);
					if (testCaseStep != null)
					{
						dotNetTest.DotNetProperties.MinDllVersion = testCaseStep.DLLVersion;
					}
				}
			}
			if (test is FolderTest)
			{
				SetupNodeAsTestStepIncludingChildren(test as FolderTest, testCaseVersion);
			}
		}
	}

	public static BaseTest DeserializeTestCaseMaster(TestCaseMaster testCaseMaster)
	{
		string xmlData = testCaseMaster.LatestVersion.XmlData;
		using StringReader textReader = new StringReader(xmlData);
		if (testCaseMaster.LatestVersion.XmlData.Contains("<TestCaseTest"))
		{
			XmlSerializer xmlSerializer = new XmlSerializer(typeof(TestCaseTest));
			TestCaseTest testCaseTest = (TestCaseTest)xmlSerializer.Deserialize(textReader);
			testCaseTest.TestCaseProperties.TestCaseMasterID = testCaseMaster.Id;
			testCaseTest.TestCaseProperties.DisplayID = testCaseMaster.DisplayId;
			testCaseTest.TestCaseProperties.TestCaseDescription = testCaseMaster.LatestVersion.Description;
			return testCaseTest;
		}
		if (testCaseMaster.LatestVersion.XmlData.Contains("<FolderTest"))
		{
			XmlSerializer xmlSerializer2 = new XmlSerializer(typeof(FolderTest));
			return (FolderTest)xmlSerializer2.Deserialize(textReader);
		}
		if (testCaseMaster.LatestVersion.XmlData.Contains("<ManualTest"))
		{
			XmlSerializer xmlSerializer3 = new XmlSerializer(typeof(ManualTest));
			return (ManualTest)xmlSerializer3.Deserialize(textReader);
		}
		if (testCaseMaster.LatestVersion.XmlData.Contains("<DotNetTest"))
		{
			XmlSerializer xmlSerializer4 = new XmlSerializer(typeof(DotNetTest));
			return (DotNetTest)xmlSerializer4.Deserialize(textReader);
		}
		return null;
	}

	private void SetTestCaseProperties(TestCaseTest testCaseTest, TestCaseMaster testCaseMaster)
	{
		testCaseTest.TestCaseProperties = new TestCaseTestProperties
		{
			TestCaseName = testCaseMaster.Name,
			TestCaseMasterID = testCaseMaster.Id,
			DisplayID = testCaseMaster.DisplayId,
			TestCaseID = testCaseMaster.LatestVersion.Id,
			TestCaseDescription = testCaseMaster.LatestVersion.Description,
			Type = testCaseMaster.Versions.First().TestCaseType
		};
		testCaseTest.TestCaseMasterData = testCaseMaster;
	}

	private static bool TestOrChildIsManual(BaseTest test)
	{
		if (test.Properties.IsManual)
		{
			return true;
		}
		if (test is FolderTest)
		{
			FolderTest folderTest = test as FolderTest;
			foreach (BaseTest test2 in folderTest.TestList)
			{
				if (TestOrChildIsManual(test2))
				{
					return true;
				}
			}
		}
		return false;
	}

	public static TestCaseMaster CreateTestCaseData(BaseTest test)
	{
		TestCaseMaster testCaseMaster = new TestCaseMaster();
		testCaseMaster.Name = test.Properties.TestName;
		TestCaseMaster testCaseMaster2 = testCaseMaster;
		if (test is TestCaseTest)
		{
			testCaseMaster2.Id = (test as TestCaseTest).TestCaseProperties.TestCaseMasterID;
			testCaseMaster2.Name = (test as TestCaseTest).TestCaseProperties.TestCaseName;
		}
		TestCaseVersion testCaseVersion = new TestCaseVersion();
		testCaseVersion.Description = test.Properties.Description;
		testCaseVersion.ApprovalState = ApprovalStates.Draft;
		testCaseVersion.CreatedDate = DateTime.Now;
		testCaseVersion.ModifiedDate = DateTime.Now;
		testCaseVersion.XmlData = GenerateXmlData(test);
		testCaseVersion.TestCaseType = ((!TestOrChildIsManual(test)) ? TestCaseTypes.Automated : TestCaseTypes.Manual);
		testCaseVersion.Steps = new List<TestCaseStep>();
		TestCaseVersion testCaseVersion2 = testCaseVersion;
		testCaseMaster2.Versions.Add(testCaseVersion2);
		if (test is FolderTest)
		{
			if (!(test is TestCaseTest) || string.IsNullOrWhiteSpace(testCaseMaster2.Name))
			{
				testCaseMaster2.Name = ((FolderTest)test).FolderProperties.TestName;
			}
			if (!AddTestCaseSteps(test, testCaseVersion2))
			{
				return null;
			}
		}
		else if (test is DotNetTest)
		{
			testCaseMaster2.Name = test.Properties.TestName;
			TestCaseStep testCaseStep = CreateTestStepData(test);
			if (testCaseStep == null)
			{
				return null;
			}
			testCaseVersion2.Steps.Add(testCaseStep);
		}
		return testCaseMaster2;
	}

	private static bool AddTestCaseSteps(BaseTest test, TestCaseVersion testCaseVersion)
	{
		foreach (BaseTest test2 in ((FolderTest)test).TestList)
		{
			if (test2 is FolderTest)
			{
				if (!AddTestCaseSteps(test2, testCaseVersion))
				{
					return false;
				}
			}
			else if (test2 is DotNetTest)
			{
				TestCaseStep testCaseStep = CreateTestStepData(test2);
				if (testCaseStep == null)
				{
					return false;
				}
				testCaseVersion.Steps.Add(testCaseStep);
			}
		}
		return true;
	}

	public static string GenerateXmlData(BaseTest test)
	{
		try
		{
			if (test is FolderTest)
			{
				TestCaseTest testCase = CreateTestCaseFromFolder(test);
				return SerializeTestCaseToString(testCase);
			}
			if (test is DotNetTest)
			{
				TestCaseTest testCase2 = CreateTestCaseFromDotNetTest(test);
				return SerializeTestCaseToString(testCase2);
			}
			return "";
		}
		catch (Exception ex)
		{
			TraceMessage.Write("TestCaseDragDrop", "Exception generating xml data: " + ex.InnerException.ToString(), TraceMessageType.Exception);
			return "";
		}
	}

	private static string SerializeTestCaseToString(TestCaseTest testCase)
	{
		using StringWriter stringWriter = new StringWriter();
		_testCaseSerializer.Serialize(stringWriter, testCase);
		return stringWriter.ToString();
	}

	private static TestCaseTest CreateTestCaseFromFolder(BaseTest test)
	{
		FolderTest folderTest = (FolderTest)test;
		FolderTestProperties folderProperties = folderTest.FolderProperties;
		TestCaseTest testCaseTest = folderTest.AsTestCaseTest();
		testCaseTest.TestCaseProperties = folderProperties.AsTestCaseTestProperties();
		return testCaseTest;
	}

	private static TestCaseTest CreateTestCaseFromDotNetTest(BaseTest test)
	{
		TestCaseTest testCaseTest = new TestCaseTest();
		testCaseTest.TestList.Add(test);
		return testCaseTest;
	}

	private static TestCaseStep CreateTestStepData(BaseTest test)
	{
		if (!((QTMRegistry)test.Root.Scheduler.QTMData.theRegistry).GetContainerForTest(test.Properties.RealName, test.Properties.TargetName, out var tContainer))
		{
			System.Windows.Forms.MessageBox.Show("Unable to create test step because DLL is missing.\nPlease load the DLL for the test " + test.Properties.RealName);
			return null;
		}
		TestCaseStep testCaseStep = new TestCaseStep();
		testCaseStep.RealName = test.Properties.RealName;
		testCaseStep.Name = test.Properties.TestName;
		testCaseStep.DLLPath = ((tContainer != null) ? tContainer.Name : string.Empty);
		testCaseStep.IsSetup = test.Properties.IsSetupTestStep;
		testCaseStep.IsTearDown = test.Properties.IsTearDownTestStep;
		TestCaseStep testCaseStep2 = testCaseStep;
		if (test.Properties is DotNetTestProperties)
		{
			testCaseStep2.DLLVersion = (test.Properties as DotNetTestProperties).MinDllVersion;
		}
		testCaseStep2.Parameters = new List<TestParameter>();
		foreach (ParameterCls parameter in test.Properties.Parameters)
		{
			testCaseStep2.Parameters.Add(new TestParameter
			{
				Value = parameter.Value,
				Description = parameter.Description,
				NoOfElements = parameter.NoOfElements,
				Name = parameter.Name,
				Unit = parameter.Unit,
				GVSet = parameter.GlobalVariableNameOther,
				GVGet = parameter.GlobalVariableName,
				IsOutput = parameter.IsOutput,
				DefaultLL = parameter.LowerLimit,
				DefaultUL = parameter.UpperLimit,
				LL = parameter.LowerLimit,
				UL = parameter.UpperLimit,
				DefaultValue = parameter.Value,
				AttributeFlags = (parameter.CanEditResultValue ? 1 : 0)
			});
		}
		return testCaseStep2;
	}
}
