Skip to content

Instantly share code, notes, and snippets.

@ArildF
Created February 2, 2012 21:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ArildF/1725881 to your computer and use it in GitHub Desktop.
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
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