/// <summary> /// Constructor for comparing Structured Lists. /// </summary> /// <param name="oldValues"></param> /// <param name="newValues"></param> /// <param name="resultReport"></param> public CompareStrategy(HashSet <Dictionary <EnumOldServiceFieldsAsKeys, StringDescriptor> > oldValues, HashSet <Dictionary <EnumOldServiceFieldsAsKeys, StringDescriptor> > newValues, ResultReport resultReport) { if (resultReport != null) { this.resultReport = resultReport; this.resultReport.AddDetailedValues(oldValues, newValues); } }
/// <summary> /// Constructor for comparing Unstructured Lists. /// </summary> /// <param name="oldValues"></param> /// <param name="newValues"></param> /// <param name="resultReport"></param> public CompareStrategy(HashSet <StringDescriptor> oldValues, HashSet <StringDescriptor> newValues, ResultReport resultReport) { if (resultReport != null) { this.resultReport = resultReport; this.resultReport.AddDetailedValues(oldValues, newValues); } }
/// <summary> /// Constructor for comparing Trees of Organizations. /// </summary> /// <param name="oldValues"></param> /// <param name="oldTreeRoot"></param> /// <param name="newValues"></param> /// <param name="newTreeRoot"></param> /// <param name="resultReport"></param> public CompareStrategy(HashSet <OrganizationTreeDescriptor> oldValues, OrganizationTreeDescriptor oldTreeRoot, HashSet <OrganizationTreeDescriptor> newValues, OrganizationTreeDescriptor newTreeRoot, ResultReport resultReport) { if (resultReport != null) { this.resultReport = resultReport; this.resultReport.AddDetailedValues(oldValues, oldTreeRoot, newValues, newTreeRoot); } }
/// <summary> /// Populates the template based on the provided data. /// Writes the entry to the log. /// </summary> /// <param name="errorMessage">Description of the failure.</param> /// <param name="userId">User Unique Identifier in the new service.</param> /// <param name="OldId">User Unique Identifier in the old service.</param> /// <param name="severity">Type of failure.</param> /// <param name="newServiceUrl">URL of the new service being called (for the specific User Identifier).</param> /// <param name="memberName">Test method generated name.</param> /// <param name="taskDescription">Human-readable description of the test.</param> /// <param name="optionalExplanation">Hint on what caused the issue.</param> /// <remarks>If the test result is SUCCESS, the entry is logged only if DEBUG mode specified.</remarks> public void LogTestResult(string oldUrl, string newServiceUrl, ResultReport resultReport) { UpdateStatistics(resultReport); if (TestSuiteUser.IsDebugMode || (resultReport.Severity != EnumResultSeverityType.SUCCESS && resultReport.Severity != EnumResultSeverityType.WARNING_NO_DATA)) { var detailedReportData = new DetailedReportSharedData(resultReport) { OldUrl = oldUrl, NewUrl = newServiceUrl }; WriteDetailedEntry(detailedReportData, resultReport.DisplayFormat); } }
/// <summary> /// Updates the Statistics with the information from the Test Result provided. /// </summary> /// <param name="OldId"></param> /// <param name="resultReport"></param> private void UpdateStatistics(ResultReport resultReport) { // keeping track of profiles without failures by logging any failure happening if (!NoWarningNorErrorHappenedFlag_ByOldId.ContainsKey(resultReport.OldId)) { NoWarningNorErrorHappenedFlag_ByOldId.Add(resultReport.OldId, false); } if (resultReport.Severity != EnumResultSeverityType.SUCCESS) { NoWarningNorErrorHappenedFlag_ByOldId[resultReport.OldId] = true; } if (!countSeverityTypeOccurences.ContainsKey(resultReport.TestName)) { countSeverityTypeOccurences.Add(resultReport.TestName, new Dictionary <EnumResultSeverityType, int>()); // initialize all the possible combinations for the given test name foreach (var severity in (EnumResultSeverityType[])Enum.GetValues(typeof(EnumResultSeverityType))) { countSeverityTypeOccurences[resultReport.TestName].Add(severity, 0); } } // increase call counter countSeverityTypeOccurences[resultReport.TestName][resultReport.Severity]++; if (!countDataBehaviorOccurences.ContainsKey(resultReport.TestName)) { // initialize all the possible combinations for the given test name countDataBehaviorOccurences.Add(resultReport.TestName, new Dictionary <EnumIdentifiedDataBehavior, int>()); foreach (var behavior in (EnumIdentifiedDataBehavior[])Enum.GetValues(typeof(EnumIdentifiedDataBehavior))) { countDataBehaviorOccurences[resultReport.TestName].Add(behavior, 0); } } // increase call counter foreach (EnumIdentifiedDataBehavior label in resultReport.IdentifedDataBehaviors) { countDataBehaviorOccurences[resultReport.TestName][label]++; } durations[resultReport.TestName].Add(resultReport.Duration); }
//private void UserGeneralInfo_AltLastName_Test() //{ // var watch = new Stopwatch(); // watch.Start(); // var resultReport = new ResultReport(this.UserId, this.OldId, EnumTestUnitNames.UserGeneralInfo_AltLastName, "Comparing AltLastName (if needed)"); // string oldValue = ParsingHelper.ParseSingleValue(this.OldDataNodes, EnumOldServiceFieldsAsKeys.lastname.ToString()); // var compareStrategy = new CompareStrategyFactory(oldValue, HttpUtility.HtmlEncode(HttpUtility.HtmlDecode(newData.LastName)), resultReport); // compareStrategy.Investigate(); // if(resultReport.Severity != EnumResultSeverityType.SUCCESS) // { // resultReport = new ResultReport(this.UserId, this.OldId, EnumTestUnitNames.UserGeneralInfo_AltLastName, "Comparing AltLastName (if needed)"); // oldValue = ParsingHelper.ParseSingleValue(this.OldDataNodes, EnumOldServiceFieldsAsKeys.lastname.ToString()); // compareStrategy = new CompareStrategyFactory(oldValue, HttpUtility.HtmlEncode(HttpUtility.HtmlDecode(newData.AltLastName)), resultReport); // compareStrategy.Investigate(); // } // watch.Stop(); // resultReport.Duration = watch.Elapsed; // this.DetailedResults.Add(resultReport.TestName, resultReport); // LogManager.Instance.LogTestResult(this.Container.BuildOldServiceFullURL(this.OldId), // this.BuildNewServiceURL(this.PageName), // resultReport); //} private void UserGeneralInfo_JobClass_Test() { var watch = new Stopwatch(); watch.Start(); var resultReport = new ResultReport(this.UserId, this.OldId, EnumTestUnitNames.UserGeneralInfo_JobClass, "Checking Job Class assigned"); //make sure test is okay if value assigned and fails if no value string oldValue = (!string.IsNullOrEmpty(newData.JobClass) ? "1":string.Empty); var compareStrategy = new CompareStrategyFactory(oldValue, HttpUtility.HtmlEncode(HttpUtility.HtmlDecode((!string.IsNullOrEmpty(newData.JobClass) ? "1" : "0"))), resultReport); compareStrategy.Investigate(); watch.Stop(); resultReport.Duration = watch.Elapsed; this.DetailedResults.Add(resultReport.TestName, resultReport); LogManager.Instance.LogTestResult(this.Container.BuildOldServiceFullURL(this.OldId), this.BuildNewServiceURL(this.PageName), resultReport); }
public CompareStrategyOrganizationList(HashSet <OrganizationTreeDescriptor> listOldIdsAndNames, OrganizationTreeDescriptor oldTreeRoot, HashSet <OrganizationTreeDescriptor> listNewIdsAndNames, OrganizationTreeDescriptor newTreeRoot, ResultReport resultReport) : base(listOldIdsAndNames, oldTreeRoot, listNewIdsAndNames, newTreeRoot, resultReport) { if (listOldIdsAndNames != null) { this.oldList = listOldIdsAndNames.Where(d => !string.IsNullOrEmpty(d.ID) || !string.IsNullOrEmpty(d.Name)).ToList(); } else { this.oldList = new List <OrganizationTreeDescriptor>(); } if (listNewIdsAndNames != null) { this.newList = listNewIdsAndNames.Where(z => !string.IsNullOrEmpty(z.ID) || !string.IsNullOrEmpty(z.Name)).ToList(); } else { this.newList = new List <OrganizationTreeDescriptor>(); } }
private void UserGeneralInfo_Organization_IdAndNameTogether_Test(OrganizationTreeDescriptor oldTreeRoot, OrganizationTreeDescriptor newTreeRoot) { var watch = new Stopwatch(); watch.Start(); var resultReport = new ResultReport(this.UserId, this.OldId, EnumTestUnitNames.UserGeneralInfo_Organizations_IdAndName, "Comparing Organization Id+Name Combinations"); var compareStrategy = new CompareStrategyFactory( oldServiceOrganizationDescriptors, oldTreeRoot, newServiceOrganizationDescriptors, newTreeRoot, resultReport); compareStrategy.Investigate(); watch.Stop(); resultReport.Duration = watch.Elapsed; this.DetailedResults.Add(resultReport.TestName, resultReport); LogManager.Instance.LogTestResult(this.Container.BuildOldServiceFullURL(this.OldId), this.BuildNewServiceURL(this.PageName), resultReport); }
/// <summary> /// Compare unstructured lists of values. /// </summary> /// <param name="oldValues"></param> /// <param name="newValues"></param> /// <param name="resultReport"></param> public CompareStrategyFactory(HashSet <string> oldValues, HashSet <string> newValues, ResultReport resultReport) { compareStrategies.Add(new CompareStrategyUnstructuredLists(StringDescriptor.EmbedInDescriptors(true, oldValues), StringDescriptor.EmbedInDescriptors(false, newValues), resultReport)); }
private void UserGeneralInfo_Organization_MergingNewTreeToOldOne_Test(OrganizationTreeDescriptor oldTreeRoot, OrganizationTreeDescriptor newTreeRoot) { var watch = new Stopwatch(); watch.Start(); var resultReport = new ResultReport(this.UserId, this.OldId, EnumTestUnitNames.UserGeneralInfo_Organizations_TreeMerged, "Trying to merge Organization Trees together"); if (newTreeRoot != null && oldTreeRoot != null) { var newTreeRootDeepClone = newTreeRoot.DeepClone(); PopulateGapsOfOldTree(this.oldServiceOrganizationDescriptors, this.newServiceOrganizationDescriptors, resultReport, true); var missingElements = this.oldServiceOrganizationDescriptors.Where(x => x.HasBeenMatched == false && string.IsNullOrEmpty(x.ID) && string.IsNullOrEmpty(x.Name) && x.Depth >= 0) .GroupBy(x => x.Depth) .ToDictionary(t => t.Key, t => t.ToList()); int countMissingElements = missingElements.Count(); if (countMissingElements == 0) { resultReport.UpdateSeverity(EnumResultSeverityType.SUCCESS); } else { //if (countMissingElements > 0) //{ // PopulateGapsOfOldTree(this.oldServiceOrganizationDescriptors, this.newServiceOrganizationDescriptors, resultReport, false); // missingElements = this.oldServiceOrganizationDescriptors.Where(x => x.HasBeenMatched == false // && string.IsNullOrEmpty(x.ID) // && string.IsNullOrEmpty(x.Name) // && x.Depth >= 0) // .GroupBy(x => x.Depth) // .ToDictionary(t => t.Key, t => t.ToList()); // countMissingElements = missingElements.Count(); //} if (countMissingElements == 0) { resultReport.UpdateSeverity(EnumResultSeverityType.FALSE_POSITIVE); } else { resultReport.UpdateSeverity(EnumResultSeverityType.ERROR); } } OrganizationTreeDescriptor root = null; try { root = this.oldServiceOrganizationDescriptors.Where(x => x.Depth == 0).First(); } catch (Exception) { } resultReport.AddDetailedValues(null, root, null, newTreeRootDeepClone); } else { resultReport.UpdateSeverity(EnumResultSeverityType.WARNING_NO_DATA); } watch.Stop(); resultReport.Duration = watch.Elapsed; this.DetailedResults.Add(resultReport.TestName, resultReport); LogManager.Instance.LogTestResult(this.Container.BuildOldServiceFullURL(this.OldId), this.BuildNewServiceURL(this.PageName), resultReport); }
private void UserGeneralInfo_Organization_CheckTreeDepthCoherence_Test(OrganizationTreeDescriptor oldTreeRoot, OrganizationTreeDescriptor newTreeRoot) { bool keepGoing = true; int index = 0; IEnumerable <OrganizationTreeDescriptor> oldEntriesSameDepth; IEnumerable <OrganizationTreeDescriptor> newEntriesSameDepth; int oldCount; int newCount; var watch = new Stopwatch(); watch.Start(); var resultReport = new ResultReport(this.UserId, this.OldId, EnumTestUnitNames.UserGeneralInfo_Organizations_TreeDepthCoherence, "Comparing Organization Tree Depth Coherence"); while (keepGoing) { oldEntriesSameDepth = this.oldServiceOrganizationDescriptors.Where(x => x.Depth == index); newEntriesSameDepth = this.newServiceOrganizationDescriptors.Where(s => s.Depth == index); oldCount = oldEntriesSameDepth.Count(); newCount = newEntriesSameDepth.Count(); if (oldCount == 0 && newCount == 0) { keepGoing = false; } try { // the only we can compare is that the old tree does not return more entries than the new one at a given depth of depth // the new service may return more because it has enriched the old tree where some of the values may have been manually - ? - excluded Assert.IsFalse(oldCount > newCount, "Comparing at depth index " + index); resultReport.UpdateSeverity(EnumResultSeverityType.SUCCESS); } catch (AssertFailedException e) { resultReport.UpdateSeverity(EnumResultSeverityType.ERROR); resultReport.ErrorMessage = e.Message; resultReport.IdentifedDataBehaviors.Add(EnumIdentifiedDataBehavior.OLD_TREE_HAS_MORE_CHILDREN_GIVEN_DEPTH); resultReport.AddDetailedValues(this.oldServiceOrganizationDescriptors, oldTreeRoot, this.newServiceOrganizationDescriptors, newTreeRoot); resultReport.TreeComparisonIndexError = index; if (resultReport.Severity == EnumResultSeverityType.ERROR) { keepGoing = false; } } index++; } if (resultReport.Severity == EnumResultSeverityType.SUCCESS) { resultReport.IdentifedDataBehaviors.Add(EnumIdentifiedDataBehavior.NEW_TREE_COUNT_CONSISTENT); resultReport.AddDetailedValues(this.oldServiceOrganizationDescriptors, oldTreeRoot, this.newServiceOrganizationDescriptors, newTreeRoot); } watch.Stop(); resultReport.Duration = watch.Elapsed; this.DetailedResults.Add(resultReport.TestName, resultReport); LogManager.Instance.LogTestResult(this.Container.BuildOldServiceFullURL(this.OldId), this.BuildNewServiceURL(this.PageName), resultReport); }
private static void PopulateGapsOfOldTree(HashSet <OrganizationTreeDescriptor> oldTree, HashSet <OrganizationTreeDescriptor> newTree, ResultReport resultReport, bool excludeMatchedElements, int previousCountMissingElements = -1) { int countUnmatchedChildrenOfMissingElement = 42; bool onlyOneOptionAvailable = false; bool matchingElementFound = false; OrganizationTreeDescriptor matchingElement; var missingElementsByDepth = oldTree.Where(x => x.HasBeenMatched == false && string.IsNullOrEmpty(x.ID) && string.IsNullOrEmpty(x.Name) && x.Depth >= 0) .GroupBy(x => x.Depth) .ToDictionary(t => t.Key, t => t.ToList()); int countMissingElements = missingElementsByDepth.Count(); Dictionary <int, List <OrganizationTreeDescriptor> > potentialMatchingElementsByDepth; if (excludeMatchedElements) { potentialMatchingElementsByDepth = newTree.Where(x => x.HasBeenMatched == false).GroupBy(g => g.Depth).ToDictionary(t => t.Key, t => t.ToList()); } else { potentialMatchingElementsByDepth = newTree.GroupBy(g => g.Depth).ToDictionary(t => t.Key, t => t.ToList()); } if (countMissingElements != previousCountMissingElements && countMissingElements > 0 && potentialMatchingElementsByDepth.Count() > 0) { foreach (var missingElementsPair in missingElementsByDepth) { foreach (var missingElement in missingElementsPair.Value) { if (potentialMatchingElementsByDepth.ContainsKey(missingElementsPair.Key)) { matchingElementFound = false; matchingElement = null; foreach (var potentialElement in potentialMatchingElementsByDepth[missingElementsPair.Key]) { onlyOneOptionAvailable = potentialMatchingElementsByDepth[missingElementsPair.Key].Count() == 1; if ((potentialElement.ParentId == missingElement.ParentId || string.IsNullOrEmpty(missingElement.ParentId)) && potentialElement.Children.Count() >= missingElement.Children.Count()) { if (potentialElement.Children.Select(x => x.MatchedPartner).Count() > 0) { countUnmatchedChildrenOfMissingElement = missingElement.Children.Except(potentialElement.Children.Select(x => x.MatchedPartner).Union(potentialElement.Children)).Count(); } else { countUnmatchedChildrenOfMissingElement = missingElement.Children.Select(y => y.ID).Except(potentialElement.Children.Select(x => x.ID)).Count(); } if (countUnmatchedChildrenOfMissingElement == 0) { matchingElementFound = true; matchingElement = potentialElement; } } // if there is only one potential match, don't be picky if (onlyOneOptionAvailable && !matchingElementFound) { matchingElementFound = true; matchingElement = potentialElement; matchingElement.WasOnlyOption = true; resultReport.IdentifedDataBehaviors.Add(EnumIdentifiedDataBehavior.MATCHING_SINGLE_ELEMENT_GIVEN_DEPTH_MISMATCH); resultReport.UpdateSeverity(EnumResultSeverityType.WARNING); } } if (matchingElementFound) { if (!excludeMatchedElements) { matchingElement.UsedMoreThanOnce = true; resultReport.IdentifedDataBehaviors.Add(EnumIdentifiedDataBehavior.REUSED_ELEMENT_TO_FILL_GAP); } matchingElement.HasBeenMatched = true; matchingElement.MatchedPartner = missingElement; missingElement.HasBeenMatched = true; missingElement.MatchedPartner = matchingElement; matchingElement.IsImportedFromNewService = true; missingElement.IsMissing = false; matchingElement.IsMissing = false; matchingElement.Children.Clear(); matchingElement.Parent = missingElement.Parent; // replace in old tree foreach (var childFromMissing in missingElement.Children) { childFromMissing.Parent = matchingElement; matchingElement.Children.Add(childFromMissing); } if (missingElement.Parent != null && missingElement.Parent.Children != null) { missingElement.Parent.Children.Add(matchingElement); missingElement.Parent.Children.Remove(missingElement); } oldTree.Add(matchingElement); oldTree.Remove(missingElement); } } } } PopulateGapsOfOldTree(oldTree, newTree, resultReport, excludeMatchedElements, countMissingElements); } }
public CompareStrategyStructuredLists(HashSet <Dictionary <EnumOldServiceFieldsAsKeys, StringDescriptor> > oldValues, HashSet <Dictionary <EnumOldServiceFieldsAsKeys, StringDescriptor> > newValues, ResultReport resultReport) : base(oldValues, newValues, resultReport) { if (oldValues != null) { this.oldValues = oldValues; } else { this.oldValues = new HashSet <Dictionary <EnumOldServiceFieldsAsKeys, StringDescriptor> >(); } if (newValues != null) { this.newValues = newValues; } else { this.newValues = new HashSet <Dictionary <EnumOldServiceFieldsAsKeys, StringDescriptor> >(); } }
/// <summary> /// Compare unstructured lists of values. They are organized in slices. /// </summary> /// <param name="oldAndNewValues"></param> /// <param name="resultReport"></param> /// <param name="stringPartialMatch"></param> public CompareStrategyFactory(Dictionary <HashSet <string>, HashSet <string> > oldAndNewValues, ResultReport resultReport) { foreach (var slice in oldAndNewValues) { compareStrategies.Add(new CompareStrategyUnstructuredLists(StringDescriptor.EmbedInDescriptors(true, slice.Key), StringDescriptor.EmbedInDescriptors(false, slice.Value), resultReport)); } }
/// <summary> /// Compare structured lists of values. Each property value is mapped to a specific key. /// </summary> /// <param name="oldValues"></param> /// <param name="newValues"></param> /// <param name="resultReport"></param> public CompareStrategyFactory(HashSet <Dictionary <EnumOldServiceFieldsAsKeys, string> > oldValues, HashSet <Dictionary <EnumOldServiceFieldsAsKeys, string> > newValues, ResultReport resultReport) { compareStrategies.Add(new CompareStrategyStructuredLists(StringDescriptor.EmbedInDescriptors(true, oldValues), StringDescriptor.EmbedInDescriptors(false, newValues), resultReport)); }
/// <summary> /// Compare structured lists of values. They are organized in slices. And each value is mapped to a specific key. /// </summary> /// <param name="oldValues"></param> /// <param name="newValues"></param> /// <param name="resultReport"></param> public CompareStrategyFactory(Dictionary <Dictionary <EnumOldServiceFieldsAsKeys, string>, Dictionary <EnumOldServiceFieldsAsKeys, string> > oldAndNewValues, ResultReport resultReport) { foreach (var slice in oldAndNewValues) { compareStrategies.Add(new CompareStrategyStructuredLists(StringDescriptor.EmbedInDescriptors(true, slice.Key), StringDescriptor.EmbedInDescriptors(false, slice.Value), resultReport)); } }
/// <summary> /// Compare Trees of Organizations. /// </summary> /// <param name="oldValues"></param> /// <param name="oldTreeRoot"></param> /// <param name="newValues"></param> /// <param name="newTreeRoot"></param> /// <param name="resultReport"></param> public CompareStrategyFactory(HashSet <OrganizationTreeDescriptor> oldValues, OrganizationTreeDescriptor oldTreeRoot, HashSet <OrganizationTreeDescriptor> newValues, OrganizationTreeDescriptor newTreeRoot, ResultReport resultReport) { compareStrategies.Add(new CompareStrategyOrganizationList(oldValues, oldTreeRoot, newValues, newTreeRoot, resultReport)); }