Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add "Get Projects" and "Find By Id" from Production Service #251

Merged
merged 6 commits into from
Feb 4, 2025
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
36 changes: 31 additions & 5 deletions src/Angor.Avalonia.sln
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,15 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution
Angor\Avalonia\Directory.Packages.props = Angor\Avalonia\Directory.Packages.props
EndProjectSection
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AngorApp.Model", "Angor\Avalonia\AngorApp.Model\AngorApp.Model.csproj", "{AD095B93-61C9-46AF-9EB5-403D1C9EB29E}"
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Angor.UI.Model", "Angor\Avalonia\Angor.UI.Model\Angor.UI.Model.csproj", "{BCCAC388-AC7D-4BA4-9C1E-58D3FAF5D0D5}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Angor.Shared", "Angor\Shared\Angor.Shared.csproj", "{700DF0C4-C965-4662-A91F-CD3BE043AC9E}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Angor.UI.Model.Implementation", "Angor\Avalonia\Angor.UI.Model.Implementation\Angor.UI.Model.Implementation.csproj", "{539B4D21-F2A9-46A6-84F1-9A51884A62E9}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Angor.UI.Model.Implementation.Tests", "Angor\Avalonia\Angor.UI.Model.Implementation.Tests\Angor.UI.Model.Implementation.Tests.csproj", "{B84751C6-1B82-4DE8-9FBE-F0A67D981C43}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Core", "Core", "{5B7EE527-242E-4C87-9BB7-AD4E05EABC4C}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand All @@ -28,15 +36,33 @@ Global
{B0BFAC0F-9F74-4770-9B12-A3A478DB0A71}.Debug|Any CPU.Build.0 = Debug|Any CPU
{B0BFAC0F-9F74-4770-9B12-A3A478DB0A71}.Release|Any CPU.ActiveCfg = Release|Any CPU
{B0BFAC0F-9F74-4770-9B12-A3A478DB0A71}.Release|Any CPU.Build.0 = Release|Any CPU
{AD095B93-61C9-46AF-9EB5-403D1C9EB29E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{AD095B93-61C9-46AF-9EB5-403D1C9EB29E}.Debug|Any CPU.Build.0 = Debug|Any CPU
{AD095B93-61C9-46AF-9EB5-403D1C9EB29E}.Release|Any CPU.ActiveCfg = Release|Any CPU
{AD095B93-61C9-46AF-9EB5-403D1C9EB29E}.Release|Any CPU.Build.0 = Release|Any CPU
{BCCAC388-AC7D-4BA4-9C1E-58D3FAF5D0D5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{BCCAC388-AC7D-4BA4-9C1E-58D3FAF5D0D5}.Debug|Any CPU.Build.0 = Debug|Any CPU
{BCCAC388-AC7D-4BA4-9C1E-58D3FAF5D0D5}.Release|Any CPU.ActiveCfg = Release|Any CPU
{BCCAC388-AC7D-4BA4-9C1E-58D3FAF5D0D5}.Release|Any CPU.Build.0 = Release|Any CPU
{700DF0C4-C965-4662-A91F-CD3BE043AC9E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{700DF0C4-C965-4662-A91F-CD3BE043AC9E}.Debug|Any CPU.Build.0 = Debug|Any CPU
{700DF0C4-C965-4662-A91F-CD3BE043AC9E}.Release|Any CPU.ActiveCfg = Release|Any CPU
{700DF0C4-C965-4662-A91F-CD3BE043AC9E}.Release|Any CPU.Build.0 = Release|Any CPU
{539B4D21-F2A9-46A6-84F1-9A51884A62E9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{539B4D21-F2A9-46A6-84F1-9A51884A62E9}.Debug|Any CPU.Build.0 = Debug|Any CPU
{539B4D21-F2A9-46A6-84F1-9A51884A62E9}.Release|Any CPU.ActiveCfg = Release|Any CPU
{539B4D21-F2A9-46A6-84F1-9A51884A62E9}.Release|Any CPU.Build.0 = Release|Any CPU
{B84751C6-1B82-4DE8-9FBE-F0A67D981C43}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{B84751C6-1B82-4DE8-9FBE-F0A67D981C43}.Debug|Any CPU.Build.0 = Debug|Any CPU
{B84751C6-1B82-4DE8-9FBE-F0A67D981C43}.Release|Any CPU.ActiveCfg = Release|Any CPU
{B84751C6-1B82-4DE8-9FBE-F0A67D981C43}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {83CB65B8-011F-4ED7-BCD3-A6CFA935EF7E}
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{BCCAC388-AC7D-4BA4-9C1E-58D3FAF5D0D5} = {5B7EE527-242E-4C87-9BB7-AD4E05EABC4C}
{539B4D21-F2A9-46A6-84F1-9A51884A62E9} = {5B7EE527-242E-4C87-9BB7-AD4E05EABC4C}
{B84751C6-1B82-4DE8-9FBE-F0A67D981C43} = {5B7EE527-242E-4C87-9BB7-AD4E05EABC4C}
{700DF0C4-C965-4662-A91F-CD3BE043AC9E} = {5B7EE527-242E-4C87-9BB7-AD4E05EABC4C}
EndGlobalSection
EndGlobal
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net9.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<IsPackable>false</IsPackable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="coverlet.collector" />
<PackageReference Include="FluentAssertions" />
<PackageReference Include="FluentAssertions.Reactive" />
<PackageReference Include="Microsoft.NET.Test.Sdk" />
<PackageReference Include="xunit" />
<PackageReference Include="xunit.runner.visualstudio" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\Shared\Angor.Shared.csproj" />
<ProjectReference Include="..\Angor.UI.Model.Implementation\Angor.UI.Model.Implementation.csproj" />
</ItemGroup>

<ItemGroup>
<Using Include="Xunit" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
using Microsoft.Extensions.Logging;
using Xunit.Abstractions;

namespace Angor.UI.Model.Implementation.Tests.Logging;

public class XUnitLogger : ILogger
{
private readonly ITestOutputHelper outputHelper;
private readonly string categoryName;

public XUnitLogger(ITestOutputHelper outputHelper, string categoryName)
{
this.outputHelper = outputHelper ??
throw new ArgumentNullException(nameof(outputHelper));
this.categoryName = categoryName;
}

public bool IsEnabled(LogLevel logLevel) => true; // Ajusta si quieres filtrar.

public void Log<TState>(
LogLevel logLevel,
EventId eventId,
TState state,
Exception exception,
Func<TState, Exception, string> formatter)
{
if (!IsEnabled(logLevel)) return;

var message = formatter(state, exception);
outputHelper.WriteLine($"{DateTime.Now:HH:mm:ss} [{logLevel}] {categoryName}: {message}");

if (exception is not null)
{
outputHelper.WriteLine(exception.ToString());
}
}

public IDisposable BeginScope<TState>(TState state) => default!;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
using Microsoft.Extensions.Logging;
using Xunit.Abstractions;

namespace Angor.UI.Model.Implementation.Tests.Logging;

public static class XUnitLoggerFactoryExtensions
{
public static ILoggingBuilder AddXUnitLogger(
this ILoggingBuilder builder,
ITestOutputHelper outputHelper,
LogLevel minLevel = LogLevel.Trace)
{
// Podrías implementar filtrado por minLevel.
// Para el ejemplo, simplemente devolvemos un provider sin filtrar.
builder.AddProvider(new XUnitLoggerProvider(outputHelper));
return builder;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
using Microsoft.Extensions.Logging;
using Xunit.Abstractions;

namespace Angor.UI.Model.Implementation.Tests.Logging;

public class XUnitLoggerProvider : ILoggerProvider
{
private readonly ITestOutputHelper outputHelper;

public XUnitLoggerProvider(ITestOutputHelper outputHelper)
{
this.outputHelper = outputHelper ??
throw new ArgumentNullException(nameof(outputHelper));
}

public ILogger CreateLogger(string categoryName)
=> new XUnitLogger(outputHelper, categoryName);

public void Dispose() { }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
using Angor.UI.Model.Implementation.Projects;
using Angor.UI.Model.Implementation.Tests.Logging;
using Microsoft.Extensions.Logging;
using Xunit.Abstractions;

namespace Angor.UI.Model.Implementation.Tests;

public class ProjectServiceTests
{
private readonly ILoggerFactory loggerFactory;

public ProjectServiceTests(ITestOutputHelper output)
{
loggerFactory = LoggerFactory.Create(builder =>
{
builder.AddXUnitLogger(output);
});
}

[Fact]
public async Task GetProjectsFromService()
{
var service = new ProjectService(DependencyFactory.GetIndexerService(loggerFactory), DependencyFactory.GetRelayService(loggerFactory));

var projectsList = await service.Latest();

Assert.NotEmpty(projectsList);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
namespace Angor.UI.Model.Implementation.Tests;

public class WalletTests
{

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net9.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="DynamicData" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\Shared\Angor.Shared.csproj" />
<ProjectReference Include="..\Angor.UI.Model\Angor.UI.Model.csproj" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
using Angor.Shared.Services;
using Microsoft.Extensions.Logging;
using Nostr.Client.Client;

namespace Angor.UI.Model.Implementation;

public static class DependencyFactory
{
public static IRelayService GetRelayService(ILoggerFactory loggerFactory)
{
var relaySubscriptionsLogger = loggerFactory.CreateLogger<RelaySubscriptionsHandling>();
var relayServiceLogger = loggerFactory.CreateLogger<RelayService>();
var clientLogger = loggerFactory.CreateLogger<NostrWebsocketClient>();
var networkServiceLogger = loggerFactory.CreateLogger<NetworkService>();
var nostrCommunicationFactoryLogger = loggerFactory.CreateLogger<NostrCommunicationFactory>();

var networkConfiguration = new NetworkConfiguration();
var httpClient = new HttpClient();
var networkService = new NetworkService(new InMemoryStorage(), httpClient, networkServiceLogger, networkConfiguration);
var nostrCommunicationFactory = new NostrCommunicationFactory(clientLogger, nostrCommunicationFactoryLogger);
var relaySubscriptionsHandling = new RelaySubscriptionsHandling(relaySubscriptionsLogger, nostrCommunicationFactory, networkService);

var relay = new RelayService(relayServiceLogger, nostrCommunicationFactory, networkService, relaySubscriptionsHandling, new Serializer());
return relay;
}

public static IIndexerService GetIndexerService(ILoggerFactory loggerFactory)
{
var networkServiceLogger = loggerFactory.CreateLogger<NetworkService>();
var networkConfiguration = new NetworkConfiguration();
var networkConfig = networkConfiguration;
var httpClient = new HttpClient();
var networkService = new NetworkService(new InMemoryStorage(), httpClient, networkServiceLogger, networkConfiguration);

return new IndexerService(networkConfig, httpClient, networkService);
}
}
Loading
Loading