コード例 #1
0
 public static TestFile FromEmbeddedResource(Assembly testAssembly, string resourceNamespace, string fileName)
 {
     var deploymentDirectory = GetAssemblyDirectoryName(testAssembly);
     var deployedFile = new TestFile(deploymentDirectory, fileName);
     SaveEmbeddedResource(testAssembly, resourceNamespace, deployedFile);
     return deployedFile;
 }
コード例 #2
0
        private static void SaveEmbeddedResource(Assembly testAssembly, string resourceNamespace, TestFile testFile)
        {
            var resourceName = string.Format("{0}.{1}", resourceNamespace, testFile.Name);
            var manifestResourceStream = testAssembly.GetManifestResourceStream(resourceName);

            if (manifestResourceStream == null)
            {
                throw new ArgumentNullException(resourceName, "Unable to locate resource");
            }

            using (var fileStream = new FileStream(testFile.FullName, FileMode.Create, FileAccess.Write))
            {
                manifestResourceStream.CopyTo(fileStream);
            }
        }
コード例 #3
0
 public virtual void ReplaceWith(TestFile file)
 {
     ReplaceFile(file.FullName, FullName);
 }
コード例 #4
0
 public void InvokeWithReplacement(TestFile replacement, Action action)
 {
     Backup();
     try
     {
         ReplaceWith(replacement);
         action();
     }
     finally
     {
         Restore();
     }
 }
コード例 #5
0
 public virtual void ReplaceWith(TestFile file)
 {
     ReplaceFile(file.FullName, FullName);
 }
コード例 #6
0
        private static void SaveEmbeddedResource(Assembly testAssembly, string resourceNamespace, TestFile testFile)
        {
            var resourceName           = string.Format("{0}.{1}", resourceNamespace, testFile.Name);
            var manifestResourceStream = testAssembly.GetManifestResourceStream(resourceName);

            if (manifestResourceStream == null)
            {
                throw new ArgumentNullException(resourceName, "Unable to locate resource");
            }

            using (var fileStream = new FileStream(testFile.FullName, FileMode.Create, FileAccess.Write))
            {
                manifestResourceStream.CopyTo(fileStream);
            }
        }