Ejemplo n.º 1
0
        public void ConvertStringToObjectAllTypes()
        {
            // testing all major types

            EntityUtils target = new EntityUtils();

            bool     MFieldbool     = false;
            short    MFieldint16    = 10;
            int      MFieldint32    = 10;
            long     MFieldint64    = 10;
            double   MFielddouble   = 100.111;
            float    MFieldfloat    = 100.111f;
            DateTime MFielddatetime = new DateTime(2013, 1, 1);
            decimal  MFielddecimal  = 8438938383832;
            string   MFieldstring   = "Some string for test";

            object[] testValues =
            {
                MFieldbool,
                MFieldint16,
                MFieldint32,
                MFieldint64,
                MFielddouble,
                MFieldfloat,
                MFielddatetime,
                MFielddecimal,
                MFieldstring,
            };
            for (int i = 0; i < testValues.Length; i++)
            {
                object result = target.ConvertStringToObject(testValues[i].ToString(), testValues[i].GetType());
                Assert.AreEqual(testValues[i], result);
            }
        }
Ejemplo n.º 2
0
        public void ConvertStringToObjectEnumByValue()
        {
            EntityUtils       target = new EntityUtils();
            GetSourceTypeEnum testE  = GetSourceTypeEnum.View;
            object            result = target.ConvertStringToObject(((int)testE).ToString(), testE.GetType());

            Assert.AreEqual(testE, result);
        }
Ejemplo n.º 3
0
        public void ConvertStringToObjectGuid()
        {
            EntityUtils target = new EntityUtils();

            Guid   fieldGuid = Guid.NewGuid();
            object result    = target.ConvertStringToObject(fieldGuid.ToString(), fieldGuid.GetType());

            Assert.AreEqual(fieldGuid, result);
        }
Ejemplo n.º 4
0
        public void ConvertStringToObjectComplexFormat()
        {
            // testing a byte[] for all values from 0 to 255

            string value = "{\"Field1\":\"f1Value\",\"Field2\":\"0cf8f670-c742-4f12-ba0b-98d8f3b9077a\",\"Field3\":\"2013-01-01T00:00:00\"}";


            EntityUtils target = new EntityUtils();
            object      o      = target.ConvertStringToObject(value, typeof(ComplexStructure));

            Assert.IsTrue(o.GetType() == typeof(ComplexStructure));
            ComplexStructure cs = (ComplexStructure)o;

            Assert.AreEqual("f1Value", cs.Field1);
            Assert.AreEqual(new Guid("0cf8f670-c742-4f12-ba0b-98d8f3b9077a"), cs.Field2);
            Assert.AreEqual(new DateTime(2013, 1, 1), cs.Field3);
        }
Ejemplo n.º 5
0
        public void ConvertStringToObjectByteArray()
        {
            // testing a byte[] for all values from 0 to 255

            byte[] MFieldbytearray50 = new byte[255];
            for (byte i = 0; i < 255; i++)
            {
                MFieldbytearray50[i] = i;
            }

            EntityUtils target     = new EntityUtils();
            string      objectJson = target.JsonSerializeObject(MFieldbytearray50);

            object o = target.ConvertStringToObject(objectJson, MFieldbytearray50.GetType());

            Assert.IsTrue(o.GetType() == typeof(byte[]));

            for (int i = 0; i < MFieldbytearray50.Length; i++)
            {
                Assert.AreEqual(MFieldbytearray50[i], ((byte[])o)[i]);
            }
        }