示例#1
0
        public void ReadXElement_Empty_ThrowsSyncDocumentException()
        {
            DailyPattern pattern = new DailyPattern();

            XElement element = XElement.Parse("<NotDailyPattern />");
            pattern.ReadXElement(element);
        }
示例#2
0
        public void GetNextDateAfter_RepeatEveryNDay()
        {
            // Arrange.
            var target = new DailyPattern();
            var afterDate = new DateTime(2013, 1, 16); // Wednesday.

            // Act.
            var result = target.GetNextDateAfter(afterDate);

            // Assert.
            var expected = new DateTime(2013, 1, 17); // Thursday.
            Assert.AreEqual(expected, result);

            // Arrange.
            target = new DailyPattern();
            afterDate = new DateTime(2013, 1, 18); // Friday.

            // Act.
            result = target.GetNextDateAfter(afterDate);

            // Assert.
            expected = new DateTime(2013, 1, 19); // Saturday.
            Assert.AreEqual(expected, result);

            // Arrange.
            target = new DailyPattern { RepeatEveryNDay = 3 };
            afterDate = new DateTime(2013, 1, 17); // Thursday.

            // Act.
            result = target.GetNextDateAfter(afterDate);

            // Assert.
            expected = new DateTime(2013, 1, 20); // Sunday.
            Assert.AreEqual(expected, result);
        }
示例#3
0
        public void GetNextDateAfter_RepeatEveryWeekDay()
        {
            // Arrange.
            var target = new DailyPattern { RepeatEveryWeekDay = true };
            var afterDate = new DateTime(2013, 1, 14); // Monday.

            // Act.
            var result = target.GetNextDateAfter(afterDate);

            // Assert.
            var expected = new DateTime(2013, 1, 15); // Tuesday.
            Assert.AreEqual(expected, result);

            // Arrange.
            target = new DailyPattern { RepeatEveryWeekDay = true };
            afterDate = new DateTime(2013, 1, 18); // Friday.

            // Act.
            result = target.GetNextDateAfter(afterDate);

            // Assert.
            expected = new DateTime(2013, 1, 21); // Monday.
            Assert.AreEqual(expected, result);

            // Arrange.
            target = new DailyPattern { RepeatEveryWeekDay = true };
            afterDate = new DateTime(2013, 1, 20); // Sunday.

            // Act.
            result = target.GetNextDateAfter(afterDate);

            // Assert.
            expected = new DateTime(2013, 1, 21); // Monday.
            Assert.AreEqual(expected, result);
        }
示例#4
0
        public void GetXElement_SetRepeatEveryWeekDayFalse_ReturnsCorrectXml()
        {
            DailyPattern pattern = new DailyPattern();
            pattern.RepeatEveryWeekDay = false;

            var element = pattern.GetXElement();

            var attribute = element.Attribute(DailyPattern.CN_REPEAT_EVERY_WEEK_DAY);

            Assert.IsNotNull(attribute);
            Assert.IsTrue(attribute.Value == "false");
        }
        public void ShouldWorkWithNumberOfOccurrences()
        {
            var date    = DateTime.Now.Date;
            var pattern = new DailyPattern(date, 1)
            {
                NumberOfOccurrences = 5
            };

            var occurrence = new Occurrence
            {
                Start = date,
                End   = date.AddHours(1)
            };

            var result = PatternConverter.Convert(pattern, occurrence);

            Assert.Equal(5, result.Count);
            Assert.Equal(date, result.First().Start);
        }
        public void ShouldContainDailyOccurences()
        {
            var date    = DateTime.Now.Date;
            var pattern = new DailyPattern(date, 1)
            {
                EndDate = DateTime.Now.Date.AddDays(5)
            };

            var occurrence = new Occurrence
            {
                Start = date.AddHours(1),
                End   = date.AddHours(2)
            };

            var result = PatternConverter.Convert(pattern, occurrence);

            Assert.Equal(6, result.Count);
            Assert.Equal(date.AddHours(1), result.First().Start);
        }
示例#7
0
        public void RepeatEveryNDayDefaultsToOne()
        {
            var target = new DailyPattern();

            Assert.AreEqual(1, target.RepeatEveryNDay);
        }
示例#8
0
        public void GetHashCodeTest()
        {
            const int RepeatEveryNDay = 4;
            const bool RepeatEveryWeekDay = true;

            var hash = RepeatEveryNDay.GetHashCode() ^ RepeatEveryWeekDay.GetHashCode();

            var instance = new DailyPattern { RepeatEveryNDay = RepeatEveryNDay, RepeatEveryWeekDay = RepeatEveryWeekDay };

            var res = instance.GetHashCode();

            Assert.AreEqual(hash, res);
        }
示例#9
0
        public void EqualsAsISheduleTest()
        {
            var instance = new DailyPattern();

            var res = instance.Equals(Mock.Create<ISchedulePattern>());

            Assert.IsFalse(res);
        }
示例#10
0
        public void PatternsWithEqualFieldsAreEqual()
        {
            var target = new DailyPattern { RepeatEveryNDay = 3, RepeatEveryWeekDay = true };

            var other = new DailyPattern { RepeatEveryNDay = 3, RepeatEveryWeekDay = true };

            Assert.IsTrue(target.Equals(other));
        }
示例#11
0
 public void PatternsWithDifferentRepeatEveryWeekDayAreNotEqual()
 {
     var target = new DailyPattern { RepeatEveryWeekDay = false };
     var other = new DailyPattern { RepeatEveryWeekDay = true };
     Assert.IsFalse(target.Equals(other));
 }
示例#12
0
 public void PatternsWithDefaultValuesAreEqual()
 {
     var target = new DailyPattern();
     var other = new DailyPattern();
     Assert.IsTrue(target.Equals(other));
 }
示例#13
0
 public void PatternIsEqualToSelf()
 {
     var target = new DailyPattern();
     Assert.IsTrue(target.Equals(target));
 }
示例#14
0
 public void PatternIsNotEqualToNull()
 {
     var target = new DailyPattern();
     Assert.IsFalse(target.Equals(null));
 }
        /// <summary>
        /// Converts the specified pattern.
        /// </summary>
        /// <param name="pattern">The pattern.</param>
        /// <param name="defaultOccurrence">The default occurrence.</param>
        /// <returns></returns>
        public static OccurrenceCollection Convert(DailyPattern pattern, Occurrence defaultOccurrence)
        {
            Expression <Func <DateTime, DateTime> > predicate = previousDate => previousDate.AddDays(pattern.Interval);

            return(Convert(pattern, defaultOccurrence, predicate));
        }
示例#16
0
        public static void Main(string[] args)
        {
            var count = 10000;

            if (args.Length > 0 && args[0].Equals("-c"))
            {
                if (!int.TryParse(args[1], out count))
                {
                    Console.WriteLine("Invalid count number");
                    return;
                }
            }

            var sequentialCollisations = 0;
            var continueForever        = false;
            var random = new Random(342);

            var          patternGenerator = new DailyPatternGenerator();
            DailyPattern previous         = null;
            var          list1            = new List <DailyPattern>();
            var          list2            = new List <DailyPattern>();

            for (var i = 0; i < count; i++)
            {
                var minutes       = random.Next(-20, 240);
                var dailyPatterns = patternGenerator.GenerateDailyPatternList(DateTime.Now.AddMinutes(minutes).AddDays(i * 3), 10, 2, true);

                if (list1.Count > 0 && list1.Last().ColorId.Equals(dailyPatterns.First().ColorId))
                {
                    Console.WriteLine("Sequential collision");
                }

                list1.AddRange(dailyPatterns);
            }

            for (var i = 0; i < count; i++)
            {
                var minutes       = random.Next(-20, 180);
                var dailyPatterns = patternGenerator.GenerateDailyPatternList(DateTime.Now.AddMinutes(minutes).AddDays(i * 3), 10, 2, true);
                list2.AddRange(dailyPatterns);
            }

            if (list1.Count != list2.Count)
            {
                throw new Exception("List item count mismatch");
            }

            for (var i = 0; i < list1.Count; i++)
            {
                var d1 = list1[i];
                var d2 = list2[i];

                if (i == 0)
                {
                    previous = d1;
                }
                if (i != 0 && previous?.ColorId == d1.ColorId)
                {
                    Console.WriteLine($"Sequential collision, previous ColorId: {previous.ColorId}, current ColorId: {d1.ColorId} ");
                    sequentialCollisations++;
                }
                previous = d1;

                Console.WriteLine($"Color1: {d1.ColorId}, Color2: {d2.ColorId} | PatternId1: {d1.PatternId}, PatternId2: {d2.PatternId} | Valid to (1): {d1.ValidTo}, Valid to (2): {d2.ValidTo}");
                if (!d1.ColorId.Equals(d2.ColorId))
                {
                    throw new Exception("Inconsistent color generation");
                }
                if (!d1.PatternId.Equals(d2.PatternId))
                {
                    throw new Exception("Inconsistent pattern generation");
                }

                if (continueForever)
                {
                    continue;
                }

                var key = Console.ReadKey();
                if (key.KeyChar.Equals('q'))
                {
                    break;
                }
                if (key.KeyChar.Equals('c'))
                {
                    continueForever = true;
                }
                ;
            }

            Console.WriteLine($"Sequential Collisions: {sequentialCollisations} of total {list1.Count} items.");
            Console.ReadKey();
        }
示例#17
0
 public void PatternIsNotEqualToRandomObject()
 {
     var target = new DailyPattern();
     Assert.IsFalse(target.Equals(new object()));
 }
示例#18
0
 public void ReadXElement_Empty_ThrowsArgumentNullException()
 {
     DailyPattern pattern = new DailyPattern();
     XElement element = null;
     pattern.ReadXElement(element);
 }