Allow GeneratedCodeContainer to accept initial output.

This commit is contained in:
N. Taylor Mullen 2018-09-10 16:14:25 -07:00
parent da935bfa95
commit d2d84d00f5
2 changed files with 28 additions and 4 deletions

View File

@ -18,7 +18,7 @@ namespace Microsoft.CodeAnalysis.Razor.ProjectSystem
public event EventHandler<TextChangeEventArgs> GeneratedCodeChanged;
private SourceText _source;
private VersionStamp _sourceVersion;
private VersionStamp? _sourceVersion;
private RazorCSharpDocument _output;
private DocumentSnapshot _latestDocument;
@ -48,7 +48,7 @@ namespace Microsoft.CodeAnalysis.Razor.ProjectSystem
{
lock (_setOutputLock)
{
return _sourceVersion;
return _sourceVersion.Value;
}
}
}
@ -106,8 +106,7 @@ namespace Microsoft.CodeAnalysis.Razor.ProjectSystem
return;
}
var newerVersion = SourceVersion.GetNewerVersion(version);
if (newerVersion == SourceVersion)
if (_sourceVersion.HasValue && _sourceVersion == SourceVersion.GetNewerVersion(version))
{
// Latest document is newer than the provided document.
return;

View File

@ -1,6 +1,8 @@
// 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.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Razor.Language;
using Microsoft.CodeAnalysis.Text;
using Xunit;
@ -9,6 +11,29 @@ namespace Microsoft.CodeAnalysis.Razor.ProjectSystem
{
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]
public void TryGetLinePositionSpan_SpanWithinSourceMapping_ReturnsTrue()
{