protected override void Context() { _report = new DiffReport(); _commonAncestor = new Container(); _settings = new ComparerSettings(); CreateSut(); }
public void GenerateDiffReport(DiffReport diffReport) { var path = Path.Combine(ReportFolderPath, $"report_{DateTime.Now.ToString(DateFormat)}.xlsx"); var fileInfo = new FileInfo(path); fileInfo.Directory.Create();//creating a dir if does not exist using (var excelPackage = new ExcelPackage(fileInfo)) { var worksheet = excelPackage.Workbook.Worksheets.Add("report"); InitializeTableHeaders(worksheet); var lastRow = GenerateMismatchPart(worksheet, diffReport.Mismatches); SetFilterForTable(worksheet, lastRow - 1);//filtering only mismatches SetSeparator(worksheet.Cells[lastRow, ExcelReport.ColumnOffset, lastRow, ExcelReport.DataEndColumn - 1]); SetMissingFromEipHeader(worksheet, ++lastRow, diffReport.CheckedRange); lastRow = GenerateMissingEipProductPart(worksheet, diffReport.ProductsMissingFromEip, ++lastRow); SetSeparator(worksheet.Cells[lastRow, ExcelReport.ColumnOffset, lastRow, ExcelReport.DataEndColumn - 1]); SetEipHeader(worksheet, lastRow, ExcelReport.ProductsMissingFromExcel, diffReport.CheckedRange); lastRow = GenerateMissingExcelProductPart(worksheet, diffReport.ProductsMissingFromExcel, ++lastRow); SetSeparator(worksheet.Cells[++lastRow, ExcelReport.ColumnOffset, lastRow, ExcelReport.DataEndColumn - 1]); SetOutOfRangeEiplHeader(worksheet, lastRow, diffReport.CheckedRange); lastRow = GenerateOutOfRangeProductPart(worksheet, diffReport.ProductsOutOfSelectedRange, ++lastRow); excelPackage.Save(); } }
public Comparison(TObject object1, TObject object2, ComparerSettings settings, DiffReport report, object commonAncestor) { Object1 = object1; Object2 = object2; Settings = settings; Report = report; CommonAncestor = commonAncestor; }
private Task GenerateExcelReportAsync(DiffReport diffReport) { return(Task.Run(() => { _logService.Information("Start generating excel report"); _lifetimeService.ExecuteInLifetime <IReportGenerator>(generator => generator.GenerateDiffReport(diffReport)); })); }
protected internal virtual void CompareWith(PropertiesRep other, DiffReport diff) { bool equals = Props.Equals(other.Props); if (!equals) { diff.Add("Properties diff for " + EntityToString + " mine:" + Props + ", other:" + other.Props); } }
private void ReportDiff(GeneratedDaoAssemblyInfo info, TypeSchema typeSchema) { OldInfoString = info.TypeSchemaInfo ?? string.Empty; NewInfoString = typeSchema.ToString(); DiffReport diff = DiffReport.Create(OldInfoString, NewInfoString); ConsoleDiffReportFormatter diffFormatter = new ConsoleDiffReportFormatter(diff); diffFormatter.Format(); // outputs to console FireEvent(SchemaDifferenceDetected, new SchemaDifferenceEventArgs { GeneratedDaoAssemblyInfo = info, TypeSchema = typeSchema, DiffReport = diff }); }
internal virtual void CompareWith(NodeRep other, DiffReport diff) { if (other.Id != Id) { diff.Add("Id differs mine:" + Id + ", other:" + other.Id); } Properties.compareWith(other.Properties, diff); if (Index != null && other.Index != null) { CompareIndex(other, diff); } CompareRelationships(other, diff); }
public void Its_possible_to_exclude_by_member_path() { var diff = new DiffReport(); diff.ReportDiff("Id", 1, 2); diff.ReportDiff("Name", "Gøran", "Torkild"); diff.ReportDiff("Age", 30, 40); diff.SetFilter( new RegexMemberPathExcludeFilter("Id"), new RegexMemberPathExcludeFilter("Age")); Assert.AreEqual(1, diff.Table.Rows.Count()); Assert.AreEqual("Name", diff.Table[0].MemberPath); }
public void Its_possible_to_filter_by_member_path_and_values() { var diff = new DiffReport(); diff.ReportDiff("Name", "Gøran", "Torkild"); diff.ReportDiff("Age", 30, 42); diff.ReportDiff("Weight", 230, 460); diff.SetFilter(new ValueInspectionFilter<int>("Age", (leftValue, rightValue) => leftValue > 30)); Assert.AreEqual(2, diff.Table.Rows.Count()); Assert.AreEqual("Name", diff.Table[0].MemberPath); Assert.AreEqual("Weight", diff.Table[1].MemberPath); }
protected override void Context() { _view = A.Fake <IComparisonView>(); _diffItemDTOMapper = A.Fake <IDiffItemToDiffItemDTOMapper>(); _objectComparer = A.Fake <IObjectComparer>(); _dataTableMapper = A.Fake <IDiffItemDTOsToDataTableMapper>(); sut = new ComparisonPresenter(_view, _objectComparer, _diffItemDTOMapper, _dataTableMapper); _settings = new ComparerSettings(); _object1 = A.Fake <IObjectBase>(); _object2 = A.Fake <IObjectBase>(); _report = new DiffReport(); A.CallTo(() => _objectComparer.Compare(_object1, _object2, _settings)).Returns(_report); }
/// <summary> /// デフォルトコンストラクタ /// </summary> /// <param name="report">比較結果</param> public MargeDialog(DiffReport report) : base() { InitializeComponent(); if (DesignMode) return; // コンボボックスのアイテムを積む actionColumn.Items.Clear(); actionColumn.Items.AddRange(SOURCE, DESTINATION, EMPTY, DELETE); DiffReport = report; }
private void ConstraintDiff(DbRepresentation other, DiffReport diff) { foreach (ConstraintDefinition constraint in _constraints) { if (!other._constraints.Contains(constraint)) { diff.Add("I have constraint " + constraint + " which other doesn't"); } } foreach (ConstraintDefinition otherConstraint in other._constraints) { if (!_constraints.Contains(otherConstraint)) { diff.Add("Other has constraint " + otherConstraint + " which I don't"); } } }
private void IndexDiff(DbRepresentation other, DiffReport diff) { foreach (IndexDefinition schemaIndex in _schemaIndexes) { if (!other._schemaIndexes.Contains(schemaIndex)) { diff.Add("I have schema index " + schemaIndex + " which other doesn't"); } } foreach (IndexDefinition otherSchemaIndex in other._schemaIndexes) { if (!_schemaIndexes.Contains(otherSchemaIndex)) { diff.Add("Other has schema index " + otherSchemaIndex + " which I don't"); } } }
/* * Yes, this is not the best way to do it - hash map does a deep equals. However, * if things go wrong, this way give the ability to check where the inequality * happened. If you feel strongly about this, feel free to change. * Admittedly, the implementation could use some cleanup. */ internal virtual void CompareIndex(NodeRep other, DiffReport diff) { if (other.Index == Index) { return; } ICollection <string> allIndexes = new HashSet <string>(); allIndexes.addAll(Index.Keys); allIndexes.addAll(other.Index.Keys); foreach (string indexName in allIndexes) { if (!Index.ContainsKey(indexName)) { diff.Add(this + " isn't indexed in " + indexName + " for mine"); continue; } if (!other.Index.ContainsKey(indexName)) { diff.Add(this + " isn't indexed in " + indexName + " for other"); continue; } IDictionary <string, Serializable> thisIndex = Index[indexName]; IDictionary <string, Serializable> otherIndex = other.Index[indexName]; if (thisIndex.Count != otherIndex.Count) { diff.Add("other index had a different mapping count than me for node " + this + " mine:" + thisIndex + ", other:" + otherIndex); continue; } foreach (KeyValuePair <string, Serializable> indexEntry in thisIndex.SetOfKeyValuePairs()) { if (!indexEntry.Value.Equals(otherIndex[indexEntry.Key])) { diff.Add("other index had a different value indexed for " + indexEntry.Key + "=" + indexEntry.Value + ", namely " + otherIndex[indexEntry.Key] + " for " + this); } } } }
private void NodeDiff(DbRepresentation other, DiffReport diff) { foreach (NodeRep node in _nodes.Values) { NodeRep otherNode = other._nodes[node.Id]; if (otherNode == null) { diff.Add("I have node " + node.Id + " which other doesn't"); continue; } node.CompareWith(otherNode, diff); } foreach (long?id in other._nodes.Keys) { if (!_nodes.ContainsKey(id)) { diff.Add("Other has node " + id + " which I don't"); } } }
internal virtual void CompareRelationships(NodeRep other, DiffReport diff) { foreach (PropertiesRep rel in OutRelationships.Values) { PropertiesRep otherRel = other.OutRelationships[rel.EntityId]; if (otherRel == null) { diff.Add("I have relationship " + rel.EntityId + " which other don't"); continue; } rel.CompareWith(otherRel, diff); } foreach (long?id in other.OutRelationships.Keys) { if (!OutRelationships.ContainsKey(id)) { diff.Add("Other has relationship " + id + " which I don't"); } } }
public void It_is_possible_to_exclude_many_diffs_using_filters() { var diff = new DiffReport(); diff.ReportDiff("StatusLog.LogItems[0].Timestamp", "", ""); diff.ReportDiff("StatusLog.LogItems[1].Timestamp", "", ""); diff.ReportDiff("JobIds[0]", 277540, 277906); diff.ReportDiff("JobIds[1]", 277541, 277907); diff.ReportDiff("JobIds[2]", 277542, 277908); diff.ReportDiff("CreatedBy", "toinds", "gohans"); diff.SetFilter(new RegexMemberPathExcludeFilter( "^MathModelCaseId$|" + @"^CaseSnapshot\.MetaData\.Name$|" + @"^CaseSnapshot\.MetaData\.Category$|" + @"^Id$|\.Id$|" + @"^StatusLog\.LogItems\[\d*\]\.Timestamp$|" + @"^JobIds\[\d*\]$|" + @"^CopyProperties.Name$|" + @"^Timestamp$|" + @"^CreatedBy$|" + @"^CreatedWhen$")); Assert.AreEqual(0, diff.Table.Rows.Count()); }
// Public methods public async Task CheckServiceForApiChanges(string webServiceName, string previousApiDocumentJSON, string freshApiDocumentJSON) { // Convert serialized JSON swagger definition into instances of OpenApiDocuments OpenApiDocument previousApiDocument = GetDeserializedJsonAsOpenApiDocument(previousApiDocumentJSON); OpenApiDocument freshApiDocument = GetDeserializedJsonAsOpenApiDocument(freshApiDocumentJSON); // Create instance of DiffReport class to store API changes DiffReport diffReport = new DiffReport(webServiceName); // Create array of tasks Task[] tasks = new Task[] { Task.Run(() => CheckForApiRouteAndHttpMethodAdditions(previousApiDocument, freshApiDocument, diffReport)), Task.Run(() => CheckForApiRouteAndHttpMethodRemovals(previousApiDocument, freshApiDocument, diffReport)) }; // Run all tasks in parallell await Task.WhenAll(tasks); // Get slack message JSON from diff report JObject slackMessage = diffReport.GenerateSlackMessageContent(); // Make Client request to post slack message _clientRequestService.SendSlackMessage(diffReport.WebServiceName, slackMessage); }
public ConsoleDiffReportFormatter(DiffReport report) : base(report) { }
protected override void Because() { _oneObject = new ARootContainer(); _report1 = sut.Compare(null, _oneObject); _report2 = sut.Compare(_oneObject, null); }
protected override void Because() { _report = sut.Compare(_object1, _object2, _comparerSettings); }
/*** API document comparison checks ***/ private void CheckForApiRouteAndHttpMethodAdditions(OpenApiDocument previousApiDocument, OpenApiDocument freshApiDocument, DiffReport diffReport) { // Get information for all routes in previous API documentation OpenApiPaths previousApiDocumentRoutes = previousApiDocument.Paths; // Get information for all routes in fresh API documentation OpenApiPaths freshApiDocumentRoutes = freshApiDocument.Paths; // Iterate over all routes in freshly downloaded API documentation foreach (KeyValuePair <string, OpenApiPathItem> route in freshApiDocumentRoutes) { // Find current API route as string string currentApiRoute = route.Key; // Check if this route in the fresh API documentation in a new addition if (!previousApiDocumentRoutes.ContainsKey(currentApiRoute)) { // NOTE: New route detected, therefore all HTTP methods associated with this route are new // Find all HTTP methods associated with this route (HTTP methods represented as enum type OpenApi.Models.OperationType) OpenApiPathItem newApiRouteValue = route.Value; IDictionary <OperationType, OpenApiOperation> newApiRouteHttpMethodsDict = newApiRouteValue.Operations; // Verify route has associated HTTP methods if (newApiRouteHttpMethodsDict.Count > 0) { // Get list of all HTTP methods associated with this new route IList <OperationType> newApiRouteHttpMethodTypes = new List <OperationType>(newApiRouteHttpMethodsDict.Keys); // Iterate through the new route's HTTP methods foreach (OperationType newApiRouteHttpMethod in newApiRouteHttpMethodTypes) { // Save added route/HTTP method information for API diff report diffReport.RecordAddedRouteInformation(currentApiRoute, newApiRouteHttpMethod); } } } else { // Previous API documentation already has this API route, check if there are any new HTTP methods for the existing route // Get dictionary of HTTP methods for current route from fresh API documentation OpenApiPathItem freshApiDocumentRouteValue = route.Value; IDictionary <OperationType, OpenApiOperation> freshApiDocumentRouteInfo = freshApiDocumentRouteValue.Operations; // Get dictionary of HTTP methods for current route from previous API documentation OpenApiPathItem previousApiDocumentRouteValue = previousApiDocumentRoutes[currentApiRoute]; IDictionary <OperationType, OpenApiOperation> previousApiDocumentRouteInfo = previousApiDocumentRouteValue.Operations; // Verify that fresh API documentation for this route contains HTTP methods if (freshApiDocumentRouteInfo.Count > 0) { // For this route, get list of HTTP methods in fresh API documentation IList <OperationType> freshApiRouteHttpMethods = new List <OperationType>(freshApiDocumentRouteInfo.Keys); // For this route, get list of HTTP methods in previous API documentation IList <OperationType> previousApiRouteHttpMethods = new List <OperationType>(previousApiDocumentRouteInfo.Keys); // Iterate over all HTTP methods listed in fresh API documentation for this route foreach (OperationType freshHttpMethod in freshApiRouteHttpMethods) { // For this route, if an HTTP method exists in fresh API documentation but not previous API documentation, // We have found a new API endpoint if (!previousApiRouteHttpMethods.Contains(freshHttpMethod)) { // Record newly detected API endpoint in diff report object diffReport.RecordAddedRouteInformation(currentApiRoute, freshHttpMethod); } } } } } }
private void CheckForApiRouteAndHttpMethodRemovals(OpenApiDocument previousApiDocument, OpenApiDocument freshApiDocument, DiffReport diffReport) { // Get information for all routes in previous API documentation OpenApiPaths previousApiDocumentRoutes = previousApiDocument.Paths; // Get information for all routes in fresh API documentation OpenApiPaths freshApiDocumentRoutes = freshApiDocument.Paths; // Iterate over all routes in previously stored API documentation foreach (KeyValuePair <string, OpenApiPathItem> route in previousApiDocumentRoutes) { // Find current API route as string string currentApiRoute = route.Key; // Check if this route in the previously downloaded API documentation has been removed if (!freshApiDocumentRoutes.ContainsKey(currentApiRoute)) { // NOTE: This route has been removed, therefore all HTTP methods associated with this route have been removed // Find all HTTP methods associated with this route (HTTP methods represented as enum type OpenApi.Models.OperationType) OpenApiPathItem removedApiRouteValue = route.Value; IDictionary <OperationType, OpenApiOperation> removedApiRouteHttpMethodsDict = removedApiRouteValue.Operations; // Verify route has associated HTTP methods if (removedApiRouteHttpMethodsDict.Count > 0) { // Get list of all HTTP methods associated with this removed route IList <OperationType> removedApiRouteHttpMethodTypes = new List <OperationType>(removedApiRouteHttpMethodsDict.Keys); // Iterate through the removed route's HTTP methods foreach (OperationType removedApiRouteHttpMethod in removedApiRouteHttpMethodTypes) { // Save removed route/HTTP method information for API diff report diffReport.RecordRemovedRouteInformation(currentApiRoute, removedApiRouteHttpMethod); } } } else { // New API documentation has this route, check if any HTTP methods have been removed // Get dictionary of HTTP methods for current route from previous API documentation OpenApiPathItem previousApiDocumentRouteValue = route.Value; IDictionary <OperationType, OpenApiOperation> previousApiDocumentRouteInfo = previousApiDocumentRouteValue.Operations; // Get dictionary of HTTP methods for current API route from fresh API documentation OpenApiPathItem freshApiRouteValue = freshApiDocumentRoutes[currentApiRoute]; IDictionary <OperationType, OpenApiOperation> freshApiDocumentRouteInfo = freshApiRouteValue.Operations; // Verify that previous API documentation for this route contains HTTP methods if (previousApiDocumentRouteInfo.Count > 0) { // For this route, get list of HTTP methods in previous API documentation IList <OperationType> previousApiRouteHttpMethods = new List <OperationType>(previousApiDocumentRouteInfo.Keys); // For this route, get list of HTTP methods in fresh API documentation IList <OperationType> freshApiRouteHttpMethods = new List <OperationType>(freshApiDocumentRouteInfo.Keys); // Iterate over all HTTP methods listted in previous API documentation for this route foreach (OperationType previousHttpMethod in previousApiRouteHttpMethods) { // For this route, if an HTTP method exists in previous API documentation but not fresh API documentation, // We have detected the removal of an API endpoint if (!freshApiRouteHttpMethods.Contains(previousHttpMethod)) { // Record removal of API endpoint in diff report object diffReport.RecordRemovedRouteInformation(currentApiRoute, previousHttpMethod); } } } } } }
public DiffReport GetDiffReport() { var report = new DiffReport(); if (TablesAdded.Any() || TablesDeleted.Any() || TablesDiff.Any()) { var tables = report.AddCategory("Tables"); foreach (var addedTable in TablesAdded) { tables.AddEntry(addedTable.Name, DiffEntryType.Added, addedTable.ScriptCreate()); } foreach (var deletedTable in TablesDeleted) { tables.AddEntry(deletedTable.Name, DiffEntryType.Deleted, deletedTable.ScriptDrop()); } foreach (var tableDiff in TablesDiff) { var diffEntry = tables.AddEntry(tableDiff.Name, DiffEntryType.Changed, tableDiff.Script() ); if (tableDiff.ColumnsAdded.Any() || tableDiff.ColumnsDroped.Any() || tableDiff.ColumnsDiff.Any()) { var columns = diffEntry.AddCategory("Columns"); foreach (var column in tableDiff.ColumnsAdded) { columns.AddEntry(column.Name, DiffEntryType.Added); } foreach (var column in tableDiff.ColumnsDroped) { columns.AddEntry(column.Name, DiffEntryType.Deleted); } foreach (var columnDiff in tableDiff.ColumnsDiff) { columns.AddEntry(columnDiff.Source.Name, DiffEntryType.Changed); } } if (tableDiff.ConstraintsAdded.Any() || tableDiff.ConstraintsDeleted.Any() || tableDiff.ConstraintsChanged.Any()) { var constraints = diffEntry.AddCategory("Constraints"); foreach (var constraint in tableDiff.ConstraintsAdded) { constraints.AddEntry(constraint.Name, DiffEntryType.Added); } foreach (var constraint in tableDiff.ConstraintsDeleted) { constraints.AddEntry(constraint.Name, DiffEntryType.Deleted); } foreach (var constraint in tableDiff.ConstraintsChanged) { constraints.AddEntry(constraint.Name, DiffEntryType.Changed); } } } } if (ForeignKeysAdded.Any() || ForeignKeysDeleted.Any() || ForeignKeysDiff.Any()) { var foreignKeys = report.AddCategory("Foreign Keys"); foreach (var foreignKey in ForeignKeysAdded) { foreignKeys.AddEntry(foreignKey.Name, DiffEntryType.Added, foreignKey.ScriptCreate()); } foreach (var foreignKey in ForeignKeysDeleted) { foreignKeys.AddEntry(foreignKey.Name, DiffEntryType.Deleted, foreignKey.ScriptDrop()); } foreach (var foreignKey in ForeignKeysDiff) { var details = new StringBuilder(); details.AppendLine(foreignKey.ScriptDrop()); details.AppendLine("GO"); details.Append(foreignKey.ScriptCreate()); foreignKeys.AddEntry(foreignKey.Name, DiffEntryType.Changed, details.ToString()); } } if (RoutinesAdded.Any() || RoutinesDeleted.Any() || RoutinesDiff.Any()) { var routines = report.AddCategory("Routines"); foreach (var routine in RoutinesAdded) { routines.AddEntry(routine.Name, DiffEntryType.Added, routine.ScriptCreate(Db)); } foreach (var routine in RoutinesDeleted) { routines.AddEntry(routine.Name, DiffEntryType.Deleted, routine.ScriptDrop()); } foreach (var routine in RoutinesDiff) { var details = new StringBuilder(); details.AppendLine(routine.ScriptDrop()); details.AppendLine("GO"); details.Append(routine.ScriptCreate(Db)); routines.AddEntry(routine.Name, DiffEntryType.Changed, details.ToString()); } } if (PropsChanged.Any()) { var props = report.AddCategory("Properties"); foreach (var dbProp in PropsChanged) { props.AddEntry(dbProp.Name, DiffEntryType.Changed, dbProp.Script()); } } return report; }