public void ByteArrayStringConversionStrategyTest() { var strategy = new ByteArrayStringConversionStrategy(); object newValue; Assert.IsTrue(strategy.TryConvert("hello", typeof(byte[]), out newValue)); var bytes = newValue as byte[]; Assert.IsNotNull(bytes); Assert.AreEqual(5, bytes.Length); Assert.IsTrue(strategy.TryConvert(bytes, typeof(string), out newValue)); Assert.AreEqual("hello", newValue); }
public void ByteArrayStringConversionStrategyTest() { var strategy = new ByteArrayStringConversionStrategy(); Assert.IsFalse(strategy.CanConvert(typeof(int), typeof(int))); Assert.IsTrue(strategy.CanConvert(typeof(byte[]), typeof(string))); Assert.IsTrue(strategy.CanConvert(typeof(string), typeof(byte[]))); var bytes = strategy.Convert(typeof(string), typeof(byte[]), "hello", Thread.CurrentThread.CurrentCulture) as byte[]; Assert.IsNotNull(bytes); Assert.AreEqual(5, bytes.Length); var str = strategy.Convert(typeof(byte[]), typeof(string), bytes, Thread.CurrentThread.CurrentCulture); Assert.AreEqual("hello", str); }