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


C# MockFile.Create方法代码示例

本文整理汇总了C#中MockFile.Create方法的典型用法代码示例。如果您正苦于以下问题:C# MockFile.Create方法的具体用法?C# MockFile.Create怎么用?C# MockFile.Create使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在MockFile的用法示例。


在下文中一共展示了MockFile.Create方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Mockfile_Create_OverwritesExistingFile

        public void Mockfile_Create_OverwritesExistingFile()
        {
            string path = XFS.Path(@"c:\some\file.txt");
            var fileSystem = new MockFileSystem();

            var mockFile = new MockFile(fileSystem);

            fileSystem.Directory.CreateDirectory(Path.GetDirectoryName(path));

            // Create a file
            using (var stream = mockFile.Create(path))
            {
                var contents = new UTF8Encoding(false).GetBytes("Test 1");
                stream.Write(contents, 0, contents.Length);
            }

            // Create new file that should overwrite existing file
            var expectedContents = new UTF8Encoding(false).GetBytes("Test 2");
            using (var stream = mockFile.Create(path))
            {
                stream.Write(expectedContents, 0, expectedContents.Length);
            }

            var actualContents = fileSystem.GetFile(path).Contents;

            Assert.That(actualContents, Is.EqualTo(expectedContents));
        }
开发者ID:BrianLanghoor,项目名称:System.IO.Abstractions,代码行数:27,代码来源:MockFileCreateTests.cs

示例2: Mockfile_Create_ThrowsWhenPathIsReadOnly

 public void Mockfile_Create_ThrowsWhenPathIsReadOnly()
 {
     string path = XFS.Path(@"c:\something\read-only.txt");
     var fileSystem = new MockFileSystem(new Dictionary<string, MockFileData> { { path, new MockFileData("Content") } });
     var mockFile = new MockFile(fileSystem);
     
     mockFile.SetAttributes(path, FileAttributes.ReadOnly);
  
     var exception =  Assert.Throws<UnauthorizedAccessException>(() => mockFile.Create(path).Close());
     Assert.That(exception.Message, Is.EqualTo(string.Format(CultureInfo.InvariantCulture, "Access to the path '{0}' is denied.", path)));
 }
开发者ID:wafe,项目名称:System.IO.Abstractions,代码行数:11,代码来源:MockFileCreateTests.cs

示例3: Mockfile_Create_ShouldCreateNewStream

        public void Mockfile_Create_ShouldCreateNewStream()
        {
            string fullPath = XFS.Path(@"c:\something\demo.txt");
            var fileSystem = new MockFileSystem();

            var sut = new MockFile(fileSystem);

            Assert.That(fileSystem.FileExists(fullPath), Is.False);

            sut.Create(fullPath).Close();

            Assert.That(fileSystem.FileExists(fullPath), Is.True);
        }
开发者ID:wafe,项目名称:System.IO.Abstractions,代码行数:13,代码来源:MockFileCreateTests.cs

示例4: Mockfile_Create_CanWriteToNewStream

        public void Mockfile_Create_CanWriteToNewStream()
        {
            string fullPath = XFS.Path(@"c:\something\demo.txt");
            var fileSystem = new MockFileSystem();
            var data = new UTF8Encoding(false).GetBytes("Test string");

            var sut = new MockFile(fileSystem);
            using (var stream = sut.Create(fullPath))
            {
                stream.Write(data, 0, data.Length);
            }

            var mockFileData = fileSystem.GetFile(fullPath);
            var fileData = mockFileData.Contents;

            Assert.That(fileData, Is.EqualTo(data));
        }
开发者ID:wafe,项目名称:System.IO.Abstractions,代码行数:17,代码来源:MockFileCreateTests.cs

示例5: Mockfile_Create_ShouldCreateNewStream

        public void Mockfile_Create_ShouldCreateNewStream()
        {
            const string fullPath = @"c:\something\demo.txt";
            var fileSystem = new MockFileSystem(new Dictionary<string, MockFileData>());

            var sut = new MockFile(fileSystem);

            Assert.That(fileSystem.FileExists(fullPath), Is.False);

            sut.Create(fullPath).Close();

            Assert.That(fileSystem.FileExists(fullPath), Is.True);
        }
开发者ID:parshim,项目名称:System.IO.Abstractions,代码行数:13,代码来源:MockFileTests.cs


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