public void AggregateTest() { IAggregatable duck = DuckTyping.Aggregate <IAggregatable>(new AggregateClass1(), new AggregateClass2()); Assert.IsNotNull(duck); Assert.AreEqual(1, duck.Method1()); Assert.AreEqual(2, duck.Method2()); // It is still possible to get access // to an interface of an underlying object. // IClass2 cls2 = DuckTyping.Implement <IClass2>(duck); Assert.IsNotNull(cls2); Assert.AreEqual(2, cls2.Method2()); // Even to switch from one aggregated object to another // IClass1 cls1 = DuckTyping.Implement <IClass1>(cls2); Assert.IsNotNull(cls1); Assert.AreEqual(1, cls1.Method1()); Assert.AreEqual(3, cls1.Method3()); }
public void MissedMethodsAggregateTest() { IClass1 duck = DuckTyping.Aggregate <IClass1>(new Version(1, 0), Guid.NewGuid()); Assert.That(duck, Is.Not.Null); // Neither System.Guid nor System.Version will ever have Method1. // Assert.That(duck.Method1(), Is.EqualTo(0)); }
public void GenericMethodWithConstrait() { MockRepository mocks = new MockRepository(); IClass1 class1 = mocks.StrictMock <IClass1>(); IClass2 class2 = mocks.StrictMock <IClass2>(); class1.Method1 <int>(1); class2.Method2(mocks); }