private bool UpdateTestSteps(ObservableList <ActivityIdentifiers> testStepsList, long tcVersionId, long tcId) { try { List <long> toDeleteSteps = new List <long>(); TestStepResource testSteps = zephyrEntRepository.GetTestCaseStepsByTcId((int)tcVersionId, projectId.ToString()); testSteps.steps.ForEach(step => toDeleteSteps.Add(step.id)); foreach (ActivityIdentifiers step in testStepsList) { string stepDescription = String.IsNullOrEmpty(step.IdentifiedActivity.Description) ? String.Empty : step.IdentifiedActivity.Description; string stepExpected = String.IsNullOrEmpty(step.IdentifiedActivity.Expected) ? String.Empty : step.IdentifiedActivity.Expected; if (!String.IsNullOrEmpty(step.ExternalID)) { TestStep currentStep = testSteps.steps.FirstOrDefault(st => step.ExternalID.Equals(st.id.ToString())); TestStepResource existedTestStepResource = new TestStepResource(testSteps.id, tcVersionId, testSteps.maxId, testSteps.tcId); TestStep existedTestStepToUpdate = new TestStep(step.ActivityName, stepDescription, testStepsList.IndexOf(step) + 1, stepExpected); existedTestStepResource.step = existedTestStepToUpdate; TestStepResource result = zephyrEntRepository.UpdateTestStep(existedTestStepResource, testSteps.tcId, tcId); toDeleteSteps.Remove(existedTestStepResource.step.id); } else { TestStep newTestStep = new TestStep(step.ActivityName, stepDescription, testStepsList.IndexOf(step) + 1, stepExpected); TestStepResource existedTestStepResource = new TestStepResource(testSteps.id, tcVersionId, testStepsList.IndexOf(step) + 1, tcId); existedTestStepResource.step = newTestStep; TestStepResource testStepResource = zephyrEntRepository.UpdateTestStep(existedTestStepResource, testSteps.tcId, tcId); toDeleteSteps.Remove(testStepResource.step.id); step.ExternalID = testStepResource.step.id.ToString(); } } // Check if steps deleted from zephyr if (toDeleteSteps.Count > 0) { // todo - delete steps from zephyr permmision issue } return(true); } catch (Exception ex) { Reporter.ToLog(eLogLevel.ERROR, "Failed to update Zephyr Ent. test steps " + GingerDicser.GetTermResValue(eTermResKey.Activities), ex); return(false); } }
private List <TestStepResource> CreateTestSteps(ObservableList <ActivityIdentifiers> testStepsList, long tcVersionId, long tcId) { try { List <TestStepResource> testStepResourcesList = new List <TestStepResource>(); long currentTestStepResourceId = 0; foreach (ActivityIdentifiers step in testStepsList) { string stepDescription = String.IsNullOrEmpty(step.IdentifiedActivity.Description) ? String.Empty : step.IdentifiedActivity.Description; string stepExpected = String.IsNullOrEmpty(step.IdentifiedActivity.Expected) ? String.Empty : step.IdentifiedActivity.Expected; if (testStepsList.IndexOf(step) == 0) // first step should be created via POST nexts - via PUT { TestStep newTestStep = new TestStep(step.ActivityName, stepDescription, testStepsList.IndexOf(step) + 1, stepExpected); TestStepResource newTestStepResource = new TestStepResource(tcVersionId, testStepsList.IndexOf(step) + 1, newTestStep, tcId); TestStepResource testStepResource = zephyrEntRepository.CreateTestStepResourceWithStep(newTestStepResource, tcVersionId, tcId); currentTestStepResourceId = testStepResource.id; testStepResourcesList.Add(testStepResource); step.ExternalID = testStepResource.step.id.ToString(); } else { TestStep newTestStep = new TestStep(step.ActivityName, stepDescription, testStepsList.IndexOf(step) + 1, stepExpected); TestStepResource existedTestStepResource = new TestStepResource(currentTestStepResourceId, tcVersionId, testStepsList.IndexOf(step) + 1, tcId); existedTestStepResource.step = newTestStep; TestStepResource testStepResource = zephyrEntRepository.UpdateTestStep(existedTestStepResource, tcVersionId, tcId); testStepResourcesList.Add(testStepResource); step.ExternalID = testStepResource.step.id.ToString(); } } return(testStepResourcesList); } catch (Exception ex) { Reporter.ToLog(eLogLevel.ERROR, "Failed to create Zephyr Ent. test steps " + GingerDicser.GetTermResValue(eTermResKey.Activities), ex); return(null); } }