Example #1
0
        public void TryConvert_NullConverter_ThrowsArgumentNullException()
        {
            var policy = new ScalarConversionPolicy();

            IPropertyToken token;

            Assert.Throws <ArgumentNullException>(() => policy.TryConvert(null, null, out token));
        }
Example #2
0
        public void TryConvert_NullValue_ReturnsFalse()
        {
            var converter = Mock.Of <IPropertyConverter>();
            var policy    = new ScalarConversionPolicy();

            IPropertyToken token;

            Assert.False(policy.TryConvert(converter, null, out token));
        }
Example #3
0
        public void TryConvert_BoolValue_ReturnsScalarToken()
        {
            var converter = Mock.Of <IPropertyConverter>();
            var policy    = new ScalarConversionPolicy();

            IPropertyToken token;

            Assert.True(policy.TryConvert(converter, true, out token));

            var scalar = token as ScalarToken;

            Assert.NotNull(scalar);
            Assert.Equal(scalar.Value, true);
        }
Example #4
0
        public void TryConvert_DecimalValue_ReturnsScalarToken()
        {
            decimal payload   = 10.0M;
            var     converter = Mock.Of <IPropertyConverter>();
            var     policy    = new ScalarConversionPolicy();

            IPropertyToken token;

            Assert.True(policy.TryConvert(converter, payload, out token));

            var scalar = token as ScalarToken;

            Assert.NotNull(scalar);
            Assert.Equal(scalar.Value, payload);
        }
Example #5
0
        public void TryConvert_UriValue_ReturnsScalarToken()
        {
            var payload   = new Uri("http://localhost/");
            var converter = Mock.Of <IPropertyConverter>();
            var policy    = new ScalarConversionPolicy();

            IPropertyToken token;

            Assert.True(policy.TryConvert(converter, payload, out token));

            var scalar = token as ScalarToken;

            Assert.NotNull(scalar);
            Assert.Equal(scalar.Value, payload);
        }
Example #6
0
        public void TryConvert_TimeSpanValue_ReturnsScalarToken()
        {
            var payload   = TimeSpan.FromHours(1);
            var converter = Mock.Of <IPropertyConverter>();
            var policy    = new ScalarConversionPolicy();

            IPropertyToken token;

            Assert.True(policy.TryConvert(converter, payload, out token));

            var scalar = token as ScalarToken;

            Assert.NotNull(scalar);
            Assert.Equal(scalar.Value, payload);
        }
Example #7
0
        public void TryConvert_StringValue_ReturnsScalarToken()
        {
            string payload   = "Hello World!";
            var    converter = Mock.Of <IPropertyConverter>();
            var    policy    = new ScalarConversionPolicy();

            IPropertyToken token;

            Assert.True(policy.TryConvert(converter, payload, out token));

            var scalar = token as ScalarToken;

            Assert.NotNull(scalar);
            Assert.Equal(scalar.Value, payload);
        }