From 20c11093fd55d22186e6b5d1989217a3cd7e8982 Mon Sep 17 00:00:00 2001 From: Florian Doyon Date: Sun, 8 Dec 2019 02:04:49 -0500 Subject: [PATCH 1/6] DefaultViewLocator now public for users to override ViewModelToViewFunc --- src/ReactiveUI/View/DefaultViewLocator.cs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/ReactiveUI/View/DefaultViewLocator.cs b/src/ReactiveUI/View/DefaultViewLocator.cs index d2a8d9c4a1..002df76964 100644 --- a/src/ReactiveUI/View/DefaultViewLocator.cs +++ b/src/ReactiveUI/View/DefaultViewLocator.cs @@ -11,14 +11,18 @@ namespace ReactiveUI { - internal sealed class DefaultViewLocator : IViewLocator, IEnableLogger + /// + /// Default implementation for . The default + /// behavior is to replace instances of "View" with "ViewMode" in the Fully Qualified Name of the ViewModel type. + /// + public sealed class DefaultViewLocator : IViewLocator, IEnableLogger { /// /// Initializes a new instance of the class. /// /// The method which will convert a ViewModel name into a View. [SuppressMessage("Globalization", "CA1307: operator could change based on locale settings", Justification = "Replace() does not have third parameter on all platforms")] - public DefaultViewLocator(Func viewModelToViewFunc = null) + internal DefaultViewLocator(Func viewModelToViewFunc = null) { ViewModelToViewFunc = viewModelToViewFunc ?? (vm => vm.Replace("ViewModel", "View")); } From 3ed129723a43a0cac1d4d469337747819bd81591 Mon Sep 17 00:00:00 2001 From: Florian Doyon Date: Sun, 8 Dec 2019 02:14:32 -0500 Subject: [PATCH 2/6] added unit tests --- .../Locator/DefaultViewLocatorTests.cs | 26 +++++++++++++++++-- .../Locator/Mocks/RoutableFooCustomView.cs | 18 +++++++++++++ 2 files changed, 42 insertions(+), 2 deletions(-) create mode 100644 src/ReactiveUI.Tests/Locator/Mocks/RoutableFooCustomView.cs diff --git a/src/ReactiveUI.Tests/Locator/DefaultViewLocatorTests.cs b/src/ReactiveUI.Tests/Locator/DefaultViewLocatorTests.cs index 8ab74f8468..ea9f9475b2 100644 --- a/src/ReactiveUI.Tests/Locator/DefaultViewLocatorTests.cs +++ b/src/ReactiveUI.Tests/Locator/DefaultViewLocatorTests.cs @@ -61,7 +61,8 @@ public void ViewModelToViewNamingConventionCanBeCustomized() using (resolver.WithResolver()) { var fixture = new DefaultViewLocator(); - fixture.ViewModelToViewFunc = viewModelName => viewModelName.Replace("ViewModel", "WithWeirdConvention"); + fixture.ViewModelToViewFunc = + viewModelName => viewModelName.Replace("ViewModel", "WithWeirdConvention"); var vm = new FooViewModel(); var result = fixture.ResolveView(vm); @@ -220,7 +221,8 @@ public void NoErrorIsRaisedIfATypeCannotBeFound() using (resolver.WithResolver()) { var fixture = new DefaultViewLocator(); - fixture.ViewModelToViewFunc = viewModelName => "DoesNotExist, " + typeof(DefaultViewLocatorTests).Assembly.FullName; + fixture.ViewModelToViewFunc = viewModelName => + "DoesNotExist, " + typeof(DefaultViewLocatorTests).Assembly.FullName; var vm = new FooViewModel(); var result = fixture.ResolveView(vm); @@ -320,5 +322,25 @@ public void CanResolveViewFromViewModelWithIRoutableViewModelType() Assert.IsType(result); } } + + [Fact] + public void CanOverrideNameResolutionFunc() + { + var resolver = new ModernDependencyResolver(); + + resolver.InitializeSplat(); + resolver.InitializeReactiveUI(); + resolver.Register(() => new RoutableFooCustomView()); + + using (resolver.WithResolver()) + { + var fixture = new DefaultViewLocator(); + fixture.ViewModelToViewFunc = x => x.Replace("ViewModel", "CustomView"); + var vm = new RoutableFooViewModel(); + + var result = fixture.ResolveView(vm); + Assert.IsType(result); + } + } } } diff --git a/src/ReactiveUI.Tests/Locator/Mocks/RoutableFooCustomView.cs b/src/ReactiveUI.Tests/Locator/Mocks/RoutableFooCustomView.cs new file mode 100644 index 0000000000..8191172c32 --- /dev/null +++ b/src/ReactiveUI.Tests/Locator/Mocks/RoutableFooCustomView.cs @@ -0,0 +1,18 @@ +// 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. + +namespace ReactiveUI.Tests +{ + public class RoutableFooCustomView : IViewFor + { + object IViewFor.ViewModel + { + get => ViewModel; + set => ViewModel = (IRoutableFooViewModel)value; + } + + public IRoutableFooViewModel ViewModel { get; set; } + } +} From eac04b8a11d0159ce76aabeb4e503247de461f80 Mon Sep 17 00:00:00 2001 From: Florian Doyon Date: Mon, 9 Dec 2019 09:49:08 -0500 Subject: [PATCH 3/6] fix API coverage tests for .net461 and .netcoreapp3 --- .../API/ApiApprovalTests.ReactiveUI.net461.approved.txt | 8 +++++++- ...ApiApprovalTests.ReactiveUI.netcoreapp3.0.approved.txt | 8 +++++++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/src/ReactiveUI.Tests/API/ApiApprovalTests.ReactiveUI.net461.approved.txt b/src/ReactiveUI.Tests/API/ApiApprovalTests.ReactiveUI.net461.approved.txt index 731a077e4c..9926254887 100644 --- a/src/ReactiveUI.Tests/API/ApiApprovalTests.ReactiveUI.net461.approved.txt +++ b/src/ReactiveUI.Tests/API/ApiApprovalTests.ReactiveUI.net461.approved.txt @@ -116,6 +116,12 @@ namespace ReactiveUI public System.IDisposable BindCommandToObject(System.Windows.Input.ICommand command, object target, System.IObservable commandParameter, string eventName) { } public int GetAffinityForObject(System.Type type, bool hasEventTarget) { } } + public sealed class DefaultViewLocator : ReactiveUI.IViewLocator, Splat.IEnableLogger + { + public System.Func ViewModelToViewFunc { get; set; } + public ReactiveUI.IViewFor ResolveView(T viewModel, string contract = null) + where T : class { } + } public class static DependencyResolverMixins { public static void InitializeReactiveUI(this Splat.IMutableDependencyResolver resolver) { } @@ -834,4 +840,4 @@ namespace System.Reactive.Disposables public static T DisposeWith(this T item, System.Reactive.Disposables.CompositeDisposable compositeDisposable) where T : System.IDisposable { } } -} \ No newline at end of file +} diff --git a/src/ReactiveUI.Tests/API/ApiApprovalTests.ReactiveUI.netcoreapp3.0.approved.txt b/src/ReactiveUI.Tests/API/ApiApprovalTests.ReactiveUI.netcoreapp3.0.approved.txt index b9d0267519..e104d257cf 100644 --- a/src/ReactiveUI.Tests/API/ApiApprovalTests.ReactiveUI.netcoreapp3.0.approved.txt +++ b/src/ReactiveUI.Tests/API/ApiApprovalTests.ReactiveUI.netcoreapp3.0.approved.txt @@ -116,6 +116,12 @@ namespace ReactiveUI public System.IDisposable BindCommandToObject(System.Windows.Input.ICommand command, object target, System.IObservable commandParameter, string eventName) { } public int GetAffinityForObject(System.Type type, bool hasEventTarget) { } } + public sealed class DefaultViewLocator : ReactiveUI.IViewLocator, Splat.IEnableLogger + { + public System.Func ViewModelToViewFunc { get; set; } + public ReactiveUI.IViewFor ResolveView(T viewModel, string contract = null) + where T : class { } + } public class static DependencyResolverMixins { public static void InitializeReactiveUI(this Splat.IMutableDependencyResolver resolver) { } @@ -834,4 +840,4 @@ namespace System.Reactive.Disposables public static T DisposeWith(this T item, System.Reactive.Disposables.CompositeDisposable compositeDisposable) where T : System.IDisposable { } } -} \ No newline at end of file +} From e6ce0ac22299e340f2af141cab87cbb85e126141 Mon Sep 17 00:00:00 2001 From: Florian Doyon Date: Mon, 9 Dec 2019 11:20:33 -0500 Subject: [PATCH 4/6] fix EOL --- .../API/ApiApprovalTests.ReactiveUI.net461.approved.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/src/ReactiveUI.Tests/API/ApiApprovalTests.ReactiveUI.net461.approved.txt b/src/ReactiveUI.Tests/API/ApiApprovalTests.ReactiveUI.net461.approved.txt index 9926254887..d7129046a8 100644 --- a/src/ReactiveUI.Tests/API/ApiApprovalTests.ReactiveUI.net461.approved.txt +++ b/src/ReactiveUI.Tests/API/ApiApprovalTests.ReactiveUI.net461.approved.txt @@ -841,3 +841,4 @@ namespace System.Reactive.Disposables where T : System.IDisposable { } } } + From d87967bd3dc3fd8ceafc8479af48a3526d863d76 Mon Sep 17 00:00:00 2001 From: Florian Doyon Date: Mon, 9 Dec 2019 14:37:38 -0500 Subject: [PATCH 5/6] fix line ending issues --- .../API/ApiApprovalTests.ReactiveUI.net461.approved.txt | 3 +-- .../API/ApiApprovalTests.ReactiveUI.netcoreapp3.0.approved.txt | 2 +- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/src/ReactiveUI.Tests/API/ApiApprovalTests.ReactiveUI.net461.approved.txt b/src/ReactiveUI.Tests/API/ApiApprovalTests.ReactiveUI.net461.approved.txt index d7129046a8..33f7f63019 100644 --- a/src/ReactiveUI.Tests/API/ApiApprovalTests.ReactiveUI.net461.approved.txt +++ b/src/ReactiveUI.Tests/API/ApiApprovalTests.ReactiveUI.net461.approved.txt @@ -840,5 +840,4 @@ namespace System.Reactive.Disposables public static T DisposeWith(this T item, System.Reactive.Disposables.CompositeDisposable compositeDisposable) where T : System.IDisposable { } } -} - +} \ No newline at end of file diff --git a/src/ReactiveUI.Tests/API/ApiApprovalTests.ReactiveUI.netcoreapp3.0.approved.txt b/src/ReactiveUI.Tests/API/ApiApprovalTests.ReactiveUI.netcoreapp3.0.approved.txt index e104d257cf..77404d6038 100644 --- a/src/ReactiveUI.Tests/API/ApiApprovalTests.ReactiveUI.netcoreapp3.0.approved.txt +++ b/src/ReactiveUI.Tests/API/ApiApprovalTests.ReactiveUI.netcoreapp3.0.approved.txt @@ -840,4 +840,4 @@ namespace System.Reactive.Disposables public static T DisposeWith(this T item, System.Reactive.Disposables.CompositeDisposable compositeDisposable) where T : System.IDisposable { } } -} +} \ No newline at end of file From 24d4ff27ee6e1aff59a86a73024f0af951432216 Mon Sep 17 00:00:00 2001 From: Rodney Littles II <6969701+RLittlesII@users.noreply.github.com> Date: Fri, 13 Dec 2019 00:19:04 -0600 Subject: [PATCH 6/6] Temporarily skip CommandBindingTests --- src/ReactiveUI.Tests/Platforms/winforms/CommandBindingTests.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ReactiveUI.Tests/Platforms/winforms/CommandBindingTests.cs b/src/ReactiveUI.Tests/Platforms/winforms/CommandBindingTests.cs index f7b011deaf..7792536db9 100755 --- a/src/ReactiveUI.Tests/Platforms/winforms/CommandBindingTests.cs +++ b/src/ReactiveUI.Tests/Platforms/winforms/CommandBindingTests.cs @@ -66,7 +66,7 @@ public void CommandBinderBindsToCustomControl() } } - [Fact] + [Fact(Skip = "https://github.com/reactiveui/ReactiveUI/issues/2279")] public void CommandBinderBindsToCustomComponent() { var fixture = new CreatesWinformsCommandBinding();