public override TaskStatu Job(TfsVariable tfsVariables, UserVariable <PartialUnitTestSetting> usrVariables) { var setting = usrVariables.Config; if (setting == null) { return(new TaskStatu("PUT01", "No setting found.")); } var changedAll = TFSHelper.ChangedFiles(); if (!changedAll.Any()) { return(new TaskStatu("No code change found on TFS")); } var codes = changedAll.Where(x => x.FilePath.EndsWith(".cs")).ToList(); var codesChanged = codes.Where(x => x.State == SourceControlFileState.Changed).ToList(); var codesAdded = codes.Where(x => x.State == SourceControlFileState.Added).ToList(); if (codesChanged.Count + codesAdded.Count < 1) { return(new TaskStatu("No code changes found to check for partial unit test")); } var tmpFile = codesChanged.Any() ? codesChanged[0] : codesAdded[0]; Solution gSolution = GetSolutionInfo(tfsVariables, setting, tmpFile); if (gSolution == null) { return(new TaskStatu("PUT03", "No suitable solution found")); } var tmpMethodsforChanged = GetChangeforChangedFiles(codesChanged, tfsVariables, gSolution); if (tmpMethodsforChanged == null) { return(new TaskStatu("PUT04", "No suitable project document found for changed list")); } var tmpMethodsforAdded = GetChangeforChangedAdded(codesAdded, tfsVariables, gSolution); if (tmpMethodsforAdded == null) { return(new TaskStatu("PUT05", "No suitable project document found for added list")); } int totalMethod = tmpMethodsforAdded.MethodCount + tmpMethodsforChanged.MethodCount; WriteDetail(string.Format("{0} number of methods will be looked for unit test", totalMethod)); var unitTesttoCheck = CheckforUnitTest(setting, gSolution, tfsVariables, tmpMethodsforChanged, tmpMethodsforAdded); if (unitTesttoCheck == null) { return(new TaskStatu("PUT06", "No unit test found for partial check")); } bool isAllSucc = RunUnitTests(tfsVariables, setting, unitTesttoCheck, usrVariables.WorkingPath); return(isAllSucc ? new TaskStatu("Partial Unit Test check successful") : new TaskStatu("PUT07", "Partial Unit Test failed")); }
private void DisplayAllChangedFiles(TfsVariable tfsVariables) { var files = TFSHelper.ChangedFiles(); if (files.Any()) { WriteDetail("Changed files are : "); foreach (var itm in files) { WriteDetail(itm.State + " : " + itm.FilePath); } } else { WriteDetail("No changed files found"); } }
public override TaskStatu Job(TfsVariable tfsVariables, UserVariable <FileControlSetting> usrVariables) { var setting = usrVariables.Config; if (setting == null) { return(new TaskStatu("No setting found.")); } var allFiles = TFSHelper.ChangedFiles(); if (!allFiles.Any()) { return(new TaskStatu("No changed file found.")); } string adName = TFSHelper.UserDomainName; var usrGroups = TFSHelper.GroupUserJoined(); foreach (var sourceData in allFiles) { var sourceFile = sourceData.FilePath; var rule = setting.Files.FirstOrDefault(x => x.FileNames.Any(y => sourceFile.EndsWith(y))); if (rule == null) { continue; } if (rule.AllowedUser.Any(x => x == adName)) { continue; } if (rule.AllowedGroup.Any(x => (usrGroups.Any(y => y.EndsWith(x))))) { continue; } return(new TaskStatu("FC01", string.Format("[{0}] file is restirected for [{1}] user.", sourceFile, adName))); } return(new TaskStatu(string.Format("All changes controlled successfully. FileCount/TotalRule = {0}/{1}.", allFiles.Count, setting.Files.Count))); }