/// <summary> /// Gets the shared step by unique identifier. /// </summary> /// <param name="sharedStepId">The shared step unique identifier.</param> /// <returns></returns> public static SharedStep GetSharedStepById(ITestManagementTeamProject testManagementTeamProject, int sharedStepId) { ISharedStep sharedStepCore = testManagementTeamProject.SharedSteps.Find(sharedStepId); SharedStep currentSharedStep = new SharedStep(sharedStepCore); return(currentSharedStep); }
/// <summary> /// Saves the specified shared step. /// </summary> /// <param name="sharedStep">The shared step.</param> /// <param name="createNew">if set to <c>true</c> [create new].</param> /// <param name="newSuiteTitle">The new suite title.</param> /// <param name="testSteps">The test steps.</param> /// <returns></returns> public static SharedStep Save(this SharedStep sharedStep, ITestManagementTeamProject testManagementTeamProject, bool createNew, ICollection <TestStep> testSteps, bool shouldSetArea = true) { SharedStep currentSharedStep = sharedStep; if (createNew) { ISharedStep sharedStepCore = testManagementTeamProject.SharedSteps.Create(); currentSharedStep = new SharedStep(sharedStepCore); } if (shouldSetArea) { currentSharedStep.ISharedStep.Area = sharedStep.Area; } currentSharedStep.ISharedStep.Title = sharedStep.Title; currentSharedStep.ISharedStep.Priority = (int)sharedStep.Priority; currentSharedStep.ISharedStep.Actions.Clear(); currentSharedStep.ISharedStep.Owner = testManagementTeamProject.TfsIdentityStore.FindByTeamFoundationId(sharedStep.TeamFoundationId); List <Guid> addedSharedStepGuids = new List <Guid>(); foreach (TestStep currentStep in testSteps) { ITestStep testStepCore = currentSharedStep.ISharedStep.CreateTestStep(); testStepCore.Title = currentStep.ActionTitle; testStepCore.ExpectedResult = currentStep.ActionExpectedResult; currentSharedStep.ISharedStep.Actions.Add(testStepCore); } currentSharedStep.ISharedStep.Flush(); currentSharedStep.ISharedStep.Save(); return(currentSharedStep); }
/// <summary> /// Заполняет Excel таблицу данными по шагам тестового случая. /// </summary> /// <param name="testActions">Шаги теста.</param> private void BySteps(TestActionCollection testActions) { int stepId = 1; foreach (var stestStep in testActions) { ITestStep testStep = stestStep as ITestStep; if (testStep != null) { xlWorkSheet.Cells[row, 3] = stepId.ToString() + @". " + testStep.Title.ToPlainText(); xlWorkSheet.Cells[row, 4] = testStep.ExpectedResult.ToPlainText(); stepId++; row++; } else { //расшаренный шаг ISharedStep testStepS = stestStep as ISharedStep; if (testStepS != null) { xlWorkSheet.Cells[row, 3] = testStepS.Title.ToString() + @". " + testStep.Title.ToPlainText(); stepId++; row++; } } } }
/// <summary> /// Adds the new shared step internal. /// </summary> /// <param name="testCase">The test case.</param> /// <param name="addedSharedStepGuids">The added shared step guids.</param> /// <param name="currentStep">The current step.</param> private void AddNewSharedStepInternal(TestCase testCase, List <Guid> addedSharedStepGuids, TestStep currentStep, int sharedStepId) { ISharedStep sharedStep = ExecutionContext.TestManagementTeamProject.SharedSteps.Find(sharedStepId); ISharedStepReference sharedStepReferenceCore = testCase.ITestCase.CreateSharedStepReference(); sharedStepReferenceCore.SharedStepId = sharedStep.Id; testCase.ITestCase.Actions.Add(sharedStepReferenceCore); addedSharedStepGuids.Add(currentStep.TestStepGuid); }
/// <summary> /// Initializes a new instance of the <see cref="TestCaseEditViewModel"/> class. /// </summary> /// <param name="editViewContext">The edit view context.</param> public TestCaseEditViewModel(EditViewContext editViewContext) { this.EditViewContext = editViewContext; this.Areas = this.GetProjectAreas(); this.ObservableTestSteps = new ObservableCollection <TestStep>(); this.GenericParameters = new Dictionary <string, Dictionary <string, string> >(); if (!this.EditViewContext.IsSharedStep) { this.ShowTestCaseSpecificFields = true; ITestSuiteBase testSuiteBaseCore = null; if (this.EditViewContext.TestSuiteId != -1) { testSuiteBaseCore = TestSuiteManager.GetTestSuiteById(TestCaseManagerCore.ExecutionContext.TestManagementTeamProject, TestCaseManagerCore.ExecutionContext.Preferences.TestPlan, this.EditViewContext.TestSuiteId); } if (this.EditViewContext.CreateNew && !this.EditViewContext.Duplicate) { ITestCase newTestCase = TestCaseManagerCore.ExecutionContext.TestManagementTeamProject.TestCases.Create(); this.TestCase = new TestCase(newTestCase, testSuiteBaseCore, TestCaseManagerCore.ExecutionContext.Preferences.TestPlan, false); } else { ITestCase testCaseCore = TestCaseManagerCore.ExecutionContext.TestManagementTeamProject.TestCases.Find(this.EditViewContext.TestCaseId); this.TestCase = new TestCase(testCaseCore, testSuiteBaseCore, TestCaseManagerCore.ExecutionContext.Preferences.TestPlan, false); } this.ObservableSharedSteps = new ObservableCollection <SharedStep>(); this.InitializeObservableSharedSteps(); this.InitializeInitialSharedStepCollection(); this.InitializeTestCaseTestStepsFromITestCaseActions(); this.AssociatedAutomation = this.TestCase.ITestCase.GetAssociatedAutomation(); this.TestBase = this.TestCase; } else { if (this.EditViewContext.CreateNew && !this.EditViewContext.Duplicate) { ISharedStep currentSharedStepCore = TestCaseManagerCore.ExecutionContext.TestManagementTeamProject.SharedSteps.Create(); this.SharedStep = new SharedStep(currentSharedStepCore); } else { SharedStep currentSharedStep = SharedStepManager.GetSharedStepById(TestCaseManagerCore.ExecutionContext.TestManagementTeamProject, this.EditViewContext.SharedStepId); this.SharedStep = currentSharedStep; } List <TestStep> innerTestSteps = TestStepManager.GetAllTestStepsInSharedStep(this.SharedStep.ISharedStep, false); this.AddTestStepsToObservableCollection(innerTestSteps); this.ShowTestCaseSpecificFields = false; this.TestBase = this.SharedStep; this.ClearTestStepNames(); } this.InitializeIdLabelFromTestBase(this.EditViewContext.CreateNew, this.EditViewContext.Duplicate); this.InitializePageTitle(); log.InfoFormat("Load Edit View with Context: {0} ", editViewContext); TestStepManager.UpdateGenericSharedSteps(this.ObservableTestSteps); }
public TfsSharedStep(ISharedStep originalSharedStep) { if (originalSharedStep == null) { throw new ArgumentNullException("originalSharedStep"); } OrginialSharedStep = originalSharedStep; Id = OrginialSharedStep.Id; Title = OrginialSharedStep.WorkItem.Title; }
/// <summary> /// Creates the new shared step. /// </summary> /// <param name="testCase">The test case.</param> /// <param name="sharedStepTitle">The shared step title.</param> /// <param name="selectedTestSteps">The selected test steps.</param> /// <returns>the shared step core object</returns> public static ISharedStep CreateNewSharedStep(this TestCase testCase, string sharedStepTitle, List<TestStep> selectedTestSteps) { log.InfoFormat("Create New Shared Step with Title= {0}", sharedStepTitle); ISharedStep sharedStepCore = ExecutionContext.TestManagementTeamProject.SharedSteps.Create(); sharedStepCore.Title = sharedStepTitle; sharedStepCore.Save(); AddTestStepsToSharedStep(sharedStepCore, Guid.NewGuid(), selectedTestSteps, sharedStepTitle); sharedStepCore.Save(); return sharedStepCore; }
/// <summary> /// Creates the new shared step. /// </summary> /// <param name="testCase">The test case.</param> /// <param name="sharedStepTitle">The shared step title.</param> /// <param name="stepTitle">The step title.</param> /// <param name="expectedResult">The expected result.</param> /// <returns>the shared step core object</returns> public static ISharedStep CreateNewSharedStep(TestCase testCase, string sharedStepTitle, string stepTitle, string expectedResult) { ISharedStepReference sharedStepReferenceCore = testCase.ITestCase.CreateSharedStepReference(); ISharedStep sharedStepCore = ExecutionContext.TestManagementTeamProject.SharedSteps.Create(); sharedStepReferenceCore.SharedStepId = sharedStepCore.Id; sharedStepCore.Title = sharedStepTitle; ITestStep testStepCore = sharedStepCore.CreateTestStep(); testStepCore.ExpectedResult = expectedResult; testStepCore.Title = stepTitle; sharedStepCore.Actions.Add(testStepCore); return sharedStepCore; }
/// <summary> /// Adds the test steps to shared steps actions. /// </summary> /// <param name="sharedStepCore">The core shared step object.</param> /// <param name="sharedStepGuid">The shared step unique identifier.</param> /// <param name="selectedTestSteps">The test steps to add.</param> /// <param name="sharedStepTitle">The shared step title.</param> private static void AddTestStepsToSharedStep(ISharedStep sharedStepCore, Guid sharedStepGuid, List <TestStep> selectedTestSteps, string sharedStepTitle) { foreach (TestStep currentTestStep in selectedTestSteps) { ITestStep testStepCore = sharedStepCore.CreateTestStep(); testStepCore.ExpectedResult = currentTestStep.ActionExpectedResult; testStepCore.Title = currentTestStep.ActionTitle; sharedStepCore.Actions.Add(testStepCore); currentTestStep.TestStepGuid = sharedStepGuid; currentTestStep.Title = sharedStepTitle; currentTestStep.IsShared = true; currentTestStep.SharedStepId = sharedStepCore.Id; } }
private void HandleSharedStep() { if (IsSharedStep(_currentStep)) { _currentSharedStepsPointer = 0; _currentSharedStep = (ISharedStepReference)_currentStep; ISharedStep ss = _currentSharedStep.FindSharedStep(); TestActionCollection sharedActions = ss.Actions; _currentSharedTestStepResult = CreateSharedStepResult(_currentSharedStep) as ISharedStepResult; _currentSharedSteps.AddRange(sharedActions); _currentStep = _currentSharedSteps[_currentSharedStepsPointer++]; } }
/// <summary> /// Создать нумерованный многоуровневый список Word /// </summary> public void CreateMultiLevelList(Word.Paragraph paragraph, Word.ListTemplate listTemplate, List <ITestCase> testCase, int Index) { // Добавить название тест кейса на первый уровень нумерованного многоуровневого списка paragraph.Range.Text = testCase.ElementAt(Index).Title; paragraph.Range.SetListLevel(1); paragraph.Range.ListFormat.ApplyListTemplateWithLevel(listTemplate, ContinuePreviousList: true, ApplyTo: WdListApplyTo.wdListApplyToSelection, DefaultListBehavior: WdDefaultListBehavior.wdWord10ListBehavior, ApplyLevel: 1); paragraph.Range.InsertParagraphAfter(); // Если в тест кейсе нет Actions if (testCase.ElementAt(Index).Actions.Count == 0) { paragraph.Range.Text = "Тест кейс пуст!"; paragraph.Range.SetListLevel(2); paragraph.Range.ListFormat.ApplyListTemplateWithLevel(listTemplate, ContinuePreviousList: true, ApplyTo: WdListApplyTo.wdListApplyToSelection, DefaultListBehavior: WdDefaultListBehavior.wdWord10ListBehavior, ApplyLevel: 2); paragraph.Range.InsertParagraphAfter(); } ISharedStep sharedStep = null; ISharedStepReference sharedStepReference = null; for (int i = 0; i < testCase.ElementAt(Index).Actions.Count; i++) { sharedStepReference = testCase.ElementAt(Index).Actions.ElementAt(i) as ISharedStepReference; // Добавить общий шаг if (sharedStepReference != null) { // Добавить текст общего шага на второй уровень нумерованного многоуровневого списка sharedStep = sharedStepReference.FindSharedStep(); paragraph.Range.Text = sharedStep.Title + "\t(ОБЩИЙ ШАГ)"; paragraph.Range.SetListLevel(2); paragraph.Range.ListFormat.ApplyListTemplateWithLevel(listTemplate, ContinuePreviousList: true, ApplyTo: WdListApplyTo.wdListApplyToSelection, DefaultListBehavior: WdDefaultListBehavior.wdWord10ListBehavior, ApplyLevel: 2); paragraph.Range.InsertParagraphAfter(); } else { ParameterizedString parametrizedString = new ParameterizedString(((ITestStep)testCase.ElementAt(Index).Actions[i]).Title.ToPlainText()); // Добавить текст Action на второй уровень нумерованного многоуровневого списка paragraph.Range.Text = get_ActionWithParameters(testCase.ElementAt(Index), parametrizedString.ToPlainText()); paragraph.Range.SetListLevel(2); paragraph.Range.ListFormat.ApplyListTemplateWithLevel(listTemplate, ContinuePreviousList: true, ApplyTo: WdListApplyTo.wdListApplyToSelection, DefaultListBehavior: WdDefaultListBehavior.wdWord10ListBehavior, ApplyLevel: 2); paragraph.Range.InsertParagraphAfter(); } } }
/// <summary> /// Initializes a new instance of the <see cref="SharedStep"/> class. /// </summary> /// <param name="sharedStepCore">The shared step core object.</param> public SharedStep(ISharedStep sharedStepCore) { this.ISharedStep = sharedStepCore; List <TestStep> allTestSteps = TestStepManager.GetAllTestStepsInSharedStep(sharedStepCore); this.StepsToolTip = TestStepManager.GenerateTestStepsText(allTestSteps); this.Title = sharedStepCore.Title; this.Area = sharedStepCore.Area; this.Priority = (Priority)sharedStepCore.Priority; this.TeamFoundationIdentityName = new TeamFoundationIdentityName(sharedStepCore.OwnerTeamFoundationId, sharedStepCore.OwnerName); this.OwnerDisplayName = sharedStepCore.OwnerName; this.TeamFoundationId = sharedStepCore.OwnerTeamFoundationId; this.DateCreated = sharedStepCore.DateCreated; this.DateModified = sharedStepCore.DateModified; base.isInitialized = true; this.Id = sharedStepCore.Id; this.CreatedBy = sharedStepCore.WorkItem.CreatedBy; }
public static int AddsharedSteps(SharedStepsObject sharedStepsObject, int newSharedStepId) { TfsTeamProjectCollection tfs; tfs = TfsTeamProjectCollectionFactory.GetTeamProjectCollection(new Uri(sharedStepsObject.uri)); // https://mytfs.visualstudio.com/DefaultCollection tfs.Authenticate(); ITestManagementService service = (ITestManagementService)tfs.GetService(typeof(ITestManagementService)); ITestManagementTeamProject testProject = service.GetTeamProject(sharedStepsObject.project); ISharedStep sharedStep = testProject.SharedSteps.Find(newSharedStepId); for (int i = 0; i < sharedStepsObject.actionSteps.Count(); i++) { ITestStep newStep = sharedStep.CreateTestStep(); newStep.Title = sharedStepsObject.actionSteps[i]; newStep.ExpectedResult = sharedStepsObject.results[i]; sharedStep.Actions.Add(newStep); } sharedStep.Save(); return(sharedStep.Id); }
/// <summary> /// Gets the test steps from test actions. /// </summary> /// <param name="testActions">The test actions.</param> /// <param name="alreadyAddedSharedSteps">The already added shared steps.</param> /// <param name="sharedSteps">The shared steps.</param> /// <returns>list of all test steps</returns> public static List <TestStep> GetTestStepsFromTestActions(ITestManagementTeamProject testManagementTeamProject, ICollection <ITestAction> testActions) { List <TestStep> testSteps = new List <TestStep>(); foreach (var currentAction in testActions) { if (currentAction is ITestStep) { Guid testStepGuid = Guid.NewGuid(); testSteps.Add(new TestStep(false, string.Empty, testStepGuid, currentAction as ITestStep)); } else if (currentAction is ISharedStepReference) { ISharedStepReference currentSharedStepReference = currentAction as ISharedStepReference; ISharedStep currentSharedStep = testManagementTeamProject.SharedSteps.Find(currentSharedStepReference.SharedStepId); testSteps.AddRange(TestStepManager.GetAllTestStepsInSharedStep(currentSharedStep)); } } return(testSteps); }
/// <summary> /// Gets the test steps from shared step. /// </summary> /// <param name="currentSharedStep">The current shared step.</param> /// <returns>list of all test steps in the specified shared step</returns> public static List<TestStep> GetAllTestStepsInSharedStep(ISharedStep currentSharedStep, bool includeSharedStep = true) { List<TestStep> testSteps = new List<TestStep>(); Guid sharedStepUniqueGuid = Guid.NewGuid(); if (currentSharedStep != null && currentSharedStep.Actions != null) { foreach (var currentSharedStepAction in currentSharedStep.Actions) { if (includeSharedStep) { testSteps.Add(new TestStep(true, currentSharedStep.Title, sharedStepUniqueGuid, currentSharedStepAction as ITestStep, currentSharedStep.Id)); } else { testSteps.Add(new TestStep(false, currentSharedStep.Title, Guid.NewGuid(), currentSharedStepAction as ITestStep)); } } } return testSteps; }
/// <summary> /// Duplicates the test case/shared Step. /// </summary> /// <param name="entityToBeDuplicated">The test case/shared step to be duplicated.</param> private void DuplicateEntityInternal(Object entityToBeDuplicated) { SharedStep currentSharedStep = null; if (entityToBeDuplicated is TestCase) { TestCase testCaseToBeDuplicated = entityToBeDuplicated as TestCase; ITestCase testCaseCore = ExecutionContext.TestManagementTeamProject.TestCases.Create(); TestCase currentTestCase = new TestCase(testCaseCore, testCaseToBeDuplicated.ITestSuiteBase, ExecutionContext.Preferences.TestPlan); currentTestCase.ITestCase.Area = testCaseToBeDuplicated.ITestCase.Area; currentTestCase.ITestCase.Title = testCaseToBeDuplicated.ITestCase.Title; //currentTestCase.ITestCase = ExecutionContext.TestManagementTeamProject.TestCases.Find(currentTestCase.ITestCase.Id); log.InfoFormat("Duplicate test case with Title= \"{0}\" id= \"{1}\"", currentTestCase.Title, currentTestCase.Id); List <TestStep> testSteps = TestStepManager.GetTestStepsFromTestActions(ExecutionContext.TestManagementTeamProject, testCaseToBeDuplicated.ITestCase.Actions.ToList()); this.ReplaceTestCaseTitle(currentTestCase); this.ChangeTestCasePriority(currentTestCase); this.ChangeTestCaseOwner(currentTestCase); this.ReplaceStepsInTestCase(currentTestCase, testSteps); currentTestCase.ITestCase.Flush(); currentTestCase.ITestCase.Save(); this.AddTestCaseToSuite(currentTestCase); } else { SharedStep sharedStepToBeDuplicated = entityToBeDuplicated as SharedStep; ISharedStep sharedStepCore = ExecutionContext.TestManagementTeamProject.SharedSteps.Create(); currentSharedStep = new SharedStep(sharedStepCore); currentSharedStep.ISharedStep.Area = sharedStepToBeDuplicated.ISharedStep.Area; log.InfoFormat("Duplicate shared step with Title= \"{0}\" id= \"{1}\"", currentSharedStep.Title, currentSharedStep.Id); List <TestStep> testSteps = TestStepManager.GetTestStepsFromTestActions(ExecutionContext.TestManagementTeamProject, currentSharedStep.ISharedStep.Actions.ToList()); this.ReplaceSharedStepTitle(currentSharedStep); this.ChangeSharedStepPriority(currentSharedStep); this.ChangeSharedStepOwner(currentSharedStep); this.ReplaceStepsInSharedStep(currentSharedStep, testSteps); currentSharedStep.ISharedStep.Flush(); currentSharedStep.ISharedStep.Save(); } }
private void TestCaseInfoForm_Load(object sender, EventArgs e) { try { label1.Text = testCase.ElementAt(nToolTipIndex).Title; ISharedStep sharedStep = null; ISharedStepReference sharedStepReference = null; List <string> actionsList = new List <string>(); if (testCase.ElementAt(nToolTipIndex).Actions.Count == 0) { actionsList.Add("Тест кейс пуст"); } for (int i = 0; i < testCase.ElementAt(nToolTipIndex).Actions.Count; i++) { sharedStepReference = testCase.ElementAt(nToolTipIndex).Actions.ElementAt(i) as ISharedStepReference; if (sharedStepReference != null) { sharedStep = sharedStepReference.FindSharedStep(); actionsList.Add((i + 1) + ". " + sharedStep.Title + "\t(ОБЩИЙ ШАГ)"); } else { ParameterizedString parametrizedString = new ParameterizedString(((ITestStep)testCase.ElementAt(nToolTipIndex).Actions[i]).Title.ToPlainText()); actionsList.Add((i + 1) + ". " + wordFile.get_ActionWithParameters(testCase.ElementAt(nToolTipIndex), parametrizedString.ToPlainText())); } } listBox1.Items.AddRange(actionsList.ToArray()); } catch { listBox1.Items.Add("В запросе отсутствуют тест кейсы."); } }
private int GenerateTestCase(ITestSuiteEntry testCaseEntry, int startRow) { int currentRowNumber = this.GenerateTestCaseHeader(startRow, testCaseEntry); int startingRowNumber = currentRowNumber; int stepNumber = 1; foreach (ITestAction action in testCaseEntry.TestCase.Actions) { if (action is ISharedStepReference) { ISharedStepReference isr = (ISharedStepReference)action; ISharedStep ss = isr.FindSharedStep(); TestActionCollection sharedActions = ss.Actions; foreach (ITestAction sharedAction in sharedActions) { GenereateTestStepRow(currentRowNumber, stepNumber, (ITestStep)sharedAction); stepNumber++; currentRowNumber++; } } else { GenereateTestStepRow(currentRowNumber, stepNumber, (ITestStep)action); stepNumber++; currentRowNumber++; } } int endingRowNumber = currentRowNumber - 1; _range = _worksheet.get_Range("B" + startingRowNumber, (RefinementWindow.createComments ? "E" : "D") + endingRowNumber); DrawAllSolidBorders(_range, 0); return(currentRowNumber + 1); }
/// <summary> /// Saves the specified test case. /// </summary> /// <param name="sourceTestCase">The test case.</param> /// <param name="testManagementTeamProject">The test management team project.</param> /// <param name="testPlan">The test plan.</param> /// <param name="createNew">should be saved as new test case.</param> /// <param name="suiteId">The suite identifier.</param> /// <param name="testSteps">The test steps.</param> /// <param name="shouldAssignArea">if set to <c>true</c> [should assign area].</param> /// <param name="isMigration">if set to <c>true</c> [is migration].</param> /// <returns> /// the saved test case /// </returns> public static TestCase Save( this TestCase sourceTestCase, ITestManagementTeamProject testManagementTeamProject, ITestPlan testPlan, bool createNew, int?suiteId, ICollection <TestStep> testSteps, bool shouldAssignArea = true, bool isMigration = false) { TestCase currentTestCase = sourceTestCase; if (createNew) { ITestCase testCaseCore = testManagementTeamProject.TestCases.Create(); currentTestCase = new TestCase(testCaseCore, sourceTestCase.ITestSuiteBase, testPlan); } if (shouldAssignArea) { currentTestCase.ITestCase.Area = sourceTestCase.Area; } currentTestCase.ITestCase.Description = sourceTestCase.ITestCase.Description; currentTestCase.ITestCase.Title = sourceTestCase.Title; currentTestCase.ITestCase.Priority = (int)sourceTestCase.Priority; currentTestCase.ITestCase.Actions.Clear(); currentTestCase.ITestCase.Owner = testManagementTeamProject.TfsIdentityStore.FindByTeamFoundationId(sourceTestCase.TeamFoundationId); if (sourceTestCase.ITestCase.Implementation != null && isMigration) { currentTestCase.ITestCase.Implementation = sourceTestCase.ITestCase.Implementation; } List <Guid> addedSharedStepGuids = new List <Guid>(); foreach (TestStep currentStep in testSteps) { if (currentStep.IsShared && !addedSharedStepGuids.Contains(currentStep.TestStepGuid)) { ISharedStep sharedStepCore = testManagementTeamProject.SharedSteps.Find(currentStep.SharedStepId); ISharedStepReference sharedStepReferenceCore = currentTestCase.ITestCase.CreateSharedStepReference(); sharedStepReferenceCore.SharedStepId = sharedStepCore.Id; currentTestCase.ITestCase.Actions.Add(sharedStepReferenceCore); addedSharedStepGuids.Add(currentStep.TestStepGuid); } else if (!currentStep.IsShared) { ITestStep testStepCore = currentTestCase.ITestCase.CreateTestStep(); testStepCore.Title = currentStep.ActionTitle; testStepCore.ExpectedResult = currentStep.ActionExpectedResult; currentTestCase.ITestCase.Actions.Add(testStepCore); } } if (suiteId != null) { var newSuite = TestSuiteManager.GetTestSuiteById(testManagementTeamProject, testPlan, (int)suiteId); sourceTestCase.ITestSuiteBase = newSuite; } currentTestCase.ITestCase.Flush(); currentTestCase.ITestCase.Save(); if (suiteId != null) { SetTestCaseSuite(testManagementTeamProject, testPlan, (int)suiteId, currentTestCase); } currentTestCase.ITestCase.Flush(); currentTestCase.ITestCase.Save(); return(currentTestCase); }
public static void MyClassInitialize(TestContext testContext) { _testContext = testContext; AIT.TFS.SyncService.Service.AssemblyInit.Instance.Init(); AIT.TFS.SyncService.Adapter.TFS2012.AssemblyInit.Instance.Init(); var serverConfig = CommonConfiguration.TfsTestServerConfiguration(_testContext); CommonConfiguration.ReplaceConfigFileTokens(_testContext); var config = CommonConfiguration.GetSimpleFieldConfiguration("Requirement", Direction.OtherToTfs, FieldValueType.PlainText, "System.Title"); _testAdapter = SyncServiceFactory.CreateTfsTestAdapter(serverConfig.TeamProjectCollectionUrl, serverConfig.TeamProjectName, config); var projectCollection = TfsTeamProjectCollectionFactory.GetTeamProjectCollection(new Uri(serverConfig.TeamProjectCollectionUrl)); _testManagement = projectCollection.GetService <ITestManagementService>().GetTeamProject(serverConfig.TeamProjectName); var sharedSteps = _testManagement.SharedSteps.Query("SELECT * FROM WorkItems WHERE System.Title='UnitTest_SharedStep'"); _sharedStep = sharedSteps.FirstOrDefault(); if (_sharedStep == null) { _sharedStep = _testManagement.SharedSteps.Create(); var sharedStep1 = _sharedStep.CreateTestStep(); sharedStep1.Title = "First Shared Step"; sharedStep1.ExpectedResult = "Result of first shared step"; var sharedStep2 = _sharedStep.CreateTestStep(); sharedStep2.Title = "Second Shared Step .: @ParametersDontLikeSpecialChars"; sharedStep2.ExpectedResult = "Result of second shared step"; _sharedStep.Actions.Add(sharedStep1); _sharedStep.Actions.Add(sharedStep2); _sharedStep.Title = "UnitTest_SharedStep_1"; _sharedStep.Save(); } else { var sharedStep1 = _sharedStep.Actions[0] as ITestStep; if (sharedStep1 != null) { sharedStep1.Title = "First Shared Step"; sharedStep1.ExpectedResult = "Result of first shared step"; } var sharedStep2 = _sharedStep.Actions[1] as ITestStep; if (sharedStep2 != null) { sharedStep2.Title = "Second Shared Step .: @ParametersDontLikeSpecialChars"; sharedStep2.ExpectedResult = "Result of second shared step"; } _sharedStep.WorkItem.Open(); _sharedStep.Save(); } var testCases = _testManagement.TestCases.Query("SELECT * FROM WorkItems WHERE System.Title='UnitTest_TestCase'"); _testCase = testCases.FirstOrDefault(); if (_testCase == null) { _testCase = _testManagement.TestCases.Create(); _testCase.Title = "UnitTest_TestCase"; var step1 = _testCase.CreateTestStep(); step1.Title = "First Step"; step1.ExpectedResult = "Result of first step"; var step2 = _testCase.CreateTestStep(); step2.Title = "Second Step"; step2.ExpectedResult = "Result of second step"; var step3 = _testCase.CreateTestStep(); step3.Title = "@DescriptionParameter"; step3.ExpectedResult = "@ExpectedResultParameter"; var ssr = _testCase.CreateSharedStepReference(); ssr.SharedStepId = _sharedStep.Id; _testCase.Actions.Add(step1); _testCase.Actions.Add(step2); _testCase.Actions.Add(ssr); _testCase.Actions.Add(step3); _testCase.Save(); } var testConfigurations = _testManagement.TestConfigurations.Query("Select * from TestConfiguration where Name='UnitTest_TestConfiguration'"); _testConfiguration = testConfigurations.FirstOrDefault(); if (_testConfiguration == null) { _testConfiguration = _testManagement.TestConfigurations.Create(); _testConfiguration.Name = "UnitTest_TestConfiguration"; _testConfiguration.Save(); } }
private void btnExport_Click(object sender, EventArgs e) { //DateTime startDateTime = DateTime.Now; flag6 = 1; if (txtFileName.Text != null || txtFileName.Text != "") { flag5 = 1; } if (txtSaveFolder.Text != null || txtSaveFolder.Text != "") { flag4 = 1; } //if (cbApplyDateFilter.Checked && (DateTime.Compare(dtpCompleteEnd.Value, dtpCompleteStart.Value) >= 0)) //{ // flag6 = 1; //} //else if (!cbApplyDateFilter.Checked) //{ // flag6 = 1; //} //else //{ // flag6 = 0; //} if (flag1 == 1 && flag2 == 1 && flag3 == 1 && flag4 == 1 && flag5 == 1 && flag6 == 1) { this.Cursor = Cursors.WaitCursor; btnExport.Enabled = false; btnCancel.Enabled = false; btnTeamProject.Enabled = false; btnFolderBrowse.Enabled = false; comBoxTestPlan.Enabled = false; comBoxTestSuite.Enabled = false; string filePath = string.Format(@"{0}\{1}.xlsx", txtSaveFolder.Text.Trim(), txtFileName.Text.Trim()); Excel.Application xlApp; Excel.Workbook xlWorkBook; Excel.Worksheet xlWorkSheet; object misValue = System.Reflection.Missing.Value; Excel.Range chartRange; xlApp = new Excel.Application(); xlWorkBook = null; if (!File.Exists(filePath)) { xlWorkBook = xlApp.Workbooks.Add(misValue); xlWorkBook.SaveAs(filePath); } xlWorkBook = xlApp.Workbooks.Open(filePath); xlWorkSheet = (Excel.Worksheet)xlWorkBook.Worksheets.Add(); string wsName = (comBoxTestSuite.Text.Length > 15) ? comBoxTestSuite.Text.Substring(0, 15) : comBoxTestSuite.Text; xlWorkSheet.Name = string.Concat(xlWorkSheet.Name.Substring(5), string.Format(" {0}-{1}", wsName, cmbRunType.Text)); xlWorkSheet.Cells[1, 1] = "ID"; //xlWorkSheet.Cells[1, 2] = "Pass %"; // xlWorkSheet.Cells[1, 3] = "Fail %"; // xlWorkSheet.Cells[1, 4] = "RunCount"; // xlWorkSheet.Cells[1, 5] = "LatestResult"; // xlWorkSheet.Cells[1, 6] = "Run Date"; // xlWorkSheet.Cells[1, 7] = "State"; xlWorkSheet.Cells[1, 8] = "Priority"; xlWorkSheet.Cells[1, 9] = "WI Type"; xlWorkSheet.Cells[1, 10] = "Title"; xlWorkSheet.Cells[1, 11] = "Action"; xlWorkSheet.Cells[1, 12] = "Expected Result"; // xlWorkSheet.Cells[1, 13] = "Complexity"; xlWorkSheet.Cells[1, 14] = "Tags"; // xlWorkSheet.Cells[1, 15] = "Area Path"; // xlWorkSheet.Cells[1, 16] = "Iteration Path"; // xlWorkSheet.Cells[1, 17] = "Module/Feature"; (xlWorkSheet.Columns["A", Type.Missing]).ColumnWidth = 5; (xlWorkSheet.Columns["B", Type.Missing]).ColumnWidth = 5; (xlWorkSheet.Columns["C", Type.Missing]).ColumnWidth = 5; (xlWorkSheet.Columns["D", Type.Missing]).ColumnWidth = 8; (xlWorkSheet.Columns["E", Type.Missing]).ColumnWidth = 10; (xlWorkSheet.Columns["F", Type.Missing]).ColumnWidth = 12; (xlWorkSheet.Columns["G", Type.Missing]).ColumnWidth = 8; (xlWorkSheet.Columns["H", Type.Missing]).ColumnWidth = 6; (xlWorkSheet.Columns["I", Type.Missing]).ColumnWidth = 8; (xlWorkSheet.Columns["J", Type.Missing]).ColumnWidth = 40; (xlWorkSheet.Columns["K", Type.Missing]).ColumnWidth = 40; (xlWorkSheet.Columns["L", Type.Missing]).ColumnWidth = 40; (xlWorkSheet.Columns["M", Type.Missing]).ColumnWidth = 10; (xlWorkSheet.Columns["N", Type.Missing]).ColumnWidth = 30; (xlWorkSheet.Columns["O", Type.Missing]).ColumnWidth = 30; (xlWorkSheet.Columns["P", Type.Missing]).ColumnWidth = 30; (xlWorkSheet.Columns["Q", Type.Missing]).ColumnWidth = 20; int row = 2; int col = 1; string upperBound = "a"; string lowerBound = "a"; // cache tfs query results ITestRunHelper allTestRuns = null; IEnumerable <ITestRun> testRuns = null; ITestCaseResultHelper allTestCaseResults = null; try { //Cache the testRuns allTestRuns = _teamProject.TestRuns; if (string.Compare(cmbRunType.Text.Trim(), "Manual") == 0) { testRuns = allTestRuns.Query("select TestRunID From TestRun where IsAutomated=0"); } else if (string.Compare(cmbRunType.Text.Trim(), "Automated") == 0) { testRuns = allTestRuns.Query("select TestRunID From TestRun where IsAutomated=1"); } //Cache testresults allTestCaseResults = this._teamProject.TestResults; foreach (ITestCase testCase in testCases) { upperBound = "a"; lowerBound = "a"; col = 1; // Get the test results var testCaseResult = allTestCaseResults.ByTestId(testCase.Id).Where(b => b.Outcome == TestOutcome.Passed || b.Outcome == TestOutcome.Failed); // apply date filter to the results //if (cbApplyDateFilter.Checked) //{ // testCaseResult = testCaseResult.Where(t => DateTime.Compare(t.DateCompleted.Date, dtpCompleteStart.Value.Date) >= 0 && DateTime.Compare(t.DateCompleted.Date, dtpCompleteEnd.Value.Date) <= 0); //} // apply Run Type filter if (string.Compare(cmbRunType.Text.Trim(), "All") != 0) { testCaseResult = testCaseResult.Where(a => testRuns.FirstOrDefault(b => b.Id == a.TestRunId) != null); } // order the output in decending order to get the latest record testCaseResult = testCaseResult.OrderByDescending(t => t.DateCompleted); if (testCaseResult.Count() > 0) { int runCount = testCaseResult.Count(); float passCount = testCaseResult.Where(p => p.Outcome == TestOutcome.Passed).Count(); float failCount = testCaseResult.Where(p => p.Outcome == TestOutcome.Failed).Count(); float passPercent = ((passCount / runCount) * 100); float failPercent = ((failCount / runCount) * 100); // xlWorkSheet.Cells[row, 4] = runCount; //xlWorkSheet.Cells[row, 2] = passPercent.ToString("00.00"); // xlWorkSheet.Cells[row, 3] = failPercent.ToString("00.00"); // xlWorkSheet.Cells[row, 5] = testCaseResult.FirstOrDefault().Outcome.ToString(); // xlWorkSheet.Cells[row, 6] = testCaseResult.FirstOrDefault().DateCompleted.ToString(); } else { xlWorkSheet.Cells[row, 5] = "Not Run"; } xlWorkSheet.Cells[row, 1] = testCase.Id.ToString(); //xlWorkSheet.Cells[row, 7] = testCase.State.ToString(); xlWorkSheet.Cells[row, 8] = testCase.Priority.ToString(); xlWorkSheet.Cells[row, 9] = "Test Title"; xlWorkSheet.Cells[row, 10] = testCase.Title.ToString(); //xlWorkSheet.Cells[row, 13] = testCase.WorkItem.Fields["Complexity"].OriginalValue.ToString(); xlWorkSheet.Cells[row, 14] = testCase.WorkItem.Tags.ToString(); // xlWorkSheet.Cells[row, 15] = testCase.Area.ToString(); // xlWorkSheet.Cells[row, 16] = testCase.WorkItem.IterationPath.ToString(); // xlWorkSheet.Cells[row, 17] = testCase.WorkItem.NodeName.ToString(); upperBound += row; row++; TestActionCollection testActions = testCase.Actions; foreach (ITestAction testAction in testActions) { var tstSharedStepRef = testAction as ISharedStepReference; string strStep = string.Empty; string strExpectedResult = string.Empty; if (tstSharedStepRef != null) { ISharedStep tstSharedStep = tstSharedStepRef.FindSharedStep(); foreach (ITestAction tstSharedAction in tstSharedStep.Actions) { ITestStep tstSharedTestStep = tstSharedAction as ITestStep; writeTestSteps(ref xlWorkSheet, tstSharedTestStep, ref row, ref col); } } else { ITestStep tstSharedTestStep = testAction as ITestStep; writeTestSteps(ref xlWorkSheet, tstSharedTestStep, ref row, ref col); } } lowerBound += (row - 1); } lowerBound = "q"; lowerBound += (row - 1); chartRange = xlWorkSheet.get_Range("a1", "q1"); chartRange.Font.Bold = true; chartRange.Interior.Color = 18018018; xlWorkSheet.UsedRange.Replace(">", ">"); xlWorkSheet.UsedRange.Font.Size = 9; xlWorkSheet.UsedRange.WrapText = true; MessageBox.Show(string.Format("Test Cases exported successfully to specified filepath: {0}", filePath)); } catch (Exception ex) { MessageBox.Show(ex.ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } finally { xlWorkBook.Save(); xlWorkBook.Close(true, misValue, misValue); xlApp.Quit(); releaseObject(xlApp); releaseObject(xlWorkBook); releaseObject(xlWorkSheet); this.Cursor = Cursors.Arrow; btnExport.Enabled = true; btnCancel.Enabled = true; btnTeamProject.Enabled = true; btnFolderBrowse.Enabled = true; comBoxTestPlan.Enabled = true; comBoxTestSuite.Enabled = true; } } else { MessageBox.Show("All fields are not populated.", "Missing Information", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } }
/// <summary> /// Adds the test steps to shared steps actions. /// </summary> /// <param name="sharedStepCore">The core shared step object.</param> /// <param name="sharedStepGuid">The shared step unique identifier.</param> /// <param name="selectedTestSteps">The test steps to add.</param> /// <param name="sharedStepTitle">The shared step title.</param> private static void AddTestStepsToSharedStep(ISharedStep sharedStepCore, Guid sharedStepGuid, List<TestStep> selectedTestSteps, string sharedStepTitle) { foreach (TestStep currentTestStep in selectedTestSteps) { ITestStep testStepCore = sharedStepCore.CreateTestStep(); testStepCore.ExpectedResult = currentTestStep.ActionExpectedResult; testStepCore.Title = currentTestStep.ActionTitle; sharedStepCore.Actions.Add(testStepCore); currentTestStep.TestStepGuid = sharedStepGuid; currentTestStep.Title = sharedStepTitle; currentTestStep.IsShared = true; currentTestStep.SharedStepId = sharedStepCore.Id; } }