Skip to content

Commit

Permalink
Added more concurrent collections
Browse files Browse the repository at this point in the history
  • Loading branch information
Romfos committed Jan 8, 2025
1 parent c2338c1 commit 99994b6
Show file tree
Hide file tree
Showing 5 changed files with 70 additions and 0 deletions.
34 changes: 34 additions & 0 deletions src/TestFixture.Tests/CollectionsTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,40 @@ public void IImmutableQueueTest()
fixture.Create<IImmutableQueue<int>>().Should().BeEquivalentTo(expected);
}

[TestMethod]
public void ConcurrentBagTest()
{
var expected = new List<int> { 1, 2, 3 };
var fixture = new TestFixtureBuilder()
.With(1, 2, 3)
.Build();

fixture.Create<ConcurrentBag<int>>().Should().BeEquivalentTo(expected);
}


[TestMethod]
public void ConcurrentQueueFactoryTest()
{
var expected = new List<int> { 1, 2, 3 };
var fixture = new TestFixtureBuilder()
.With(1, 2, 3)
.Build();

fixture.Create<ConcurrentQueue<int>>().Should().BeEquivalentTo(expected);
}

[TestMethod]
public void ConcurrentStackTest()
{
var expected = new List<int> { 1, 2, 3 };
var fixture = new TestFixtureBuilder()
.With(1, 2, 3)
.Build();

fixture.Create<ConcurrentStack<int>>().Should().BeEquivalentTo(expected);
}

#if NET
[TestMethod]
public void FrozenDictionaryTest()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
using System.Collections.Concurrent;

namespace TestFixture.Factories.Collections.Concurrent;

internal sealed class ConcurrentBagFactory<T> : IFactory
{
public object Create(Fixture fixture)
{
return new ConcurrentBag<T>(fixture.Create<T>(3));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
using System.Collections.Concurrent;

namespace TestFixture.Factories.Collections.Concurrent;

internal sealed class ConcurrentQueueFactory<T> : IFactory
{
public object Create(Fixture fixture)
{
return new ConcurrentQueue<T>(fixture.Create<T>(3));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
using System.Collections.Concurrent;

namespace TestFixture.Factories.Collections.Concurrent;

internal sealed class ConcurrentStackFactory<T> : IFactory
{
public object Create(Fixture fixture)
{
return new ConcurrentStack<T>(fixture.Create<T>(3));
}
}
3 changes: 3 additions & 0 deletions src/TestFixture/SharedFixtureState.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,9 @@ internal static class SharedFixtureState
new GenericFactory(typeof(Stack<>), typeof(StackFactory<>)),

new GenericFactory(typeof(ConcurrentDictionary<,>), typeof(ConcurrentDictionaryFactory<,>)),
new GenericFactory(typeof(ConcurrentQueue<>), typeof(ConcurrentQueueFactory<>)),
new GenericFactory(typeof(ConcurrentBag<>), typeof(ConcurrentBagFactory<>)),
new GenericFactory(typeof(ConcurrentStack<>), typeof(ConcurrentStackFactory<>)),

new GenericFactory(typeof(IEnumerable<>), typeof(ListFactory<>)),
new GenericFactory(typeof(IAsyncEnumerable<>), typeof(AsyncEnumerableFactory<>)),
Expand Down

0 comments on commit 99994b6

Please sign in to comment.