From 81f256d2315d6d4c9769789f9e9a7c5cebc1df5d Mon Sep 17 00:00:00 2001 From: Antony Male Date: Fri, 25 Sep 2015 15:19:23 +0100 Subject: [PATCH] Move away from separate ViewManagerConfig class --- Bootstrappers/AutofacBootstrapper.cs | 10 +- Bootstrappers/CastleWindsorBootstrapper.cs | 16 +-- Bootstrappers/NinjectBootstrapper.cs | 10 +- Bootstrappers/NoIoCContainerBootstrapper.cs | 7 +- Bootstrappers/StructureMapBootstrapper.cs | 10 +- Bootstrappers/UnityBootstrapper.cs | 8 +- Stylet/Bootstrapper.cs | 15 ++- Stylet/ViewManager.cs | 67 +++++------ StyletUnitTests/ViewManagerTests.cs | 125 ++++++++------------ 9 files changed, 105 insertions(+), 163 deletions(-) diff --git a/Bootstrappers/AutofacBootstrapper.cs b/Bootstrappers/AutofacBootstrapper.cs index 1fcf443..d9d836d 100644 --- a/Bootstrappers/AutofacBootstrapper.cs +++ b/Bootstrappers/AutofacBootstrapper.cs @@ -31,13 +31,9 @@ namespace Bootstrappers /// protected virtual void DefaultConfigureIoC(ContainerBuilder builder) { - var viewManagerConfig = new ViewManagerConfig() - { - ViewAssemblies = new List() { this.GetType().Assembly }, - ViewFactory = this.GetInstance, - }; - builder.RegisterInstance(viewManagerConfig); - builder.RegisterType().As().SingleInstance(); + var viewManager = new ViewManager(this.GetInstance, new List() { this.GetType().Assembly }); + builder.RegisterInstance(viewManager); + builder.RegisterInstance(this); builder.RegisterType().As().SingleInstance(); builder.RegisterType().As().SingleInstance(); diff --git a/Bootstrappers/CastleWindsorBootstrapper.cs b/Bootstrappers/CastleWindsorBootstrapper.cs index d1c4899..3e7b6d0 100644 --- a/Bootstrappers/CastleWindsorBootstrapper.cs +++ b/Bootstrappers/CastleWindsorBootstrapper.cs @@ -31,19 +31,15 @@ namespace Bootstrappers /// protected virtual void DefaultConfigureIoC(IWindsorContainer container) { - container.AddFacility(); - var viewManagerConfig = new ViewManagerConfig() - { - ViewAssemblies = new List() { this.GetType().Assembly }, - ViewFactory = this.GetInstance, - }; + var viewManager = new ViewManager(this.GetInstance, new List() { this.GetType().Assembly }); container.Register( - Component.For().Instance(viewManagerConfig), + Component.For().Instance(viewManager), Component.For().Instance(this), - Component.For().ImplementedBy().LifestyleSingleton(), + Component.For().ImplementedBy().LifestyleTransient(), + // For some reason we need to register the delegate separately? + Component.For>().Instance(() => new MessageBoxViewModel()), Component.For().ImplementedBy().LifestyleSingleton(), - Component.For().ImplementedBy().LifestyleSingleton(), - Component.For().ImplementedBy().LifestyleTransient() + Component.For().ImplementedBy().LifestyleSingleton() ); container.Register(Classes.FromAssembly(this.GetType().Assembly).Pick().LifestyleTransient()); } diff --git a/Bootstrappers/NinjectBootstrapper.cs b/Bootstrappers/NinjectBootstrapper.cs index 49c32be..93e8078 100644 --- a/Bootstrappers/NinjectBootstrapper.cs +++ b/Bootstrappers/NinjectBootstrapper.cs @@ -29,13 +29,9 @@ namespace Bootstrappers /// protected virtual void DefaultConfigureIoC(IKernel kernel) { - var viewManagerConfig = new ViewManagerConfig() - { - ViewAssemblies = new List() { this.GetType().Assembly }, - ViewFactory = this.GetInstance, - }; - kernel.Bind().ToConstant(viewManagerConfig); - kernel.Bind().To().InSingletonScope(); + var viewManager = new ViewManager(this.GetInstance, new List() { this.GetType().Assembly }); + kernel.Bind().ToConstant(viewManager); + kernel.Bind().ToConstant(this); kernel.Bind().ToMethod(c => new WindowManager(c.Kernel.Get(), () => c.Kernel.Get(), c.Kernel.Get())).InSingletonScope(); kernel.Bind().To().InSingletonScope(); diff --git a/Bootstrappers/NoIoCContainerBootstrapper.cs b/Bootstrappers/NoIoCContainerBootstrapper.cs index 5e078a6..40cc43a 100644 --- a/Bootstrappers/NoIoCContainerBootstrapper.cs +++ b/Bootstrappers/NoIoCContainerBootstrapper.cs @@ -17,12 +17,7 @@ namespace Bootstrappers protected virtual void DefaultConfigureContainer() { - var viewManagerConfig = new ViewManagerConfig() - { - ViewAssemblies = new List() { this.GetType().Assembly }, - ViewFactory = this.GetInstance, - }; - var viewManager = new ViewManager(viewManagerConfig); + var viewManager = new ViewManager(this.GetInstance, new List() { this.GetType().Assembly }); this.Container.Add(typeof(IViewManager), () => viewManager); var windowManager = new WindowManager(viewManager, () => (IMessageBoxViewModel)this.Container[typeof(IMessageBoxViewModel)](), this); diff --git a/Bootstrappers/StructureMapBootstrapper.cs b/Bootstrappers/StructureMapBootstrapper.cs index 190c0ab..c7a92ec 100644 --- a/Bootstrappers/StructureMapBootstrapper.cs +++ b/Bootstrappers/StructureMapBootstrapper.cs @@ -32,13 +32,9 @@ namespace Bootstrappers /// protected virtual void DefaultConfigureIoC(ConfigurationExpression config) { - var viewManagerConfig = new ViewManagerConfig() - { - ViewAssemblies = new List() { this.GetType().Assembly }, - ViewFactory = this.GetInstance, - }; - config.For().Add(viewManagerConfig); - config.For().Add().LifecycleIs(); + var viewManager = new ViewManager(this.GetInstance, new List() { this.GetType().Assembly }); + config.For().Add(viewManager); + config.For().Add(this); config.For().Add().LifecycleIs(); config.For().Add().LifecycleIs(); diff --git a/Bootstrappers/UnityBootstrapper.cs b/Bootstrappers/UnityBootstrapper.cs index 49629c7..e8e5fbb 100644 --- a/Bootstrappers/UnityBootstrapper.cs +++ b/Bootstrappers/UnityBootstrapper.cs @@ -29,14 +29,8 @@ namespace Bootstrappers /// protected virtual void DefaultConfigureIoC(IUnityContainer container) { - // This is a workaround - var viewManagerConfig = new ViewManagerConfig() - { - ViewAssemblies = new List() { this.GetType().Assembly }, - ViewFactory = this.GetInstance, - }; + var viewManager = new ViewManager(this.GetInstance, new List() { this.GetType().Assembly }); // For some reason using ContainerControlledLifetimeManager results in a transient registration.... - var viewManager = new ViewManager(viewManagerConfig); container.RegisterInstance(viewManager); container.RegisterInstance(new WindowManager(viewManager, () => container.Resolve(), this)); container.RegisterInstance(new EventAggregator()); diff --git a/Stylet/Bootstrapper.cs b/Stylet/Bootstrapper.cs index a451dd1..38e9c15 100644 --- a/Stylet/Bootstrapper.cs +++ b/Stylet/Bootstrapper.cs @@ -47,15 +47,14 @@ namespace Stylet /// StyletIoC builder to use to configure the container protected virtual void DefaultConfigureIoC(StyletIoCBuilder builder) { - // Mark these as auto-bindings, so the user can replace them if they want - var viewManagerConfig = new ViewManagerConfig() - { - ViewAssemblies = new List() { this.GetType().Assembly }, - ViewFactory = this.GetInstance, - }; - builder.Bind().ToInstance(viewManagerConfig).AsWeakBinding(); + // Mark these as weak-bindings, so the user can replace them if they want + + var viewManager = new ViewManager(this.GetInstance, new List() { this.GetType().Assembly }); + // Bind it to both IViewManager and to itself, so that people can get it with Container.Get() + builder.Bind().ToInstance(viewManager).AsWeakBinding(); + builder.Bind().ToInstance(viewManager).AsWeakBinding(); + builder.Bind().ToInstance(this).AsWeakBinding(); - builder.Bind().To().InSingletonScope().AsWeakBinding(); builder.Bind().To().InSingletonScope().AsWeakBinding(); builder.Bind().To().InSingletonScope().AsWeakBinding(); builder.Bind().To().AsWeakBinding(); diff --git a/Stylet/ViewManager.cs b/Stylet/ViewManager.cs index 86e60db..3fc0941 100644 --- a/Stylet/ViewManager.cs +++ b/Stylet/ViewManager.cs @@ -45,11 +45,28 @@ namespace Stylet } /// - /// Configuration passed to ViewManager + /// Default implementation of ViewManager. Responsible for locating, creating, and settings up Views. Also owns the View.Model and View.ActionTarget attached properties /// - public class ViewManagerConfig + public class ViewManager : IViewManager { - private List _viewAssemblies = new List(); + private static readonly ILogger logger = LogManager.GetLogger(typeof(ViewManager)); + + private Func _viewFactory; // This is assigned by the ctor + + /// + /// Gets and sets the delegate used to retrieve an instance of a view + /// + public Func ViewFactory + { + get { return this._viewFactory; }set + { + if (value == null) + throw new ArgumentNullException(); + this._viewFactory = value; + } + } + + private List _viewAssemblies; // This is assigned by the ctor /// /// Gets and sets the assemblies which are used for IoC container auto-binding and searching for Views. @@ -65,12 +82,6 @@ namespace Stylet } } - /// - /// Gets and sets the delegate used to retrieve an instance of a view - /// - public Func ViewFactory { get; set; } - - private Dictionary _namespaceTransformations = new Dictionary(); /// @@ -118,32 +129,22 @@ namespace Stylet this._viewModelNameSuffix = value; } } - } - - /// - /// Default implementation of ViewManager. Responsible for locating, creating, and settings up Views. Also owns the View.Model and View.ActionTarget attached properties - /// - public class ViewManager : IViewManager - { - private static readonly ILogger logger = LogManager.GetLogger(typeof(ViewManager)); - - /// - /// Gets or sets the configuration object provided to this ViewManager - /// - protected ViewManagerConfig Config { get; set; } - /// /// Initialises a new instance of the class, with the given viewFactory /// - /// Configuration to use - public ViewManager(ViewManagerConfig config) + /// ViewFactory to use + /// Assembles to search for views in + public ViewManager(Func viewFactory, List viewAssemblies) { // Config.ViewAssemblies cannot be null - ViewManagerConfig ensures this - if (config.ViewFactory == null) - throw new ArgumentNullException("config.ViewFactory"); + if (viewFactory == null) + throw new ArgumentNullException("viewFactoryy"); + if (viewAssemblies == null) + throw new ArgumentNullException("viewAssemblies"); - this.Config = config; + this.ViewFactory = viewFactory; + this.ViewAssemblies = viewAssemblies; } /// @@ -216,7 +217,7 @@ namespace Stylet /// Type for that view name protected virtual Type ViewTypeForViewName(string viewName) { - return this.Config.ViewAssemblies.Select(x => x.GetType(viewName)).FirstOrDefault(); + return this.ViewAssemblies.Select(x => x.GetType(viewName)).FirstOrDefault(); } /// @@ -232,7 +233,7 @@ namespace Stylet { string transformed = modelTypeName; - foreach (var transformation in this.Config.NamespaceTransformations) + foreach (var transformation in this.NamespaceTransformations) { if (transformed.StartsWith(transformation.Key + ".")) { @@ -242,8 +243,8 @@ namespace Stylet } transformed = Regex.Replace(transformed, - String.Format(@"(?<=.){0}(?=s?\.)|{0}$", Regex.Escape(this.Config.ViewModelNameSuffix)), - Regex.Escape(this.Config.ViewNameSuffix)); + String.Format(@"(?<=.){0}(?=s?\.)|{0}$", Regex.Escape(this.ViewModelNameSuffix)), + Regex.Escape(this.ViewNameSuffix)); return transformed; } @@ -291,7 +292,7 @@ namespace Stylet throw e; } - var view = (UIElement)this.Config.ViewFactory(viewType); + var view = (UIElement)this.ViewFactory(viewType); this.InitializeView(view, viewType); diff --git a/StyletUnitTests/ViewManagerTests.cs b/StyletUnitTests/ViewManagerTests.cs index 2e6abe5..5ac7b08 100644 --- a/StyletUnitTests/ViewManagerTests.cs +++ b/StyletUnitTests/ViewManagerTests.cs @@ -24,11 +24,11 @@ namespace StyletUnitTests private interface I1 { } private abstract class AC1 { } private class C1 { } - private ViewManagerConfig viewManagerConfig; private class AccessibleViewManager : ViewManager { - public AccessibleViewManager(ViewManagerConfig config) : base(config) { } + public AccessibleViewManager(Func viewFactory, List viewAssemblies) + : base(viewFactory, viewAssemblies) { } public new UIElement CreateViewForModel(object model) { @@ -61,7 +61,8 @@ namespace StyletUnitTests public UIElement View; public object RequestedModel; - public CreatingAndBindingViewManager(ViewManagerConfig config) : base(config) { } + public CreatingAndBindingViewManager(Func viewFactory, List viewAssemblies) + : base(viewFactory, viewAssemblies) { } public override UIElement CreateViewForModel(object model) { @@ -80,7 +81,8 @@ namespace StyletUnitTests private class LocatingViewManager : ViewManager { - public LocatingViewManager(ViewManagerConfig config) : base(config) { } + public LocatingViewManager(Func viewFactory, List viewAssemblies) + : base(viewFactory, viewAssemblies) { } public Type LocatedViewType; protected override Type LocateViewForModel(Type modelType) @@ -91,7 +93,8 @@ namespace StyletUnitTests private class ResolvingViewManager : ViewManager { - public ResolvingViewManager(ViewManagerConfig config) : base(config) { } + public ResolvingViewManager(Func viewFactory, List viewAssemblies) + : base(viewFactory, viewAssemblies) { } public Type ViewType; protected override Type ViewTypeForViewName(string viewName) @@ -125,46 +128,39 @@ namespace StyletUnitTests [SetUp] public void SetUp() { - this.viewManagerConfig = new ViewManagerConfig() - { - ViewFactory = type => null, - }; - this.viewManager = new AccessibleViewManager(this.viewManagerConfig); + this.viewManager = new AccessibleViewManager(type => null, new List()); } [Test] - public void ViewManagerConfigRejectsNullViewAssemblies() + public void ViewManagerRejectsNullViewAssemblies() { - var config = new ViewManagerConfig(); - Assert.Throws(() => config.ViewAssemblies = null); + Assert.Throws(() => new ViewManager(type => null, null)); + Assert.Throws(() => this.viewManager.ViewAssemblies = null); } [Test] - public void ViewManagerConfigRejectsNullNamespaceTransformations() + public void ViewManagerRejectsNullNamespaceTransformations() { - var config = new ViewManagerConfig(); - Assert.Throws(() => config.NamespaceTransformations = null); + Assert.Throws(() => this.viewManager.NamespaceTransformations = null); } [Test] - public void ViewManagerConfigRejectsNullViewNameSuffix() + public void ViewManagerRejectsNullViewNameSuffix() { - var config = new ViewManagerConfig(); - Assert.Throws(() => config.ViewNameSuffix = null); + Assert.Throws(() => this.viewManager.ViewNameSuffix = null); } [Test] - public void ViewManagerConfigRejectsNullViewModelNameSuffix() + public void ViewManagerRejectsNullViewModelNameSuffix() { - var config = new ViewManagerConfig(); - Assert.Throws(() => config.ViewModelNameSuffix = null); + Assert.Throws(() => this.viewManager.ViewModelNameSuffix = null); } [Test] public void ViewManagerRejectsNullViewFactory() { - var config = new ViewManagerConfig(); - Assert.Throws(() => new ViewManager(config)); + Assert.Throws(() => new ViewManager(null, new List())); + Assert.Throws(() => this.viewManager.ViewFactory = null); } [Test] @@ -201,7 +197,7 @@ namespace StyletUnitTests var target = new ContentControl(); var model = new object(); var view = new UIElement(); - var viewManager = new CreatingAndBindingViewManager(this.viewManagerConfig); + var viewManager = new CreatingAndBindingViewManager(type => null, new List()); viewManager.View = view; @@ -219,7 +215,7 @@ namespace StyletUnitTests var target = new ContentControl(); var model = new object(); var view = new Window(); - var viewManager = new CreatingAndBindingViewManager(this.viewManagerConfig); + var viewManager = new CreatingAndBindingViewManager(type => null, new List()); viewManager.View = view; @@ -229,13 +225,7 @@ namespace StyletUnitTests [Test] public void CreateViewForModelReturnsNullIfViewNotFound() { - var config = new ViewManagerConfig() - { - ViewAssemblies = new List() { typeof(BootstrapperBase).Assembly, Assembly.GetExecutingAssembly() }, - ViewFactory = type => null, - }; - - var viewManager = new AccessibleViewManager(config); + var viewManager = new AccessibleViewManager(type => null, new List() { typeof(BootstrapperBase).Assembly, Assembly.GetExecutingAssembly() }); Assert.IsNull(viewManager.ViewTypeForViewName("Test")); } @@ -248,11 +238,7 @@ namespace StyletUnitTests [Test] public void LocateViewForModelThrowsIfTypeLocationDoesntWork() { - var config = new ViewManagerConfig() - { - ViewFactory = type => null, - }; - var viewManager = new ResolvingViewManager(config); + var viewManager = new ResolvingViewManager(type => null, new List()); viewManager.ViewType = null; Assert.Throws(() => viewManager.LocateViewForModel(typeof(C1))); } @@ -260,12 +246,7 @@ namespace StyletUnitTests [Test] public void LocateViewForModelFindsViewForModel() { - var config = new ViewManagerConfig() - { - ViewFactory = type => null, - ViewAssemblies = new List() { Assembly.GetExecutingAssembly() } - }; - var viewManager = new AccessibleViewManager(config); + var viewManager = new AccessibleViewManager(type => null, new List() { Assembly.GetExecutingAssembly() }); var viewType = viewManager.LocateViewForModel(typeof(ViewManagerTestsViewModel)); Assert.AreEqual(typeof(ViewManagerTestsView), viewType); } @@ -273,7 +254,7 @@ namespace StyletUnitTests [Test] public void CreateViewForModelIfNecessaryThrowsIfViewIsNotConcreteUIElement() { - var viewManager = new LocatingViewManager(this.viewManagerConfig); + var viewManager = new LocatingViewManager(type => null, new List()); viewManager.LocatedViewType = typeof(I1); Assert.Throws(() => viewManager.CreateAndBindViewForModelIfNecessary(new object())); @@ -289,11 +270,7 @@ namespace StyletUnitTests public void CreateAndBindViewForModelIfNecessaryCallsFetchesViewAndCallsInitializeComponent() { var view = new TestView(); - var config = new ViewManagerConfig() - { - ViewFactory = type => view - }; - var viewManager = new LocatingViewManager(config); + var viewManager = new LocatingViewManager(type => view, new List()); viewManager.LocatedViewType = typeof(TestView); var returnedView = viewManager.CreateAndBindViewForModelIfNecessary(new object()); @@ -318,11 +295,7 @@ namespace StyletUnitTests public void CreateViewForModelDoesNotComplainIfNoInitializeComponentMethod() { var view = new UIElement(); - var config = new ViewManagerConfig() - { - ViewFactory = type => view, - }; - var viewManager = new LocatingViewManager(config); + var viewManager = new LocatingViewManager(type => view, new List()); viewManager.LocatedViewType = typeof(UIElement); var returnedView = viewManager.CreateAndBindViewForModelIfNecessary(new object()); @@ -334,7 +307,7 @@ namespace StyletUnitTests public void BindViewToModelDoesNotSetActionTarget() { var view = new UIElement(); - var viewManager = new AccessibleViewManager(this.viewManagerConfig); + var viewManager = new AccessibleViewManager(type => null, new List()); viewManager.BindViewToModel(view, new object()); Assert.AreEqual(View.InitialActionTarget, View.GetActionTarget(view)); @@ -345,7 +318,7 @@ namespace StyletUnitTests { var view = new FrameworkElement(); var model = new object(); - var viewManager = new AccessibleViewManager(this.viewManagerConfig); + var viewManager = new AccessibleViewManager(type => null, new List()); viewManager.BindViewToModel(view, model); Assert.AreEqual(model, view.DataContext); @@ -356,7 +329,7 @@ namespace StyletUnitTests { var view = new UIElement(); var model = new Mock(); - var viewManager = new AccessibleViewManager(this.viewManagerConfig); + var viewManager = new AccessibleViewManager(type => null, new List()); viewManager.BindViewToModel(view, model.Object); model.Verify(x => x.AttachView(view)); @@ -365,29 +338,26 @@ namespace StyletUnitTests [Test] public void ViewNameResolutionWorksAsExpected() { - var viewManager = new AccessibleViewManager(this.viewManagerConfig); + Assert.AreEqual("Root.Test.ThingView", this.viewManager.ViewTypeNameForModelTypeName("Root.Test.ThingViewModel")); + Assert.AreEqual("Root.Views.ThingView", this.viewManager.ViewTypeNameForModelTypeName("Root.ViewModels.ThingViewModel")); + Assert.AreEqual("Root.View.ThingView", this.viewManager.ViewTypeNameForModelTypeName("Root.ViewModel.ThingViewModel")); + Assert.AreEqual("Root.View.ViewModelThing", this.viewManager.ViewTypeNameForModelTypeName("Root.ViewModel.ViewModelThing")); + Assert.AreEqual("Root.ThingViews.ThingView", this.viewManager.ViewTypeNameForModelTypeName("Root.ThingViewModels.ThingViewModel")); + Assert.AreEqual("Root.ThingView.ThingView", this.viewManager.ViewTypeNameForModelTypeName("Root.ThingViewModel.ThingViewModel")); - Assert.AreEqual("Root.Test.ThingView", viewManager.ViewTypeNameForModelTypeName("Root.Test.ThingViewModel")); - Assert.AreEqual("Root.Views.ThingView", viewManager.ViewTypeNameForModelTypeName("Root.ViewModels.ThingViewModel")); - Assert.AreEqual("Root.View.ThingView", viewManager.ViewTypeNameForModelTypeName("Root.ViewModel.ThingViewModel")); - Assert.AreEqual("Root.View.ViewModelThing", viewManager.ViewTypeNameForModelTypeName("Root.ViewModel.ViewModelThing")); - Assert.AreEqual("Root.ThingViews.ThingView", viewManager.ViewTypeNameForModelTypeName("Root.ThingViewModels.ThingViewModel")); - Assert.AreEqual("Root.ThingView.ThingView", viewManager.ViewTypeNameForModelTypeName("Root.ThingViewModel.ThingViewModel")); + Assert.AreEqual("Root.ViewModelsNamespace.ThingView", this.viewManager.ViewTypeNameForModelTypeName("Root.ViewModelsNamespace.ThingViewModel")); + Assert.AreEqual("Root.ViewModelNamespace.ThingView", this.viewManager.ViewTypeNameForModelTypeName("Root.ViewModelNamespace.ThingViewModel")); + Assert.AreEqual("Root.NamespaceOfViews.ThingView", this.viewManager.ViewTypeNameForModelTypeName("Root.NamespaceOfViewModels.ThingViewModel")); + Assert.AreEqual("Root.NamespaceOfView.ThingView", this.viewManager.ViewTypeNameForModelTypeName("Root.NamespaceOfViewModel.ThingViewModel")); - Assert.AreEqual("Root.ViewModelsNamespace.ThingView", viewManager.ViewTypeNameForModelTypeName("Root.ViewModelsNamespace.ThingViewModel")); - Assert.AreEqual("Root.ViewModelNamespace.ThingView", viewManager.ViewTypeNameForModelTypeName("Root.ViewModelNamespace.ThingViewModel")); - Assert.AreEqual("Root.NamespaceOfViews.ThingView", viewManager.ViewTypeNameForModelTypeName("Root.NamespaceOfViewModels.ThingViewModel")); - Assert.AreEqual("Root.NamespaceOfView.ThingView", viewManager.ViewTypeNameForModelTypeName("Root.NamespaceOfViewModel.ThingViewModel")); - - Assert.AreEqual("ViewModels.TestView", viewManager.ViewTypeNameForModelTypeName("ViewModels.TestViewModel")); + Assert.AreEqual("ViewModels.TestView", this.viewManager.ViewTypeNameForModelTypeName("ViewModels.TestViewModel")); } [Test] public void ViewNameResolutionUsesConfig() { - this.viewManagerConfig.ViewNameSuffix = "Viiiiew"; - this.viewManagerConfig.ViewModelNameSuffix = "ViiiiiewModel"; - var viewManager = new AccessibleViewManager(this.viewManagerConfig); + this.viewManager.ViewNameSuffix = "Viiiiew"; + this.viewManager.ViewModelNameSuffix = "ViiiiiewModel"; Assert.AreEqual("Root.Test.ThingViiiiew", viewManager.ViewTypeNameForModelTypeName("Root.Test.ThingViiiiiewModel")); } @@ -395,8 +365,7 @@ namespace StyletUnitTests [Test] public void NamespaceTransformationsTransformsNamespace() { - this.viewManagerConfig.NamespaceTransformations["Foo.Bar"] = "Baz.Yay"; - var viewManager = new AccessibleViewManager(this.viewManagerConfig); + this.viewManager.NamespaceTransformations["Foo.Bar"] = "Baz.Yay"; Assert.AreEqual("Baz.Yay.ThingView", viewManager.ViewTypeNameForModelTypeName("Foo.Bar.ThingViewModel")); Assert.AreEqual("Baz.Yay.Thing", viewManager.ViewTypeNameForModelTypeName("Foo.Bar.Thing")); @@ -405,8 +374,8 @@ namespace StyletUnitTests [Test] public void NamespaceTransformationsTransformOnlyFirstMatch() { - this.viewManagerConfig.NamespaceTransformations["Foo.Bar"] = "Baz.Yay"; - this.viewManagerConfig.NamespaceTransformations["Baz.Yay"] = "One.Two"; + this.viewManager.NamespaceTransformations["Foo.Bar"] = "Baz.Yay"; + this.viewManager.NamespaceTransformations["Baz.Yay"] = "One.Two"; Assert.AreEqual("Baz.Yay.ThingView", viewManager.ViewTypeNameForModelTypeName("Foo.Bar.ThingViewModel")); Assert.AreEqual("One.Two.ThingView", viewManager.ViewTypeNameForModelTypeName("Baz.Yay.ThingViewModel"));