Ejemplo n.º 1
0
 /// <summary>
 /// Prepares the value to be converted to a format appropriate for sql
 /// </summary>
 /// <param name="objValue">The value to prepare</param>
 /// <returns>Returns the reformatted object</returns>
 public virtual object PrepareValue(object objValue)
 {
     if (objValue is Guid)
     {
         if (Guid.Empty.Equals(objValue))
         {
             return(DBNull.Value);
         }
         return(((Guid)objValue).ToString("B").ToUpper(CultureInfo.InvariantCulture));
     }
     if (objValue is bool)
     {
         return((bool)objValue ? 1 : 0);
     }
     if (objValue is Image)
     {
         return(SerialisationUtilities.ObjectToByteArray(objValue));
     }
     if (objValue is CustomProperty)
     {
         return(((CustomProperty)objValue).GetPersistValue());
     }
     if (objValue is TimeSpan)
     {
         TimeSpan time = (TimeSpan)objValue;
         return(TimeSpanDataMapper.BaseDate.Add(time));
     }
     return(objValue);
 }
Ejemplo n.º 2
0
        public void TestTwoWayConversion()
        {
            Image image = (Image)_resourceManager.GetObject("TestJpeg");

            byte[] bytesOut  = SerialisationUtilities.ObjectToByteArray(image);
            Object objectOut = SerialisationUtilities.ByteArrayToObject(bytesOut);

            Assert.AreEqual(image.GetType(), objectOut.GetType());
        }
Ejemplo n.º 3
0
        public void TryParsePropValue_ConvertsByteArrayToImage()
        {
            //---------------Set up test pack-------------------
            var    dataMapper   = new ImageDataMapper();
            var    img          = new System.Drawing.Bitmap(100, 100);
            var    valueToParse = SerialisationUtilities.ObjectToByteArray(img);
            object parsedValue;
            //---------------Execute Test ----------------------
            var parseSucceed = dataMapper.TryParsePropValue(valueToParse, out parsedValue);

            //---------------Test Result -----------------------
            Assert.IsTrue(parseSucceed);
            Assert.IsInstanceOf(typeof(System.Drawing.Bitmap), parsedValue);
            Assert.AreEqual(img.Width, ((System.Drawing.Bitmap)parsedValue).Width);
            Assert.AreEqual(img.Height, ((System.Drawing.Bitmap)parsedValue).Height);
        }