Exemple #1
0
        public void CheckMeasuredValueConverter()
        {
            string   name  = "TestName";
            string   value = "Text";
            DateTime dt    = DateTime.Now;

            MeasuredValue mv = MeasuredValueConverter.ConvertTo(name, dt, value, TypeCode.String);

            Assert.AreEqual(name, mv.Name);
            Assert.AreEqual(dt, mv.TimeStamp);
            Assert.AreEqual(value, mv.Value);
            Assert.AreEqual(TypeCode.String, mv.GetTypeCode());

            TypeCode tc         = TypeCode.Int16;
            short    shortValue = 100;

            value = shortValue.ToString();
            mv    = MeasuredValueConverter.ConvertTo(name, dt, value, tc);
            Assert.AreEqual(name, mv.Name);
            Assert.AreEqual(dt, mv.TimeStamp);
            Assert.AreEqual(shortValue, mv.Value);
            Assert.AreEqual(tc, mv.GetTypeCode());
            Assert.AreEqual(OPCQuality.Good, mv.Quality);

            tc = TypeCode.Int32;
            int intValue = 110;

            value = intValue.ToString();
            mv    = MeasuredValueConverter.ConvertTo(name, dt, value, tc);
            Assert.AreEqual(name, mv.Name);
            Assert.AreEqual(dt, mv.TimeStamp);
            Assert.AreEqual(intValue, mv.Value);
            Assert.AreEqual(tc, mv.GetTypeCode());
            Assert.AreEqual(OPCQuality.Good, mv.Quality);

            tc = TypeCode.Int64;
            long longValue = 120;

            value = longValue.ToString();
            mv    = MeasuredValueConverter.ConvertTo(name, dt, value, tc);
            Assert.AreEqual(name, mv.Name);
            Assert.AreEqual(dt, mv.TimeStamp);
            Assert.AreEqual(longValue, mv.Value);
            Assert.AreEqual(tc, mv.GetTypeCode());
            Assert.AreEqual(OPCQuality.Good, mv.Quality);

            tc = TypeCode.Single;
            float floatValue = 1002.2f;

            value = floatValue.ToString(System.Globalization.CultureInfo.InvariantCulture);
            mv    = MeasuredValueConverter.ConvertTo(name, dt, value, tc);
            Assert.AreEqual(name, mv.Name);
            Assert.AreEqual(dt, mv.TimeStamp);
            Assert.AreEqual(floatValue, mv.Value);
            Assert.AreEqual(tc, mv.GetTypeCode());
            Assert.AreEqual(OPCQuality.Good, mv.Quality);

            tc = TypeCode.Double;
            double doubleValue = 2002.2;

            value = doubleValue.ToString(System.Globalization.CultureInfo.InvariantCulture);
            mv    = MeasuredValueConverter.ConvertTo(name, dt, value, tc);
            Assert.AreEqual(name, mv.Name);
            Assert.AreEqual(dt, mv.TimeStamp);
            Assert.AreEqual(doubleValue, mv.Value);
            Assert.AreEqual(tc, mv.GetTypeCode());
            Assert.AreEqual(OPCQuality.Good, mv.Quality);

            value = doubleValue.ToString(System.Globalization.CultureInfo.CreateSpecificCulture("de"));
            MeasuredValueConverter.UsedCultureInfo = System.Globalization.CultureInfo.CreateSpecificCulture("de");
            mv = MeasuredValueConverter.ConvertTo(name, dt, value, tc);
            Assert.AreEqual(name, mv.Name);
            Assert.AreEqual(dt, mv.TimeStamp);
            Assert.AreEqual(doubleValue, mv.Value);
            Assert.AreEqual(tc, mv.GetTypeCode());
            Assert.AreEqual(OPCQuality.Good, mv.Quality);

            MeasuredValueConverter.UsedCultureInfo = System.Globalization.CultureInfo.InvariantCulture;
            tc = TypeCode.Boolean;
            bool boolValue = true;

            value = boolValue.ToString();
            mv    = MeasuredValueConverter.ConvertTo(name, dt, value, tc);
            Assert.AreEqual(name, mv.Name);
            Assert.AreEqual(dt, mv.TimeStamp);
            Assert.AreEqual(boolValue, mv.Value);
            Assert.AreEqual(tc, mv.GetTypeCode());
            Assert.AreEqual(OPCQuality.Good, mv.Quality);

            value = "True";
            mv    = MeasuredValueConverter.ConvertTo(name, dt, value, tc);
            Assert.AreEqual(boolValue, mv.Value);
            Assert.AreEqual(OPCQuality.Good, mv.Quality);

            value = "TRUE";
            mv    = MeasuredValueConverter.ConvertTo(name, dt, value, tc);
            Assert.AreEqual(boolValue, mv.Value);
            Assert.AreEqual(OPCQuality.Good, mv.Quality);
        }
Exemple #2
0
 public void CheckMeasuredValueConverterException()
 {
     MeasuredValue mv = MeasuredValueConverter.ConvertTo("name", DateTime.Now, null, TypeCode.Empty);
 }