diff --git a/Ical.Net.Tests/CalendarEventTest.cs b/Ical.Net.Tests/CalendarEventTest.cs index 61f5ade70..1076005bc 100644 --- a/Ical.Net.Tests/CalendarEventTest.cs +++ b/Ical.Net.Tests/CalendarEventTest.cs @@ -173,63 +173,6 @@ public static IEnumerable EnsureAutomaticallySetDtStampIsSerializedAsUtcKind_Tes .Returns(true); } - [Test] - public void EventWithExDateShouldNotBeEqualToSameEventWithoutExDate() - { - const string icalNoException = @"BEGIN:VCALENDAR -PRODID:-//Telerik Inc.//NONSGML RadScheduler//EN -VERSION:2.0 -CALSCALE:GREGORIAN -METHOD:PUBLISH -BEGIN:VTIMEZONE -TZID:UTC -BEGIN:STANDARD -TZNAME:UTC -TZOFFSETTO:+0000 -TZOFFSETFROM:+0000 -DTSTART:16010101T000000 -END:STANDARD -END:VTIMEZONE -BEGIN:VEVENT -DTSTART;TZID=UTC:20161020T170000 -DTEND;TZID=UTC:20161020T230000 -UID:694f818f-6d67-4307-9c4d-0b5211686ff0 -IMPORTANCE:None -RRULE:FREQ=DAILY -END:VEVENT -END:VCALENDAR"; - - const string icalWithException = @"BEGIN:VCALENDAR -PRODID:-//Telerik Inc.//NONSGML RadScheduler//EN -VERSION:2.0 -CALSCALE:GREGORIAN -METHOD:PUBLISH -BEGIN:VTIMEZONE -TZID:UTC -BEGIN:STANDARD -TZNAME:UTC -TZOFFSETTO:+0000 -TZOFFSETFROM:+0000 -DTSTART:16010101T000000 -END:STANDARD -END:VTIMEZONE -BEGIN:VEVENT -DTSTART;TZID=UTC:20161020T170000 -DTEND;TZID=UTC:20161020T230000 -UID:694f818f-6d67-4307-9c4d-0b5211686ff0 -IMPORTANCE:None -RRULE:FREQ=DAILY -EXDATE;TZID=UTC:20161020T170000 -END:VEVENT -END:VCALENDAR"; - - var noException = Calendar.Load(icalNoException).Events.First(); - var withException = Calendar.Load(icalWithException).Events.First(); - - Assert.That(withException, Is.Not.EqualTo(noException)); - Assert.That(withException.GetHashCode(), Is.Not.EqualTo(noException.GetHashCode())); - } - private static CalendarEvent GetSimpleEvent() => new CalendarEvent { DtStart = new CalDateTime(_now), @@ -237,169 +180,11 @@ public void EventWithExDateShouldNotBeEqualToSameEventWithoutExDate() Uid = _uid, }; - [Test] - public void RrulesAreSignificantTests() - { - var rrule = new RecurrencePattern(FrequencyType.Daily, 1); - var testRrule = GetSimpleEvent(); - testRrule.RecurrenceRules = new List { rrule }; - - var simpleEvent = GetSimpleEvent(); - Assert.That(testRrule, Is.Not.EqualTo(simpleEvent)); - Assert.That(testRrule.GetHashCode(), Is.Not.EqualTo(simpleEvent.GetHashCode())); - - var testRdate = GetSimpleEvent(); - testRdate.RecurrenceDatesPeriodLists = new List { new PeriodList { new Period(new CalDateTime(_now)) } }; - Assert.That(testRdate, Is.Not.EqualTo(simpleEvent)); - Assert.That(testRdate.GetHashCode(), Is.Not.EqualTo(simpleEvent.GetHashCode())); - } - private static List GetSimpleRecurrenceList() => new List { new RecurrencePattern(FrequencyType.Daily, 1) { Count = 5 } }; private static List GetExceptionDates() => new List { new CalDateTime(_now.AddDays(1).Date) }; - - [Test] - public void EventWithRecurrenceAndExceptionComparison() - { - var vEvent = GetSimpleEvent(); - vEvent.RecurrenceRules = GetSimpleRecurrenceList(); - vEvent.ExceptionDates.AddRange(GetExceptionDates()); - - var calendar = new Calendar(); - calendar.Events.Add(vEvent); - - var vEvent2 = GetSimpleEvent(); - vEvent2.RecurrenceRules = GetSimpleRecurrenceList(); - vEvent2.ExceptionDates.AddRange(GetExceptionDates()); - - var cal2 = new Calendar(); - cal2.Events.Add(vEvent2); - - var eventA = calendar.Events.First(); - var eventB = cal2.Events.First(); - - Assert.Multiple(() => - { - Assert.That(eventB.RecurrenceRules.First(), Is.EqualTo(eventA.RecurrenceRules.First())); - Assert.That(eventB.RecurrenceRules.First().GetHashCode(), Is.EqualTo(eventA.RecurrenceRules.First().GetHashCode())); - Assert.That(eventB.ExceptionDates.GetAllDates().First(), Is.EqualTo(eventA.ExceptionDates.GetAllDates().First())); - Assert.That(eventB.GetHashCode(), Is.EqualTo(eventA.GetHashCode())); - Assert.That(eventB, Is.EqualTo(eventA)); - Assert.That(cal2, Is.EqualTo(calendar)); - }); - } - - [Test] - public void AddingExdateToEventShouldNotBeEqualToOriginal() - { - //Create a calendar with an event with a recurrence rule - //Serialize to string, and deserialize - //Change the original calendar.Event to have an ExDate - //Serialize to string, and deserialize - //CalendarEvent and Calendar hash codes and equality should NOT be the same - var serializer = new CalendarSerializer(); - - var vEvent = GetSimpleEvent(); - vEvent.RecurrenceRules = GetSimpleRecurrenceList(); - var cal1 = new Calendar(); - cal1.Events.Add(vEvent); - var serialized = serializer.SerializeToString(cal1); - var deserializedNoExDate = Calendar.Load(serialized); - Assert.That(deserializedNoExDate, Is.EqualTo(cal1)); - - vEvent.ExceptionDates.AddRange(GetExceptionDates()); - serialized = serializer.SerializeToString(cal1); - var deserializedWithExDate = Calendar.Load(serialized); - - Assert.Multiple(() => - { - Assert.That(deserializedWithExDate.Events.First(), Is.Not.EqualTo(deserializedNoExDate.Events.First())); - Assert.That(deserializedWithExDate.Events.First().GetHashCode(), Is.Not.EqualTo(deserializedNoExDate.Events.First().GetHashCode())); - Assert.That(deserializedWithExDate, Is.Not.EqualTo(deserializedNoExDate)); - }); - } - - [Test] - public void ChangingRrulesShouldNotBeEqualToOriginalEvent() - { - var eventA = GetSimpleEvent(); - eventA.RecurrenceRules = GetSimpleRecurrenceList(); - - var eventB = GetSimpleEvent(); - eventB.RecurrenceRules = GetSimpleRecurrenceList(); - Assert.Multiple(() => - { - Assert.That(ReferenceEquals(eventA, eventB), Is.False); - Assert.That(eventB, Is.EqualTo(eventA)); - }); - - var foreverDailyRule = new RecurrencePattern(FrequencyType.Daily, 1); - eventB.RecurrenceRules = new List { foreverDailyRule }; - - Assert.That(eventB, Is.Not.EqualTo(eventA)); - Assert.That(eventB.GetHashCode(), Is.Not.EqualTo(eventA.GetHashCode())); - } - - [Test] - public void EventsDifferingByDtStampAreEqual() - { - const string eventA = @"BEGIN:VCALENDAR -PRODID:-//github.com/rianjs/ical.net//NONSGML ical.net 2.2//EN -VERSION:2.0 -BEGIN:VEVENT -ATTACH;FMTTYPE=application/json;VALUE=BINARY;ENCODING=BASE64:eyJzdWJqZWN0I - joiSFAgQ29hdGVyIGFuZCBDdXR0ZXIgQ2xlYW51cCIsInVuaXF1ZUlkZW50aWZpZXIiOiIwND - EwNzI1NGRjNWM5MDk0YWY3MWEwZTE5N2U2NWE1NTdkZmJjYjg0IiwiaWNhbFN0cmluZyI6IiI - sImxhYm9yRG93bnRpbWVzIjpbXSwiZGlzYWJsZWRFcXVpcG1lbnQiOlt7ImRpc2FibGVkRXF1 - aXBtZW50SW5zdGFuY2VOYW1lcyI6WyJEaWdpdGFsIFByaW50XFxIUCAyOCIsIkRpZ2l0YWwgU - HJpbnRcXEhQIDQ0Il0sImZ1bGxUaW1lRXF1aXZhbGVudHNDb3VudCI6MC4wfV0sIm1vZGVzTm - 90QWxsb3dlZCI6W10sInJhd01hdGVyaWFsc05vdEFsbG93ZWQiOltdLCJsYWJvckFsbG9jYXR - pb25zIjpbXX0= -DTEND;TZID=UTC:20150615T055000 -DTSTAMP:20161011T195316Z -DTSTART;TZID=UTC:20150615T054000 -EXDATE;TZID=UTC:20151023T054000 -IMPORTANCE:None -RRULE:FREQ=WEEKLY;BYDAY=MO,TU,WE,TH,FR,SA -UID:04107254dc5c9094af71a0e197e65a557dfbcb84 -END:VEVENT -END:VCALENDAR"; - - const string eventB = @"BEGIN:VCALENDAR -PRODID:-//github.com/rianjs/ical.net//NONSGML ical.net 2.2//EN -VERSION:2.0 -BEGIN:VEVENT -ATTACH;FMTTYPE=application/json;VALUE=BINARY;ENCODING=BASE64:eyJzdWJqZWN0I - joiSFAgQ29hdGVyIGFuZCBDdXR0ZXIgQ2xlYW51cCIsInVuaXF1ZUlkZW50aWZpZXIiOiIwND - EwNzI1NGRjNWM5MDk0YWY3MWEwZTE5N2U2NWE1NTdkZmJjYjg0IiwiaWNhbFN0cmluZyI6IiI - sImxhYm9yRG93bnRpbWVzIjpbXSwiZGlzYWJsZWRFcXVpcG1lbnQiOlt7ImRpc2FibGVkRXF1 - aXBtZW50SW5zdGFuY2VOYW1lcyI6WyJEaWdpdGFsIFByaW50XFxIUCAyOCIsIkRpZ2l0YWwgU - HJpbnRcXEhQIDQ0Il0sImZ1bGxUaW1lRXF1aXZhbGVudHNDb3VudCI6MC4wfV0sIm1vZGVzTm - 90QWxsb3dlZCI6W10sInJhd01hdGVyaWFsc05vdEFsbG93ZWQiOltdLCJsYWJvckFsbG9jYXR - pb25zIjpbXX0= -DTEND;TZID=UTC:20150615T055000 -DTSTAMP:20161024T201419Z -DTSTART;TZID=UTC:20150615T054000 -EXDATE;TZID=UTC:20151023T054000 -IMPORTANCE:None -RRULE:FREQ=WEEKLY;BYDAY=MO,TU,WE,TH,FR,SA -UID:04107254dc5c9094af71a0e197e65a557dfbcb84 -END:VEVENT -END:VCALENDAR"; - - var calendarA = Calendar.Load(eventA); - var calendarB = Calendar.Load(eventB); - - Assert.Multiple(() => - { - Assert.That(calendarB.Events.First().GetHashCode(), Is.EqualTo(calendarA.Events.First().GetHashCode())); - Assert.That(calendarB.Events.First(), Is.EqualTo(calendarA.Events.First())); - Assert.That(calendarB.GetHashCode(), Is.EqualTo(calendarA.GetHashCode())); - Assert.That(calendarB, Is.EqualTo(calendarA)); - }); - } - + [Test] public void EventResourcesCanBeZeroedOut() { diff --git a/Ical.Net.Tests/CopyComponentTests.cs b/Ical.Net.Tests/CopyComponentTests.cs index 1be5799fd..71fc42fad 100644 --- a/Ical.Net.Tests/CopyComponentTests.cs +++ b/Ical.Net.Tests/CopyComponentTests.cs @@ -20,39 +20,6 @@ namespace Ical.Net.Tests; [TestFixture] public class CopyComponentTests { - [Test, TestCaseSource(nameof(CopyCalendarTest_TestCases)), Category("Copy tests")] - public void CopyCalendarTest(string calendarString) - { - var iCal1 = Calendar.Load(calendarString)!; - var iCal2 = iCal1.Copy(); - SerializationTests.CompareCalendars(iCal1, iCal2); - } - - public static IEnumerable CopyCalendarTest_TestCases() - { - yield return new TestCaseData(IcsFiles.Attachment3).SetName("Attachment3"); - yield return new TestCaseData(IcsFiles.Bug2148092).SetName("Bug2148092"); - yield return new TestCaseData(IcsFiles.CaseInsensitive1).SetName("CaseInsensitive1"); - yield return new TestCaseData(IcsFiles.CaseInsensitive2).SetName("CaseInsensitive2"); - yield return new TestCaseData(IcsFiles.CaseInsensitive3).SetName("CaseInsensitive3"); - yield return new TestCaseData(IcsFiles.Categories1).SetName("Categories1"); - yield return new TestCaseData(IcsFiles.Duration1).SetName("Duration1"); - yield return new TestCaseData(IcsFiles.Encoding1).SetName("Encoding1"); - yield return new TestCaseData(IcsFiles.Event1).SetName("Event1"); - yield return new TestCaseData(IcsFiles.Event2).SetName("Event2"); - yield return new TestCaseData(IcsFiles.Event3).SetName("Event3"); - yield return new TestCaseData(IcsFiles.Event4).SetName("Event4"); - yield return new TestCaseData(IcsFiles.GeographicLocation1).SetName("GeographicLocation1"); - yield return new TestCaseData(IcsFiles.Language1).SetName("Language1"); - yield return new TestCaseData(IcsFiles.Language2).SetName("Language2"); - yield return new TestCaseData(IcsFiles.Language3).SetName("Language3"); - yield return new TestCaseData(IcsFiles.TimeZone1).SetName("TimeZone1"); - yield return new TestCaseData(IcsFiles.TimeZone2).SetName("TimeZone2"); - yield return new TestCaseData(IcsFiles.TimeZone3).SetName("TimeZone3"); - yield return new TestCaseData(IcsFiles.XProperty1).SetName("XProperty1"); - yield return new TestCaseData(IcsFiles.XProperty2).SetName("XProperty2"); - } - private static readonly DateTime _now = DateTime.SpecifyKind(DateTime.Now, DateTimeKind.Unspecified); private static readonly DateTime _later = _now.AddHours(1); @@ -95,7 +62,6 @@ public void CopyCalendarEventTest() Assert.That(copy.Resources[0], Is.Not.EqualTo(orig.Resources[0])); Assert.That(resourcesCopyFromOrig, Is.EquivalentTo(orig.Resources)); - Assert.That(copy.GeographicLocation, Is.EqualTo(orig.GeographicLocation)); Assert.That(copy.Transparency, Is.EqualTo(orig.Transparency)); Assert.That(Regex.Matches(serializedOrig, uidPattern, RegexOptions.Compiled, TimeSpan.FromSeconds(100)), Has.Count.EqualTo(1)); @@ -142,7 +108,7 @@ public void CopyAlarmTest() Assert.Multiple(() => { Assert.That(copy.Action, Is.EqualTo(orig.Action)); - Assert.That(copy.Trigger, Is.EqualTo(orig.Trigger)); + Assert.That(copy.Trigger?.DateTime, Is.EqualTo(orig.Trigger.DateTime)); Assert.That(copy.Description, Is.EqualTo(orig.Description)); }); } diff --git a/Ical.Net.Tests/EqualityAndHashingTests.cs b/Ical.Net.Tests/EqualityAndHashingTests.cs index f379e3b48..99f5971c3 100644 --- a/Ical.Net.Tests/EqualityAndHashingTests.cs +++ b/Ical.Net.Tests/EqualityAndHashingTests.cs @@ -44,33 +44,6 @@ public static IEnumerable CalDateTime_TestCases() yield return new TestCaseData(nowCalDtWithTz, new CalDateTime(_nowTime, TzId)).SetName("Now, with time zone"); } - [Test] - public void RecurrencePatternTests() - { - var patternA = GetSimpleRecurrencePattern(); - var patternB = GetSimpleRecurrencePattern(); - - Assert.That(patternB, Is.EqualTo(patternA)); - Assert.That(patternB.GetHashCode(), Is.EqualTo(patternA.GetHashCode())); - } - - [Test, TestCaseSource(nameof(Event_TestCases))] - public void Event_Tests(CalendarEvent incoming, CalendarEvent expected) - { - Assert.Multiple(() => - { - Assert.That(expected.DtStart, Is.EqualTo(incoming.DtStart)); - Assert.That(expected.DtEnd, Is.EqualTo(incoming.DtEnd)); - Assert.That(expected.Location, Is.EqualTo(incoming.Location)); - Assert.That(expected.Status, Is.EqualTo(incoming.Status)); - Assert.That(expected.IsActive, Is.EqualTo(incoming.IsActive)); - Assert.That(expected.Duration, Is.EqualTo(incoming.Duration)); - Assert.That(expected.Transparency, Is.EqualTo(incoming.Transparency)); - Assert.That(expected.GetHashCode(), Is.EqualTo(incoming.GetHashCode())); - Assert.That(incoming.Equals(expected), Is.True); - }); - } - private static RecurrencePattern GetSimpleRecurrencePattern() => new RecurrencePattern(FrequencyType.Daily, 1) { Count = 5 @@ -84,168 +57,6 @@ public void Event_Tests(CalendarEvent incoming, CalendarEvent expected) private static string SerializeEvent(CalendarEvent e) => new CalendarSerializer().SerializeToString(new Calendar { Events = { e } }); - - public static IEnumerable Event_TestCases() - { - var outgoing = GetSimpleEvent(); - var expected = GetSimpleEvent(); - yield return new TestCaseData(outgoing, expected).SetName("Events with start, end, and duration"); - - var fiveA = GetSimpleRecurrencePattern(); - var fiveB = GetSimpleRecurrencePattern(); - - outgoing = GetSimpleEvent(); - expected = GetSimpleEvent(); - outgoing.RecurrenceRules = new List { fiveA }; - expected.RecurrenceRules = new List { fiveB }; - yield return new TestCaseData(outgoing, expected).SetName("Events with start, end, duration, and one recurrence rule"); - } - - [Test] - public void Calendar_Tests() - { - var rruleA = new RecurrencePattern(FrequencyType.Daily, 1) - { - Count = 5 - }; - - var e = new CalendarEvent - { - DtStart = new CalDateTime(_nowTime), - Duration = Duration.FromHours(1), - RecurrenceRules = new List { rruleA }, - }; - - var actualCalendar = new Calendar(); - actualCalendar.Events.Add(e); - - //Work around referential equality... - var rruleB = new RecurrencePattern(FrequencyType.Daily, 1) - { - Count = 5 - }; - - var expectedCalendar = new Calendar(); - expectedCalendar.Events.Add(new CalendarEvent - { - DtStart = new CalDateTime(_nowTime), - Duration = Duration.FromHours(1), - RecurrenceRules = new List { rruleB }, - }); - - Assert.Multiple(() => - { - Assert.That(expectedCalendar.GetHashCode(), Is.EqualTo(actualCalendar.GetHashCode())); - Assert.That(actualCalendar.Equals(expectedCalendar), Is.True); - }); - } - - [Test, TestCaseSource(nameof(VTimeZone_TestCases))] - public void VTimeZone_Tests(VTimeZone actual, VTimeZone expected) - { - Assert.Multiple(() => - { - Assert.That(expected.Url, Is.EqualTo(actual.Url)); - Assert.That(expected.TzId, Is.EqualTo(actual.TzId)); - Assert.That(expected, Is.EqualTo(actual)); - Assert.That(expected.GetHashCode(), Is.EqualTo(actual.GetHashCode())); - }); - } - - public static IEnumerable VTimeZone_TestCases() - { - const string nzSt = "New Zealand Standard Time"; - var first = new VTimeZone - { - TzId = nzSt, - }; - var second = new VTimeZone(nzSt); - yield return new TestCaseData(first, second); - - first.Url = new Uri("http://example.com/"); - second.Url = new Uri("http://example.com"); - yield return new TestCaseData(first, second); - } - - [Test, TestCaseSource(nameof(Attendees_TestCases))] - public void Attendees_Tests(Attendee actual, Attendee expected) - { - Assert.Multiple(() => - { - Assert.That(actual.GetHashCode(), Is.EqualTo(expected.GetHashCode())); - Assert.That(actual, Is.EqualTo(expected)); - }); - } - - public static IEnumerable Attendees_TestCases() - { - var tentative1 = new Attendee("MAILTO:james@example.com") - { - CommonName = "James Tentative", - Role = ParticipationRole.RequiredParticipant, - Rsvp = true, - ParticipationStatus = EventParticipationStatus.Tentative - }; - var tentative2 = new Attendee("MAILTO:james@example.com") - { - CommonName = "James Tentative", - Role = ParticipationRole.RequiredParticipant, - Rsvp = true, - ParticipationStatus = EventParticipationStatus.Tentative - }; - yield return new TestCaseData(tentative1, tentative2).SetName("Simple attendee test case"); - - var complex1 = new Attendee("MAILTO:mary@example.com") - { - CommonName = "Mary Accepted", - Rsvp = true, - ParticipationStatus = EventParticipationStatus.Accepted, - SentBy = new Uri("mailto:someone@example.com"), - DirectoryEntry = new Uri("ldap://example.com:6666/o=eDABC Industries,c=3DUS??(cn=3DBMary Accepted)"), - Type = "CuType", - Members = new List { "Group A", "Group B" }, - Role = ParticipationRole.Chair, - DelegatedTo = new List { "Peon A", "Peon B" }, - DelegatedFrom = new List { "Bigwig A", "Bigwig B" } - }; - var complex2 = new Attendee("MAILTO:mary@example.com") - { - CommonName = "Mary Accepted", - Rsvp = true, - ParticipationStatus = EventParticipationStatus.Accepted, - SentBy = new Uri("mailto:someone@example.com"), - DirectoryEntry = new Uri("ldap://example.com:6666/o=eDABC Industries,c=3DUS??(cn=3DBMary Accepted)"), - Type = "CuType", - Members = new List { "Group A", "Group B" }, - Role = ParticipationRole.Chair, - DelegatedTo = new List { "Peon A", "Peon B" }, - DelegatedFrom = new List { "Bigwig A", "Bigwig B" } - }; - yield return new TestCaseData(complex1, complex2).SetName("Complex attendee test"); - } - - [Test, TestCaseSource(nameof(CalendarCollection_TestCases))] - public void CalendarCollection_Tests(string rawCalendar) - { - var a = Calendar.Load(IcsFiles.UsHolidays); - var b = Calendar.Load(IcsFiles.UsHolidays); - - Assert.That(a, Is.Not.Null); - Assert.That(b, Is.Not.Null); - Assert.Multiple(() => - { - Assert.That(b.GetHashCode(), Is.EqualTo(a.GetHashCode())); - Assert.That(b, Is.EqualTo(a)); - }); - } - - public static IEnumerable CalendarCollection_TestCases() - { - yield return new TestCaseData(IcsFiles.Google1).SetName("Google calendar test case"); - yield return new TestCaseData(IcsFiles.Parse1).SetName("Weird file parse test case"); - yield return new TestCaseData(IcsFiles.UsHolidays).SetName("US Holidays (quite large)"); - } - [Test] public void Resources_Tests() { @@ -290,40 +101,6 @@ private static (byte[] original, byte[] copy) GetAttachments() return (payload, payloadCopy); } - [Test, TestCaseSource(nameof(RecurringComponentAttachment_TestCases))] - public void RecurringComponentAttachmentTests(RecurringComponent noAttachment, RecurringComponent withAttachment) - { - var attachments = GetAttachments(); - - Assert.That(withAttachment, Is.Not.EqualTo(noAttachment)); - Assert.That(withAttachment.GetHashCode(), Is.Not.EqualTo(noAttachment.GetHashCode())); - - noAttachment.Attachments.Add(new Attachment(attachments.copy)); - - Assert.That(withAttachment, Is.EqualTo(noAttachment)); - Assert.That(withAttachment.GetHashCode(), Is.EqualTo(noAttachment.GetHashCode())); - } - - public static IEnumerable RecurringComponentAttachment_TestCases() - { - var attachments = GetAttachments(); - - var journalNoAttach = new Journal { Start = new CalDateTime(_nowTime), Summary = "A summary!", Class = "Some class!" }; - var journalWithAttach = new Journal { Start = new CalDateTime(_nowTime), Summary = "A summary!", Class = "Some class!" }; - journalWithAttach.Attachments.Add(new Attachment(attachments.original)); - yield return new TestCaseData(journalNoAttach, journalWithAttach).SetName("Journal recurring component attachment"); - - var todoNoAttach = new Todo { Start = new CalDateTime(_nowTime), Summary = "A summary!", Class = "Some class!" }; - var todoWithAttach = new Todo { Start = new CalDateTime(_nowTime), Summary = "A summary!", Class = "Some class!" }; - todoWithAttach.Attachments.Add(new Attachment(attachments.original)); - yield return new TestCaseData(todoNoAttach, todoWithAttach).SetName("Todo recurring component attachment"); - - var eventNoAttach = GetSimpleEvent(); - var eventWithAttach = GetSimpleEvent(); - eventWithAttach.Attachments.Add(new Attachment(attachments.original)); - yield return new TestCaseData(eventNoAttach, eventWithAttach).SetName("Event recurring component attachment"); - } - [Test, TestCaseSource(nameof(PeriodTestCases))] public void PeriodTests(Period a, Period b) { @@ -380,17 +157,12 @@ public void PeriodListTests() var collectionEqual = CollectionHelpers.Equals(a, b); - var listOfListA = new List { a }; - var listOfListB = new List { b }; - var aThenB = new List { a, b }; var bThenA = new List { b, a }; Assert.Multiple(() => { Assert.That(collectionEqual, Is.EqualTo(true)); - Assert.That(b.GetHashCode(), Is.EqualTo(a.GetHashCode())); - Assert.That(CollectionHelpers.Equals(listOfListA, listOfListB), Is.True); Assert.That(CollectionHelpers.Equals(aThenB, bThenA), Is.True); }); } diff --git a/Ical.Net.Tests/GetOccurrenceTests.cs b/Ical.Net.Tests/GetOccurrenceTests.cs index 62b4f3c9f..95c6e52b9 100644 --- a/Ical.Net.Tests/GetOccurrenceTests.cs +++ b/Ical.Net.Tests/GetOccurrenceTests.cs @@ -284,28 +284,4 @@ public void GetOccurrencesWithRecurrenceId_DateOnly_ShouldEnumerate() Assert.That(occurrences2.Select(x => x.Period.StartTime), Is.EqualTo(expectedStartDates.Take(3))); }); } - - [TestCase] - public void TestOccurenceEquals() - { - var occurrence = new Occurrence(new CalendarEvent() { Description = "o1" }, new Period(new CalDateTime(2023, 10, 1), new CalDateTime(2023, 10, 2))); - - Assert.Multiple(() => - { - Assert.That(occurrence.Equals((object)new Occurrence( - new CalendarEvent() { Description = "o1" }, new Period(new CalDateTime(2023, 10, 1), new CalDateTime(2023, 10, 2)))), - Is.True); - - Assert.That(occurrence.Equals((object)new Occurrence( - new CalendarEvent() { Description = "different" }, new Period(new CalDateTime(2023, 10, 1), new CalDateTime(2023, 10, 2)))), - Is.False); - - Assert.That(occurrence.Equals((object)new Occurrence( - new CalendarEvent() { Description = "o1" }, new Period(new CalDateTime(2000, 10, 1), new CalDateTime(2023, 10, 2)))), - Is.False); - - Assert.That(occurrence.Equals((object)null), - Is.False); - }); - } } diff --git a/Ical.Net.Tests/RecurrenceTests.cs b/Ical.Net.Tests/RecurrenceTests.cs index 8cb4b1725..bf53a0c7a 100644 --- a/Ical.Net.Tests/RecurrenceTests.cs +++ b/Ical.Net.Tests/RecurrenceTests.cs @@ -3510,8 +3510,6 @@ public void RecurrenceRuleTests() eventB.RecurrenceRules.Add(ten); eventB.RecurrenceRules.Add(five); - Assert.That(eventB, Is.EqualTo(eventA)); - const string aString = """ BEGIN:VCALENDAR @@ -3582,84 +3580,6 @@ public void RecurrenceRuleTests() Assert.That(newEventList, Has.Count.EqualTo(1)); } - [Test] - public void ManyExclusionDatesEqualityTesting() - { - const string icalA = - """ - BEGIN:VCALENDAR - PRODID:-//github.com/rianjs/ical.net//NONSGML ical.net 2.2//EN - VERSION:2.0 - BEGIN:VEVENT - DTEND;TZID=UTC:20170228T140000 - DTSTAMP;TZID=UTC:20170428T145334 - DTSTART;TZID=UTC:20170228T060000 - EXDATE;TZID=UTC:20170302T060000,20170303T060000,20170306T060000,20170307T0 - 60000,20170308T060000,20170309T060000,20170310T060000,20170313T060000,201 - 70314T060000,20170317T060000,20170320T060000,20170321T060000,20170322T060 - 000,20170323T060000,20170324T060000,20170327T060000,20170328T060000,20170 - 329T060000,20170330T060000,20170331T060000,20170403T060000,20170405T06000 - 0,20170406T060000,20170407T060000,20170410T060000,20170411T060000,2017041 - 2T060000,20170413T060000,20170417T060000,20170418T060000,20170419T060000, - 20170420T060000,20170421T060000,20170424T060000,20170425T060000,20170427T - 060000,20170428T060000,20170501T060000 - IMPORTANCE:None - RRULE:FREQ=WEEKLY;BYDAY=MO,TU,WE,TH,FR - UID:001b7e43-98df-4fcc-b9ec-345a28a4fc14 - END:VEVENT - END:VCALENDAR - """; - - const string icalB = - """ - BEGIN:VCALENDAR - PRODID:-//github.com/rianjs/ical.net//NONSGML ical.net 2.2//EN - VERSION:2.0 - BEGIN:VEVENT - DTEND;TZID=UTC:20170228T140000 - DTSTAMP;TZID=UTC:20170501T131355 - DTSTART;TZID=UTC:20170228T060000 - EXDATE;TZID=UTC:20170302T060000,20170303T060000,20170306T060000,20170307T0 - 60000,20170308T060000,20170309T060000,20170310T060000,20170313T060000,201 - 70314T060000,20170317T060000,20170320T060000,20170321T060000,20170322T060 - 000,20170323T060000,20170324T060000,20170327T060000,20170328T060000,20170 - 329T060000,20170330T060000,20170331T060000,20170403T060000,20170405T06000 - 0,20170406T060000,20170407T060000,20170410T060000,20170411T060000,2017041 - 2T060000,20170413T060000,20170417T060000,20170418T060000,20170419T060000, - 20170420T060000,20170421T060000,20170424T060000,20170425T060000,20170427T - 060000,20170428T060000,20170501T060000 - IMPORTANCE:None - RRULE:FREQ=WEEKLY;BYDAY=MO,TU,WE,TH,FR - UID:001b7e43-98df-4fcc-b9ec-345a28a4fc14 - END:VEVENT - END:VCALENDAR - """; - - // The only textual difference between A and B - // is a different DTSTAMP, which is not considered significant for equality or hashing - - var collectionA = CalendarCollection.Load(icalA); - var collectionB = CalendarCollection.Load(icalB); - var calendarA = collectionA.First(); - var calendarB = collectionB.First(); - var eventA = calendarA.Events.First(); - var eventB = calendarB.Events.First(); - var exDatesA = eventA.ExceptionDates.GetAllDates(); - var exDatesB = eventB.ExceptionDates.GetAllDates(); - - Assert.Multiple(() => - { - //Comparing the two... - Assert.That(collectionB, Is.EqualTo(collectionA)); - Assert.That(collectionB.GetHashCode(), Is.EqualTo(collectionA.GetHashCode())); - Assert.That(calendarB, Is.EqualTo(calendarA)); - Assert.That(calendarB.GetHashCode(), Is.EqualTo(calendarA.GetHashCode())); - Assert.That(eventB, Is.EqualTo(eventA)); - Assert.That(eventB.GetHashCode(), Is.EqualTo(eventA.GetHashCode())); - Assert.That(exDatesB, Is.EqualTo(exDatesA)); - }); - } - [TestCase(null, false)] [TestCase(CalDateTime.UtcTzId, false)] [TestCase("America/New_York", true)] diff --git a/Ical.Net.Tests/SerializationTests.cs b/Ical.Net.Tests/SerializationTests.cs index 80e92cedc..5919b5a54 100644 --- a/Ical.Net.Tests/SerializationTests.cs +++ b/Ical.Net.Tests/SerializationTests.cs @@ -30,23 +30,6 @@ public class SerializationTests private static CalendarEvent GetSimpleEvent() => new CalendarEvent { DtStart = new CalDateTime(_nowTime), Duration = (_later.Value - _nowTime.Value).ToDurationExact() }; private static Calendar DeserializeCalendar(string s) => Calendar.Load(s); - internal static void CompareCalendars(Calendar cal1, Calendar cal2) - { - CompareComponents(cal1, cal2); - - Assert.That(cal2.Children, Has.Count.EqualTo(cal1.Children.Count), "Children count is different between calendars."); - - for (var i = 0; i < cal1.Children.Count; i++) - { - var component1 = cal1.Children[i] as ICalendarComponent; - var component2 = cal2.Children[i] as ICalendarComponent; - if (component1 != null && component2 != null) - { - CompareComponents(component1, component2); - } - } - } - internal static void CompareComponents(ICalendarComponent cb1, ICalendarComponent cb2) { foreach (var p1 in cb1.Properties) @@ -210,37 +193,6 @@ public void SerializeDeserialize_CalendarWithVTimezone() }); } - [Test, Category("Serialization")] - public void SerializeDeserialize() - { - var cal1 = new Calendar - { - Method = "PUBLISH", - Version = "2.0" - }; - - var evt = new CalendarEvent - { - Class = "PRIVATE", - Created = new CalDateTime(2010, 3, 25, 12, 53, 35), - DtStamp = new CalDateTime(2010, 3, 25, 12, 53, 35), - LastModified = new CalDateTime(2010, 3, 27, 13, 53, 35), - Sequence = 0, - Uid = "42f58d4f-847e-46f8-9f4a-ce52697682cf", - Priority = 5, - Location = "here", - Summary = "test", - DtStart = new CalDateTime(2012, 3, 25, 12, 50, 00), - DtEnd = new CalDateTime(2012, 3, 25, 13, 10, 00) - }; - cal1.Events.Add(evt); - - var serializer = new CalendarSerializer(); - var serializedCalendar = serializer.SerializeToString(cal1)!; - var cal2 = Calendar.Load(serializedCalendar); - CompareCalendars(cal1, cal2); - } - [Test, Category("Serialization")] public void EventPropertiesSerialized() { diff --git a/Ical.Net.Tests/SymmetricSerializationTests.cs b/Ical.Net.Tests/SymmetricSerializationTests.cs index eb0ddd54b..336c9635e 100644 --- a/Ical.Net.Tests/SymmetricSerializationTests.cs +++ b/Ical.Net.Tests/SymmetricSerializationTests.cs @@ -38,55 +38,7 @@ private static CalendarEvent GetSimpleEvent(bool useDtEnd = true) } private static Calendar UnserializeCalendar(string s) => Calendar.Load(s); - - [Test, TestCaseSource(nameof(Event_TestCases))] - public void Event_Tests(Calendar iCalendar) - { - var originalEvent = iCalendar.Events.Single(); - - var serializedCalendar = SerializeToString(iCalendar); - var unserializedCalendar = UnserializeCalendar(serializedCalendar); - - var onlyEvent = unserializedCalendar.Events.Single(); - - Assert.Multiple(() => - { - Assert.That(onlyEvent.GetHashCode(), Is.EqualTo(originalEvent.GetHashCode())); - Assert.That(onlyEvent, Is.EqualTo(originalEvent)); - Assert.That(unserializedCalendar, Is.EqualTo(iCalendar)); - }); - } - - public static IEnumerable Event_TestCases() - { - return Event_TestCasesInt(true).Concat(Event_TestCasesInt(false)); - } - - private static IEnumerable Event_TestCasesInt(bool useDtEnd) - { - var rrule = new RecurrencePattern(FrequencyType.Daily, 1) { Count = 5 }; - var e = new CalendarEvent - { - DtStart = new CalDateTime(_nowTime), - RecurrenceRules = new List { rrule }, - }; - - if (useDtEnd) - e.DtEnd = new CalDateTime(_later); - else - e.Duration = (_later - _nowTime).ToDurationExact(); - - var calendar = new Calendar(); - calendar.Events.Add(e); - yield return new TestCaseData(calendar).SetName($"readme.md example with {(useDtEnd ? "DTEND" : "DURATION")}"); - - e = GetSimpleEvent(useDtEnd); - e.Description = "This is an event description that is really rather long. Hopefully the line breaks work now, and it's serialized properly."; - calendar = new Calendar(); - calendar.Events.Add(e); - yield return new TestCaseData(calendar).SetName($"Description serialization isn't working properly. Issue #60 {(useDtEnd ? "DTEND" : "DURATION")}"); - } - + [Test] public void VTimeZoneSerialization_Test() { @@ -178,8 +130,6 @@ public void BinaryAttachment_Tests(string theString, string expectedAttachment) Assert.Multiple(() => { Assert.That(unserializedAttachment, Is.EqualTo(expectedAttachment)); - Assert.That(unserialized.GetHashCode(), Is.EqualTo(calendar.GetHashCode())); - Assert.That(unserialized, Is.EqualTo(calendar)); }); } diff --git a/Ical.Net/Calendar.cs b/Ical.Net/Calendar.cs index 3a149eed2..69dac7837 100644 --- a/Ical.Net/Calendar.cs +++ b/Ical.Net/Calendar.cs @@ -94,43 +94,6 @@ protected override void OnDeserializing(StreamingContext context) Initialize(); } - protected bool Equals(Calendar other) - => 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); - - public override bool Equals(object? obj) - { - if (ReferenceEquals(null, obj)) - { - return false; - } - if (ReferenceEquals(this, obj)) - { - return true; - } - return obj.GetType() == GetType() && Equals((Calendar) obj); - } - - public override int GetHashCode() - { - unchecked - { - var hashCode = Name.GetHashCode(); - hashCode = (hashCode * 397) ^ CollectionHelpers.GetHashCode(UniqueComponents); - hashCode = (hashCode * 397) ^ CollectionHelpers.GetHashCode(Events); - hashCode = (hashCode * 397) ^ CollectionHelpers.GetHashCode(Todos); - hashCode = (hashCode * 397) ^ CollectionHelpers.GetHashCode(Journals); - hashCode = (hashCode * 397) ^ CollectionHelpers.GetHashCode(FreeBusy); - hashCode = (hashCode * 397) ^ CollectionHelpers.GetHashCode(TimeZones); - return hashCode; - } - } - public virtual IUniqueComponentList UniqueComponents => _mUniqueComponents; public virtual IEnumerable RecurringItems => Children.OfType(); diff --git a/Ical.Net/CalendarCollection.cs b/Ical.Net/CalendarCollection.cs index ea6648b19..f3304fc3d 100644 --- a/Ical.Net/CalendarCollection.cs +++ b/Ical.Net/CalendarCollection.cs @@ -85,15 +85,4 @@ private FreeBusy CombineFreeBusy(FreeBusy? main, FreeBusy current) return current is null || freeBusy is null ? freeBusy : CombineFreeBusy(current, freeBusy); }); } - - public override int GetHashCode() => CollectionHelpers.GetHashCode(this); - - protected bool Equals(CalendarCollection obj) => CollectionHelpers.Equals(this, obj); - - public override bool Equals(object? obj) - { - if (ReferenceEquals(null, obj)) return false; - if (ReferenceEquals(this, obj)) return true; - return obj.GetType() == GetType() && Equals((CalendarEvent) obj); - } } diff --git a/Ical.Net/CalendarComponents/CalendarEvent.cs b/Ical.Net/CalendarComponents/CalendarEvent.cs index ba4bdcdde..99f48589a 100644 --- a/Ical.Net/CalendarComponents/CalendarEvent.cs +++ b/Ical.Net/CalendarComponents/CalendarEvent.cs @@ -307,38 +307,6 @@ protected bool Equals(CalendarEvent? other) return true; } - /// - public override bool Equals(object? obj) - { - if (ReferenceEquals(null, obj)) return false; - if (ReferenceEquals(this, obj)) return true; - return obj.GetType() == GetType() && Equals((CalendarEvent)obj); - } - - /// - public override int GetHashCode() - { - unchecked - { - var hashCode = DtStart?.GetHashCode() ?? 0; - hashCode = (hashCode * 397) ^ (Summary?.GetHashCode() ?? 0); - hashCode = (hashCode * 397) ^ (Description?.GetHashCode() ?? 0); - hashCode = (hashCode * 397) ^ (DtEnd?.GetHashCode() ?? 0); - hashCode = (hashCode * 397) ^ Duration.GetHashCode(); - hashCode = (hashCode * 397) ^ (Location?.GetHashCode() ?? 0); - hashCode = (hashCode * 397) ^ Status?.GetHashCode() ?? 0; - hashCode = (hashCode * 397) ^ IsActive.GetHashCode(); - hashCode = (hashCode * 397) ^ Transparency?.GetHashCode() ?? 0; - hashCode = (hashCode * 397) ^ CollectionHelpers.GetHashCode(Attachments); - hashCode = (hashCode * 397) ^ CollectionHelpers.GetHashCode(Resources); - hashCode = (hashCode * 397) ^ CollectionHelpers.GetHashCode(ExceptionDates.GetAllPeriodsByKind(PeriodKind.Period, PeriodKind.DateOnly, PeriodKind.DateTime)); - hashCode = (hashCode * 397) ^ CollectionHelpers.GetHashCode(ExceptionRules); - hashCode = (hashCode * 397) ^ CollectionHelpers.GetHashCode(RecurrenceDates.GetAllPeriodsByKind(PeriodKind.Period, PeriodKind.DateOnly, PeriodKind.DateTime)); - hashCode = (hashCode * 397) ^ CollectionHelpers.GetHashCode(RecurrenceRules); - return hashCode; - } - } - /// public int CompareTo(CalendarEvent? other) => DtStart?.CompareTo(other?.DtStart) ?? -1; } diff --git a/Ical.Net/CalendarComponents/Journal.cs b/Ical.Net/CalendarComponents/Journal.cs index f51b9a9e3..82a0072ff 100644 --- a/Ical.Net/CalendarComponents/Journal.cs +++ b/Ical.Net/CalendarComponents/Journal.cs @@ -34,28 +34,4 @@ protected override void OnDeserializing(StreamingContext context) { base.OnDeserializing(context); } - - protected bool Equals(Journal? other) - { - if (Start == null || other?.Start == null) - { - return Start == other?.Start; // Both must be null to be considered equal - } - - return Start.Equals(other.Start) && Equals(other as RecurringComponent); - } - - public override bool Equals(object? obj) - { - if (ReferenceEquals(null, obj)) return false; - if (ReferenceEquals(this, obj)) return true; - return obj.GetType() == GetType() && Equals((Journal) obj); - } - - public override int GetHashCode() - { - var hashCode = Start?.GetHashCode() ?? 0; - hashCode = (hashCode * 397) ^ base.GetHashCode(); - return hashCode; - } } diff --git a/Ical.Net/CalendarComponents/RecurringComponent.cs b/Ical.Net/CalendarComponents/RecurringComponent.cs index 53f4ced69..7c37f0cda 100644 --- a/Ical.Net/CalendarComponents/RecurringComponent.cs +++ b/Ical.Net/CalendarComponents/RecurringComponent.cs @@ -196,51 +196,4 @@ public virtual IEnumerable GetOccurrences(CalDateTime? startTime = n public virtual IList PollAlarms(CalDateTime? startTime, CalDateTime? endTime) => Alarms.SelectMany(a => a.Poll(startTime).TakeWhile(p => (endTime == null) || (p.Period?.StartTime < endTime))).ToList(); - - 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(ExceptionDatesPeriodLists, other.ExceptionDatesPeriodLists) - && CollectionHelpers.Equals(ExceptionRules, other.ExceptionRules) - && CollectionHelpers.Equals(RecurrenceDatesPeriodLists, other.RecurrenceDatesPeriodLists, orderSignificant: true) - && CollectionHelpers.Equals(RecurrenceRules, other.RecurrenceRules, orderSignificant: true); - - return result; - } - - public override bool Equals(object? obj) - { - if (ReferenceEquals(null, obj)) return false; - if (ReferenceEquals(this, obj)) return true; - return obj.GetType() == GetType() && Equals((RecurringComponent) obj); - } - - public override int GetHashCode() - { - unchecked - { - var hashCode = DtStart?.GetHashCode() ?? 0; - hashCode = (hashCode * 397) ^ Priority.GetHashCode(); - hashCode = (hashCode * 397) ^ (Summary?.GetHashCode() ?? 0); - hashCode = (hashCode * 397) ^ (Class?.GetHashCode() ?? 0); - hashCode = (hashCode * 397) ^ (Description?.GetHashCode() ?? 0); - hashCode = (hashCode * 397) ^ (RecurrenceId?.GetHashCode() ?? 0); - hashCode = (hashCode * 397) ^ CollectionHelpers.GetHashCode(Attachments); - hashCode = (hashCode * 397) ^ CollectionHelpers.GetHashCode(Categories); - hashCode = (hashCode * 397) ^ CollectionHelpers.GetHashCode(Contacts); - hashCode = (hashCode * 397) ^ CollectionHelpers.GetHashCode(ExceptionDatesPeriodLists); - hashCode = (hashCode * 397) ^ CollectionHelpers.GetHashCode(ExceptionRules); - hashCode = (hashCode * 397) ^ CollectionHelpers.GetHashCode(RecurrenceDatesPeriodLists); - hashCode = (hashCode * 397) ^ CollectionHelpers.GetHashCode(RecurrenceRules); - return hashCode; - } - } } diff --git a/Ical.Net/CalendarComponents/VTimeZone.cs b/Ical.Net/CalendarComponents/VTimeZone.cs index 64f78304e..b92aca88c 100644 --- a/Ical.Net/CalendarComponents/VTimeZone.cs +++ b/Ical.Net/CalendarComponents/VTimeZone.cs @@ -364,28 +364,4 @@ public string? Location } public ICalendarObjectList TimeZoneInfos => new CalendarObjectListProxy(Children); - - protected bool Equals(VTimeZone other) - => string.Equals(Name, other.Name, StringComparison.OrdinalIgnoreCase) - && string.Equals(TzId, other.TzId, StringComparison.OrdinalIgnoreCase) - && Equals(Url, other.Url); - - public override bool Equals(object? obj) - { - if (ReferenceEquals(null, obj)) return false; - if (ReferenceEquals(this, obj)) return true; - if (obj.GetType() != GetType()) return false; - return Equals((VTimeZone) obj); - } - - public override int GetHashCode() - { - unchecked - { - var hashCode = Name.GetHashCode(); - hashCode = (hashCode * 397) ^ (TzId?.GetHashCode() ?? 0); - hashCode = (hashCode * 397) ^ (Url?.GetHashCode() ?? 0); - return hashCode; - } - } } diff --git a/Ical.Net/DataTypes/AlarmOccurrence.cs b/Ical.Net/DataTypes/AlarmOccurrence.cs index 344c97d35..530e6e517 100644 --- a/Ical.Net/DataTypes/AlarmOccurrence.cs +++ b/Ical.Net/DataTypes/AlarmOccurrence.cs @@ -16,7 +16,7 @@ namespace Ical.Net.DataTypes; /// the alarm occurs, the that fired, and the /// component on which the alarm fired. /// -public class AlarmOccurrence : IComparable +public class AlarmOccurrence { public Period? Period { get; set; } @@ -43,35 +43,4 @@ public AlarmOccurrence(Alarm a, CalDateTime dt, IRecurringComponent rc) Period = new Period(dt); Component = rc; } - - public int CompareTo(AlarmOccurrence? other) - { - if (other == null) return 1; - if (Period == null) return other.Period == null ? 0 : -1; - return Period.CompareTo(other.Period); - } - - protected bool Equals(AlarmOccurrence other) - => Equals(Period, other.Period) - && Equals(Component, other.Component) - && Equals(Alarm, other.Alarm); - - public override bool Equals(object? obj) - { - if (ReferenceEquals(null, obj)) return false; - if (ReferenceEquals(this, obj)) return true; - return obj.GetType() == GetType() && Equals((AlarmOccurrence) obj); - } - - public override int GetHashCode() - { - // ToDo: Alarm doesn't implement Equals or GetHashCode() - unchecked - { - var hashCode = Period?.GetHashCode() ?? 0; - hashCode = (hashCode * 397) ^ (Component?.GetHashCode() ?? 0); - hashCode = (hashCode * 397) ^ (Alarm?.GetHashCode() ?? 0); - return hashCode; - } - } } diff --git a/Ical.Net/DataTypes/Attachment.cs b/Ical.Net/DataTypes/Attachment.cs index 24bbcc1dd..e0cc5fe08 100644 --- a/Ical.Net/DataTypes/Attachment.cs +++ b/Ical.Net/DataTypes/Attachment.cs @@ -4,10 +4,8 @@ // using System; -using System.Linq; using System.Text; using Ical.Net.Serialization.DataTypes; -using Ical.Net.Utility; namespace Ical.Net.DataTypes; @@ -85,36 +83,4 @@ public override void CopyFrom(ICopyable obj) ValueEncoding = att.ValueEncoding; FormatType = att.FormatType; } - - protected bool Equals(Attachment? other) - { - var firstPart = Equals(Uri, other?.Uri) && ValueEncoding.Equals(other?.ValueEncoding); - if (Data == null && other?.Data == null) - { - return firstPart; - } - if (Data == null || other?.Data == null) - { - return false; - } - return firstPart && Data.SequenceEqual(other.Data); - } - - public override bool Equals(object? obj) - { - if (ReferenceEquals(null, obj)) return false; - if (ReferenceEquals(this, obj)) return true; - return obj.GetType() == GetType() && Equals((Attachment) obj); - } - - public override int GetHashCode() - { - unchecked - { - var hashCode = Uri?.GetHashCode() ?? 0; - hashCode = (hashCode * 397) ^ (Data != null ? CollectionHelpers.GetHashCode(Data) : 0); - hashCode = (hashCode * 397) ^ (ValueEncoding.GetHashCode()); - return hashCode; - } - } } diff --git a/Ical.Net/DataTypes/Attendee.cs b/Ical.Net/DataTypes/Attendee.cs index 9212f8a6e..5ccc679c1 100644 --- a/Ical.Net/DataTypes/Attendee.cs +++ b/Ical.Net/DataTypes/Attendee.cs @@ -275,45 +275,4 @@ public override void CopyFrom(ICopyable obj) SentBy = atn.SentBy; DirectoryEntry = atn.DirectoryEntry; } - - protected bool Equals(Attendee other) - => Equals(SentBy, other.SentBy) - && string.Equals(CommonName, other.CommonName, - StringComparison.OrdinalIgnoreCase) - && Equals(DirectoryEntry, other.DirectoryEntry) - && string.Equals(Type, other.Type, StringComparison.OrdinalIgnoreCase) - && string.Equals(Role, other.Role) - && string.Equals(ParticipationStatus, other.ParticipationStatus, - StringComparison.OrdinalIgnoreCase) - && Rsvp == other.Rsvp - && Equals(Value, other.Value) - && Members.SequenceEqual(other.Members) - && DelegatedTo.SequenceEqual(other.DelegatedTo) - && DelegatedFrom.SequenceEqual(other.DelegatedFrom); - public override bool Equals(object? obj) - { - if (ReferenceEquals(null, obj)) return false; - if (ReferenceEquals(this, obj)) return true; - if (obj.GetType() != GetType()) return false; - return Equals((Attendee) obj); - } - - public override int GetHashCode() - { - unchecked - { - var hashCode = SentBy?.GetHashCode() ?? 0; - hashCode = (hashCode * 397) ^ (CommonName?.GetHashCode() ?? 0); - hashCode = (hashCode * 397) ^ (DirectoryEntry?.GetHashCode() ?? 0); - hashCode = (hashCode * 397) ^ (Type?.GetHashCode() ?? 0); - hashCode = (hashCode * 397) ^ CollectionHelpers.GetHashCode(Members); - hashCode = (hashCode * 397) ^ (Role?.GetHashCode() ?? 0); - hashCode = (hashCode * 397) ^ (ParticipationStatus?.GetHashCode() ?? 0); - hashCode = (hashCode * 397) ^ Rsvp.GetHashCode(); - hashCode = (hashCode * 397) ^ CollectionHelpers.GetHashCode(DelegatedTo); - hashCode = (hashCode * 397) ^ CollectionHelpers.GetHashCode(DelegatedFrom); - hashCode = (hashCode * 397) ^ (Value?.GetHashCode() ?? 0); - return hashCode; - } - } } diff --git a/Ical.Net/DataTypes/GeographicLocation.cs b/Ical.Net/DataTypes/GeographicLocation.cs index 0727d88e8..cc4453ca3 100644 --- a/Ical.Net/DataTypes/GeographicLocation.cs +++ b/Ical.Net/DataTypes/GeographicLocation.cs @@ -50,21 +50,4 @@ public override void CopyFrom(ICopyable obj) } public override string ToString() => Latitude.ToString("0.000000", CultureInfo.InvariantCulture) + ";" + Longitude.ToString("0.000000", CultureInfo.InvariantCulture); - - protected bool Equals(GeographicLocation other) => Latitude.Equals(other.Latitude) && Longitude.Equals(other.Longitude); - - public override bool Equals(object? obj) - { - if (ReferenceEquals(null, obj)) return false; - if (ReferenceEquals(this, obj)) return true; - return obj.GetType() == GetType() && Equals((GeographicLocation) obj); - } - - public override int GetHashCode() - { - unchecked - { - return (Latitude.GetHashCode() * 397) ^ Longitude.GetHashCode(); - } - } } diff --git a/Ical.Net/DataTypes/Organizer.cs b/Ical.Net/DataTypes/Organizer.cs index d14df650b..208baf693 100644 --- a/Ical.Net/DataTypes/Organizer.cs +++ b/Ical.Net/DataTypes/Organizer.cs @@ -87,27 +87,6 @@ public Organizer(string value) : this() CopyFrom(deserialized); } - protected bool Equals(Organizer other) => Equals(Value, other.Value); - - public override bool Equals(object? obj) - { - if (ReferenceEquals(null, obj)) - { - return false; - } - if (ReferenceEquals(this, obj)) - { - return true; - } - if (obj.GetType() != GetType()) - { - return false; - } - return Equals((Organizer) obj); - } - - public override int GetHashCode() => Value?.GetHashCode() ?? 0; - /// public sealed override void CopyFrom(ICopyable obj) { diff --git a/Ical.Net/DataTypes/PeriodList.cs b/Ical.Net/DataTypes/PeriodList.cs index ee8a8de3b..b5419ce5b 100644 --- a/Ical.Net/DataTypes/PeriodList.cs +++ b/Ical.Net/DataTypes/PeriodList.cs @@ -7,7 +7,6 @@ using System.Collections; using System.Collections.Generic; using System.IO; -using Ical.Net.Evaluation; using Ical.Net.Serialization.DataTypes; using Ical.Net.Utility; @@ -78,19 +77,6 @@ public override void CopyFrom(ICopyable obj) /// public override string? ToString() => new PeriodListSerializer().SerializeToString(this); - protected bool Equals(PeriodList other) => CollectionHelpers.Equals(Periods, other.Periods); - - /// - public override bool Equals(object? obj) - { - if (ReferenceEquals(null, obj)) return false; - if (ReferenceEquals(this, obj)) return true; - return obj.GetType() == GetType() && Equals((PeriodList) obj); - } - - /// - public override int GetHashCode() => CollectionHelpers.GetHashCode(Periods); - /// public Period this[int index] { diff --git a/Ical.Net/DataTypes/RecurrencePattern.cs b/Ical.Net/DataTypes/RecurrencePattern.cs index c21a4bfc7..72effb7b6 100644 --- a/Ical.Net/DataTypes/RecurrencePattern.cs +++ b/Ical.Net/DataTypes/RecurrencePattern.cs @@ -150,52 +150,6 @@ public RecurrencePattern(string value) : this() return serializer.SerializeToString(this); } - protected bool Equals(RecurrencePattern? other) - => other != null - && Interval == other.Interval - && Frequency == other.Frequency - && (Until?.Equals(other.Until!) ?? other.Until == null) - && Count == other.Count - && FirstDayOfWeek == other.FirstDayOfWeek - && CollectionEquals(BySecond, other.BySecond) - && CollectionEquals(ByMinute, other.ByMinute) - && CollectionEquals(ByHour, other.ByHour) - && CollectionEquals(ByDay, other.ByDay) - && CollectionEquals(ByMonthDay, other.ByMonthDay) - && CollectionEquals(ByYearDay, other.ByYearDay) - && CollectionEquals(ByWeekNo, other.ByWeekNo) - && CollectionEquals(ByMonth, other.ByMonth) - && CollectionEquals(BySetPosition, other.BySetPosition); - - public override bool Equals(object? obj) - { - if (ReferenceEquals(null, obj)) return false; - if (ReferenceEquals(this, obj)) return true; - return obj.GetType() == GetType() && Equals((RecurrencePattern) obj); - } - - public override int GetHashCode() - { - unchecked - { - var hashCode = Interval.GetHashCode(); - hashCode = (hashCode * 397) ^ (int) Frequency; - hashCode = (hashCode * 397) ^ (Until != null ? Until.GetHashCode() : 0); - hashCode = (hashCode * 397) ^ (Count ?? 0); - hashCode = (hashCode * 397) ^ (int) FirstDayOfWeek; - hashCode = (hashCode * 397) ^ CollectionHelpers.GetHashCode(BySecond); - hashCode = (hashCode * 397) ^ CollectionHelpers.GetHashCode(ByMinute); - hashCode = (hashCode * 397) ^ CollectionHelpers.GetHashCode(ByHour); - hashCode = (hashCode * 397) ^ CollectionHelpers.GetHashCode(ByDay); - hashCode = (hashCode * 397) ^ CollectionHelpers.GetHashCode(ByMonthDay); - hashCode = (hashCode * 397) ^ CollectionHelpers.GetHashCode(ByYearDay); - hashCode = (hashCode * 397) ^ CollectionHelpers.GetHashCode(ByWeekNo); - hashCode = (hashCode * 397) ^ CollectionHelpers.GetHashCode(ByMonth); - hashCode = (hashCode * 397) ^ CollectionHelpers.GetHashCode(BySetPosition); - return hashCode; - } - } - /// public override void CopyFrom(ICopyable obj) { diff --git a/Ical.Net/DataTypes/Trigger.cs b/Ical.Net/DataTypes/Trigger.cs index 21bf6d965..38bad1ef9 100644 --- a/Ical.Net/DataTypes/Trigger.cs +++ b/Ical.Net/DataTypes/Trigger.cs @@ -92,34 +92,4 @@ public override void CopyFrom(ICopyable obj) Duration = t.Duration; Related = t.Related; } - - protected bool Equals(Trigger other) => Equals(_mDateTime, other._mDateTime) && _mDuration.Equals(other._mDuration) && _mRelated == other._mRelated; - - public override bool Equals(object? obj) - { - if (ReferenceEquals(null, obj)) - { - return false; - } - if (ReferenceEquals(this, obj)) - { - return true; - } - if (obj.GetType() != GetType()) - { - return false; - } - return Equals((Trigger)obj); - } - - public override int GetHashCode() - { - unchecked - { - var hashCode = _mDateTime?.GetHashCode() ?? 0; - hashCode = (hashCode * 397) ^ _mDuration.GetHashCode(); - hashCode = (hashCode * 397) ^ _mRelated.GetHashCode(); - return hashCode; - } - } } diff --git a/Ical.Net/VTimeZoneInfo.cs b/Ical.Net/VTimeZoneInfo.cs index 5c2bfc9b7..4fb544bce 100644 --- a/Ical.Net/VTimeZoneInfo.cs +++ b/Ical.Net/VTimeZoneInfo.cs @@ -44,30 +44,6 @@ protected override void OnDeserializing(StreamingContext context) Initialize(); } - public override bool Equals(object? obj) - { - var tzi = obj as VTimeZoneInfo; - if (tzi != null) - { - return Equals(TimeZoneName, tzi.TimeZoneName) && - Equals(OffsetFrom, tzi.OffsetFrom) && - Equals(OffsetTo, tzi.OffsetTo); - } - return base.Equals(obj); - } - - public override int GetHashCode() - { - unchecked - { - var hashCode = TimeZoneName?.GetHashCode() ?? 0; - hashCode = (hashCode * 397) ^ (OffsetFrom?.GetHashCode() ?? 0); - hashCode = (hashCode * 397) ^ (OffsetTo?.GetHashCode() ?? 0); - - return hashCode; - } - } - public virtual string? TzId { get =>