~ubuntu-branches/ubuntu/trusty/monodevelop/trusty-proposed

« back to all changes in this revision

Viewing changes to external/ngit/Sharpen.Test/FilePathTest.cs

  • Committer: Package Import Robot
  • Author(s): Jo Shields
  • Date: 2013-05-12 09:46:03 UTC
  • mto: This revision was merged to the branch mainline in revision 29.
  • Revision ID: package-import@ubuntu.com-20130512094603-mad323bzcxvmcam0
Tags: upstream-4.0.5+dfsg
ImportĀ upstreamĀ versionĀ 4.0.5+dfsg

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
using System;
 
2
using NUnit.Framework;
 
3
using System.IO;
 
4
 
 
5
namespace Sharpen.Test
 
6
{
 
7
        [TestFixture]
 
8
        public class FilePathTest
 
9
        {
 
10
                static bool RunningOnLinux = !Environment.OSVersion.Platform.ToString().StartsWith("Win");
 
11
 
 
12
                [Test]
 
13
                public void SetLastWriteTime_Directory ()
 
14
                {
 
15
                        var temp = (FilePath) Path.Combine (Path.GetTempPath (), Path.GetRandomFileName ());
 
16
                        Directory.CreateDirectory (temp);
 
17
 
 
18
                        try {
 
19
                                var lastWriteTime = temp.LastModified ();
 
20
                                Assert.AreNotEqual (0, lastWriteTime, "#1");
 
21
 
 
22
                                lastWriteTime += (long)TimeSpan.FromHours (1).TotalMilliseconds;
 
23
                                temp.SetLastModified (lastWriteTime);
 
24
                                Assert.AreEqual (lastWriteTime, temp.LastModified (), "#2");
 
25
                        } finally {
 
26
                                Directory.Delete (temp);
 
27
                        }
 
28
                }
 
29
 
 
30
                [Test]
 
31
                public void SetLastWriteTime_File ()
 
32
                {
 
33
                        var temp = (FilePath) Path.GetTempFileName ();
 
34
                        try {
 
35
                                var lastWriteTime = temp.LastModified ();
 
36
                                Assert.AreNotEqual (0, lastWriteTime, "#1");
 
37
                                
 
38
                                lastWriteTime += (long)TimeSpan.FromHours (1).TotalMilliseconds;
 
39
                                temp.SetLastModified (lastWriteTime);
 
40
                                Assert.AreEqual (lastWriteTime, temp.LastModified (), "#2");
 
41
                        } finally {
 
42
                                File.Delete (temp);
 
43
                        }
 
44
                }
 
45
 
 
46
                [Test]
 
47
                public void CombineTwoAbsolutes_Unix ()
 
48
                {
 
49
                        var result = RunningOnLinux ? "/Foo/Bar" : @"C:\Foo\Bar";
 
50
                        Assert.AreEqual(result, new FilePath("/Foo", "/Bar").GetAbsolutePath());
 
51
                }
 
52
 
 
53
                [Test]
 
54
                public void CombineTwoAbsolutes_DoubleSeperator_Unix ()
 
55
                {
 
56
                        var result = RunningOnLinux ? "/Foo/Bar" : @"C:\Foo\Bar";
 
57
                        Assert.AreEqual (result, new FilePath ("/Foo", "////Bar").GetAbsolutePath ());
 
58
                }
 
59
 
 
60
                [Test]
 
61
                public void CombineTwoAbsolutes_NullParentFilePath_Unix ()
 
62
                {
 
63
                        var result = RunningOnLinux ? "/Bar" : @"C:\Bar";
 
64
                        Assert.AreEqual(result, new FilePath((FilePath)null, "/Bar").GetAbsolutePath());
 
65
                }
 
66
 
 
67
                [Test]
 
68
                public void CombineTwoAbsolutes_NullParentString_Unix ()
 
69
                {
 
70
                        var result = RunningOnLinux ? "/Bar" : @"C:\Bar";
 
71
                        Assert.AreEqual(result, new FilePath((string)null, "/Bar").GetAbsolutePath());
 
72
                }
 
73
 
 
74
                [Test]
 
75
                public void CombineTwoAbsolutes_WindowsStyle_Unix ()
 
76
                {
 
77
                        var result = RunningOnLinux ? @"/Foo/\Bar" : @"C:\Foo\Bar";
 
78
                        Assert.AreEqual(result, new FilePath("/Foo", @"\Bar").GetAbsolutePath());
 
79
                }
 
80
        }
 
81
}