using System.Collections;
using Xunit;
namespace XFEExtension.NetCore.AutoConfig.Tests;
public sealed class CollectionTests
{
[Fact]
public void ProfileListSupportsAllMutationPathsAndSnapshotEnumeration()
{
var list = new ProfileList<int>();
list.Add(1);
((IList)list).Add(2);
list.AddRange(new[] { 3, 4 });
list.AddRange(new ReadOnlySpan<int>([5, 6]));
list[0] = 10;
((IList)list)[1] = 20;
list.Insert(2, 30);
((IList)list).Insert(3, 40);
var snapshot = list.ToArray();
list.Remove(30);
((IList)list).Remove(40);
list.RemoveAt(0);
Assert.Equal([10, 20, 30, 40, 3, 4, 5, 6], snapshot);
Assert.Equal([20, 3, 4, 5, 6], list.ToArray());
list.Clear();
Assert.Empty(list);
}
[Fact]
public void ProfileDictionarySupportsAllMutationPathsAndSnapshotEnumeration()
{
var dictionary = new ProfileDictionary<string, int>();
dictionary.Add("one", 1);
dictionary.Add(new KeyValuePair<string, int>("two", 2));
((IDictionary)dictionary).Add("three", 3);
Assert.True(dictionary.TryAdd("four", 4));
dictionary["one"] = 10;
((IDictionary)dictionary)["two"] = 20;
var snapshot = dictionary.ToDictionary();
dictionary.Remove("three");
dictionary.Remove(new KeyValuePair<string, int>("four", 4));
((IDictionary)dictionary).Remove("one");
Assert.Equal(4, snapshot.Count);
Assert.Equal(10, snapshot["one"]);
Assert.Equal(20, dictionary["two"]);
Assert.Single(dictionary);
dictionary.Clear();
Assert.Empty(dictionary);
}
}
using System.Collections;
using Xunit;
namespace XFEExtension.NetCore.AutoConfig.Tests;
public sealed class CollectionTests
{
[Fact]
public void ProfileListSupportsAllMutationPathsAndSnapshotEnumeration()
{
var list = new ProfileList<int>();
list.Add(1);
((IList)list).Add(2);
list.AddRange(new[] { 3, 4 });
list.AddRange(new ReadOnlySpan<int>([5, 6]));
list[0] = 10;
((IList)list)[1] = 20;
list.Insert(2, 30);
((IList)list).Insert(3, 40);
var snapshot = list.ToArray();
list.Remove(30);
((IList)list).Remove(40);
list.RemoveAt(0);
Assert.Equal([10, 20, 30, 40, 3, 4, 5, 6], snapshot);
Assert.Equal([20, 3, 4, 5, 6], list.ToArray());
list.Clear();
Assert.Empty(list);
}
[Fact]
public void ProfileDictionarySupportsAllMutationPathsAndSnapshotEnumeration()
{
var dictionary = new ProfileDictionary<string, int>();
dictionary.Add("one", 1);
dictionary.Add(new KeyValuePair<string, int>("two", 2));
((IDictionary)dictionary).Add("three", 3);
Assert.True(dictionary.TryAdd("four", 4));
dictionary["one"] = 10;
((IDictionary)dictionary)["two"] = 20;
var snapshot = dictionary.ToDictionary();
dictionary.Remove("three");
dictionary.Remove(new KeyValuePair<string, int>("four", 4));
((IDictionary)dictionary).Remove("one");
Assert.Equal(4, snapshot.Count);
Assert.Equal(10, snapshot["one"]);
Assert.Equal(20, dictionary["two"]);
Assert.Single(dictionary);
dictionary.Clear();
Assert.Empty(dictionary);
}
}