Skip to content
This repository has been archived by the owner on Dec 14, 2018. It is now read-only.

Commit

Permalink
Remove IDisposable contract from IMvcRazorHost
Browse files Browse the repository at this point in the history
Fixes #4709
  • Loading branch information
pranavkm committed May 25, 2016
1 parent 3d0f436 commit 9acd0f5
Show file tree
Hide file tree
Showing 4 changed files with 372 additions and 396 deletions.
3 changes: 1 addition & 2 deletions src/Microsoft.AspNetCore.Mvc.Razor.Host/IMvcRazorHost.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// 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;
using System.IO;
using Microsoft.AspNetCore.Razor.CodeGenerators;

Expand All @@ -10,7 +9,7 @@ namespace Microsoft.AspNetCore.Mvc.Razor
/// <summary>
/// Specifies the contracts for a Razor host that parses Razor files and generates C# code.
/// </summary>
public interface IMvcRazorHost : IDisposable
public interface IMvcRazorHost
{
/// <summary>
/// Parses and generates the contents of a Razor file represented by <paramref name="inputStream"/>.
Expand Down
6 changes: 0 additions & 6 deletions src/Microsoft.AspNetCore.Mvc.Razor.Host/MvcRazorHost.cs
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,6 @@ public override RazorParser DecorateRazorParser(RazorParser razorParser, string
}

var inheritedChunkTrees = GetInheritedChunkTrees(sourceFileName);

return new MvcRazorParser(razorParser, inheritedChunkTrees, DefaultInheritedChunks, ModelExpressionType);
}

Expand Down Expand Up @@ -345,11 +344,6 @@ public override CodeGenerator DecorateCodeGenerator(
});
}

public void Dispose()
{
_chunkTreeCache.Dispose();
}

private IReadOnlyList<ChunkTree> GetInheritedChunkTrees(string sourceFileName)
{
var inheritedChunkTrees = GetInheritedChunkTreeResults(sourceFileName)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,83 +32,81 @@ @inherits MyBaseType
new UsingChunk { Namespace = "AppNamespace.Model" },
};
var cache = new DefaultChunkTreeCache(fileProvider);
using (var host = new MvcRazorHost(cache, new TagHelperDescriptorResolver(designTime: false)))
{
var utility = new ChunkInheritanceUtility(host, cache, defaultChunks);
var host = new MvcRazorHost(cache, new TagHelperDescriptorResolver(designTime: false));
var utility = new ChunkInheritanceUtility(host, cache, defaultChunks);

// Act
var chunkTreeResults = utility.GetInheritedChunkTreeResults(
PlatformNormalizer.NormalizePath(@"Views\home\Index.cshtml"));
// Act
var chunkTreeResults = utility.GetInheritedChunkTreeResults(
PlatformNormalizer.NormalizePath(@"Views\home\Index.cshtml"));

// Assert
Assert.Collection(chunkTreeResults,
chunkTreeResult =>
{
var viewImportsPath = @"/Views/_ViewImports.cshtml";
Assert.Collection(chunkTreeResult.ChunkTree.Children,
chunk =>
{
Assert.IsType<LiteralChunk>(chunk);
Assert.Equal(viewImportsPath, chunk.Start.FilePath);
},
chunk =>
{
var injectChunk = Assert.IsType<InjectChunk>(chunk);
Assert.Equal("MyHelper<TModel>", injectChunk.TypeName);
Assert.Equal("Helper", injectChunk.MemberName);
Assert.Equal(viewImportsPath, chunk.Start.FilePath);
},
chunk =>
{
Assert.IsType<LiteralChunk>(chunk);
Assert.Equal(viewImportsPath, chunk.Start.FilePath);
},
chunk =>
{
var setBaseTypeChunk = Assert.IsType<SetBaseTypeChunk>(chunk);
Assert.Equal("MyBaseType", setBaseTypeChunk.TypeName);
Assert.Equal(viewImportsPath, chunk.Start.FilePath);
},
chunk =>
{
Assert.IsType<LiteralChunk>(chunk);
Assert.Equal(viewImportsPath, chunk.Start.FilePath);
},
chunk =>
{
Assert.IsType<StatementChunk>(chunk);
Assert.Equal(viewImportsPath, chunk.Start.FilePath);
},
chunk =>
{
Assert.IsType<LiteralChunk>(chunk);
Assert.Equal(viewImportsPath, chunk.Start.FilePath);
});
Assert.Equal(viewImportsPath, chunkTreeResult.FilePath);
},
chunkTreeResult =>
{
var viewImportsPath = "/Views/home/_ViewImports.cshtml";
Assert.Collection(chunkTreeResult.ChunkTree.Children,
chunk =>
{
Assert.IsType<LiteralChunk>(chunk);
Assert.Equal(viewImportsPath, chunk.Start.FilePath);
},
chunk =>
{
var usingChunk = Assert.IsType<UsingChunk>(chunk);
Assert.Equal("MyNamespace", usingChunk.Namespace);
Assert.Equal(viewImportsPath, chunk.Start.FilePath);
},
chunk =>
{
Assert.IsType<LiteralChunk>(chunk);
Assert.Equal(viewImportsPath, chunk.Start.FilePath);
});
Assert.Equal(viewImportsPath, chunkTreeResult.FilePath);
});
}
// Assert
Assert.Collection(chunkTreeResults,
chunkTreeResult =>
{
var viewImportsPath = @"/Views/_ViewImports.cshtml";
Assert.Collection(chunkTreeResult.ChunkTree.Children,
chunk =>
{
Assert.IsType<LiteralChunk>(chunk);
Assert.Equal(viewImportsPath, chunk.Start.FilePath);
},
chunk =>
{
var injectChunk = Assert.IsType<InjectChunk>(chunk);
Assert.Equal("MyHelper<TModel>", injectChunk.TypeName);
Assert.Equal("Helper", injectChunk.MemberName);
Assert.Equal(viewImportsPath, chunk.Start.FilePath);
},
chunk =>
{
Assert.IsType<LiteralChunk>(chunk);
Assert.Equal(viewImportsPath, chunk.Start.FilePath);
},
chunk =>
{
var setBaseTypeChunk = Assert.IsType<SetBaseTypeChunk>(chunk);
Assert.Equal("MyBaseType", setBaseTypeChunk.TypeName);
Assert.Equal(viewImportsPath, chunk.Start.FilePath);
},
chunk =>
{
Assert.IsType<LiteralChunk>(chunk);
Assert.Equal(viewImportsPath, chunk.Start.FilePath);
},
chunk =>
{
Assert.IsType<StatementChunk>(chunk);
Assert.Equal(viewImportsPath, chunk.Start.FilePath);
},
chunk =>
{
Assert.IsType<LiteralChunk>(chunk);
Assert.Equal(viewImportsPath, chunk.Start.FilePath);
});
Assert.Equal(viewImportsPath, chunkTreeResult.FilePath);
},
chunkTreeResult =>
{
var viewImportsPath = "/Views/home/_ViewImports.cshtml";
Assert.Collection(chunkTreeResult.ChunkTree.Children,
chunk =>
{
Assert.IsType<LiteralChunk>(chunk);
Assert.Equal(viewImportsPath, chunk.Start.FilePath);
},
chunk =>
{
var usingChunk = Assert.IsType<UsingChunk>(chunk);
Assert.Equal("MyNamespace", usingChunk.Namespace);
Assert.Equal(viewImportsPath, chunk.Start.FilePath);
},
chunk =>
{
Assert.IsType<LiteralChunk>(chunk);
Assert.Equal(viewImportsPath, chunk.Start.FilePath);
});
Assert.Equal(viewImportsPath, chunkTreeResult.FilePath);
});
}

[Fact]
Expand All @@ -120,21 +118,19 @@ public void GetInheritedChunks_ReturnsEmptySequenceIfNoGlobalsArePresent()
fileProvider.AddFile(@"/Views/_Layout.cshtml", string.Empty);
fileProvider.AddFile(@"/Views/home/_not-viewimports.cshtml", string.Empty);
var cache = new DefaultChunkTreeCache(fileProvider);
using (var host = new MvcRazorHost(cache, new TagHelperDescriptorResolver(designTime: false)))
var host = new MvcRazorHost(cache, new TagHelperDescriptorResolver(designTime: false));
var defaultChunks = new Chunk[]
{
var defaultChunks = new Chunk[]
{
new InjectChunk("MyTestHtmlHelper", "Html"),
new UsingChunk { Namespace = "AppNamespace.Model" },
};
var utility = new ChunkInheritanceUtility(host, cache, defaultChunks);
};
var utility = new ChunkInheritanceUtility(host, cache, defaultChunks);

// Act
var chunkTrees = utility.GetInheritedChunkTreeResults(PlatformNormalizer.NormalizePath(@"Views\home\Index.cshtml"));
// Act
var chunkTrees = utility.GetInheritedChunkTreeResults(PlatformNormalizer.NormalizePath(@"Views\home\Index.cshtml"));

// Assert
Assert.Empty(chunkTrees);
}
// Assert
Assert.Empty(chunkTrees);
}

[Fact]
Expand All @@ -145,15 +141,14 @@ public void MergeInheritedChunks_MergesDefaultInheritedChunks()
fileProvider.AddFile(@"/Views/_ViewImports.cshtml",
"@inject DifferentHelper<TModel> Html");
var cache = new DefaultChunkTreeCache(fileProvider);
using (var host = new MvcRazorHost(cache, new TagHelperDescriptorResolver(designTime: false)))
var host = new MvcRazorHost(cache, new TagHelperDescriptorResolver(designTime: false));
var defaultChunks = new Chunk[]
{
var defaultChunks = new Chunk[]
{
new InjectChunk("MyTestHtmlHelper", "Html"),
new UsingChunk { Namespace = "AppNamespace.Model" },
};
var inheritedChunkTrees = new ChunkTree[]
{
};
var inheritedChunkTrees = new ChunkTree[]
{
new ChunkTree
{
Children = new Chunk[]
Expand All @@ -169,20 +164,19 @@ public void MergeInheritedChunks_MergesDefaultInheritedChunks()
new UsingChunk { Namespace = "AppNamespace.Model" },
}
}
};
};

var utility = new ChunkInheritanceUtility(host, cache, defaultChunks);
var chunkTree = new ChunkTree();
var utility = new ChunkInheritanceUtility(host, cache, defaultChunks);
var chunkTree = new ChunkTree();

// Act
utility.MergeInheritedChunkTrees(chunkTree, inheritedChunkTrees, "dynamic");
// Act
utility.MergeInheritedChunkTrees(chunkTree, inheritedChunkTrees, "dynamic");

// Assert
Assert.Collection(chunkTree.Children,
chunk => Assert.Same(defaultChunks[1], chunk),
chunk => Assert.Same(inheritedChunkTrees[0].Children[0], chunk),
chunk => Assert.Same(defaultChunks[0], chunk));
}
// Assert
Assert.Collection(chunkTree.Children,
chunk => Assert.Same(defaultChunks[1], chunk),
chunk => Assert.Same(inheritedChunkTrees[0].Children[0], chunk),
chunk => Assert.Same(defaultChunks[0], chunk));
}
}
}
Loading

0 comments on commit 9acd0f5

Please sign in to comment.