private IIndexStrategy CreateResolver(object source) { IIndexStrategy resolver = null; var numericIndex = 0; if (int.TryParse(_index, out numericIndex)) { var dict = source as IDictionary; var list = source as IList; if (dict != null) { resolver = new NumericDictStrategy(numericIndex); } else if (list != null) { resolver = new ListStrategy(numericIndex); } } // Numeric failed, try text if (resolver == null) { if (source is IDictionary) { resolver = new TextDictStrategy(_index); } else { resolver = new NullStrategy(); } } return(resolver); }
public QueryCategory( QueryFlags flags, ITypeSymbol?itemType, NullableAnnotation itemNullability, ListStrategy listStrategy, ITypeSymbol listType) { Flags = flags; ItemType = itemType; ItemNullability = itemNullability; ListStrategy = listStrategy; ListType = listType; }
public void TestListOfNumbersWithVariableItems() { var strategy = new DataCreationStrategy <Person>(); var intstrategy = new IntegerStrategy(); intstrategy.Value(42); var liststrategy = new ListStrategy <int>(intstrategy); strategy.Add(p => p.Changes, liststrategy).Min(10).Max(20); var items = Common.CreateItems(100, strategy).ToList(); Assert.IsTrue(items.Select(p => p.Changes.Count).Distinct().ToList().Count == 10); Assert.IsTrue(items.All(p => p.Changes.All(c => c == 42))); }
public void TestListOfNumbers() { var strategy = new DataCreationStrategy <Person>(); var intstrategy = new IntegerStrategy(); intstrategy.Value(42); var liststrategy = new ListStrategy <int>(intstrategy); strategy.Add(p => p.Changes, liststrategy).Amount(249); var items = Common.CreateItems(10, strategy).ToList(); Assert.IsTrue(items.All(p => p.Changes.Count == 249)); Assert.IsTrue(items.All(p => p.Changes.All(c => c == 42))); }
public void Cloner_Strategy_List() { //Arange var strategy = new ListStrategy(); //Act var result1 = strategy.IsMatch(typeof(List <Class1>)); var result2 = strategy.IsMatch(typeof(HashSet <Class1>)); //Assert Assert.IsTrue(result1, "ListStrategy should be able to make cloner for type List<Class1>"); Assert.IsTrue(result2, "ListStrategy should be able to make cloner for type HashSet<Class1>"); }