public void SetOutput_InvokesChangedEvent()
        {
            // Arrange
            using var workspace = TestWorkspace.Create();

            var services     = workspace.Services;
            var hostProject  = new HostProject("C:/project.csproj", RazorConfiguration.Default, "project");
            var projectState = ProjectState.Create(services, hostProject);
            var project      = new DefaultProjectSnapshot(projectState);

            var text           = SourceText.From("...");
            var textAndVersion = TextAndVersion.Create(text, VersionStamp.Default);
            var hostDocument   = new HostDocument("C:/file.cshtml", "C:/file.cshtml");
            var documentState  = new DocumentState(services, hostDocument, text, VersionStamp.Default, () => Task.FromResult(textAndVersion));
            var document       = new DefaultDocumentSnapshot(project, documentState);
            var csharpDocument = RazorCSharpDocument.Create("...", RazorCodeGenerationOptions.CreateDefault(), Enumerable.Empty <RazorDiagnostic>());
            var htmlDocument   = RazorHtmlDocument.Create("...", RazorCodeGenerationOptions.CreateDefault());

            var version       = VersionStamp.Create();
            var container     = new GeneratedDocumentContainer();
            var csharpChanged = false;
            var htmlChanged   = false;

            container.GeneratedCSharpChanged += (o, a) => { csharpChanged = true; };
            container.GeneratedHtmlChanged   += (o, a) => { htmlChanged = true; };

            // Act
            container.SetOutput(document, csharpDocument, htmlDocument, version, version, version);

            // Assert
            Assert.NotNull(container.LatestDocument);
            Assert.True(csharpChanged);
            Assert.True(htmlChanged);
        }
        public void SetOutput_AcceptsSameVersionedDocuments()
        {
            // Arrange
            using var workspace = TestWorkspace.Create();

            var services     = workspace.Services;
            var hostProject  = new HostProject("C:/project.csproj", RazorConfiguration.Default, "project");
            var projectState = ProjectState.Create(services, hostProject);
            var project      = new DefaultProjectSnapshot(projectState);

            var text           = SourceText.From("...");
            var textAndVersion = TextAndVersion.Create(text, VersionStamp.Default);
            var hostDocument   = new HostDocument("C:/file.cshtml", "C:/file.cshtml");
            var documentState  = new DocumentState(services, hostDocument, text, VersionStamp.Default, () => Task.FromResult(textAndVersion));
            var document       = new DefaultDocumentSnapshot(project, documentState);
            var newDocument    = new DefaultDocumentSnapshot(project, documentState);

            var csharpDocument = RazorCSharpDocument.Create("...", RazorCodeGenerationOptions.CreateDefault(), Enumerable.Empty <RazorDiagnostic>());
            var htmlDocument   = RazorHtmlDocument.Create("...", RazorCodeGenerationOptions.CreateDefault());

            var version   = VersionStamp.Create();
            var container = new GeneratedDocumentContainer();

            container.SetOutput(document, csharpDocument, htmlDocument, version, version, version);

            // Act
            container.SetOutput(newDocument, csharpDocument, htmlDocument, version, version, version);

            // Assert
            Assert.Same(newDocument, container.LatestDocument);
        }
Ejemplo n.º 3
0
        public HostDocument(HostDocument other)
        {
            if (other == null)
            {
                throw new ArgumentNullException(nameof(other));
            }

            FileKind   = other.FileKind;
            FilePath   = other.FilePath;
            TargetPath = other.TargetPath;

            GeneratedDocumentContainer = new GeneratedDocumentContainer();
        }
Ejemplo n.º 4
0
        public HostDocument(string filePath, string targetPath, string fileKind)
        {
            if (filePath == null)
            {
                throw new ArgumentNullException(nameof(filePath));
            }

            if (targetPath == null)
            {
                throw new ArgumentNullException(nameof(targetPath));
            }

            FilePath   = filePath;
            TargetPath = targetPath;
            FileKind   = fileKind ?? FileKinds.GetFileKindFromFilePath(filePath);
            GeneratedDocumentContainer = new GeneratedDocumentContainer();
        }