public void NonWideningFails() { var handledMessages = new List<IMessage> (); FakeConsumer<TestMessages.ADerivedTestMessage> consumer = new FakeConsumer<TestMessages.ADerivedTestMessage> (msg => handledMessages.Add (msg)); IMessage message = new TestMessages.ADerivedTestMessage (); //comment this line back in to see that the code will not compile //consumer.Handle (message); Assert.AreEqual (1, handledMessages.Count); }
public void CanHandleContravariantMessages() { var handledMessages = new List<IMessage> (); IConsume<IMessage> consumer = new FakeConsumer<IMessage> (msg => handledMessages.Add (msg)); var wideningConsumer = new WideningConsumer<TestMessages.ADerivedTestMessage, IMessage>(consumer); var message = new TestMessages.ADerivedTestMessage (); wideningConsumer.Handle (message); Assert.AreEqual (1, handledMessages.Count); Assert.IsInstanceOf<TestMessages.ADerivedTestMessage>(handledMessages[0]); }