// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; using System.Collections.Generic; using System.IO; using Microsoft.AspNet.FileProviders; using Microsoft.Framework.Expiration.Interfaces; namespace Microsoft.AspNet.Mvc.Razor { internal class TestFileProvider : IFileProvider { private readonly Dictionary _lookup = new Dictionary(StringComparer.Ordinal); private readonly Dictionary _fileTriggers = new Dictionary(StringComparer.Ordinal); public virtual IDirectoryContents GetDirectoryContents(string subpath) { throw new NotSupportedException(); } public void AddFile(string path, string contents) { var fileInfo = new TestFileInfo { Content = contents, PhysicalPath = path, Name = Path.GetFileName(path), LastModified = DateTime.UtcNow, }; AddFile(path, fileInfo); } public void AddFile(string path, IFileInfo contents) { _lookup[path] = contents; } public void DeleteFile(string path) { _lookup.Remove(path); } public virtual IFileInfo GetFileInfo(string subpath) { if (_lookup.ContainsKey(subpath)) { return _lookup[subpath]; } else { return new NotFoundFileInfo(subpath); } } public virtual IExpirationTrigger Watch(string filter) { TestFileTrigger trigger; if (!_fileTriggers.TryGetValue(filter, out trigger) || trigger.IsExpired) { trigger = new TestFileTrigger(); _fileTriggers[filter] = trigger; } return trigger; } public TestFileTrigger GetTrigger(string filter) { return _fileTriggers[filter]; } } }