本文整理汇总了C#中TempDirectory类的典型用法代码示例。如果您正苦于以下问题:C# TempDirectory类的具体用法?C# TempDirectory怎么用?C# TempDirectory使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
TempDirectory类属于命名空间,在下文中一共展示了TempDirectory类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ItPersistsArgumentsInFile
public void ItPersistsArgumentsInFile(
string containerDirectory, string machineIp, string syslogHostIp, string syslogPort, string machineName)
{
using(var tempDirectory = new TempDirectory())
{
var configurationManager = new ConfigurationManagerTest();
var context = new InstallContext();
context.Parameters.Add("CONTAINER_DIRECTORY", containerDirectory);
context.Parameters.Add("MACHINE_IP", machineIp);
context.Parameters.Add("SYSLOG_HOST_IP", syslogHostIp);
context.Parameters.Add("SYSLOG_PORT", syslogPort);
context.Parameters.Add("assemblypath", tempDirectory.ToString());
context.Parameters.Add("MACHINE_NAME", machineName);
configurationManager.Context = context;
configurationManager.OnBeforeInstall(null);
var javaScriptSerializer = new System.Web.Script.Serialization.JavaScriptSerializer();
var jsonString = File.ReadAllText(Path.Combine(tempDirectory.ToString(), @"..\parameters.json"));
var hash = javaScriptSerializer.Deserialize<Dictionary<string, string>>(jsonString);
Assert.Equal(hash["CONTAINER_DIRECTORY"], containerDirectory);
Assert.Equal(hash["MACHINE_IP"], machineIp);
Assert.Equal(hash["SYSLOG_HOST_IP"], syslogHostIp);
Assert.Equal(hash["SYSLOG_PORT"], syslogPort);
Assert.Equal(hash["MACHINE_NAME"], machineName);
}
}
示例2: ctor
public void ctor()
{
using (var directory = new TempDirectory())
{
Assert.NotNull(directory);
}
}
示例3: BundleCollectionCache_Write_Tests
public BundleCollectionCache_Write_Tests()
{
path = new TempDirectory();
directory = new FileSystemDirectory(path);
var bundles = new BundleCollection(new CassetteSettings(), Mock.Of<IFileSearchProvider>(), Mock.Of<IBundleFactoryProvider>());
scriptBundle = new Mock<ScriptBundle>("~/test1");
scriptBundle.CallBase = true;
scriptBundle.Object.Hash = new byte[] { 1, 2, 3 };
scriptBundle.Object.Assets.Add(new StubAsset("~/test/asset.js", "script-bundle-content"));
scriptBundle.Object.Renderer = new ScriptBundleHtmlRenderer(Mock.Of<IUrlGenerator>());
scriptBundle.Setup(b => b.Render()).Returns("");
bundles.Add(scriptBundle.Object);
stylesheetBundle = new Mock<StylesheetBundle>("~/test2");
stylesheetBundle.CallBase = true;
stylesheetBundle.Object.Hash = new byte[] { 4, 5, 6 };
stylesheetBundle.Object.Assets.Add(new StubAsset("~/test2/asset.css", "stylesheet-bundle-content"));
stylesheetBundle.Object.Renderer = new StylesheetHtmlRenderer(Mock.Of<IUrlGenerator>());
stylesheetBundle.Setup(b => b.Render()).Returns("");
bundles.Add(stylesheetBundle.Object);
var cache = new BundleCollectionCache(directory, b => null);
cache.Write(new Manifest(bundles, "VERSION"));
}
示例4: ctor_DirectoryInfo_bool
public void ctor_DirectoryInfo_bool()
{
using (var temp = new TempDirectory())
{
Assert.NotNull(new DirectoryCreateCommand(temp.Info, true));
}
}
示例5: SetUp
public void SetUp()
{
kernel = new StandardKernel();
tmp = new TempDirectory();
rootDir = new LocalFileSystemDirectory(tmp);
using (var writer = rootDir.CreateTextFile("file1"))
writer.WriteLine("Contents of file 1");
using (var writer = rootDir.CreateTextFile("file2"))
writer.WriteLine("Contents of file 2");
using (var writer = rootDir.CreateTextFile("file3"))
writer.WriteLine("Contents of file 3");
sourceSet1 = new SourceSet("test1");
sourceSet1.Add(new SuiteRelativePath("file1"));
sourceSet1.Add(new SuiteRelativePath("file2"));
sourceSet2 = new SourceSet("test2");
sourceSet2.Add(new SuiteRelativePath("file1"));
sourceSet2.Add(new SuiteRelativePath("file3"));
kernel.Bind<IFileSystemDirectory>().ToConstant(rootDir).WhenTargetHas<SuiteRootAttribute>();
var factoryMock = new Mock<ISourceSetFingerprintFactory>();
factoryMock.Setup(
f =>
f.CreateSourceSetFingerprint(It.IsAny<IEnumerable<SuiteRelativePath>>(), It.IsAny<Func<string, bool>>(), It.IsAny<bool>()))
.Returns<IEnumerable<SuiteRelativePath>, Func<string, bool>, bool>(
(files, exclusions, fullDependency) => new SourceSetFingerprint(rootDir, files, exclusions, fullDependency));
fingerprintFactory = factoryMock.Object;
}
示例6: CreateCSharpAnalyzerAssemblyWithTestAnalyzer
public static TempFile CreateCSharpAnalyzerAssemblyWithTestAnalyzer(TempDirectory dir, string assemblyName)
{
var analyzerSource = @"
using System;
using System.Collections.Immutable;
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.Diagnostics;
[DiagnosticAnalyzer(LanguageNames.CSharp)]
public class TestAnalyzer : DiagnosticAnalyzer
{
public override ImmutableArray<DiagnosticDescriptor> SupportedDiagnostics { get { throw new NotImplementedException(); } }
public override void Initialize(AnalysisContext context) { throw new NotImplementedException(); }
}";
dir.CopyFile(typeof(System.Reflection.Metadata.MetadataReader).Assembly.Location);
var immutable = dir.CopyFile(typeof(ImmutableArray).Assembly.Location);
var analyzer = dir.CopyFile(typeof(DiagnosticAnalyzer).Assembly.Location);
dir.CopyFile(Path.Combine(Path.GetDirectoryName(typeof(CSharpCompilation).Assembly.Location), "System.IO.FileSystem.dll"));
var analyzerCompilation = CSharpCompilation.Create(
assemblyName,
new SyntaxTree[] { SyntaxFactory.ParseSyntaxTree(analyzerSource) },
new MetadataReference[]
{
TestReferences.NetStandard13.SystemRuntime,
MetadataReference.CreateFromFile(immutable.Path),
MetadataReference.CreateFromFile(analyzer.Path)
},
new CSharpCompilationOptions(OutputKind.DynamicallyLinkedLibrary));
return dir.CreateFile(assemblyName + ".dll").WriteAllBytes(analyzerCompilation.EmitToArray());
}
示例7: transaction_Complete
public void transaction_Complete()
{
try
{
using (var temp = new TempDirectory())
{
var path = temp.Info.ToDirectory("example").FullName;
Recovery.MasterDirectory = temp.Info.ToDirectory("Recovery");
using (var scope = new TransactionScope())
{
var obj = new DerivedDurableEnlistmentNotification(Guid.NewGuid(), EnlistmentOptions.None);
obj.Operation.Commands.Add(new DirectoryCreateCommand(path));
scope.Complete();
}
Assert.True(new DirectoryInfo(path).Exists);
Thread.Sleep(1000);
}
}
finally
{
Recovery.MasterDirectory = null;
}
}
示例8: op_Run_DirectoryInfo_TextWriter
public void op_Run_DirectoryInfo_TextWriter()
{
using (var temp = new TempDirectory())
{
var log = temp.Info.ToFile("log.txt");
using (var stream = File.Open(log.FullName, FileMode.CreateNew, FileAccess.Write, FileShare.Read))
{
using (var writer = new StreamWriter(stream))
{
var mock = new Mock<IRunTest>();
// ReSharper disable AccessToDisposedClosure
mock
.Setup(x => x.Run(temp.Info, writer))
.Returns(true)
.Verifiable();
// ReSharper restore AccessToDisposedClosure
Assert.True(mock.Object.Run(temp.Info, writer));
mock.VerifyAll();
}
}
}
}
示例9: FileSystemWatchingBundleRebuilder_Tests
public FileSystemWatchingBundleRebuilder_Tests()
{
tempDirectory = new TempDirectory();
Directory.CreateDirectory(Path.Combine(tempDirectory, "cache"));
var settings = new CassetteSettings
{
SourceDirectory = new FileSystemDirectory(tempDirectory),
CacheDirectory = new FileSystemDirectory(Path.Combine(tempDirectory, "cache")),
IsFileSystemWatchingEnabled = true
};
bundles = new BundleCollection(settings, Mock.Of<IFileSearchProvider>(), Mock.Of<IBundleFactoryProvider>());
bundleConfiguration = new Mock<IConfiguration<BundleCollection>>();
var bundle = new TestableBundle("~");
var asset1 = new StubAsset("~/test.js");
var asset2 = new StubAsset("~/sub/test2.js");
asset1.AddRawFileReference("~/image.png");
bundle.Assets.Add(asset1);
bundle.Assets.Add(asset2);
bundles.Add(bundle);
fileSearch = new Mock<IFileSearch>();
fileSearch
.Setup(s => s.IsMatch(It.IsAny<string>()))
.Returns<string>(path => path.EndsWith(".js"));
var initializer = new BundleCollectionInitializer(new[] { bundleConfiguration.Object }, new ExternalBundleGenerator(Mock.Of<IBundleFactoryProvider>(), settings));
rebuilder = new FileSystemWatchingBundleRebuilder(settings, bundles, initializer, new[] { fileSearch.Object });
}
示例10: ctor_DirectoryInfo
public void ctor_DirectoryInfo()
{
using (var directory = new TempDirectory(new DirectoryInfo("C:\\").Root))
{
Assert.NotNull(directory);
}
}
示例11: ctor_string_bool
public void ctor_string_bool()
{
using (var temp = new TempDirectory())
{
Assert.NotNull(new DirectoryCreateCommand(temp.Info.FullName, true));
}
}
示例12: op_Do
public void op_Do()
{
try
{
using (var temp = new TempDirectory())
{
Recovery.MasterDirectory = temp.Info.ToDirectory("Recovery");
var path1 = temp.Info.ToDirectory("1").FullName;
var path2 = temp.Info.ToDirectory("2").FullName;
var obj = new Operation(Guid.NewGuid())
{
Info = Guid.NewGuid().ToString()
};
obj.Commands.Add(new DirectoryCreateCommand(path1));
obj.Commands.Add(new DirectoryCreateCommand(path2));
Assert.True(obj.Do());
Assert.True(new DirectoryInfo(path1).Exists);
Assert.True(new DirectoryInfo(path2).Exists);
}
}
finally
{
Recovery.MasterDirectory = null;
}
}
示例13: CopyProjectToTempDir
private void CopyProjectToTempDir(string projectDir, TempDirectory tempDir)
{
foreach (var file in Directory.EnumerateFiles(projectDir))
{
tempDir.CopyFile(file);
}
}
示例14: FileSystemWatcher_Directory_Delete_DeepDirectoryStructure
public void FileSystemWatcher_Directory_Delete_DeepDirectoryStructure()
{
// List of created directories
List<TempDirectory> lst = new List<TempDirectory>();
using (var testDirectory = new TempDirectory(GetTestFilePath()))
using (var dir = new TempDirectory(Path.Combine(testDirectory.Path, "dir")))
using (var watcher = new FileSystemWatcher(dir.Path, "*"))
{
watcher.IncludeSubdirectories = true;
watcher.NotifyFilter = NotifyFilters.DirectoryName;
// Priming directory
lst.Add(new TempDirectory(Path.Combine(dir.Path, "dir")));
// Create a deep directory structure and expect things to work
for (int i = 1; i < 20; i++)
{
// Test that the creation triggers an event correctly
string dirPath = Path.Combine(lst[i - 1].Path, String.Format("dir{0}", i));
Action action = () => Directory.Delete(dirPath);
Action cleanup = () => Directory.CreateDirectory(dirPath);
cleanup();
ExpectEvent(watcher, WatcherChangeTypes.Deleted, action, cleanup);
// Create the directory so subdirectories may be created from it.
lst.Add(new TempDirectory(dirPath));
}
}
}
示例15: FileSystemWatcher_File_NotifyFilter_Attributes
public void FileSystemWatcher_File_NotifyFilter_Attributes(NotifyFilters filter)
{
using (var testDirectory = new TempDirectory(GetTestFilePath()))
using (var file = new TempFile(Path.Combine(testDirectory.Path, "file")))
using (var watcher = new FileSystemWatcher(testDirectory.Path, Path.GetFileName(file.Path)))
{
watcher.NotifyFilter = filter;
var attributes = File.GetAttributes(file.Path);
Action action = () => File.SetAttributes(file.Path, attributes | FileAttributes.ReadOnly);
Action cleanup = () => File.SetAttributes(file.Path, attributes);
WatcherChangeTypes expected = 0;
if (filter == NotifyFilters.Attributes)
expected |= WatcherChangeTypes.Changed;
else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux) && ((filter & LinuxFiltersForAttribute) > 0))
expected |= WatcherChangeTypes.Changed;
else if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX) && ((filter & OSXFiltersForModify) > 0))
expected |= WatcherChangeTypes.Changed;
else if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX) && ((filter & NotifyFilters.Security) > 0))
expected |= WatcherChangeTypes.Changed; // Attribute change on OSX is a ChangeOwner operation which passes the Security NotifyFilter.
ExpectEvent(watcher, expected, action, cleanup, file.Path);
}
}