예제 #1
0
        public void IsDirectoryTest_NonExistantDirectory_ThrowsException()
        {
            // Given
            string   directoryPath = DexterCSTestUtil.TestingDirectory + @"\" + DexterCSTestUtil.RandomString();
            FileInfo fileInfo      = new FileInfo(directoryPath);

            // When
            bool result = DexterUtil.IsDirectory(fileInfo);

            // Then
            // FileNotFoundException is thrown
        }
예제 #2
0
        public void IsDirectoryTest_ExistingFile_ReturnsFalse()
        {
            try
            {
                // Given
                string filePath = DexterCSTestUtil.TestingDirectory + @"\" + DexterCSTestUtil.RandomString();
                File.Create(filePath).Close();
                FileInfo fileInfo = new FileInfo(filePath);

                // When
                bool result = DexterUtil.IsDirectory(fileInfo);

                // Then
                Assert.IsFalse(result);
            }
            finally
            {
                DexterCSTestUtil.ClearTestingDirectory();
            }
        }
예제 #3
0
        public void IsDirectoryTest_ExistingDirectory_ReturnsTrue()
        {
            try
            {
                // Given
                string directoryPath = DexterCSTestUtil.TestingDirectory + @"\" + DexterCSTestUtil.RandomString();
                Directory.CreateDirectory(directoryPath);
                FileInfo fileInfo = new FileInfo(directoryPath);

                // When
                bool result = DexterUtil.IsDirectory(fileInfo);

                // Then
                Assert.IsTrue(result);
            }
            finally
            {
                DexterCSTestUtil.ClearTestingDirectory();
            }
        }
예제 #4
0
        private static void SendResult(FileInfo resultFile, IDexterClient client)
        {
            if (DexterUtil.IsDirectory(resultFile) || !resultFile.Exists || resultFile.IsReadOnly)
            {
                throw new DexterRuntimeException("Cannot access result file (is not a directory or does not exist or is read-only: " + resultFile);
            }

            if (!DexterUtil.JSON_EXTENSION.Equals(resultFile.Extension) ||
                !resultFile.ToString().StartsWith("result_", StringComparison.Ordinal))
            {
                return;
            }
            try
            {
                client.SendAnalysisResult(File.ReadAllText(resultFile.FullName, Encoding.UTF8)).Wait();
            }
            catch (Exception e)
            {
                CliLog.Error(e.StackTrace);
            }
        }