Exemple #1
0
 public void ToIsoStringTest()
 {
     ExecuteInsideSession(() => {
         RunTest <SingleDateTimeEntity>(c => c.DateTime.ToString("s") == FirstDateTime.ToString("s"));
         RunWrongTest <SingleDateTimeEntity>(c => c.DateTime.ToString("s") == FirstDateTime.AddMinutes(1).ToString("s"));
     });
 }
        /// <summary>
        ///     Returns this class as a byte array
        /// </summary>
        internal byte[] ToByteArray()
        {
            using (var memoryStream = new MemoryStream())
            {
                var binaryWriter = new BinaryWriter(memoryStream);
                // ReaderVersion (2 bytes):  This field MUST be set to 0x3004.
                binaryWriter.Write((ushort)0x3004);
                // WriterVersion (2 bytes):  This field MUST be set to 0x3004.
                binaryWriter.Write(0x3004);
                // RecurFrequency (2 bytes):  An integer that specifies the frequency of the recurring series
                binaryWriter.Write((ushort)RecurFrequency);
                // PatternType (2 bytes): An integer that specifies the type of recurrence pattern
                binaryWriter.Write((ushort)PatternType);
                //CalendarType (2 bytes): An integer that specifies the type of calendar that is used
                binaryWriter.Write((ushort)CalendarType);
                // FirstDateTime (4 bytes):  An integer that specifies the first ever day, week, or month of a recurring series, dating back to a reference date, which is January 1, 1601, for a Gregorian calendar. The value and its meaning depend on the value of the RecurFrequency field. The value of the FirstDateTime field is used to determine the valid dates of a recurring series, as specified in section 2.2.1.44.1.2.
                binaryWriter.Write((int)FirstDateTime.ToFileTime());

                // TODO : Write the rest of the properties https://msdn.microsoft.com/en-us/library/ee203303(v=exchg.80).aspx

                //if (BitConverter.IsLittleEndian)
                //{
                //    bits = bits.Reverse().ToArray();
                //    binaryWriter.Write(bits);
                //}
                //else
                //    binaryWriter.Write(bits);

                //Strings.WriteNullTerminatedUnicodeString(binaryWriter, DisplayName);
                //Strings.WriteNullTerminatedUnicodeString(binaryWriter, AddressTypeString);
                //Strings.WriteNullTerminatedUnicodeString(binaryWriter, Email);

                return(memoryStream.ToArray());
            }
        }
 public void NotEqualTest()
 {
     ExecuteInsideSession(() => {
         RunTest <SingleDateTimeEntity>(c => c.DateTime != FirstDateTime.AddYears(1));
         RunTest <SingleDateTimeEntity>(c => c.MillisecondDateTime != FirstMillisecondDateTime.AddYears(1));
         RunTest <SingleDateTimeEntity>(c => c.NullableDateTime != NullableDateTime.AddYears(1));
     });
 }
        public void AddSecondsTest()
        {
            ExecuteInsideSession(() => {
                RunTest <SingleDateTimeEntity>(c => c.DateTime.AddSeconds(1) == FirstDateTime.AddSeconds(1));
                RunTest <SingleDateTimeEntity>(c => c.MillisecondDateTime.AddSeconds(-2) == FirstMillisecondDateTime.AddSeconds(-2));
                RunTest <SingleDateTimeEntity>(c => c.NullableDateTime.Value.AddSeconds(33) == NullableDateTime.AddSeconds(33));

                RunWrongTest <SingleDateTimeEntity>(c => c.DateTime.AddSeconds(1) == FirstDateTime.AddSeconds(2));
                RunWrongTest <SingleDateTimeEntity>(c => c.MillisecondDateTime.AddSeconds(-1) == FirstMillisecondDateTime.AddSeconds(-2));
                RunWrongTest <SingleDateTimeEntity>(c => c.NullableDateTime.Value.AddSeconds(33) == NullableDateTime.AddSeconds(44));
            });
        }
        public void AddTimeSpanTest()
        {
            ExecuteInsideSession(() => {
                RunTest <SingleDateTimeEntity>(c => c.DateTime.Add(FirstOffset) == FirstDateTime.Add(FirstOffset));
                RunTest <SingleDateTimeEntity>(c => c.MillisecondDateTime.Add(SecondOffset) == FirstMillisecondDateTime.Add(SecondOffset));
                RunTest <SingleDateTimeEntity>(c => c.NullableDateTime.Value.Add(FirstOffset) == NullableDateTime.Add(FirstOffset));

                RunWrongTest <SingleDateTimeEntity>(c => c.DateTime.Add(FirstOffset) == FirstDateTime.Add(WrongOffset));
                RunWrongTest <SingleDateTimeEntity>(c => c.MillisecondDateTime.Add(SecondOffset) == FirstMillisecondDateTime.Add(WrongOffset));
                RunWrongTest <SingleDateTimeEntity>(c => c.NullableDateTime.Value.Add(FirstOffset) == NullableDateTime.Add(WrongOffset));
            });
        }
        public void MysqlCompareTest()
        {
            Require.ProviderIs(StorageProvider.MySql);
            ExecuteInsideSession(() => {
                RunTest <SingleDateTimeEntity>(c => c.DateTime > FirstDateTime.Date);
                RunTest <SingleDateTimeEntity>(c => c.DateTime > FirstDateTime.AddSeconds(-1));

                RunTest <SingleDateTimeEntity>(c => c.DateTime < FirstDateTime.Date.AddDays(1));
                RunTest <SingleDateTimeEntity>(c => c.DateTime < FirstDateTime.AddSeconds(1));

                RunWrongTest <SingleDateTimeEntity>(c => c.DateTime > FirstDateTime);
                RunWrongTest <SingleDateTimeEntity>(c => c.MillisecondDateTime > FirstMillisecondDateTime);
                RunWrongTest <SingleDateTimeEntity>(c => c.MillisecondDateTime < FirstMillisecondDateTime.Date);
            });
        }
        public void CompareTest()
        {
            ExecuteInsideSession(() => {
                RunTest <SingleDateTimeEntity>(c => c.DateTime > FirstDateTime.Date);
                RunTest <SingleDateTimeEntity>(c => c.DateTime > FirstDateTime.AddSeconds(-1));
                RunTest <SingleDateTimeEntity>(c => c.MillisecondDateTime > FirstMillisecondDateTime.AddMilliseconds(-1));

                RunTest <SingleDateTimeEntity>(c => c.DateTime < FirstDateTime.Date.AddDays(1));
                RunTest <SingleDateTimeEntity>(c => c.DateTime < FirstDateTime.AddSeconds(1));
                RunTest <SingleDateTimeEntity>(c => c.MillisecondDateTime < FirstMillisecondDateTime.AddMilliseconds(1));

                RunWrongTest <SingleDateTimeEntity>(c => c.DateTime > FirstDateTime);
                RunWrongTest <SingleDateTimeEntity>(c => c.MillisecondDateTime > FirstMillisecondDateTime);
                RunWrongTest <SingleDateTimeEntity>(c => c.MillisecondDateTime < FirstMillisecondDateTime.Date);
            });
        }
        public void MysqlMinisDateTimeTest()
        {
            Require.ProviderIs(StorageProvider.MySql);
            ExecuteInsideSession(() => {
                var firstDateTime            = FirstDateTime.FixDateTimeForProvider(StorageProviderInfo.Instance);
                var firstMillisecondDateTime = FirstMillisecondDateTime.FixDateTimeForProvider(StorageProviderInfo.Instance);
                var secondDateTime           = SecondDateTime.FixDateTimeForProvider(StorageProviderInfo.Instance);
                var nullableDateTime         = NullableDateTime.FixDateTimeForProvider(StorageProviderInfo.Instance);

                RunTest <SingleDateTimeEntity>(c => c.DateTime - secondDateTime == firstDateTime - secondDateTime);
                RunTest <SingleDateTimeEntity>(c => c.MillisecondDateTime - secondDateTime == firstMillisecondDateTime - secondDateTime);
                RunTest <SingleDateTimeEntity>(c => c.NullableDateTime - secondDateTime == nullableDateTime - secondDateTime);

                RunWrongTest <SingleDateTimeEntity>(c => c.DateTime - secondDateTime == firstDateTime - WrongDateTime);
                RunWrongTest <SingleDateTimeEntity>(c => c.MillisecondDateTime - secondDateTime == firstMillisecondDateTime - WrongDateTime);
                RunWrongTest <SingleDateTimeEntity>(c => c.NullableDateTime - secondDateTime == nullableDateTime - WrongDateTime);
            });
        }
        public void SubtractDateTimeTest()
        {
            Require.ProviderIsNot(StorageProvider.MySql);
            ExecuteInsideSession(() => {
                RunTest <SingleDateTimeEntity>(c => c.DateTime.Subtract(SecondDateTime) == FirstDateTime.Subtract(SecondDateTime));
                RunTest <SingleDateTimeEntity>(c => c.MillisecondDateTime.Subtract(SecondDateTime) == FirstMillisecondDateTime.Subtract(SecondDateTime));
                RunTest <SingleDateTimeEntity>(c => c.NullableDateTime.Value.Subtract(SecondDateTime) == NullableDateTime.Subtract(SecondDateTime));

                RunWrongTest <SingleDateTimeEntity>(c => c.DateTime.Subtract(SecondDateTime) == FirstDateTime.Subtract(WrongDateTime));
                RunWrongTest <SingleDateTimeEntity>(c => c.MillisecondDateTime.Subtract(SecondDateTime) == FirstMillisecondDateTime.Subtract(WrongDateTime));
                RunWrongTest <SingleDateTimeEntity>(c => c.NullableDateTime.Value.Subtract(SecondDateTime) == NullableDateTime.Subtract(WrongDateTime));
            });
        }
Exemple #10
0
        public void SubtractDateTimeTest()
        {
            ExecuteInsideSession(() => {
                RunTest <SingleDateTimeEntity>(c => c.DateTime.Subtract(SecondDateTime) == FirstDateTime.Subtract(SecondDateTime));
                RunTest <SingleDateTimeEntity>(c => c.MillisecondDateTime.Subtract(SecondDateTime) == FirstMillisecondDateTime.Subtract(SecondDateTime));
                RunTest <SingleDateTimeEntity>(c => c.NullableDateTime.Value.Subtract(SecondDateTime) == NullableDateTime.Subtract(SecondDateTime));

                RunWrongTest <SingleDateTimeEntity>(c => c.DateTime.Subtract(SecondDateTime) == FirstDateTime.Subtract(WrongDateTime));
                RunWrongTest <SingleDateTimeEntity>(c => c.MillisecondDateTime.Subtract(SecondDateTime) == FirstMillisecondDateTime.Subtract(WrongDateTime));
                RunWrongTest <SingleDateTimeEntity>(c => c.NullableDateTime.Value.Subtract(SecondDateTime) == NullableDateTime.Subtract(WrongDateTime));
            });
        }