private static ITestCase CreateTestCase(ITestManagementTeamProject teamProject, ScenarioDefinition scenarioDefinition, IEnumerable <TestCaseField> fieldsCollection) { var scenarioTags = GherkinUtils.GetTags(scenarioDefinition); var testCase = teamProject.TestCases.Create(); TestCaseHelper.UpdateTestCaseDetails(scenarioDefinition, testCase); TestCaseHelper.UpdateTestcaseFields(scenarioTags, testCase, fieldsCollection); testCase.WorkItem.Fields["Reason"].Value = SyncUtil.REASON; testCase.State = SyncUtil.TestCaseStateReady; return(testCase); }
private static void SaveChanges(ITestManagementTeamProject teamProject, IHasSteps background, ITestCase testCase, ScenarioDefinition scenarioDefinition, string hash, string area, ICollection <Tag> tags, IEnumerable <TestCaseField> fieldsCollection) { var isUpdate = true; if (testCase == null) { try { testCase = CreateTestCase(teamProject, scenarioDefinition, fieldsCollection); } catch (InvalidFieldValueException exception) { Logger.Error( ResourceStrings.DECORATION, string.Format(CultureInfo.InvariantCulture, SyncUtil.ABORTED_MESSAGE, exception.Message)); return; } isUpdate = false; } testCase.WorkItem.Fields[SyncUtil.VersionField].Value = hash; UpdateTestCaseArea(testCase, area); TestCaseHelper.UpdateTestcase(background, scenarioDefinition, testCase); if (!IsTestCaseValid(testCase)) { Logger.Error( ResourceStrings.DECORATION, string.Format( CultureInfo.InvariantCulture, SyncUtil.ABORTED_MESSAGE, "Something is wrong, check the field values")); return; } SaveTestCase(testCase); if (!isUpdate) { var scenarioTags = GherkinUtils.GetTags(scenarioDefinition); var mtmIdTag = scenarioTags.Last(); tags.Add( new Tag( new Location(mtmIdTag.Location.Line, mtmIdTag.Location.Column + 1), $"{SyncUtil.MtmTcLink}{testCase.Id}")); Logger.Info(ResourceStrings.DECORATION, $"{testCase.Id} is created"); return; } Logger.Info(ResourceStrings.DECORATION, $"{testCase.Id} is updated"); }
private static bool UpdateTestCase(ITestBase testCase, ScenarioDefinition scenarioDefinition, string hash, IEnumerable <TestCaseField> fieldsCollection) { testCase.Refresh(); var currentState = testCase.State; if (currentState.Equals(SyncUtil.RemovedState, StringComparison.InvariantCulture) || currentState.Equals(SyncUtil.ClosedState, StringComparison.InvariantCulture)) { Logger.Info(ResourceStrings.DECORATION, $"{testCase.Id} is {currentState}"); return(false); } var scenarioTags = GherkinUtils.GetTags(scenarioDefinition); var removedTag = scenarioTags.FirstOrDefault( scenarioTag => scenarioTag.Name.Trim().ToUpperInvariant().StartsWith( SyncUtil.RemovedTag, StringComparison.InvariantCulture)); if (removedTag != null) { testCase.State = SyncUtil.RemovedState; SaveTestCase(testCase); Logger.Info(ResourceStrings.DECORATION, $"{testCase.Id} is marked removed"); return(false); } var currentVersion = testCase.WorkItem.Fields[SyncUtil.VersionField].Value .ToString(); var isTestCaseDetailsChanged = TestCaseHelper.UpdateTestCaseDetails( scenarioDefinition, testCase); var isTestCaseFieldsChanged = TestCaseHelper.UpdateTestcaseFields( scenarioTags, testCase, fieldsCollection); var scenarioStepsUptoDate = VersionUtils.IsUptoDate(hash, currentVersion); if (isTestCaseDetailsChanged || isTestCaseFieldsChanged || !scenarioStepsUptoDate) { return(true); } Logger.Info(ResourceStrings.DECORATION, $"{scenarioDefinition.Name}<{testCase.Id}> is uptodate"); return(false); }
private static bool ValidateTags(IEnumerable <Tag> scenarioTags, IEnumerable <TestCaseField> fieldsCollection) { scenarioTags = scenarioTags.ToList(); foreach (var testCaseField in fieldsCollection) { if (testCaseField.Required && IsRequiredFieldMissing(testCaseField, scenarioTags)) { Logger.Error( $"{testCaseField.Tag} is a required tag but is not found as one of the tags of the scenario"); return(false); } var tag = GetTag(scenarioTags, testCaseField.Tag); var tagValue = TestCaseHelper.GetTagValue(scenarioTags, testCaseField.Tag, testCaseField.Prefix); if (tag != null && tagValue.Length <= 0) { Logger.Error( $"{testCaseField.Tag} does not have a value associated with it"); return(false); } if (testCaseField.RequirementField == null || testCaseField.RequirementField.Trim().Length <= 0) { continue; } tagValue = TestCaseHelper.GetTagValue(scenarioTags, SyncUtil.REQUIREMENT_TAG_NAME, ""); if (tagValue.Trim().Length > 0 && !IsValidRequirement(testCaseField, tagValue)) { return(false); } } return(true); }