Skip to content
Draft
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
47 changes: 47 additions & 0 deletions src/ServiceComposer.InMemory.Tests/Sample.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
using Microsoft.Extensions.DependencyInjection;
using Xunit;

namespace ServiceComposer.InMemory.Tests
{
public class Sample
{
class Handler : ICompositionRequestsHandler
{
public Task Handle(ICompositionContext context)
{
// how to access the view model? Using the same GetComposedResponseModel
// as in Asp.NetCore but on the contenxt? e.g.:
//var vm = context.GetComposedResponseModel();

// should te default view model be the usual dynamic object?

return Task.CompletedTask;
}
}

[Fact]
public async Task Should_run()
{
// In a console app the following would be the minimum
// required configuration. Given that there is no "run"
// phase, there is no place to initialize the composition
// engine.
// One option is to do that when adding stuff to the ServiceCollection
// Another option woul dbe to require usage of the Host and register a
// HostedService that does te heavy lifting when the application host
// starts.

var services = new ServiceCollection();
services.AddInMemoryViewModelComposition(options =>
{
options.AssemblyScanner.Disable();
options.RegisterCompositionHandler<Handler>();
});

var serviceProvider = services.BuildServiceProvider();
var compositionEngine = serviceProvider.GetRequiredService<ICompositionEngine>();

var composedViewModel = await compositionEngine.HandleComposableRequest("a/request");
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<Project Sdk="Microsoft.NET.Sdk">

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

<ItemGroup>
<PackageReference Include="ApprovalTests" Version="5.7.3" />
<PackageReference Include="FakeItEasy" Version="7.3.1" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="6.0.1" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.3.2" />
<PackageReference Include="PublicApiGenerator" Version="10.3.0" />
<PackageReference Include="xunit" Version="2.4.2" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.5">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\ServiceComposer.InMemory\ServiceComposer.InMemory.csproj" />
</ItemGroup>

</Project>
6 changes: 6 additions & 0 deletions src/ServiceComposer.InMemory.sln
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ VisualStudioVersion = 17.0.31912.275
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ServiceComposer.InMemory", "ServiceComposer.InMemory\ServiceComposer.InMemory.csproj", "{5D70C2D3-7F78-48E6-8EB9-BC8E85B850D1}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ServiceComposer.InMemory.Tests", "ServiceComposer.InMemory.Tests\ServiceComposer.InMemory.Tests.csproj", "{576936D7-A7C4-40A7-B87B-E759B80C09DF}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand All @@ -14,6 +16,10 @@ Global
{5D70C2D3-7F78-48E6-8EB9-BC8E85B850D1}.Debug|Any CPU.Build.0 = Debug|Any CPU
{5D70C2D3-7F78-48E6-8EB9-BC8E85B850D1}.Release|Any CPU.ActiveCfg = Release|Any CPU
{5D70C2D3-7F78-48E6-8EB9-BC8E85B850D1}.Release|Any CPU.Build.0 = Release|Any CPU
{576936D7-A7C4-40A7-B87B-E759B80C09DF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{576936D7-A7C4-40A7-B87B-E759B80C09DF}.Debug|Any CPU.Build.0 = Debug|Any CPU
{576936D7-A7C4-40A7-B87B-E759B80C09DF}.Release|Any CPU.ActiveCfg = Release|Any CPU
{576936D7-A7C4-40A7-B87B-E759B80C09DF}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down