Beispiel #1
0
        public void TryConvert_Scalar_ReturnsFalse()
        {
            var config    = Mock.Of <IConversionConfig>();
            var converter = Mock.Of <IPropertyConverter>();
            var policy    = new StringConversionPolicy(config);

            IPropertyToken token;

            Assert.False(policy.TryConvert(converter, false, out token));
        }
Beispiel #2
0
        public void TryConvert_String_ReturnsScalarToken()
        {
            var    config    = Mock.Of <IConversionConfig>();
            var    converter = Mock.Of <IPropertyConverter>();
            var    policy    = new StringConversionPolicy(config);
            string value     = "Hello World";

            IPropertyToken token;

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

            var scalar = token as ScalarToken;

            Assert.NotNull(scalar);
            Assert.Equal(value, scalar.Value);
        }
Beispiel #3
0
        public void TryConvert_StringLimitSet_ReturnsScalarToken()
        {
            var configMock = new Mock <IConversionConfig>();

            configMock.Setup(m => m.StringLimit).Returns(5);

            var    config    = configMock.Object;
            var    converter = Mock.Of <IPropertyConverter>();
            var    policy    = new StringConversionPolicy(config);
            string value     = "Hello World";

            IPropertyToken token;

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

            var scalar = token as ScalarToken;

            Assert.NotNull(scalar);
            string text = scalar.Value as string;

            Assert.True(text.StartsWith("Hello"));
            Assert.True(text.EndsWith("…"));
        }