PageRenderTime 28ms CodeModel.GetById 15ms app.highlight 8ms RepoModel.GetById 2ms app.codeStats 0ms

/Mercurial.Net.Tests/RemoveTests.cs

#
C# | 90 lines | 83 code | 7 blank | 0 comment | 1 complexity | 9cb5f94379443e9f3f94ff717bafa405 MD5 | raw file
 1using System;
 2using System.IO;
 3using System.Linq;
 4using NUnit.Framework;
 5
 6namespace Mercurial.Tests
 7{
 8    [TestFixture]
 9    public class RemoveTests : SingleRepositoryTestsBase
10    {
11        [TestCase((string)null)]
12        [TestCase("")]
13        [TestCase(" \t\n\r")]
14        [Test]
15        [Category("API")]
16        public void Remove_NullOrEmptyPath_ThrowsArgumentNullException(string input)
17        {
18            Assert.Throws<ArgumentNullException>(() => Repo.Remove(input));
19        }
20
21        [Test]
22        [Category("Integration")]
23        public void Remove_UncommittedFileWithForce_RemovesFile()
24        {
25            Repo.Init();
26            File.WriteAllText(Path.Combine(Repo.Path, "test.txt"), "contents");
27            Repo.Add("test.txt");
28            Repo.Remove(
29                "test.txt", new RemoveCommand
30                {
31                    ForceRemoval = true,
32                });
33            CollectionAssert.AreEqual(
34                Repo.Status(),
35                new[]
36                {
37                    new FileStatus(FileState.Unknown, "test.txt"),
38                });
39        }
40
41        [Test]
42        [Category("Integration")]
43        public void Remove_DeletedFileWithRecordDeletesOption_RemovesFile()
44        {
45            Repo.Init();
46            WriteTextFileAndCommit(Repo, "test.txt", "dummy", "dummy", true);
47            File.Delete(Path.Combine(Repo.Path, "test.txt"));
48            Repo.Remove(
49                new RemoveCommand
50                {
51                    RecordDeletes = true,
52                });
53            FileStatus[] status = Repo.Status().ToArray();
54
55            CollectionAssert.AreEqual(
56                status, new[]
57                {
58                    new FileStatus(FileState.Removed, "test.txt"),
59                });
60        }
61
62        [Test]
63        [Category("Integration")]
64        public void Remove_FileDoesNotExist_ThrowsMercurialExecutionException()
65        {
66            Repo.Init();
67            Assert.Throws<MercurialExecutionException>(() => Repo.Remove("test.txt"));
68        }
69
70        [Test]
71        [Category("Integration")]
72        public void Remove_InUninitializedRepository_ThrowsMercurialExecutionException()
73        {
74            File.WriteAllText(Path.Combine(Repo.Path, "test.txt"), "contents");
75            Assert.Throws<MercurialExecutionException>(() => Repo.Remove("test.txt"));
76        }
77
78        [Test]
79        [Category("Integration")]
80        public void Remove_UncommittedFile_ThrowsMercurialExecutionException()
81        {
82            if (ClientExecutable.GetVersion() < new Version(1, 7, 0, 0))
83                Assert.Ignore("This is not reported as a problem in Mercurial <1.7");
84            Repo.Init();
85            File.WriteAllText(Path.Combine(Repo.Path, "test.txt"), "contents");
86            Repo.Add("test.txt");
87            Assert.Throws<MercurialExecutionException>(() => Repo.Remove("test.txt"));
88        }
89    }
90}