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."); }
public void Test_LocateFromInterfaces_Immediate() { Type type = typeof(IEntity); string action = "Save"; StrategyStateNameValueCollection strategies = new StrategyStateNameValueCollection(); strategies.Add(typeof(SaveStrategy)); strategies.Add(typeof(UpdateStrategy)); StrategyLocator locator = new StrategyLocator(strategies); StrategyInfo info = locator.LocateFromInterfaces(action,type); Assert.IsNotNull(info, "No strategy info found."); }
public StrategyInfo GetStrategy(string action, string typeName, bool throwErrorIfNotFound) { StrategyInfo foundStrategy = null; using (LogGroup logGroup = LogGroup.StartDebug("Retrieving the strategy for performing the action '" + action + "' with the type '" + typeName + "'.")) { StrategyLocator locator = new StrategyLocator(this); foundStrategy = locator.Locate(action, typeName); if (foundStrategy == null && throwErrorIfNotFound) { throw new StrategyNotFoundException(action, typeName); } } return(foundStrategy); }
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."); }