本文整理汇总了C#中TempFile类的典型用法代码示例。如果您正苦于以下问题:C# TempFile类的具体用法?C# TempFile怎么用?C# TempFile使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
TempFile类属于命名空间,在下文中一共展示了TempFile类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: op_Execute_IEnumerable
public void op_Execute_IEnumerable()
{
using (var file = new TempFile())
{
file.Info.AppendLine("CANONICAL,SYNONYMS");
file.Info.AppendLine("1,One");
file.Info.AppendLine("1,Unit");
var obj = new LexiconTidy
{
BuildEngine = new Mock<IBuildEngine>().Object,
Paths = new ITaskItem[]
{
new TaskItem(file.Info.FullName)
}
};
Assert.True(obj.Execute());
file.Info.Refresh();
Assert.True(file.Info.Exists);
Assert.True(File.ReadAllText(file.Info.FullName).Contains("1,One;Unit"));
}
}
示例2: ctor
public void ctor()
{
using (var file = new TempFile())
{
Assert.NotNull(file);
}
}
示例3: Process
public void Process(Crawler crawler, PropertyBag propertyBag)
{
if (propertyBag.StatusCode != HttpStatusCode.OK)
{
return;
}
string extension = MapContentTypeToExtension(propertyBag.ContentType);
if (extension.IsNullOrEmpty())
{
return;
}
propertyBag.Title = propertyBag.Step.Uri.PathAndQuery;
using (TempFile temp = new TempFile())
{
temp.FileName += "." + extension;
using (FileStream fs = new FileStream(temp.FileName, FileMode.Create, FileAccess.Write, FileShare.Read, 0x1000))
using (Stream input = propertyBag.GetResponse())
{
input.CopyToStream(fs);
}
using (FilterReader filterReader = new FilterReader(temp.FileName))
{
string content = filterReader.ReadToEnd();
propertyBag.Text = content.Trim();
}
}
}
示例4: op_Execute_IEnumerable
public void op_Execute_IEnumerable()
{
using (var file = new TempFile())
{
using (var resource = Assembly.GetExecutingAssembly().GetManifestResourceStream(@"Cavity.Build.MSBuildCompliance.xml"))
{
if (null != resource)
{
using (var reader = new StreamReader(resource))
{
file.Info.Append(reader.ReadToEnd());
}
}
}
var obj = new MSBuildCompliance
{
BuildEngine = new Mock<IBuildEngine>().Object,
Projects = new ITaskItem[]
{
new TaskItem(file.Info.FullName)
},
XPath = "0=count(/b:Project/b:PropertyGroup[@Condition][not(b:WarningLevel[text()='4'])])"
};
Assert.True(obj.Execute());
}
}
示例5: BothModifiedExampleFormTextWorksWithConflict
public void BothModifiedExampleFormTextWorksWithConflict()
{
const string ancestor = @"<?xml version='1.0' encoding='utf-8'?>
<lift version='0.10' producer='WeSay 1.0.0.0'>
<entry id='test' guid='F169EB3D-16F2-4eb0-91AA-FDB91636F8F6'>
<sense id='123'>
<example>
<form lang='chorus'>
<text>This is my example sentence.</text>
</form>
</example>
</sense>
</entry>
</lift>";
var ours = ancestor.Replace(@"This is my example", @"This was your example");
var theirs = ancestor.Replace(@"This is my example", @"It's mine don't touch it.");
using (var oursTemp = new TempFile(ours))
using (var theirsTemp = new TempFile(theirs))
using (var ancestorTemp = new TempFile(ancestor))
{
var listener = new ListenerForUnitTests();
var situation = new NullMergeSituation();
var mergeOrder = new MergeOrder(oursTemp.Path, ancestorTemp.Path, theirsTemp.Path, situation) { EventListener = listener };
XmlMergeService.Do3WayMerge(mergeOrder, new LiftEntryMergingStrategy(mergeOrder),
false,
"header",
"entry", "guid");
var result = File.ReadAllText(mergeOrder.pathToOurs);
Assert.AreEqual(1, listener.Conflicts.Count);
var warning = listener.Conflicts[0];
Assert.AreEqual(typeof(XmlTextBothEditedTextConflict), warning.GetType(), warning.ToString());
XmlTestHelper.AssertXPathMatchesExactlyOne(result, "//example/form");
}
}
示例6: ctor_FileInfo
public void ctor_FileInfo()
{
using (var temp = new TempFile())
{
Assert.NotNull(new TsvDataFile(temp.Info));
}
}
示例7: InvalidArguments_Mode
public void InvalidArguments_Mode()
{
// FileMode out of range
Assert.Throws<ArgumentOutOfRangeException>("mode", () => MemoryMappedFile.CreateFromFile(GetTestFilePath(), (FileMode)42));
Assert.Throws<ArgumentOutOfRangeException>("mode", () => MemoryMappedFile.CreateFromFile(GetTestFilePath(), (FileMode)42, null));
Assert.Throws<ArgumentOutOfRangeException>("mode", () => MemoryMappedFile.CreateFromFile(GetTestFilePath(), (FileMode)42, null, 4096));
Assert.Throws<ArgumentOutOfRangeException>("mode", () => MemoryMappedFile.CreateFromFile(GetTestFilePath(), (FileMode)42, null, 4096, MemoryMappedFileAccess.ReadWrite));
// FileMode.Append never allowed
Assert.Throws<ArgumentException>("mode", () => MemoryMappedFile.CreateFromFile(GetTestFilePath(), FileMode.Append));
Assert.Throws<ArgumentException>("mode", () => MemoryMappedFile.CreateFromFile(GetTestFilePath(), FileMode.Append, null));
Assert.Throws<ArgumentException>("mode", () => MemoryMappedFile.CreateFromFile(GetTestFilePath(), FileMode.Append, null, 4096));
Assert.Throws<ArgumentException>("mode", () => MemoryMappedFile.CreateFromFile(GetTestFilePath(), FileMode.Append, null, 4096, MemoryMappedFileAccess.ReadWrite));
// FileMode.CreateNew/Create/OpenOrCreate can't be used with default capacity, as the file will be empty
Assert.Throws<ArgumentException>(() => MemoryMappedFile.CreateFromFile(GetTestFilePath(), FileMode.CreateNew));
Assert.Throws<ArgumentException>(() => MemoryMappedFile.CreateFromFile(GetTestFilePath(), FileMode.Create));
Assert.Throws<ArgumentException>(() => MemoryMappedFile.CreateFromFile(GetTestFilePath(), FileMode.OpenOrCreate));
// FileMode.Truncate can't be used with default capacity, as resulting file will be empty
using (TempFile file = new TempFile(GetTestFilePath()))
{
Assert.Throws<ArgumentException>(() => MemoryMappedFile.CreateFromFile(file.Path, FileMode.Truncate));
}
}
示例8: ClickAllControlsOnPage_UsingReflection_Succeeds
public void ClickAllControlsOnPage_UsingReflection_Succeeds()
{
//Arrange
using (TempFile tempFile = new TempFile(
@"<html>
<head>
<title>test</title>
</head>
<body>
<a href=""#"">test</a>
<button>test</button>
<input type=""text"" value=""test""/>
</body>
</html>"))
{
BrowserWindow.Launch(tempFile.FilePath);
var window = new BrowserWindowUnderTest("test");
IControlBase a = window.Get<HtmlHyperlink>("InnerText=test");
a.Click();
List<Type> list = new List<Type>();
list.Add(typeof(HtmlHyperlink));
list.Add(typeof(HtmlButton));
list.Add(typeof(HtmlEdit));
MethodInfo getMethodInfo = typeof(BrowserWindowUnderTest).GetMethod("Get");
foreach(Type t in list)
{
MethodInfo test = getMethodInfo.MakeGenericMethod(t);
IControlBase control;
if ((t == typeof(HtmlEdit)) || (t == typeof(HtmlTextArea)))
{
control = (IControlBase)test.Invoke(window, new object[] { "Value=test" });
}
else
{
//window.Get<t>("InnerText=test");
control = (IControlBase)test.Invoke(window, new object[] { "InnerText=test" });
}
//Act
control.Click();
if (control is HtmlEdit)
{
(control as HtmlEdit).SetText("text");
}
else if (control is HtmlTextArea)
{
(control as HtmlTextArea).SetText("text");
}
}
window.Close();
}
}
示例9: ChorusNotesMergeEventListener
public ChorusNotesMergeEventListener(string path)
{
_path = path;
try
{
if (!File.Exists(path))
{
var doc = new XmlDocument();
doc.LoadXml(string.Format("<notes version='{0}'/>", FormatVersionNumber.ToString()));
using (var fileWriter = XmlWriter.Create(path, CanonicalXmlSettings.CreateXmlWriterSettings()))
{
doc.Save(fileWriter);
}
}
}
catch (Exception error)
{
Debug.Fail("Something went wrong trying to create a blank ChorusNotes file :"+error.Message);
//todo log that the xml was the wrong format
}
_tempFile = new TempFile();
_readerStream = new FileStream(path, FileMode.Open);
_reader = XmlReader.Create(_readerStream, CanonicalXmlSettings.CreateXmlReaderSettings());
_writer = XmlWriter.Create(_tempFile.Path, CanonicalXmlSettings.CreateXmlWriterSettings());
StreamToInsertionPoint(_reader, _writer);
}
示例10: TestTransactionLogOptions
public void TestTransactionLogOptions()
{
using (TempFile temp = new TempFile())
{
temp.Delete();
var opt = new TransactionLogOptions<int, string>(temp.TempPath,
PrimitiveSerializer.Int32,
PrimitiveSerializer.String);
//FileName
Assert.AreEqual(temp.TempPath, opt.FileName);
//Key/Value serializers
Assert.IsTrue(ReferenceEquals(opt.KeySerializer, PrimitiveSerializer.Int32));
Assert.IsTrue(ReferenceEquals(opt.ValueSerializer, PrimitiveSerializer.String));
//FileOptions
Assert.AreEqual(FileOptions.WriteThrough, opt.FileOptions);
Assert.AreEqual(FileOptions.WriteThrough | FileOptions.Asynchronous, opt.FileOptions |= FileOptions.Asynchronous);
//Read Only
Assert.AreEqual(false, opt.ReadOnly);
Assert.AreEqual(true, opt.ReadOnly = true);
//File Buffer
Assert.AreEqual(8, opt.FileBuffer);
Assert.AreEqual(0x40000, opt.FileBuffer = 0x40000);
//Clone
Assert.IsFalse(ReferenceEquals(opt, opt.Clone()));
using(TransactionLog<int, string> log = new TransactionLog<int,string>(opt))
Assert.AreEqual(0, log.Size);
}
}
示例11: ctor_FileInfo
public void ctor_FileInfo()
{
using (var file = new TempFile())
{
Assert.NotNull(new CsvLexiconStorage(file.Info));
}
}
示例12: ctor_string
public void ctor_string()
{
using (var temp = new TempFile())
{
Assert.NotNull(new TsvDataSheet(temp.Info.FullName));
}
}
示例13: SaveLoadTest
public void SaveLoadTest()
{
using (var tempFile = new TempFile(_xml))
{
Assert.Throws<ApplicationException>(() =>
{
FishSettingsBase.Load(tempFile.Name, "badName");
});
var settings = FishSettingsBase.Load(tempFile.Name, "name0");
Assert.AreEqual("name0", settings.Name);
Assert.AreEqual("version0", settings.Version);
Assert.IsInstanceOf<System.Int32>(settings["a"]);
Assert.AreEqual(typeof(System.Int32), settings.GetType_TESTONLY("a"));
Assert.AreEqual(2, settings["a"]);
Assert.AreEqual(1, settings.GetDefaultValue("a"));
Assert.IsInstanceOf<int[]>(settings["b"]);
Assert.AreEqual(typeof(int[]), settings.GetType_TESTONLY("b"));
CollectionAssert.AreEqual(new [] { 3, 4, 5 }, (int[])settings["b"]);
CollectionAssert.AreEqual(new [] { 1, 2 }, (int[])settings.GetDefaultValue("b"));
using (var tempFile2 = new TempFile())
{
settings.Save(tempFile2.Name);
Assert.AreEqual(tempFile.Text, tempFile2.Text);
FileAssert.AreEqual(tempFile.Name, tempFile2.Name);
}
}
}
示例14: ctor_FileInfo
public void ctor_FileInfo()
{
using (var temp = new TempFile())
{
Assert.NotNull(new ExcelWorksheet(temp.Info));
}
}
示例15: LoadingAndSavingTest
public void LoadingAndSavingTest()
{
var text = @"version = 1.1
document
{
prop1 = a
obj1
{
prop2 = b
obj2
{
prop3 = c
}
}
}
";
using (var tempFile = new TempFile(text))
{
var doc = FishDocument.Load(tempFile.Name);
using (var savedFile = new TempFile())
{
doc.Save(savedFile.Name);
// TestUtility.CompareWithWinMerge(tempFile.Name, savedFile.Name);
FileAssert.AreEqual(tempFile.Name, savedFile.Name);
}
}
}