forked from aspnet/AspNetWebStack
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTestFileSystem.cs
More file actions
53 lines (46 loc) · 1.56 KB
/
Copy pathTestFileSystem.cs
File metadata and controls
53 lines (46 loc) · 1.56 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System.Collections.Generic;
using System.IO;
using System.Linq;
using Microsoft.Internal.Web.Utils;
namespace System.Web.WebPages.Deployment.Test
{
public class TestFileSystem : IFileSystem
{
private readonly Dictionary<string, MemoryStream> _files = new Dictionary<string, MemoryStream>(StringComparer.OrdinalIgnoreCase);
public void AddFile(string file, MemoryStream content = null)
{
content = content ?? new MemoryStream();
_files[file] = content;
}
public bool FileExists(string path)
{
return _files.ContainsKey(path);
}
public Stream ReadFile(string path)
{
return _files[path];
}
public Stream OpenFile(string path)
{
MemoryStream memoryStream;
if (_files.TryGetValue(path, out memoryStream))
{
var copiedStream = new MemoryStream(memoryStream.ToArray());
_files[path] = copiedStream;
}
else
{
AddFile(path);
}
return _files[path];
}
public IEnumerable<string> EnumerateFiles(string path)
{
return from file in _files.Keys
where Path.GetDirectoryName(file).Equals(path, StringComparison.OrdinalIgnoreCase)
select file;
}
}
}