private void PopulateTreeDescriptorsFromNew(OrganizationTreeInfo newData, OrganizationTreeDescriptor parent, int depth = 0) { var organizationDescriptor = new OrganizationTreeDescriptor() { ID = newData.OrganizationId.ToString(), Name = HttpUtility.HtmlEncode(HttpUtility.HtmlDecode(newData.Name)), Type = HttpUtility.HtmlEncode(HttpUtility.HtmlDecode(newData.Type)), Depth = depth + 1, IsDisplayedOnYmg = newData.IsDisplayedOnYmg }; if (newData.Missions != null) { organizationDescriptor.Missions = new HashSet <string>(newData.Missions.Select(x => HttpUtility.HtmlEncode(HttpUtility.HtmlDecode(x.Name)))); } if (parent != null) { organizationDescriptor.ParentId = parent.ID; organizationDescriptor.Parent = parent; parent.Children.Add(organizationDescriptor); } this.newServiceOrganizationDescriptors.Add(organizationDescriptor); foreach (var child in newData.Children) { PopulateTreeDescriptorsFromNew(child, organizationDescriptor, depth + 1); } }
/// <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); } }
private OrganizationTreeDescriptor ParseNewServiceData() { var rootContainer = new OrganizationTreeDescriptor(); rootContainer.Depth = 0; this.newServiceOrganizationDescriptors.Add(rootContainer); if (this.newData != null && this.newData.Count() > 0) { foreach (var organization in this.newData) { PopulateTreeDescriptorsFromNew(organization, rootContainer); } } return(rootContainer); }
protected override void RunAllSingleTests() { OrganizationTreeDescriptor oldTreeRoot = null; try { oldTreeRoot = ParseOldServiceData(); } catch (Exception e) { System.Diagnostics.Debug.WriteLine(e.StackTrace); } if (this.oldServiceOrganizationDescriptors.Count == 1) { // it means that there is only the root node, which is equivalent to no tree this.oldServiceOrganizationDescriptors.Clear(); } OrganizationTreeDescriptor newTreeRoot = ParseNewServiceData(); UserGeneralInfo_Organization_Id_Test(new HashSet <string>(this.oldServiceOrganizationDescriptors.Where(a => !string.IsNullOrEmpty(a.ID)).Select(a => a.ID)), new HashSet <string>(this.newServiceOrganizationDescriptors.Where(a => !string.IsNullOrEmpty(a.ID)).Select(a => a.ID))); UserGeneralInfo_Organization_Name_Test(new HashSet <string>(this.oldServiceOrganizationDescriptors.Where(a => !string.IsNullOrEmpty(a.Name)).Select(a => HttpUtility.HtmlEncode(HttpUtility.HtmlDecode(a.Name)))), new HashSet <string>(this.newServiceOrganizationDescriptors.Where(a => !string.IsNullOrEmpty(a.Name)).Select(a => HttpUtility.HtmlEncode(HttpUtility.HtmlDecode(a.Name))))); UserGeneralInfo_Organization_Type_Test(); UserGeneralInfo_Organization_IdAndNameTogether_Test(oldTreeRoot, newTreeRoot); UserGeneralInfo_Organization_CheckTreeDepthCoherence_Test(oldTreeRoot, newTreeRoot); UserGeneralInfo_Organization_MergingNewTreeToOldOne_Test(oldTreeRoot, newTreeRoot); UserGeneralInfo_Organization_Missions_Test(); UserGeneralInfo_Organizations_YmgStatus_Test(); ComputeOverallSeverity(); }
private OrganizationTreeDescriptor ParseOldServiceData() { var rootContainer = new OrganizationTreeDescriptor(); rootContainer.Depth = 0; this.oldServiceOrganizationDescriptors.Add(rootContainer); string parsedOrgId = string.Empty; string parsedOrgName = string.Empty; string parsedMissions = string.Empty; // first get the tree and its elements try { PopulateTreeDescriptorsFromOld(this.OldDataNodes.First(), rootContainer, this.oldServiceOrganizationDescriptors); } catch (Exception) { // there is no existing attribute to parse } return(rootContainer); }
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> /// Overloaded method that stores the input data for later display, according to the data types supplied. /// </summary> /// <param name="oldValues"></param> /// <param name="oldTreeRoot"></param> /// <param name="newValues"></param> /// <param name="newTreeRoot"></param> public void AddDetailedValues(HashSet <OrganizationTreeDescriptor> oldValues, OrganizationTreeDescriptor oldTreeRoot, HashSet <OrganizationTreeDescriptor> newValues, OrganizationTreeDescriptor newTreeRoot) { if (oldValues != null) { this.OldOrganizationValues = oldValues; } this.OldTreeRoot = oldTreeRoot; if (newValues != null) { this.NewOrganizationValues = newValues; } this.NewTreeRoot = newTreeRoot; this.DisplayFormat = EnumResultDisplayFormat.OrganizationTree; }
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_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 PopulateTreeDescriptorsFromOld(XElement element, OrganizationTreeDescriptor parent, HashSet <OrganizationTreeDescriptor> allPuzzlePieces, int depth = 0) { OrganizationTreeDescriptor orgDesc = parent; string tempValue; if (element != null && element.Name == EnumOldServiceFieldsAsKeys.treeDepartment.ToString()) { orgDesc = new OrganizationTreeDescriptor(); try { orgDesc.ID = element.Element(EnumOldServiceFieldsAsKeys.orgID.ToString()).Value.Trim(); } catch (Exception) { // no value to parse orgDesc.ID = string.Empty; } try { orgDesc.Name = HttpUtility.HtmlEncode(HttpUtility.HtmlDecode(element.Element(EnumOldServiceFieldsAsKeys.name.ToString()).Value.Trim())); // #307 - Will be reviewed at launch //if (orgDesc.Name == "Molecular Biophysics and Biochemistry") //{ //orgDesc.Name = "MB and B"; //} } catch (Exception) { // no value to parse orgDesc.Name = string.Empty; } try { orgDesc.Type = HttpUtility.HtmlEncode(HttpUtility.HtmlDecode(element.Element(EnumOldServiceFieldsAsKeys.orgType.ToString()).Value.Trim())); } catch (Exception) { // no value to parse orgDesc.Type = string.Empty; } try { orgDesc.IsDisplayedOnYmg = (element.Element(EnumOldServiceFieldsAsKeys.ymgStatus.ToString()).Value.Trim() == "Y"); } catch (Exception) { // no value to parse orgDesc.IsDisplayedOnYmg = false; } try { tempValue = HttpUtility.HtmlEncode(HttpUtility.HtmlDecode(element.Element(EnumOldServiceFieldsAsKeys.mission.ToString()).Value)); if (!string.IsNullOrEmpty(tempValue)) { var tempValues = tempValue.Split(','); foreach (var temp in tempValues) { orgDesc.Missions.Add(temp.Trim()); } } } catch (Exception) { // no value to parse } try { string isPrimary = element.Element(EnumOldServiceFieldsAsKeys.primaryDept.ToString()).Value.Trim(); if (isPrimary == "Y") { orgDesc.IsPrimary = true; } else { orgDesc.IsPrimary = false; } } catch (Exception) { // no value to parse } if (depth > 0) { orgDesc.Parent = parent; } orgDesc.Depth = depth; if (parent != null) { parent.Children.Add(orgDesc); } allPuzzlePieces.Add(orgDesc); } if (element.Elements(EnumOldServiceFieldsAsKeys.treeDepartment.ToString()).Count() > 0) { foreach (XElement child in element.Elements(EnumOldServiceFieldsAsKeys.treeDepartment.ToString())) { PopulateTreeDescriptorsFromOld(child, orgDesc, allPuzzlePieces, depth + 1); } } }
/// <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)); }