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

feature: Added Splat.DryIoc #249

Merged
merged 5 commits into from
Jan 31, 2019
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
2 changes: 2 additions & 0 deletions build.cake
Original file line number Diff line number Diff line change
Expand Up @@ -78,13 +78,15 @@ var packageWhitelist = new[]
{
"Splat",
"Splat.Autofac",
"Splat.DryIoc",
"Splat.SimpleInjector",
};

var packageTestWhitelist = new[]
{
"Splat.Tests",
"Splat.Autofac.Tests",
"Splat.DryIoc.Tests",
"Splat.SimpleInjector.Tests",
};

Expand Down
2 changes: 1 addition & 1 deletion src/Splat.Autofac.Tests/Splat.Autofac.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

<ItemGroup>
<PackageReference Include="Autofac" Version="4.8.1" />
<PackageReference Include="ReactiveUI" Version="9.8.23" />
<PackageReference Include="ReactiveUI" Version="*" />
</ItemGroup>

<ItemGroup>
Expand Down
127 changes: 127 additions & 0 deletions src/Splat.DryIoc.Tests/DependencyResolverTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
// Copyright (c) 2019 .NET Foundation and Contributors. All rights reserved.
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for full license information.

using System;
using System.Collections.Generic;
using System.Linq;
using DryIoc;
using ReactiveUI;
using Shouldly;
using Xunit;

namespace Splat.DryIoc.Tests
{
/// <summary>
/// Tests to show the <see cref="DryIocDependencyResolver"/> works correctly.
/// </summary>
public class DependencyResolverTests
{
/// <summary>
/// Shoulds the resolve views.
/// </summary>
[Fact]
public void DryIocDependencyResolver_Should_Resolve_Views()
{
var container = new Container();
container.Register<IViewFor<ViewModelOne>, ViewOne>();
container.Register<IViewFor<ViewModelTwo>, ViewTwo>();
container.UseDryIocDependencyResolver();

var viewOne = Locator.Current.GetService(typeof(IViewFor<ViewModelOne>));
var viewTwo = Locator.Current.GetService(typeof(IViewFor<ViewModelTwo>));

viewOne.ShouldNotBeNull();
viewOne.ShouldBeOfType<ViewOne>();
viewTwo.ShouldNotBeNull();
viewTwo.ShouldBeOfType<ViewTwo>();
}

/// <summary>
/// Shoulds the resolve views.
/// </summary>
[Fact]
public void DryIocDependencyResolver_Should_Resolve_Named_View()
{
var container = new Container();
container.Register<IViewFor<ViewModelTwo>, ViewTwo>(serviceKey: "Other");
container.UseDryIocDependencyResolver();

var viewTwo = Locator.Current.GetService(typeof(IViewFor<ViewModelTwo>), "Other");

viewTwo.ShouldNotBeNull();
viewTwo.ShouldBeOfType<ViewTwo>();
}

/// <summary>
/// Shoulds the resolve view models.
/// </summary>
[Fact]
public void DryIocDependencyResolver_Should_Resolve_View_Models()
{
var container = new Container();
container.Register<ViewModelOne>();
container.Register<ViewModelTwo>();
container.UseDryIocDependencyResolver();

var vmOne = Locator.Current.GetService<ViewModelOne>();
var vmTwo = Locator.Current.GetService<ViewModelTwo>();

vmOne.ShouldNotBeNull();
vmTwo.ShouldNotBeNull();
}

/// <summary>
/// Shoulds the resolve screen.
/// </summary>
[Fact]
public void DryIocDependencyResolver_Should_Resolve_Screen()
{
var builder = new Container();
builder.Register<IScreen, MockScreen>(Reuse.Singleton);
builder.UseDryIocDependencyResolver();

var screen = Locator.Current.GetService<IScreen>();

screen.ShouldNotBeNull();
screen.ShouldBeOfType<MockScreen>();
}

/// <summary>
/// Shoulds register ReactiveUI binding type converters.
/// </summary>
[Fact]
public void DryIocDependencyResolver_Should_Register_ReactiveUI_BindingTypeConverters()
{
// Invoke RxApp which initializes the ReactiveUI platform.
var scheduler = RxApp.MainThreadScheduler;
var container = new Container();
container.UseDryIocDependencyResolver();

var converters = container.Resolve<IEnumerable<IBindingTypeConverter>>().ToList();

converters.ShouldNotBeNull();
converters.ShouldContain(x => x.GetType() == typeof(StringConverter));
converters.ShouldContain(x => x.GetType() == typeof(EqualityTypeConverter));
}

/// <summary>
/// Shoulds register ReactiveUI creates command bindings.
/// </summary>
[Fact]
public void DryIocDependencyResolver_Should_Register_ReactiveUI_CreatesCommandBinding()
{
// Invoke RxApp which initializes the ReactiveUI platform.
var scheduler = RxApp.MainThreadScheduler;
var container = new Container();
container.UseDryIocDependencyResolver();

var converters = container.Resolve<IEnumerable<ICreatesCommandBinding>>().ToList();

converters.ShouldNotBeNull();
converters.ShouldContain(x => x.GetType() == typeof(CreatesCommandBindingViaEvent));
converters.ShouldContain(x => x.GetType() == typeof(CreatesCommandBindingViaCommandParameter));
}
}
}
21 changes: 21 additions & 0 deletions src/Splat.DryIoc.Tests/Mocks/MockScreen.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// Copyright (c) 2019 .NET Foundation and Contributors. All rights reserved.
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for full license information.

using ReactiveUI;

namespace Splat.DryIoc.Tests
{
/// <summary>
/// An <see cref="IScreen"/> implementation.
/// </summary>
/// <seealso cref="IScreen" />
public class MockScreen : IScreen
{
/// <summary>
/// Gets the Router associated with this Screen.
/// </summary>
public RoutingState Router { get; }
}
}
23 changes: 23 additions & 0 deletions src/Splat.DryIoc.Tests/Mocks/ViewModelOne.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// Copyright (c) 2019 .NET Foundation and Contributors. All rights reserved.
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for full license information.

using ReactiveUI;

namespace Splat.DryIoc.Tests
{
/// <summary>
/// View Model One.
/// </summary>
/// <seealso cref="ReactiveObject" />
/// <seealso cref="IRoutableViewModel" />
public class ViewModelOne : ReactiveObject, IRoutableViewModel
{
/// <inheritdoc />
public string UrlPathSegment { get; }

/// <inheritdoc />
public IScreen HostScreen { get; }
}
}
23 changes: 23 additions & 0 deletions src/Splat.DryIoc.Tests/Mocks/ViewModelTwo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// Copyright (c) 2019 .NET Foundation and Contributors. All rights reserved.
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for full license information.

using ReactiveUI;

namespace Splat.DryIoc.Tests
{
/// <summary>
/// View Model Two.
/// </summary>
/// <seealso cref="ReactiveObject" />
/// <seealso cref="IRoutableViewModel" />
public class ViewModelTwo : ReactiveObject, IRoutableViewModel
{
/// <inheritdoc />
public string UrlPathSegment { get; }

/// <inheritdoc />
public IScreen HostScreen { get; }
}
}
26 changes: 26 additions & 0 deletions src/Splat.DryIoc.Tests/Mocks/ViewOne.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// Copyright (c) 2019 .NET Foundation and Contributors. All rights reserved.
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for full license information.

using ReactiveUI;

namespace Splat.DryIoc.Tests
{
/// <summary>
/// View One.
/// </summary>
/// <seealso cref="ViewModelOne" />
public class ViewOne : IViewFor<ViewModelOne>
{
/// <inheritdoc />
object IViewFor.ViewModel
{
get => ViewModel;
set => ViewModel = (ViewModelOne)value;
}

/// <inheritdoc />
public ViewModelOne ViewModel { get; set; }
}
}
27 changes: 27 additions & 0 deletions src/Splat.DryIoc.Tests/Mocks/ViewTwo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// Copyright (c) 2019 .NET Foundation and Contributors. All rights reserved.
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for full license information.

using ReactiveUI;

namespace Splat.DryIoc.Tests
{
/// <summary>
/// View Two.
/// </summary>
/// <seealso cref="ViewModelTwo" />
[ViewContract("Other")]
public class ViewTwo : IViewFor<ViewModelTwo>
{
/// <inheritdoc />
object IViewFor.ViewModel
{
get => ViewModel;
set => ViewModel = (ViewModelTwo)value;
}

/// <inheritdoc />
public ViewModelTwo ViewModel { get; set; }
}
}
25 changes: 25 additions & 0 deletions src/Splat.DryIoc.Tests/Splat.DryIoc.Tests.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>netcoreapp2.1;net472</TargetFrameworks>

<IsPackable>false</IsPackable>
<NoWarn>$(NoWarn);1591;CA1707;SA1633</NoWarn>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="ReactiveUI" Version="*" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\Splat.DryIoc\Splat.DryIoc.csproj" />
<ProjectReference Include="..\Splat\Splat.csproj" />
</ItemGroup>

<ItemGroup>
<None Update="xunit.runner.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
</ItemGroup>

</Project>
Loading