Skip to content

Commit

Permalink
REBASE - work on attendee serialization and deserialization. HashCode…
Browse files Browse the repository at this point in the history
…s and Equality working as expected #45
  • Loading branch information
rianjs committed Jul 22, 2016
1 parent 116592f commit 4991ab4
Show file tree
Hide file tree
Showing 5 changed files with 300 additions and 75 deletions.
9 changes: 4 additions & 5 deletions ical.NET.UnitTests/AttendeeTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand All @@ -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);
}

Expand All @@ -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);
Expand Down
74 changes: 53 additions & 21 deletions ical.NET.UnitTests/EqualityAndHashingTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
}
}
5 changes: 2 additions & 3 deletions ical.NET.UnitTests/SerializationTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
55 changes: 55 additions & 0 deletions ical.NET.UnitTests/SymmetricSerializationTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
{
Expand Down Expand Up @@ -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");
}
}
}
Loading

0 comments on commit 4991ab4

Please sign in to comment.