Skip to content

Commit d1b58c7

Browse files
authored
Remove redundant Equals and GetHashCode implementations (#810)
* `Calendar`: Remove Equals and GetHashCode overrides * `CalendarEvent`: Remove Equals and GetHashCode overrides * `CalendarCollection`: Remove Equals and GetHashCode overrides * `RecurringComponent`: Remove Equals and GetHashCode overrides * `Journal`: Remove Equals and GetHashCode overrides * `AlarmOccurrence` (`RecurringComponent`): Remove Equals and GetHashCode overrides, IComparable<AlarmOccurrence> * `Attachment`: Remove Equals and GetHashCode overrides * `Attendee`: Remove Equals and GetHashCode overrides * `GeographicLocation`: Remove Equals and GetHashCode overrides * `Organizer`, `PeriodList`: Remove Equals and GetHashCode overrides * `RecurrencePattern`: Remove Equals and GetHashCode overrides * `Trigger`: Remove Equals and GetHashCode overrides * `VTimeZoneInfo`: Remove Equals and GetHashCode overrides * Remove remaining test with explict calls to `Equals` and `GetHashCode`
1 parent c656c3e commit d1b58c7

22 files changed

+4
-1116
lines changed

Ical.Net.Tests/CalendarEventTest.cs

Lines changed: 1 addition & 216 deletions
Original file line numberDiff line numberDiff line change
@@ -173,233 +173,18 @@ public static IEnumerable EnsureAutomaticallySetDtStampIsSerializedAsUtcKind_Tes
173173
.Returns(true);
174174
}
175175

176-
[Test]
177-
public void EventWithExDateShouldNotBeEqualToSameEventWithoutExDate()
178-
{
179-
const string icalNoException = @"BEGIN:VCALENDAR
180-
PRODID:-//Telerik Inc.//NONSGML RadScheduler//EN
181-
VERSION:2.0
182-
CALSCALE:GREGORIAN
183-
METHOD:PUBLISH
184-
BEGIN:VTIMEZONE
185-
TZID:UTC
186-
BEGIN:STANDARD
187-
TZNAME:UTC
188-
TZOFFSETTO:+0000
189-
TZOFFSETFROM:+0000
190-
DTSTART:16010101T000000
191-
END:STANDARD
192-
END:VTIMEZONE
193-
BEGIN:VEVENT
194-
DTSTART;TZID=UTC:20161020T170000
195-
DTEND;TZID=UTC:20161020T230000
196-
UID:694f818f-6d67-4307-9c4d-0b5211686ff0
197-
IMPORTANCE:None
198-
RRULE:FREQ=DAILY
199-
END:VEVENT
200-
END:VCALENDAR";
201-
202-
const string icalWithException = @"BEGIN:VCALENDAR
203-
PRODID:-//Telerik Inc.//NONSGML RadScheduler//EN
204-
VERSION:2.0
205-
CALSCALE:GREGORIAN
206-
METHOD:PUBLISH
207-
BEGIN:VTIMEZONE
208-
TZID:UTC
209-
BEGIN:STANDARD
210-
TZNAME:UTC
211-
TZOFFSETTO:+0000
212-
TZOFFSETFROM:+0000
213-
DTSTART:16010101T000000
214-
END:STANDARD
215-
END:VTIMEZONE
216-
BEGIN:VEVENT
217-
DTSTART;TZID=UTC:20161020T170000
218-
DTEND;TZID=UTC:20161020T230000
219-
UID:694f818f-6d67-4307-9c4d-0b5211686ff0
220-
IMPORTANCE:None
221-
RRULE:FREQ=DAILY
222-
EXDATE;TZID=UTC:20161020T170000
223-
END:VEVENT
224-
END:VCALENDAR";
225-
226-
var noException = Calendar.Load(icalNoException).Events.First();
227-
var withException = Calendar.Load(icalWithException).Events.First();
228-
229-
Assert.That(withException, Is.Not.EqualTo(noException));
230-
Assert.That(withException.GetHashCode(), Is.Not.EqualTo(noException.GetHashCode()));
231-
}
232-
233176
private static CalendarEvent GetSimpleEvent() => new CalendarEvent
234177
{
235178
DtStart = new CalDateTime(_now),
236179
DtEnd = new CalDateTime(_later),
237180
Uid = _uid,
238181
};
239182

240-
[Test]
241-
public void RrulesAreSignificantTests()
242-
{
243-
var rrule = new RecurrencePattern(FrequencyType.Daily, 1);
244-
var testRrule = GetSimpleEvent();
245-
testRrule.RecurrenceRules = new List<RecurrencePattern> { rrule };
246-
247-
var simpleEvent = GetSimpleEvent();
248-
Assert.That(testRrule, Is.Not.EqualTo(simpleEvent));
249-
Assert.That(testRrule.GetHashCode(), Is.Not.EqualTo(simpleEvent.GetHashCode()));
250-
251-
var testRdate = GetSimpleEvent();
252-
testRdate.RecurrenceDatesPeriodLists = new List<PeriodList> { new PeriodList { new Period(new CalDateTime(_now)) } };
253-
Assert.That(testRdate, Is.Not.EqualTo(simpleEvent));
254-
Assert.That(testRdate.GetHashCode(), Is.Not.EqualTo(simpleEvent.GetHashCode()));
255-
}
256-
257183
private static List<RecurrencePattern> GetSimpleRecurrenceList()
258184
=> new List<RecurrencePattern> { new RecurrencePattern(FrequencyType.Daily, 1) { Count = 5 } };
259185
private static List<CalDateTime> GetExceptionDates()
260186
=> new List<CalDateTime> { new CalDateTime(_now.AddDays(1).Date) };
261-
262-
[Test]
263-
public void EventWithRecurrenceAndExceptionComparison()
264-
{
265-
var vEvent = GetSimpleEvent();
266-
vEvent.RecurrenceRules = GetSimpleRecurrenceList();
267-
vEvent.ExceptionDates.AddRange(GetExceptionDates());
268-
269-
var calendar = new Calendar();
270-
calendar.Events.Add(vEvent);
271-
272-
var vEvent2 = GetSimpleEvent();
273-
vEvent2.RecurrenceRules = GetSimpleRecurrenceList();
274-
vEvent2.ExceptionDates.AddRange(GetExceptionDates());
275-
276-
var cal2 = new Calendar();
277-
cal2.Events.Add(vEvent2);
278-
279-
var eventA = calendar.Events.First();
280-
var eventB = cal2.Events.First();
281-
282-
Assert.Multiple(() =>
283-
{
284-
Assert.That(eventB.RecurrenceRules.First(), Is.EqualTo(eventA.RecurrenceRules.First()));
285-
Assert.That(eventB.RecurrenceRules.First().GetHashCode(), Is.EqualTo(eventA.RecurrenceRules.First().GetHashCode()));
286-
Assert.That(eventB.ExceptionDates.GetAllDates().First(), Is.EqualTo(eventA.ExceptionDates.GetAllDates().First()));
287-
Assert.That(eventB.GetHashCode(), Is.EqualTo(eventA.GetHashCode()));
288-
Assert.That(eventB, Is.EqualTo(eventA));
289-
Assert.That(cal2, Is.EqualTo(calendar));
290-
});
291-
}
292-
293-
[Test]
294-
public void AddingExdateToEventShouldNotBeEqualToOriginal()
295-
{
296-
//Create a calendar with an event with a recurrence rule
297-
//Serialize to string, and deserialize
298-
//Change the original calendar.Event to have an ExDate
299-
//Serialize to string, and deserialize
300-
//CalendarEvent and Calendar hash codes and equality should NOT be the same
301-
var serializer = new CalendarSerializer();
302-
303-
var vEvent = GetSimpleEvent();
304-
vEvent.RecurrenceRules = GetSimpleRecurrenceList();
305-
var cal1 = new Calendar();
306-
cal1.Events.Add(vEvent);
307-
var serialized = serializer.SerializeToString(cal1);
308-
var deserializedNoExDate = Calendar.Load(serialized);
309-
Assert.That(deserializedNoExDate, Is.EqualTo(cal1));
310-
311-
vEvent.ExceptionDates.AddRange(GetExceptionDates());
312-
serialized = serializer.SerializeToString(cal1);
313-
var deserializedWithExDate = Calendar.Load(serialized);
314-
315-
Assert.Multiple(() =>
316-
{
317-
Assert.That(deserializedWithExDate.Events.First(), Is.Not.EqualTo(deserializedNoExDate.Events.First()));
318-
Assert.That(deserializedWithExDate.Events.First().GetHashCode(), Is.Not.EqualTo(deserializedNoExDate.Events.First().GetHashCode()));
319-
Assert.That(deserializedWithExDate, Is.Not.EqualTo(deserializedNoExDate));
320-
});
321-
}
322-
323-
[Test]
324-
public void ChangingRrulesShouldNotBeEqualToOriginalEvent()
325-
{
326-
var eventA = GetSimpleEvent();
327-
eventA.RecurrenceRules = GetSimpleRecurrenceList();
328-
329-
var eventB = GetSimpleEvent();
330-
eventB.RecurrenceRules = GetSimpleRecurrenceList();
331-
Assert.Multiple(() =>
332-
{
333-
Assert.That(ReferenceEquals(eventA, eventB), Is.False);
334-
Assert.That(eventB, Is.EqualTo(eventA));
335-
});
336-
337-
var foreverDailyRule = new RecurrencePattern(FrequencyType.Daily, 1);
338-
eventB.RecurrenceRules = new List<RecurrencePattern> { foreverDailyRule };
339-
340-
Assert.That(eventB, Is.Not.EqualTo(eventA));
341-
Assert.That(eventB.GetHashCode(), Is.Not.EqualTo(eventA.GetHashCode()));
342-
}
343-
344-
[Test]
345-
public void EventsDifferingByDtStampAreEqual()
346-
{
347-
const string eventA = @"BEGIN:VCALENDAR
348-
PRODID:-//github.com/rianjs/ical.net//NONSGML ical.net 2.2//EN
349-
VERSION:2.0
350-
BEGIN:VEVENT
351-
ATTACH;FMTTYPE=application/json;VALUE=BINARY;ENCODING=BASE64:eyJzdWJqZWN0I
352-
joiSFAgQ29hdGVyIGFuZCBDdXR0ZXIgQ2xlYW51cCIsInVuaXF1ZUlkZW50aWZpZXIiOiIwND
353-
EwNzI1NGRjNWM5MDk0YWY3MWEwZTE5N2U2NWE1NTdkZmJjYjg0IiwiaWNhbFN0cmluZyI6IiI
354-
sImxhYm9yRG93bnRpbWVzIjpbXSwiZGlzYWJsZWRFcXVpcG1lbnQiOlt7ImRpc2FibGVkRXF1
355-
aXBtZW50SW5zdGFuY2VOYW1lcyI6WyJEaWdpdGFsIFByaW50XFxIUCAyOCIsIkRpZ2l0YWwgU
356-
HJpbnRcXEhQIDQ0Il0sImZ1bGxUaW1lRXF1aXZhbGVudHNDb3VudCI6MC4wfV0sIm1vZGVzTm
357-
90QWxsb3dlZCI6W10sInJhd01hdGVyaWFsc05vdEFsbG93ZWQiOltdLCJsYWJvckFsbG9jYXR
358-
pb25zIjpbXX0=
359-
DTEND;TZID=UTC:20150615T055000
360-
DTSTAMP:20161011T195316Z
361-
DTSTART;TZID=UTC:20150615T054000
362-
EXDATE;TZID=UTC:20151023T054000
363-
IMPORTANCE:None
364-
RRULE:FREQ=WEEKLY;BYDAY=MO,TU,WE,TH,FR,SA
365-
UID:04107254dc5c9094af71a0e197e65a557dfbcb84
366-
END:VEVENT
367-
END:VCALENDAR";
368-
369-
const string eventB = @"BEGIN:VCALENDAR
370-
PRODID:-//github.com/rianjs/ical.net//NONSGML ical.net 2.2//EN
371-
VERSION:2.0
372-
BEGIN:VEVENT
373-
ATTACH;FMTTYPE=application/json;VALUE=BINARY;ENCODING=BASE64:eyJzdWJqZWN0I
374-
joiSFAgQ29hdGVyIGFuZCBDdXR0ZXIgQ2xlYW51cCIsInVuaXF1ZUlkZW50aWZpZXIiOiIwND
375-
EwNzI1NGRjNWM5MDk0YWY3MWEwZTE5N2U2NWE1NTdkZmJjYjg0IiwiaWNhbFN0cmluZyI6IiI
376-
sImxhYm9yRG93bnRpbWVzIjpbXSwiZGlzYWJsZWRFcXVpcG1lbnQiOlt7ImRpc2FibGVkRXF1
377-
aXBtZW50SW5zdGFuY2VOYW1lcyI6WyJEaWdpdGFsIFByaW50XFxIUCAyOCIsIkRpZ2l0YWwgU
378-
HJpbnRcXEhQIDQ0Il0sImZ1bGxUaW1lRXF1aXZhbGVudHNDb3VudCI6MC4wfV0sIm1vZGVzTm
379-
90QWxsb3dlZCI6W10sInJhd01hdGVyaWFsc05vdEFsbG93ZWQiOltdLCJsYWJvckFsbG9jYXR
380-
pb25zIjpbXX0=
381-
DTEND;TZID=UTC:20150615T055000
382-
DTSTAMP:20161024T201419Z
383-
DTSTART;TZID=UTC:20150615T054000
384-
EXDATE;TZID=UTC:20151023T054000
385-
IMPORTANCE:None
386-
RRULE:FREQ=WEEKLY;BYDAY=MO,TU,WE,TH,FR,SA
387-
UID:04107254dc5c9094af71a0e197e65a557dfbcb84
388-
END:VEVENT
389-
END:VCALENDAR";
390-
391-
var calendarA = Calendar.Load(eventA);
392-
var calendarB = Calendar.Load(eventB);
393-
394-
Assert.Multiple(() =>
395-
{
396-
Assert.That(calendarB.Events.First().GetHashCode(), Is.EqualTo(calendarA.Events.First().GetHashCode()));
397-
Assert.That(calendarB.Events.First(), Is.EqualTo(calendarA.Events.First()));
398-
Assert.That(calendarB.GetHashCode(), Is.EqualTo(calendarA.GetHashCode()));
399-
Assert.That(calendarB, Is.EqualTo(calendarA));
400-
});
401-
}
402-
187+
403188
[Test]
404189
public void EventResourcesCanBeZeroedOut()
405190
{

Ical.Net.Tests/CopyComponentTests.cs

Lines changed: 1 addition & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -20,39 +20,6 @@ namespace Ical.Net.Tests;
2020
[TestFixture]
2121
public class CopyComponentTests
2222
{
23-
[Test, TestCaseSource(nameof(CopyCalendarTest_TestCases)), Category("Copy tests")]
24-
public void CopyCalendarTest(string calendarString)
25-
{
26-
var iCal1 = Calendar.Load(calendarString)!;
27-
var iCal2 = iCal1.Copy<Calendar>();
28-
SerializationTests.CompareCalendars(iCal1, iCal2);
29-
}
30-
31-
public static IEnumerable CopyCalendarTest_TestCases()
32-
{
33-
yield return new TestCaseData(IcsFiles.Attachment3).SetName("Attachment3");
34-
yield return new TestCaseData(IcsFiles.Bug2148092).SetName("Bug2148092");
35-
yield return new TestCaseData(IcsFiles.CaseInsensitive1).SetName("CaseInsensitive1");
36-
yield return new TestCaseData(IcsFiles.CaseInsensitive2).SetName("CaseInsensitive2");
37-
yield return new TestCaseData(IcsFiles.CaseInsensitive3).SetName("CaseInsensitive3");
38-
yield return new TestCaseData(IcsFiles.Categories1).SetName("Categories1");
39-
yield return new TestCaseData(IcsFiles.Duration1).SetName("Duration1");
40-
yield return new TestCaseData(IcsFiles.Encoding1).SetName("Encoding1");
41-
yield return new TestCaseData(IcsFiles.Event1).SetName("Event1");
42-
yield return new TestCaseData(IcsFiles.Event2).SetName("Event2");
43-
yield return new TestCaseData(IcsFiles.Event3).SetName("Event3");
44-
yield return new TestCaseData(IcsFiles.Event4).SetName("Event4");
45-
yield return new TestCaseData(IcsFiles.GeographicLocation1).SetName("GeographicLocation1");
46-
yield return new TestCaseData(IcsFiles.Language1).SetName("Language1");
47-
yield return new TestCaseData(IcsFiles.Language2).SetName("Language2");
48-
yield return new TestCaseData(IcsFiles.Language3).SetName("Language3");
49-
yield return new TestCaseData(IcsFiles.TimeZone1).SetName("TimeZone1");
50-
yield return new TestCaseData(IcsFiles.TimeZone2).SetName("TimeZone2");
51-
yield return new TestCaseData(IcsFiles.TimeZone3).SetName("TimeZone3");
52-
yield return new TestCaseData(IcsFiles.XProperty1).SetName("XProperty1");
53-
yield return new TestCaseData(IcsFiles.XProperty2).SetName("XProperty2");
54-
}
55-
5623
private static readonly DateTime _now = DateTime.SpecifyKind(DateTime.Now, DateTimeKind.Unspecified);
5724
private static readonly DateTime _later = _now.AddHours(1);
5825

@@ -95,7 +62,6 @@ public void CopyCalendarEventTest()
9562
Assert.That(copy.Resources[0], Is.Not.EqualTo(orig.Resources[0]));
9663

9764
Assert.That(resourcesCopyFromOrig, Is.EquivalentTo(orig.Resources));
98-
Assert.That(copy.GeographicLocation, Is.EqualTo(orig.GeographicLocation));
9965
Assert.That(copy.Transparency, Is.EqualTo(orig.Transparency));
10066

10167
Assert.That(Regex.Matches(serializedOrig, uidPattern, RegexOptions.Compiled, TimeSpan.FromSeconds(100)), Has.Count.EqualTo(1));
@@ -142,7 +108,7 @@ public void CopyAlarmTest()
142108
Assert.Multiple(() =>
143109
{
144110
Assert.That(copy.Action, Is.EqualTo(orig.Action));
145-
Assert.That(copy.Trigger, Is.EqualTo(orig.Trigger));
111+
Assert.That(copy.Trigger?.DateTime, Is.EqualTo(orig.Trigger.DateTime));
146112
Assert.That(copy.Description, Is.EqualTo(orig.Description));
147113
});
148114
}

0 commit comments

Comments
 (0)