예제 #1
0
        public void Not_Wrapped_If_Exception_Not_Registered()
        {
            Person person = new Person();
            Food   food   = new Food {
                FoodCalories = 100
            };

            IFood   foodTarget   = food.As <IFood>();
            IPerson personTarget = person.As <IPerson>(GooseTypePair.Create <Food, IFood>());

            Assert.Throws <FoodExpiredException>(() => personTarget.Eat(foodTarget));
        }
예제 #2
0
        public void Different_Number_Of_Parameter_Overload_Test()
        {
            Person person = new Person();
            Food   food   = new Food {
                FoodCalories = 100
            };

            IFood   foodTarget   = food.As <IFood>();
            IPerson personTarget = person.As <IPerson>(
                GooseTypePair.Create <Food, IFood>(),
                GooseTypePair.Create <Remain, IRemain>());

            personTarget.Eat(foodTarget, 90);
        }
예제 #3
0
        public void Same_Number_of_Parameter_Overload_Test()
        {
            Person person = new Person();
            Food   food   = new Food {
                FoodCalories = 100
            };

            IFood   foodTarget   = food.As <IFood>();
            IPerson personTarget = person.As <IPerson>(
                GooseTypePair.Create <Fruit, IFruit>(),
                GooseTypePair.Create <Food, IFood>(),
                GooseTypePair.Create <Remain, IRemain>());

            personTarget.EatOne(foodTarget);
        }
예제 #4
0
        public void Ambiguous_If_Multiple_Register()
        {
            Person person = new Person();
            Food   food   = new Food {
                FoodCalories = 100
            };

            IFood   foodTarget   = food.As <IFood>();
            IPerson personTarget = person.As <IPerson>(
                GooseTypePair.Create <Food, IFood>(),
                GooseTypePair.Create <Fruit, IFood>(),
                GooseTypePair.Create <Remain, IRemain>());

            Assert.Throws <GooseAmbiguousMatchException>(() => personTarget.EatOne(foodTarget));
        }
예제 #5
0
        public void Interchangable_If_Registered()
        {
            Person person = new Person();
            Food   food   = new Food {
                FoodCalories = 100
            };

            IFood   foodTarget   = food.As <IFood>();
            IPerson personTarget = person.As <IPerson>(
                GooseTypePair.Create <Food, IFood>(),
                GooseTypePair.Create <Remain, IRemain>());

            IRemain remain = personTarget.Eat(foodTarget, 90, out var enough);

            Assert.Equal(food.FoodCalories, person.CaloriesTaken + remain.RemainCalories);
        }
예제 #6
0
        public void Not_Implemented_If_Not_Registered()
        {
            Person person = new Person();
            Food   food   = new Food {
                FoodCalories = 100
            };

            IFood   foodTarget   = food.As <IFood>();
            IPerson personTarget = person.As <IPerson>();

            Assert.Throws <GooseNotImplementedException>(() => personTarget.Eat(foodTarget, 90, out var enough));

            // <Remain, IRemain> is not registered
            IPerson personTarget2 = person.As <IPerson>(GooseTypePair.Create <Food, IFood>());

            Assert.Throws <GooseNotImplementedException>(() => personTarget.Eat(foodTarget, 90, out var enough));
        }
예제 #7
0
        public void Interchangable_If_Exception_Registered()
        {
            Person person = new Person();
            Food   food   = new Food {
                FoodCalories = 100
            };

            IFood   foodTarget   = food.As <IFood>();
            IPerson personTarget = person.As <IPerson>(
                GooseTypePair.Create <Food, IFood>(),
                GooseTypePair.Create <FoodExpiredException, IFoodExpiredException>());

            var ex = Assert.Throws <WrappedException <IFoodExpiredException> >(() => personTarget.Eat(foodTarget));

            Assert.NotNull(ex.Exception);
            Assert.Same(food, ex.Exception.ExpiredFood.GetSource <Food>());
            Assert.Same(food, ex.Exception.GetSource <FoodExpiredException>().ExpiredFood);
        }