Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
<PackageVersion Include="AspNetCore.HealthChecks.MongoDb" Version="9.0.0"/>
<PackageVersion Include="AspNetCore.HealthChecks.UI.Client" Version="9.0.0"/>
<PackageVersion Include="Docker.DotNet" Version="3.125.15"/>
<PackageVersion Include="DxWorks.Hub.Sdk" Version="1.0.3"/>
<PackageVersion Include="FluentValidation" Version="11.11.0"/>
<PackageVersion Include="FluentValidation.DependencyInjectionExtensions" Version="11.11.0"/>
<PackageVersion Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="9.0.1"/>
Expand Down
7 changes: 0 additions & 7 deletions ScriptBee.Marketplace.Client/Data/PluginVersion.cs

This file was deleted.

15 changes: 0 additions & 15 deletions ScriptBee.Marketplace.Client/ScriptBee.Marketplace.Client.csproj

This file was deleted.

12 changes: 12 additions & 0 deletions ScriptBee.sln
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,10 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Service.Plugin.Tests", "tes
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Service.Plugin", "src\Application\Domain\Service.Plugin\Service.Plugin.csproj", "{23230FA8-50CC-4883-ABC3-8BA66BC92023}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Marketplace.Client", "src\Adapters\Driven\Marketplace.Client\Marketplace.Client.csproj", "{D8626754-E493-456D-A809-9AA76677E8F8}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Marketplace.Client.Tests", "test\Adapters\Driven\Marketplace.Client.Tests\Marketplace.Client.Tests.csproj", "{6B16EF85-94DA-427B-ADAA-55565AC89287}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -217,5 +221,13 @@ Global
{23230FA8-50CC-4883-ABC3-8BA66BC92023}.Debug|Any CPU.Build.0 = Debug|Any CPU
{23230FA8-50CC-4883-ABC3-8BA66BC92023}.Release|Any CPU.ActiveCfg = Release|Any CPU
{23230FA8-50CC-4883-ABC3-8BA66BC92023}.Release|Any CPU.Build.0 = Release|Any CPU
{D8626754-E493-456D-A809-9AA76677E8F8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{D8626754-E493-456D-A809-9AA76677E8F8}.Debug|Any CPU.Build.0 = Debug|Any CPU
{D8626754-E493-456D-A809-9AA76677E8F8}.Release|Any CPU.ActiveCfg = Release|Any CPU
{D8626754-E493-456D-A809-9AA76677E8F8}.Release|Any CPU.Build.0 = Release|Any CPU
{6B16EF85-94DA-427B-ADAA-55565AC89287}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{6B16EF85-94DA-427B-ADAA-55565AC89287}.Debug|Any CPU.Build.0 = Debug|Any CPU
{6B16EF85-94DA-427B-ADAA-55565AC89287}.Release|Any CPU.ActiveCfg = Release|Any CPU
{6B16EF85-94DA-427B-ADAA-55565AC89287}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
EndGlobal
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
public enum MarketPlaceProjectType
{
Plugin,
Bundle
Bundle,
}

public record MarketPlaceProject(
Expand Down
3 changes: 3 additions & 0 deletions src/Adapters/Driven/Marketplace.Client/Data/PluginVersion.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
namespace ScriptBee.Marketplace.Client.Data;

public record PluginVersion(string Url, Version Version, string ManifestUrl);
12 changes: 12 additions & 0 deletions src/Adapters/Driven/Marketplace.Client/Marketplace.Client.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<RootNamespace>ScriptBee.Marketplace.Client</RootNamespace>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="DxWorks.Hub.Sdk" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection"/>
<PackageReference Include="Microsoft.Extensions.Http"/>
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@ namespace ScriptBee.Marketplace.Client;

public static class ScriptBeeMarketplaceClientExtensions
{
public static IServiceCollection AddScriptBeeMarketplaceClient(this IServiceCollection services,
Action<DxWorksHubSdkOptions>? configureOptionsAction = null)
public static IServiceCollection AddScriptBeeMarketplaceClient(
this IServiceCollection services,
Action<DxWorksHubSdkOptions>? configureOptionsAction = null
)
{
services.AddDxWorksHubSdk(configureOptionsAction);
services.AddSingleton<IMarketPluginFetcher, MarketPluginFetcher>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,35 +4,26 @@

namespace ScriptBee.Marketplace.Client.Services;

public sealed class MarketPluginFetcher : IMarketPluginFetcher
public sealed class MarketPluginFetcher(IScriptBeeClient hubClient) : IMarketPluginFetcher
{
private readonly IScriptBeeClient _hubClient;


public MarketPluginFetcher(IScriptBeeClient hubClient)
{
_hubClient = hubClient;
}

public async Task UpdateRepositoryAsync(CancellationToken cancellationToken = default)
{
await _hubClient.UpdateRepositoryAsync(cancellationToken);
await hubClient.UpdateRepositoryAsync(cancellationToken);
}

public IEnumerable<MarketPlaceProject> GetProjectsAsync()
{
return _hubClient.GetScriptBeeProjects()
.Select(ConvertToPlugin);
return hubClient.GetScriptBeeProjects().Select(ConvertToPlugin);
}

private static MarketPlaceProject ConvertToPlugin(ScriptBeeProject project)
{
var projectType = project.Type == ScriptBeeProjectTypes.Bundle
? MarketPlaceProjectType.Bundle
: MarketPlaceProjectType.Plugin;
var projectType =
project.Type == ScriptBeeProjectTypes.Bundle
? MarketPlaceProjectType.Bundle
: MarketPlaceProjectType.Plugin;

return new MarketPlaceProject
(
return new MarketPlaceProject(
project.Id,
project.Name,
projectType,
Expand All @@ -44,11 +35,6 @@ private static MarketPlaceProject ConvertToPlugin(ScriptBeeProject project)

private static PluginVersion ConvertToPluginVersion(ScriptBeeProjectVersion version)
{
return new PluginVersion
(
version.DownloadUrl,
version.Version,
version.Manifest
);
return new PluginVersion(version.DownloadUrl, version.Version, version.Manifest);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<RootNamespace>ScriptBee.Marketplace.Client.Tests</RootNamespace>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\..\..\..\src\Adapters\Driven\Marketplace.Client\Marketplace.Client.csproj" />
<ProjectReference Include="..\..\..\Common\Tests.Common\Tests.Common.csproj" />
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
using DxWorks.Hub.Sdk.Clients;
using DxWorks.Hub.Sdk.Project;
using NSubstitute;
using ScriptBee.Marketplace.Client.Data;
using ScriptBee.Marketplace.Client.Services;

namespace ScriptBee.Marketplace.Client.Tests.Services;

public class MarketPluginFetcherTest
{
private readonly IScriptBeeClient _hubClient = Substitute.For<IScriptBeeClient>();
private readonly MarketPluginFetcher _pluginFetcher;

public MarketPluginFetcherTest()
{
_pluginFetcher = new MarketPluginFetcher(_hubClient);
}

[Fact]
public async Task UpdateRepositoryAsync_CallsHubClientUpdateRepositoryAsync()
{
var cancellationToken = new CancellationTokenSource().Token;

await _pluginFetcher.UpdateRepositoryAsync(cancellationToken);

await _hubClient.Received(1).UpdateRepositoryAsync(cancellationToken);
}

[Fact]
public void GetProjectsAsync_CallsHubClientGetScriptBeeProjects()
{
_pluginFetcher.GetProjectsAsync();

_hubClient.Received(1).GetScriptBeeProjects();
}

[Fact]
public void GetProjectsAsync_ReturnsEmptyList_WhenHubClientReturnsEmptyList()
{
_hubClient.GetScriptBeeProjects().Returns([]);

var result = _pluginFetcher.GetProjectsAsync();

result.ShouldBeEmpty();
}

[Fact]
public void GetProjectsAsync_MapsScriptBeeProjectsToMarketPlaceProjects()
{
var scriptBeeProjects = new List<ScriptBeeProject>
{
new()
{
Id = "project1",
Name = "Test Plugin",
Type = ScriptBeeProjectTypes.Plugin,
Description = "A test plugin description.",
Authors = [new Author { Name = "John Doe" }],
Versions =
[
new ScriptBeeProjectVersion
{
DownloadUrl = "url1",
Version = new Version("1.0.0"),
Manifest = "manifest1",
},
],
},
new()
{
Id = "bundle1",
Name = "Test Bundle",
Type = ScriptBeeProjectTypes.Bundle,
Description = "A test bundle description.",
Authors = [new Author { Name = "Jane Doe" }],
Versions =
[
new ScriptBeeProjectVersion
{
DownloadUrl = "url2",
Version = new Version("2.0.0"),
Manifest = "manifest2",
},
],
},
};
_hubClient.GetScriptBeeProjects().Returns(scriptBeeProjects);

var result = _pluginFetcher.GetProjectsAsync().ToList();

result.Count.ShouldBe(2);
var pluginProject = result.First(p => p.Id == "project1");
pluginProject.Name.ShouldBe("Test Plugin");
pluginProject.Type.ShouldBe(MarketPlaceProjectType.Plugin);
pluginProject.Description.ShouldBe("A test plugin description.");
pluginProject.Authors.ShouldContain("John Doe");
var pluginVersion = pluginProject.Versions.Single();
pluginVersion.Url.ShouldBe("url1");
pluginVersion.Version.ShouldBe(new Version("1.0.0"));
pluginVersion.ManifestUrl.ShouldBe("manifest1");

var bundleProject = result.First(p => p.Id == "bundle1");
bundleProject.Name.ShouldBe("Test Bundle");
bundleProject.Type.ShouldBe(MarketPlaceProjectType.Bundle);
bundleProject.Description.ShouldBe("A test bundle description.");
bundleProject.Authors.ShouldContain("Jane Doe");
var version = bundleProject.Versions.Single();
version.Url.ShouldBe("url2");
version.Version.ShouldBe(new Version("2.0.0"));
version.ManifestUrl.ShouldBe("manifest2");
}
}
Loading