Created
February 2, 2012 21:28
-
-
Save ArildF/1725881 to your computer and use it in GitHub Desktop.
Test for automatic creation of a datatemplate matching a view to a viewmodel
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.Windows; | |
using System.Windows.Controls; | |
using System.Windows.Media; | |
using Castle.MicroKernel.Registration; | |
using Castle.Windsor; | |
using Core.Tests.Infrastructure.ViewModels; | |
using Core.Tests.Infrastructure.Views; | |
using NUnit.Framework; | |
using Rogue.Core.UI.Infrastructure; | |
namespace Core.Tests.Infrastructure | |
{ | |
[TestFixture] | |
public class ViewModelRegistrationFacilityTest | |
{ | |
[Test] | |
[RequiresSTA] | |
public void View_will_automatically_bind_to_corresponding_viewmodel() | |
{ | |
var app = new Application(); | |
var container = new WindsorContainer(); | |
container.AddFacility(new ViewModelRegistrationFacility(Application.Current)); | |
container.Register(Component.For<SquareViewModel>().ImplementedBy<SquareViewModel>()); | |
var window = new Window(); | |
app.MainWindow = window; | |
var contentPresenter = new ContentPresenter(); | |
window.Content = contentPresenter; | |
contentPresenter.Content = new SquareViewModel(); | |
window.Show(); | |
try | |
{ | |
var child = VisualTreeHelper.GetChild(contentPresenter, 0); | |
Assert.That(child, Is.InstanceOf<SquareView>()); | |
} | |
finally | |
{ | |
window.Close(); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment