Skip to content

Commit

Permalink
- Create ModuleLoader.Abstractions package
Browse files Browse the repository at this point in the history
- Add unit tests for StartupContext
  • Loading branch information
ztanczos committed Oct 9, 2023
1 parent 90e0865 commit f05a0b5
Show file tree
Hide file tree
Showing 13 changed files with 406 additions and 0 deletions.
39 changes: 39 additions & 0 deletions src/module-loader/dotnet/ModuleLoader.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.7.34031.279
MinimumVisualStudioVersion = 10.0.40219.1
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{0991543E-FA51-4D1C-8756-F6D6FD64C612}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "tests", "tests", "{95B79432-5E5D-4889-8719-D610D6CCC35E}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MorganStanley.ComposeUI.ModuleLoader.Abstractions", "src\MorganStanley.ComposeUI.ModuleLoader.Abstractions\MorganStanley.ComposeUI.ModuleLoader.Abstractions.csproj", "{841D9BAC-DEE6-4E1A-A577-25B20633B110}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MorganStanley.ComposeUI.ModuleLoader.Abstractions.Tests", "tests\MorganStanley.ComposeUI.ModuleLoader.Abstractions.Tests\MorganStanley.ComposeUI.ModuleLoader.Abstractions.Tests.csproj", "{81B6905B-EE74-4387-A5EB-11271A4458A4}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{841D9BAC-DEE6-4E1A-A577-25B20633B110}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{841D9BAC-DEE6-4E1A-A577-25B20633B110}.Debug|Any CPU.Build.0 = Debug|Any CPU
{841D9BAC-DEE6-4E1A-A577-25B20633B110}.Release|Any CPU.ActiveCfg = Release|Any CPU
{841D9BAC-DEE6-4E1A-A577-25B20633B110}.Release|Any CPU.Build.0 = Release|Any CPU
{81B6905B-EE74-4387-A5EB-11271A4458A4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{81B6905B-EE74-4387-A5EB-11271A4458A4}.Debug|Any CPU.Build.0 = Debug|Any CPU
{81B6905B-EE74-4387-A5EB-11271A4458A4}.Release|Any CPU.ActiveCfg = Release|Any CPU
{81B6905B-EE74-4387-A5EB-11271A4458A4}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{841D9BAC-DEE6-4E1A-A577-25B20633B110} = {0991543E-FA51-4D1C-8756-F6D6FD64C612}
{81B6905B-EE74-4387-A5EB-11271A4458A4} = {95B79432-5E5D-4889-8719-D610D6CCC35E}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {147A1BDA-77DE-4D1A-B8D5-6E8803E11F47}
EndGlobalSection
EndGlobal
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// Morgan Stanley makes this available to you under the Apache License,
// Version 2.0 (the "License"). You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0.
//
// See the NOTICE file distributed with this work for additional information
// regarding copyright ownership. Unless required by applicable law or agreed
// to in writing, software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
// or implied. See the License for the specific language governing permissions
// and limitations under the License.

namespace MorganStanley.ComposeUI.ModuleLoader;

public interface IModuleCatalog
{
IModuleManifest GetManifest(string moduleId);

IEnumerable<string> GetModuleIds();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// Morgan Stanley makes this available to you under the Apache License,
// Version 2.0 (the "License"). You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0.
//
// See the NOTICE file distributed with this work for additional information
// regarding copyright ownership. Unless required by applicable law or agreed
// to in writing, software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
// or implied. See the License for the specific language governing permissions
// and limitations under the License.

namespace MorganStanley.ComposeUI.ModuleLoader;

public interface IModuleLoader
{
void RequestStart(StartRequest startupRequest);

void RequestStop(StopRequest stopRequest);

IObservable<LifetimeEvent> LifetimeEvents { get; }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// Morgan Stanley makes this available to you under the Apache License,
// Version 2.0 (the "License"). You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0.
//
// See the NOTICE file distributed with this work for additional information
// regarding copyright ownership. Unless required by applicable law or agreed
// to in writing, software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
// or implied. See the License for the specific language governing permissions
// and limitations under the License.

namespace MorganStanley.ComposeUI.ModuleLoader;

public interface IModuleManifest
{
string Id { get; }

string Name { get; }

string StartupType { get; }
}

public interface IModuleManifest<out TDetails> : IModuleManifest
{
TDetails GetDetails();
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// Morgan Stanley makes this available to you under the Apache License,
// Version 2.0 (the "License"). You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0.
//
// See the NOTICE file distributed with this work for additional information
// regarding copyright ownership. Unless required by applicable law or agreed
// to in writing, software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
// or implied. See the License for the specific language governing permissions
// and limitations under the License.

namespace MorganStanley.ComposeUI.ModuleLoader;

public interface IStartupAction
{
Task InvokeAsync(StartupContext startupContext, Func<Task> next);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
// Morgan Stanley makes this available to you under the Apache License,
// Version 2.0 (the "License"). You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0.
//
// See the NOTICE file distributed with this work for additional information
// regarding copyright ownership. Unless required by applicable law or agreed
// to in writing, software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
// or implied. See the License for the specific language governing permissions
// and limitations under the License.

namespace MorganStanley.ComposeUI.ModuleLoader;

public abstract class LifetimeEvent
{
protected LifetimeEvent(Guid instanceId)

Check warning on line 17 in src/module-loader/dotnet/src/MorganStanley.ComposeUI.ModuleLoader.Abstractions/LifetimeEvent.cs

View check run for this annotation

Codecov / codecov/patch

src/module-loader/dotnet/src/MorganStanley.ComposeUI.ModuleLoader.Abstractions/LifetimeEvent.cs#L17

Added line #L17 was not covered by tests
{
InstanceId = instanceId;
}

Check warning on line 20 in src/module-loader/dotnet/src/MorganStanley.ComposeUI.ModuleLoader.Abstractions/LifetimeEvent.cs

View check run for this annotation

Codecov / codecov/patch

src/module-loader/dotnet/src/MorganStanley.ComposeUI.ModuleLoader.Abstractions/LifetimeEvent.cs#L19-L20

Added lines #L19 - L20 were not covered by tests

public Guid InstanceId { get; }

Check warning on line 22 in src/module-loader/dotnet/src/MorganStanley.ComposeUI.ModuleLoader.Abstractions/LifetimeEvent.cs

View check run for this annotation

Codecov / codecov/patch

src/module-loader/dotnet/src/MorganStanley.ComposeUI.ModuleLoader.Abstractions/LifetimeEvent.cs#L22

Added line #L22 was not covered by tests

public abstract LifetimeEventType EventType { get; }

public sealed class Starting : LifetimeEvent
{
internal Starting(Guid instanceId)
: base(instanceId)
{ }

Check warning on line 30 in src/module-loader/dotnet/src/MorganStanley.ComposeUI.ModuleLoader.Abstractions/LifetimeEvent.cs

View check run for this annotation

Codecov / codecov/patch

src/module-loader/dotnet/src/MorganStanley.ComposeUI.ModuleLoader.Abstractions/LifetimeEvent.cs#L29-L30

Added lines #L29 - L30 were not covered by tests

public override LifetimeEventType EventType => LifetimeEventType.Starting;

Check warning on line 32 in src/module-loader/dotnet/src/MorganStanley.ComposeUI.ModuleLoader.Abstractions/LifetimeEvent.cs

View check run for this annotation

Codecov / codecov/patch

src/module-loader/dotnet/src/MorganStanley.ComposeUI.ModuleLoader.Abstractions/LifetimeEvent.cs#L32

Added line #L32 was not covered by tests
}

public sealed class Started : LifetimeEvent
{
internal Started(Guid instanceId)
: base(instanceId)
{ }

Check warning on line 39 in src/module-loader/dotnet/src/MorganStanley.ComposeUI.ModuleLoader.Abstractions/LifetimeEvent.cs

View check run for this annotation

Codecov / codecov/patch

src/module-loader/dotnet/src/MorganStanley.ComposeUI.ModuleLoader.Abstractions/LifetimeEvent.cs#L38-L39

Added lines #L38 - L39 were not covered by tests

public override LifetimeEventType EventType => LifetimeEventType.Started;

Check warning on line 41 in src/module-loader/dotnet/src/MorganStanley.ComposeUI.ModuleLoader.Abstractions/LifetimeEvent.cs

View check run for this annotation

Codecov / codecov/patch

src/module-loader/dotnet/src/MorganStanley.ComposeUI.ModuleLoader.Abstractions/LifetimeEvent.cs#L41

Added line #L41 was not covered by tests
}

public sealed class Stopping : LifetimeEvent
{
internal Stopping(Guid instanceId)
: base(instanceId)
{ }

Check warning on line 48 in src/module-loader/dotnet/src/MorganStanley.ComposeUI.ModuleLoader.Abstractions/LifetimeEvent.cs

View check run for this annotation

Codecov / codecov/patch

src/module-loader/dotnet/src/MorganStanley.ComposeUI.ModuleLoader.Abstractions/LifetimeEvent.cs#L47-L48

Added lines #L47 - L48 were not covered by tests

public override LifetimeEventType EventType => LifetimeEventType.Stopping;

Check warning on line 50 in src/module-loader/dotnet/src/MorganStanley.ComposeUI.ModuleLoader.Abstractions/LifetimeEvent.cs

View check run for this annotation

Codecov / codecov/patch

src/module-loader/dotnet/src/MorganStanley.ComposeUI.ModuleLoader.Abstractions/LifetimeEvent.cs#L50

Added line #L50 was not covered by tests
}

public sealed class Stopped : LifetimeEvent
{
internal Stopped(Guid instanceId, bool isExpected = true)
: base(instanceId)

Check warning on line 56 in src/module-loader/dotnet/src/MorganStanley.ComposeUI.ModuleLoader.Abstractions/LifetimeEvent.cs

View check run for this annotation

Codecov / codecov/patch

src/module-loader/dotnet/src/MorganStanley.ComposeUI.ModuleLoader.Abstractions/LifetimeEvent.cs#L56

Added line #L56 was not covered by tests
{
IsExpected = isExpected;
}

Check warning on line 59 in src/module-loader/dotnet/src/MorganStanley.ComposeUI.ModuleLoader.Abstractions/LifetimeEvent.cs

View check run for this annotation

Codecov / codecov/patch

src/module-loader/dotnet/src/MorganStanley.ComposeUI.ModuleLoader.Abstractions/LifetimeEvent.cs#L58-L59

Added lines #L58 - L59 were not covered by tests

public override LifetimeEventType EventType => LifetimeEventType.Stopped;

Check warning on line 61 in src/module-loader/dotnet/src/MorganStanley.ComposeUI.ModuleLoader.Abstractions/LifetimeEvent.cs

View check run for this annotation

Codecov / codecov/patch

src/module-loader/dotnet/src/MorganStanley.ComposeUI.ModuleLoader.Abstractions/LifetimeEvent.cs#L61

Added line #L61 was not covered by tests

public bool IsExpected { get; set; }

Check warning on line 63 in src/module-loader/dotnet/src/MorganStanley.ComposeUI.ModuleLoader.Abstractions/LifetimeEvent.cs

View check run for this annotation

Codecov / codecov/patch

src/module-loader/dotnet/src/MorganStanley.ComposeUI.ModuleLoader.Abstractions/LifetimeEvent.cs#L63

Added line #L63 was not covered by tests
}
}









public enum LifetimeEventType
{
Starting,
Started,
Stopping,
Stopped
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<RootNamespace>MorganStanley.ComposeUI.ModuleLoader</RootNamespace>
</PropertyGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// Morgan Stanley makes this available to you under the Apache License,
// Version 2.0 (the "License"). You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0.
//
// See the NOTICE file distributed with this work for additional information
// regarding copyright ownership. Unless required by applicable law or agreed
// to in writing, software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
// or implied. See the License for the specific language governing permissions
// and limitations under the License.

namespace MorganStanley.ComposeUI.ModuleLoader;

public sealed class StartRequest
{
public StartRequest(string moduleId)
{
ModuleId = moduleId;
InstanceId = Guid.NewGuid();
}

public Guid InstanceId { get; }

Check warning on line 23 in src/module-loader/dotnet/src/MorganStanley.ComposeUI.ModuleLoader.Abstractions/StartRequest.cs

View check run for this annotation

Codecov / codecov/patch

src/module-loader/dotnet/src/MorganStanley.ComposeUI.ModuleLoader.Abstractions/StartRequest.cs#L23

Added line #L23 was not covered by tests

public string ModuleId { get; }

Check warning on line 25 in src/module-loader/dotnet/src/MorganStanley.ComposeUI.ModuleLoader.Abstractions/StartRequest.cs

View check run for this annotation

Codecov / codecov/patch

src/module-loader/dotnet/src/MorganStanley.ComposeUI.ModuleLoader.Abstractions/StartRequest.cs#L25

Added line #L25 was not covered by tests
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
// Morgan Stanley makes this available to you under the Apache License,
// Version 2.0 (the "License"). You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0.
//
// See the NOTICE file distributed with this work for additional information
// regarding copyright ownership. Unless required by applicable law or agreed
// to in writing, software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
// or implied. See the License for the specific language governing permissions
// and limitations under the License.

using System.Collections.Concurrent;
using System.Collections.Immutable;

namespace MorganStanley.ComposeUI.ModuleLoader;

public sealed class StartupContext
{
private readonly ConcurrentDictionary<Type, ImmutableList<object>> _properties = new();

public StartupContext(StartRequest startRequest)
{
StartRequest = startRequest;
}

public StartRequest StartRequest { get; }

Check warning on line 27 in src/module-loader/dotnet/src/MorganStanley.ComposeUI.ModuleLoader.Abstractions/StartupContext.cs

View check run for this annotation

Codecov / codecov/patch

src/module-loader/dotnet/src/MorganStanley.ComposeUI.ModuleLoader.Abstractions/StartupContext.cs#L27

Added line #L27 was not covered by tests

public void AddProperty<T>(T value)
{
ArgumentNullException.ThrowIfNull(value, nameof(value));

_properties.AddOrUpdate(typeof(T),
(_) => ImmutableList<object>.Empty.Add(value),
(_, list) => list.Add(value));
}

public IEnumerable<T> GetProperties<T>()
{
if (!_properties.TryGetValue(typeof(T), out var list))
{
return Enumerable.Empty<T>();
}

return list.OfType<T>();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// Morgan Stanley makes this available to you under the Apache License,
// Version 2.0 (the "License"). You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0.
//
// See the NOTICE file distributed with this work for additional information
// regarding copyright ownership. Unless required by applicable law or agreed
// to in writing, software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
// or implied. See the License for the specific language governing permissions
// and limitations under the License.

namespace MorganStanley.ComposeUI.ModuleLoader;

public struct StopRequest
{
public Guid InstanceId;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// Morgan Stanley makes this available to you under the Apache License,
// Version 2.0 (the "License"). You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0.
//
// See the NOTICE file distributed with this work for additional information
// regarding copyright ownership. Unless required by applicable law or agreed
// to in writing, software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
// or implied. See the License for the specific language governing permissions
// and limitations under the License.

global using Xunit;
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<Project Sdk="Microsoft.NET.Sdk">

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

<IsPackable>false</IsPackable>
<IsTestProject>true</IsTestProject>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" />
<PackageReference Include="xunit" />
<PackageReference Include="xunit.runner.visualstudio">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="coverlet.collector">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\src\MorganStanley.ComposeUI.ModuleLoader.Abstractions\MorganStanley.ComposeUI.ModuleLoader.Abstractions.csproj" />
</ItemGroup>

</Project>
Loading

0 comments on commit f05a0b5

Please sign in to comment.