|
1 | 1 | // Copyright (c) .NET Foundation. All rights reserved.
|
2 | 2 | // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
3 | 3 |
|
| 4 | +using System.IO; |
| 5 | +using System.Text.Json; |
4 | 6 | using System.Threading.Tasks;
|
5 | 7 | using Xunit;
|
6 | 8 |
|
@@ -36,5 +38,122 @@ public async Task Build_WithLinker_IsIncremental()
|
36 | 38 | }
|
37 | 39 | }
|
38 | 40 | }
|
| 41 | + |
| 42 | + [Fact] |
| 43 | + public async Task Build_SatelliteAssembliesFileIsPreserved() |
| 44 | + { |
| 45 | + // Arrange |
| 46 | + using var project = ProjectDirectory.Create("standalone", additionalProjects: new[] { "razorclasslibrary" }); |
| 47 | + File.Move(Path.Combine(project.DirectoryPath, "Resources.ja.resx.txt"), Path.Combine(project.DirectoryPath, "Resource.ja.resx")); |
| 48 | + var result = await MSBuildProcessManager.DotnetMSBuild(project); |
| 49 | + |
| 50 | + Assert.BuildPassed(result); |
| 51 | + |
| 52 | + var satelliteAssemblyCacheFile = Path.Combine(project.IntermediateOutputDirectory, "blazor", "blazor.satelliteasm.props"); |
| 53 | + var satelliteAssemblyFile = Path.Combine(project.BuildOutputDirectory, "wwwroot", "_framework", "_bin", "ja", "standalone.resources.dll"); |
| 54 | + var bootJson = Path.Combine(project.DirectoryPath, project.BuildOutputDirectory, "wwwroot", "_framework", "blazor.boot.json"); |
| 55 | + |
| 56 | + // Assert |
| 57 | + for (var i = 0; i < 3; i++) |
| 58 | + { |
| 59 | + result = await MSBuildProcessManager.DotnetMSBuild(project); |
| 60 | + Assert.BuildPassed(result); |
| 61 | + |
| 62 | + Verify(); |
| 63 | + } |
| 64 | + |
| 65 | + // Assert - incremental builds with BuildingProject=false |
| 66 | + for (var i = 0; i < 3; i++) |
| 67 | + { |
| 68 | + result = await MSBuildProcessManager.DotnetMSBuild(project, args: "/p:BuildingProject=false"); |
| 69 | + Assert.BuildPassed(result); |
| 70 | + |
| 71 | + Verify(); |
| 72 | + } |
| 73 | + |
| 74 | + void Verify() |
| 75 | + { |
| 76 | + Assert.FileExists(result, satelliteAssemblyCacheFile); |
| 77 | + Assert.FileExists(result, satelliteAssemblyFile); |
| 78 | + |
| 79 | + var bootJsonFile = JsonSerializer.Deserialize<GenerateBlazorBootJson.BootJsonData>(File.ReadAllText(bootJson), new JsonSerializerOptions { PropertyNameCaseInsensitive = true }); |
| 80 | + var satelliteResources = bootJsonFile.resources.satelliteResources; |
| 81 | + var kvp = Assert.Single(satelliteResources); |
| 82 | + Assert.Equal("ja", kvp.Key); |
| 83 | + Assert.Equal("ja/standalone.resources.dll", Assert.Single(kvp.Value).Key); |
| 84 | + } |
| 85 | + } |
| 86 | + |
| 87 | + [Fact] |
| 88 | + public async Task Build_SatelliteAssembliesFileIsCreated_IfNewFileIsAdded() |
| 89 | + { |
| 90 | + // Arrange |
| 91 | + using var project = ProjectDirectory.Create("standalone", additionalProjects: new[] { "razorclasslibrary" }); |
| 92 | + var result = await MSBuildProcessManager.DotnetMSBuild(project); |
| 93 | + |
| 94 | + Assert.BuildPassed(result); |
| 95 | + |
| 96 | + var satelliteAssemblyCacheFile = Path.Combine(project.IntermediateOutputDirectory, "blazor", "blazor.satelliteasm.props"); |
| 97 | + var satelliteAssemblyFile = Path.Combine(project.BuildOutputDirectory, "wwwroot", "_framework", "_bin", "ja", "standalone.resources.dll"); |
| 98 | + var bootJson = Path.Combine(project.DirectoryPath, project.BuildOutputDirectory, "wwwroot", "_framework", "blazor.boot.json"); |
| 99 | + |
| 100 | + result = await MSBuildProcessManager.DotnetMSBuild(project); |
| 101 | + Assert.BuildPassed(result); |
| 102 | + |
| 103 | + Assert.FileDoesNotExist(result, satelliteAssemblyCacheFile); |
| 104 | + Assert.FileDoesNotExist(result, satelliteAssemblyFile); |
| 105 | + var bootJsonFile = JsonSerializer.Deserialize<GenerateBlazorBootJson.BootJsonData>(File.ReadAllText(bootJson), new JsonSerializerOptions { PropertyNameCaseInsensitive = true }); |
| 106 | + var satelliteResources = bootJsonFile.resources.satelliteResources; |
| 107 | + Assert.Null(satelliteResources); |
| 108 | + |
| 109 | + File.Move(Path.Combine(project.DirectoryPath, "Resources.ja.resx.txt"), Path.Combine(project.DirectoryPath, "Resource.ja.resx")); |
| 110 | + result = await MSBuildProcessManager.DotnetMSBuild(project); |
| 111 | + Assert.BuildPassed(result); |
| 112 | + |
| 113 | + Assert.FileExists(result, satelliteAssemblyCacheFile); |
| 114 | + Assert.FileExists(result, satelliteAssemblyFile); |
| 115 | + bootJsonFile = JsonSerializer.Deserialize<GenerateBlazorBootJson.BootJsonData>(File.ReadAllText(bootJson), new JsonSerializerOptions { PropertyNameCaseInsensitive = true }); |
| 116 | + satelliteResources = bootJsonFile.resources.satelliteResources; |
| 117 | + var kvp = Assert.Single(satelliteResources); |
| 118 | + Assert.Equal("ja", kvp.Key); |
| 119 | + Assert.Equal("ja/standalone.resources.dll", Assert.Single(kvp.Value).Key); |
| 120 | + } |
| 121 | + |
| 122 | + [Fact] |
| 123 | + public async Task Build_SatelliteAssembliesFileIsDeleted_IfAllSatelliteFilesAreRemoved() |
| 124 | + { |
| 125 | + // Arrange |
| 126 | + using var project = ProjectDirectory.Create("standalone", additionalProjects: new[] { "razorclasslibrary" }); |
| 127 | + File.Move(Path.Combine(project.DirectoryPath, "Resources.ja.resx.txt"), Path.Combine(project.DirectoryPath, "Resource.ja.resx")); |
| 128 | + |
| 129 | + var result = await MSBuildProcessManager.DotnetMSBuild(project); |
| 130 | + |
| 131 | + Assert.BuildPassed(result); |
| 132 | + |
| 133 | + var satelliteAssemblyCacheFile = Path.Combine(project.IntermediateOutputDirectory, "blazor", "blazor.satelliteasm.props"); |
| 134 | + var satelliteAssemblyFile = Path.Combine(project.BuildOutputDirectory, "wwwroot", "_framework", "_bin", "ja", "standalone.resources.dll"); |
| 135 | + var bootJson = Path.Combine(project.DirectoryPath, project.BuildOutputDirectory, "wwwroot", "_framework", "blazor.boot.json"); |
| 136 | + |
| 137 | + result = await MSBuildProcessManager.DotnetMSBuild(project); |
| 138 | + Assert.BuildPassed(result); |
| 139 | + |
| 140 | + Assert.FileExists(result, satelliteAssemblyCacheFile); |
| 141 | + Assert.FileExists(result, satelliteAssemblyFile); |
| 142 | + var bootJsonFile = JsonSerializer.Deserialize<GenerateBlazorBootJson.BootJsonData>(File.ReadAllText(bootJson), new JsonSerializerOptions { PropertyNameCaseInsensitive = true }); |
| 143 | + var satelliteResources = bootJsonFile.resources.satelliteResources; |
| 144 | + var kvp = Assert.Single(satelliteResources); |
| 145 | + Assert.Equal("ja", kvp.Key); |
| 146 | + Assert.Equal("ja/standalone.resources.dll", Assert.Single(kvp.Value).Key); |
| 147 | + |
| 148 | + |
| 149 | + File.Delete(Path.Combine(project.DirectoryPath, "Resource.ja.resx")); |
| 150 | + result = await MSBuildProcessManager.DotnetMSBuild(project); |
| 151 | + Assert.BuildPassed(result); |
| 152 | + |
| 153 | + Assert.FileDoesNotExist(result, satelliteAssemblyCacheFile); |
| 154 | + bootJsonFile = JsonSerializer.Deserialize<GenerateBlazorBootJson.BootJsonData>(File.ReadAllText(bootJson), new JsonSerializerOptions { PropertyNameCaseInsensitive = true }); |
| 155 | + satelliteResources = bootJsonFile.resources.satelliteResources; |
| 156 | + Assert.Null(satelliteResources); |
| 157 | + } |
39 | 158 | }
|
40 | 159 | }
|
0 commit comments