Skip to content

Commit 9c7a8b6

Browse files
committed
wip
1 parent 7fa954c commit 9c7a8b6

File tree

5 files changed

+13
-51
lines changed

5 files changed

+13
-51
lines changed

src/UnityNuGet.Tests/NativeTests.cs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,9 @@
22
using System.IO;
33
using System.Threading;
44
using System.Threading.Tasks;
5-
using Microsoft.Extensions.Hosting;
65
using Microsoft.Extensions.Logging;
76
using Microsoft.Extensions.Logging.Testing;
87
using Microsoft.Extensions.Options;
9-
using Moq;
108
using NUnit.Framework;
119
using UnityNuGet.Npm;
1210

@@ -18,9 +16,6 @@ public class NativeTests
1816
[Test]
1917
public async Task TestBuild()
2018
{
21-
Mock<IHostEnvironment> hostEnvironmentMock = new();
22-
hostEnvironmentMock.Setup(h => h.EnvironmentName).Returns(Environments.Development);
23-
2419
LoggerFactory loggerFactory = new();
2520
loggerFactory.AddProvider(new FakeLoggerProvider());
2621

@@ -29,7 +24,7 @@ public async Task TestBuild()
2924

3025
bool errorsTriggered = false;
3126

32-
Registry registry = new(hostEnvironmentMock.Object, loggerFactory, Options.Create(new RegistryOptions { RegistryFilePath = "registry.json" }));
27+
Registry registry = new(loggerFactory, Options.Create(new RegistryOptions { RegistryFilePath = "registry.json" }));
3328

3429
await registry.StartAsync(CancellationToken.None);
3530

src/UnityNuGet.Tests/RegistryCacheTests.cs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,9 @@
22
using System.IO;
33
using System.Threading;
44
using System.Threading.Tasks;
5-
using Microsoft.Extensions.Hosting;
65
using Microsoft.Extensions.Logging;
76
using Microsoft.Extensions.Logging.Testing;
87
using Microsoft.Extensions.Options;
9-
using Moq;
108
using NuGet.Versioning;
119
using NUnit.Framework;
1210
using UnityNuGet.Npm;
@@ -31,14 +29,11 @@ public async Task TestBuild()
3129
{
3230
bool errorsTriggered = false;
3331

34-
Mock<IHostEnvironment> hostEnvironmentMock = new();
35-
hostEnvironmentMock.Setup(h => h.EnvironmentName).Returns(Environments.Development);
36-
3732
LoggerFactory loggerFactory = new();
3833
loggerFactory.AddProvider(new FakeLoggerProvider());
3934

4035
string unityPackages = Path.Combine(Path.GetDirectoryName(typeof(RegistryCacheTests).Assembly.Location)!, "unity_packages");
41-
Registry registry = new(hostEnvironmentMock.Object, loggerFactory, Options.Create(new RegistryOptions { RegistryFilePath = "registry.json" }));
36+
Registry registry = new(loggerFactory, Options.Create(new RegistryOptions { RegistryFilePath = "registry.json" }));
4237

4338
await registry.StartAsync(CancellationToken.None);
4439

src/UnityNuGet.Tests/RegistryTests.cs

Lines changed: 7 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,12 @@
11
using System.Collections.Generic;
22
using System.IO;
33
using System.Linq;
4-
using System.Text;
54
using System.Text.RegularExpressions;
65
using System.Threading;
76
using System.Threading.Tasks;
8-
using Microsoft.Extensions.Hosting;
97
using Microsoft.Extensions.Logging;
108
using Microsoft.Extensions.Logging.Testing;
119
using Microsoft.Extensions.Options;
12-
using Moq;
1310
using NuGet.Configuration;
1411
using NuGet.PackageManagement;
1512
using NuGet.Packaging;
@@ -31,13 +28,10 @@ public class RegistryTests
3128
[TestCase("Scriban")]
3229
public async Task Make_Sure_That_The_Registry_Is_Case_Insensitive(string packageName)
3330
{
34-
Mock<IHostEnvironment> hostEnvironmentMock = new();
35-
hostEnvironmentMock.Setup(h => h.EnvironmentName).Returns(Environments.Development);
36-
3731
LoggerFactory loggerFactory = new();
3832
loggerFactory.AddProvider(new FakeLoggerProvider());
3933

40-
Registry registry = new(hostEnvironmentMock.Object, loggerFactory, Options.Create(s_registryOptions));
34+
Registry registry = new(loggerFactory, Options.Create(s_registryOptions));
4135

4236
await registry.StartAsync(CancellationToken.None);
4337

@@ -51,13 +45,10 @@ public async Task Make_Sure_That_The_Registry_Is_Case_Insensitive(string package
5145
[Test]
5246
public async Task Make_Sure_That_The_Order_In_The_Registry_Is_Respected()
5347
{
54-
Mock<IHostEnvironment> hostEnvironmentMock = new();
55-
hostEnvironmentMock.Setup(h => h.EnvironmentName).Returns(Environments.Development);
56-
5748
LoggerFactory loggerFactory = new();
5849
loggerFactory.AddProvider(new FakeLoggerProvider());
5950

60-
Registry registry = new(hostEnvironmentMock.Object, loggerFactory, Options.Create(s_registryOptions));
51+
Registry registry = new(loggerFactory, Options.Create(s_registryOptions));
6152

6253
await registry.StartAsync(CancellationToken.None);
6354

@@ -70,13 +61,10 @@ public async Task Make_Sure_That_The_Order_In_The_Registry_Is_Respected()
7061
[Test]
7162
public async Task Ensure_That_Packages_Already_Included_In_Net_Standard_Are_not_Included_In_The_Registry()
7263
{
73-
Mock<IHostEnvironment> hostEnvironmentMock = new();
74-
hostEnvironmentMock.Setup(h => h.EnvironmentName).Returns(Environments.Development);
75-
7664
LoggerFactory loggerFactory = new();
7765
loggerFactory.AddProvider(new FakeLoggerProvider());
7866

79-
Registry registry = new(hostEnvironmentMock.Object, loggerFactory, Options.Create(s_registryOptions));
67+
Registry registry = new(loggerFactory, Options.Create(s_registryOptions));
8068

8169
await registry.StartAsync(CancellationToken.None);
8270

@@ -138,19 +126,16 @@ public async Task CanParse_PackageWithRuntimes()
138126

139127
static async Task<TestCaseData[]> AllRegistries()
140128
{
141-
Mock<IHostEnvironment> hostEnvironmentMock = new ();
142-
hostEnvironmentMock.Setup(h => h.EnvironmentName).Returns(Environments.Development);
143-
144-
LoggerFactory loggerFactory = new ();
129+
LoggerFactory loggerFactory = new();
145130
loggerFactory.AddProvider(new FakeLoggerProvider());
146131

147-
Registry registry = new (hostEnvironmentMock.Object, loggerFactory, Options.Create(s_registryOptions));
132+
Registry registry = new(loggerFactory, Options.Create(s_registryOptions));
148133

149-
NuGetConsoleTestLogger logger = new ();
134+
NuGetConsoleTestLogger logger = new();
150135

151136
await registry.StartAsync(CancellationToken.None);
152137

153-
SourceCacheContext cache = new ();
138+
SourceCacheContext cache = new();
154139
SourceRepository repository = Repository.Factory.GetCoreV3("https://api.nuget.org/v3/index.json");
155140
PackageMetadataResource resource = await repository.GetResourceAsync<PackageMetadataResource>();
156141

src/UnityNuGet.Tests/UnityNuGet.Tests.csproj

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,9 @@
1919
</ItemGroup>
2020

2121
<ItemGroup>
22-
<EmbeddedResource Include="..\..\registry.json" />
22+
<EmbeddedResource Include="..\..\registry.json">
23+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
24+
</EmbeddedResource>
2325
<ProjectReference Include="..\UnityNuGet\UnityNuGet.csproj" />
2426
</ItemGroup>
2527

src/UnityNuGet/Registry.cs

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,11 @@ namespace UnityNuGet
1515
/// Loads the `registry.json` file at startup
1616
/// </summary>
1717
public sealed class Registry(
18-
IHostEnvironment hostEnvironment,
1918
ILoggerFactory loggerFactory,
2019
IOptions<RegistryOptions> registryOptionsAccessor) : IHostedService, IReadOnlyCollection<KeyValuePair<string, RegistryEntry>>, IEnumerable<KeyValuePair<string, RegistryEntry>>
2120
{
2221
private IDictionary<string, RegistryEntry>? _data;
2322

24-
private readonly IHostEnvironment _hostEnvironment = hostEnvironment;
2523
private readonly ILoggerFactory _loggerFactory = loggerFactory;
2624
private readonly RegistryOptions _registryOptions = registryOptionsAccessor.Value;
2725

@@ -43,20 +41,7 @@ public async Task StartAsync(CancellationToken cancellationToken)
4341
}
4442
else
4543
{
46-
bool isDevelopment = _hostEnvironment.IsDevelopment();
47-
48-
string currentDirectory;
49-
50-
if (isDevelopment)
51-
{
52-
currentDirectory = Path.GetDirectoryName(AppContext.BaseDirectory)!;
53-
}
54-
else
55-
{
56-
currentDirectory = Directory.GetCurrentDirectory();
57-
}
58-
59-
registryFilePath = Path.Combine(currentDirectory, _registryOptions.RegistryFilePath!);
44+
registryFilePath = Path.Combine(Directory.GetCurrentDirectory(), _registryOptions.RegistryFilePath!);
6045
}
6146

6247
ILogger logger = _loggerFactory.CreateLogger("NuGet");

0 commit comments

Comments
 (0)