Exemple #1
0
        public virtual Data.FileChange ConvertFile(FileDiff fileDiff)
        {
            Requires.NotNull(fileDiff, "fileDiff");

            // Figure out the change type
            Data.FileChange chg;
            if (String.Equals(fileDiff.ModifiedFile, "/dev/null"))
            {
                // Deletion
                chg = new Data.FileDeletion() { FileName = fileDiff.OriginalFile };
            }
            else if (String.Equals(fileDiff.OriginalFile, "/dev/null"))
            {
                // Addition
                chg = new Data.FileAddition() { FileName = fileDiff.ModifiedFile };
            }
            else
            {
                // Modification
                chg = new Data.FileModification() {
                    FileName = CleanPath(fileDiff.OriginalFile),
                    NewFileName = CleanPath(fileDiff.ModifiedFile)
                };
            }

            // Fill the lines
            chg.Diff = String.Join(Environment.NewLine, fileDiff.Hunks.Select(WriteHunk));
            return chg;
        }
            public void ReadsFromInputAndPassesToConverter()
            {
                // Arrange
                var service = CreateService();
                var expected = new FileModification();
                var input = new StringReader("abc");
                var set = new DiffSet(new FileDiff("Orig", "Mod"));
                service.MockReader.Setup(r => r.Read(input)).Returns(set);
                service.MockConverter.Setup(c => c.ConvertFile(set.Files.First())).Returns(expected);

                // Act
                var actual = service.CreateFromGitDiff(input).SingleOrDefault();

                // Assert
                Assert.Same(expected, actual);
            }