Add RazorCSharpSourceDocument

Precursor to actual CSharp lowering
This commit is contained in:
Ryan Nowak 2016-12-04 23:22:15 -08:00
parent 9cefcdd450
commit 2190dc2096
3 changed files with 66 additions and 0 deletions

View File

@ -0,0 +1,15 @@
// 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 Microsoft.AspNetCore.Razor.Evolution.Legacy;
namespace Microsoft.AspNetCore.Razor.Evolution
{
public class RazorCSharpDocument
{
public string GeneratedCode { get; set; }
internal IReadOnlyList<LineMapping> LineMappings { get; set; }
}
}

View File

@ -47,5 +47,25 @@ namespace Microsoft.AspNetCore.Razor.Evolution
document.Items[typeof(DocumentIRNode)] = irDocument;
}
public static RazorCSharpDocument GetCSharpDocument(this RazorCodeDocument document)
{
if (document == null)
{
throw new ArgumentNullException(nameof(document));
}
return (RazorCSharpDocument)document.Items[typeof(RazorCSharpDocument)];
}
public static void SetCSharpDocument(this RazorCodeDocument document, RazorCSharpDocument csharp)
{
if (document == null)
{
throw new ArgumentNullException(nameof(document));
}
document.Items[typeof(RazorCSharpDocument)] = csharp;
}
}
}

View File

@ -69,5 +69,36 @@ namespace Microsoft.AspNetCore.Razor.Evolution
// Assert
Assert.Same(expected, codeDocument.Items[typeof(DocumentIRNode)]);
}
[Fact]
public void GetCSharpDocument_ReturnsCSharpDocument()
{
// Arrange
var codeDocument = TestRazorCodeDocument.CreateEmpty();
var expected = new RazorCSharpDocument();
codeDocument.Items[typeof(RazorCSharpDocument)] = expected;
// Act
var actual = codeDocument.GetCSharpDocument();
// Assert
Assert.Same(expected, actual);
}
[Fact]
public void SetCSharpDocument_SetsCSharpDocument()
{
// Arrange
var codeDocument = TestRazorCodeDocument.CreateEmpty();
var expected = new RazorCSharpDocument();
// Act
codeDocument.SetCSharpDocument(expected);
// Assert
Assert.Same(expected, codeDocument.Items[typeof(RazorCSharpDocument)]);
}
}
}