From a2dafa1d45d3f855358a2ed3d8adf44b6106c6c6 Mon Sep 17 00:00:00 2001 From: Rian Stockbower Date: Wed, 8 Nov 2017 11:54:28 -0500 Subject: [PATCH] COnvert Journal statuses from enum to class #318 --- .../Ical.Net.UnitTests/SerializationTests.cs | 17 +++++++++++++++++ .../Ical.Net/Ical.Net/Components/Journal.cs | 8 ++++---- net-core/Ical.Net/Ical.Net/Constants.cs | 13 ++++++++----- .../Serialization/Factory/ComponentFactory.cs | 2 +- 4 files changed, 30 insertions(+), 10 deletions(-) diff --git a/net-core/Ical.Net/Ical.Net.UnitTests/SerializationTests.cs b/net-core/Ical.Net/Ical.Net.UnitTests/SerializationTests.cs index 4038314da..9721ff350 100644 --- a/net-core/Ical.Net/Ical.Net.UnitTests/SerializationTests.cs +++ b/net-core/Ical.Net/Ical.Net.UnitTests/SerializationTests.cs @@ -399,5 +399,22 @@ public void ToDoStatusAllCaps() var status = calendar.Todos.First().Status; Assert.IsTrue(string.Equals(TodoStatus.NeedsAction, status, TodoStatus.Comparison)); } + + [Test] + public void JournalStatusAllCaps() + { + var component = new Journal + { + Status = JournalStatus.Final, + }; + + var c = new Calendar { Journals = {component} }; + var serialized = SerializeToString(c); + Assert.IsTrue(serialized.Contains(JournalStatus.Final, JournalStatus.Comparison)); + + var calendar = UnserializeCalendar(serialized); + var status = calendar.Todos.First().Status; + Assert.IsTrue(string.Equals(JournalStatus.Final, status, JournalStatus.Comparison)); + } } } diff --git a/net-core/Ical.Net/Ical.Net/Components/Journal.cs b/net-core/Ical.Net/Ical.Net/Components/Journal.cs index 2b3a39f61..697b92816 100644 --- a/net-core/Ical.Net/Ical.Net/Components/Journal.cs +++ b/net-core/Ical.Net/Ical.Net/Components/Journal.cs @@ -7,10 +7,10 @@ namespace Ical.Net /// public class Journal : RecurringComponent { - public JournalStatus Status + public string Status { - get => Properties.Get("STATUS"); - set => Properties.Set("STATUS", value); + get => Properties.Get(JournalStatus.Key); + set => Properties.Set(JournalStatus.Key, value); } /// @@ -19,7 +19,7 @@ public JournalStatus Status /// public Journal() { - Name = Components.Journal; + Name = JournalStatus.Name; } protected override bool EvaluationIncludesReferenceDate => true; diff --git a/net-core/Ical.Net/Ical.Net/Constants.cs b/net-core/Ical.Net/Ical.Net/Constants.cs index 2cb3121d6..c758deccd 100644 --- a/net-core/Ical.Net/Ical.Net/Constants.cs +++ b/net-core/Ical.Net/Ical.Net/Constants.cs @@ -21,7 +21,6 @@ public static class Components public const string Alarm = "VALARM"; public const string Calendar = "VCALENDAR"; public const string Freebusy = "VFREEBUSY"; - public const string Journal = "VJOURNAL"; public const string Timezone = "VTIMEZONE"; public const string Daylight = "DAYLIGHT"; public const string Standard = "STANDARD"; @@ -140,11 +139,15 @@ public static class TodoStatus /// /// Status codes available to a entry. /// - public enum JournalStatus + public static class JournalStatus { - Draft, // Indicates journal is draft. - Final, // Indicates journal is final. - Cancelled // Indicates journal is removed. + public const string Name = "VJOURNAL"; + public const string Key = "STATUS"; + public static readonly StringComparison Comparison = StringComparison.Ordinal; + + public const string Draft = "DRAFT"; + public const string Final = "FINAL"; + public const string Cancelled = "CANCELLED"; } public enum FreeBusyStatus diff --git a/net-core/Ical.Net/Ical.Net/Serialization/Factory/ComponentFactory.cs b/net-core/Ical.Net/Ical.Net/Serialization/Factory/ComponentFactory.cs index ebab977af..cec70d397 100644 --- a/net-core/Ical.Net/Ical.Net/Serialization/Factory/ComponentFactory.cs +++ b/net-core/Ical.Net/Ical.Net/Serialization/Factory/ComponentFactory.cs @@ -21,7 +21,7 @@ public virtual ICalendarComponent Build(string objectName) case Components.Freebusy: c = new FreeBusy(); break; - case Components.Journal: + case JournalStatus.Name: c = new Journal(); break; case Components.Timezone: