public void Test_Locate_Base_Save() { StrategyLocator locator = new StrategyLocator(StrategyState.Strategies); StrategyInfo info = locator.Locate("Save", "IEntity"); string expectedType = typeof(SaveStrategy).FullName + ", " + typeof(SaveStrategy).Assembly.GetName().Name; Assert.AreEqual(expectedType, info.StrategyType, "Wrong strategy located."); }
public void Test_Locate() { StrategyLocator locator = new StrategyLocator(StrategyState.Strategies); StrategyInfo info = locator.Locate("Delete", "TestArticle"); string expectedType = typeof(DeleteStrategy).FullName + ", " + typeof(DeleteStrategy).Assembly.GetName().Name; Assert.AreEqual(expectedType, info.StrategyType, "Wrong strategy located."); }
/// <summary> /// Tests the LocateFromInterfaces method where the matching interface is implemented by a base type. /// </summary> public void Test_LocateFromInterfaces_Heirarchy() { Type type = typeof(TestArticle); string action = "Save"; StrategyStateNameValueCollection strategies = new StrategyStateNameValueCollection(); strategies.Add(typeof(SaveStrategy)); // Save-IEntity strategies.Add(typeof(UpdateStrategy)); // Update-IEntity StrategyLocator locator = new StrategyLocator(strategies); StrategyInfo info = locator.LocateFromInterfaces(action, type); Assert.IsNotNull(info, "No strategy info found."); }
public void Test_Locate_CustomOverride() { string type = "Widget"; string action = "Index"; StrategyStateNameValueCollection strategies = new StrategyStateNameValueCollection(); strategies.Add(typeof(IndexStrategy)); strategies.Add(typeof(MockIndexWidgetStrategy)); StrategyLocator locator = new StrategyLocator(strategies); StrategyInfo info = locator.Locate(action, type); Assert.IsNotNull(info, "No strategy info found."); Type mockStrategyType = new MockIndexWidgetStrategy().GetType(); string expected = mockStrategyType.FullName + ", " + mockStrategyType.Assembly.GetName().Name; Assert.AreEqual(expected, info.StrategyType, "Wrong strategy type selected."); }