Skip to content

Commit

Permalink
Refactor Hosts (again) and Reconcile Project & Solution referecnces. (#…
Browse files Browse the repository at this point in the history
…2225)

♻️ (solution): remove NKDAgility.AzureDevOps.Tools.CommandHost project
and update project references

🔧 (docs): update generated XML documentation to reflect latest commit
and branch information

The NKDAgility.AzureDevOps.Tools.CommandHost project is removed from the
solution to streamline the project structure. This change also updates
the project references to point to the correct paths, ensuring that the
solution builds correctly. The generated XML documentation is updated to
reflect the latest commit and branch information, ensuring that the
documentation is accurate and up-to-date.

♻️ (refactor): update project references and remove unused code

- Update project references to use `MigrationTools.Helpers.Tests`
instead of `MigrationTools.Fakes`.
- Rename `NKDAgility.AzureDevOps.Tools.CommandHost` project to
`MigrationTools.Helpers.Tests`.
- Add new fake classes `FakeMigrationToolVersion` and
`FakeMigrationToolVersionInfo` for testing.
- Replace `RunMigrationTools` with `RunConsoleAsync` in `Program.cs`
files.
- Remove unused `HostExtensions` and `MigrationService` classes.

These changes improve the project structure by consolidating test
helpers into a single project, ensuring consistency in project
references, and removing obsolete code. This refactor enhances
maintainability and clarity in the codebase.

♻️ (MigrationTools.Host): refactor to use
Spectre.Console.Extensions.Hosting and remove redundant services
🔧 (MigrationTools.Host): update project references to reflect new
structure

Refactor the code to use `Spectre.Console.Extensions.Hosting` instead of
`Spectre.Console.Cli.Extensions.DependencyInjection` for better
integration and maintainability. Remove redundant services like
`StartupService` and `DetectVersionService` to simplify the codebase.
Update project references to reflect the new structure, ensuring that
tests and other dependencies are correctly aligned with the changes.
This improves the overall architecture and reduces complexity.

♻️ (tests): update namespace and project references from
MigrationTools.Fakes to MigrationTools.Helpers.Tests

The namespace and project references are updated to reflect the new
location and naming convention for the test helpers. This change
improves code organization and clarity by using a more descriptive and
accurate namespace.
  • Loading branch information
MrHinsh authored Jul 29, 2024
2 parents 86fba5d + 63c5742 commit 859423f
Show file tree
Hide file tree
Showing 33 changed files with 38 additions and 317 deletions.
9 changes: 1 addition & 8 deletions MigrationTools.sln
Original file line number Diff line number Diff line change
Expand Up @@ -126,9 +126,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = ".build", ".build", "{88C358
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Shared", "Shared", "{BB497233-248C-49DF-AE12-F7A76F775E74}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "NKDAgility.AzureDevOps.Tools.CommandHost", "src\NKDAgility.AzureDevOps.Tools.CommandHost\NKDAgility.AzureDevOps.Tools.CommandHost.csproj", "{60EF98A1-5AA4-4589-8B6F-A77B3940025D}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MigrationTools.Helpers.Tests", "src\MigrationTools.Fakes\MigrationTools.Helpers.Tests.csproj", "{EB20ED85-8876-4585-BC90-E6976C11DEE3}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MigrationTools.Helpers.Tests", "src\MigrationTools.Helpers.Tests\MigrationTools.Helpers.Tests.csproj", "{EB20ED85-8876-4585-BC90-E6976C11DEE3}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand Down Expand Up @@ -212,10 +210,6 @@ Global
{6A259EA6-860B-448A-8943-594DC1A15105}.Debug|Any CPU.Build.0 = Debug|Any CPU
{6A259EA6-860B-448A-8943-594DC1A15105}.Release|Any CPU.ActiveCfg = Release|Any CPU
{6A259EA6-860B-448A-8943-594DC1A15105}.Release|Any CPU.Build.0 = Release|Any CPU
{60EF98A1-5AA4-4589-8B6F-A77B3940025D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{60EF98A1-5AA4-4589-8B6F-A77B3940025D}.Debug|Any CPU.Build.0 = Debug|Any CPU
{60EF98A1-5AA4-4589-8B6F-A77B3940025D}.Release|Any CPU.ActiveCfg = Release|Any CPU
{60EF98A1-5AA4-4589-8B6F-A77B3940025D}.Release|Any CPU.Build.0 = Release|Any CPU
{EB20ED85-8876-4585-BC90-E6976C11DEE3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{EB20ED85-8876-4585-BC90-E6976C11DEE3}.Debug|Any CPU.Build.0 = Debug|Any CPU
{EB20ED85-8876-4585-BC90-E6976C11DEE3}.Release|Any CPU.ActiveCfg = Release|Any CPU
Expand Down Expand Up @@ -253,7 +247,6 @@ Global
{6A259EA6-860B-448A-8943-594DC1A15105} = {83F36820-E9BC-4F48-8202-5EAF9530405E}
{AC3B5101-83F5-4C28-976C-C325425D1988} = {1F5E9C8C-AD05-4C4F-B370-FF3D080A6541}
{BB497233-248C-49DF-AE12-F7A76F775E74} = {83F36820-E9BC-4F48-8202-5EAF9530405E}
{60EF98A1-5AA4-4589-8B6F-A77B3940025D} = {BB497233-248C-49DF-AE12-F7A76F775E74}
{EB20ED85-8876-4585-BC90-E6976C11DEE3} = {BB497233-248C-49DF-AE12-F7A76F775E74}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
Expand Down
14 changes: 7 additions & 7 deletions docs/Reference/Generated/MigrationTools.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@

<ItemGroup>
<ProjectReference Include="..\MigrationTools.Clients.AzureDevops.ObjectModel\MigrationTools.Clients.AzureDevops.ObjectModel.csproj" />
<ProjectReference Include="..\MigrationTools.Fakes\MigrationTools.Helpers.Tests.csproj" />
<ProjectReference Include="..\MigrationTools.Helpers.Tests\MigrationTools.Helpers.Tests.csproj" />
<ProjectReference Include="..\MigrationTools.TestExtensions\MigrationTools.TestExtensions.csproj" />
<ProjectReference Include="..\MigrationTools\MigrationTools.csproj" />
</ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using MigrationTools.Endpoints;
using MigrationTools.Fakes;
using MigrationTools.Helpers.Tests;
using MigrationTools.Services;
using MigrationTools.TestExtensions;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@

<ItemGroup>
<ProjectReference Include="..\MigrationTools.Clients.AzureDevops.Rest\MigrationTools.Clients.AzureDevops.Rest.csproj" />
<ProjectReference Include="..\MigrationTools.Fakes\MigrationTools.Fakes.csproj" />
<ProjectReference Include="..\MigrationTools.Fakes\MigrationTools.Helpers.Tests.csproj" />
<ProjectReference Include="..\MigrationTools.Helpers.Tests\MigrationTools.Helpers.Tests.csproj" />
<ProjectReference Include="..\MigrationTools.TestExtensions\MigrationTools.TestExtensions.csproj" />
<ProjectReference Include="..\MigrationTools\MigrationTools.csproj" />
</ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using MigrationTools.Endpoints;
using MigrationTools.Fakes;
using MigrationTools.Helpers.Tests;
using MigrationTools.Services;
using MigrationTools.TestExtensions;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

<ItemGroup>
<ProjectReference Include="..\MigrationTools.Clients.FileSystem\MigrationTools.Clients.FileSystem.csproj" />
<ProjectReference Include="..\MigrationTools.Fakes\MigrationTools.Helpers.Tests.csproj" />
<ProjectReference Include="..\MigrationTools.Helpers.Tests\MigrationTools.Helpers.Tests.csproj" />
<ProjectReference Include="..\MigrationTools.TestExtensions\MigrationTools.TestExtensions.csproj" />
</ItemGroup>

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using Microsoft.Extensions.DependencyInjection;
using MigrationTools.Fakes;
using MigrationTools.Services;
using MigrationTools.TestExtensions;
using MigrationTools.Helpers.Tests;

namespace MigrationTools.Tests
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@

<ItemGroup>
<ProjectReference Include="..\MigrationTools.Clients.InMemory\MigrationTools.Clients.InMemory.csproj" />
<ProjectReference Include="..\MigrationTools.Fakes\MigrationTools.Fakes.csproj" />
<ProjectReference Include="..\MigrationTools.Fakes\MigrationTools.Helpers.Tests.csproj" />
<ProjectReference Include="..\MigrationTools.Helpers.Tests\MigrationTools.Helpers.Tests.csproj" />
<ProjectReference Include="..\MigrationTools.TestExtensions\MigrationTools.TestExtensions.csproj" />
</ItemGroup>

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using Microsoft.Extensions.DependencyInjection;
using MigrationTools.Fakes;
using MigrationTools.Helpers.Tests;
using MigrationTools.Services;
using MigrationTools.TestExtensions;

Expand Down
3 changes: 2 additions & 1 deletion src/MigrationTools.ConsoleCore/Program.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System.Threading.Tasks;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using MigrationTools.Clients.AzureDevops.Rest.FieldMaps;
using MigrationTools.Host;

Expand Down Expand Up @@ -35,7 +36,7 @@ public static async Task Main(string[] args)
// Core
// services.AddTransient<IMigrationClient, MigrationRestClient>();
});
await hostBuilder.RunMigrationTools(args);
await hostBuilder.RunConsoleAsync();
}
}
}
3 changes: 2 additions & 1 deletion src/MigrationTools.ConsoleFull/Program.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Threading.Tasks;
using Microsoft.Extensions.Hosting;
using MigrationTools;
using MigrationTools.Host;

Expand Down Expand Up @@ -27,7 +28,7 @@ public static async Task Main(string[] args)
services.AddMigrationToolServicesForClientLegacyCore();
});

await hostBuilder.RunMigrationTools(args);
await hostBuilder.RunConsoleAsync();
}
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using MigrationTools.Services;

namespace MigrationTools.Fakes
namespace MigrationTools.Helpers.Tests
{
public class FakeMigrationToolVersion : IMigrationToolVersion
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
using System.Threading.Tasks;
using MigrationTools.Services;

namespace MigrationTools.Fakes
namespace MigrationTools.Helpers.Tests
{
public class FakeMigrationToolVersionInfo : MigrationToolVersionInfo
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\MigrationTools.Fakes\MigrationTools.Fakes.csproj" />
<ProjectReference Include="..\MigrationTools.Helpers.Tests\MigrationTools.Helpers.Tests.csproj" />
<ProjectReference Include="..\MigrationTools.Host\MigrationTools.Host.csproj" />
<ProjectReference Include="..\MigrationTools.Tests\MigrationTools.Tests.csproj" />
</ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
using Serilog.Events;
using MigrationTools.Host.Tests;
using MigrationTools.Tests;
using MigrationTools.Fakes;
using MigrationTools.Helpers.Tests;

namespace MigrationTools.Host.Services.Tests
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,6 @@ namespace MigrationTools.Host.Services.Tests
[TestClass]
public class DetectVersionServiceTests
{
[Ignore]
[TestMethod, TestCategory("L3")]
public void DetectVersionServiceTest()
{
var dos = new DetectVersionService(new TelemetryLoggerMock());
var result = dos.GetLatestVersion();
Assert.IsNotNull(result);
}

}
}
15 changes: 0 additions & 15 deletions src/MigrationTools.Host/HostExtensions.cs

This file was deleted.

33 changes: 0 additions & 33 deletions src/MigrationTools.Host/MigrationService.cs

This file was deleted.

39 changes: 5 additions & 34 deletions src/MigrationTools.Host/MigrationToolHost.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@
using Serilog.Core;
using Serilog.Events;
using Serilog.Sinks.SystemConsole.Themes;
using Spectre.Console.Cli.Extensions.DependencyInjection;
using Spectre.Console.Cli;
using Serilog.Filters;
using MigrationTools.Host.Commands;
using System.Diagnostics;
using System.Text.RegularExpressions;
using MigrationTools.Services;
using Spectre.Console.Extensions.Hosting;

namespace MigrationTools.Host
{
Expand All @@ -42,7 +42,6 @@ public static IHostBuilder CreateDefaultBuilder(string[] args)
var mtv = new MigrationToolVersion();

var hostBuilder = Microsoft.Extensions.Hosting.Host.CreateDefaultBuilder(args);

hostBuilder.UseSerilog((hostingContext, services, loggerConfiguration) =>
{
string outputTemplate = "[{Timestamp:HH:mm:ss} {Level:u3}] [" + mtv.GetRunningVersion().versionString + "] {Message:lj}{NewLine}{Exception}"; // {SourceContext}
Expand Down Expand Up @@ -134,49 +133,21 @@ public static IHostBuilder CreateDefaultBuilder(string[] args)
services.AddMigrationToolServicesLegacy();
// New v2Bits
services.AddMigrationToolServices();
// Host Services
services.AddTransient<IStartupService, StartupService>();
});

hostBuilder.ConfigureServices((context, services) =>
{
using var registrar = new DependencyInjectionRegistrar(services);
var app = new CommandApp(registrar);
app.Configure(config =>
{
config.PropagateExceptions();
config.AddCommand<Commands.ExecuteMigrationCommand>("execute");
config.AddCommand<Commands.InitMigrationCommand>("init");
});
services.AddSingleton<ICommandApp>(app);
});

hostBuilder.ConfigureServices((context, services) =>
hostBuilder.UseSpectreConsole(config =>
{
services.AddHostedService<MigrationService>();
config.AddCommand<Commands.ExecuteMigrationCommand>("execute");
config.AddCommand<Commands.InitMigrationCommand>("init");
config.PropagateExceptions();
});

hostBuilder.UseConsoleLifetime();



return hostBuilder;
}

public static async Task RunMigrationTools(this IHostBuilder hostBuilder, string[] args)
{
var host = hostBuilder.Build();
var startupService = host.InitializeMigrationSetup(args);
if (startupService == null)
{
return;
}
await host.RunAsync();
}

static string logDate = DateTime.Now.ToString("yyyyMMddHHmmss");

private static string CreateLogsPath()
Expand Down
2 changes: 1 addition & 1 deletion src/MigrationTools.Host/MigrationTools.Host.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
<PackageReference Include="Serilog.Sinks.Console" Version="6.0.0" />
<PackageReference Include="Serilog.Sinks.File" Version="6.0.0" />
<PackageReference Include="Spectre.Console.Cli" Version="0.49.1" />
<PackageReference Include="Spectre.Console.Cli.Extensions.DependencyInjection" Version="0.2.0" />
<PackageReference Include="Spectre.Console.Extensions.Hosting" Version="0.2.0" />
<PackageReference Include="System.CommandLine" Version="2.0.0-beta4.22272.1" />
<PackageReference Include="WGet.NET" Version="4.1.0" />
<PackageReference Include="YamlDotNet" Version="16.0.0" />
Expand Down
Loading

0 comments on commit 859423f

Please sign in to comment.