示例#1
0
        public async void Polymorphism_For_Override_Method()
        {
            Duck  duck   = new ExecitedDuck();
            IDuck target = duck.As <IDuck>();

            Assert.Equal(await duck.WalkAsync(), await target.WalkAsync());
            Assert.Same(duck, target.GetSource <Duck>());
            Assert.Same(duck, target.GetSource <ExecitedDuck>());
        }
示例#2
0
        public void Should_Use_Original_Object()
        {
            Duck  source = new Duck();
            IDuck target = source.As <IDuck>();

            Assert.Same(source, target);
            Assert.Same(source, target.GetSource <Duck>());
            Assert.Throws <ArgumentException>(() => target.GetSource <ExecitedDuck>());
        }
示例#3
0
        public void Hide_Base_Using_New()
        {
            ExecitedDuck source = new ExecitedDuck();
            IDuck        target = source.As <IDuck>();

            Assert.Equal(source.Quack(), target.Quack());
            Assert.Same(source, target.GetSource <Duck>());
            Assert.Same(source, target.GetSource <ExecitedDuck>());
        }
示例#4
0
        public void Primitive_Type_As_Unrelated_Interface()
        {
            int   source = 1;
            IDuck target = source.As <IDuck>();

            Assert.NotNull(target);
            Assert.Equal(source, target.GetSource <int>());
            Assert.Throws <InvalidCastException>(() => target.GetSource <long>());
        }
示例#5
0
        public async Task Override_Virtual_Method()
        {
            ExecitedDuck source = new ExecitedDuck();
            IDuck        target = source.As <IDuck>();

            Assert.Equal(await source.WalkAsync(), await target.WalkAsync());
            Assert.Same(source, target.GetSource <ExecitedDuck>());
        }
示例#6
0
        public void Null_Can_Be_Goosed()
        {
            Duck  source = null;
            IDuck target = source.As <IDuck>();

            Assert.NotNull(target);
            Assert.Null(target.GetSource <Duck>());
        }
示例#7
0
 public void Get_Source_Reference_Check()
 {
     Assert.Same(_source, _target.GetSource <Duck>());
 }