Skip to content
Open
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
// Copyright (c) 2011-2026 Roland Pheasant. All rights reserved.
// Roland Pheasant licenses this file to you under the MIT license.
// See the LICENSE file in the project root for full license information.

using System;
using System.Threading.Tasks;

using Randomizer = Bogus.Randomizer;

using DynamicData.Kernel;
using DynamicData.Tests.Domain;

using FluentAssertions;

using Xunit;
using Xunit.Abstractions;

namespace DynamicData.Tests.Cache;

public partial class TransformSafeAsyncFixture
{
private const int ArgumentValidationSeed = 0x2409_1165;

private readonly Randomizer _argumentRandomizer = new(ArgumentValidationSeed);

public TransformSafeAsyncFixture(ITestOutputHelper output)
=> output.WriteLine($"{nameof(TransformSafeAsyncFixture)} seed: {ArgumentValidationSeed:X8}");

/// <summary>Verifies that the options overload rejects a null factory without subscribing to the source.</summary>
[Theory]
[InlineData(false)]
[InlineData(true)]
public void OptionsOverload_NullFactory_ThrowsBeforeSubscription(bool populateSource)
{
// Arrange
using var source = new SourceCache<Person, string>(static person => person.Key);

if (populateSource)
{
source.AddOrUpdate(new Person(_argumentRandomizer.String2(_argumentRandomizer.Int(5, 20)), _argumentRandomizer.Int(1, 100)));
}

Func<Person, Optional<Person>, string, Task<Person>>? transformFactory = null;

// Act
Action action = () => source.Connect().TransformSafeAsync(transformFactory!, static _ => { }, TransformAsyncOptions.Default);

// Assert
action.Should().Throw<ArgumentNullException>(because: "invalid factories must be rejected before processing any items")
.WithParameterName(nameof(transformFactory));
}
}
4 changes: 2 additions & 2 deletions src/DynamicData.Tests/Cache/TransformSafeAsyncFixture.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reactive;
Expand All @@ -13,7 +13,7 @@

namespace DynamicData.Tests.Cache;

public class TransformSafeAsyncFixture
public partial class TransformSafeAsyncFixture
{
[Fact]
public void ReTransformAll()
Expand Down
4 changes: 4 additions & 0 deletions src/DynamicData/Cache/ObservableCacheEx.TransformSafeAsync.cs
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,10 @@ public static IObservable<IChangeSet<TDestination, TKey>> TransformSafeAsync<TDe
where TSource : notnull
where TKey : notnull
{
source.ThrowArgumentNullExceptionIfNull(nameof(source));
transformFactory.ThrowArgumentNullExceptionIfNull(nameof(transformFactory));
errorHandler.ThrowArgumentNullExceptionIfNull(nameof(errorHandler));

return source.TransformSafeAsync((current, previous, key, cancel) => transformFactory(current, previous, key), errorHandler, options);
}

Expand Down
Loading