Exemple #1
0
        public void Diff_RunDiffTests()
        {
            SvnSandBox sbox = new SvnSandBox(this);

            sbox.Create(SandBoxRepository.Empty, false);
            string WcPath = sbox.Wc;

            string start    = Guid.NewGuid().ToString() + Environment.NewLine + Guid.NewGuid().ToString();
            string end      = Guid.NewGuid().ToString() + Environment.NewLine + Guid.NewGuid().ToString();
            string origLine = Guid.NewGuid().ToString();
            string newLine  = Guid.NewGuid().ToString();

            using (SvnClient client = NewSvnClient(true, false))
            {
                string diffFile = Path.Combine(WcPath, "DiffTest");

                using (StreamWriter sw = File.CreateText(diffFile))
                {
                    sw.WriteLine(start);
                    sw.WriteLine(origLine);
                    sw.WriteLine(end);
                }

                client.Add(diffFile);
                SvnCommitResult ci;
                client.Commit(diffFile, out ci);

                using (StreamWriter sw = File.CreateText(diffFile))
                {
                    sw.WriteLine(start);
                    sw.WriteLine(newLine);
                    sw.WriteLine(end);
                }

                MemoryStream diffOutput = new MemoryStream();

                client.Diff(new SvnPathTarget(diffFile, SvnRevisionType.Head), diffFile, diffOutput);
                VerifyDiffOutput(origLine, newLine, diffOutput);

                diffOutput = new MemoryStream();

                client.Diff(new SvnPathTarget(diffFile, SvnRevisionType.Committed), diffFile, diffOutput);
                VerifyDiffOutput(origLine, newLine, diffOutput);

                diffOutput = new MemoryStream();

                client.Diff(new Uri(sbox.RepositoryUri, "DiffTest"), diffFile, diffOutput);
                VerifyDiffOutput(origLine, newLine, diffOutput);

                SvnCommitResult info;
                client.Commit(diffFile, out info);

                bool visited = false;
                client.DiffSummary(new SvnUriTarget(sbox.RepositoryUri, info.Revision - 1), sbox.RepositoryUri,
                                   delegate(object sender, SvnDiffSummaryEventArgs e)
                {
                    if (e.Path == "DiffTest")
                    {
                        Assert.That(e.DiffKind, Is.EqualTo(SvnDiffKind.Modified));
                        Assert.That(e.PropertiesChanged, Is.False);
                        visited = true;
                    }
                });

                Assert.That(visited);

                int n = 0;

                client.Blame(new SvnPathTarget(diffFile), delegate(object sender, SvnBlameEventArgs e)
                {
                    Assert.That(e.Author, Is.EqualTo(Environment.UserName));
                    Assert.That(e.LineNumber, Is.EqualTo((long)n));
                    switch (n)
                    {
                    case 0:
                    case 1:
                    case 3:
                    case 4:
                        Assert.That(e.Revision, Is.EqualTo(ci.Revision));
                        break;

                    case 2:
                        Assert.That(e.Revision, Is.EqualTo(info.Revision));
                        break;

                    default:
                        Assert.That(false, "EOF");
                        break;
                    }
                    Assert.That(e.Line, Is.Not.Null);
                    n++;
                });

                Assert.That(n, Is.EqualTo(5), "Blame receiver received 5 lines");

                string tempFile = GetTempFile();
                using (FileStream fs = File.Create(tempFile))
                {
                    SvnDiffArgs da = new SvnDiffArgs();
                    da.RelativeToPath = Path.GetDirectoryName(diffFile);
                    client.Diff(diffFile, new SvnRevisionRange(ci.Revision, SvnRevisionType.Head), da, fs);
                }

                client.Update(diffFile, new SvnUpdateArgs {
                    Revision = ci.Revision
                });
                SvnPatchArgs pa = new SvnPatchArgs();
                n          = 0;
                pa.Filter += delegate(object sender, SvnPatchFilterEventArgs e)
                {
                    Assert.That(File.Exists(e.RejectPath));
                    Assert.That(File.Exists(e.ResultPath));
                    Assert.That(new FileInfo(e.RejectPath).Length, Is.EqualTo(0));
                    n++;
                };
                client.Patch(tempFile, Path.GetDirectoryName(diffFile), pa);
                Assert.That(n, Is.EqualTo(1));
            }
        }