Skip to content

Commit

Permalink
feature: Update to Shiny 2.* (#66)
Browse files Browse the repository at this point in the history
* feature: Update to Shiny 2.*

+semver:minor

* fixing net6 syntax
  • Loading branch information
RLittlesII authored Nov 18, 2021
1 parent d34dc7b commit ebdc350
Show file tree
Hide file tree
Showing 9 changed files with 90 additions and 61 deletions.
25 changes: 12 additions & 13 deletions .nuke/build.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,17 +50,6 @@
"VSCode"
]
},
"LintFiles": {
"type": "array",
"description": "The files to lint, if not given lints all files",
"items": {
"type": "string"
}
},
"LintProfile": {
"type": "string",
"description": "The profile to use for linting"
},
"NoLogo": {
"type": "boolean",
"description": "Disables displaying the NUKE logo"
Expand Down Expand Up @@ -99,14 +88,19 @@
"Generate_Code_Coverage_Report",
"Generate_Code_Coverage_Report_Cobertura",
"Generate_Code_Coverage_Summary",
"GenerateCodeCoverageBadges",
"GenerateCodeCoverageReport",
"GenerateCodeCoverageReportCobertura",
"GenerateCodeCoverageSummary",
"GenerateReadme",
"Lint",
"NetPack",
"NetRestore",
"Pack",
"Restore",
"Test",
"Trigger_Code_Coverage_Reports"
"Trigger_Code_Coverage_Reports",
"TriggerCodeCoverageReports"
]
}
},
Expand All @@ -129,14 +123,19 @@
"Generate_Code_Coverage_Report",
"Generate_Code_Coverage_Report_Cobertura",
"Generate_Code_Coverage_Summary",
"GenerateCodeCoverageBadges",
"GenerateCodeCoverageReport",
"GenerateCodeCoverageReportCobertura",
"GenerateCodeCoverageSummary",
"GenerateReadme",
"Lint",
"NetPack",
"NetRestore",
"Pack",
"Restore",
"Test",
"Trigger_Code_Coverage_Reports"
"Trigger_Code_Coverage_Reports",
"TriggerCodeCoverageReports"
]
}
},
Expand Down
7 changes: 4 additions & 3 deletions packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,10 @@
<PackageReference Update="Rocket.Surgery.Xamarin.Essentials.Abstractions" Version="0.4.*" />
<PackageReference Update="Serilog.Sinks.AppCenter.Crash" Version="1.*" />
<PackageReference Update="Serilog.Sinks.Xamarin" Version="0.*" />
<PackageReference Update="Shiny.Core" Version="1.2.0.*" />
<PackageReference Update="Shiny.Locations" Version="1.2.0.*" />
<PackageReference Update="Shiny.Notifications" Version="1.2.0.*" />
<PackageReference Update="Shiny" Version="2.*" />
<PackageReference Update="Shiny.Core" Version="2.*" />
<PackageReference Update="Shiny.Locations" Version="2.*" />
<PackageReference Update="Shiny.Notifications" Version="2.*" />
<PackageReference Update="Sextant" Version="2.*" />
<PackageReference Update="Sextant.Plugins.Popup" Version="2.*" />
<PackageReference Update="Splat" Version="11.*" />
Expand Down
43 changes: 13 additions & 30 deletions src/Shiny/ReactiveShinyStartup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ namespace Rocket.Surgery.Airframe.Shiny
/// <summary>
/// Represents an <see cref="IShinyStartup"/> for application composition.
/// </summary>
public abstract class ReactiveShinyStartup : IShinyStartup
public abstract class ReactiveShinyStartup : ShinyStartup
{
private readonly IServiceCollection _serviceCollection;
private readonly IConfigurationBuilder _configurationBuilder = new ConfigurationBuilder();
Expand Down Expand Up @@ -44,42 +44,28 @@ protected ReactiveShinyStartup(IServiceCollection serviceCollection, IConfigurat
}

/// <inheritdoc/>
void IShinyStartup.ConfigureApp(IServiceProvider provider)
public sealed override IServiceProvider CreateServiceProvider(IServiceCollection services)
{
RegisterApplicationServices(provider);
ConfigureApp(provider);
}

/// <inheritdoc/>
IServiceProvider IShinyStartup.CreateServiceProvider(IServiceCollection services)
{
foreach (var service in services)
foreach (var serviceDescriptor in services)
{
if (!_serviceCollection.Contains(service))
if (!_serviceCollection.Contains(serviceDescriptor))
{
_serviceCollection.Add(service);
_serviceCollection.Add(serviceDescriptor);
}
}

_serviceCollection.UseMicrosoftDependencyResolver();

return _serviceCollection.BuildServiceProvider();
}

/// <inheritdoc/>
void IShinyStartup.ConfigureServices(IServiceCollection services)
public sealed override void ConfigureServices(IServiceCollection services, IPlatform platform)
{
ConfigureShiny(services);
ConfigureAppSettings(_serviceCollection, _configurationBuilder);
ConfigureServices(_serviceCollection);
}

/// <summary>
/// Configure the application with the given service provider.
/// </summary>
/// <param name="provider">The service provider.</param>
protected virtual void ConfigureApp(IServiceProvider provider)
{
RegisterApplicationServices();
}

/// <summary>
Expand All @@ -97,8 +83,7 @@ protected virtual void ConfigureApp(IServiceProvider provider)
/// <summary>
/// Register core services.
/// </summary>
/// <param name="provider">The service provider.</param>
protected virtual void RegisterCoreServices(IServiceProvider provider)
protected virtual void RegisterCoreServices()
{
}

Expand All @@ -110,20 +95,18 @@ protected virtual void BuildConfiguration(IConfigurationBuilder configurationBui
{
}

private void RegisterApplicationServices(IServiceProvider serviceProvider)
private void RegisterApplicationServices()
{
Locator.CurrentMutable.InitializeSplat();
Locator.CurrentMutable.InitializeReactiveUI(RegistrationNamespace.XamForms);
RegisterCoreServices(serviceProvider);
RegisterCoreServices();
}

private void ConfigureAppSettings(IServiceCollection services, IConfigurationBuilder configurationBuilder)
{
configurationBuilder
.AddJsonFile("appsettings.json", optional: true)
.AddJsonFile("appsettings.dev.json", optional: true);

BuildConfiguration(configurationBuilder);
BuildConfiguration(configurationBuilder
.AddJsonFile("appsettings.json", optional: true)
.AddJsonFile("appsettings.dev.json", optional: true));

services.AddSingleton<IConfiguration>(_ => configurationBuilder.AddConfiguration(_configuration).Build());
}
Expand Down
10 changes: 5 additions & 5 deletions src/Shiny/Settings/SettingsProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@
using DynamicData;
using ReactiveUI;
using Rocket.Surgery.Airframe.Settings;
using Shiny.Settings;
using Shiny.Stores;

namespace Rocket.Surgery.Airframe.Shiny.Settings
{
/// <summary>
/// Represents a <see cref="ISettingsProvider"/> for <see cref="ISettings"/>.
/// Represents a <see cref="ISettingsProvider"/> for <see cref="IKeyValueStore"/>.
/// </summary>
public sealed class SettingsProvider : ReactiveObject, ISettingsProvider, IDisposable
{
Expand All @@ -20,11 +20,11 @@ public sealed class SettingsProvider : ReactiveObject, ISettingsProvider, IDispo
/// Initializes a new instance of the <see cref="SettingsProvider"/> class.
/// </summary>
/// <param name="shinySettings">The shiny settings interface.</param>
public SettingsProvider(ISettings shinySettings)
public SettingsProvider(IKeyValueStore shinySettings)
{
static void PersistSetting(ISetting setting, ISettings settings) => settings.Set(setting.Key, setting.Value);
static void PersistSetting(ISetting setting, IKeyValueStore settings) => settings.Set(setting.Key, setting.Value);

static void RemoveSetting(ISetting setting, ISettings settings) => settings.Remove(setting.Key);
static void RemoveSetting(ISetting setting, IKeyValueStore settings) => settings.Remove(setting.Key);

var settingsChanged = _settingsCache
.DeferUntilLoaded()
Expand Down
1 change: 1 addition & 0 deletions src/Shiny/Shiny.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
<PackageReference Include="Microsoft.Extensions.Configuration" />
<PackageReference Include="Microsoft.Extensions.Configuration.Json" />
<PackageReference Include="Microsoft.Extensions.Options.ConfigurationExtensions" />
<PackageReference Include="Shiny" />
<PackageReference Include="Shiny.Core" />
<PackageReference Include="Shiny.Locations" />
<PackageReference Include="Shiny.Notifications" />
Expand Down
28 changes: 28 additions & 0 deletions test/Airframe.Tests/Shiny/ReactiveShinyStartupTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
using FluentAssertions;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using NSubstitute;
using Shiny;
using Xunit;

namespace Airframe.Tests.Shiny
{
public class ReactiveShinyStartupTests
{
[Fact]
public void Should_Register_Configuration()
{
// Given
var configuration = Substitute.For<IConfiguration>();
var serviceCollection = new ServiceCollection();
var sut = new TestStartup(serviceCollection, configuration);

// When
sut.ConfigureServices(serviceCollection, Arg.Any<IPlatform>());

// Then
serviceCollection.Should().ContainSingle(x => x.ServiceType == typeof(IConfiguration));
}

}
}
6 changes: 3 additions & 3 deletions test/Airframe.Tests/Shiny/Settings/SettingsProviderFixture.cs
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
using NSubstitute;
using Rocket.Surgery.Airframe.Shiny.Settings;
using Rocket.Surgery.Extensions.Testing.Fixtures;
using Shiny.Settings;
using Shiny.Stores;

namespace Airframe.Tests.Shiny.Settings
{
internal class SettingsProviderFixture : ITestFixtureBuilder
{
private ISettings _settings = Substitute.For<ISettings>();
private IKeyValueStore _settings = Substitute.For<IKeyValueStore>();
public static implicit operator SettingsProvider(SettingsProviderFixture providerFixture) => providerFixture.Build();

public SettingsProviderFixture WithSettings(ISettings settings) => this.With(ref _settings, settings);
public SettingsProviderFixture WithSettings(IKeyValueStore settings) => this.With(ref _settings, settings);

private SettingsProvider Build() => new SettingsProvider(_settings);
}
Expand Down
10 changes: 3 additions & 7 deletions test/Airframe.Tests/Shiny/Settings/SettingsTests.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
using FluentAssertions;
using NSubstitute;
using ReactiveMarbles.PropertyChanged;
using Rocket.Surgery.Airframe.Shiny.Settings;
using Shiny.Settings;
using Shiny.Stores;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reactive.Linq;
using Xunit;

namespace Airframe.Tests.Shiny.Settings
Expand Down Expand Up @@ -95,7 +91,7 @@ public void GivenObservingChange_WhenSettingChanged_ThenChangeObserved()
public void GivenSetting_WhenSet_ThenPersisted()
{
// Given
var settings = Substitute.For<ISettings>();
var settings = Substitute.For<IKeyValueStore>();
SettingsProvider sut = new SettingsProviderFixture().WithSettings(settings);
sut.Set(new Setting<int>(Key, 1));

Expand All @@ -110,7 +106,7 @@ public void GivenSetting_WhenSet_ThenPersisted()
public void GivenSetting_WhenChanged_ThenPersisted()
{
// Given
var settings = Substitute.For<ISettings>();
var settings = Substitute.For<IKeyValueStore>();
SettingsProvider sut = new SettingsProviderFixture().WithSettings(settings);
sut.Set(new Setting<int>(Key, 5));
var setting = sut.Get<int>(Key);
Expand Down
21 changes: 21 additions & 0 deletions test/Airframe.Tests/Shiny/TestStartup.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Rocket.Surgery.Airframe.Shiny;

namespace Airframe.Tests.Shiny
{
internal class TestStartup : ReactiveShinyStartup
{
/// <summary>
/// Initializes a new instance of the <see cref="ReactiveShinyStartup"/> class.
/// </summary>
/// <param name="serviceCollection">The service collection.</param>
/// <param name="configuration">The configuration.</param>
public TestStartup(IServiceCollection serviceCollection, IConfiguration configuration)
: base(serviceCollection, configuration) { }

protected override void ConfigureServices(IServiceCollection services) { }

protected override void ConfigureShiny(IServiceCollection services) { }
}
}

0 comments on commit ebdc350

Please sign in to comment.