public MFTestResults DateTime_ConstructorTest1()
        {
            /// <summary>
            ///  1. Creates a DateTime
            ///  2. Verifies that the created object is a DateTime
            /// </summary>

            MFTestResults testResult = MFTestResults.Pass;
            try
            {
                Log.Comment("Creating new DateTime Object");
                DateTime dt = new DateTime();
                Log.Comment(dt.ToString());
                Type type = dt.GetType();
                Log.Comment("Verifying its type");
                if (!(type == Type.GetType("System.DateTime")))
                {
                    Log.Comment("Expected Type 'System.DateTime' but got '" + type.ToString());
                    testResult = MFTestResults.Fail;
                }
            }
            catch (Exception ex)
            {
                Log.Comment("Caught Unexpected Exception : " + ex.Message);
                return MFTestResults.Fail;
            }

            return testResult;
        }
Пример #2
0
        public void AddParameter(string pNameParameter, DateTime?pValuesParameter)
        {
            System.DateTime exemplo         = DateTime.Now;
            Type            pTypesParameter = exemplo.GetType();

            AddParameter(pNameParameter, pValuesParameter, pTypesParameter);
        }
Пример #3
0
        public void DateTimeIsSerializedCorrect()
        {
            var elementValue = new DateTime(2001, 12, 31, 22, 45, 30);

            var xDoc = Serialize(elementValue);

            if (xDoc.Root == null) Assert.Fail("Document should not be null");
            Assert.That(xDoc.Root.Name.LocalName, Is.EqualTo(elementValue.GetType().Name));
            Assert.That(xDoc.Descendants("DateTime").First().Value, Is.EqualTo(elementValue.ToString(CultureInfo.InvariantCulture)));
        }
 public override bool IsValid(object value, object container)
 {
     object dependentValue = GetDependentValue(container);
     if (value != null && dependentValue != null) {
         try {
             DateTime date = new DateTime();
             if (DateTime.TryParse(value.ToString(), out date)) {
                 value = Convert.ChangeType(value, date.GetType());
             }
             if (DateTime.TryParse(dependentValue.ToString(), out date)) {
                 dependentValue = Convert.ChangeType(dependentValue, date.GetType());
             }
             else
                 dependentValue = Convert.ChangeType(dependentValue, value.GetType());
         }
         catch (Exception) {
             throw new InvalidOperationException("EzValidation: Specific value must be same type, or a type that is able to be cast to the type of property being validated!");
         }
     }
     return IsValid(value, dependentValue, container);
 }
        public static void Main()
        {
            DateTime dateTime = new DateTime();

            Type type = dateTime.GetType();
            foreach(
                System.Reflection.PropertyInfo property in
                    type.GetProperties())
            {
                Console.WriteLine(property.Name);
            }
        }
Пример #6
0
        private static void MarshalCOMVariant()
        {
            MarshalCOMDataTypeClass comObj = new MarshalCOMDataTypeClass();

            object outArg = null;
            string description = string.Empty;

            uint uintArg = 10;
            description = comObj.MarshalCOMVariant(uintArg, out outArg);
            Console.WriteLine("VARIANT - uint: {0}, {1}, {2}",
                uintArg.GetType().Name, outArg.GetType().Name, description);

            double doubleArg = 10.0;
            description = comObj.MarshalCOMVariant(doubleArg, out outArg);
            Console.WriteLine("VARIANT - double: {0}, {1}, {2}",
                doubleArg.GetType().Name, outArg.GetType().Name, description);

            string stringArg = "�ַ���";
            description = comObj.MarshalCOMVariant(stringArg, out outArg);
            Console.WriteLine("VARIANT - string: {0}, {1}, {2}",
                stringArg.GetType().Name, outArg.GetType().Name, description);

            decimal decimalArg = 10.20m;
            description = comObj.MarshalCOMVariant(decimalArg, out outArg);
            Console.WriteLine("VARIANT - decimal: {0}, {1}, {2}",
                decimalArg.GetType().Name, outArg.GetType().Name, description);

            CurrencyWrapper currencyArg = new CurrencyWrapper(10.20m);
            description = comObj.MarshalCOMVariant(currencyArg, out outArg);
            Console.WriteLine("VARIANT - currency: {0}, {1}, {2}",
                currencyArg.GetType().Name, outArg.GetType().Name, description);

            DateTime dateArg = new DateTime(2008, 8, 8);
            description = comObj.MarshalCOMVariant(dateArg, out outArg);
            Console.WriteLine("VARIANT - date: {0}, {1}, {2}",
                dateArg.GetType().Name, outArg.GetType().Name, description);

            object objectArg = new object();
            description = comObj.MarshalCOMVariant(objectArg, out outArg);
            Console.WriteLine("VARIANT - object: {0}, {1}, {2}",
                objectArg.GetType().Name, outArg.GetType().Name, description);

            object nullArg = null;
            description = comObj.MarshalCOMVariant(nullArg, out outArg);
            Console.WriteLine("VARIANT - null: {0}, {1}, {2}",
                "null", outArg == null ? "null" : outArg.GetType().Name, description);

            IntPtr intptrArg = IntPtr.Zero;
            description = comObj.MarshalCOMVariant(intptrArg, out outArg);
            Console.WriteLine("VARIANT - IntPtr: {0}, {1}, {2}",
                intptrArg.GetType().Name, outArg.GetType().Name, description);
        }
Пример #7
0
        public void Test()
        {
            byte a = 1;
            short b = 1;
            int c = -1;
            long d = 1;
            ushort e = 1;
            uint f = 1;
            ulong g = 1;
            float h = 1.1f;
            double i = 1.222;
            bool j = true;
            char k = 'a';
            string l = "aaa";
            DateTime m = new DateTime(2015,1,1,1,1,1);

            var encoder = new BasicType();
            Assert.IsTrue(BasicType.IsBasicType(a.GetType()));
            Assert.AreEqual(a, encoder.DeSerialize<byte>(encoder.Serialize(a)));
            Assert.IsTrue(BasicType.IsBasicType(b.GetType()));
            Assert.AreEqual(b, encoder.DeSerialize<short>(encoder.Serialize(b)));
            Assert.IsTrue(BasicType.IsBasicType(c.GetType()));
            Assert.AreEqual(c, encoder.DeSerialize<int>(encoder.Serialize(c)));
            Assert.IsTrue(BasicType.IsBasicType(d.GetType()));
            Assert.AreEqual(d, encoder.DeSerialize<long>(encoder.Serialize(d)));
            Assert.IsTrue(BasicType.IsBasicType(e.GetType()));
            Assert.AreEqual(e, encoder.DeSerialize<ushort>(encoder.Serialize(e)));
            Assert.IsTrue(BasicType.IsBasicType(f.GetType()));
            Assert.AreEqual(f, encoder.DeSerialize<uint>(encoder.Serialize(f)));
            Assert.IsTrue(BasicType.IsBasicType(g.GetType()));
            Assert.AreEqual(g, encoder.DeSerialize<ulong>(encoder.Serialize(g)));
            Assert.IsTrue(BasicType.IsBasicType(h.GetType()));
            Assert.AreEqual(h, encoder.DeSerialize<float>(encoder.Serialize(h)));
            Assert.IsTrue(BasicType.IsBasicType(i.GetType()));
            Assert.AreEqual(i, encoder.DeSerialize<double>(encoder.Serialize(i)));
            Assert.IsTrue(BasicType.IsBasicType(j.GetType()));
            Assert.AreEqual(j, encoder.DeSerialize<bool>(encoder.Serialize(j)));
            Assert.IsTrue(BasicType.IsBasicType(k.GetType()));
            Assert.AreEqual(k, encoder.DeSerialize<char>(encoder.Serialize(k)));
            Assert.IsTrue(BasicType.IsBasicType(l.GetType()));
            Assert.AreEqual(l, encoder.DeSerialize<string>(encoder.Serialize(l)));
            Assert.IsTrue(BasicType.IsBasicType(m.GetType()));
            Assert.AreEqual(m, encoder.DeSerialize<DateTime>(encoder.Serialize(m)));
            Assert.IsFalse(BasicType.IsBasicType(typeof(object)));
            Assert.Throws(typeof(ArgumentException), () => encoder.Serialize(new List<int>()));
        }
Пример #8
0
        public void Should_test_nullable_non_numeric_types_gettype()
        {
            bool? nullableBool = true;
            Assert.False(nullableBool.GetType().IsNumeric());

            char? nullableChar = ' ';
            Assert.False(nullableChar.GetType().IsNumeric());
            
            DateTime? nullableDateTime = new DateTime(2009, 1, 1);
            Assert.False(nullableDateTime.GetType().IsNumeric());
        }
Пример #9
0
 private bool EvalDateTimeOperator(TokenId op, DateTime lValue, DateTime rValue)
 {
     switch (op)
     {
         case TokenId.EqualEqual:
             {
                 return lValue == rValue;
             }
         case TokenId.Less:
             {
                 return lValue < rValue;
             }
         case TokenId.LessEqual:
             {
                 return lValue <= rValue;
             }
         case TokenId.Greater:
             {
                 return lValue > rValue;
             }
         case TokenId.GreaterEqual:
             {
                 return lValue >= rValue;
             }
         case TokenId.NotEqual:
             {
                 return lValue != rValue;
             }
         default:
             {
                 throw new ParseException("BinaryNotSupport '{0}' between type of '{1}' and '{2}'", op.ToString(), lValue.GetType().Name, rValue.GetType().Name);
             }
     }
 }
Пример #10
0
 public void MarshalDate(DateTime value)
 {
     Console.WriteLine(".NET�е����ͣ�{0}, ֵΪ��{1}", value.GetType().Name, value);
 }
Пример #11
0
        public void SyncGold(DateTime date)
        {
            XmlSerializer dateSerializer = new XmlSerializer(date.GetType());
            var serializer = new XmlSerializer(typeof(IdCardError));

            var memoryStream = new MemoryStream();
            var streamWriter = new StreamWriter(memoryStream, System.Text.Encoding.UTF8);

            dateSerializer.Serialize(streamWriter, date);

            byte[] utf8EncodedXml = memoryStream.ToArray();

            HttpWebRequest request = (HttpWebRequest)WebRequest.Create(String.Concat(URI.RESTurl(), "SyncGold"));
            request.Method = "POST";
            request.ContentType = "application/xml";
            request.ContentLength = utf8EncodedXml.Length;
            this.authenticationProvider.AuthenticatePostRequest(request, null); //serializedValue);
            request.Accept = "application/xml";

            Stream dataStream = request.GetRequestStream();
            dataStream.Write(utf8EncodedXml, 0, utf8EncodedXml.Length);
            dataStream.Close();

            HttpWebResponse response = null;

            IdCardError status = null;

            try
            {
                using (response = (HttpWebResponse)request.GetResponse())
                {
                    if (response.StatusCode == HttpStatusCode.OK)
                    {
                        Stream ReceiveStream = response.GetResponseStream();
                        StreamReader readStream = new StreamReader(ReceiveStream);
                        string xml = readStream.ReadToEnd();

                        status = (IdCardError)serializer.Deserialize(new StringReader(xml));
                    }
                }
            }
            catch (WebException webEx)
            {
                if (response == null)
                {
                    System.Diagnostics.Debug.WriteLine(webEx.Message);
                }
            }

            if (status.Errors == null)
            {
                MessageBox.Show("There are no cards from " + date.ToShortDateString() + " to synchronize.", "Nothing to Sync", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }
            else
            {
                string message = "";
                foreach (Errors error in status.Errors)
                {
                    message += error.Error;
                    message += "\n";
                }
                MessageBox.Show(message, "Synchronize From " + date.ToShortDateString() + " Complete", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }
        }
Пример #12
0
 public string DateTimeInfo(sys.DateTime date, string property)
 {
     return(date.GetType().GetProperty(property).GetValue(date, null).ToString());
 }