-
Notifications
You must be signed in to change notification settings - Fork 232
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
REBASE - work on attendee serialization and deserialization. HashCode…
…s and Equality working as expected #45
- Loading branch information
Showing
5 changed files
with
300 additions
and
75 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,20 +21,19 @@ internal static Event VEventFactory() | |
}; | ||
} | ||
|
||
private const string _requiredParticipant = "REQ-PARTICIPANT"; //this string may be added to the api in the future | ||
private static readonly IList<Attendee> _attendees = new List<Attendee> | ||
{ | ||
new Attendee("MAILTO:[email protected]") | ||
{ | ||
CommonName = "James James", | ||
Role = _requiredParticipant, | ||
Role = ParticipationRole.RequiredParticipant, | ||
Rsvp = true, | ||
ParticipationStatus = EventParticipationStatus.Tentative | ||
}, | ||
new Attendee("MAILTO:[email protected]") | ||
{ | ||
CommonName = "Mary Mary", | ||
Role = _requiredParticipant, | ||
Role = ParticipationRole.RequiredParticipant, | ||
Rsvp = true, | ||
ParticipationStatus = EventParticipationStatus.Accepted | ||
} | ||
|
@@ -54,7 +53,7 @@ public void Add1Attendee() | |
Assert.AreEqual(1, evt.Attendees.Count); | ||
|
||
//the properties below had been set to null during the Attendees.Add operation in NuGet version 2.1.4 | ||
Assert.AreEqual(_requiredParticipant, evt.Attendees[0].Role); | ||
Assert.AreEqual(ParticipationRole.RequiredParticipant, evt.Attendees[0].Role); | ||
Assert.AreEqual(EventParticipationStatus.Tentative, evt.Attendees[0].ParticipationStatus); | ||
} | ||
|
||
|
@@ -67,7 +66,7 @@ public void Add2Attendees() | |
evt.Attendees.Add(_attendees[0]); | ||
evt.Attendees.Add(_attendees[1]); | ||
Assert.AreEqual(2, evt.Attendees.Count); | ||
Assert.AreEqual(_requiredParticipant, evt.Attendees[1].Role); | ||
Assert.AreEqual(ParticipationRole.RequiredParticipant, evt.Attendees[1].Role); | ||
|
||
var cal = new Calendar(); | ||
cal.Events.Add(evt); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -139,26 +139,58 @@ public static IEnumerable<ITestCaseData> VTimeZone_TestCases() | |
yield return new TestCaseData(first, second); | ||
} | ||
|
||
//ToDo: Tests for: | ||
//private IUniqueComponentList<IUniqueComponent> _mUniqueComponents; | ||
//private IUniqueComponentList<IEvent> _mEvents; | ||
//private IUniqueComponentList<ITodo> _mTodos; | ||
//private ICalendarObjectList<IJournal> _mJournals; | ||
//private IUniqueComponentList<IFreeBusy> _mFreeBusy; | ||
//private ICalendarObjectList<ITimeZone> _mTimeZones; | ||
|
||
// FreeBusy | ||
//VAlarm | ||
//Journal | ||
//RecurringComponent? | ||
//Todo | ||
//VTimeZone? | ||
//IAttachment | ||
//GeographicLocation | ||
//Organizer | ||
//StatusCode | ||
//Trigger | ||
//UTCOffset -- perhaps try to retire this entirely first | ||
//WeekDay | ||
[Test, TestCaseSource(nameof(Attendees_TestCases))] | ||
public void Attendees_Tests(Attendee actual, Attendee expected) | ||
{ | ||
Assert.AreEqual(expected.GetHashCode(), actual.GetHashCode()); | ||
Assert.AreEqual(expected, actual); | ||
} | ||
|
||
public static IEnumerable<ITestCaseData> Attendees_TestCases() | ||
{ | ||
var tentative1 = new Attendee("MAILTO:[email protected]") | ||
{ | ||
CommonName = "James Tentative", | ||
Role = ParticipationRole.RequiredParticipant, | ||
Rsvp = true, | ||
ParticipationStatus = EventParticipationStatus.Tentative | ||
}; | ||
var tentative2 = new Attendee("MAILTO:[email protected]") | ||
{ | ||
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:[email protected]") | ||
{ | ||
CommonName = "Mary Accepted", | ||
Rsvp = true, | ||
ParticipationStatus = EventParticipationStatus.Accepted, | ||
SentBy = new Uri("mailto:[email protected]"), | ||
DirectoryEntry = new Uri("ldap://example.com:6666/o=eDABC Industries,c=3DUS??(cn=3DBMary Accepted)"), | ||
Type = "CuType", | ||
Members = new List<string> { "Group A", "Group B"}, | ||
Role = ParticipationRole.Chair, | ||
DelegatedTo = new List<string> { "Peon A", "Peon B"}, | ||
DelegatedFrom = new List<string> { "Bigwig A", "Bigwig B"} | ||
}; | ||
var complex2 = new Attendee("MAILTO:[email protected]") | ||
{ | ||
CommonName = "Mary Accepted", | ||
Rsvp = true, | ||
ParticipationStatus = EventParticipationStatus.Accepted, | ||
SentBy = new Uri("mailto:[email protected]"), | ||
DirectoryEntry = new Uri("ldap://example.com:6666/o=eDABC Industries,c=3DUS??(cn=3DBMary Accepted)"), | ||
Type = "CuType", | ||
Members = new List<string> { "Group A", "Group B" }, | ||
Role = ParticipationRole.Chair, | ||
DelegatedTo = new List<string> { "Peon A", "Peon B" }, | ||
DelegatedFrom = new List<string> { "Bigwig A", "Bigwig B" } | ||
}; | ||
yield return new TestCaseData(complex1, complex2).SetName("Complex attendee test"); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -286,20 +286,19 @@ public void EventPropertiesSerialized() | |
}); | ||
} | ||
|
||
private const string _requiredParticipant = "REQ-PARTICIPANT"; //this string may be added to the api in the future | ||
private static readonly IList<Attendee> _attendees = new List<Attendee> | ||
{ | ||
new Attendee("MAILTO:[email protected]") | ||
{ | ||
CommonName = "James James", | ||
Role = _requiredParticipant, | ||
Role = ParticipationRole.RequiredParticipant, | ||
Rsvp = true, | ||
ParticipationStatus = EventParticipationStatus.Tentative | ||
}, | ||
new Attendee("MAILTO:[email protected]") | ||
{ | ||
CommonName = "Mary Mary", | ||
Role = _requiredParticipant, | ||
Role = ParticipationRole.RequiredParticipant, | ||
Rsvp = true, | ||
ParticipationStatus = EventParticipationStatus.Accepted | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,15 +4,25 @@ | |
using System.Linq; | ||
using Ical.Net; | ||
using Ical.Net.DataTypes; | ||
using Ical.Net.Interfaces; | ||
using Ical.Net.Interfaces.DataTypes; | ||
using Ical.Net.Serialization; | ||
using Ical.Net.Serialization.iCalendar.Serializers; | ||
using NUnit.Framework; | ||
using NUnit.Framework.Interfaces; | ||
using NUnit.Framework.Internal; | ||
|
||
namespace ical.Net.UnitTests | ||
{ | ||
public class SymmetricSerializationTests | ||
{ | ||
private static readonly DateTime _nowTime = DateTime.Now; | ||
private static readonly DateTime _later = _nowTime.AddHours(1); | ||
private static CalendarSerializer GetNewSerializer() => new CalendarSerializer(new SerializationContext()); | ||
private static string SerializeToString(Calendar c) => GetNewSerializer().SerializeToString(c); | ||
private static Event GetSimpleEvent() => new Event {DtStart = new CalDateTime(_nowTime), DtEnd = new CalDateTime(_later),Duration = _later - _nowTime}; | ||
private static ICalendar UnserializeCalendar(string s) => Calendar.LoadFromStream(new StringReader(s)).Single(); | ||
|
||
[Test] | ||
public void SimpleEvent_Test() | ||
{ | ||
|
@@ -66,5 +76,50 @@ public void VTimeZoneSerialization_Test() | |
Assert.AreEqual(originalCalendar, unserializedCalendar); | ||
Assert.AreEqual(originalCalendar.GetHashCode(), unserializedCalendar.GetHashCode()); | ||
} | ||
|
||
[Test, TestCaseSource(nameof(AttendeeSerialization_TestCases))] | ||
public void AttendeeSerialization_Test(Attendee attendee) | ||
{ | ||
var calendar = new Calendar(); | ||
calendar.AddTimeZone(new VTimeZone("America/Los_Angeles")); | ||
var someEvent = GetSimpleEvent(); | ||
someEvent.Attendees = new List<IAttendee> {attendee}; | ||
calendar.Events.Add(someEvent); | ||
|
||
var serialized = SerializeToString(calendar); | ||
var unserialized = UnserializeCalendar(serialized); | ||
|
||
Assert.AreEqual(calendar.GetHashCode(), unserialized.GetHashCode()); | ||
Assert.IsTrue(calendar.Events.SequenceEqual(unserialized.Events)); | ||
Assert.AreEqual(calendar, unserialized); | ||
} | ||
|
||
public static IEnumerable<ITestCaseData> AttendeeSerialization_TestCases() | ||
{ | ||
//TODO: Fix this. It appears to be non-deterministic. E.g. you can have one of the Delegated* properties uncommented, and it works, but not both | ||
var complex1 = new Attendee("MAILTO:[email protected]") | ||
{ | ||
CommonName = "Mary Accepted", | ||
Rsvp = true, | ||
ParticipationStatus = EventParticipationStatus.Accepted, | ||
//SentBy = new Uri("mailto:[email protected]"), //Broken | ||
//DirectoryEntry = new Uri("ldap://example.com:6666/o=eDABC Industries,c=3DUS??(cn=3DBMary Accepted)"), //Broken | ||
//Type = "CuType", | ||
//Members = new List<string> { "Group A", "Group B" }, | ||
//Role = ParticipationRole.Chair, | ||
//DelegatedTo = new List<string> { "Peon A", "Peon B" }, | ||
//DelegatedFrom = new List<string> { "Bigwig A", "Bigwig B" } | ||
}; | ||
yield return new TestCaseData(complex1).SetName("Complex attendee"); | ||
|
||
var simple = new Attendee("MAILTO:[email protected]") | ||
{ | ||
CommonName = "James James", | ||
Role = ParticipationRole.RequiredParticipant, | ||
Rsvp = true, | ||
ParticipationStatus = EventParticipationStatus.Tentative | ||
}; | ||
yield return new TestCaseData(simple).SetName("Simple attendee"); | ||
} | ||
} | ||
} |
Oops, something went wrong.