当前位置: 首页>>代码示例>>C#>>正文


C# TempFile类代码示例

本文整理汇总了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"));
            }
        }
开发者ID:KarlDirck,项目名称:cavity,代码行数:25,代码来源:LexiconTidy.Facts.cs

示例2: ctor

 public void ctor()
 {
     using (var file = new TempFile())
     {
         Assert.NotNull(file);
     }
 }
开发者ID:KarlDirck,项目名称:cavity,代码行数:7,代码来源:TempFile.Facts.cs

示例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();
				}
			}
		}
开发者ID:senzacionale,项目名称:ncrawler,代码行数:30,代码来源:IFilterProcessor.cs

示例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());
            }
        }
开发者ID:KarlDirck,项目名称:cavity,代码行数:28,代码来源:MSBuildCompliance.Facts.cs

示例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");
            }
        }
开发者ID:JessieGriffin,项目名称:chorus,代码行数:35,代码来源:ExampleSentenceMergingTests.cs

示例6: ctor_FileInfo

 public void ctor_FileInfo()
 {
     using (var temp = new TempFile())
     {
         Assert.NotNull(new TsvDataFile(temp.Info));
     }
 }
开发者ID:KarlDirck,项目名称:cavity,代码行数:7,代码来源:TsvDataFile.Facts.cs

示例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));
            }
        }
开发者ID:er0dr1guez,项目名称:corefx,代码行数:25,代码来源:MemoryMappedFile.CreateFromFile.Tests.cs

示例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();
            }
        }
开发者ID:umakanthk,项目名称:cuite,代码行数:60,代码来源:HtmlControlTests.cs

示例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);
        }
开发者ID:JessieGriffin,项目名称:chorus,代码行数:28,代码来源:ChorusNotesMergeEventListener.cs

示例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);
            }
        }
开发者ID:langimike,项目名称:CSharpTest.Net.Collections,代码行数:29,代码来源:TestTransactionLog.cs

示例11: ctor_FileInfo

 public void ctor_FileInfo()
 {
     using (var file = new TempFile())
     {
         Assert.NotNull(new CsvLexiconStorage(file.Info));
     }
 }
开发者ID:KarlDirck,项目名称:cavity,代码行数:7,代码来源:CsvLexiconStorage.Facts.cs

示例12: ctor_string

 public void ctor_string()
 {
     using (var temp = new TempFile())
     {
         Assert.NotNull(new TsvDataSheet(temp.Info.FullName));
     }
 }
开发者ID:KarlDirck,项目名称:cavity,代码行数:7,代码来源:TsvDataSheet.Facts.cs

示例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);
                }
            }
        }
开发者ID:kaijin-games,项目名称:larning-english-game,代码行数:30,代码来源:FishSettingsBase.test.cs

示例14: ctor_FileInfo

 public void ctor_FileInfo()
 {
     using (var temp = new TempFile())
     {
         Assert.NotNull(new ExcelWorksheet(temp.Info));
     }
 }
开发者ID:KarlDirck,项目名称:cavity,代码行数:7,代码来源:ExcelWorksheet.Facts.cs

示例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);
         }
     }
 }
开发者ID:kaijin-games,项目名称:larning-english-game,代码行数:27,代码来源:FishDocument.test.cs


注:本文中的TempFile类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。