I am using NUnit in combination with NSubstitute to test an application. The application uses the Caliburn.Micro MVVM framework. Consider the following example code that I would like to create a test for. It utilizes Caliburn Micro's event aggregator class to publish a message. I would like to verify that the event published in this code actually contains the integer list that I expect (as indicated by the comment in the test code below).
public class ExampleEvent
{
List<int> SampleValues { get; set; }
}
public class ExampleClass
{
private IEventAggregator _eventAggregator;
public ExampleClass(IEventAggregator eventAggregator)
{
_eventAggregator = eventAggregator
}
public void ExampleMethod()
{
var exampleArray = new List<int>{ 1, 2, 3, 4, 5, 6, 7, 8, 9 };
_eventAggregator.PublishOnUIThread(new ExampleEvent { SampleValues = exampleArray });
}
}
A test for the code above might look like the following...
[TestFixture]
public class ExampleClassTests()
{
private ExampleClass _uut;
private IEventAggregator _eventAggregator;
[SetUp]
public void SetUp()
{
_eventAggregator = Substitute.For<IEventAggregator>();
_uut = new ExampleClass(_eventAggregator);
}
[Test]
public void ExampleMethod_ShouldRaiseEvent()
{
_uut.ExampleMethod();
// I would like to add something like the line below but errors are thrown when it is executed...
_eventAggregator.Received().PublishOnUIThread(Arg.Is<ExampleEvent>(x => x.SampleValues.Equals( new List<int>{ 1, 2, 3, 4, 5, 6, 7, 8, 9 } )))
}
}
How would one properly accomplish this?