Ejemplo n.º 1
0
        public void AggregateTest()
        {
            var 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.
            //
            var cls2 = DuckTyping.Implement <IClass2>(duck);

            Assert.IsNotNull(cls2);
            Assert.AreEqual(2, cls2.Method2());

            // Even to switch from one aggregated object to another
            //
            var cls1 = DuckTyping.Implement <IClass1>(cls2);

            Assert.IsNotNull(cls1);
            Assert.AreEqual(1, cls1.Method1());
            Assert.AreEqual(3, cls1.Method3());
        }
Ejemplo n.º 2
0
 public void BuildTimeAggregateExceptionTest()
 {
     Assert.Throws <TypeBuilderException>(() =>
     {
         // Exception here.
         //
         _ = DuckTyping.Aggregate <IOptionalInterface>(string.Empty, Guid.Empty);
     });
 }
Ejemplo n.º 3
0
        public void MissedMethodsAggregateTest()
        {
            var 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));
        }
Ejemplo n.º 4
0
        public void RuntimeAggregateExceptionTest()
        {
            var duck = DuckTyping.Aggregate <IOptionalInterface>(new TestClass(), new EmptyClass());

            Assert.AreEqual(1, duck.RequiredMethod());

            // Exception here.
            //
            duck.OptionalMethod();
        }
Ejemplo n.º 5
0
        public void Test()
        {
            var duck = DuckTyping.Implement <IOptionalInterfaceNoException> (new TestClass());

            Assert.AreEqual(1, duck.RequiredMethod());
            Assert.AreEqual(0, duck.OtherOptionalMethod());
            Assert.AreEqual(2, duck.SameMethodName());

            duck = DuckTyping.Aggregate <IOptionalInterfaceNoException>(new TestClass(), string.Empty, Guid.Empty);

            Assert.AreEqual(1, duck.RequiredMethod());
            Assert.AreEqual(0, duck.OtherOptionalMethod());
            Assert.AreEqual(2, duck.SameMethodName());
        }
Ejemplo n.º 6
0
        public void AsLikeBehaviourTest()
        {
            var duck = DuckTyping.Implement <IOtherOptionalInterface>(new TestClass());

            Assert.IsNotNull(duck);

            duck = DuckTyping.Implement <IOtherOptionalInterface>(new EmptyClass());
            Assert.IsNull(duck);

            duck = DuckTyping.Implement <IOtherOptionalInterface>(new EmptyClass());
            Assert.IsNull(duck);

            duck = DuckTyping.Aggregate <IOtherOptionalInterface>(new EmptyClass(), string.Empty);
            Assert.IsNull(duck);
        }
Ejemplo n.º 7
0
 public void BuildtimeAggregateExceptionTest()
 {
     // Exception here.
     //
     var duck1 = DuckTyping.Aggregate <IOptionalInterface>(string.Empty, Guid.Empty);
 }