public async Task GetGeneratedOutputAsync_SetsHostDocumentOutput()
        {
            // Act
            await LegacyDocument.GetGeneratedOutputAsync();

            // Assert
            Assert.NotNull(LegacyHostDocument.GeneratedCodeContainer.Output);
            Assert.Same(SourceText, LegacyHostDocument.GeneratedCodeContainer.Source);
        }
        public async Task GetGeneratedOutputAsync_Legacy()
        {
            // Act
            await LegacyDocument.GetGeneratedOutputAsync();

            // Assert
            Assert.NotNull(LegacyHostDocument.GeneratedDocumentContainer.OutputCSharp);
            Assert.Contains("Template", LegacyHostDocument.GeneratedDocumentContainer.OutputCSharp.GeneratedCode, StringComparison.Ordinal);
        }
        public async Task GetGeneratedOutputAsync_Legacy()
        {
            // Act
            await LegacyDocument.GetGeneratedOutputAsync();

            // Assert
            Assert.NotNull(LegacyHostDocument.GeneratedCodeContainer.Output);
            Assert.Contains("Template", LegacyHostDocument.GeneratedCodeContainer.Output.GeneratedCode);
        }
Example #4
0
        public async Task RegeneratingWithReference_CachesOutput()
        {
            // Arrange
            var output = await LegacyDocument.GetGeneratedOutputAsync();

            // Mostly doing this to ensure "var output" doesn't get optimized out
            Assert.NotNull(output);

            // Act & Assert
            Assert.True(LegacyDocument.TryGetGeneratedOutput(out _));
            Assert.True(LegacyDocument.TryGetGeneratedOutputVersionAsync(out _));
        }
Example #5
0
        public async Task GCCollect_OutputIsNoLongerCached()
        {
            // Arrange
            await LegacyDocument.GetGeneratedOutputAsync();

            // Act

            // Forces collection of the cached document output
            GC.Collect();

            // Assert
            Assert.False(LegacyDocument.TryGetGeneratedOutput(out _));
            Assert.False(LegacyDocument.TryGetGeneratedOutputVersionAsync(out _));
        }
Example #6
0
        public async Task GCCollect_OnRegenerationMaintainsOutputVersion()
        {
            // Arrange
            var initialOutputVersion = await LegacyDocument.GetGeneratedOutputVersionAsync();

            // Forces collection of the cached document output
            GC.Collect();

            // Act
            var regeneratedOutputVersion = await LegacyDocument.GetGeneratedOutputVersionAsync();

            // Assert
            Assert.Equal(initialOutputVersion, regeneratedOutputVersion);
        }
        public async Task GetGeneratedOutputAsync_OnlySetsOutputIfDocumentNewer()
        {
            // Arrange
            var newSourceText    = SourceText.From("NEW!");
            var newDocumentState = LegacyDocument.State.WithText(newSourceText, Version.GetNewerVersion());
            var newDocument      = new DefaultDocumentSnapshot(LegacyDocument.ProjectInternal, newDocumentState);

            // Force the output to be the new output
            await newDocument.GetGeneratedOutputAsync();

            // Act
            await LegacyDocument.GetGeneratedOutputAsync();

            // Assert
            Assert.NotNull(LegacyHostDocument.GeneratedCodeContainer.Output);
            Assert.Same(newSourceText, LegacyHostDocument.GeneratedCodeContainer.Source);
        }