diff --git a/csharpcore/GildedRoseTests/GildedRoseTest.cs b/csharpcore/GildedRoseTests/GildedRoseTest.cs index ec5c2262..82a9d8c9 100644 --- a/csharpcore/GildedRoseTests/GildedRoseTest.cs +++ b/csharpcore/GildedRoseTests/GildedRoseTest.cs @@ -1,5 +1,8 @@ -using Xunit; +using System; +using Xunit; using System.Collections.Generic; +using System.Reflection; +using GildedRose.Models; using GildedRoseKata; namespace GildedRoseTests @@ -9,10 +12,38 @@ namespace GildedRoseTests [Fact] public void foo() { - IList Items = new List { new Item { Name = "foo", SellIn = 0, Quality = 0 } }; - GildedRoseKata.GildedRose app = new GildedRoseKata.GildedRose(Items); - app.UpdateQuality(); - Assert.Equal("fixme", Items[0].Name); + IList items = new List { new AgedBrie() { Name = "fixme", SellIn = 0, Quality = 0 } }; + + GildedRoseKata.GildedRose app = new GildedRoseKata.GildedRose(items); + + foreach (Item t in items) + { + Type type = t.GetType(); + var instance = Activator.CreateInstance(type); + + // Get a property on the type that is stored in the + // property string + PropertyInfo propSellDaysGone = type.GetProperty("SellDaysGone"); + PropertyInfo propSellIn = type.GetProperty("SellIn"); + PropertyInfo propQuality = type.GetProperty("Quality"); + PropertyInfo propName = type.GetProperty("Name"); + + // Set the value of the given property on the given instance + propSellDaysGone.SetValue(instance, 10, null); + propSellIn.SetValue(instance, t.SellIn, null); + propQuality.SetValue(instance, t.Quality, null); + propName.SetValue(instance, t.Name, null); + + // Fetch the methods + MethodInfo updateQualityMethod = type.GetMethod("UpdateQuality"); + MethodInfo updateSellinMethod = type.GetMethod("UpdateSellIn"); + + // Invoke the respective implementation of the methods + updateQualityMethod.Invoke(instance, new object[0]); + updateSellinMethod.Invoke(instance, new object[0]); + + Assert.Equal("fixme", t.Name); + } } } }