Skip to content

Commit

Permalink
COnvert Journal statuses from enum to class #318
Browse files Browse the repository at this point in the history
  • Loading branch information
Rian Stockbower committed Nov 9, 2017
1 parent cd782b5 commit 038d3d7
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 10 deletions.
17 changes: 17 additions & 0 deletions net-core/Ical.Net/Ical.Net.UnitTests/SerializationTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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.Journals.First().Status;
Assert.IsTrue(string.Equals(JournalStatus.Final, status, JournalStatus.Comparison));
}
}
}
8 changes: 4 additions & 4 deletions net-core/Ical.Net/Ical.Net/Components/Journal.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ namespace Ical.Net
/// </summary>
public class Journal : RecurringComponent
{
public JournalStatus Status
public string Status
{
get => Properties.Get<JournalStatus>("STATUS");
set => Properties.Set("STATUS", value);
get => Properties.Get<string>(JournalStatus.Key);
set => Properties.Set(JournalStatus.Key, value);
}

/// <summary>
Expand All @@ -19,7 +19,7 @@ public JournalStatus Status
/// </summary>
public Journal()
{
Name = Components.Journal;
Name = JournalStatus.Name;
}

protected override bool EvaluationIncludesReferenceDate => true;
Expand Down
13 changes: 8 additions & 5 deletions net-core/Ical.Net/Ical.Net/Constants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -140,11 +139,15 @@ public static class TodoStatus
/// <summary>
/// Status codes available to a <see cref="Components.Journal"/> entry.
/// </summary>
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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit 038d3d7

Please sign in to comment.