public void TestAppConfigPath()
        {
            FileInfo fileInfo = ConfigFileLocator.GetFromAppConfigLocation("log4net_commonlibrary.config");

            Assert.NotNull(fileInfo);
            Assert.IsTrue(fileInfo.Exists);
        }
Example #2
0
        public void TestEncryptionBoundaryFileEncryptEmptyString()
        {
            const string toEncryptFile     = "encryption_test_commonlibrary.txt";
            FileInfo     toEncryptFileInfo = ConfigFileLocator.GetFromAppConfigLocation(toEncryptFile);

            EncryptionUtil.EncryptFile(toEncryptFileInfo, "");
        }
Example #3
0
        public void TestEncryptionBoundaryFileDecryptEmptyString()
        {
            const string toEncryptFile     = "encryption_test_commonlibrary.txt";
            FileInfo     toEncryptFileInfo = ConfigFileLocator.GetFromAppConfigLocation(toEncryptFile);

            const string toDecryptFile     = "post-decryption_test_commonlibrary.txt";
            FileInfo     decryptedFileInfo = new FileInfo(toEncryptFileInfo.DirectoryName + @"\" + toDecryptFile);

            EncryptionUtil.DecryptFile(decryptedFileInfo, "");
        }
Example #4
0
        public void TestDecryptFile()
        {
            TestEncryptFile();

            const string encryptedFile     = "encryption_corrupted_test_commonlibrary.txt";
            const string toDecryptFile     = "post-encryption_corrupted_test_commonlibrary.txt";
            FileInfo     encryptedFileInfo = ConfigFileLocator.GetFromAppConfigLocation(encryptedFile);

            FileInfo decryptedFileInfo = new FileInfo(encryptedFileInfo.DirectoryName + @"\" + toDecryptFile);

            EncryptionUtil.DecryptFile(encryptedFileInfo, decryptedFileInfo.FullName);
        }
        public void TestRelativePath()
        {
            const string fileName = "log4net_commonlibrary.config";

            FileInfo fileInfo = ConfigFileLocator.GetFromAppConfigLocation(fileName);

            Assert.NotNull(fileInfo);

            //Copy the config file to the subfolder
            {
                string sourcePath = fileInfo.DirectoryName;
                string targetPath = sourcePath + @"\Config";
                // To copy a folder's contents to a new location:
                // Create a new target folder, if necessary.
                if (!Directory.Exists(targetPath))
                {
                    Directory.CreateDirectory(targetPath);
                }

                // Use Path class to manipulate file and directory paths.
                {
                    string sourceFile = Path.Combine(sourcePath, fileName);
                    string destFile   = Path.Combine(targetPath, fileName);

                    // To copy a file to another location and
                    // overwrite the destination file if it already exists.
                    File.Copy(sourceFile, destFile, true);
                }
            }

            FileInfo configInfo = ConfigFileLocator.GetFromAppConfigLocation("Config", "log4net_commonlibrary.config");

            Assert.NotNull(configInfo);
            Assert.IsTrue(configInfo.Exists);

            configInfo = ConfigFileLocator.GetFromAppConfigLocation(@"\Config", "log4net_commonlibrary.config");
            Assert.NotNull(configInfo);
            Assert.IsTrue(configInfo.Exists);

            configInfo = ConfigFileLocator.GetFromAppConfigLocation(@"Config\", "log4net_commonlibrary.config");
            Assert.NotNull(configInfo);
            Assert.IsTrue(configInfo.Exists);

            configInfo = ConfigFileLocator.GetFromAppConfigLocation(@"\Config\", "log4net_commonlibrary.config");
            Assert.NotNull(configInfo);
            Assert.IsTrue(configInfo.Exists);
            Assert.AreEqual("log4net_commonlibrary.config", configInfo.Name);

            configInfo = ConfigFileLocator.GetFromAppConfigLocation(@"NonExist\", "log4net_commonlibrary.config");
            Assert.IsFalse(configInfo.Exists);
        }
Example #6
0
        public void TestEncryptFile()
        {
            const string toEncryptFile     = "encryption_test_commonlibrary.txt";
            const string encryptedFile     = "post-encryption_test_commonlibrary.txt";
            FileInfo     toEncryptFileInfo = ConfigFileLocator.GetFromAppConfigLocation(toEncryptFile);

            Assert.NotNull(toEncryptFileInfo);

            FileInfo encryptedFileInfo = new FileInfo(toEncryptFileInfo.DirectoryName + @"\" + encryptedFile);

            EncryptionUtil.EncryptFile(toEncryptFileInfo, encryptedFileInfo.FullName);

            Assert.IsTrue(encryptedFileInfo.Exists);
        }
 public void TestBoundary()
 {
     Assert.Throws <ArgumentNullException>(() => ConfigFileLocator.GetFromAppConfigLocation(""));
     Assert.Throws <ArgumentNullException>(() => ConfigFileLocator.GetFromAppConfigLocation("", "HelloWorld"));
     Assert.Throws <ArgumentNullException>(() => ConfigFileLocator.GetFromAppConfigLocation("HelloWorld", ""));
 }