示例#1
0
        public void ArgumentExistsFileInfoTest()
        {
            var fileName = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData, Environment.SpecialFolderOption.DoNotVerify), "tempfileinfotest.dat");

            _ = RandomData.GenerateFile(fileName, 500);

            var tempFile = new FileInfo(fileName);

            try
            {
                tempFile.ArgumentExists();
            }
            catch
            {
                Assert.Fail();
            }

            FileInfo nullFileInfo = null;

            _ = Assert.ThrowsException <NullReferenceException>(() => nullFileInfo.ArgumentExists());

            _ = Assert.ThrowsException <FileNotFoundException>(() => new FileInfo("fakefile").ArgumentExists());

            tempFile.Delete();
        }
示例#2
0
        public void MoveFileTest01()
        {
            var file    = RandomData.GenerateFile(Path.Combine(Environment.GetEnvironmentVariable(EnvironmentKey.TEMP.ToString()), $"{RandomData.GenerateKey()}.test"));
            var newFile = Path.Combine(Path.Combine(_tempPath.ToString(), $"{RandomData.GenerateKey()}.moved"));

            FileHelper.MoveFile(file, newFile, FileMoveOptions.ReplaceExisting);
        }
示例#3
0
        public void GenerateFileTest()
        {
            var fileName = RandomData.GenerateFile(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData, Environment.SpecialFolderOption.DoNotVerify), "UnitTest.test"), fileLength: FileLength);

            Assert.IsNotNull(fileName);

            var testFile = new FileInfo(fileName);

            Assert.IsTrue(testFile.Exists);

            Assert.IsTrue(FileLength == testFile.Length);

            testFile.Delete();
        }
示例#4
0
        public void GenerateFileTest()
        {
            const int length   = _fileLength;
            var       fileName = RandomData.GenerateFile(@"c:\temp\UnitTest.test", fileLength: length);

            Assert.IsNotNull(fileName);

            var testFile = new FileInfo(fileName);

            Assert.IsTrue(testFile.Exists);

            Assert.IsTrue(length == testFile.Length);

            testFile.Delete();
        }
示例#5
0
        public void TryValidateParamFileInfoTest()
        {
            var fileName = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData, Environment.SpecialFolderOption.DoNotVerify), "tempfileinfotest.dat");

            _ = RandomData.GenerateFile(fileName, 500);

            var fileInfo = new FileInfo(fileName);

            try
            {
                Validate.TryValidateParam(fileInfo, "None");
            }
            catch
            {
                Assert.Fail();
            }

            FileInfo nullFileInfo = null;

            _ = Assert.ThrowsException <NullReferenceException>(() => Validate.TryValidateParam(nullFileInfo, "none"));

            _ = Assert.ThrowsException <FileNotFoundException>(() => Validate.TryValidateParam(new FileInfo("fakefile"), "none"));
        }
示例#6
0
        public void ArgumentExistsFileInfoWithDefaultTest()
        {
            var firstFileName = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData, Environment.SpecialFolderOption.DoNotVerify), "tempfileinfotest.dat1");
            var firstTempFile = new FileInfo(firstFileName);

            var secondFileName = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData, Environment.SpecialFolderOption.DoNotVerify), "tempfileinfotest.dat2");

            _ = RandomData.GenerateFile(secondFileName, 500);
            var secondTempFile = new FileInfo(secondFileName);

            try
            {
                var result = firstTempFile.ArgumentExists(secondTempFile);

                Assert.AreEqual(result, secondTempFile);
            }
            catch
            {
                Assert.Fail();
            }

            secondTempFile.Delete();
        }