Example #1
0
            public void WhenDirectoryHasFiles_ThenAssertTrue()
            {
                BaseDir.CreateFile("Test-ContainsFiles1.txt");
                BaseDir.CreateFile("Test-ContainsFiles2.txt");

                Assert.DoesNotThrow(() => AssertDir.ContainsFiles(ExistingDirectory, 2));
            }
Example #2
0
        public void ForceDeleteFile_WithNormalFile_DeletesIt()
        {
            var path = BaseDir.CreateFile("normal.txt");

            Should.NotThrow(() => SafeFile.ForceDeleteFile(path));
            path.FileExists().ShouldBeFalse();
        }
            public void WhenSizeIsEqual_ThenAssertTrue()
            {
                var file1 = BaseDir.CreateFile("SizeEquals-Test1.txt");
                var file2 = BaseDir.CreateFile("SizeEquals-Test2.txt");

                Assert.DoesNotThrow(() => AssertFile.SizeEquals(file1, file2));
            }
            public void WhenSizeIsNotEqual_ThenAssertFalse()
            {
                var file1 = BaseDir.CreateFile("SizeEquals-Test1.txt", "test1");
                var file2 = BaseDir.CreateFile("SizeEquals-Test2.txt", "test12");

                Assert.Throws <AssertionException>(() => AssertFile.SizeEquals(file1, file2));
            }
            public void WhenOriginalFileDoesNotExist_AndTargetExists_ThenAssertTrue()
            {
                const string file1 = "HasMoved-File1.txt";

                BaseDir.CreateFile(file1);

                Assert.DoesNotThrow(() => AssertFile.HasMoved(DoesNotExistFile.FullName, Path.Combine(ExistingDirectoryPath, file1)));
            }
            public void WhenFileExists_ThenAssertFalse()
            {
                const string file1 = "NotExists-File1.txt";

                BaseDir.CreateFile(file1);

                Assert.Throws <AssertionException>(() => AssertFile.NotExists(Path.Combine(ExistingDirectoryPath, file1)));
            }
            public void WhenFileExists_ThenAssertTrue()
            {
                const string file1 = "Exists-File1.txt";

                BaseDir.CreateFile(file1);

                Assert.DoesNotThrow(() => AssertFile.Exists(Path.Combine(ExistingDirectoryPath, file1)));
            }
            public void WhenFileHasNotBeenModifiedSince_ThenAssertFalse()
            {
                var file = BaseDir.CreateFile("ModifiedSince-Test1.txt");

                var since = DateTime.Now;

                Assert.Throws <AssertionException>(() => AssertFile.ModifiedSince(file, since));
            }
            public void WhenFileHasBeenModifiedSince_ThenAssertTrue()
            {
                var since = DateTime.Now.AddSeconds(-1);

                var file = BaseDir.CreateFile("ModifiedSince-Test1.txt");

                Assert.DoesNotThrow(() => AssertFile.ModifiedSince(file, since));
            }
            public void WhenFileContentIsNotExpected_ThenAssertFalse()
            {
                const string content = "test1";

                var file = BaseDir.CreateFile("ContentEquals-Test2.txt", content);

                Assert.Throws <AssertionException>(() => AssertFile.ContentEquals(file, content + "A"));
            }
            public void WhenFileContentIsExpected_ThenAssertTrue()
            {
                const string content = "test1";

                var file = BaseDir.CreateFile("ContentEquals-Test1.txt", content);

                Assert.DoesNotThrow(() => AssertFile.ContentEquals(file, content));
            }
Example #12
0
        public void ForceDeleteFile_WithReadOnlyFile_DeletesIt()
        {
            var path = BaseDir.CreateFile("readonly.txt");

            SafeFile.SetReadOnly(path);

            Should.NotThrow(() => SafeFile.ForceDeleteFile(path));
            path.FileExists().ShouldBeFalse();
        }
Example #13
0
        public void AtomicWrite_ReplacingExistingReadOnlyFile_Throws()
        {
            var path = BaseDir.CreateFile("test.txt");

            SafeFile.SetReadOnly(path);

            Should.Throw <UnauthorizedAccessException>(() =>
                                                       SafeFile.AtomicWrite(path, tmpPath => tmpPath.ToNPath().CreateFile()));
        }
Example #14
0
        public void AtomicWrite_WithEmptyAction_ShouldDoNothing()
        {
            var path = BaseDir.CreateFile("test.txt");

            SafeFile.AtomicWrite(path, tmpPath => { });

            path.FileExists().ShouldBeTrue();
            (path + SafeFile.TmpExtension).ToNPath().FileExists().ShouldBeFalse();
            (path + SafeFile.BakExtension).ToNPath().FileExists().ShouldBeFalse();
        }
Example #15
0
        public void SetReadOnly_AppliesProperFileAttributes()
        {
            var path = BaseDir.CreateFile("normal.txt");

            ((File.GetAttributes(path) & FileAttributes.ReadOnly) == 0).ShouldBeTrue();

            SafeFile.SetReadOnly(path);
            ((File.GetAttributes(path) & FileAttributes.ReadOnly) != 0).ShouldBeTrue();
            SafeFile.SetReadOnly(path, false);
            ((File.GetAttributes(path) & FileAttributes.ReadOnly) == 0).ShouldBeTrue();
        }
        public void Set_Permission_Works([ValueSource(nameof(PermissionScenarios))] NativeUnix.UnixFilePermissions permission)
        {
            if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
            {
                return;
            }

            var path = BaseDir.CreateFile("normal.txt");

            Assert.That(NativeUnix.SetFileMode(path, NativeUnix.UnixFilePermissions.None), Is.EqualTo(0));

            NativeUnix.UnixFilePermissions actual;
            Assert.That(NativeUnix.GetFileMode(path, out actual), Is.EqualTo(0));
            Assert.That(actual, Is.EqualTo(NativeUnix.UnixFilePermissions.None));

            Assert.That(NativeUnix.SetFileMode(path, permission), Is.EqualTo(0));

            Assert.That(NativeUnix.GetFileMode(path, out actual), Is.EqualTo(0));
            Assert.That(actual, Is.EqualTo(permission));
        }
            public void WhenSizeIsEqualNumber_ThenAssertTrue()
            {
                var file = BaseDir.CreateFile("SizeEquals-Test1.txt", "test1");

                Assert.DoesNotThrow(() => AssertFile.SizeEquals(file, 5));
            }
            public void WhenFileIsEmpty_ThenAssertTrue()
            {
                var file = BaseDir.CreateFile("SizeEquals-Test1.txt", string.Empty);

                Assert.DoesNotThrow(() => AssertFile.IsEmpty(file));
            }
            public void WhenFileIsNotEmpty_ThenAssertFalse()
            {
                var file = BaseDir.CreateFile("SizeEquals-Test1.txt", "A");

                Assert.Throws <AssertionException>(() => AssertFile.IsEmpty(file));
            }
            public void WhenSizeIsNotEqualNumber_ThenAssertFalse()
            {
                var file = BaseDir.CreateFile("SizeEquals-Test1.txt", "test1");

                Assert.Throws <AssertionException>(() => AssertFile.SizeEquals(file, 6));
            }
Example #21
0
            public void WhenDirectoryHasFiles_ThenAssertFalse()
            {
                BaseDir.CreateFile(Path.Combine(ExistingDirectory.FullName, "TestFile1.txt"));

                Assert.Throws <AssertionException>(() => AssertDir.IsEmpty(ExistingDirectory));
            }
Example #22
0
            public void WhenDirectoryHasFiles_ThenAssertFalse()
            {
                BaseDir.CreateFile("Test-HasNoFiles.txt");

                Assert.Throws <AssertionException>(() => AssertDir.HasNoFiles(ExistingDirectory));
            }