コード例 #1
0
        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");
        }
コード例 #2
0
        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");
        }
コード例 #3
0
        public void property_set_to_value_provided()
        {
            //arrange
            UserModel model = new UserModel()
            {
                Id = 111, Name = "John"
            };

            Configurator.Substitute <UserModel, int>(x => x.Id);

            Substitutable subs = Configurator.SubstitutesFor(typeof(UserModel)).First();

            //act
            ReflectionHelper.SetValue <UserModel>(model, subs, 10);

            //assert
            Assert.AreEqual(10, model.Id);
        }
コード例 #4
0
        public void property_value_received_by_substitutable()
        {
            //arrange
            UserModel model = new UserModel()
            {
                Id = 111, Name = "John"
            };

            Configurator.Substitute <UserModel, int>(x => x.Id);

            Substitutable subs = Configurator.SubstitutesFor(typeof(UserModel)).First();

            //act
            int res = ReflectionHelper.GetValue <UserModel>(model, subs);

            //assert
            Assert.AreEqual(111, res);
            //Assert.AreNotEqual(1, model.Id);
        }
コード例 #5
0
        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.");
        }
コード例 #6
0
        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.");
        }
コード例 #7
0
        public static void SetValue <T>(this T obj, Substitutable property, int setValue)
        {
            var prop = obj.GetType().GetProperty(property.PropertyName);

            prop.SetValue(obj, setValue, null);
        }
コード例 #8
0
        public static int GetValue <T>(this T obj, Substitutable property)
        {
            var prop = obj.GetType().GetProperty(property.PropertyName);

            return((int)prop.GetValue(obj, null));
        }
コード例 #9
0
 private static ISubstitutionStrategy GetStrategyFor(Substitutable item)
 {
     return(_strategy);
 }