コード例 #1
0
        public void Set_SetValueToGenericNotNullable_ValueIsNotSet()
        {
            var dummy = new DummyWithAllProperties();

            var propertyInfo = typeof(DummyWithAllProperties).GetProperty("Strings", BindingFlags.Public | BindingFlags.Instance);

            var sut = new Impl.ValueSetter();

            sut.Set(propertyInfo, null, dummy).ShouldBe(false);
        }
コード例 #2
0
        public void Set_SetValueDateTime_ValueIsSet()
        {
            var dummy = new DummyWithAllProperties();

            var propertyInfo = typeof(DummyWithAllProperties).GetProperty("DateTime", BindingFlags.Public | BindingFlags.Instance);

            var sut = new Impl.ValueSetter();

            sut.Set(propertyInfo, "2017-04-02", dummy).ShouldBeTrue();

            propertyInfo.GetValue(dummy).ShouldBe(new DateTime(2017, 04, 02));
        }
コード例 #3
0
        public void Set_SetValue_ValueIsSet(string property, string value, bool isConverted, object expectedValue)
        {
            var dummy = new DummyWithAllProperties();

            var propertyInfo = typeof(DummyWithAllProperties).GetProperty(property, BindingFlags.Public | BindingFlags.Instance);

            var sut = new Impl.ValueSetter();

            sut.Set(propertyInfo, value, dummy).ShouldBe(isConverted);

            if (isConverted)
            {
                propertyInfo.GetValue(dummy).ShouldBe(expectedValue);
            }
        }
コード例 #4
0
        public void Set_SetValueTNullableoDateTime_ValueIsSet()
        {
            var dummy = new DummyWithAllProperties();

            var propertyInfo = typeof(DummyWithAllProperties).GetProperty("NullableDateTime", BindingFlags.Public | BindingFlags.Instance);

            var sut = new Impl.ValueSetter();

            sut.Set(propertyInfo, "2017-12-11", dummy).ShouldBe(true);

            DateTime?dateTime = null;

            dateTime = new DateTime(2017, 12, 11);

            propertyInfo.GetValue(dummy).ShouldBe(dateTime);
        }