Ejemplo n.º 1
0
        public void GetLastEventStampTest()
        {
            DateTime expectedValue = DateTime.UtcNow;
            long     ticks         = expectedValue.Ticks;
            string   filePath      = string.Format("{0}\\1_2_3_6.0.0.1_4_5_{1}_0000000000.dtr.zip", TestUtility.TestDirectory, ticks);

            File.Create(filePath).Dispose();

            DateTime result = EventStampInfo.GetLastEventStamp(new FileInfo(filePath));

            Assert.AreEqual(expectedValue, result);
            File.Delete(filePath);

            string[] invalidfilePaths = new string[]
            {
                string.Format("{0}\\1_2_3_6.0.0.1_4_5_hiahia_0000000000.dtr.zip", TestUtility.TestDirectory),
                string.Format("{0}\\1_2_3_6.0.0.1_4_5_99999999999999999999999999999999999999999999999999_0000000000.dtr.zip", TestUtility.TestDirectory),
                string.Format("{0}\\0000000000.dtr.zip", TestUtility.TestDirectory),
            };

            foreach (string invalidFilePath in invalidfilePaths)
            {
                File.Create(invalidFilePath).Dispose();
                Assert.AreEqual(DateTime.MinValue.ToUniversalTime(), EventStampInfo.GetLastEventStamp(new FileInfo(invalidFilePath)));
                File.Delete(invalidFilePath);
            }
        }
Ejemplo n.º 2
0
        public void ConstructFromFileInfosTest()
        {
            List <FileInfo> fileInfos = new List <FileInfo>(this.testFiles.Select(p => new FileInfo(p.Value)));

            EventStampInfo[] result = EventStampInfo.ConstructFromFileInfos(fileInfos).ToArray();

            Assert.AreEqual(this.testFiles.Count(), result.Count());
            Assert.AreEqual(result[result.Length - 1].LastEventStamp, result.Max(p => p.LastEventStamp));

            HashSet <DateTime> firstEventStamps = new HashSet <DateTime>(result.Select(p => p.FirstEventStamp));

            Assert.AreEqual(result.Length, firstEventStamps.Count);
            HashSet <DateTime> lastEventStamps = new HashSet <DateTime>(result.Select(p => p.LastEventStamp));

            Assert.AreEqual(result.Length, lastEventStamps.Count);

            for (int i = 0; i < result.Length; i++)
            {
                if (i == 0)
                {
                    Assert.AreEqual(DateTime.MinValue.ToUniversalTime(), result[i].FirstEventStamp);
                }
                else
                {
                    Assert.AreEqual(result[i - 1].LastEventStamp, result[i].FirstEventStamp);
                }
            }
        }
Ejemplo n.º 3
0
        public void ConstructorTest()
        {
            DateTime       expectedFirstStamp = new DateTime(2, 2, 2, 2, 2, 2, DateTimeKind.Utc);
            DateTime       expectedLastStamp  = new DateTime(3, 3, 3, 3, 3, 3, DateTimeKind.Utc);
            EventStampInfo info = new EventStampInfo(expectedFirstStamp, expectedLastStamp);

            Assert.AreEqual(expectedFirstStamp, info.FirstEventStamp);
            Assert.AreEqual(expectedLastStamp, info.LastEventStamp);
        }
Ejemplo n.º 4
0
        public void GetEventStampCutsTest()
        {
            EventStampInfo[] infos = new EventStampInfo[]
            {
                new EventStampInfo(DateTime.MinValue, new DateTime(2000, 1, 1)),
                new EventStampInfo(new DateTime(2000, 1, 1), new DateTime(3000, 1, 1)),
                new EventStampInfo(new DateTime(3000, 1, 1), new DateTime(4000, 1, 1)),
                new EventStampInfo(new DateTime(4000, 1, 1), new DateTime(5000, 1, 1)),
                new EventStampInfo(new DateTime(5000, 1, 1), new DateTime(6000, 1, 1)),
            };

            DateTime startTime;
            DateTime endTime;
            DateTime startCut;
            DateTime endCut;

            startTime = new DateTime(1000, 1, 1);
            endTime   = startTime + TimeSpan.FromDays(1);
            EventStampFilter.GetEventStampCuts(infos, startTime, endTime, out startCut, out endCut);
            Assert.AreEqual(new DateTime(2000, 1, 1), startCut);
            Assert.AreEqual(new DateTime(2000, 1, 1), endCut);

            startTime = new DateTime(7000, 1, 1);
            endTime   = startTime + TimeSpan.FromDays(1);
            EventStampFilter.GetEventStampCuts(infos, startTime, endTime, out startCut, out endCut);
            Assert.AreEqual(DateTime.MaxValue.ToUniversalTime(), startCut);
            Assert.AreEqual(DateTime.MinValue.ToUniversalTime(), endCut);

            startTime = new DateTime(3000, 1, 1);
            endTime   = new DateTime(4000, 1, 1);
            EventStampFilter.GetEventStampCuts(infos, startTime, endTime, out startCut, out endCut);
            Assert.AreEqual(startTime, startCut);
            Assert.AreEqual(new DateTime(5000, 1, 1), endCut);

            startTime = new DateTime(1000, 1, 1);
            endTime   = new DateTime(9000, 1, 1);
            EventStampFilter.GetEventStampCuts(infos, startTime, endTime, out startCut, out endCut);
            Assert.AreEqual(startTime, startCut);
            Assert.AreEqual(DateTime.MaxValue.ToUniversalTime(), endCut);

            startTime = new DateTime(1000, 1, 1);
            endTime   = new DateTime(3000, 1, 1);
            EventStampFilter.GetEventStampCuts(infos, startTime, endTime, out startCut, out endCut);
            Assert.AreEqual(new DateTime(2000, 1, 1), startCut);
            Assert.AreEqual(new DateTime(4000, 1, 1), endCut);

            startTime = new DateTime(3000, 1, 1);
            endTime   = new DateTime(9000, 1, 1);
            EventStampFilter.GetEventStampCuts(infos, startTime, endTime, out startCut, out endCut);
            Assert.AreEqual(startTime, startCut);
            Assert.AreEqual(DateTime.MaxValue.ToUniversalTime(), endCut);
        }