Пример #1
0
        public void TryConvert_ByteArrayLimitSet_ReturnsScalarToken()
        {
            var configMock = new Mock <IConversionConfig>();

            configMock.Setup(m => m.ByteArrayLimit).Returns(1024);

            var config    = configMock.Object;
            var converter = Mock.Of <IPropertyConverter>();
            var policy    = new ByteArrayConversionPolicy(config);
            var bytes     = Enumerable.Range(0, 1025).Select(b => (byte)b).ToArray();

            IPropertyToken token;

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

            var scalar = token as ScalarToken;

            Assert.NotNull(scalar);

            string value = scalar.Value as string;

            Assert.NotNull(value);
            Assert.True(value.StartsWith("0x:"));
            Assert.True(value.EndsWith("(1025 bytes)"));
        }
Пример #2
0
        public void TryConvert_NullConverter_ThrowsArgumentNullException()
        {
            var config = Mock.Of <IConversionConfig>();
            var policy = new ByteArrayConversionPolicy(config);

            IPropertyToken token;

            Assert.Throws <ArgumentNullException>(() => policy.TryConvert(null, null, out token));
        }
Пример #3
0
        public void TryConvert_NullValue_ReturnsFalse()
        {
            var config    = Mock.Of <IConversionConfig>();
            var converter = Mock.Of <IPropertyConverter>();
            var policy    = new ByteArrayConversionPolicy(config);

            IPropertyToken token;

            Assert.False(policy.TryConvert(converter, null, out token));
        }
Пример #4
0
        public void TryConvert_ByteArray_ReturnsScalarToken()
        {
            var config    = Mock.Of <IConversionConfig>();
            var converter = Mock.Of <IPropertyConverter>();
            var policy    = new ByteArrayConversionPolicy(config);
            var bytes     = new byte[] { 1, 2, 3 };

            IPropertyToken token;

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

            var scalar = token as ScalarToken;

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