public void find_return_one_element_array_after_first_add() { //arrange Substitutable item = new Substitutable() { TypeName = "UserClass", TypeGuid = "111", PropertyName = "Id" }; SubstitutablesRegistry.Instance.Add(item); //act var res = SubstitutablesRegistry.Instance.Find("111"); //assert Assert.AreEqual(1, res.Count, "Should be only 1 item"); }
public void find_return_null_if_no_elements_for_the_key() { //arrange Substitutable item = new Substitutable() { TypeName = "UserClass", TypeGuid = "111", PropertyName = "Id" }; SubstitutablesRegistry.Instance.Add(item); //act var res = SubstitutablesRegistry.Instance.Find("222"); //assert Assert.IsNull(res, "Should be null for 222"); }
public void Add(Substitutable item) { var items = Find(item.TypeGuid); if (items != null) items.Add(item); else { var newItems = new List<Substitutable>(); newItems.Add(item); _items.Add(item.TypeGuid, newItems); } }
public void if_substitutable_is_added_to_registry_it_can_be_received_by_type_guid() { //arrange Substitutable item = new Substitutable(){TypeName="UserClass", TypeGuid="111", PropertyName="Id"}; SubstitutablesRegistry.Instance.Add(item); //act var registryItem = SubstitutablesRegistry.Instance.Find("111").First(); //assert Assert.IsNotNull(registryItem); Assert.AreEqual("UserClass", registryItem.TypeName, "TypeName doesn`t match."); Assert.AreEqual("111", registryItem.TypeGuid, "TypeGuid doesn`t match."); Assert.AreEqual("Id", registryItem.PropertyName, "PropertyName doesn`t match."); }
public void all_added_substitutables_are_loaded_by_type_guid() { //arrange Substitutable item1 = new Substitutable() { TypeName = "UserClass", TypeGuid = "111", PropertyName = "Id" }; Substitutable item2 = new Substitutable() { TypeName = "UserClass", TypeGuid = "111", PropertyName = "Name" }; SubstitutablesRegistry.Instance.Add(item1); SubstitutablesRegistry.Instance.Add(item2); //act var res = SubstitutablesRegistry.Instance.Find("111"); //assert Assert.IsInstanceOfType(res, typeof(List<Substitutable>), "Should return list of substitutables"); Assert.AreEqual("Id", res[0].PropertyName, "First property name is Id."); Assert.AreEqual("Name", res[1].PropertyName, "Second property name is Name."); }
public void Add(Substitutable item) { var items = Find(item.TypeGuid); if (items != null) { items.Add(item); } else { var newItems = new List <Substitutable>(); newItems.Add(item); _items.Add(item.TypeGuid, newItems); } }
public static void Substitute <T, V>(this Expression <Func <T, V> > expression) { var memberExpression = expression.Body as MemberExpression; if (memberExpression == null) { throw new InvalidOperationException("Expression must be a member expression"); } Type classType = memberExpression.Expression.Type; var item = new Substitutable() { PropertyName = memberExpression.Member.Name, TypeGuid = classType.GUID.ToString(), TypeName = classType.Name }; SubstitutablesRegistry.Instance.Add(item); //TODO: add provided expression data to substitutables registry. //memberExpression.Expression.Type.Name; }