Пример #1
0
        /// <summary>
        /// Writes a SIF 1.x &lt;SIF_Time&gt; element
        /// </summary>
        /// <param name="writer"></param>
        /// <param name="formatter"></param>
        /// <param name="elementName"></param>
        /// <param name="time"></param>
        public static void WriteSIFTime(
            XmlWriter writer,
            SifFormatter formatter,
            String elementName,
            DateTime time)
        {
            String xmlTime = formatter.ToTimeString(time);

            writer.WriteStartElement(elementName);
            writer.WriteAttributeString("Zone", Sif1xFormatter.FormatTimeZone(time));
            writer.WriteValue(xmlTime);
            writer.WriteEndElement();
        }
Пример #2
0
        public void testSIF1xEmtpyStringSupport()
        {
            SifFormatter SIF1x = new Sif1xFormatter();


            Assertion.AssertNull("Should be null", SIF1x.ToBool(""));
            Assertion.AssertNull("Should be null", SIF1x.ToBool("  "));
            Assertion.AssertNull("Should be null", SIF1x.ToDecimal(""));
            Assertion.AssertNull("Should be null", SIF1x.ToDecimal("  "));
            Assertion.AssertNull("Should be null", SIF1x.ToInt(""));
            Assertion.AssertNull("Should be null", SIF1x.ToInt("  "));
            Assertion.AssertNull("Should be null", SIF1x.ToDateTime(""));
            Assertion.AssertNull("Should be null", SIF1x.ToDateTime("  "));
        }
Пример #3
0
        public void testParsing()
        {
            SifFormatter SIF1x        = new Sif1xFormatter();
            SifFormatter SIF2x        = new Sif2xFormatter();
            Boolean      BooleanValue = true;
            //mjn declare types as nullable
            Boolean?BooleanNull = null;
            int?    intNull     = null;

            assertBooleanParsing(SIF1x, "Yes", BooleanValue);
            Assert.AreEqual("", SIF1x.ToString(BooleanNull), "Null Bool Value"); //( (Boolean)null ));
            assertBooleanParsing(SIF2x, "true", BooleanValue);
            Assert.IsNull(SIF2x.ToString(BooleanNull), "Null Bool Value");

            bool?testValue = SIF2x.ToBool("1");

            Assert.IsTrue(testValue.Value, "Boolean Value");

            testValue = SIF2x.ToBool("0");
            Assert.IsFalse(testValue.Value, "Boolean Value");

            float floatValue = 99.34f;

            assertFloatParsing(SIF1x, "99.34", floatValue);
            Assert.IsNull(SIF1x.ToString((float?)null));
            assertFloatParsing(SIF2x, "99.34", floatValue);
            Assert.IsNull(SIF2x.ToString((float?)null));

            floatValue = 321651.09934f;
            assertFloatParsing(SIF1x, "321651.1", floatValue);
            assertFloatParsing(SIF2x, "321651.1", floatValue);


            //INF, -INF and NaN
            assertFloatParsing(SIF1x, "INF", float.PositiveInfinity);
            assertFloatParsing(SIF1x, "-INF", float.NegativeInfinity);

            float?nan = SIF1x.ToFloat("NaN");

            Assert.IsTrue(float.IsNaN(nan.Value));

            assertFloatParsing(SIF2x, "INF", float.PositiveInfinity);
            assertFloatParsing(SIF2x, "-INF", float.NegativeInfinity);

            nan = SIF2x.ToFloat("NaN");
            Assert.IsTrue(float.IsNaN(nan.Value));


            int intValue = 9998877; // new int(9998877);

            assertintParsing(SIF1x, "9998877", intValue);
            Assertion.AssertEquals("Null int Value", "", SIF1x.ToString(intNull));
            assertintParsing(SIF2x, "9998877", intValue);
            Assertion.AssertNull("Null int Value", SIF2x.ToString(intNull));
            DateTime?sampleDate = new DateTime(1999, 10, 01);

            AssertDateParsing(SIF1x, "19991001", sampleDate);
            Assertion.AssertEquals("Null Value", "", SIF1x.ToDateString(null));
            AssertDateParsing(SIF2x, "1999-10-01" /* + tzOffset */, sampleDate);
            Assertion.AssertNull("Null Date Value", SIF2x.ToDateString(null));
        }