diff --git a/src/DynamicData.Tests/Cache/TransformImmutableFixture.cs b/src/DynamicData.Tests/Cache/TransformImmutableFixture.cs index 0ac977e6..4b529b34 100644 --- a/src/DynamicData.Tests/Cache/TransformImmutableFixture.cs +++ b/src/DynamicData.Tests/Cache/TransformImmutableFixture.cs @@ -267,6 +267,26 @@ public void TransformFactoryThrows_ExceptionIsCaptured() results.IsCompleted.Should().BeFalse(); } + // https://github.com/reactivemarbles/DynamicData/issues/925 + [Fact] + public void TDestinationIsValueType_DoesNotThrowException() + { + using var source = new Subject>(); + + using var results = source + .TransformImmutable(transformFactory: static value => value.Length) + .AsAggregator(); + + + source.OnNext(new ChangeSet() + { + new(reason: ChangeReason.Add, key: "Item #1", current: "Item #1", index: 0) + }); + + results.Error.Should().BeNull(); + results.Messages.Count.Should().Be(1, "1 source operation was performed"); + } + private class Item { public static readonly Func IdSelector diff --git a/src/DynamicData/Cache/Internal/TransformImmutable.cs b/src/DynamicData/Cache/Internal/TransformImmutable.cs index 8e866db7..88527020 100644 --- a/src/DynamicData/Cache/Internal/TransformImmutable.cs +++ b/src/DynamicData/Cache/Internal/TransformImmutable.cs @@ -5,6 +5,8 @@ using System.Reactive; using System.Reactive.Linq; +using DynamicData.Kernel; + namespace DynamicData.Cache.Internal; internal sealed class TransformImmutable @@ -40,7 +42,7 @@ public IObservable> Run() current: _transformFactory.Invoke(change.Current), previous: change.Previous.HasValue ? _transformFactory.Invoke(change.Previous.Value) - : default, + : Optional.None(), currentIndex: change.CurrentIndex, previousIndex: change.PreviousIndex)); }