public void AlignElements_NullAligner_ThrowsArgumentNullException() { IList <int> collection1 = new int[0]; IList <int> collection2 = new int[0]; IEnumerable <DiffSection> diffSections = new DiffSection[0]; IDiffElementAligner <int> aligner = null; Assert.Throws <ArgumentNullException>(() => Diff.AlignElements(collection1, collection2, diffSections, aligner)); }
public object GetDiff(int id) { var diff = _diffReository.GetDiff(id); if (diff == null) { return(null); } var leftData = Convert.FromBase64String(diff.Left); var decodedLeftString = Encoding.UTF8.GetString(leftData); var rightData = Convert.FromBase64String(diff.Right); var decodedRightString = Encoding.UTF8.GetString(rightData); if (decodedLeftString == decodedRightString) { return(new { diffResultType = DiffMessages.EqualsResponse }); } else if (decodedLeftString.Length != decodedRightString.Length) { return(new { diffResultType = DiffMessages.SizeDoNotMatchResponse }); } var leftPieces = decodedLeftString.ToCharArray(); var rightPieces = decodedRightString.ToCharArray(); var differences = new List <DiffSection>(); DiffSection currentDiff = null; for (int i = 0; i < leftPieces.Length; i++) { if (currentDiff == null) { if (leftPieces[i] != rightPieces[i]) { currentDiff = new DiffSection { Offset = i, Length = 1 }; } } else { if (leftPieces[i] != rightPieces[i]) { currentDiff.Length++; } else { differences.Add(currentDiff); currentDiff = null; } } } if (currentDiff != null) { differences.Add(currentDiff); } return(new { diffResultType = DiffMessages.ContentDoNotMatchResponse, diffs = differences }); }
public void DiffSection_True_Line() { var lineDelete = new DiffLine { Type = DiffLineType.DiffLineDelete, Content = "- <groupId>com.ambientideas</groupId>", LeftLine = 4, RightLine = 0 }; var lineAdd = new DiffLine { Type = DiffLineType.DiffLineAdd, Content = "+ <groupId>com.github</groupId", LeftLine = 0, RightLine = 4 }; var section = new DiffSection { Lines = new List <DiffLine> { new DiffLine { Type = DiffLineType.DiffLineSection, Content = "@@ -1,7 +1,7 @@" }, new DiffLine { Type = DiffLineType.DiffLinePlain, Content = " <project xmlns=\"http://maven.apache.org/POM/4.0.0\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"", LeftLine = 1, RightLine = 1 }, new DiffLine { Type = DiffLineType.DiffLinePlain, Content = " xsi:schemaLocation=\"http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd\">", LeftLine = 2, RightLine = 2 }, new DiffLine { Type = DiffLineType.DiffLinePlain, Content = " <modelVersion>4.0.0</modelVersion>", LeftLine = 3, RightLine = 3 }, lineDelete, lineAdd, new DiffLine { Type = DiffLineType.DiffLinePlain, Content = " <artifactId>egitdemo</artifactId>", LeftLine = 5, RightLine = 5 }, new DiffLine { Type = DiffLineType.DiffLinePlain, Content = " <packaging>jar</packaging>", LeftLine = 6, RightLine = 6 }, new DiffLine { Type = DiffLineType.DiffLinePlain, Content = " <version>1.0-SNAPSHOT</version>", LeftLine = 7, RightLine = 7 } } }; var del = section.Line(lineDelete.Type, 4); Assert.Equal(lineDelete, del); var add = section.Line(lineAdd.Type, 4); Assert.Equal(lineAdd, add); }