Example #1
0
        public void ConstructorWithMillisAndTimeZoneOffset()
        {
            ASDate asDate = new ASDate(123.0, 456);

            Assert.AreEqual(123.0, asDate.MillisecondsSinceEpoch);
            Assert.AreEqual(456, asDate.TimeZoneOffsetMinutes);
        }
Example #2
0
        public void ReadObject_Objects_ReferenceCaching_AMF3()
        {
            // Read an array with multiple copies of each kind of object and including a self-reference
            SetStreamContents(new byte[] {
                (byte)AMF0ObjectTypeCode.AMF3Data, (byte)AMF3ObjectTypeCode.Array, 0x0d,
                0x03, 0x61, (byte)AMF3ObjectTypeCode.Array, 0x00,                  // array by reference
                0x01,                                                              // end of mixed values
                (byte)AMF3ObjectTypeCode.Object, 0x0b, 0x01, 0x01,                 // obj
                (byte)AMF3ObjectTypeCode.ByteArray, 0x01,                          // byte array
                (byte)AMF3ObjectTypeCode.Date, 0x01, 0x3f, 0xf0, 0, 0, 0, 0, 0, 0, // date
                (byte)AMF3ObjectTypeCode.Object, 0x02,                             // obj by reference
                (byte)AMF3ObjectTypeCode.ByteArray, 0x04,                          // byte array by reference
                (byte)AMF3ObjectTypeCode.Date, 0x06,                               // date by reference
            });

            input.BeginObjectStream();
            ASArray array = (ASArray)input.ReadObject();

            Assert.AreEqual(AMFObjectEncoding.AMF3, input.ObjectEncoding);
            input.EndObjectStream();

            Assert.AreEqual(6, array.IndexedValues.Count);
            Assert.AreEqual(1, array.DynamicProperties.Count);

            ASObject    obj       = (ASObject)array.IndexedValues[0];
            ASByteArray byteArray = (ASByteArray)array.IndexedValues[1];
            ASDate      date      = (ASDate)array.IndexedValues[2];

            Assert.AreSame(obj, array.IndexedValues[3]);
            Assert.AreSame(byteArray, array.IndexedValues[4]);
            Assert.AreSame(date, array.IndexedValues[5]);
            Assert.AreSame(array, array.DynamicProperties["a"]);
        }
Example #3
0
        public void ToDateTimeIsARoundTripOperationExceptForLossOfPrecision_NonUtc()
        {
            DateTime now  = new DateTime(1999, 12, 31, 0, 0, 0, DateTimeKind.Local);
            ASDate   date = new ASDate(now);

            Assert.AreEqual(now, date.ToDateTime());
        }
Example #4
0
        public void EqualsWithOtherDate(double millis1, int tzoffset1, double millis2, int tzoffset2, bool expectedResult)
        {
            ASDate date1 = new ASDate(millis1, tzoffset1);
            ASDate date2 = new ASDate(millis2, tzoffset2);

            Assert.AreEqual(expectedResult, date1.Equals(date2));
        }
Example #5
0
        public void GetHashCodeIsSane()
        {
            ASDate date1 = new ASDate(12.0, 120);
            ASDate date2 = new ASDate(12.0, 120);

            Assert.AreEqual(date1.GetHashCode(), date2.GetHashCode());
        }
Example #6
0
        public void ConstructorWithDateTimeAndTimeZoneOffset()
        {
            DateTime then   = new DateTime(1970, 1, 2, 0, 0, 0, DateTimeKind.Local);
            ASDate   asDate = new ASDate(then, -600);

            Assert.AreEqual(86400000.0, asDate.MillisecondsSinceEpoch);
            Assert.AreEqual(-600, asDate.TimeZoneOffsetMinutes);
        }
Example #7
0
        public void ConstructorWithDateTime_NonUtc()
        {
            DateTime then   = new DateTime(1970, 1, 2, 0, 0, 0, DateTimeKind.Local);
            ASDate   asDate = new ASDate(then);

            int tzOffset = (int)TimeZone.CurrentTimeZone.GetUtcOffset(then).TotalMinutes;

            Assert.AreEqual(86400000.0 + tzOffset * 60000, asDate.MillisecondsSinceEpoch);
            Assert.AreEqual(tzOffset, asDate.TimeZoneOffsetMinutes);
        }
Example #8
0
        public void WriteObject_Dates(AMFObjectEncoding objectEncoding, byte[] expected, int millisecondsSinceEpoch)
        {
            ASDate date = new ASDate(1, 0);

            output.ObjectEncoding = objectEncoding;
            output.BeginObjectStream();
            output.WriteObject(date);
            output.EndObjectStream();

            CollectionAssert.AreElementsEqual(expected, stream.ToArray());
        }
Example #9
0
        public void ReadObject_Dates(AMFObjectEncoding objectEncoding, byte[] bytes, int millisecondsSinceEpoch, int timezoneOffsetMinutes)
        {
            SetStreamContents(bytes);

            input.BeginObjectStream();
            ASDate result = (ASDate)input.ReadObject();

            Assert.AreEqual(objectEncoding, input.ObjectEncoding);
            input.EndObjectStream();

            Assert.AreEqual(millisecondsSinceEpoch, result.MillisecondsSinceEpoch);
            Assert.AreEqual(timezoneOffsetMinutes, result.TimeZoneOffsetMinutes);
        }
Example #10
0
        private IASValue ReadDate()
        {
            int bits = input.ReadVWInt29();

            // Handle cached objects.
            if ((bits & 1) == 0)
            {
                int referenceId = bits >> 1;
                return(GetObjectFromCache(AMF3ObjectTypeCode.Date, referenceId));
            }

            // Read out the whole date.
            double millisecondsSinceEpoch = input.ReadDouble();

            ASDate result = new ASDate(millisecondsSinceEpoch, 0);

            AddObjectToCache(AMF3ObjectTypeCode.Date, result);
            return(result);
        }
Example #11
0
        public void WriteObject_Objects_ReferenceCaching(AMFObjectEncoding objectEncoding, byte[] expected)
        {
            // Create an array with multiple copies of each kind of object and including a self-reference
            ASObject    obj       = new ASObject();
            ASByteArray byteArray = new ASByteArray(new byte[0]);
            ASDate      date      = new ASDate(1, 0);
            ASArray     array     = new ASArray(6);

            array.IndexedValues[0]       = obj;
            array.IndexedValues[1]       = byteArray;
            array.IndexedValues[2]       = date;
            array.IndexedValues[3]       = obj;
            array.IndexedValues[4]       = byteArray;
            array.IndexedValues[5]       = date;
            array.DynamicProperties["a"] = array;

            output.ObjectEncoding = objectEncoding;
            output.BeginObjectStream();
            output.WriteObject(array);
            output.EndObjectStream();

            CollectionAssert.AreElementsEqual(expected, stream.ToArray());
        }
Example #12
0
 protected override object MapDateToNative(IActionScriptSerializer serializer, Type nativeType, double millisecondsSinceEpoch, int timeZoneOffsetMinutes)
 {
     return(String.Format(CultureInfo.InstalledUICulture, "{0:yyyy/MM/dd HH:mm:ss.fff}",
                          ASDate.ToDateTime(millisecondsSinceEpoch, timeZoneOffsetMinutes)));
 }
Example #13
0
 protected override object MapDateToNative(IActionScriptSerializer serializer, Type nativeType, double millisecondsSinceEpoch, int timeZoneOffsetMinutes)
 {
     return(ASDate.ToDateTime(millisecondsSinceEpoch, timeZoneOffsetMinutes));
 }
Example #14
0
        public void EqualsWithNonDateIsFalse()
        {
            ASDate date = new ASDate(DateTime.Now);

            Assert.AreNotEqual(date, 42);
        }
Example #15
0
        public void EqualsWithNullIsFalse()
        {
            ASDate date = new ASDate(DateTime.Now);

            Assert.AreNotEqual(date, null);
        }