Exemple #1
0
 public static List<string> GetDeletedStrings(SideBySideDiffModel SideBySideDiffResult)
 {
     List<string> DeletedStrings = new List<string>();
     foreach (DiffPiece Line in SideBySideDiffResult.OldText.Lines)
     {
         switch (Line.Type)
         {
             case ChangeType.Deleted:
                 DeletedStrings.Add(Line.Text);
                 break;
             case ChangeType.Modified:
                 foreach (DiffPiece Word in Line.SubPieces)
                 {
                     switch (Word.Type)
                     {
                         case ChangeType.Deleted:
                             DeletedStrings.Add(Word.Text);
                             break;
                         case ChangeType.Inserted:
                         case ChangeType.Imaginary:
                         case ChangeType.Unchanged:
                         case ChangeType.Modified:
                             break;
                     }
                 }
                 break;
             case ChangeType.Inserted:
             case ChangeType.Unchanged:
             case ChangeType.Imaginary:
                 break;
         }
     }
     return DeletedStrings;
 }
 private SideBySideDiffModel BuildLineDiff(string oldText, string newText)
 {
     var model = new SideBySideDiffModel();
     var diffResult = differ.CreateLineDiffs(oldText, newText, true);
     BuildDiffPieces(diffResult, model.OldText.Lines, model.NewText.Lines, BuildWordDiffPieces);
     return model;
 }
Exemple #3
0
 public static int GetLevel(SideBySideDiffModel SideBySideDiffResult, string Source, string Destination)
 {
     Double[] Result = new Double[2];
     Result[0] = FullDiff(SideBySideDiffResult.OldText.Lines, Source.Length);
     if (Source.Length == 0 && Destination.Length != 0) Result[0] = 100.0;
     Result[1] = FullDiff(SideBySideDiffResult.NewText.Lines, Destination.Length);
     if (Destination.Length == 0 && Source.Length != 0) Result[1] = 100.0;
     return (int)((Result[0] + Result[1]) / 2);
 }
Exemple #4
0
        public string Format(SideBySideDiffModel diffResult)
        {
            var dataInfo = new[] { diffResult.OldText.Lines, diffResult.NewText.Lines };
            var dir = Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location);

            string templateText;
            using (var templateStream = new StreamReader(string.Format(@"{0}\Templates\email.template", dir)))
                templateText = templateStream.ReadToEnd();

            return Razor.Parse(templateText, new { data = dataInfo });
        }
            public void Will_change_null_inputs_into_emtpty_strings()
            {
                var controller = TestableDiffController.Create();
                string oldText = null;
                string newText = null;
                var model = new SideBySideDiffModel();
                controller.MockDiffBuilder.Setup(x => x.BuildDiffModel(string.Empty, string.Empty)).Returns(model);

                var result = controller.Diff(oldText, newText);

                Assert.IsType<ViewResult>(result);
                var viewResult = (ViewResult) result;
                Assert.Equal(model, viewResult.ViewData.Model);
            }
            public void Will_call_BidiffBuild_with_given_text_and_return_model_to_view()
            {
                var controller = TestableDiffController.Create();
                string oldText = "a";
                string newText = "b";
                var model = new SideBySideDiffModel();
                controller.MockDiffBuilder.Setup(x => x.BuildDiffModel(oldText, newText)).Returns(model);

                var result = controller.Diff(oldText, newText);

                Assert.IsType<ViewResult>(result);
                var viewResult = (ViewResult) result;
                Assert.Equal(model, viewResult.ViewData.Model);
            }