Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions Ical.Net.Tests/EncodingProviderTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

#nullable enable
using System;
using System.Runtime.Serialization;
using Ical.Net.Serialization;
using NUnit.Framework;
using EncodingProvider = Ical.Net.Serialization.EncodingProvider;
Expand Down Expand Up @@ -33,7 +34,7 @@ public void Encode_ShouldBeNull_WhenInvalidEncodingIsProvided()
const string encoding = "Invalid-Encoding";
var data = "Hello"u8.ToArray();

Assert.That(GetEncodingProvider().Encode(encoding, data), Is.Null);
Assert.That(() => GetEncodingProvider().Encode(encoding, data), Throws.TypeOf<SerializationException>());
}

[Test]
Expand All @@ -53,7 +54,7 @@ public void Decode_ShouldBeNull_WhenInvalidEncodingIsProvided()
const string encoding = "Invalid-Encoding";
const string data = "Hello";

Assert.That(GetEncodingProvider().DecodeString(encoding, data), Is.Null);
Assert.That(() => GetEncodingProvider().DecodeString(encoding, data), Throws.TypeOf<SerializationException>());
}

[Test]
Expand Down
2 changes: 1 addition & 1 deletion Ical.Net.Tests/PeriodListWrapperTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ public void AddRPeriod_ShouldCreate_DedicatePeriodList()
]);

var serializer = new CalendarSerializer(cal);
var serialized = serializer.SerializeToString();
var serialized = serializer.SerializeToString()!;
// Assign the deserialized event
cal = Calendar.Load(serialized)!;
evt = cal.Events[0];
Expand Down
2 changes: 1 addition & 1 deletion Ical.Net.Tests/RecurrenceTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3940,7 +3940,7 @@ public void TestDtStartTimezone(string? tzId)
[TestCase(1, TestMaxIncrementCountWithoutGaps, false)]
public void TestMaxIncrementCount(int? limit, string ical, bool expectException)
{
var cal = Calendar.Load(ical);
var cal = Calendar.Load(ical)!;

var options = new EvaluationOptions
{
Expand Down
8 changes: 4 additions & 4 deletions Ical.Net.Tests/RecurrenceWithExDateTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public void ShouldNotOccurOnLocalExceptionDate(bool useExDateWithTime)

// Act
var serializer = new CalendarSerializer();
var ics = serializer.SerializeToString(calendar);
var ics = serializer.SerializeToString(calendar)!;

var deserializedCalendar = Calendar.Load(ics)!;
var occurrences = deserializedCalendar.GetOccurrences<CalendarEvent>().ToList();
Expand Down Expand Up @@ -102,7 +102,7 @@ public void ShouldNotOccurOnUtcExceptionDate()
var serializer = new CalendarSerializer();
ics = serializer.SerializeToString(cal);
// serialize and deserialize to ensure the exclusion dates de/serialized
cal = Calendar.Load(new CalendarSerializer(cal).SerializeToString())!;
cal = Calendar.Load(new CalendarSerializer(cal).SerializeToString()!)!;

// Start date: 2024-10-19 at 18:00 (GMT Standard Time)
// Recurrence: Every hour, 4 occurrences
Expand Down Expand Up @@ -150,7 +150,7 @@ public void MultipleExclusionDatesSameTimeZoneShouldBeExcluded()
var serializer = new CalendarSerializer();
ics = serializer.SerializeToString(cal);
// serialize and deserialize to ensure the exclusion dates de/serialized
cal = Calendar.Load(new CalendarSerializer(cal).SerializeToString())!;
cal = Calendar.Load(new CalendarSerializer(cal).SerializeToString()!)!;

// Occurrences:
// 2023-10-25 09:00 (UTC Offset: +0200)
Expand Down Expand Up @@ -206,7 +206,7 @@ public void MultipleExclusionDatesDifferentZoneShouldBeExcluded()

var cal = Calendar.Load(ics)!;
// serialize and deserialize to ensure the exclusion dates de/serialized
cal = Calendar.Load(new CalendarSerializer(cal).SerializeToString())!;
cal = Calendar.Load(new CalendarSerializer(cal).SerializeToString()!)!;
var occurrences = cal.GetOccurrences<CalendarEvent>().ToList();

// Occurrences:
Expand Down
8 changes: 3 additions & 5 deletions Ical.Net/Calendar.cs
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ public override int GetHashCode()
{
unchecked
{
var hashCode = Name?.GetHashCode() ?? 0;
var hashCode = Name.GetHashCode();
hashCode = (hashCode * 397) ^ CollectionHelpers.GetHashCode(UniqueComponents);
hashCode = (hashCode * 397) ^ CollectionHelpers.GetHashCode(Events);
hashCode = (hashCode * 397) ^ CollectionHelpers.GetHashCode(Todos);
Expand Down Expand Up @@ -227,7 +227,7 @@ public virtual IEnumerable<Occurrence> GetOccurrences<T>(CalDateTime? startTime
// These are the UID/RECURRENCE-ID combinations that replace other occurrences.
var recurrenceIdsAndUids = this.Children.OfType<IRecurrable>()
.Where(r => r.RecurrenceId != null)
.Select(r => new { (r as IUniqueComponent).Uid, Dt = r.RecurrenceId!.Value })
.Select(r => new { (r as IUniqueComponent)?.Uid, Dt = r.RecurrenceId!.Value })
.Where(r => r.Uid != null)
.ToDictionary(x => x);

Expand Down Expand Up @@ -290,14 +290,12 @@ public virtual void MergeWith(IMergeable obj)
return;
}

Name ??= c.Name;

Method = c.Method;
Version = c.Version;
ProductId = c.ProductId;
Scale = c.Scale;

foreach (var p in c.Properties.Where(p => p.Name != null && !Properties.ContainsKey(p.Name)))
foreach (var p in c.Properties.Where(p => !Properties.ContainsKey(p.Name)))
{
Properties.Add(p);
}
Expand Down
4 changes: 2 additions & 2 deletions Ical.Net/CalendarCollection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ private FreeBusy CombineFreeBusy(FreeBusy? main, FreeBusy current)
return this.Aggregate<Calendar, FreeBusy?>(null, (current, iCal) =>
{
var freeBusy = iCal.GetFreeBusy(freeBusyRequest);
return current is null ? freeBusy : CombineFreeBusy(current, freeBusy);
return current is null || freeBusy is null ? freeBusy : CombineFreeBusy(current, freeBusy);
});
}

Expand All @@ -83,7 +83,7 @@ private FreeBusy CombineFreeBusy(FreeBusy? main, FreeBusy current)
return this.Aggregate<Calendar, FreeBusy?>(null, (current, iCal) =>
{
var freeBusy = iCal.GetFreeBusy(organizer, contacts, fromInclusive, toExclusive);
return current is null ? freeBusy : CombineFreeBusy(current, freeBusy);
return current is null || freeBusy is null ? freeBusy : CombineFreeBusy(current, freeBusy);
});
}

Expand Down
2 changes: 1 addition & 1 deletion Ical.Net/CalendarComponents/Alarm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ private void AddRepeatedItems(List<AlarmOccurrence> occurrences)
for (var i = 0; i < len; i++)
{
var ao = occurrences[i];
if (ao?.DateTime == null || ao.Component == null)
if (ao.DateTime == null || ao.Component == null)
{
continue;
}
Expand Down
2 changes: 1 addition & 1 deletion Ical.Net/CalendarComponents/Todo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@
public virtual IList<string> Resources
{
get => Properties.GetMany<string>("RESOURCES");
set => Properties.Set("RESOURCES", value ?? new List<string>());
set => Properties.Set("RESOURCES", value);

Check warning on line 88 in Ical.Net/CalendarComponents/Todo.cs

View check run for this annotation

Codecov / codecov/patch

Ical.Net/CalendarComponents/Todo.cs#L88

Added line #L88 was not covered by tests
}

/// <summary>
Expand Down
2 changes: 1 addition & 1 deletion Ical.Net/CalendarComponents/VTimeZone.cs
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,7 @@
return;
}

_nodaZone = DateUtil.GetZone(value);

Check warning on line 327 in Ical.Net/CalendarComponents/VTimeZone.cs

View workflow job for this annotation

GitHub Actions / coverage

Possible null reference argument for parameter 'tzId' in 'DateTimeZone DateUtil.GetZone(string tzId)'.

Check warning on line 327 in Ical.Net/CalendarComponents/VTimeZone.cs

View workflow job for this annotation

GitHub Actions / coverage

Possible null reference argument for parameter 'tzId' in 'DateTimeZone DateUtil.GetZone(string tzId)'.

Check warning on line 327 in Ical.Net/CalendarComponents/VTimeZone.cs

View workflow job for this annotation

GitHub Actions / tests

Possible null reference argument for parameter 'tzId' in 'DateTimeZone DateUtil.GetZone(string tzId)'.

Check warning on line 327 in Ical.Net/CalendarComponents/VTimeZone.cs

View workflow job for this annotation

GitHub Actions / tests

Possible null reference argument for parameter 'tzId' in 'DateTimeZone DateUtil.GetZone(string tzId)'.
var id = _nodaZone.Id;
if (string.IsNullOrWhiteSpace(id))
{
Expand Down Expand Up @@ -383,7 +383,7 @@
{
unchecked
{
var hashCode = Name?.GetHashCode() ?? 0;
var hashCode = Name.GetHashCode();
hashCode = (hashCode * 397) ^ (TzId?.GetHashCode() ?? 0);
hashCode = (hashCode * 397) ^ (Url?.GetHashCode() ?? 0);
return hashCode;
Expand Down
2 changes: 1 addition & 1 deletion Ical.Net/Collections/Proxies/GroupedValueListProxy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@
foreach (var obj in _realObject)
{
// Get the number of items of the target value i this object
var count = obj.Values?.OfType<TNewValue>().Count() ?? 0;
var count = obj.Values.OfType<TNewValue>().Count();

Check warning on line 67 in Ical.Net/Collections/Proxies/GroupedValueListProxy.cs

View check run for this annotation

Codecov / codecov/patch

Ical.Net/Collections/Proxies/GroupedValueListProxy.cs#L67

Added line #L67 was not covered by tests

// Perform some action on this item
if (!action(obj, i, count))
Expand Down
4 changes: 2 additions & 2 deletions Ical.Net/DataTypes/Attachment.cs
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,8 @@ public override int GetHashCode()
unchecked
{
var hashCode = Uri?.GetHashCode() ?? 0;
hashCode = (hashCode * 397) ^ (CollectionHelpers.GetHashCode(Data));
hashCode = (hashCode * 397) ^ (ValueEncoding?.GetHashCode() ?? 0);
hashCode = (hashCode * 397) ^ (Data != null ? CollectionHelpers.GetHashCode(Data) : 0);
hashCode = (hashCode * 397) ^ (ValueEncoding.GetHashCode());
return hashCode;
}
}
Expand Down
2 changes: 1 addition & 1 deletion Ical.Net/DataTypes/Occurrence.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
{
unchecked
{
return ((Period?.GetHashCode() ?? 0) * 397) ^ (Source?.GetHashCode() ?? 0);
return ((Period.GetHashCode()) * 397) ^ (Source.GetHashCode());

Check warning on line 44 in Ical.Net/DataTypes/Occurrence.cs

View check run for this annotation

Codecov / codecov/patch

Ical.Net/DataTypes/Occurrence.cs#L44

Added line #L44 was not covered by tests
}
}

Expand Down
4 changes: 2 additions & 2 deletions Ical.Net/DataTypes/PeriodList.cs
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ public void Insert(int index, Period item)
}

/// <inheritdoc/>
public void RemoveAt(int index) => Periods?.RemoveAt(index);
public void RemoveAt(int index) => Periods.RemoveAt(index);

/// <summary>
/// Adds a <see cref="Period"/> to the list if it does not already exist.<br/>
Expand Down Expand Up @@ -159,7 +159,7 @@ public void Add(CalDateTime dt)
public bool Contains(Period item) => Periods.Contains(item);

/// <inheritdoc/>
public void CopyTo(Period[] array, int arrayIndex) => Periods?.CopyTo(array, arrayIndex);
public void CopyTo(Period[] array, int arrayIndex) => Periods.CopyTo(array, arrayIndex);

/// <inheritdoc/>
public IEnumerator<Period> GetEnumerator() => Periods.GetEnumerator();
Expand Down
2 changes: 1 addition & 1 deletion Ical.Net/DataTypes/Trigger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@
{
var hashCode = _mDateTime?.GetHashCode() ?? 0;
hashCode = (hashCode * 397) ^ _mDuration.GetHashCode();
hashCode = (hashCode * 397) ^ _mRelated?.GetHashCode() ?? 0;
hashCode = (hashCode * 397) ^ _mRelated.GetHashCode();

Check warning on line 122 in Ical.Net/DataTypes/Trigger.cs

View check run for this annotation

Codecov / codecov/patch

Ical.Net/DataTypes/Trigger.cs#L122

Added line #L122 was not covered by tests
return hashCode;
}
}
Expand Down
8 changes: 4 additions & 4 deletions Ical.Net/Evaluation/RecurrencePatternEvaluator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -100,10 +100,10 @@ private RecurrencePattern ProcessRecurrencePattern(CalDateTime referenceDate)

// Pre-order those BY values that don't allow for negative values. Those with negative values can only
// be ordered once the individual position is known.
if (r.BySecond?.Count > 0) r.BySecond = r.BySecond.OrderBy(x => x).ToList();
if (r.ByMinute?.Count > 0) r.ByMinute = r.ByMinute.OrderBy(x => x).ToList();
if (r.ByHour?.Count > 0) r.ByHour = r.ByHour.OrderBy(x => x).ToList();
if (r.ByMonth?.Count > 0) r.ByMonth = r.ByMonth.OrderBy(x => x).ToList();
if (r.BySecond.Count > 0) r.BySecond = r.BySecond.OrderBy(x => x).ToList();
if (r.ByMinute.Count > 0) r.ByMinute = r.ByMinute.OrderBy(x => x).ToList();
if (r.ByHour.Count > 0) r.ByHour = r.ByHour.OrderBy(x => x).ToList();
if (r.ByMonth.Count > 0) r.ByMonth = r.ByMonth.OrderBy(x => x).ToList();

return r;
}
Expand Down
2 changes: 1 addition & 1 deletion Ical.Net/Serialization/ComponentSerializer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public ComponentSerializer(SerializationContext ctx) : base(ctx) { }
foreach (var p in properties)
{
// Get a serializer for each property.
var serializer = sf?.Build(p.GetType(), SerializationContext) as IStringSerializer;
var serializer = sf.Build(p.GetType(), SerializationContext) as IStringSerializer;
var val = serializer?.SerializeToString(p);
if (val != null) sb.Append(val);
}
Expand Down
2 changes: 1 addition & 1 deletion Ical.Net/Serialization/DataTypes/DataTypeSerializer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ protected DataTypeSerializer(SerializationContext ctx) : base(ctx) { }
return null;
}

if (SerializationContext?.Peek() is ICalendarObject associatedObject)
if (SerializationContext.Peek() is ICalendarObject associatedObject)
{
dt.AssociatedObject = associatedObject;
}
Expand Down
2 changes: 1 addition & 1 deletion Ical.Net/Serialization/DataTypes/DateTimeSerializer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public DateTimeSerializer(SerializationContext ctx) : base(ctx) { }
var value = tr.ReadToEnd();

// CalDateTime is defined as the Target type
var parent = SerializationContext?.Peek();
var parent = SerializationContext.Peek();

// The associated object is an ICalendarObject of type CalendarProperty
// that contains any timezone ("TZID" property) deserialized in a prior step
Expand Down
15 changes: 7 additions & 8 deletions Ical.Net/Serialization/DataTypes/EncodableDataTypeSerializer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,8 @@

// Return the value in the current encoding
var encodingStack = GetService<EncodingStack>();
return encodingStack?.Current == null
? value
: Encode(dt, encodingStack.Current.GetBytes(value));

return Encode(dt, encodingStack.Current.GetBytes(value));

Check warning on line 32 in Ical.Net/Serialization/DataTypes/EncodableDataTypeSerializer.cs

View check run for this annotation

Codecov / codecov/patch

Ical.Net/Serialization/DataTypes/EncodableDataTypeSerializer.cs#L32

Added line #L32 was not covered by tests
}

protected string? Encode(IEncodableDataType dt, byte[]? data)
Expand All @@ -44,11 +43,11 @@
{
// Default to the current encoding
var encodingStack = GetService<EncodingStack>();
return encodingStack?.Current.GetString(data);
return encodingStack.Current.GetString(data);

Check warning on line 46 in Ical.Net/Serialization/DataTypes/EncodableDataTypeSerializer.cs

View check run for this annotation

Codecov / codecov/patch

Ical.Net/Serialization/DataTypes/EncodableDataTypeSerializer.cs#L46

Added line #L46 was not covered by tests
}

var encodingProvider = GetService<IEncodingProvider>();
return encodingProvider?.Encode(dt.Encoding, data);
return encodingProvider.Encode(dt.Encoding, data);
}

protected string? Decode(IEncodableDataType dt, string value)
Expand All @@ -66,7 +65,7 @@

// Default to the current encoding
var encodingStack = GetService<EncodingStack>();
return encodingStack?.Current.GetString(data);
return encodingStack.Current.GetString(data);
}

protected byte[]? DecodeData(IEncodableDataType dt, string? value)
Expand All @@ -80,10 +79,10 @@
{
// Default to the current encoding
var encodingStack = GetService<EncodingStack>();
return encodingStack?.Current.GetBytes(value);
return encodingStack.Current.GetBytes(value);
}

var encodingProvider = GetService<IEncodingProvider>();
return encodingProvider?.DecodeData(dt.Encoding, value);
return encodingProvider.DecodeData(dt.Encoding, value);
}
}
4 changes: 2 additions & 2 deletions Ical.Net/Serialization/DataTypes/EnumSerializer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public EnumSerializer(Type enumType, SerializationContext ctx) : base(ctx)
{
try
{
if (SerializationContext?.Peek() is ICalendarObject calObject)
if (SerializationContext.Peek() is ICalendarObject calObject)
{
// Encode the value as needed.
var dt = new EncodableDataType
Expand All @@ -53,7 +53,7 @@ public EnumSerializer(Type enumType, SerializationContext ctx) : base(ctx)

try
{
if (SerializationContext?.Peek() is ICalendarObject obj)
if (SerializationContext.Peek() is ICalendarObject obj)
{
// Decode the value, if necessary!
var dt = new EncodableDataType
Expand Down
4 changes: 2 additions & 2 deletions Ical.Net/Serialization/DataTypes/IntegerSerializer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public IntegerSerializer(SerializationContext ctx) : base(ctx) { }
{
var i = Convert.ToInt32(obj);

if (SerializationContext?.Peek() is ICalendarObject calObject)
if (SerializationContext.Peek() is ICalendarObject calObject)
{
// Encode the value as needed.
var dt = new EncodableDataType
Expand All @@ -47,7 +47,7 @@ public IntegerSerializer(SerializationContext ctx) : base(ctx) { }

try
{
if (SerializationContext?.Peek() is ICalendarObject obj)
if (SerializationContext.Peek() is ICalendarObject obj)
{
// Decode the value, if necessary!
var dt = new EncodableDataType
Expand Down
4 changes: 2 additions & 2 deletions Ical.Net/Serialization/DataTypes/PeriodSerializer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public PeriodSerializer(SerializationContext ctx) : base(ctx) { }
}

// Push the period onto the serialization context stack
SerializationContext?.Push(p);
SerializationContext.Push(p);

try
{
Expand Down Expand Up @@ -71,7 +71,7 @@ public PeriodSerializer(SerializationContext ctx) : base(ctx) { }
finally
{
// Pop the period off the serialization context stack
SerializationContext?.Pop();
SerializationContext.Pop();
}
}

Expand Down
6 changes: 3 additions & 3 deletions Ical.Net/Serialization/DataTypes/RequestStatusSerializer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
try
{
var factory = GetService<ISerializerFactory>();
var serializer = factory?.Build(typeof(StatusCode), SerializationContext) as IStringSerializer;
var serializer = factory.Build(typeof(StatusCode), SerializationContext) as IStringSerializer;

Check warning on line 43 in Ical.Net/Serialization/DataTypes/RequestStatusSerializer.cs

View check run for this annotation

Codecov / codecov/patch

Ical.Net/Serialization/DataTypes/RequestStatusSerializer.cs#L43

Added line #L43 was not covered by tests
if (serializer == null)
{
return null;
Expand All @@ -60,7 +60,7 @@
finally
{
// Pop the object off the serialization stack
SerializationContext?.Pop();
SerializationContext.Pop();

Check warning on line 63 in Ical.Net/Serialization/DataTypes/RequestStatusSerializer.cs

View check run for this annotation

Codecov / codecov/patch

Ical.Net/Serialization/DataTypes/RequestStatusSerializer.cs#L63

Added line #L63 was not covered by tests
}
}
catch
Expand Down Expand Up @@ -128,7 +128,7 @@
finally
{
// Pop the object off the serialization stack
SerializationContext?.Pop();
SerializationContext.Pop();
}
return null;
}
Expand Down
Loading
Loading