Stitch EventAggregator into bootstrapper

This commit is contained in:
Antony Male 2014-02-25 13:21:26 +00:00
parent 5f655188c5
commit 6ee8927137
2 changed files with 35 additions and 0 deletions

View File

@ -25,7 +25,9 @@ namespace Stylet
protected virtual void ConfigureIoC(IStyletIoCBuilder builder)
{
builder.Autobind(AssemblySource.Assemblies);
builder.Bind<IWindowManager>().To<WindowManager>().InSingletonScope();
builder.Bind<IEventAggregator>().To<EventAggregator>().InSingletonScope();
builder.Bind<IViewManager>().To<ViewManager>().InSingletonScope();
}

View File

@ -28,6 +28,11 @@ namespace StyletUnitTests
public void Handle(M1 message) { this.ReceivedM1 = message; }
}
public class C3 : IHandle<M1>
{
public void Handle(M1 message) { throw new Exception("Should not be called. Ever"); }
}
[Test]
public void SubscribesAndDeliversExactMessage()
{
@ -54,5 +59,33 @@ namespace StyletUnitTests
Assert.AreEqual(message, target.ReceivedM1);
Assert.AreEqual(message, target.ReceivedM2);
}
[Test]
public void UnsubscribeUnsubscribes()
{
var ea = new EventAggregator();
var target = new C1();
ea.Subscribe(target);
ea.Unsubscribe(target);
var message = new M1();
ea.Publish(message);
Assert.IsNull(target.ReceivedMessage);
}
[Test]
public void TargetReferenceIsWeak()
{
var ea = new EventAggregator();
var target = new C3();
ea.Subscribe(target);
// Ugly, but it's the only way to test a WeakReference...
target = null;
GC.Collect();
Assert.DoesNotThrow(() => ea.Publish(new M1()));
}
}
}