Move away from separate ViewManagerConfig class

This commit is contained in:
Antony Male 2015-09-25 15:19:23 +01:00
parent d265bb3ba2
commit 81f256d231
9 changed files with 105 additions and 163 deletions

View File

@ -31,13 +31,9 @@ namespace Bootstrappers
/// </summary>
protected virtual void DefaultConfigureIoC(ContainerBuilder builder)
{
var viewManagerConfig = new ViewManagerConfig()
{
ViewAssemblies = new List<Assembly>() { this.GetType().Assembly },
ViewFactory = this.GetInstance,
};
builder.RegisterInstance<ViewManagerConfig>(viewManagerConfig);
builder.RegisterType<ViewManager>().As<IViewManager>().SingleInstance();
var viewManager = new ViewManager(this.GetInstance, new List<Assembly>() { this.GetType().Assembly });
builder.RegisterInstance<IViewManager>(viewManager);
builder.RegisterInstance<IWindowManagerConfig>(this);
builder.RegisterType<WindowManager>().As<IWindowManager>().SingleInstance();
builder.RegisterType<EventAggregator>().As<IEventAggregator>().SingleInstance();

View File

@ -31,19 +31,15 @@ namespace Bootstrappers
/// </summary>
protected virtual void DefaultConfigureIoC(IWindsorContainer container)
{
container.AddFacility<TypedFactoryFacility>();
var viewManagerConfig = new ViewManagerConfig()
{
ViewAssemblies = new List<Assembly>() { this.GetType().Assembly },
ViewFactory = this.GetInstance,
};
var viewManager = new ViewManager(this.GetInstance, new List<Assembly>() { this.GetType().Assembly });
container.Register(
Component.For<ViewManagerConfig>().Instance(viewManagerConfig),
Component.For<IViewManager>().Instance(viewManager),
Component.For<IWindowManagerConfig>().Instance(this),
Component.For<IViewManager>().ImplementedBy<ViewManager>().LifestyleSingleton(),
Component.For<IMessageBoxViewModel>().ImplementedBy<MessageBoxViewModel>().LifestyleTransient(),
// For some reason we need to register the delegate separately?
Component.For<Func<IMessageBoxViewModel>>().Instance(() => new MessageBoxViewModel()),
Component.For<IWindowManager>().ImplementedBy<WindowManager>().LifestyleSingleton(),
Component.For<IEventAggregator>().ImplementedBy<EventAggregator>().LifestyleSingleton(),
Component.For<IMessageBoxViewModel>().ImplementedBy<MessageBoxViewModel>().LifestyleTransient()
Component.For<IEventAggregator>().ImplementedBy<EventAggregator>().LifestyleSingleton()
);
container.Register(Classes.FromAssembly(this.GetType().Assembly).Pick().LifestyleTransient());
}

View File

@ -29,13 +29,9 @@ namespace Bootstrappers
/// </summary>
protected virtual void DefaultConfigureIoC(IKernel kernel)
{
var viewManagerConfig = new ViewManagerConfig()
{
ViewAssemblies = new List<Assembly>() { this.GetType().Assembly },
ViewFactory = this.GetInstance,
};
kernel.Bind<ViewManagerConfig>().ToConstant(viewManagerConfig);
kernel.Bind<IViewManager>().To<ViewManager>().InSingletonScope();
var viewManager = new ViewManager(this.GetInstance, new List<Assembly>() { this.GetType().Assembly });
kernel.Bind<IViewManager>().ToConstant(viewManager);
kernel.Bind<IWindowManagerConfig>().ToConstant(this);
kernel.Bind<IWindowManager>().ToMethod(c => new WindowManager(c.Kernel.Get<IViewManager>(), () => c.Kernel.Get<IMessageBoxViewModel>(), c.Kernel.Get<IWindowManagerConfig>())).InSingletonScope();
kernel.Bind<IEventAggregator>().To<EventAggregator>().InSingletonScope();

View File

@ -17,12 +17,7 @@ namespace Bootstrappers
protected virtual void DefaultConfigureContainer()
{
var viewManagerConfig = new ViewManagerConfig()
{
ViewAssemblies = new List<Assembly>() { this.GetType().Assembly },
ViewFactory = this.GetInstance,
};
var viewManager = new ViewManager(viewManagerConfig);
var viewManager = new ViewManager(this.GetInstance, new List<Assembly>() { this.GetType().Assembly });
this.Container.Add(typeof(IViewManager), () => viewManager);
var windowManager = new WindowManager(viewManager, () => (IMessageBoxViewModel)this.Container[typeof(IMessageBoxViewModel)](), this);

View File

@ -32,13 +32,9 @@ namespace Bootstrappers
/// </summary>
protected virtual void DefaultConfigureIoC(ConfigurationExpression config)
{
var viewManagerConfig = new ViewManagerConfig()
{
ViewAssemblies = new List<Assembly>() { this.GetType().Assembly },
ViewFactory = this.GetInstance,
};
config.For<ViewManagerConfig>().Add(viewManagerConfig);
config.For<IViewManager>().Add<ViewManager>().LifecycleIs<SingletonLifecycle>();
var viewManager = new ViewManager(this.GetInstance, new List<Assembly>() { this.GetType().Assembly });
config.For<IViewManager>().Add(viewManager);
config.For<IWindowManagerConfig>().Add(this);
config.For<IWindowManager>().Add<WindowManager>().LifecycleIs<SingletonLifecycle>();
config.For<IEventAggregator>().Add<EventAggregator>().LifecycleIs<SingletonLifecycle>();

View File

@ -29,14 +29,8 @@ namespace Bootstrappers
/// </summary>
protected virtual void DefaultConfigureIoC(IUnityContainer container)
{
// This is a workaround
var viewManagerConfig = new ViewManagerConfig()
{
ViewAssemblies = new List<Assembly>() { this.GetType().Assembly },
ViewFactory = this.GetInstance,
};
var viewManager = new ViewManager(this.GetInstance, new List<Assembly>() { this.GetType().Assembly });
// For some reason using ContainerControlledLifetimeManager results in a transient registration....
var viewManager = new ViewManager(viewManagerConfig);
container.RegisterInstance<IViewManager>(viewManager);
container.RegisterInstance<IWindowManager>(new WindowManager(viewManager, () => container.Resolve<IMessageBoxViewModel>(), this));
container.RegisterInstance<IEventAggregator>(new EventAggregator());

View File

@ -47,15 +47,14 @@ namespace Stylet
/// <param name="builder">StyletIoC builder to use to configure the container</param>
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<Assembly>() { this.GetType().Assembly },
ViewFactory = this.GetInstance,
};
builder.Bind<ViewManagerConfig>().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<Assembly>() { this.GetType().Assembly });
// Bind it to both IViewManager and to itself, so that people can get it with Container.Get<ViewManager>()
builder.Bind<ViewManager>().ToInstance(viewManager).AsWeakBinding();
builder.Bind<IViewManager>().ToInstance(viewManager).AsWeakBinding();
builder.Bind<IWindowManagerConfig>().ToInstance(this).AsWeakBinding();
builder.Bind<IViewManager>().To<ViewManager>().InSingletonScope().AsWeakBinding();
builder.Bind<IWindowManager>().To<WindowManager>().InSingletonScope().AsWeakBinding();
builder.Bind<IEventAggregator>().To<EventAggregator>().InSingletonScope().AsWeakBinding();
builder.Bind<IMessageBoxViewModel>().To<MessageBoxViewModel>().AsWeakBinding();

View File

@ -45,11 +45,28 @@ namespace Stylet
}
/// <summary>
/// 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
/// </summary>
public class ViewManagerConfig
public class ViewManager : IViewManager
{
private List<Assembly> _viewAssemblies = new List<Assembly>();
private static readonly ILogger logger = LogManager.GetLogger(typeof(ViewManager));
private Func<Type, object> _viewFactory; // This is assigned by the ctor
/// <summary>
/// Gets and sets the delegate used to retrieve an instance of a view
/// </summary>
public Func<Type, object> ViewFactory
{
get { return this._viewFactory; }set
{
if (value == null)
throw new ArgumentNullException();
this._viewFactory = value;
}
}
private List<Assembly> _viewAssemblies; // This is assigned by the ctor
/// <summary>
/// Gets and sets the assemblies which are used for IoC container auto-binding and searching for Views.
@ -65,12 +82,6 @@ namespace Stylet
}
}
/// <summary>
/// Gets and sets the delegate used to retrieve an instance of a view
/// </summary>
public Func<Type, object> ViewFactory { get; set; }
private Dictionary<string, string> _namespaceTransformations = new Dictionary<string, string>();
/// <summary>
@ -118,32 +129,22 @@ namespace Stylet
this._viewModelNameSuffix = value;
}
}
}
/// <summary>
/// Default implementation of ViewManager. Responsible for locating, creating, and settings up Views. Also owns the View.Model and View.ActionTarget attached properties
/// </summary>
public class ViewManager : IViewManager
{
private static readonly ILogger logger = LogManager.GetLogger(typeof(ViewManager));
/// <summary>
/// Gets or sets the configuration object provided to this ViewManager
/// </summary>
protected ViewManagerConfig Config { get; set; }
/// <summary>
/// Initialises a new instance of the <see cref="ViewManager"/> class, with the given viewFactory
/// </summary>
/// <param name="config">Configuration to use</param>
public ViewManager(ViewManagerConfig config)
/// <param name="viewFactory">ViewFactory to use</param>
/// <param name="viewAssemblies">Assembles to search for views in</param>
public ViewManager(Func<Type, object> viewFactory, List<Assembly> 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;
}
/// <summary>
@ -216,7 +217,7 @@ namespace Stylet
/// <returns>Type for that view name</returns>
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();
}
/// <summary>
@ -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);

View File

@ -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<Type, object> viewFactory, List<Assembly> 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<Type, object> viewFactory, List<Assembly> 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<Type, object> viewFactory, List<Assembly> 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<Type, object> viewFactory, List<Assembly> 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<Assembly>());
}
[Test]
public void ViewManagerConfigRejectsNullViewAssemblies()
public void ViewManagerRejectsNullViewAssemblies()
{
var config = new ViewManagerConfig();
Assert.Throws<ArgumentNullException>(() => config.ViewAssemblies = null);
Assert.Throws<ArgumentNullException>(() => new ViewManager(type => null, null));
Assert.Throws<ArgumentNullException>(() => this.viewManager.ViewAssemblies = null);
}
[Test]
public void ViewManagerConfigRejectsNullNamespaceTransformations()
public void ViewManagerRejectsNullNamespaceTransformations()
{
var config = new ViewManagerConfig();
Assert.Throws<ArgumentNullException>(() => config.NamespaceTransformations = null);
Assert.Throws<ArgumentNullException>(() => this.viewManager.NamespaceTransformations = null);
}
[Test]
public void ViewManagerConfigRejectsNullViewNameSuffix()
public void ViewManagerRejectsNullViewNameSuffix()
{
var config = new ViewManagerConfig();
Assert.Throws<ArgumentNullException>(() => config.ViewNameSuffix = null);
Assert.Throws<ArgumentNullException>(() => this.viewManager.ViewNameSuffix = null);
}
[Test]
public void ViewManagerConfigRejectsNullViewModelNameSuffix()
public void ViewManagerRejectsNullViewModelNameSuffix()
{
var config = new ViewManagerConfig();
Assert.Throws<ArgumentNullException>(() => config.ViewModelNameSuffix = null);
Assert.Throws<ArgumentNullException>(() => this.viewManager.ViewModelNameSuffix = null);
}
[Test]
public void ViewManagerRejectsNullViewFactory()
{
var config = new ViewManagerConfig();
Assert.Throws<ArgumentNullException>(() => new ViewManager(config));
Assert.Throws<ArgumentNullException>(() => new ViewManager(null, new List<Assembly>()));
Assert.Throws<ArgumentNullException>(() => 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<Assembly>());
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<Assembly>());
viewManager.View = view;
@ -229,13 +225,7 @@ namespace StyletUnitTests
[Test]
public void CreateViewForModelReturnsNullIfViewNotFound()
{
var config = new ViewManagerConfig()
{
ViewAssemblies = new List<Assembly>() { typeof(BootstrapperBase).Assembly, Assembly.GetExecutingAssembly() },
ViewFactory = type => null,
};
var viewManager = new AccessibleViewManager(config);
var viewManager = new AccessibleViewManager(type => null, new List<Assembly>() { 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<Assembly>());
viewManager.ViewType = null;
Assert.Throws<StyletViewLocationException>(() => 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>() { Assembly.GetExecutingAssembly() }
};
var viewManager = new AccessibleViewManager(config);
var viewManager = new AccessibleViewManager(type => null, new List<Assembly>() { 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<Assembly>());
viewManager.LocatedViewType = typeof(I1);
Assert.Throws<StyletViewLocationException>(() => 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<Assembly>());
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<Assembly>());
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<Assembly>());
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<Assembly>());
viewManager.BindViewToModel(view, model);
Assert.AreEqual(model, view.DataContext);
@ -356,7 +329,7 @@ namespace StyletUnitTests
{
var view = new UIElement();
var model = new Mock<IViewAware>();
var viewManager = new AccessibleViewManager(this.viewManagerConfig);
var viewManager = new AccessibleViewManager(type => null, new List<Assembly>());
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"));