Skip to content

Commit

Permalink
- Rename IModuleLoader.RequestStartProcess/RequestStopProcess to Requ…
Browse files Browse the repository at this point in the history
…estStart/RequestStop

- Rename StartupRequest to StartRequest
- Change StartupContext's object holder to ImmutableList
  • Loading branch information
ztanczos committed Oct 9, 2023
1 parent c69ef67 commit 5eb40b7
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ namespace MorganStanley.ComposeUI.ModuleLoader;

public interface IModuleLoader
{
void RequestStartProcess(StartupRequest startupRequest);
void RequestStart(StartRequest startupRequest);

void RequestStopProcess(StopRequest stopRequest);
void RequestStop(StopRequest stopRequest);

IObservable<LifetimeEvent> LifetimeEvents { get; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@

namespace MorganStanley.ComposeUI.ModuleLoader;

public sealed class StartupRequest
public sealed class StartRequest
{
public StartupRequest(string name)
public StartRequest(string moduleName)
{
Name = name;
ModuleName = moduleName;
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 Name { get; }
public string ModuleName { 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
Expand Up @@ -11,27 +11,28 @@
// 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, List<object>> _values = new ConcurrentDictionary<Type, List<object>>();
private readonly ConcurrentDictionary<Type, ImmutableList<object>> _values = new();

public StartupContext(StartupRequest startupRequest)
public StartupContext(StartRequest startupRequest)
{
StartupRequest = startupRequest;
}

public StartupRequest StartupRequest { get; }
public StartRequest StartupRequest { 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 Add<T>(T value)
{
ArgumentNullException.ThrowIfNull(value, nameof(value));

_values.AddOrUpdate(typeof(T),
new List<object> { value },
(type, list) => { list.Add(value); return list; });
(type) => { var list = ImmutableList<object>.Empty.Add(value); return list; },
(type, list) => { var newList = list.Add(value); return newList; });
}

public IEnumerable<T> Get<T>()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public void WhenAdd_AddedValuesCanBeRetrieved()
new MyContextInfo { Name = "Test2" }
};

StartupContext context = new StartupContext(new StartupRequest("test"));
StartupContext context = new StartupContext(new StartRequest("test"));
context.Add(expected[0]);
context.Add(expected[1]);

Expand All @@ -35,14 +35,14 @@ public void WhenAdd_AddedValuesCanBeRetrieved()
[Fact]
public void GivenNullArgument_WhenAdd_ThrowsArgumentNullException()
{
StartupContext context = new StartupContext(new StartupRequest("test"));
StartupContext context = new StartupContext(new StartRequest("test"));
Assert.Throws<ArgumentNullException>(() => context.Add<object>(null!));
}

[Fact]
public void WhenGet_UnknownType_EmptyEnumerableIsReturned()
{
StartupContext context = new StartupContext(new StartupRequest("test"));
StartupContext context = new StartupContext(new StartRequest("test"));
var result = context.Get<MyContextInfo>();

Assert.Equal(Enumerable.Empty<MyContextInfo>(), result);
Expand Down

0 comments on commit 5eb40b7

Please sign in to comment.