Example #1
0
        protected bool Equals(Event other)
        {
            var resourcesSet = new HashSet <string>(StringComparer.OrdinalIgnoreCase);

            resourcesSet.UnionWith(Resources);

            var result = Equals(DtStart, other.DtStart) &&
                         string.Equals(Summary, other.Summary, StringComparison.OrdinalIgnoreCase) &&
                         string.Equals(Description, other.Description, StringComparison.OrdinalIgnoreCase) &&
                         Equals(DtEnd, other.DtEnd) &&
                         string.Equals(Location, other.Location, StringComparison.OrdinalIgnoreCase) &&
                         resourcesSet.SetEquals(other.Resources) &&
                         Status.Equals(other.Status) &&
                         IsActive() == other.IsActive() &&
                         Transparency.Equals(other.Transparency) &&
                         EvaluationIncludesReferenceDate == other.EvaluationIncludesReferenceDate &&
                         Attachments.SequenceEqual(other.Attachments) &&
                         CollectionHelpers.Equals(ExceptionRules, other.ExceptionRules) &&
                         CollectionHelpers.Equals(RecurrenceRules, other.RecurrenceRules);

            if (!result)
            {
                return(false);
            }

            //RDATEs and EXDATEs are all List<PeriodList>, because the spec allows for multiple declarations of collections.
            //Consequently we have to contrive a normalized representation before we can determine whether two events are equal

            var exDates      = PeriodList.GetGroupedPeriods(ExceptionDates);
            var otherExDates = PeriodList.GetGroupedPeriods(other.ExceptionDates);

            if (exDates.Keys.Count != otherExDates.Keys.Count || !exDates.Keys.OrderBy(k => k).SequenceEqual(otherExDates.Keys.OrderBy(k => k)))
            {
                return(false);
            }

            if (exDates.Any(exDate => !exDate.Value.OrderBy(d => d).SequenceEqual(otherExDates[exDate.Key].OrderBy(d => d))))
            {
                return(false);
            }

            var rDates      = PeriodList.GetGroupedPeriods(RecurrenceDates);
            var otherRDates = PeriodList.GetGroupedPeriods(other.RecurrenceDates);

            if (rDates.Keys.Count != otherRDates.Keys.Count || !rDates.Keys.OrderBy(k => k).SequenceEqual(otherRDates.Keys.OrderBy(k => k)))
            {
                return(false);
            }

            if (rDates.Any(exDate => !exDate.Value.OrderBy(d => d).SequenceEqual(otherRDates[exDate.Key].OrderBy(d => d))))
            {
                return(false);
            }

            return(true);
        }
Example #2
0
 protected bool Equals(Calendar other)
 {
     return(string.Equals(Name, other.Name, StringComparison.OrdinalIgnoreCase) &&
            CollectionHelpers.Equals(UniqueComponents, other.UniqueComponents) &&
            CollectionHelpers.Equals(Events, other.Events) &&
            CollectionHelpers.Equals(Todos, other.Todos) &&
            CollectionHelpers.Equals(Journals, other.Journals) &&
            CollectionHelpers.Equals(FreeBusy, other.FreeBusy) &&
            CollectionHelpers.Equals(TimeZones, other.TimeZones));
 }
Example #3
0
        protected bool Equals(RecurringComponent other)
        {
            var result = Equals(DtStart, other.DtStart) &&
                         Equals(Priority, other.Priority) &&
                         string.Equals(Summary, other.Summary, StringComparison.OrdinalIgnoreCase) &&
                         string.Equals(Class, other.Class, StringComparison.OrdinalIgnoreCase) &&
                         string.Equals(Description, other.Description, StringComparison.OrdinalIgnoreCase) &&
                         Equals(RecurrenceId, other.RecurrenceId) &&
                         Attachments.SequenceEqual(other.Attachments) &&
                         CollectionHelpers.Equals(Categories, other.Categories) &&
                         CollectionHelpers.Equals(Contacts, other.Contacts) &&
                         CollectionHelpers.Equals(ExceptionDates, other.ExceptionDates) &&
                         CollectionHelpers.Equals(ExceptionRules, other.ExceptionRules) &&
                         CollectionHelpers.Equals(RecurrenceDates, other.RecurrenceDates, orderSignificant: true) &&
                         CollectionHelpers.Equals(RecurrenceRules, other.RecurrenceRules, orderSignificant: true);

            return(result);
        }
Example #4
0
        protected bool Equals(CalendarEvent other)
        {
            var resourcesSet = new HashSet <string>(StringComparer.OrdinalIgnoreCase);

            resourcesSet.UnionWith(Resources);

            var result = Equals(DtStart, other.DtStart) &&
                         Equals(DtEnd, other.DtEnd) &&
                         string.Equals(Location, other.Location, StringComparison.OrdinalIgnoreCase) &&
                         resourcesSet.SetEquals(other.Resources) &&
                         Status.Equals(other.Status) &&
                         IsActive() == other.IsActive() &&
                         Transparency.Equals(other.Transparency) &&
                         EvaluationIncludesReferenceDate == other.EvaluationIncludesReferenceDate &&
                         Attachments.SequenceEqual(other.Attachments) &&
                         CollectionHelpers.Equals(ExceptionDates, other.ExceptionDates) &&
                         CollectionHelpers.Equals(ExceptionRules, other.ExceptionRules) &&
                         CollectionHelpers.Equals(RecurrenceRules, other.RecurrenceRules, true) &&
                         CollectionHelpers.Equals(RecurrenceDates, other.RecurrenceDates, true);

            return(result);
        }
Example #5
0
 protected bool Equals(PeriodList other)
 {
     return(string.Equals(TzId, other.TzId, StringComparison.OrdinalIgnoreCase) &&
            CollectionHelpers.Equals(Periods, other.Periods));
 }
Example #6
0
 protected bool Equals(CalendarCollection obj) => CollectionHelpers.Equals(this, obj);
Example #7
0
        public void PeriodListTests()
        {
            var startTimesA = new List <DateTime>
            {
                new DateTime(2017, 03, 02, 06, 00, 00),
                new DateTime(2017, 03, 03, 06, 00, 00),
                new DateTime(2017, 03, 06, 06, 00, 00),
                new DateTime(2017, 03, 07, 06, 00, 00),
                new DateTime(2017, 03, 08, 06, 00, 00),
                new DateTime(2017, 03, 09, 06, 00, 00),
                new DateTime(2017, 03, 10, 06, 00, 00),
                new DateTime(2017, 03, 13, 06, 00, 00),
                new DateTime(2017, 03, 14, 06, 00, 00),
                new DateTime(2017, 03, 17, 06, 00, 00),
                new DateTime(2017, 03, 20, 06, 00, 00),
                new DateTime(2017, 03, 21, 06, 00, 00),
                new DateTime(2017, 03, 22, 06, 00, 00),
                new DateTime(2017, 03, 23, 06, 00, 00),
                new DateTime(2017, 03, 24, 06, 00, 00),
                new DateTime(2017, 03, 27, 06, 00, 00),
                new DateTime(2017, 03, 28, 06, 00, 00),
                new DateTime(2017, 03, 29, 06, 00, 00),
                new DateTime(2017, 03, 30, 06, 00, 00),
                new DateTime(2017, 03, 31, 06, 00, 00),
                new DateTime(2017, 04, 03, 06, 00, 00),
                new DateTime(2017, 04, 05, 06, 00, 00),
                new DateTime(2017, 04, 06, 06, 00, 00),
                new DateTime(2017, 04, 07, 06, 00, 00),
                new DateTime(2017, 04, 10, 06, 00, 00),
                new DateTime(2017, 04, 11, 06, 00, 00),
                new DateTime(2017, 04, 12, 06, 00, 00),
                new DateTime(2017, 04, 13, 06, 00, 00),
                new DateTime(2017, 04, 17, 06, 00, 00),
                new DateTime(2017, 04, 18, 06, 00, 00),
                new DateTime(2017, 04, 19, 06, 00, 00),
                new DateTime(2017, 04, 20, 06, 00, 00),
                new DateTime(2017, 04, 21, 06, 00, 00),
                new DateTime(2017, 04, 24, 06, 00, 00),
                new DateTime(2017, 04, 25, 06, 00, 00),
                new DateTime(2017, 04, 27, 06, 00, 00),
                new DateTime(2017, 04, 28, 06, 00, 00),
                new DateTime(2017, 05, 01, 06, 00, 00),
            }
            .Select(dt => new Period(new CalDateTime(dt))).ToList();
            var a = new PeriodList();

            foreach (var period in startTimesA)
            {
                a.Add(period);
            }

            //Difference from A: first element became the second, and last element became the second-to-last element
            var startTimesB = new List <DateTime>
            {
                new DateTime(2017, 03, 03, 06, 00, 00),
                new DateTime(2017, 03, 02, 06, 00, 00),
                new DateTime(2017, 03, 06, 06, 00, 00),
                new DateTime(2017, 03, 07, 06, 00, 00),
                new DateTime(2017, 03, 08, 06, 00, 00),
                new DateTime(2017, 03, 09, 06, 00, 00),
                new DateTime(2017, 03, 10, 06, 00, 00),
                new DateTime(2017, 03, 13, 06, 00, 00),
                new DateTime(2017, 03, 14, 06, 00, 00),
                new DateTime(2017, 03, 17, 06, 00, 00),
                new DateTime(2017, 03, 20, 06, 00, 00),
                new DateTime(2017, 03, 21, 06, 00, 00),
                new DateTime(2017, 03, 22, 06, 00, 00),
                new DateTime(2017, 03, 23, 06, 00, 00),
                new DateTime(2017, 03, 24, 06, 00, 00),
                new DateTime(2017, 03, 27, 06, 00, 00),
                new DateTime(2017, 03, 28, 06, 00, 00),
                new DateTime(2017, 03, 29, 06, 00, 00),
                new DateTime(2017, 03, 30, 06, 00, 00),
                new DateTime(2017, 03, 31, 06, 00, 00),
                new DateTime(2017, 04, 03, 06, 00, 00),
                new DateTime(2017, 04, 05, 06, 00, 00),
                new DateTime(2017, 04, 06, 06, 00, 00),
                new DateTime(2017, 04, 07, 06, 00, 00),
                new DateTime(2017, 04, 10, 06, 00, 00),
                new DateTime(2017, 04, 11, 06, 00, 00),
                new DateTime(2017, 04, 12, 06, 00, 00),
                new DateTime(2017, 04, 13, 06, 00, 00),
                new DateTime(2017, 04, 17, 06, 00, 00),
                new DateTime(2017, 04, 18, 06, 00, 00),
                new DateTime(2017, 04, 19, 06, 00, 00),
                new DateTime(2017, 04, 20, 06, 00, 00),
                new DateTime(2017, 04, 21, 06, 00, 00),
                new DateTime(2017, 04, 24, 06, 00, 00),
                new DateTime(2017, 04, 25, 06, 00, 00),
                new DateTime(2017, 04, 27, 06, 00, 00),
                new DateTime(2017, 05, 01, 06, 00, 00),
                new DateTime(2017, 04, 28, 06, 00, 00),
            }
            .Select(dt => new Period(new CalDateTime(dt))).ToList();
            var b = new PeriodList();

            foreach (var period in startTimesB)
            {
                b.Add(period);
            }

            var collectionEqual = CollectionHelpers.Equals(a, b);

            Assert.AreEqual(true, collectionEqual);
            Assert.AreEqual(a.GetHashCode(), b.GetHashCode());

            var listOfListA = new List <IPeriodList> {
                a
            };
            var listOfListB = new List <IPeriodList> {
                b
            };

            Assert.IsTrue(CollectionHelpers.Equals(listOfListA, listOfListB));

            var aThenB = new List <IPeriodList> {
                a, b
            };
            var bThenA = new List <IPeriodList> {
                b, a
            };

            Assert.IsTrue(CollectionHelpers.Equals(aThenB, bThenA));
        }
Example #8
0
 protected bool Equals(PeriodList other)
 {
     return(string.Equals(TzId, other.TzId) && CollectionHelpers.Equals(Periods, other.Periods));
 }