public static IRouteTable AddFileRoute(this IRouteTable routeTable, string urlPath, string filename, Func<OwinRequest, object> modelProvider)
        {
            if (routeTable == null)
            {
                throw new ArgumentNullException("routeTable");
            }
            if (modelProvider == null)
            {
                throw new ArgumentNullException("modelProvider");
            }
            if (string.IsNullOrWhiteSpace(urlPath))
            {
                throw new ArgumentNullException("urlPath");
            }
            if (string.IsNullOrWhiteSpace(filename))
            {
                throw new ArgumentNullException("filename");
            }

            IFileInfo fileInfo;
            if (!routeTable.FileSystem.TryGetFileInfo(filename, out fileInfo))
            {
                throw new IOException(string.Format(CultureInfo.CurrentCulture, "File '{0}' was not found.", filename));
            }

            var handler = new SimpleRequestHandler(fileInfo, modelProvider);
            var route = new SingleFileRoute(urlPath, handler);

            return routeTable.AddRoute(route);
        }
 public void GetIdentity()
 {
     var file = new Mock<IFileInfo>();
     file.Setup(x => x.PhysicalPath).Returns("c:\\tmp\\template.cshtml");
     var handler = new SimpleRequestHandler(file.Object, x => "abc-def");
     handler.GetIdentity(new OwinRequest()).Should().Be("c:\\tmp\\template.cshtml");
 }
        public void GetTemplate()
        {
            var file = new Mock<IFileInfo>();
            var handler = new SimpleRequestHandler(file.Object, x => new object());

            using (var stream = new MemoryStream(Encoding.Default.GetBytes("The test template @Model.Name.")))
            {
                file.Setup(x => x.CreateReadStream()).Returns(stream);
                handler.GetTemplate(new OwinRequest()).Result.Should().Be("The test template @Model.Name.");
            }
        }
 public void GetModel()
 {
     var handler = new SimpleRequestHandler(new Mock<IFileInfo>().Object, x => "abc-def");
     handler.GetModel(new OwinRequest()).Result.Should().Be("abc-def");
 }