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)); }
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); }
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); }
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)); }
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); }
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)); }
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); }