-
Notifications
You must be signed in to change notification settings - Fork 247
Fix: CalendarComponent.AddProperty adds the CalendarProperty
#801
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
axunonb
merged 5 commits into
main
from
wip/axunonb/pr/fix-calendarcomponent-addproperty
May 18, 2025
Merged
Changes from 3 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
c10d7fd
Fix: `CalendarComponent.AddProperty` adds the `CalendarProperty`
axunonb d7b3ef1
Enable all properties in `SerializationTests.EventPropertiesSerialized`
axunonb b40a150
Add test for property deserialization including parameters
axunonb 73c3d61
Fix ics file for test containing property with ENCODING=BASE64 parameter
axunonb fbe6c1a
Merge branch 'main' into wip/axunonb/pr/fix-calendarcomponent-addprop…
axunonb File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 |
|---|---|---|
|
|
@@ -32,27 +32,68 @@ public void AddPropertyShouldNotIncludePropertyNameInValue() | |
| } | ||
|
|
||
| [Test] | ||
| [Ignore("Calendar properties aren't being properly serialized")] | ||
| public void PropertySerialization_Tests() | ||
| public void PropertySerialization() | ||
| { | ||
| const string formatted = | ||
| @"FMTTYPE=text/html:<!DOCTYPE HTML PUBLIC ""-//W3C//DTD HTML 3.2//EN"">\n<HTML>\n<HEAD>\n<META NAME=""Generator"" CONTENT=""MS Exchange Server version rmj.rmm.rup.rpr"">\n<TITLE></TITLE>\n</HEAD>\n<BODY>\n<!-- Converted from text/rtf format -->\n\n<P DIR=LTR><SPAN LANG=""en-us""><FONT FACE=""Calibri"">This is some</FONT></SPAN><SPAN LANG=""en-us""><B> <FONT FACE=""Calibri"">HTML</FONT></B></SPAN><SPAN LANG=""en-us""><FONT FACE=""Calibri""></FONT></SPAN><SPAN LANG=""en-us""><U> <FONT FACE=""Calibri"">formatted</FONT></U></SPAN><SPAN LANG=""en-us""><FONT FACE=""Calibri""></FONT></SPAN><SPAN LANG=""en-us""><I> <FONT FACE=""Calibri"">text</FONT></I></SPAN><SPAN LANG=""en-us""><FONT FACE=""Calibri"">.</FONT></SPAN><SPAN LANG=""en-us""></SPAN></P>\n\n</BODY>\n</HTML>"; | ||
|
|
||
| var start = DateTime.Now; | ||
| const string propValue = | ||
| """<html><body>BodyText</body></html>"""; | ||
| var start = DateTime.UtcNow; | ||
| var end = start.AddHours(1); | ||
| var @event = new CalendarEvent | ||
| { | ||
| Start = new CalDateTime(start), | ||
| End = new CalDateTime(end), | ||
| Description = "This is a description", | ||
| }; | ||
| var property = new CalendarProperty("X-ALT-DESC", formatted); | ||
| var property = new CalendarProperty("X-ALT-DESC", propValue); | ||
| // Parameters most not be part of the value | ||
| property.Parameters.Add("FMTTYPE", "text/html"); | ||
| var property2 = new CalendarProperty("ATTENDEE", "mailto:[email protected]"); | ||
| property2.Parameters.Add("MEMBER", "mailto:[email protected],mailto:[email protected]"); | ||
| @event.Properties.Add(property2); | ||
| @event.AddProperty(property); | ||
| var calendar = new Calendar(); | ||
| calendar.Events.Add(@event); | ||
|
|
||
| var serialized = new CalendarSerializer().SerializeToString(calendar); | ||
| Assert.That(serialized, Does.Contain("X-ALT-DESC;")); | ||
| Assert.That(serialized, Does.Contain($"X-ALT-DESC;FMTTYPE=text/html:{propValue}"), | ||
| "Parameter and value should get serialized standard compliant"); | ||
| } | ||
|
|
||
| [Test] | ||
| public void PropertyDeserialization() | ||
| { | ||
| var ics = """ | ||
| BEGIN:VCALENDAR | ||
| PRODID:-//github.com/ical-org/ical.net//NONSGML ical.net 5.0.0.0//EN | ||
| VERSION:2.0 | ||
| BEGIN:VEVENT | ||
| DESCRIPTION:This is a description | ||
| DTEND:20250518T145922Z | ||
| DTSTAMP:20250518T135922Z | ||
| DTSTART:20250518T135922Z | ||
| SEQUENCE:0 | ||
| UID:8f7aa9fc-e9d7-4276-8bf6-915dfe168f0d | ||
| X-ALT-DESC;FMTTYPE=text/html:<html><body>BodyText</body></html> | ||
| X-PROJECTS;PROP=name;PRIO=high:ProjectA,ProjectB | ||
| END:VEVENT | ||
| END:VCALENDAR | ||
| """; | ||
| var calendar = Calendar.Load(ics)!; | ||
| var calEvent = calendar.Events.First(); | ||
| var propDescription = calEvent.Properties.FirstOrDefault(x => x.Name == "X-ALT-DESC")!; | ||
| var propProjects = calEvent.Properties.FirstOrDefault(x => x.Name == "X-PROJECTS")!; | ||
|
|
||
| Assert.Multiple(() => | ||
| { | ||
| Assert.That(propDescription.Parameters, Has.Count.EqualTo(1)); | ||
| Assert.That(propDescription.Value, Is.EqualTo("<html><body>BodyText</body></html>")); | ||
| Assert.That(propDescription.Parameters.FirstOrDefault(p => p.Name == "FMTTYPE")!.Value, Is.EqualTo("text/html")); | ||
|
|
||
| Assert.That(propProjects.Parameters, Has.Count.EqualTo(2), "Parameter list should have 2 elements"); | ||
| Assert.That(propProjects.Value, Is.EqualTo("ProjectA,ProjectB")); | ||
| Assert.That(propProjects.Parameters.FirstOrDefault(p => p.Name == "PROP")!.Value!.ToString(), Is.EqualTo("name")); | ||
| Assert.That(propProjects.Parameters.FirstOrDefault(p => p.Name == "PRIO")!.Value!.ToString(), Is.EqualTo("high")); | ||
| }); | ||
| } | ||
|
|
||
| [Test] | ||
|
|
||
This file contains hidden or 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
This file contains hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should propProject.Values be a list containing ProjectA and ProjectB as elements?