Allow GeneratedCodeContainer to accept initial output.
This commit is contained in:
parent
da935bfa95
commit
d2d84d00f5
|
|
@ -18,7 +18,7 @@ namespace Microsoft.CodeAnalysis.Razor.ProjectSystem
|
||||||
public event EventHandler<TextChangeEventArgs> GeneratedCodeChanged;
|
public event EventHandler<TextChangeEventArgs> GeneratedCodeChanged;
|
||||||
|
|
||||||
private SourceText _source;
|
private SourceText _source;
|
||||||
private VersionStamp _sourceVersion;
|
private VersionStamp? _sourceVersion;
|
||||||
private RazorCSharpDocument _output;
|
private RazorCSharpDocument _output;
|
||||||
private DocumentSnapshot _latestDocument;
|
private DocumentSnapshot _latestDocument;
|
||||||
|
|
||||||
|
|
@ -48,7 +48,7 @@ namespace Microsoft.CodeAnalysis.Razor.ProjectSystem
|
||||||
{
|
{
|
||||||
lock (_setOutputLock)
|
lock (_setOutputLock)
|
||||||
{
|
{
|
||||||
return _sourceVersion;
|
return _sourceVersion.Value;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -106,8 +106,7 @@ namespace Microsoft.CodeAnalysis.Razor.ProjectSystem
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
var newerVersion = SourceVersion.GetNewerVersion(version);
|
if (_sourceVersion.HasValue && _sourceVersion == SourceVersion.GetNewerVersion(version))
|
||||||
if (newerVersion == SourceVersion)
|
|
||||||
{
|
{
|
||||||
// Latest document is newer than the provided document.
|
// Latest document is newer than the provided document.
|
||||||
return;
|
return;
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,8 @@
|
||||||
// Copyright (c) .NET Foundation. All rights reserved.
|
// 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.
|
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||||
|
|
||||||
|
using System.Linq;
|
||||||
|
using System.Threading.Tasks;
|
||||||
using Microsoft.AspNetCore.Razor.Language;
|
using Microsoft.AspNetCore.Razor.Language;
|
||||||
using Microsoft.CodeAnalysis.Text;
|
using Microsoft.CodeAnalysis.Text;
|
||||||
using Xunit;
|
using Xunit;
|
||||||
|
|
@ -9,6 +11,29 @@ namespace Microsoft.CodeAnalysis.Razor.ProjectSystem
|
||||||
{
|
{
|
||||||
public class GeneratedCodeContainerTest
|
public class GeneratedCodeContainerTest
|
||||||
{
|
{
|
||||||
|
[Fact]
|
||||||
|
public void SetOutput_AcceptsInitialOutput()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var csharpDocument = RazorCSharpDocument.Create("...", RazorCodeGenerationOptions.CreateDefault(), Enumerable.Empty<RazorDiagnostic>());
|
||||||
|
var hostProject = new HostProject("C:/project.csproj", RazorConfiguration.Default);
|
||||||
|
var services = TestWorkspace.Create().Services;
|
||||||
|
var projectState = ProjectState.Create(services, hostProject);
|
||||||
|
var project = new DefaultProjectSnapshot(projectState);
|
||||||
|
var hostDocument = new HostDocument("C:/file.cshtml", "C:/file.cshtml");
|
||||||
|
var text = SourceText.From("...");
|
||||||
|
var textAndVersion = TextAndVersion.Create(text, VersionStamp.Default);
|
||||||
|
var documentState = new DocumentState(services, hostDocument, text, VersionStamp.Default, () => Task.FromResult(textAndVersion));
|
||||||
|
var document = new DefaultDocumentSnapshot(project, documentState);
|
||||||
|
var container = new GeneratedCodeContainer();
|
||||||
|
|
||||||
|
// Act
|
||||||
|
container.SetOutput(csharpDocument, document);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
Assert.NotNull(container.LatestDocument);
|
||||||
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void TryGetLinePositionSpan_SpanWithinSourceMapping_ReturnsTrue()
|
public void TryGetLinePositionSpan_SpanWithinSourceMapping_ReturnsTrue()
|
||||||
{
|
{
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue