Ejemplo n.º 1
0
        public void BuildIncrementalism_CausingRecompilation_WhenApplicationPartAttributeIsGenerated()
        {
            var testAsset        = "RazorAppWithP2PReference";
            var projectDirectory = CreateRazorSdkTestAsset(testAsset);

            var build = new BuildCommand(projectDirectory, "AppWithP2PReference");

            build.Execute().Should().Pass();

            string intermediateOutputPath = build.GetIntermediateDirectory(DefaultTfm, "Debug").ToString();
            string outputPath             = build.GetOutputDirectory(DefaultTfm, "Debug").ToString();

            var generatedAttributeFile = Path.Combine(intermediateOutputPath, "AppWithP2PReference.MvcApplicationPartsAssemblyInfo.cs");

            File.Exists(generatedAttributeFile).Should().BeTrue();
            new FileInfo(generatedAttributeFile).Should().Contain("[assembly: Microsoft.AspNetCore.Mvc.ApplicationParts.ApplicationPartAttribute(\"ClassLibrary\")]");

            var thumbPrint = FileThumbPrint.Create(generatedAttributeFile);

            // Touch a file in the main app which should call recompilation, but not the Mvc discovery tasks to re-run.
            File.AppendAllText(Path.Combine(build.ProjectRootPath, "Program.cs"), " ");

            build = new BuildCommand(projectDirectory, "AppWithP2PReference");
            build.Execute().Should().Pass();

            File.Exists(generatedAttributeFile).Should().BeTrue();
            Assert.Equal(thumbPrint, FileThumbPrint.Create(generatedAttributeFile));
            new FileInfo(Path.Combine(outputPath, "AppWithP2PReference.dll")).AssemblyShould().HaveAttribute("Microsoft.AspNetCore.Mvc.ApplicationParts.ApplicationPartAttribute");
        }
Ejemplo n.º 2
0
        public void Publish_WithoutLinkerAndCompression_UpdatesFilesWhenSourcesChange()
        {
            // Arrange
            var testAppName  = "BlazorHosted";
            var testInstance = CreateAspNetSdkTestAsset(testAppName);

            var publishCommand = new PublishCommand(Log, Path.Combine(testInstance.TestRoot, "blazorhosted"));

            publishCommand.Execute("/p:BlazorWebAssemblyEnableLinking=false").Should().Pass();

            // Act
            var buildOutputDirectory = publishCommand.GetOutputDirectory(DefaultTfm).ToString();
            var mainAppDll           = Path.Combine(testInstance.TestRoot, "blazorhosted", "bin", "Debug", DefaultTfm, "publish", "wwwroot", "_framework", "blazorwasm.dll");
            var mainAppDllThumbPrint = FileThumbPrint.Create(mainAppDll);

            var mainAppCompressedDll           = Path.Combine(testInstance.TestRoot, "blazorhosted", "bin", "Debug", DefaultTfm, "publish", "wwwroot", "_framework", "blazorwasm.dll.br");
            var mainAppCompressedDllThumbPrint = FileThumbPrint.Create(mainAppCompressedDll);

            var programFile         = Path.Combine(testInstance.TestRoot, "blazorwasm", "Program.cs");
            var programFileContents = File.ReadAllText(programFile);

            File.WriteAllText(programFile, programFileContents.Replace("args", "arguments"));

            // Assert
            publishCommand = new PublishCommand(Log, Path.Combine(testInstance.TestRoot, "blazorhosted"));
            publishCommand.Execute("/p:BlazorWebAssemblyEnableLinking=false").Should().Pass();

            var newMainAppDllThumbPrint           = FileThumbPrint.Create(mainAppDll);
            var newMainAppCompressedDllThumbPrint = FileThumbPrint.Create(mainAppCompressedDll);

            Assert.NotEqual(mainAppDllThumbPrint, newMainAppDllThumbPrint);
            Assert.NotEqual(mainAppCompressedDllThumbPrint, newMainAppCompressedDllThumbPrint);
        }
Ejemplo n.º 3
0
        public void Build_RemovingScopedCssAndBuilding_UpdatesGeneratedCodeAndBundle()
        {
            var testAsset        = "RazorComponentApp";
            var projectDirectory = CreateAspNetSdkTestAsset(testAsset);

            var build = new BuildCommand(projectDirectory);

            build.Execute().Should().Pass();

            var intermediateOutputPath = Path.Combine(build.GetBaseIntermediateDirectory().ToString(), "Debug", DefaultTfm);

            new FileInfo(Path.Combine(intermediateOutputPath, "scopedcss", "Components", "Pages", "Counter.razor.rz.scp.css")).Should().Exist();
            var generatedBundle = Path.Combine(intermediateOutputPath, "scopedcss", "bundle", "ComponentApp.styles.css");

            new FileInfo(generatedBundle).Should().Exist();
            var generatedProjectBundle = Path.Combine(intermediateOutputPath, "scopedcss", "projectbundle", "ComponentApp.bundle.scp.css");

            new FileInfo(generatedProjectBundle).Should().Exist();

            var bundleThumbprint = FileThumbPrint.Create(generatedBundle);

            File.Delete(Path.Combine(projectDirectory.Path, "Components", "Pages", "Counter.razor.css"));

            build = new BuildCommand(projectDirectory);
            build.Execute().Should().Pass();

            new FileInfo(Path.Combine(intermediateOutputPath, "scopedcss", "Components", "Pages", "Counter.razor.rz.scp.css")).Should().NotExist();

            var newBundleThumbprint = FileThumbPrint.Create(generatedBundle);

            Assert.NotEqual(bundleThumbprint, newBundleThumbprint);
        }
Ejemplo n.º 4
0
        public void RazorGenerate_RegeneratesTagHelperInputs_IfFileChanges()
        {
            var testAsset        = "RazorSimpleMvc";
            var projectDirectory = CreateRazorSdkTestAsset(testAsset);

            // Act - 1
            var build  = new BuildCommand(projectDirectory);
            var result = build.Execute();

            var intermediateOutputPath = build.GetIntermediateDirectory(DefaultTfm, "Debug").ToString();

            var expectedTagHelperCacheContent = @"""Name"":""SimpleMvc.SimpleTagHelper""";
            var file = Path.Combine(projectDirectory.Path, "SimpleTagHelper.cs");
            var tagHelperOutputCache = Path.Combine(intermediateOutputPath, "SimpleMvc.TagHelpers.output.cache");
            var generatedFile        = Path.Combine(intermediateOutputPath, "Razor", "Views", "Home", "Index.cshtml.g.cs");

            // Assert - 1
            result.Should().Pass();
            new FileInfo(tagHelperOutputCache).Should().Contain(expectedTagHelperCacheContent);
            var fileThumbPrint = FileThumbPrint.Create(generatedFile);

            // Act - 2
            // Update the source content and build. We should expect the outputs to be regenerated.
            File.WriteAllText(file, string.Empty);
            build  = new BuildCommand(projectDirectory);
            result = build.Execute();

            // Assert - 2
            result.Should().Pass();
            new FileInfo(tagHelperOutputCache).Should().NotContain(@"""Name"":""SimpleMvc.SimpleTagHelper""");
            var newThumbPrint = FileThumbPrint.Create(generatedFile);

            Assert.NotEqual(fileThumbPrint, newThumbPrint);
        }
Ejemplo n.º 5
0
        public void BuildComponents_DoesNotRegenerateComponentDefinition_WhenDefinitionIsUnchanged()
        {
            var testAsset        = "RazorMvcWithComponents";
            var projectDirectory = CreateAspNetSdkTestAsset(testAsset);

            // Act - 1
            var build = new BuildCommand(projectDirectory);

            var intermediateOutputPath = build.GetIntermediateDirectory(DefaultTfm, "Debug").ToString();
            var outputPath             = build.GetOutputDirectory(DefaultTfm, "Debug").ToString();

            var updatedContent       = "Some content";
            var tagHelperOutputCache = Path.Combine(intermediateOutputPath, "MvcWithComponents.TagHelpers.output.cache");

            var generatedFile           = Path.Combine(intermediateOutputPath, "Razor", "Views", "Shared", "NavMenu.razor.g.cs");
            var generatedDefinitionFile = Path.Combine(intermediateOutputPath, "RazorDeclaration", "Views", "Shared", "NavMenu.razor.g.cs");

            // Assert - 1
            var result = build.Execute();

            result.Should().Pass();

            var outputFile = Path.Combine(outputPath, "MvcWithComponents.dll");

            new FileInfo(outputFile).Should().Exist();
            var outputAssemblyThumbprint = FileThumbPrint.Create(outputFile);

            new FileInfo(generatedDefinitionFile).Should().Exist();
            var generatedDefinitionThumbprint = FileThumbPrint.Create(generatedDefinitionFile);

            new FileInfo(generatedFile).Should().Exist();
            var generatedFileThumbprint = FileThumbPrint.Create(generatedFile);

            new FileInfo(tagHelperOutputCache).Should().Exist();
            new FileInfo(tagHelperOutputCache).Should().Contain(@"""Name"":""MvcWithComponents.Views.Shared.NavMenu""");

            var definitionThumbprint = FileThumbPrint.Create(tagHelperOutputCache);

            // Act - 2
            var page = Path.Combine(projectDirectory.Path, "Views", "Shared", "NavMenu.razor");

            File.WriteAllText(page, updatedContent, Encoding.UTF8);
            File.SetLastWriteTimeUtc(page, File.GetLastWriteTimeUtc(page).AddSeconds(1));

            build  = new BuildCommand(projectDirectory);
            result = build.Execute();

            // Assert - 2
            new FileInfo(generatedDefinitionFile).Should().Exist();
            // Definition file remains unchanged.
            Assert.Equal(generatedDefinitionThumbprint, FileThumbPrint.Create(generatedDefinitionFile));
            new FileInfo(generatedFile).Should().Exist();
            // Generated file should change and include the new content.
            Assert.NotEqual(generatedFileThumbprint, FileThumbPrint.Create(generatedFile));
            new FileInfo(generatedFile).Should().Contain(updatedContent);

            // TagHelper cache should remain unchanged.
            Assert.Equal(definitionThumbprint, FileThumbPrint.Create(tagHelperOutputCache));
        }
Ejemplo n.º 6
0
        public void BuildComponents_DoesNotModifyFiles_IfFilesDoNotChange()
        {
            var testAsset        = "RazorMvcWithComponents";
            var projectDirectory = CreateRazorSdkTestAsset(testAsset);

            var build = new BuildCommand(projectDirectory);

            var intermediateOutputPath = build.GetIntermediateDirectory(DefaultTfm, "Debug").ToString();
            var outputPath             = build.GetOutputDirectory(DefaultTfm, "Debug").ToString();

            // Act - 1
            var tagHelperOutputCache = Path.Combine(intermediateOutputPath, "MvcWithComponents.TagHelpers.output.cache");

            var file                    = Path.Combine(projectDirectory.Path, "Views", "Shared", "NavMenu.razor.g.cs");
            var generatedFile           = Path.Combine(intermediateOutputPath, "Razor", "Views", "Shared", "NavMenu.razor.g.cs");
            var generatedDefinitionFile = Path.Combine(intermediateOutputPath, "RazorDeclaration", "Views", "Shared", "NavMenu.razor.g.cs");

            // Assert - 1
            var result = build.Execute();

            result.Should().Pass();
            var outputFile = Path.Combine(outputPath, "MvcWithComponents.dll");

            new FileInfo(outputFile).Should().Exist();
            var outputAssemblyThumbprint = FileThumbPrint.Create(outputFile);

            new FileInfo(generatedDefinitionFile).Should().Exist();
            var generatedDefinitionThumbprint = FileThumbPrint.Create(generatedDefinitionFile);

            new FileInfo(generatedFile).Should().Exist();
            var generatedFileThumbprint = FileThumbPrint.Create(generatedFile);

            new FileInfo(tagHelperOutputCache).Should().Exist();
            new FileInfo(tagHelperOutputCache).Should().Contain(@"""Name"":""MvcWithComponents.Views.Shared.NavMenu""");

            var definitionThumbprint = FileThumbPrint.Create(tagHelperOutputCache);

            // Act - 2
            result = build.Execute();

            // Assert - 2
            new FileInfo(outputFile).Should().Exist();
            Assert.Equal(outputAssemblyThumbprint, FileThumbPrint.Create(outputFile));

            new FileInfo(generatedDefinitionFile).Should().Exist();
            Assert.Equal(generatedDefinitionThumbprint, FileThumbPrint.Create(generatedDefinitionFile));
            new FileInfo(generatedFile).Should().Exist();
            Assert.Equal(generatedFileThumbprint, FileThumbPrint.Create(generatedFile));

            new FileInfo(tagHelperOutputCache).Should().Exist();
            new FileInfo(tagHelperOutputCache).Should().Contain(@"""Name"":""MvcWithComponents.Views.Shared.NavMenu""");

            Assert.Equal(definitionThumbprint, FileThumbPrint.Create(tagHelperOutputCache));
        }
Ejemplo n.º 7
0
        public void Build_TouchesUpToDateMarkerFile()
        {
            var testAsset        = "RazorClassLibrary";
            var projectDirectory = CreateAspNetSdkTestAsset(testAsset);

            // Remove the components so that they don't interfere with these tests
            Directory.Delete(Path.Combine(projectDirectory.Path, "Components"), recursive: true);

            var build = new BuildCommand(projectDirectory);

            build.Execute()
            .Should()
            .Pass();

            string intermediateOutputPath = Path.Combine(build.GetBaseIntermediateDirectory().FullName, "Debug", DefaultTfm);

            var classLibraryDll      = Path.Combine(intermediateOutputPath, "ClassLibrary.dll");
            var classLibraryViewsDll = Path.Combine(intermediateOutputPath, "ClassLibrary.Views.dll");
            var markerFile           = Path.Combine(intermediateOutputPath, "ClassLibrary.csproj.CopyComplete");;

            new FileInfo(classLibraryDll).Should().Exist();
            new FileInfo(classLibraryViewsDll).Should().Exist();
            new FileInfo(markerFile).Should().Exist();

            // Gather thumbprints before incremental build.
            var classLibraryThumbPrint      = FileThumbPrint.Create(classLibraryDll);
            var classLibraryViewsThumbPrint = FileThumbPrint.Create(classLibraryViewsDll);
            var markerFileThumbPrint        = FileThumbPrint.Create(markerFile);

            build = new BuildCommand(projectDirectory);
            build.Execute()
            .Should()
            .Pass();

            // Verify thumbprint file is unchanged between true incremental builds
            Assert.Equal(classLibraryThumbPrint, FileThumbPrint.Create(classLibraryDll));
            Assert.Equal(classLibraryViewsThumbPrint, FileThumbPrint.Create(classLibraryViewsDll));
            // In practice, this should remain unchanged. However, since our tests reference
            // binaries from other projects, this file gets updated by Microsoft.Common.targets
            Assert.NotEqual(markerFileThumbPrint, FileThumbPrint.Create(markerFile));

            // Change a cshtml file and verify ClassLibrary.Views.dll and marker file are updated
            File.AppendAllText(Path.Combine(projectDirectory.Path, "Views", "_ViewImports.cshtml"), Environment.NewLine);

            build = new BuildCommand(projectDirectory);
            build.Execute()
            .Should()
            .Pass();

            Assert.Equal(classLibraryThumbPrint, FileThumbPrint.Create(classLibraryDll));
            Assert.NotEqual(classLibraryViewsThumbPrint, FileThumbPrint.Create(classLibraryViewsDll));
            Assert.NotEqual(markerFileThumbPrint, FileThumbPrint.Create(markerFile));
        }
        public void Rebuild_Success_RecreatesManifestAndCache()
        {
            var testAsset        = "RazorAppWithPackageAndP2PReference";
            var projectDirectory = CreateAspNetSdkTestAsset(testAsset);

            // Arrange
            var build = new BuildCommand(projectDirectory, "AppWithPackageAndP2PReference");

            build.Execute().Should().Pass();

            var intermediateOutputPath = build.GetIntermediateDirectory(DefaultTfm, "Debug").ToString();
            var outputPath             = build.GetOutputDirectory(DefaultTfm, "Debug").ToString();

            // GenerateStaticWebAssetsManifest should generate the manifest and the cache.
            new FileInfo(Path.Combine(intermediateOutputPath, "staticwebassets", "AppWithPackageAndP2PReference.StaticWebAssets.xml")).Should().Exist();
            new FileInfo(Path.Combine(intermediateOutputPath, "staticwebassets", "AppWithPackageAndP2PReference.StaticWebAssets.Manifest.cache")).Should().Exist();

            var directoryPath   = Path.Combine(intermediateOutputPath, "staticwebassets");
            var thumbPrints     = new Dictionary <string, FileThumbPrint>();
            var thumbPrintFiles = new[]
            {
                Path.Combine(directoryPath, "AppWithPackageAndP2PReference.StaticWebAssets.xml"),
                Path.Combine(directoryPath, "AppWithPackageAndP2PReference.StaticWebAssets.Manifest.cache"),
            };

            foreach (var file in thumbPrintFiles)
            {
                var thumbprint = FileThumbPrint.Create(file);
                thumbPrints[file] = thumbprint;
            }

            // Act
            // var rebuild = new MSBuildCommand(Log, "Rebuild", Path.Combine(projectDirectory.Path, "AppWithPackageAndP2PReference"));
            // rebuild.Execute().Should().Pass();

            // foreach (var file in thumbPrintFiles)
            // {
            //     var thumbprint = FileThumbPrint.Create(file);
            //     Assert.NotEqual(thumbPrints[file], thumbprint);
            // }

            var path = Path.Combine(outputPath, "AppWithPackageAndP2PReference.dll");

            new FileInfo(path).Should().Exist();
            var manifest = Path.Combine(outputPath, "AppWithPackageAndP2PReference.StaticWebAssets.xml");

            new FileInfo(manifest).Should().Exist();
            var data = File.ReadAllText(manifest);

            AssertExpectedManifest(projectDirectory, data);
        }
Ejemplo n.º 9
0
        public void Pack_Incremental_DoesNotRegenerateCacheAndPropsFiles()
        {
            var testAsset        = "PackageLibraryTransitiveDependency";
            var projectDirectory = _testAssetsManager
                                   .CopyTestAsset(testAsset, testAssetSubdirectory: "TestPackages")
                                   .WithSource();

            var pack   = new MSBuildCommand(Log, "Pack", projectDirectory.Path);
            var result = pack.Execute();

            var intermediateOutputPath = pack.GetIntermediateDirectory("netstandard2.0", "Debug").ToString();
            var outputPath             = pack.GetOutputDirectory("netstandard2.0", "Debug").ToString();

            new FileInfo(Path.Combine(outputPath, "PackageLibraryTransitiveDependency.dll")).Should().Exist();

            new FileInfo(Path.Combine(intermediateOutputPath, "staticwebassets", "msbuild.PackageLibraryTransitiveDependency.Microsoft.AspNetCore.StaticWebAssets.props")).Should().Exist();
            new FileInfo(Path.Combine(intermediateOutputPath, "staticwebassets", "msbuild.build.PackageLibraryTransitiveDependency.props")).Should().Exist();
            new FileInfo(Path.Combine(intermediateOutputPath, "staticwebassets", "msbuild.buildMultiTargeting.PackageLibraryTransitiveDependency.props")).Should().Exist();
            new FileInfo(Path.Combine(intermediateOutputPath, "staticwebassets", "msbuild.buildTransitive.PackageLibraryTransitiveDependency.props")).Should().Exist();
            new FileInfo(Path.Combine(intermediateOutputPath, "staticwebassets", "PackageLibraryTransitiveDependency.StaticWebAssets.Pack.cache")).Should().Exist();

            var directoryPath   = Path.Combine(intermediateOutputPath, "staticwebassets");
            var thumbPrints     = new Dictionary <string, FileThumbPrint>();
            var thumbPrintFiles = new[]
            {
                Path.Combine(directoryPath, "msbuild.PackageLibraryTransitiveDependency.Microsoft.AspNetCore.StaticWebAssets.props"),
                Path.Combine(directoryPath, "msbuild.build.PackageLibraryTransitiveDependency.props"),
                Path.Combine(directoryPath, "msbuild.buildMultiTargeting.PackageLibraryTransitiveDependency.props"),
                Path.Combine(directoryPath, "msbuild.buildTransitive.PackageLibraryTransitiveDependency.props"),
                Path.Combine(directoryPath, "PackageLibraryTransitiveDependency.StaticWebAssets.Pack.cache"),
            };

            foreach (var file in thumbPrintFiles)
            {
                var thumbprint = FileThumbPrint.Create(file);
                thumbPrints[file] = thumbprint;
            }

            // Act
            var incremental = new MSBuildCommand(Log, "Pack", projectDirectory.Path);

            incremental.Execute().Should().Pass();
            foreach (var file in thumbPrintFiles)
            {
                var thumbprint = FileThumbPrint.Create(file);
                Assert.Equal(thumbPrints[file], thumbprint);
            }
        }
Ejemplo n.º 10
0
        public void BuildIncremental_SimpleMvc_PersistsTargetInputFile()
        {
            // Arrange
            var thumbprintLookup = new Dictionary <string, FileThumbPrint>();

            // Act 1
            var testAsset        = "RazorSimpleMvc";
            var projectDirectory = CreateAspNetSdkTestAsset(testAsset);

            var build  = new BuildCommand(projectDirectory);
            var result = build.Execute();

            var intermediateOutputPath = build.GetIntermediateDirectory(DefaultTfm, "Debug").ToString();
            var filesToIgnore          = new[]
            {
                // These files are generated on every build.
                Path.Combine(intermediateOutputPath, "SimpleMvc.csproj.CopyComplete"),
                Path.Combine(intermediateOutputPath, "SimpleMvc.csproj.FileListAbsolute.txt"),
            };

            var files = Directory.GetFiles(intermediateOutputPath).Where(p => !filesToIgnore.Contains(p));

            foreach (var file in files)
            {
                var thumbprint = FileThumbPrint.Create(file);
                thumbprintLookup[file] = thumbprint;
            }

            // Assert 1
            result.Should().Pass();

            // Act & Assert 2
            for (var i = 0; i < 2; i++)
            {
                // We want to make sure nothing changed between multiple incremental builds.
                using (var razorGenDirectoryLock = LockDirectory(Path.Combine(intermediateOutputPath, "Razor")))
                {
                    result = build.Execute();
                }

                result.Should().Pass();
                foreach (var file in files)
                {
                    var thumbprint = FileThumbPrint.Create(file);
                    Assert.Equal(thumbprintLookup[file], thumbprint);
                }
            }
        }
        public void GenerateStaticWebAssetsManifest_IncrementalBuild_ReusesManifest()
        {
            var testAsset        = "RazorAppWithPackageAndP2PReference";
            var projectDirectory = CreateAspNetSdkTestAsset(testAsset);

            var command = new MSBuildCommand(Log, "GenerateStaticWebAssetsManifest", projectDirectory.Path, "AppWithPackageAndP2PReference");

            command.Execute().Should().Pass();

            var intermediateOutputPath = command.GetIntermediateDirectory(DefaultTfm, "Debug").ToString();
            var outputPath             = command.GetOutputDirectory(DefaultTfm, "Debug").ToString();

            // GenerateStaticWebAssetsManifest should generate the manifest and the cache.
            new FileInfo(Path.Combine(intermediateOutputPath, "staticwebassets", "AppWithPackageAndP2PReference.StaticWebAssets.xml")).Should().Exist();
            new FileInfo(Path.Combine(intermediateOutputPath, "staticwebassets", "AppWithPackageAndP2PReference.StaticWebAssets.Manifest.cache")).Should().Exist();

            var directoryPath   = Path.Combine(intermediateOutputPath, "staticwebassets");
            var thumbPrints     = new Dictionary <string, FileThumbPrint>();
            var thumbPrintFiles = new[]
            {
                Path.Combine(directoryPath, "AppWithPackageAndP2PReference.StaticWebAssets.xml"),
                Path.Combine(directoryPath, "AppWithPackageAndP2PReference.StaticWebAssets.Manifest.cache"),
            };

            foreach (var file in thumbPrintFiles)
            {
                var thumbprint = FileThumbPrint.Create(file);
                thumbPrints[file] = thumbprint;
            }

            // Act
            var incremental = new MSBuildCommand(Log, "GenerateStaticWebAssetsManifest", projectDirectory.Path, "AppWithPackageAndP2PReference");

            // Assert
            incremental.Execute().Should().Pass();

            foreach (var file in thumbPrintFiles)
            {
                var thumbprint = FileThumbPrint.Create(file);
                Assert.Equal(thumbPrints[file], thumbprint);
            }
        }
Ejemplo n.º 12
0
        public void Publish_UpdatesFilesWhenSourcesChange()
        {
            // Arrange
            var testAppName  = "BlazorHosted";
            var testInstance = _testAssetsManager.CopyTestAsset(testAppName)
                               .WithSource();

            var publishCommand = new PublishCommand(Log, Path.Combine(testInstance.TestRoot, "blazorhosted"));

            publishCommand.Execute().Should().Pass();

            // Act
            var mainAppDll                     = Path.Combine(testInstance.TestRoot, "blazorhosted", "bin", "Debug", "net5.0", "publish", "wwwroot", "_framework", "blazorwasm.dll");
            var mainAppDllThumbPrint           = FileThumbPrint.Create(mainAppDll);
            var mainAppCompressedDll           = Path.Combine(testInstance.TestRoot, "blazorhosted", "bin", "Debug", "net5.0", "publish", "wwwroot", "_framework", "blazorwasm.dll.br");
            var mainAppCompressedDllThumbPrint = FileThumbPrint.Create(mainAppCompressedDll);

            var blazorBootJson                     = Path.Combine(testInstance.TestRoot, publishCommand.GetOutputDirectory("net5.0").ToString(), "wwwroot", "_framework", "blazor.boot.json");
            var blazorBootJsonThumbPrint           = FileThumbPrint.Create(blazorBootJson);
            var blazorBootJsonCompressed           = Path.Combine(testInstance.TestRoot, publishCommand.GetOutputDirectory("net5.0").ToString(), "wwwroot", "_framework", "blazor.boot.json.br");
            var blazorBootJsonCompressedThumbPrint = FileThumbPrint.Create(blazorBootJsonCompressed);

            var programFile         = Path.Combine(testInstance.TestRoot, "blazorwasm", "Program.cs");
            var programFileContents = File.ReadAllText(programFile);

            File.WriteAllText(programFile, programFileContents.Replace("args", "arguments"));

            // Assert
            publishCommand = new PublishCommand(Log, Path.Combine(testInstance.TestRoot, "blazorhosted"));
            publishCommand.Execute().Should().Pass();

            var newMainAppDllThumbPrint               = FileThumbPrint.Create(mainAppDll);
            var newMainAppCompressedDllThumbPrint     = FileThumbPrint.Create(mainAppCompressedDll);
            var newBlazorBootJsonThumbPrint           = FileThumbPrint.Create(blazorBootJson);
            var newBlazorBootJsonCompressedThumbPrint = FileThumbPrint.Create(blazorBootJsonCompressed);

            Assert.NotEqual(mainAppDllThumbPrint, newMainAppDllThumbPrint);
            Assert.NotEqual(mainAppCompressedDllThumbPrint, newMainAppCompressedDllThumbPrint);

            Assert.NotEqual(blazorBootJsonThumbPrint, newBlazorBootJsonThumbPrint);
            Assert.NotEqual(blazorBootJsonCompressedThumbPrint, newBlazorBootJsonCompressedThumbPrint);
        }
Ejemplo n.º 13
0
        public void Build_ScopedCssTransformation_AndBundling_IsIncremental()
        {
            // Arrange
            var thumbprintLookup = new Dictionary <string, FileThumbPrint>();

            var testAsset        = "RazorComponentApp";
            var projectDirectory = CreateAspNetSdkTestAsset(testAsset);

            // Act & Assert 1
            var build = new BuildCommand(projectDirectory);

            build.Execute("/p:_RazorSourceGeneratorWriteGeneratedOutput=true").Should().Pass();

            var intermediateOutputPath = Path.Combine(build.GetBaseIntermediateDirectory().ToString(), "Debug", DefaultTfm);
            var directoryPath          = Path.Combine(intermediateOutputPath, "scopedcss");

            var files = Directory.GetFiles(directoryPath, "*", SearchOption.AllDirectories);

            foreach (var file in files)
            {
                var thumbprint = FileThumbPrint.Create(file);
                thumbprintLookup[file] = thumbprint;
            }

            // Act & Assert 2
            for (var i = 0; i < 2; i++)
            {
                // We want to make sure nothing changed between multiple incremental builds.
                using (var razorGenDirectoryLock = LockDirectory(Path.Combine(intermediateOutputPath, "Razor")))
                {
                    build = new BuildCommand(projectDirectory);
                    build.Execute().Should().Pass();
                }

                foreach (var file in files)
                {
                    var thumbprint = FileThumbPrint.Create(file);
                    Assert.Equal(thumbprintLookup[file], thumbprint);
                }
            }
        }
Ejemplo n.º 14
0
        public void Build_JsModules_IsIncremental()
        {
            // Arrange
            var thumbprintLookup = new Dictionary <string, FileThumbPrint>();

            var testAsset        = "RazorComponentApp";
            var projectDirectory = CreateAspNetSdkTestAsset(testAsset);

            Directory.CreateDirectory(Path.Combine(projectDirectory.TestRoot, "wwwroot"));
            File.WriteAllText(Path.Combine(projectDirectory.TestRoot, "wwwroot", "ComponentApp.lib.module.js"), "console.log('Hello world!');");

            // Act & Assert 1
            var build = new BuildCommand(projectDirectory);

            build.Execute().Should().Pass();

            var intermediateOutputPath = Path.Combine(build.GetBaseIntermediateDirectory().ToString(), "Debug", DefaultTfm);
            var directoryPath          = Path.Combine(intermediateOutputPath, "jsmodules");

            var files = Directory.GetFiles(directoryPath, "*", SearchOption.AllDirectories);

            foreach (var file in files)
            {
                var thumbprint = FileThumbPrint.Create(file);
                thumbprintLookup[file] = thumbprint;
            }

            // Act & Assert 2
            for (var i = 0; i < 2; i++)
            {
                build = new BuildCommand(projectDirectory);
                build.Execute().Should().Pass();

                foreach (var file in files)
                {
                    var thumbprint = FileThumbPrint.Create(file);
                    Assert.Equal(thumbprintLookup[file], thumbprint);
                }
            }
        }
Ejemplo n.º 15
0
        public void Build_ScopedCssTransformation_AndBundling_IsIncremental()
        {
            // Arrange
            var thumbprintLookup = new Dictionary <string, FileThumbPrint>();

            var testAsset        = "RazorComponentApp";
            var projectDirectory = CreateAspNetSdkTestAsset(testAsset);

            // Act & Assert 1
            var build = new BuildCommand(projectDirectory);

            build.Execute().Should().Pass();

            var intermediateOutputPath = Path.Combine(build.GetBaseIntermediateDirectory().ToString(), "Debug", DefaultTfm);
            var directoryPath          = Path.Combine(intermediateOutputPath, "scopedcss");

            var files = Directory.GetFiles(directoryPath, "*", SearchOption.AllDirectories);

            foreach (var file in files)
            {
                var thumbprint = FileThumbPrint.Create(file);
                thumbprintLookup[file] = thumbprint;
            }

            // Act & Assert 2
            for (var i = 0; i < 2; i++)
            {
                build = new BuildCommand(projectDirectory);
                build.Execute().Should().Pass();

                foreach (var file in files)
                {
                    var thumbprint = FileThumbPrint.Create(file);
                    Assert.Equal(thumbprintLookup[file], thumbprint);
                }
            }
        }
Ejemplo n.º 16
0
        public void BuildComponents_RegeneratesComponentDefinition_WhenFilesChange()
        {
            var testAsset        = "RazorMvcWithComponents";
            var projectDirectory = CreateRazorSdkTestAsset(testAsset);

            var build = new BuildCommand(projectDirectory);

            var intermediateOutputPath = build.GetIntermediateDirectory(DefaultTfm, "Debug").ToString();
            var outputPath             = build.GetOutputDirectory(DefaultTfm, "Debug").ToString();

            // Act - 1
            var updatedContent       = "@code { [Parameter] public string AParameter { get; set; } }";
            var tagHelperOutputCache = Path.Combine(intermediateOutputPath, "MvcWithComponents.TagHelpers.output.cache");

            var generatedFile           = Path.Combine(intermediateOutputPath, "Razor", "Views", "Shared", "NavMenu.razor.g.cs");
            var generatedDefinitionFile = Path.Combine(intermediateOutputPath, "RazorDeclaration", "Views", "Shared", "NavMenu.razor.g.cs");

            // Assert - 1
            var result = build.Execute();

            result.Should().Pass();
            var outputFile = Path.Combine(outputPath, "MvcWithComponents.dll");

            new FileInfo(outputFile).Should().Exist();
            var outputAssemblyThumbprint = FileThumbPrint.Create(outputFile);

            new FileInfo(generatedDefinitionFile).Should().Exist();
            var generatedDefinitionThumbprint = FileThumbPrint.Create(generatedDefinitionFile);

            new FileInfo(generatedFile).Should().Exist();
            var generatedFileThumbprint = FileThumbPrint.Create(generatedFile);

            new FileInfo(tagHelperOutputCache).Should().Exist();
            new FileInfo(tagHelperOutputCache).Should().Contain(@"""Name"":""MvcWithComponents.Views.Shared.NavMenu""");

            var definitionThumbprint = FileThumbPrint.Create(tagHelperOutputCache);

            // Act - 2
            var page = Path.Combine(projectDirectory.Path, "Views", "Shared", "NavMenu.razor");

            File.WriteAllText(page, updatedContent);

            build  = new BuildCommand(projectDirectory);
            result = build.Execute();

            // Assert - 2
            new FileInfo(outputFile).Should().Exist();
            Assert.NotEqual(outputAssemblyThumbprint, FileThumbPrint.Create(outputFile));

            new FileInfo(generatedDefinitionFile).Should().Exist();
            Assert.NotEqual(generatedDefinitionThumbprint, FileThumbPrint.Create(generatedDefinitionFile));
            new FileInfo(generatedFile).Should().Exist();
            Assert.NotEqual(generatedFileThumbprint, FileThumbPrint.Create(generatedFile));

            new FileInfo(tagHelperOutputCache).Should().Exist();
            new FileInfo(tagHelperOutputCache).Should().Contain(@"""Name"":""MvcWithComponents.Views.Shared.NavMenu""");

            new FileInfo(tagHelperOutputCache).Should().Contain("AParameter");

            Assert.NotEqual(definitionThumbprint, FileThumbPrint.Create(tagHelperOutputCache));
        }