Skip to content

Commit

Permalink
List-to-List MergeManyChangeSets (#780)
Browse files Browse the repository at this point in the history
Implements the MergeManyChangeSets operator for when both the Source and the Child changesets are List ChangeSets.
  • Loading branch information
dwcullop committed Dec 4, 2023
1 parent fba2ebe commit 102fa7a
Show file tree
Hide file tree
Showing 11 changed files with 717 additions and 58 deletions.
21 changes: 9 additions & 12 deletions src/DynamicData.Tests/Domain/Animal.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,26 +15,23 @@ public enum AnimalFamily
Bird
}

public class Animal : AbstractNotifyPropertyChanged
public class Animal(string name, string type, AnimalFamily family, bool include = true) : AbstractNotifyPropertyChanged
{
private bool _includeInResults;
private bool _includeInResults = include;

public Animal(string name, string type, AnimalFamily family)
{
Name = name;
Type = type;
Family = family;
}

public AnimalFamily Family { get; }
public AnimalFamily Family { get; } = family;

public bool IncludeInResults
{
get => _includeInResults;
set => SetAndRaise(ref _includeInResults, value);
}

public string Name { get; }
public string Name { get; } = name;

public string Type { get; } = type;

public string FormalName => $"{Name} the {Type}";

public string Type { get; }
public override string ToString() => $"{FormalName} ({Family})";
}
15 changes: 15 additions & 0 deletions src/DynamicData.Tests/Domain/AnimalOwner.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@

using System;

namespace DynamicData.Tests.Domain;

internal class AnimalOwner(string name) : IDisposable
{
public Guid Id { get; } = Guid.NewGuid();

public string Name => name;

public ISourceList<Animal> Animals { get; } = new SourceList<Animal>();

public void Dispose() => Animals.Dispose();
}
53 changes: 53 additions & 0 deletions src/DynamicData.Tests/Domain/Fakers.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
using Bogus;

namespace DynamicData.Tests.Domain;

internal static class Fakers
{
const int MinAnimals = 3;
#if DEBUG
const int MaxAnimals = 7;
#else
const int MaxAnimals = 23;
#endif

private static readonly string[][] AnimalTypeNames =
[
// Mammal
["Dog", "Cat", "Ferret", "Hamster", "Gerbil", "Cavie", "Mouse", "Pot-Bellied Pig"],

// Reptile
["Corn Snake", "Python", "Gecko", "Skink", "Monitor Lizard", "Chameleon", "Tortoise", "Box Turtle", "Iguana"],

// Fish
["Betta", "Goldfish", "Angelfish", "Catfish", "Guppie", "Mollie", "Neon Tetra", "Platie", "Koi"],

// Amphibian
["Frog", "Toad", "Salamander"],

// Bird
["Parakeet", "Cockatoo", "Parrot", "Finch", "Conure", "Lovebird", "Cockatiel"],
];

public static Faker<Animal> Animal { get; } =
new Faker<Animal>()
.CustomInstantiator(faker =>
{
var family = faker.PickRandom<AnimalFamily>();
var type = faker.PickRandom(AnimalTypeNames[(int)family]);
var name = faker.Commerce.ProductAdjective();
return new Animal(name, type, family);
});

public static Faker<AnimalOwner> AnimalOwner { get; } =
new Faker<AnimalOwner>()
.CustomInstantiator(faker =>
{
var result = new AnimalOwner(faker.Person.FullName);
result.Animals.AddRange(Animal.Generate(faker.Random.Number(MinAnimals, MaxAnimals)));
return result;
});
}
3 changes: 2 additions & 1 deletion src/DynamicData.Tests/DynamicData.Tests.csproj
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<Project Sdk="MSBuild.Sdk.Extras">
<Project Sdk="MSBuild.Sdk.Extras">
<PropertyGroup>
<TargetFrameworks>net6.0;net7.0;net8.0</TargetFrameworks>
<NoWarn>$(NoWarn);CS0618;CA1801;CA1063;CS8767;CS8602;CS8618;IDE1006</NoWarn>
Expand All @@ -12,6 +12,7 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Bogus" Version="34.0.2" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.8.0" />
<PackageReference Include="xunit" Version="$(XunitVersion)" />
<PackageReference Include="xunit.runner.console" Version="$(XunitVersion)" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

namespace DynamicData.Tests.List;

public sealed class MergeManyCacheChangeSetsFixture : IDisposable
public sealed class MergeManyChangeSetsCacheFixture : IDisposable
{
#if DEBUG
const int MarketCount = 3;
Expand All @@ -36,7 +36,7 @@ public sealed class MergeManyCacheChangeSetsFixture : IDisposable

private readonly ChangeSetAggregator<IMarket> _marketListResults;

public MergeManyCacheChangeSetsFixture()
public MergeManyChangeSetsCacheFixture()
{
_marketListResults = _marketList.Connect().AsAggregator();
}
Expand Down Expand Up @@ -749,17 +749,3 @@ private void DisposeMarkets()
_marketList.Clear();
}
}

internal static class Extensions
{
public static T With<T>(this T item, Action<T> action)
{
action(item);
return item;
}

public static IObservable<T> ForceFail<T>(this IObservable<T> source, int count, Exception? e) =>
(e is not null)
? source.Take(count).Concat(Observable.Throw<T>(e))
: source;
}
Loading

0 comments on commit 102fa7a

Please sign in to comment.