Skip to content

Commit bf14bce

Browse files
authored
Rename project.assets.json to test.assets.json (#10060)
* Rename project.assets.json to test.assets.json * Copy files to output * update comment
1 parent e474e0b commit bf14bce

File tree

5 files changed

+51
-105
lines changed

5 files changed

+51
-105
lines changed

test/WebJobs.Script.Tests/Description/DotNet/PackageManagerTests.cs

Lines changed: 39 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,15 @@
11
// Copyright (c) .NET Foundation. All rights reserved.
22
// Licensed under the MIT License. See License.txt in the project root for license information.
33

4-
using System;
54
using System.IO;
65
using Microsoft.Azure.WebJobs.Script.Config;
76
using Microsoft.Azure.WebJobs.Script.Description;
8-
using WebJobs.Script.Tests;
97
using Xunit;
108

119
namespace Microsoft.Azure.WebJobs.Script.Tests
1210
{
1311
public class PackageManagerTests
1412
{
15-
private static readonly ScriptSettingsManager SettingsManager = ScriptSettingsManager.Instance;
16-
1713
[Theory]
1814
[InlineData(@"ProjectWithLockMatch", false)]
1915
[InlineData(@"FunctionWithNoProject", false)]
@@ -23,20 +19,51 @@ public class PackageManagerTests
2319
public void RequirePackageRestore_ReturnsExpectedResult(string projectPath, bool shouldRequireRestore)
2420
{
2521
projectPath = Path.Combine(Directory.GetCurrentDirectory(), "Description", "DotNet", "TestFiles", "PackageReferences", projectPath);
26-
bool result = PackageManager.RequiresPackageRestore(projectPath);
22+
try
23+
{
24+
CopyLockFile(projectPath);
25+
bool result = PackageManager.RequiresPackageRestore(projectPath);
26+
27+
Assert.True(Directory.Exists(projectPath));
2728

28-
Assert.True(Directory.Exists(projectPath));
29+
string message = $"Project in '{projectPath}' did not return expected result.";
30+
31+
// Using .True or .False (instead of .Equal) to trace additional information.
32+
if (shouldRequireRestore)
33+
{
34+
Assert.True(result, message);
35+
}
36+
else
37+
{
38+
Assert.False(result, message);
39+
}
40+
}
41+
finally
42+
{
43+
DeleteLockFile(projectPath);
44+
}
45+
}
2946

30-
string message = $"Project in '{projectPath}' did not return expected result.";
47+
private static void CopyLockFile(string projectPath)
48+
{
49+
// We save the lock file as something other than 'project.assets.json' so it is not flagged by component governance.
50+
// Only renaming to project.assets.json for the duration of the test.
51+
string lockFile = Path.Combine(projectPath, DotNetConstants.ProjectLockFileName);
52+
string sourceFile = Path.Combine(projectPath, "test.assets.json");
3153

32-
// Using .True or .False (instead of .Equal) to trace additional information.
33-
if (shouldRequireRestore)
54+
if (File.Exists(sourceFile))
3455
{
35-
Assert.True(result, message);
56+
File.Copy(sourceFile, lockFile, true);
3657
}
37-
else
58+
}
59+
60+
private static void DeleteLockFile(string projectPath)
61+
{
62+
// Clean up the 'project.assets.json' file so component governance does not flag it.
63+
string lockFile = Path.Combine(projectPath, DotNetConstants.ProjectLockFileName);
64+
if (File.Exists(lockFile))
3865
{
39-
Assert.False(result, message);
66+
File.Delete(lockFile);
4067
}
4168
}
4269
}

test/WebJobs.Script.Tests/WebJobs.Script.Tests.csproj

Lines changed: 12 additions & 93 deletions
Original file line numberDiff line numberDiff line change
@@ -28,24 +28,9 @@
2828
</ItemGroup>
2929

3030
<ItemGroup>
31-
<None Include="..\WebJobs.Script.Tests.Integration\TestScripts\**\*.*">
32-
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
33-
<Link>TestScripts\%(RecursiveDir)%(Filename)%(Extension)</Link>
34-
</None>
35-
</ItemGroup>
36-
37-
<ItemGroup>
38-
<None Include="Description\DotNet\TestFiles\PackageReferences\ProjectWithLockMatch\function.proj">
39-
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
40-
</None>
41-
<None Include="Description\DotNet\TestFiles\PackageReferences\ProjectWithMismatchedLock\MismatchedPackageVersions\function.proj">
42-
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
43-
</None>
44-
<None Include="Description\DotNet\TestFiles\PackageReferences\ProjectWithMismatchedLock\MismatchedProjectDependencies\function.proj">
45-
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
46-
</None>
47-
<None Include="Description\DotNet\TestFiles\PackageReferences\ProjectWithoutLock\function.proj">
31+
<None Include="..\WebJobs.Script.Tests.Integration\TestScripts\**">
4832
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
33+
<LinkBase>TestScripts</LinkBase>
4934
</None>
5035
</ItemGroup>
5136

@@ -58,7 +43,7 @@
5843
<PackageReference Include="appinsights.testlogger" Version="1.0.0" />
5944
<PackageReference Include="FluentAssertions" Version="5.9.0" />
6045
<PackageReference Include="Microsoft.AspNetCore.TestHost" Version="8.0.0" />
61-
<PackageReference Include="Microsoft.Extensions.Diagnostics.Testing" Version="8.1.0" />
46+
<PackageReference Include="Microsoft.Extensions.Diagnostics.Testing" Version="8.1.0" />
6247
<PackageReference Include="Microsoft.Azure.Functions.PythonWorker" Version="4.28.1" />
6348
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.9.4" />
6449
<PackageReference Include="Moq" Version="4.9.0" />
@@ -88,84 +73,18 @@
8873
</ItemGroup>
8974

9075
<ItemGroup>
91-
<None Update="Description\DotNet\TestFiles\DepsFiles\function.deps.json">
92-
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
93-
</None>
94-
<None Update="Description\DotNet\TestFiles\DepsFiles\function2.deps.json">
95-
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
96-
</None>
97-
<None Update="Description\DotNet\TestFiles\DepsFiles\RidNativeDeps\function.deps.json">
98-
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
99-
</None>
100-
<None Update="Description\DotNet\TestFiles\PackageReferences\FunctionWithNoProject\function.json">
101-
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
102-
</None>
103-
<None Update="Description\DotNet\TestFiles\PackageReferences\ProjectWithLockMatch\project.assets.json">
104-
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
105-
</None>
106-
<None Update="Description\DotNet\TestFiles\PackageReferences\ProjectWithMismatchedLock\MismatchedPackageVersions\project.lock.json">
107-
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
108-
</None>
109-
<None Update="Description\DotNet\TestFiles\PackageReferences\ProjectWithMismatchedLock\MismatchedProjectDependencies\project.assets.json">
110-
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
111-
</None>
112-
<None Update="Managment\Payloads\ExpectedConcurrencyPayload.json">
113-
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
114-
</None>
115-
<None Update="Managment\Payloads\ExpectedHostJsonPayload.json">
116-
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
117-
</None>
118-
<None Update="Managment\Payloads\ExpectedHttpExtensionsPayload.json">
119-
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
120-
</None>
121-
<None Update="Microsoft.Azure.WebJobs.Script.WebHost.deps.json">
122-
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
123-
</None>
124-
<None Update="TestFixture\HostOptionsProviderTests\TestBasicBindings.json">
125-
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
126-
</None>
127-
<None Update="TestFixture\HostOptionsProviderTests\TestBasicConcurrency.json">
128-
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
129-
</None>
130-
<None Update="TestFixture\HostOptionsProviderTests\TestDefaultConcurrency.json">
131-
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
132-
</None>
133-
<None Update="TestFixture\HostOptionsProviderTests\TestIrregularNamingBindings.json">
134-
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
135-
</None>
136-
<None Update="TestFixture\HostOptionsProviderTests\TestMultipleBindings.json">
137-
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
138-
</None>
139-
<None Update="TestFixture\HostOptionsProviderTests\TestWihtoutExtensionsAttributeBindings.json">
140-
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
141-
</None>
142-
<None Update="TestFixture\HostOptionsProviderTests\TestWihtoutIOptionsFormatter.json">
143-
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
144-
</None>
145-
<None Update="Workers\Rpc\Resources\functions.png">
146-
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
147-
</None>
148-
<None Update="xunit.runner.json">
149-
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
150-
</None>
151-
</ItemGroup>
152-
153-
<ItemGroup>
154-
<None Remove="Resources\FileProvisioning\PowerShell\PSGalleryEmptyFeed.xml" />
155-
<None Remove="Resources\FileProvisioning\PowerShell\PSGallerySampleFeed.xml" />
156-
<None Remove="Resources\FileProvisioning\PowerShell\requirements_PSGalleryOffline.psd1" />
157-
<None Remove="Resources\FileProvisioning\PowerShell\requirements_PSGalleryOnline.psd1" />
158-
<None Remove="Resources\FileProvisioning\PowerShell\profile.ps1" />
76+
<None Include="Description\DotNet\TestFiles\**\*.proj" />
77+
<None Update="Description\DotNet\TestFiles\**" CopyToOutputDirectory="PreserveNewest" />
78+
<None Update="Microsoft.Azure.WebJobs.Script.WebHost.deps.json" CopyToOutputDirectory="PreserveNewest" />
79+
<None Update="TestFixture\HostOptionsProviderTests\*.json" CopyToOutputDirectory="PreserveNewest" />
80+
<None Update="Workers\Rpc\Resources\**" CopyToOutputDirectory="PreserveNewest" />
81+
<None Update="xunit.runner.json" CopyToOutputDirectory="PreserveNewest" />
82+
<None Remove="Resources\FileProvisioning\PowerShell\*" />
15983
</ItemGroup>
16084

16185
<ItemGroup>
162-
<EmbeddedResource Include="Resources\FileProvisioning\PowerShell\PSGallerySampleFeed.xml" />
163-
<EmbeddedResource Include="Resources\FileProvisioning\PowerShell\PSGalleryEmptyFeed.xml" />
164-
<EmbeddedResource Include="Resources\FileProvisioning\PowerShell\requirements_PSGalleryOffline.psd1" />
165-
<EmbeddedResource Include="Resources\FileProvisioning\PowerShell\requirements_PSGalleryOnline.psd1" />
166-
<EmbeddedResource Include="Resources\FileProvisioning\PowerShell\profile.ps1">
167-
<CopyToOutputDirectory>Never</CopyToOutputDirectory>
168-
</EmbeddedResource>
86+
<EmbeddedResource Include="Resources\FileProvisioning\PowerShell\*" />
87+
<EmbeddedResource Update="Resources\FileProvisioning\PowerShell\profile.ps1" CopyToOutputDirectory="Never" />
16988
</ItemGroup>
17089

17190
<Import Project="..\..\build\GrpcTestFix.targets" />

0 commit comments

Comments
 (0)