You cannot get at the state of an event; by design you can only register to it += or unregister -= from it. Because of this, there is no extension or other mechanism that NUnit provides to test the event has been subscribed to.
If the event is on an interface, you can test subscription via a mock class (either your own or a framework's mock, like Rhino).
You can of course test the behavior of the event, in any event!
If you post some code I'm sure someone will help you come up with a meaningful test. Here's a sample dummy one to give you some ideas:
[Test]
public void ChangingTheWhateverProperty_TriggersPropertyChange()
{
// Create anonymous delegate which is also your test assertion
PropertyChangedEventHandler anonymousDelegate = (sender, e) => Assert.AreEqual("Whatever", e.PropertyName);
// Subscribe to the needed event
vm.PropertyChanged += anonymousDelegate;
// trigger the event
vm.Whatever = "blah";
}
HTH,
Berryl
=== modified example with your code =======
[Test]
public void AddingToCollectionShouldHookPropertyChangedEventUp()
{
// Arrange:
var viewModel = new viewModel();
var viewModelCollection = new viewModelCollection();
// This *IS* your assert also, and will get called back when you Act
// The only part you need to supply for this test is the property that gets fired when you add a viewmodel
PropertyChangedEventHandler anonymousDelegate = (sender, e) => Assert.AreEqual("Whatever", e.PropertyName);
// Subscribe to the needed event
viewModelCollection.PropertyChanged += anonymousDelegate;
// Act:
viewModelCollection.AddViewModel(viewModel);
}
=== example rhino test for event registration =====
[Test]
public void Test()
{
var mockCorpseKicker = MockRepository.GenerateMock<INotifyPropertyChanged>();
mockCorpseKicker.PropertyChanged += null;
mockCorpseKicker.AssertWasCalled(x => x.PropertyChanged += Arg<PropertyChangedEventHandler>.Is.Anything);
}