From 4d9444ebb0451f4f5f9d1536044ab3f47355e2da Mon Sep 17 00:00:00 2001
From: Joyless <65855333+Joy-less@users.noreply.github.com>
Date: Sun, 2 Feb 2025 21:52:20 +0000
Subject: [PATCH 1/3] Migrate to Shouldly
---
.../BitFaster.Caching.UnitTests.Std.csproj | 8 +-
.../DurationTests.cs | 16 +-
.../Atomic/AsyncAtomicFactoryTests.cs | 48 +-
.../Atomic/AtomicFactoryAsyncCacheTests.cs | 85 +-
.../Atomic/AtomicFactoryCacheTests.cs | 84 +-
.../AtomicFactoryScopedAsyncCacheTests.cs | 23 +-
.../Atomic/AtomicFactoryScopedCacheTests.cs | 29 +-
.../Atomic/AtomicFactorySoakTests.cs | 5 +-
.../Atomic/AtomicFactoryTests.cs | 59 +-
.../ConcurrentDictionaryExtensionTests.cs | 45 +-
.../ScopedAsyncAtomicFactorySoakTests.cs | 8 +-
.../Atomic/ScopedAsyncAtomicFactoryTests.cs | 58 +-
.../Atomic/ScopedAtomicFactorySoakTests.cs | 8 +-
.../Atomic/ScopedAtomicFactoryTests.cs | 57 +-
.../BitFaster.Caching.UnitTests.csproj | 12 +-
BitFaster.Caching.UnitTests/BitOpsTests.cs | 25 +-
.../Buffers/MpmcBoundedBufferSoakTests.cs | 6 +-
.../Buffers/MpmcBoundedBufferTests.cs | 41 +-
.../Buffers/MpscBoundedBufferSoakTests.cs | 6 +-
.../Buffers/MpscBoundedBufferTests.cs | 62 +-
.../Buffers/StripedMpscBufferTests.cs | 33 +-
.../CacheEventProxyBaseTests.cs | 22 +-
.../CacheEventsTests.cs | 3 +-
.../CacheMetricsTests.cs | 5 +-
.../CachePolicyTests.cs | 10 +-
BitFaster.Caching.UnitTests/CacheTests.cs | 27 +-
.../ConcurrentDictionarySizeTests.cs | 6 +-
.../Counters/CounterSoakTests.cs | 4 +-
.../Counters/StripedLongAdderTests.cs | 6 +-
BitFaster.Caching.UnitTests/Disposable.cs | 4 +-
.../DisposableValueFactory.cs | 8 +-
BitFaster.Caching.UnitTests/DurationTests.cs | 46 +-
.../ExpireAfterAccessTests.cs | 11 +-
.../ExpireAfterWriteTests.cs | 11 +-
.../Lfu/CmSketchTests.cs | 37 +-
.../Lfu/ConcurrentLfuBuilderTests.cs | 120 +-
.../Lfu/ConcurrentLfuCoreTests.cs | 62 +-
.../Lfu/ConcurrentLfuSoakTests.cs | 24 +-
.../Lfu/ConcurrentLfuTests.cs | 172 ++-
.../Lfu/ConcurrentTLfuSoakTests.cs | 3 -
.../Lfu/ConcurrentTLfuTests.cs | 45 +-
.../Lfu/LfuCapacityPartitionTests.cs | 24 +-
.../Lfu/LfuInfoTests.cs | 6 +-
.../Lfu/LfuNodeListTests.cs | 12 +-
.../Lfu/TestScheduler.cs | 4 -
.../Lfu/TimerWheelTests.cs | 56 +-
.../Lru/AfterAccessPolicyTests.cs | 34 +-
.../Lru/CacheExtTests.cs | 20 +-
.../Lru/CapacityPartitionExtensionsTests.cs | 14 +-
.../Lru/ClassicLruTests.cs | 187 ++-
.../Lru/ConcurrentLruAfterAccessTests.cs | 36 +-
.../Lru/ConcurrentLruAfterDiscreteTests.cs | 38 +-
.../Lru/ConcurrentLruBuilderTests.cs | 1114 ++++++++---------
.../Lru/ConcurrentLruSoakTests.cs | 16 +-
.../Lru/ConcurrentLruTests.cs | 330 ++---
.../Lru/ConcurrentTLruTests.cs | 60 +-
.../Lru/DiscretePolicyTests.cs | 34 +-
.../Lru/DisposableItem.cs | 2 -
.../Lru/DisposableValueFactory.cs | 4 +-
.../Lru/EqualCapacityPartitionTests.cs | 14 +-
.../Lru/FastConcurrentLruTests.cs | 14 +-
.../Lru/FastConcurrentTLruTests.cs | 17 +-
.../Lru/FavorWarmPartitionTests.cs | 18 +-
.../Lru/LruInfoTests.cs | 6 +-
.../Lru/LruItemMemoryLayoutDumps.cs | 3 +-
.../Lru/LruPolicyTests.cs | 26 +-
.../Lru/NoTelemetryPolicyTests.cs | 22 +-
.../Lru/StopwatchTickConverterTests.cs | 4 +-
.../Lru/TLruTickCount64PolicyTests .cs | 38 +-
.../Lru/TelemetryPolicyTests.cs | 52 +-
.../Lru/TestCapacityPartition.cs | 7 +-
.../Lru/TlruDateTimePolicyTests.cs | 30 +-
.../Lru/TlruStopwatchPolicyTests.cs | 38 +-
.../Lru/TlruTicksPolicyTests.cs | 34 +-
.../Lru/ValueFactory.cs | 5 +-
.../ReferenceCountTests.cs | 14 +-
.../Retry/DelayedMessageBus.cs | 6 +-
.../Retry/RetryFact.cs | 4 +-
.../Scheduler/BackgroundSchedulerTests.cs | 20 +-
.../Scheduler/ForegroundSchedulerTests.cs | 20 +-
.../Scheduler/NullSchedulerTests.cs | 19 +-
.../Scheduler/SchedulerTestExtensions.cs | 3 -
.../Scheduler/ThreadPoolSchedulerTests.cs | 16 +-
.../ScopedAsyncCacheTestBase.cs | 74 +-
.../ScopedAsyncCacheTests.cs | 12 +-
.../ScopedCacheSoakTests.cs | 4 +-
.../ScopedCacheTestBase.cs | 71 +-
.../ScopedCacheTests.cs | 14 +-
.../ScopedSoakTests.cs | 10 +-
BitFaster.Caching.UnitTests/ScopedTests.cs | 22 +-
.../SingletonCacheTests.cs | 24 +-
BitFaster.Caching.UnitTests/Threaded.cs | 3 -
BitFaster.Caching.UnitTests/Timed.cs | 4 +-
BitFaster.Caching.UnitTests/TypePropsTests.cs | 4 +-
94 files changed, 1944 insertions(+), 2063 deletions(-)
diff --git a/BitFaster.Caching.UnitTests.Std/BitFaster.Caching.UnitTests.Std.csproj b/BitFaster.Caching.UnitTests.Std/BitFaster.Caching.UnitTests.Std.csproj
index 1f91474b..1faad828 100644
--- a/BitFaster.Caching.UnitTests.Std/BitFaster.Caching.UnitTests.Std.csproj
+++ b/BitFaster.Caching.UnitTests.Std/BitFaster.Caching.UnitTests.Std.csproj
@@ -10,16 +10,16 @@
all
runtime; build; native; contentfiles; analyzers; buildtransitive
-
+
-
+
-
+
all
runtime; build; native; contentfiles; analyzers; buildtransitive
-
+
diff --git a/BitFaster.Caching.UnitTests.Std/DurationTests.cs b/BitFaster.Caching.UnitTests.Std/DurationTests.cs
index 7a58df9f..e67fd624 100644
--- a/BitFaster.Caching.UnitTests.Std/DurationTests.cs
+++ b/BitFaster.Caching.UnitTests.Std/DurationTests.cs
@@ -2,9 +2,9 @@
using System.Diagnostics;
using System.Runtime.InteropServices;
using BitFaster.Caching.Lru;
-using FluentAssertions;
using Xunit;
using Xunit.Abstractions;
+using Shouldly;
namespace BitFaster.Caching.UnitTests.Std
{
@@ -25,13 +25,11 @@ public void SinceEpoch()
// On .NET Standard, only windows uses TickCount64
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
{
- Duration.SinceEpoch().raw.Should().BeCloseTo(Duration.GetTickCount64(), 15);
+ Duration.SinceEpoch().raw.ShouldBe(Duration.GetTickCount64());
}
else
{
- // eps is 1/200 of a second
- ulong eps = (ulong)(Stopwatch.Frequency / 200);
- Duration.SinceEpoch().raw.Should().BeCloseTo(Stopwatch.GetTimestamp(), eps);
+ Duration.SinceEpoch().raw.ShouldBe(Stopwatch.GetTimestamp());
}
}
@@ -41,12 +39,12 @@ public void ToTimeSpan()
// On .NET Standard, only windows uses TickCount64
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
{
- new Duration(1000).ToTimeSpan().Should().BeCloseTo(TimeSpan.FromMilliseconds(1000), TimeSpan.FromMilliseconds(10));
+ new Duration(1000).ToTimeSpan().ShouldBe(TimeSpan.FromMilliseconds(1000), TimeSpan.FromMilliseconds(10));
}
else
{
// for Stopwatch.GetTimestamp() this is number of ticks
- new Duration(1 * Stopwatch.Frequency).ToTimeSpan().Should().BeCloseTo(TimeSpan.FromSeconds(1), TimeSpan.FromMilliseconds(10));
+ new Duration(1 * Stopwatch.Frequency).ToTimeSpan().ShouldBe(TimeSpan.FromSeconds(1), TimeSpan.FromMilliseconds(10));
}
}
@@ -57,12 +55,12 @@ public void FromTimeSpan()
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
{
Duration.FromTimeSpan(TimeSpan.FromSeconds(1)).raw
- .Should().Be((long)TimeSpan.FromSeconds(1).TotalMilliseconds);
+ .ShouldBe((long)TimeSpan.FromSeconds(1).TotalMilliseconds);
}
else
{
Duration.FromTimeSpan(TimeSpan.FromSeconds(1)).raw
- .Should().Be(Stopwatch.Frequency);
+ .ShouldBe(Stopwatch.Frequency);
}
}
diff --git a/BitFaster.Caching.UnitTests/Atomic/AsyncAtomicFactoryTests.cs b/BitFaster.Caching.UnitTests/Atomic/AsyncAtomicFactoryTests.cs
index fdb8a6f8..30774ed2 100644
--- a/BitFaster.Caching.UnitTests/Atomic/AsyncAtomicFactoryTests.cs
+++ b/BitFaster.Caching.UnitTests/Atomic/AsyncAtomicFactoryTests.cs
@@ -2,7 +2,7 @@
using System.Threading;
using System.Threading.Tasks;
using BitFaster.Caching.Atomic;
-using FluentAssertions;
+using Shouldly;
using Xunit;
namespace BitFaster.Caching.UnitTests.Atomic
@@ -14,8 +14,8 @@ public void DefaultCtorValueIsNotCreated()
{
var a = new AsyncAtomicFactory();
- a.IsValueCreated.Should().BeFalse();
- a.ValueIfCreated.Should().Be(0);
+ a.IsValueCreated.ShouldBeFalse();
+ a.ValueIfCreated.ShouldBe(0);
}
[Fact]
@@ -23,28 +23,28 @@ public void WhenValuePassedToCtorValueIsStored()
{
var a = new AsyncAtomicFactory(1);
- a.ValueIfCreated.Should().Be(1);
- a.IsValueCreated.Should().BeTrue();
+ a.ValueIfCreated.ShouldBe(1);
+ a.IsValueCreated.ShouldBeTrue();
}
[Fact]
public async Task WhenValueCreatedValueReturned()
{
var a = new AsyncAtomicFactory();
- (await a.GetValueAsync(1, k => Task.FromResult(2))).Should().Be(2);
+ (await a.GetValueAsync(1, k => Task.FromResult(2))).ShouldBe(2);
- a.ValueIfCreated.Should().Be(2);
- a.IsValueCreated.Should().BeTrue();
+ a.ValueIfCreated.ShouldBe(2);
+ a.IsValueCreated.ShouldBeTrue();
}
[Fact]
public async Task WhenValueCreatedWithArgValueReturned()
{
var a = new AsyncAtomicFactory();
- (await a.GetValueAsync(1, (k, a) => Task.FromResult(k + a), 7)).Should().Be(8);
+ (await a.GetValueAsync(1, (k, a) => Task.FromResult(k + a), 7)).ShouldBe(8);
- a.ValueIfCreated.Should().Be(8);
- a.IsValueCreated.Should().BeTrue();
+ a.ValueIfCreated.ShouldBe(8);
+ a.IsValueCreated.ShouldBeTrue();
}
[Fact]
@@ -52,7 +52,7 @@ public async Task WhenValueCreatedGetValueReturnsOriginalValue()
{
var a = new AsyncAtomicFactory();
await a.GetValueAsync(1, k => Task.FromResult(2));
- (await a.GetValueAsync(1, k => Task.FromResult(3))).Should().Be(2);
+ (await a.GetValueAsync(1, k => Task.FromResult(3))).ShouldBe(2);
}
[Fact]
@@ -60,7 +60,7 @@ public async Task WhenValueCreatedArgGetValueReturnsOriginalValue()
{
var a = new AsyncAtomicFactory();
await a.GetValueAsync(1, (k, a) => Task.FromResult(k + a), 7);
- (await a.GetValueAsync(1, (k, a) => Task.FromResult(k + a), 9)).Should().Be(8);
+ (await a.GetValueAsync(1, (k, a) => Task.FromResult(k + a), 9)).ShouldBe(8);
}
[Fact]
@@ -70,9 +70,9 @@ public async Task WhenValueCreateThrowsValueIsNotStored()
Func getOrAdd = async () => { await a.GetValueAsync(1, k => throw new ArithmeticException()); };
- await getOrAdd.Should().ThrowAsync();
+ var ex = await getOrAdd.ShouldThrowAsync();;
- (await a.GetValueAsync(1, k => Task.FromResult(3))).Should().Be(3);
+ (await a.GetValueAsync(1, k => Task.FromResult(3))).ShouldBe(3);
}
[Fact]
@@ -108,10 +108,10 @@ public async Task WhenCallersRunConcurrentlyResultIsFromWinner()
await enter.Task;
resume.SetResult(true);
- (await first).Should().Be(result);
- (await second).Should().Be(result);
+ (await first).ShouldBe(result);
+ (await second).ShouldBe(result);
- winnerCount.Should().Be(1);
+ winnerCount.ShouldBe(1);
}
[Fact]
@@ -119,7 +119,7 @@ public void WhenValueNotCreatedHashCodeIsZero()
{
new AsyncAtomicFactory()
.GetHashCode()
- .Should().Be(0);
+ .ShouldBe(0);
}
[Fact]
@@ -127,7 +127,7 @@ public void WhenValueCreatedHashCodeIsValueHashCode()
{
new AsyncAtomicFactory(1)
.GetHashCode()
- .Should().Be(1);
+ .ShouldBe(1);
}
[Fact]
@@ -136,7 +136,7 @@ public void WhenValueNotCreatedEqualsFalse()
var a = new AsyncAtomicFactory();
var b = new AsyncAtomicFactory();
- a.Equals(b).Should().BeFalse();
+ a.Equals(b).ShouldBeFalse();
}
[Fact]
@@ -145,7 +145,7 @@ public void WhenOtherValueNotCreatedEqualsFalse()
var a = new AsyncAtomicFactory(1);
var b = new AsyncAtomicFactory();
- a.Equals(b).Should().BeFalse();
+ a.Equals(b).ShouldBeFalse();
}
[Fact]
@@ -153,7 +153,7 @@ public void WhenArgNullEqualsFalse()
{
new AsyncAtomicFactory(1)
.Equals(null)
- .Should().BeFalse();
+ .ShouldBeFalse();
}
[Fact]
@@ -163,7 +163,7 @@ public void WhenArgObjectValuesAreSameEqualsTrue()
new AsyncAtomicFactory(1)
.Equals(other)
- .Should().BeTrue();
+ .ShouldBeTrue();
}
}
}
diff --git a/BitFaster.Caching.UnitTests/Atomic/AtomicFactoryAsyncCacheTests.cs b/BitFaster.Caching.UnitTests/Atomic/AtomicFactoryAsyncCacheTests.cs
index 7459de31..b2a52b4c 100644
--- a/BitFaster.Caching.UnitTests/Atomic/AtomicFactoryAsyncCacheTests.cs
+++ b/BitFaster.Caching.UnitTests/Atomic/AtomicFactoryAsyncCacheTests.cs
@@ -2,11 +2,10 @@
using System.Collections;
using System.Collections.Generic;
using System.Linq;
-using System.Text;
using System.Threading.Tasks;
using BitFaster.Caching.Lru;
using BitFaster.Caching.Atomic;
-using FluentAssertions;
+using Shouldly;
using Xunit;
using Moq;
@@ -31,23 +30,23 @@ public void WhenInnerCacheIsNullCtorThrows()
{
Action constructor = () => { var x = new AtomicFactoryAsyncCache(null); };
- constructor.Should().Throw();
+ constructor.ShouldThrow();
}
[Fact]
public void WhenCreatedCapacityPropertyWrapsInnerCache()
{
- this.cache.Policy.Eviction.Value.Capacity.Should().Be(capacity);
+ this.cache.Policy.Eviction.Value.Capacity.ShouldBe(capacity);
}
[Fact]
public void WhenItemIsAddedCountIsCorrect()
{
- this.cache.Count.Should().Be(0);
+ this.cache.Count.ShouldBe(0);
this.cache.AddOrUpdate(2, 2);
- this.cache.Count.Should().Be(1);
+ this.cache.Count.ShouldBe(1);
}
[Fact]
@@ -56,8 +55,8 @@ public async Task WhenItemIsAddedThenLookedUpMetricsAreCorrect()
this.cache.AddOrUpdate(1, 1);
await this.cache.GetOrAddAsync(1, k => Task.FromResult(k));
- this.cache.Metrics.Value.Misses.Should().Be(0);
- this.cache.Metrics.Value.Hits.Should().Be(1);
+ this.cache.Metrics.Value.Misses.ShouldBe(0);
+ this.cache.Metrics.Value.Hits.ShouldBe(1);
}
[Fact]
@@ -65,8 +64,8 @@ public async Task WhenItemIsAddedWithArgValueIsCorrect()
{
await this.cache.GetOrAddAsync(1, (k, a) => Task.FromResult(k + a), 2);
- this.cache.TryGet(1, out var value).Should().BeTrue();
- value.Should().Be(3);
+ this.cache.TryGet(1, out var value).ShouldBeTrue();
+ value.ShouldBe(3);
}
[Fact]
@@ -77,7 +76,7 @@ public void WhenNoInnerEventsNoOuterEvents()
var cache = new AtomicFactoryAsyncCache(inner.Object);
- cache.Events.HasValue.Should().BeFalse();
+ cache.Events.HasValue.ShouldBeFalse();
}
[Fact]
@@ -88,7 +87,7 @@ public void WhenRemovedEventHandlerIsRegisteredItIsFired()
this.cache.AddOrUpdate(1, 1);
this.cache.TryRemove(1);
- this.removedItems.First().Key.Should().Be(1);
+ this.removedItems.First().Key.ShouldBe(1);
}
// backcompat: remove conditional compile
@@ -101,9 +100,9 @@ public void WhenUpdatedEventHandlerIsRegisteredItIsFired()
this.cache.AddOrUpdate(1, 2);
this.cache.AddOrUpdate(1, 3);
- this.updatedItems.First().Key.Should().Be(1);
- this.updatedItems.First().OldValue.Should().Be(2);
- this.updatedItems.First().NewValue.Should().Be(3);
+ this.updatedItems.First().Key.ShouldBe(1);
+ this.updatedItems.First().OldValue.ShouldBe(2);
+ this.updatedItems.First().NewValue.ShouldBe(3);
}
#endif
@@ -112,8 +111,8 @@ public void WhenKeyDoesNotExistAddOrUpdateAddsNewItem()
{
this.cache.AddOrUpdate(1, 1);
- this.cache.TryGet(1, out var value).Should().BeTrue();
- value.Should().Be(1);
+ this.cache.TryGet(1, out var value).ShouldBeTrue();
+ value.ShouldBe(1);
}
[Fact]
@@ -122,8 +121,8 @@ public void WhenKeyExistsAddOrUpdateUpdatesExistingItem()
this.cache.AddOrUpdate(1, 1);
this.cache.AddOrUpdate(1, 2);
- this.cache.TryGet(1, out var value).Should().BeTrue();
- value.Should().Be(2);
+ this.cache.TryGet(1, out var value).ShouldBeTrue();
+ value.ShouldBe(2);
}
[Fact]
@@ -133,13 +132,13 @@ public void WhenClearedItemsAreRemoved()
this.cache.Clear();
- this.cache.Count.Should().Be(0);
+ this.cache.Count.ShouldBe(0);
}
[Fact]
public void WhenItemDoesNotExistTryGetReturnsFalse()
{
- this.cache.TryGet(1, out var value).Should().BeFalse();
+ this.cache.TryGet(1, out var value).ShouldBeFalse();
}
[Fact]
@@ -147,8 +146,8 @@ public async Task WhenKeyDoesNotExistGetOrAddAsyncAddsValue()
{
await this.cache.GetOrAddAsync(1, k => Task.FromResult(k));
- this.cache.TryGet(1, out var value).Should().BeTrue();
- value.Should().Be(1);
+ this.cache.TryGet(1, out var value).ShouldBeTrue();
+ value.ShouldBe(1);
}
[Fact]
@@ -160,26 +159,26 @@ public void WhenCacheContainsValuesTrim1RemovesColdestValue()
this.cache.Policy.Eviction.Value.Trim(1);
- this.cache.TryGet(0, out var value).Should().BeFalse();
+ this.cache.TryGet(0, out var value).ShouldBeFalse();
}
[Fact]
public void WhenKeyDoesNotExistTryRemoveReturnsFalse()
{
- this.cache.TryRemove(1).Should().BeFalse();
+ this.cache.TryRemove(1).ShouldBeFalse();
}
[Fact]
public void WhenKeyExistsTryRemoveReturnsTrue()
{
this.cache.AddOrUpdate(1, 1);
- this.cache.TryRemove(1).Should().BeTrue();
+ this.cache.TryRemove(1).ShouldBeTrue();
}
[Fact]
public void WhenKeyDoesNotExistTryUpdateReturnsFalse()
{
- this.cache.TryUpdate(1, 1).Should().BeFalse();
+ this.cache.TryUpdate(1, 1).ShouldBeFalse();
}
[Fact]
@@ -187,38 +186,38 @@ public void WhenKeyExistsTryUpdateReturnsTrue()
{
this.cache.AddOrUpdate(1, 1);
- this.cache.TryUpdate(1, 2).Should().BeTrue();
+ this.cache.TryUpdate(1, 2).ShouldBeTrue();
this.cache.TryGet(1, out var value);
- value.Should().Be(2);
+ value.ShouldBe(2);
}
[Fact]
public void WhenItemsAddedKeysContainsTheKeys()
{
- cache.Count.Should().Be(0);
+ cache.Count.ShouldBe(0);
cache.AddOrUpdate(1, 1);
cache.AddOrUpdate(2, 2);
- cache.Keys.Should().BeEquivalentTo(new[] { 1, 2 });
+ cache.Keys.ShouldBe(new[] { 1, 2 });
}
[Fact]
public void WhenItemsAddedGenericEnumerateContainsKvps()
{
- cache.Count.Should().Be(0);
+ cache.Count.ShouldBe(0);
cache.AddOrUpdate(1, 1);
cache.AddOrUpdate(2, 2);
- cache.Should().BeEquivalentTo(new[] { new KeyValuePair(1, 1), new KeyValuePair(2, 2) });
+ cache.ShouldBe(new[] { new KeyValuePair(1, 1), new KeyValuePair(2, 2) });
}
[Fact]
public void WhenItemsAddedEnumerateContainsKvps()
{
- cache.Count.Should().Be(0);
+ cache.Count.ShouldBe(0);
cache.AddOrUpdate(1, 1);
cache.AddOrUpdate(2, 2);
var enumerable = (IEnumerable)cache;
- enumerable.Should().BeEquivalentTo(new[] { new KeyValuePair(1, 1), new KeyValuePair(2, 2) });
+ enumerable.ShouldBe(new[] { new KeyValuePair(1, 1), new KeyValuePair(2, 2) });
}
[Fact]
@@ -230,7 +229,7 @@ public async Task WhenFactoryThrowsEmptyValueIsNotCounted()
}
catch { }
- cache.Count.Should().Be(0);
+ cache.Count.ShouldBe(0);
}
[Fact]
@@ -243,7 +242,7 @@ public async Task WhenFactoryThrowsEmptyValueIsNotEnumerable()
catch { }
// IEnumerable.Count() instead of Count property
- cache.Count().Should().Be(0);
+ cache.Count().ShouldBe(0);
}
[Fact]
@@ -255,7 +254,7 @@ public async Task WhenFactoryThrowsEmptyKeyIsNotEnumerable()
}
catch { }
- cache.Keys.Count().Should().Be(0);
+ cache.Keys.Count().ShouldBe(0);
}
// backcompat: remove conditional compile
@@ -266,7 +265,7 @@ public void WhenRemovedValueIsReturned()
this.cache.AddOrUpdate(1, 1);
this.cache.TryRemove(1, out var value);
- value.Should().Be(1);
+ value.ShouldBe(1);
}
[Fact]
@@ -275,21 +274,21 @@ public void WhenNotRemovedValueIsDefault()
this.cache.AddOrUpdate(1, 1);
this.cache.TryRemove(2, out var value);
- value.Should().Be(0);
+ value.ShouldBe(0);
}
[Fact]
public void WhenRemoveKeyValueAndValueDoesntMatchDontRemove()
{
this.cache.AddOrUpdate(1, 1);
- this.cache.TryRemove(new KeyValuePair(1, 2)).Should().BeFalse();
+ this.cache.TryRemove(new KeyValuePair(1, 2)).ShouldBeFalse();
}
[Fact]
public void WhenRemoveKeyValueAndValueDoesMatchThenRemove()
{
this.cache.AddOrUpdate(1, 1);
- this.cache.TryRemove(new KeyValuePair(1, 1)).Should().BeTrue();
+ this.cache.TryRemove(new KeyValuePair(1, 1)).ShouldBeTrue();
}
[Fact]
@@ -299,7 +298,7 @@ public void WhenRemoveKeyValueAndValueIsNotCreatedDoesNotRemove()
this.innerCache.AddOrUpdate(1, new AsyncAtomicFactory());
// try to remove with the default value (0)
- this.cache.TryRemove(new KeyValuePair(1, 0)).Should().BeFalse();
+ this.cache.TryRemove(new KeyValuePair(1, 0)).ShouldBeFalse();
}
#endif
diff --git a/BitFaster.Caching.UnitTests/Atomic/AtomicFactoryCacheTests.cs b/BitFaster.Caching.UnitTests/Atomic/AtomicFactoryCacheTests.cs
index 0c8bd66c..8566bf3c 100644
--- a/BitFaster.Caching.UnitTests/Atomic/AtomicFactoryCacheTests.cs
+++ b/BitFaster.Caching.UnitTests/Atomic/AtomicFactoryCacheTests.cs
@@ -4,7 +4,7 @@
using System.Linq;
using BitFaster.Caching.Lru;
using BitFaster.Caching.Atomic;
-using FluentAssertions;
+using Shouldly;
using Xunit;
using Moq;
@@ -30,23 +30,23 @@ public void WhenInnerCacheIsNullCtorThrows()
{
Action constructor = () => { var x = new AtomicFactoryCache(null); };
- constructor.Should().Throw();
+ constructor.ShouldThrow();
}
[Fact]
public void WhenCreatedCapacityPropertyWrapsInnerCache()
{
- this.cache.Policy.Eviction.Value.Capacity.Should().Be(capacity);
+ this.cache.Policy.Eviction.Value.Capacity.ShouldBe(capacity);
}
[Fact]
public void WhenItemIsAddedCountIsCorrect()
{
- this.cache.Count.Should().Be(0);
+ this.cache.Count.ShouldBe(0);
this.cache.AddOrUpdate(2, 2);
- this.cache.Count.Should().Be(1);
+ this.cache.Count.ShouldBe(1);
}
[Fact]
@@ -55,8 +55,8 @@ public void WhenItemIsAddedThenLookedUpMetricsAreCorrect()
this.cache.AddOrUpdate(1, 1);
this.cache.GetOrAdd(1, k => k);
- this.cache.Metrics.Value.Misses.Should().Be(0);
- this.cache.Metrics.Value.Hits.Should().Be(1);
+ this.cache.Metrics.Value.Misses.ShouldBe(0);
+ this.cache.Metrics.Value.Hits.ShouldBe(1);
}
[Fact]
@@ -64,8 +64,8 @@ public void WhenItemIsAddedWithArgValueIsCorrect()
{
this.cache.GetOrAdd(1, (k, a) => k + a, 2);
- this.cache.TryGet(1, out var value).Should().BeTrue();
- value.Should().Be(3);
+ this.cache.TryGet(1, out var value).ShouldBeTrue();
+ value.ShouldBe(3);
}
[Fact]
@@ -76,7 +76,7 @@ public void WhenRemovedEventHandlerIsRegisteredItIsFired()
this.cache.AddOrUpdate(1, 1);
this.cache.TryRemove(1);
- this.removedItems.First().Key.Should().Be(1);
+ this.removedItems.First().Key.ShouldBe(1);
}
// backcompat: remove conditional compile
@@ -87,7 +87,7 @@ public void WhenRemovedValueIsReturned()
this.cache.AddOrUpdate(1, 1);
this.cache.TryRemove(1, out var value);
- value.Should().Be(1);
+ value.ShouldBe(1);
}
[Fact]
@@ -96,21 +96,21 @@ public void WhenNotRemovedValueIsDefault()
this.cache.AddOrUpdate(1, 1);
this.cache.TryRemove(2, out var value);
- value.Should().Be(0);
+ value.ShouldBe(0);
}
[Fact]
public void WhenRemoveKeyValueAndValueDoesntMatchDontRemove()
{
this.cache.AddOrUpdate(1, 1);
- this.cache.TryRemove(new KeyValuePair(1, 2)).Should().BeFalse();
+ this.cache.TryRemove(new KeyValuePair(1, 2)).ShouldBeFalse();
}
[Fact]
public void WhenRemoveKeyValueAndValueDoesMatchThenRemove()
{
this.cache.AddOrUpdate(1, 1);
- this.cache.TryRemove(new KeyValuePair(1, 1)).Should().BeTrue();
+ this.cache.TryRemove(new KeyValuePair(1, 1)).ShouldBeTrue();
}
[Fact]
@@ -120,7 +120,7 @@ public void WhenRemoveKeyValueAndValueIsNotCreatedDoesNotRemove()
this.innerCache.AddOrUpdate(1, new AtomicFactory());
// try to remove with the default value (0)
- this.cache.TryRemove(new KeyValuePair(1, 0)).Should().BeFalse();
+ this.cache.TryRemove(new KeyValuePair(1, 0)).ShouldBeFalse();
}
[Fact]
@@ -131,9 +131,9 @@ public void WhenUpdatedEventHandlerIsRegisteredItIsFired()
this.cache.AddOrUpdate(1, 2);
this.cache.AddOrUpdate(1, 3);
- this.updatedItems.First().Key.Should().Be(1);
- this.updatedItems.First().OldValue.Should().Be(2);
- this.updatedItems.First().NewValue.Should().Be(3);
+ this.updatedItems.First().Key.ShouldBe(1);
+ this.updatedItems.First().OldValue.ShouldBe(2);
+ this.updatedItems.First().NewValue.ShouldBe(3);
}
#endif
[Fact]
@@ -144,7 +144,7 @@ public void WhenNoInnerEventsNoOuterEvents()
var cache = new AtomicFactoryCache(inner.Object);
- cache.Events.HasValue.Should().BeFalse();
+ cache.Events.HasValue.ShouldBeFalse();
}
[Fact]
@@ -152,8 +152,8 @@ public void WhenKeyDoesNotExistAddOrUpdateAddsNewItem()
{
this.cache.AddOrUpdate(1, 1);
- this.cache.TryGet(1, out var value).Should().BeTrue();
- value.Should().Be(1);
+ this.cache.TryGet(1, out var value).ShouldBeTrue();
+ value.ShouldBe(1);
}
[Fact]
@@ -162,8 +162,8 @@ public void WhenKeyExistsAddOrUpdateUpdatesExistingItem()
this.cache.AddOrUpdate(1, 1);
this.cache.AddOrUpdate(1, 2);
- this.cache.TryGet(1, out var value).Should().BeTrue();
- value.Should().Be(2);
+ this.cache.TryGet(1, out var value).ShouldBeTrue();
+ value.ShouldBe(2);
}
[Fact]
@@ -173,13 +173,13 @@ public void WhenClearedItemsAreRemoved()
this.cache.Clear();
- this.cache.Count.Should().Be(0);
+ this.cache.Count.ShouldBe(0);
}
[Fact]
public void WhenItemDoesNotExistTryGetReturnsFalse()
{
- this.cache.TryGet(1, out var value).Should().BeFalse();
+ this.cache.TryGet(1, out var value).ShouldBeFalse();
}
[Fact]
@@ -187,8 +187,8 @@ public void WhenKeyDoesNotExistGetOrAddAddsValue()
{
this.cache.GetOrAdd(1, k => k);
- this.cache.TryGet(1, out var value).Should().BeTrue();
- value.Should().Be(1);
+ this.cache.TryGet(1, out var value).ShouldBeTrue();
+ value.ShouldBe(1);
}
[Fact]
@@ -200,26 +200,26 @@ public void WhenCacheContainsValuesTrim1RemovesColdestValue()
this.cache.Policy.Eviction.Value.Trim(1);
- this.cache.TryGet(0, out var value).Should().BeFalse();
+ this.cache.TryGet(0, out var value).ShouldBeFalse();
}
[Fact]
public void WhenKeyDoesNotExistTryRemoveReturnsFalse()
{
- this.cache.TryRemove(1).Should().BeFalse();
+ this.cache.TryRemove(1).ShouldBeFalse();
}
[Fact]
public void WhenKeyExistsTryRemoveReturnsTrue()
{
this.cache.AddOrUpdate(1, 1);
- this.cache.TryRemove(1).Should().BeTrue();
+ this.cache.TryRemove(1).ShouldBeTrue();
}
[Fact]
public void WhenKeyDoesNotExistTryUpdateReturnsFalse()
{
- this.cache.TryUpdate(1, 1).Should().BeFalse();
+ this.cache.TryUpdate(1, 1).ShouldBeFalse();
}
[Fact]
@@ -227,38 +227,38 @@ public void WhenKeyExistsTryUpdateReturnsTrue()
{
this.cache.AddOrUpdate(1, 1);
- this.cache.TryUpdate(1, 2).Should().BeTrue();
+ this.cache.TryUpdate(1, 2).ShouldBeTrue();
this.cache.TryGet(1, out var value);
- value.Should().Be(2);
+ value.ShouldBe(2);
}
[Fact]
public void WhenItemsAddedKeysContainsTheKeys()
{
- cache.Count.Should().Be(0);
+ cache.Count.ShouldBe(0);
cache.AddOrUpdate(1, 1);
cache.AddOrUpdate(2, 2);
- cache.Keys.Should().BeEquivalentTo(new[] { 1, 2 });
+ cache.Keys.ShouldBe(new[] { 1, 2 });
}
[Fact]
public void WhenItemsAddedGenericEnumerateContainsKvps()
{
- cache.Count.Should().Be(0);
+ cache.Count.ShouldBe(0);
cache.AddOrUpdate(1, 1);
cache.AddOrUpdate(2, 2);
- cache.Should().BeEquivalentTo(new[] { new KeyValuePair(1, 1), new KeyValuePair(2, 2) });
+ cache.ShouldBe(new[] { new KeyValuePair(1, 1), new KeyValuePair(2, 2) });
}
[Fact]
public void WhenItemsAddedEnumerateContainsKvps()
{
- cache.Count.Should().Be(0);
+ cache.Count.ShouldBe(0);
cache.AddOrUpdate(1, 1);
cache.AddOrUpdate(2, 2);
var enumerable = (IEnumerable)cache;
- enumerable.Should().BeEquivalentTo(new[] { new KeyValuePair(1, 1), new KeyValuePair(2, 2) });
+ enumerable.ShouldBe(new[] { new KeyValuePair(1, 1), new KeyValuePair(2, 2) });
}
[Fact]
@@ -270,7 +270,7 @@ public void WhenFactoryThrowsEmptyValueIsNotCounted()
}
catch { }
- cache.Count.Should().Be(0);
+ cache.Count.ShouldBe(0);
}
[Fact]
@@ -283,7 +283,7 @@ public void WhenFactoryThrowsEmptyValueIsNotEnumerable()
catch { }
// IEnumerable.Count() instead of Count property
- cache.Count().Should().Be(0);
+ cache.Count().ShouldBe(0);
}
[Fact]
@@ -295,7 +295,7 @@ public void WhenFactoryThrowsEmptyKeyIsNotEnumerable()
}
catch { }
- cache.Keys.Count().Should().Be(0);
+ cache.Keys.Count().ShouldBe(0);
}
private void OnItemRemoved(object sender, ItemRemovedEventArgs e)
diff --git a/BitFaster.Caching.UnitTests/Atomic/AtomicFactoryScopedAsyncCacheTests.cs b/BitFaster.Caching.UnitTests/Atomic/AtomicFactoryScopedAsyncCacheTests.cs
index e9244c6c..757e700d 100644
--- a/BitFaster.Caching.UnitTests/Atomic/AtomicFactoryScopedAsyncCacheTests.cs
+++ b/BitFaster.Caching.UnitTests/Atomic/AtomicFactoryScopedAsyncCacheTests.cs
@@ -1,11 +1,8 @@
using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
using System.Threading.Tasks;
using BitFaster.Caching.Lru;
using BitFaster.Caching.Atomic;
-using FluentAssertions;
+using Shouldly;
using Xunit;
using Moq;
@@ -23,7 +20,7 @@ public void WhenInnerCacheIsNullCtorThrows()
{
Action constructor = () => { var x = new AtomicFactoryScopedAsyncCache(null); };
- constructor.Should().Throw();
+ constructor.ShouldThrow();
}
[Fact]
@@ -35,7 +32,7 @@ public async Task WhenScopeIsDisposedTryGetReturnsFalse()
scope.Dispose();
- this.cache.ScopedTryGet(1, out var lifetime).Should().BeFalse();
+ this.cache.ScopedTryGet(1, out var lifetime).ShouldBeFalse();
}
[Fact]
@@ -43,7 +40,7 @@ public async Task WhenKeyDoesNotExistGetOrAddAsyncAddsValue()
{
await this.cache.ScopedGetOrAddAsync(1, k => Task.FromResult(new Scoped(new Disposable())));
- this.cache.ScopedTryGet(1, out var lifetime).Should().BeTrue();
+ this.cache.ScopedTryGet(1, out var lifetime).ShouldBeTrue();
}
[Fact]
@@ -54,7 +51,7 @@ public async Task GetOrAddAsyncDisposedScopeThrows()
Func getOrAdd = async () => { await this.cache.ScopedGetOrAddAsync(1, k => Task.FromResult(scope)); };
- await getOrAdd.Should().ThrowAsync();
+ var ex = await getOrAdd.ShouldThrowAsync();;
}
[Fact]
@@ -65,7 +62,7 @@ public void WhenNoInnerEventsNoOuterEvents()
var cache = new AtomicFactoryScopedAsyncCache(inner.Object);
- cache.Events.HasValue.Should().BeFalse();
+ cache.Events.HasValue.ShouldBeFalse();
}
// Infer identified AddOrUpdate and TryUpdate as resource leaks. This test verifies correct disposal.
@@ -77,11 +74,11 @@ public void WhenEntryIsUpdatedOldEntryIsDisposed()
this.cache.AddOrUpdate(1, disposable1);
- this.cache.TryUpdate(1, disposable2).Should().BeTrue();
- disposable1.IsDisposed.Should().BeTrue();
+ this.cache.TryUpdate(1, disposable2).ShouldBeTrue();
+ disposable1.IsDisposed.ShouldBeTrue();
- this.cache.TryUpdate(1, new Disposable()).Should().BeTrue();
- disposable2.IsDisposed.Should().BeTrue();
+ this.cache.TryUpdate(1, new Disposable()).ShouldBeTrue();
+ disposable2.IsDisposed.ShouldBeTrue();
}
}
}
diff --git a/BitFaster.Caching.UnitTests/Atomic/AtomicFactoryScopedCacheTests.cs b/BitFaster.Caching.UnitTests/Atomic/AtomicFactoryScopedCacheTests.cs
index 58254424..dcf2d1c4 100644
--- a/BitFaster.Caching.UnitTests/Atomic/AtomicFactoryScopedCacheTests.cs
+++ b/BitFaster.Caching.UnitTests/Atomic/AtomicFactoryScopedCacheTests.cs
@@ -1,11 +1,8 @@
using System;
-using System.Collections.Generic;
using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
using BitFaster.Caching.Lru;
using BitFaster.Caching.Atomic;
-using FluentAssertions;
+using Shouldly;
using Xunit;
using Moq;
@@ -23,7 +20,7 @@ public void WhenInnerCacheIsNullCtorThrows()
{
Action constructor = () => { var x = new AtomicFactoryScopedCache(null); };
- constructor.Should().Throw();
+ constructor.ShouldThrow();
}
[Fact]
@@ -35,7 +32,7 @@ public void WhenScopeIsDisposedTryGetReturnsFalse()
scope.Dispose();
- this.cache.ScopedTryGet(1, out var lifetime).Should().BeFalse();
+ this.cache.ScopedTryGet(1, out var lifetime).ShouldBeFalse();
}
[Fact]
@@ -43,7 +40,7 @@ public void WhenKeyDoesNotExistGetOrAddAddsValue()
{
this.cache.ScopedGetOrAdd(1, k => new Scoped(new Disposable()));
- this.cache.ScopedTryGet(1, out var lifetime).Should().BeTrue();
+ this.cache.ScopedTryGet(1, out var lifetime).ShouldBeTrue();
}
[Fact]
@@ -54,7 +51,7 @@ public void GetOrAddDisposedScopeThrows()
Action getOrAdd = () => { this.cache.ScopedGetOrAdd(1, k => scope); };
- getOrAdd.Should().Throw();
+ getOrAdd.ShouldThrow();
}
[Fact]
@@ -65,7 +62,7 @@ public void WhenNoInnerEventsNoOuterEvents()
var cache = new AtomicFactoryScopedCache(inner.Object);
- cache.Events.HasValue.Should().BeFalse();
+ cache.Events.HasValue.ShouldBeFalse();
}
// Infer identified AddOrUpdate and TryUpdate as resource leaks. This test verifies correct disposal.
@@ -77,11 +74,11 @@ public void WhenEntryIsUpdatedOldEntryIsDisposed()
this.cache.AddOrUpdate(1, disposable1);
- this.cache.TryUpdate(1, disposable2).Should().BeTrue();
- disposable1.IsDisposed.Should().BeTrue();
+ this.cache.TryUpdate(1, disposable2).ShouldBeTrue();
+ disposable1.IsDisposed.ShouldBeTrue();
- this.cache.TryUpdate(1, new Disposable()).Should().BeTrue();
- disposable2.IsDisposed.Should().BeTrue();
+ this.cache.TryUpdate(1, new Disposable()).ShouldBeTrue();
+ disposable2.IsDisposed.ShouldBeTrue();
}
[Fact]
@@ -93,7 +90,7 @@ public void WhenFactoryThrowsEmptyValueIsNotCounted()
}
catch { }
- cache.Count.Should().Be(0);
+ cache.Count.ShouldBe(0);
}
[Fact]
@@ -106,7 +103,7 @@ public void WhenFactoryThrowsEmptyValueIsNotEnumerable()
catch { }
// IEnumerable.Count() instead of Count property
- cache.Count().Should().Be(0);
+ cache.Count().ShouldBe(0);
}
[Fact]
@@ -118,7 +115,7 @@ public void WhenFactoryThrowsEmptyKeyIsNotEnumerable()
}
catch { }
- cache.Keys.Count().Should().Be(0);
+ cache.Keys.Count().ShouldBe(0);
}
}
}
diff --git a/BitFaster.Caching.UnitTests/Atomic/AtomicFactorySoakTests.cs b/BitFaster.Caching.UnitTests/Atomic/AtomicFactorySoakTests.cs
index b4ab2708..ab590429 100644
--- a/BitFaster.Caching.UnitTests/Atomic/AtomicFactorySoakTests.cs
+++ b/BitFaster.Caching.UnitTests/Atomic/AtomicFactorySoakTests.cs
@@ -2,8 +2,7 @@
using System.Linq;
using System.Threading.Tasks;
using BitFaster.Caching.Atomic;
-using BitFaster.Caching.Lru;
-using FluentAssertions;
+using Shouldly;
using Xunit;
namespace BitFaster.Caching.UnitTests.Atomic
@@ -27,7 +26,7 @@ await Threaded.Run(threads, (r) =>
}
});
- counters.Sum(x => x).Should().Be(items);
+ counters.Sum(x => x).ShouldBe(items);
}
}
}
diff --git a/BitFaster.Caching.UnitTests/Atomic/AtomicFactoryTests.cs b/BitFaster.Caching.UnitTests/Atomic/AtomicFactoryTests.cs
index dfe9a32c..1925edb1 100644
--- a/BitFaster.Caching.UnitTests/Atomic/AtomicFactoryTests.cs
+++ b/BitFaster.Caching.UnitTests/Atomic/AtomicFactoryTests.cs
@@ -1,9 +1,8 @@
-
-using System;
+using System;
using System.Threading;
using System.Threading.Tasks;
using BitFaster.Caching.Atomic;
-using FluentAssertions;
+using Shouldly;
using Xunit;
namespace BitFaster.Caching.UnitTests.Atomic
@@ -15,8 +14,8 @@ public void DefaultCtorValueIsNotCreated()
{
var a = new AtomicFactory();
- a.IsValueCreated.Should().BeFalse();
- a.ValueIfCreated.Should().Be(0);
+ a.IsValueCreated.ShouldBeFalse();
+ a.ValueIfCreated.ShouldBe(0);
}
[Fact]
@@ -24,28 +23,28 @@ public void WhenValuePassedToCtorValueIsStored()
{
var a = new AtomicFactory(1);
- a.ValueIfCreated.Should().Be(1);
- a.IsValueCreated.Should().BeTrue();
+ a.ValueIfCreated.ShouldBe(1);
+ a.IsValueCreated.ShouldBeTrue();
}
[Fact]
public void WhenValueCreatedValueReturned()
{
var a = new AtomicFactory();
- a.GetValue(1, k => 2).Should().Be(2);
+ a.GetValue(1, k => 2).ShouldBe(2);
- a.ValueIfCreated.Should().Be(2);
- a.IsValueCreated.Should().BeTrue();
+ a.ValueIfCreated.ShouldBe(2);
+ a.IsValueCreated.ShouldBeTrue();
}
[Fact]
public void WhenValueCreatedWithArgValueReturned()
{
var a = new AtomicFactory();
- a.GetValue(1, (k, a) => k + a, 7).Should().Be(8);
+ a.GetValue(1, (k, a) => k + a, 7).ShouldBe(8);
- a.ValueIfCreated.Should().Be(8);
- a.IsValueCreated.Should().BeTrue();
+ a.ValueIfCreated.ShouldBe(8);
+ a.IsValueCreated.ShouldBeTrue();
}
[Fact]
@@ -53,7 +52,7 @@ public void WhenValueCreatedGetValueReturnsOriginalValue()
{
var a = new AtomicFactory();
a.GetValue(1, k => 2);
- a.GetValue(1, k => 3).Should().Be(2);
+ a.GetValue(1, k => 3).ShouldBe(2);
}
[Fact]
@@ -61,7 +60,7 @@ public void WhenValueCreatedArgGetValueReturnsOriginalValue()
{
var a = new AtomicFactory();
a.GetValue(1, (k, a) => k + a, 7);
- a.GetValue(1, (k, a) => k + a, 9).Should().Be(8);
+ a.GetValue(1, (k, a) => k + a, 9).ShouldBe(8);
}
[Fact]
@@ -69,7 +68,7 @@ public void WhenValueNotCreatedHashCodeIsZero()
{
new AtomicFactory()
.GetHashCode()
- .Should().Be(0);
+ .ShouldBe(0);
}
[Fact]
@@ -77,7 +76,7 @@ public void WhenValueCreatedHashCodeIsValueHashCode()
{
new AtomicFactory(1)
.GetHashCode()
- .Should().Be(1);
+ .ShouldBe(1);
}
[Fact]
@@ -86,7 +85,7 @@ public void WhenValueNotCreatedEqualsFalse()
var a = new AtomicFactory();
var b = new AtomicFactory();
- a.Equals(b).Should().BeFalse();
+ a.Equals(b).ShouldBeFalse();
}
[Fact]
@@ -95,7 +94,7 @@ public void WhenOtherValueNotCreatedEqualsFalse()
var a = new AtomicFactory(1);
var b = new AtomicFactory();
- a.Equals(b).Should().BeFalse();
+ a.Equals(b).ShouldBeFalse();
}
[Fact]
@@ -103,7 +102,7 @@ public void WhenArgNullEqualsFalse()
{
new AtomicFactory(1)
.Equals(null)
- .Should().BeFalse();
+ .ShouldBeFalse();
}
[Fact]
@@ -113,7 +112,7 @@ public void WhenArgObjectValuesAreSameEqualsTrue()
new AtomicFactory(1)
.Equals(other)
- .Should().BeTrue();
+ .ShouldBeTrue();
}
[Fact]
@@ -161,10 +160,10 @@ public async Task WhenCallersRunConcurrentlyResultIsFromWinner()
factory.WaitOne();
resume.Set();
- (await first).Should().Be(result);
- (await second).Should().Be(result);
+ (await first).ShouldBe(result);
+ (await second).ShouldBe(result);
- winnerCount.Should().Be(1);
+ winnerCount.ShouldBe(1);
}
[Fact]
@@ -219,8 +218,8 @@ public async Task WhenCallersRunConcurrentlyAndFailExceptionIsPropogated()
Func act1 = () => first;
Func act2 = () => second;
- await act1.Should().ThrowAsync();
- await act2.Should().ThrowAsync();
+ await act1.ShouldThrowAsync();;
+ await act2.ShouldThrowAsync();;
if (throwCount == 1)
{
@@ -228,7 +227,7 @@ public async Task WhenCallersRunConcurrentlyAndFailExceptionIsPropogated()
}
}
- timesContended.Should().BeGreaterThan(0);
+ timesContended.ShouldBeGreaterThan(0);
}
[Fact]
@@ -271,11 +270,11 @@ public async Task WhenCallersRunConcurrentlyAndFailNewCallerStartsClean()
Func act1 = () => first;
Func act2 = () => second;
- await act1.Should().ThrowAsync();
- await act2.Should().ThrowAsync();
+ await act1.ShouldThrowAsync();;
+ await act2.ShouldThrowAsync();;
// verify exception is no longer cached
- atomicFactory.GetValue(1, k => k).Should().Be(1);
+ atomicFactory.GetValue(1, k => k).ShouldBe(1);
}
}
}
diff --git a/BitFaster.Caching.UnitTests/Atomic/ConcurrentDictionaryExtensionTests.cs b/BitFaster.Caching.UnitTests/Atomic/ConcurrentDictionaryExtensionTests.cs
index 02473a91..59e38b55 100644
--- a/BitFaster.Caching.UnitTests/Atomic/ConcurrentDictionaryExtensionTests.cs
+++ b/BitFaster.Caching.UnitTests/Atomic/ConcurrentDictionaryExtensionTests.cs
@@ -1,9 +1,8 @@
-
+using System.Collections.Generic;
using System.Collections.Concurrent;
-using System.Collections.Generic;
using System.Threading.Tasks;
using BitFaster.Caching.Atomic;
-using FluentAssertions;
+using Shouldly;
using Xunit;
namespace BitFaster.Caching.UnitTests.Atomic
@@ -18,8 +17,8 @@ public void WhenItemIsAddedItCanBeRetrieved()
{
dictionary.GetOrAdd(1, k => k);
- dictionary.TryGetValue(1, out int value).Should().BeTrue();
- value.Should().Be(1);
+ dictionary.TryGetValue(1, out int value).ShouldBeTrue();
+ value.ShouldBe(1);
}
[Fact]
@@ -27,8 +26,8 @@ public async Task WhenItemIsAddedAsyncItCanBeRetrieved()
{
await dictionaryAsync.GetOrAddAsync(1, k => Task.FromResult(k));
- dictionaryAsync.TryGetValue(1, out int value).Should().BeTrue();
- value.Should().Be(1);
+ dictionaryAsync.TryGetValue(1, out int value).ShouldBeTrue();
+ value.ShouldBe(1);
}
[Fact]
@@ -36,8 +35,8 @@ public void WhenItemIsAddedWithArgItCanBeRetrieved()
{
dictionary.GetOrAdd(1, (k,a) => k + a, 2);
- dictionary.TryGetValue(1, out int value).Should().BeTrue();
- value.Should().Be(3);
+ dictionary.TryGetValue(1, out int value).ShouldBeTrue();
+ value.ShouldBe(3);
}
[Fact]
@@ -45,20 +44,20 @@ public async Task WhenItemIsAddedWithArgAsyncItCanBeRetrieved()
{
await dictionaryAsync.GetOrAddAsync(1, (k, a) => Task.FromResult(k + a), 2);
- dictionaryAsync.TryGetValue(1, out int value).Should().BeTrue();
- value.Should().Be(3);
+ dictionaryAsync.TryGetValue(1, out int value).ShouldBeTrue();
+ value.ShouldBe(3);
}
[Fact]
public void WhenKeyDoesNotExistTryGetReturnsFalse()
{
- dictionary.TryGetValue(1, out int _).Should().BeFalse();
+ dictionary.TryGetValue(1, out int _).ShouldBeFalse();
}
[Fact]
public void WhenKeyDoesNotExistAsyncTryGetReturnsFalse()
{
- dictionaryAsync.TryGetValue(1, out int _).Should().BeFalse();
+ dictionaryAsync.TryGetValue(1, out int _).ShouldBeFalse();
}
[Fact]
@@ -66,8 +65,8 @@ public void WhenItemIsAddedItCanBeRemovedByKey()
{
dictionary.GetOrAdd(1, k => k);
- dictionary.TryRemove(1, out int value).Should().BeTrue();
- value.Should().Be(1);
+ dictionary.TryRemove(1, out int value).ShouldBeTrue();
+ value.ShouldBe(1);
}
[Fact]
@@ -75,8 +74,8 @@ public async Task WhenItemIsAddedAsyncItCanBeRemovedByKey()
{
await dictionaryAsync.GetOrAddAsync(1, k => Task.FromResult(k));
- dictionaryAsync.TryRemove(1, out int value).Should().BeTrue();
- value.Should().Be(1);
+ dictionaryAsync.TryRemove(1, out int value).ShouldBeTrue();
+ value.ShouldBe(1);
}
[Fact]
@@ -84,8 +83,8 @@ public void WhenItemIsAddedItCanBeRemovedByKvp()
{
dictionary.GetOrAdd(1, k => k);
- dictionary.TryRemove(new KeyValuePair(1, 1)).Should().BeTrue();
- dictionary.TryGetValue(1, out _).Should().BeFalse();
+ dictionary.TryRemove(new KeyValuePair(1, 1)).ShouldBeTrue();
+ dictionary.TryGetValue(1, out _).ShouldBeFalse();
}
[Fact]
@@ -93,20 +92,20 @@ public async Task WhenItemIsAddedAsyncItCanBeRemovedByKvp()
{
await dictionaryAsync.GetOrAddAsync(1, k => Task.FromResult(k));
- dictionaryAsync.TryRemove(new KeyValuePair(1, 1)).Should().BeTrue();
- dictionaryAsync.TryGetValue(1, out _).Should().BeFalse();
+ dictionaryAsync.TryRemove(new KeyValuePair(1, 1)).ShouldBeTrue();
+ dictionaryAsync.TryGetValue(1, out _).ShouldBeFalse();
}
[Fact]
public void WhenKeyDoesNotExistTryRemoveReturnsFalse()
{
- dictionary.TryRemove(1, out int _).Should().BeFalse();
+ dictionary.TryRemove(1, out int _).ShouldBeFalse();
}
[Fact]
public void WhenKeyDoesNotExistAsyncTryRemoveReturnsFalse()
{
- dictionaryAsync.TryRemove(1, out int _).Should().BeFalse();
+ dictionaryAsync.TryRemove(1, out int _).ShouldBeFalse();
}
}
}
diff --git a/BitFaster.Caching.UnitTests/Atomic/ScopedAsyncAtomicFactorySoakTests.cs b/BitFaster.Caching.UnitTests/Atomic/ScopedAsyncAtomicFactorySoakTests.cs
index f8c94e9d..4d0a9c0c 100644
--- a/BitFaster.Caching.UnitTests/Atomic/ScopedAsyncAtomicFactorySoakTests.cs
+++ b/BitFaster.Caching.UnitTests/Atomic/ScopedAsyncAtomicFactorySoakTests.cs
@@ -2,7 +2,7 @@
using System.Linq;
using System.Threading.Tasks;
using BitFaster.Caching.Atomic;
-using FluentAssertions;
+using Shouldly;
using Xunit;
namespace BitFaster.Caching.UnitTests.Atomic
@@ -32,7 +32,7 @@ await Threaded.RunAsync(threads, async (r) =>
{
using (lifetime)
{
- lifetime.Value.IsDisposed.Should().BeFalse();
+ lifetime.Value.IsDisposed.ShouldBeFalse();
}
break;
@@ -41,7 +41,7 @@ await Threaded.RunAsync(threads, async (r) =>
}
});
- counters.Sum(x => x).Should().Be(items);
+ counters.Sum(x => x).ShouldBe(items);
}
[Fact]
@@ -67,7 +67,7 @@ await Threaded.RunAsync(threads, async (r) =>
{
using (lifetime)
{
- lifetime.Value.IsDisposed.Should().BeFalse();
+ lifetime.Value.IsDisposed.ShouldBeFalse();
}
break;
diff --git a/BitFaster.Caching.UnitTests/Atomic/ScopedAsyncAtomicFactoryTests.cs b/BitFaster.Caching.UnitTests/Atomic/ScopedAsyncAtomicFactoryTests.cs
index bc941309..559eff1f 100644
--- a/BitFaster.Caching.UnitTests/Atomic/ScopedAsyncAtomicFactoryTests.cs
+++ b/BitFaster.Caching.UnitTests/Atomic/ScopedAsyncAtomicFactoryTests.cs
@@ -2,7 +2,7 @@
using System.Threading;
using System.Threading.Tasks;
using BitFaster.Caching.Atomic;
-using FluentAssertions;
+using Shouldly;
using Xunit;
namespace BitFaster.Caching.UnitTests.Atomic
@@ -14,7 +14,7 @@ public void WhenScopeIsNotCreatedScopeIfCreatedReturnsNull()
{
var atomicFactory = new ScopedAsyncAtomicFactory();
- atomicFactory.ScopeIfCreated.Should().BeNull();
+ atomicFactory.ScopeIfCreated.ShouldBeNull();
}
[Fact]
@@ -23,16 +23,16 @@ public void WhenScopeIsCreatedScopeIfCreatedReturnsScope()
var expectedDisposable = new Disposable();
var atomicFactory = new ScopedAsyncAtomicFactory(expectedDisposable);
- atomicFactory.ScopeIfCreated.Should().NotBeNull();
- atomicFactory.ScopeIfCreated.TryCreateLifetime(out var lifetime).Should().BeTrue();
- lifetime.Value.Should().Be(expectedDisposable);
+ atomicFactory.ScopeIfCreated.ShouldNotBeNull();
+ atomicFactory.ScopeIfCreated.TryCreateLifetime(out var lifetime).ShouldBeTrue();
+ lifetime.Value.ShouldBe(expectedDisposable);
}
[Fact]
public void WhenNotInitTryCreateReturnsFalse()
{
var sa = new ScopedAsyncAtomicFactory();
- sa.TryCreateLifetime(out var l).Should().BeFalse();
+ sa.TryCreateLifetime(out var l).ShouldBeFalse();
}
[Fact]
@@ -41,8 +41,8 @@ public void WhenCreatedTryCreateLifetimeReturnsScope()
var expectedDisposable = new Disposable();
var sa = new ScopedAsyncAtomicFactory(expectedDisposable);
- sa.TryCreateLifetime(out var lifetime).Should().BeTrue();
- lifetime.Value.Should().Be(expectedDisposable);
+ sa.TryCreateLifetime(out var lifetime).ShouldBeTrue();
+ lifetime.Value.ShouldBe(expectedDisposable);
}
[Fact]
@@ -55,8 +55,8 @@ public async Task WhenCreateFromValueLifetimeContainsValue()
return Task.FromResult(new Scoped(new IntHolder() { actualNumber = 2 }));
});
- result.r.Should().BeTrue();
- result.l.Value.actualNumber.Should().Be(1);
+ result.r.ShouldBeTrue();
+ result.l.Value.actualNumber.ShouldBe(1);
}
[Fact]
@@ -69,8 +69,8 @@ public async Task WhenCreateFromFactoryLifetimeContainsValue()
return Task.FromResult(new Scoped(new IntHolder() { actualNumber = 2 }));
});
- result.r.Should().BeTrue();
- result.l.Value.actualNumber.Should().Be(2);
+ result.r.ShouldBeTrue();
+ result.l.Value.actualNumber.ShouldBe(2);
}
[Fact]
@@ -81,8 +81,8 @@ public async Task WhenCreateFromFactoryArgLifetimeContainsValue()
(bool r, Lifetime l) result = await atomicFactory.TryCreateLifetimeAsync(1, factory);
- result.r.Should().BeTrue();
- result.l.Value.actualNumber.Should().Be(8);
+ result.r.ShouldBeTrue();
+ result.l.Value.actualNumber.ShouldBe(8);
}
[Fact]
@@ -96,8 +96,8 @@ public async Task WhenScopeIsDisposedTryCreateReturnsFalse()
return Task.FromResult(new Scoped(new IntHolder() { actualNumber = 2 }));
});
- result.r.Should().BeFalse();
- result.l.Should().BeNull();
+ result.r.ShouldBeFalse();
+ result.l.ShouldBeNull();
}
[Fact]
@@ -108,7 +108,7 @@ public void WhenValueIsCreatedDisposeDisposesValue()
atomicFactory.Dispose();
- holder.disposed.Should().BeTrue();
+ holder.disposed.ShouldBeTrue();
}
[Fact]
@@ -147,13 +147,13 @@ public async Task WhenCallersRunConcurrentlyResultIsFromWinner()
var result1 = await first;
var result2 = await second;
- result1.r.Should().BeTrue();
- result2.r.Should().BeTrue();
+ result1.r.ShouldBeTrue();
+ result2.r.ShouldBeTrue();
- result1.l.Value.actualNumber.Should().Be(winningNumber);
- result2.l.Value.actualNumber.Should().Be(winningNumber);
+ result1.l.Value.actualNumber.ShouldBe(winningNumber);
+ result2.l.Value.actualNumber.ShouldBe(winningNumber);
- winnerCount.Should().Be(1);
+ winnerCount.ShouldBe(1);
}
[Fact]
@@ -179,10 +179,10 @@ public async Task WhenDisposedWhileInitResultIsDisposed()
var result = await first;
- result.r.Should().BeFalse();
- result.l.Should().BeNull();
+ result.r.ShouldBeFalse();
+ result.l.ShouldBeNull();
- holder.disposed.Should().BeTrue();
+ holder.disposed.ShouldBeTrue();
}
[Fact]
@@ -211,17 +211,17 @@ public async Task WhenDisposedWhileThrowingNextInitIsDisposed()
// If we create an item, to be in a consistent state we should dispose it.
Func tryCreateAsync = async () => { await first; };
- await tryCreateAsync.Should().ThrowAsync();
+ var ex = await tryCreateAsync.ShouldThrowAsync();;
(bool r, Lifetime l) result = await atomicFactory.TryCreateLifetimeAsync(1, k =>
{
return Task.FromResult(new Scoped(holder));
});
- result.r.Should().BeFalse();
- result.l.Should().BeNull();
+ result.r.ShouldBeFalse();
+ result.l.ShouldBeNull();
- holder.disposed.Should().BeTrue();
+ holder.disposed.ShouldBeTrue();
}
private static AsyncValueFactoryArg> CreateArgFactory(int arg)
diff --git a/BitFaster.Caching.UnitTests/Atomic/ScopedAtomicFactorySoakTests.cs b/BitFaster.Caching.UnitTests/Atomic/ScopedAtomicFactorySoakTests.cs
index d99c6200..d7387de1 100644
--- a/BitFaster.Caching.UnitTests/Atomic/ScopedAtomicFactorySoakTests.cs
+++ b/BitFaster.Caching.UnitTests/Atomic/ScopedAtomicFactorySoakTests.cs
@@ -2,7 +2,7 @@
using System.Linq;
using System.Threading.Tasks;
using BitFaster.Caching.Atomic;
-using FluentAssertions;
+using Shouldly;
using Xunit;
namespace BitFaster.Caching.UnitTests.Atomic
@@ -30,7 +30,7 @@ await Threaded.Run(threads, (r) =>
{
using (lifetime)
{
- lifetime.Value.IsDisposed.Should().BeFalse();
+ lifetime.Value.IsDisposed.ShouldBeFalse();
}
break;
@@ -40,7 +40,7 @@ await Threaded.Run(threads, (r) =>
}
});
- counters.Sum(x => x).Should().Be(items);
+ counters.Sum(x => x).ShouldBe(items);
}
[Fact]
@@ -65,7 +65,7 @@ await Threaded.Run(threads, (r) =>
{
using (lifetime)
{
- lifetime.Value.IsDisposed.Should().BeFalse();
+ lifetime.Value.IsDisposed.ShouldBeFalse();
}
break;
diff --git a/BitFaster.Caching.UnitTests/Atomic/ScopedAtomicFactoryTests.cs b/BitFaster.Caching.UnitTests/Atomic/ScopedAtomicFactoryTests.cs
index 072375be..d9704330 100644
--- a/BitFaster.Caching.UnitTests/Atomic/ScopedAtomicFactoryTests.cs
+++ b/BitFaster.Caching.UnitTests/Atomic/ScopedAtomicFactoryTests.cs
@@ -1,6 +1,5 @@
-
-using BitFaster.Caching.Atomic;
-using FluentAssertions;
+using BitFaster.Caching.Atomic;
+using Shouldly;
using Xunit;
namespace BitFaster.Caching.UnitTests.Atomic
@@ -13,9 +12,9 @@ public void WhenInitializedWithValueTryCreateLifetimeCreatesLifetimeWithValue()
var expectedDisposable = new Disposable();
var sa = new ScopedAtomicFactory(expectedDisposable);
- sa.TryCreateLifetime(1, k => new Scoped(new Disposable()), out var lifetime).Should().BeTrue();
+ sa.TryCreateLifetime(1, k => new Scoped(new Disposable()), out var lifetime).ShouldBeTrue();
- lifetime.Value.Should().Be(expectedDisposable);
+ lifetime.Value.ShouldBe(expectedDisposable);
}
[Fact]
@@ -24,9 +23,9 @@ public void WhenInitializedWithFactoryTryCreateLifetimeCreatesLifetimeWithValue(
var expectedDisposable = new Disposable();
var sa = new ScopedAtomicFactory();
- sa.TryCreateLifetime(1, k => new Scoped(expectedDisposable), out var lifetime).Should().BeTrue();
+ sa.TryCreateLifetime(1, k => new Scoped(expectedDisposable), out var lifetime).ShouldBeTrue();
- lifetime.Value.Should().Be(expectedDisposable);
+ lifetime.Value.ShouldBe(expectedDisposable);
}
[Fact]
@@ -35,10 +34,10 @@ public void WhenInitializedWithFactoryValueIsCached()
var expectedDisposable = new Disposable();
var sa = new ScopedAtomicFactory();
- sa.TryCreateLifetime(1, k => new Scoped(expectedDisposable), out var lifetime1).Should().BeTrue();
- sa.TryCreateLifetime(1, k => new Scoped(new Disposable()), out var lifetime2).Should().BeTrue();
+ sa.TryCreateLifetime(1, k => new Scoped(expectedDisposable), out var lifetime1).ShouldBeTrue();
+ sa.TryCreateLifetime(1, k => new Scoped(new Disposable()), out var lifetime2).ShouldBeTrue();
- lifetime2.Value.Should().Be(expectedDisposable);
+ lifetime2.Value.ShouldBe(expectedDisposable);
}
[Fact]
@@ -50,11 +49,11 @@ public void WhenInitializedWithFactoryArgValueIsCached()
var factory1 = new ValueFactoryArg>((k, v) => { expectedDisposable.State = v; return new Scoped(expectedDisposable); }, 1);
var factory2 = new ValueFactoryArg>((k, v) => { expectedDisposable.State = v; return new Scoped(expectedDisposable); }, 2);
- sa.TryCreateLifetime(1, factory1, out var lifetime1).Should().BeTrue();
- sa.TryCreateLifetime(1, factory2, out var lifetime2).Should().BeTrue();
+ sa.TryCreateLifetime(1, factory1, out var lifetime1).ShouldBeTrue();
+ sa.TryCreateLifetime(1, factory2, out var lifetime2).ShouldBeTrue();
- lifetime2.Value.Should().Be(expectedDisposable);
- lifetime2.Value.State.Should().Be(1);
+ lifetime2.Value.ShouldBe(expectedDisposable);
+ lifetime2.Value.State.ShouldBe(1);
}
[Fact]
@@ -62,7 +61,7 @@ public void WhenScopeIsNotCreatedScopeIfCreatedReturnsNull()
{
var sa = new ScopedAtomicFactory();
- sa.ScopeIfCreated.Should().BeNull();
+ sa.ScopeIfCreated.ShouldBeNull();
}
[Fact]
@@ -71,16 +70,16 @@ public void WhenScopeIsCreatedScopeIfCreatedReturnsScope()
var expectedDisposable = new Disposable();
var sa = new ScopedAtomicFactory(expectedDisposable);
- sa.ScopeIfCreated.Should().NotBeNull();
- sa.ScopeIfCreated.TryCreateLifetime(out var lifetime).Should().BeTrue();
- lifetime.Value.Should().Be(expectedDisposable);
+ sa.ScopeIfCreated.ShouldNotBeNull();
+ sa.ScopeIfCreated.TryCreateLifetime(out var lifetime).ShouldBeTrue();
+ lifetime.Value.ShouldBe(expectedDisposable);
}
[Fact]
public void WhenNotInitTryCreateReturnsFalse()
{
var sa = new ScopedAtomicFactory();
- sa.TryCreateLifetime(out var l).Should().BeFalse();
+ sa.TryCreateLifetime(out var l).ShouldBeFalse();
}
[Fact]
@@ -89,8 +88,8 @@ public void WhenCreatedTryCreateLifetimeReturnsScope()
var expectedDisposable = new Disposable();
var sa = new ScopedAtomicFactory(expectedDisposable);
- sa.TryCreateLifetime(out var lifetime).Should().BeTrue();
- lifetime.Value.Should().Be(expectedDisposable);
+ sa.TryCreateLifetime(out var lifetime).ShouldBeTrue();
+ lifetime.Value.ShouldBe(expectedDisposable);
}
[Fact]
@@ -99,7 +98,7 @@ public void WhenScopeDisposedTryCreateLifetimeReturnsFalse()
var sa = new ScopedAtomicFactory();
sa.Dispose();
- sa.TryCreateLifetime(out var lifetime).Should().BeFalse();
+ sa.TryCreateLifetime(out var lifetime).ShouldBeFalse();
}
[Fact]
@@ -108,7 +107,7 @@ public void WhenInitializedWithValueThenDisposedCreateLifetimeIsFalse()
var sa = new ScopedAtomicFactory(new Disposable());
sa.Dispose();
- sa.TryCreateLifetime(1, k => new Scoped(new Disposable()), out var l).Should().BeFalse();
+ sa.TryCreateLifetime(1, k => new Scoped(new Disposable()), out var l).ShouldBeFalse();
}
[Fact]
@@ -117,7 +116,7 @@ public void WhenCreatedThenDisposedCreateLifetimeIsFalse()
var sa = new ScopedAtomicFactory();
sa.Dispose();
- sa.TryCreateLifetime(1, k => new Scoped(new Disposable()), out var l).Should().BeFalse();
+ sa.TryCreateLifetime(1, k => new Scoped(new Disposable()), out var l).ShouldBeFalse();
}
[Fact]
@@ -126,17 +125,17 @@ public void WhenInitializedLifetimeKeepsValueAlive()
var disposable = new Disposable();
var sa = new ScopedAtomicFactory();
- sa.TryCreateLifetime(1, k => new Scoped(disposable), out var lifetime1).Should().BeTrue();
- sa.TryCreateLifetime(1, k => null, out var lifetime2).Should().BeTrue();
+ sa.TryCreateLifetime(1, k => new Scoped(disposable), out var lifetime1).ShouldBeTrue();
+ sa.TryCreateLifetime(1, k => null, out var lifetime2).ShouldBeTrue();
sa.Dispose();
- disposable.IsDisposed.Should().BeFalse();
+ disposable.IsDisposed.ShouldBeFalse();
lifetime1.Dispose();
- disposable.IsDisposed.Should().BeFalse();
+ disposable.IsDisposed.ShouldBeFalse();
lifetime2.Dispose();
- disposable.IsDisposed.Should().BeTrue();
+ disposable.IsDisposed.ShouldBeTrue();
}
}
}
diff --git a/BitFaster.Caching.UnitTests/BitFaster.Caching.UnitTests.csproj b/BitFaster.Caching.UnitTests/BitFaster.Caching.UnitTests.csproj
index 93a5a179..b8b0a674 100644
--- a/BitFaster.Caching.UnitTests/BitFaster.Caching.UnitTests.csproj
+++ b/BitFaster.Caching.UnitTests/BitFaster.Caching.UnitTests.csproj
@@ -1,4 +1,4 @@
-
+
net48;netcoreapp3.1;net6.0
@@ -10,20 +10,20 @@
all
runtime; build; native; contentfiles; analyzers; buildtransitive
-
+
-
+
-
+
all
runtime; build; native; contentfiles; analyzers; buildtransitive
-
+
-
+
diff --git a/BitFaster.Caching.UnitTests/BitOpsTests.cs b/BitFaster.Caching.UnitTests/BitOpsTests.cs
index bfc956c2..6b52cfff 100644
--- a/BitFaster.Caching.UnitTests/BitOpsTests.cs
+++ b/BitFaster.Caching.UnitTests/BitOpsTests.cs
@@ -1,9 +1,4 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
-using FluentAssertions;
+using Shouldly;
using Xunit;
namespace BitFaster.Caching.UnitTests
@@ -17,7 +12,7 @@ public class BitOpsTests
[InlineData(536870913, 1073741824)]
public void IntCeilingPowerOfTwo(int input, int power)
{
- BitOps.CeilingPowerOfTwo(input).Should().Be(power);
+ BitOps.CeilingPowerOfTwo(input).ShouldBe(power);
}
[Theory]
@@ -28,7 +23,7 @@ public void IntCeilingPowerOfTwo(int input, int power)
[InlineData(34359738368, 34359738368)]
public void LongCeilingPowerOfTwo(long input, long power)
{
- BitOps.CeilingPowerOfTwo(input).Should().Be(power);
+ BitOps.CeilingPowerOfTwo(input).ShouldBe(power);
}
[Theory]
@@ -39,7 +34,7 @@ public void LongCeilingPowerOfTwo(long input, long power)
public void UIntCeilingPowerOfTwo(uint input, uint power)
{
- BitOps.CeilingPowerOfTwo(input).Should().Be(power);
+ BitOps.CeilingPowerOfTwo(input).ShouldBe(power);
}
[Theory]
@@ -51,7 +46,7 @@ public void UIntCeilingPowerOfTwo(uint input, uint power)
public void UlongCeilingPowerOfTwo(ulong input, ulong power)
{
- BitOps.CeilingPowerOfTwo(input).Should().Be(power);
+ BitOps.CeilingPowerOfTwo(input).ShouldBe(power);
}
[Theory]
@@ -65,7 +60,7 @@ public void UlongCeilingPowerOfTwo(ulong input, ulong power)
public void LongTrailingZeroCount(long input, int count)
{
- BitOps.TrailingZeroCount(input).Should().Be(count);
+ BitOps.TrailingZeroCount(input).ShouldBe(count);
}
[Theory]
@@ -79,25 +74,25 @@ public void LongTrailingZeroCount(long input, int count)
public void ULongTrailingZeroCount(ulong input, int count)
{
- BitOps.TrailingZeroCount(input).Should().Be(count);
+ BitOps.TrailingZeroCount(input).ShouldBe(count);
}
[Fact]
public void IntBitCount()
{
- BitOps.BitCount(666).Should().Be(5);
+ BitOps.BitCount(666).ShouldBe(5);
}
[Fact]
public void LongtBitCount()
{
- BitOps.BitCount(666L).Should().Be(5);
+ BitOps.BitCount(666L).ShouldBe(5);
}
[Fact]
public void ULongtBitCount()
{
- BitOps.BitCount(666UL).Should().Be(5);
+ BitOps.BitCount(666UL).ShouldBe(5);
}
}
}
diff --git a/BitFaster.Caching.UnitTests/Buffers/MpmcBoundedBufferSoakTests.cs b/BitFaster.Caching.UnitTests/Buffers/MpmcBoundedBufferSoakTests.cs
index 01fab64f..4ad20552 100644
--- a/BitFaster.Caching.UnitTests/Buffers/MpmcBoundedBufferSoakTests.cs
+++ b/BitFaster.Caching.UnitTests/Buffers/MpmcBoundedBufferSoakTests.cs
@@ -2,7 +2,7 @@
using System.Threading;
using System.Threading.Tasks;
using BitFaster.Caching.Buffers;
-using FluentAssertions;
+using Shouldly;
using Xunit;
using Xunit.Abstractions;
@@ -33,7 +33,7 @@ await Threaded.Run(4, () =>
{
}
- buffer.Count.Should().Be(1024);
+ buffer.Count.ShouldBe(1024);
});
}
@@ -80,7 +80,7 @@ public async Task WhileBufferIsFilledCountCanBeTaken()
while (!fill.IsCompleted)
{
int newcount = buffer.Count;
- newcount.Should().BeGreaterThanOrEqualTo(count);
+ newcount.ShouldBeGreaterThanOrEqualTo(count);
count = newcount;
}
});
diff --git a/BitFaster.Caching.UnitTests/Buffers/MpmcBoundedBufferTests.cs b/BitFaster.Caching.UnitTests/Buffers/MpmcBoundedBufferTests.cs
index ede26594..fbf13035 100644
--- a/BitFaster.Caching.UnitTests/Buffers/MpmcBoundedBufferTests.cs
+++ b/BitFaster.Caching.UnitTests/Buffers/MpmcBoundedBufferTests.cs
@@ -1,11 +1,6 @@
using System;
-using System.Collections.Concurrent;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
using BitFaster.Caching.Buffers;
-using FluentAssertions;
+using Shouldly;
using Xunit;
namespace BitFaster.Caching.UnitTests.Buffers
@@ -19,19 +14,19 @@ public void WhenSizeIsLessThan1CtorThrows()
{
Action constructor = () => { var x = new MpmcBoundedBuffer(-1); };
- constructor.Should().Throw();
+ constructor.ShouldThrow();
}
[Fact]
public void SizeIsPowerOfTwo()
{
- buffer.Capacity.Should().Be(16);
+ buffer.Capacity.ShouldBe(16);
}
[Fact]
public void WhenBufferIsEmptyCountIsZero()
{
- buffer.Count.Should().Be(0);
+ buffer.Count.ShouldBe(0);
}
[Fact]
@@ -39,22 +34,22 @@ public void WhenBufferHasOneItemCountIsOne()
{
// head < tail
buffer.TryAdd(1);
- buffer.Count.Should().Be(1);
+ buffer.Count.ShouldBe(1);
}
[Fact]
public void WhenBufferHas15ItemCountIs15()
{
- buffer.TryAdd(0).Should().Be(BufferStatus.Success);
- buffer.TryTake(out var _).Should().Be(BufferStatus.Success);
+ buffer.TryAdd(0).ShouldBe(BufferStatus.Success);
+ buffer.TryTake(out var _).ShouldBe(BufferStatus.Success);
for (var i = 0; i < 15; i++)
{
- buffer.TryAdd(0).Should().Be(BufferStatus.Success);
+ buffer.TryAdd(0).ShouldBe(BufferStatus.Success);
}
// head = 1, tail = 0 : head > tail
- buffer.Count.Should().Be(15);
+ buffer.Count.ShouldBe(15);
}
[Fact]
@@ -62,24 +57,24 @@ public void WhenBufferIsFullTryAddIsFalse()
{
for (var i = 0; i < 16; i++)
{
- buffer.TryAdd(i).Should().Be(BufferStatus.Success);
+ buffer.TryAdd(i).ShouldBe(BufferStatus.Success);
}
- buffer.TryAdd(666).Should().Be(BufferStatus.Full);
+ buffer.TryAdd(666).ShouldBe(BufferStatus.Full);
}
[Fact]
public void WhenBufferIsEmptyTryTakeIsFalse()
{
- buffer.TryTake(out var _).Should().Be(BufferStatus.Empty);
+ buffer.TryTake(out var _).ShouldBe(BufferStatus.Empty);
}
[Fact]
public void WhenItemAddedItCanBeTaken()
{
- buffer.TryAdd(123).Should().Be(BufferStatus.Success);
- buffer.TryTake(out var item).Should().Be(BufferStatus.Success);
- item.Should().Be(123);
+ buffer.TryAdd(123).ShouldBe(BufferStatus.Success);
+ buffer.TryTake(out var item).ShouldBe(BufferStatus.Success);
+ item.ShouldBe(123);
}
[Fact]
@@ -88,12 +83,12 @@ public void WhenItemsAreAddedClearRemovesItems()
buffer.TryAdd(1);
buffer.TryAdd(2);
- buffer.Count.Should().Be(2);
+ buffer.Count.ShouldBe(2);
buffer.Clear();
- buffer.Count.Should().Be(0);
- buffer.TryTake(out var _).Should().Be(BufferStatus.Empty);
+ buffer.Count.ShouldBe(0);
+ buffer.TryTake(out var _).ShouldBe(BufferStatus.Empty);
}
}
}
diff --git a/BitFaster.Caching.UnitTests/Buffers/MpscBoundedBufferSoakTests.cs b/BitFaster.Caching.UnitTests/Buffers/MpscBoundedBufferSoakTests.cs
index edc77a36..0d94f731 100644
--- a/BitFaster.Caching.UnitTests/Buffers/MpscBoundedBufferSoakTests.cs
+++ b/BitFaster.Caching.UnitTests/Buffers/MpscBoundedBufferSoakTests.cs
@@ -2,7 +2,7 @@
using System.Threading;
using System.Threading.Tasks;
using BitFaster.Caching.Buffers;
-using FluentAssertions;
+using Shouldly;
using Xunit;
using Xunit.Abstractions;
@@ -33,7 +33,7 @@ await Threaded.Run(4, () =>
{
}
- buffer.Count.Should().Be(1024);
+ buffer.Count.ShouldBe(1024);
});
}
@@ -99,7 +99,7 @@ public async Task WhileBufferIsFilledCountCanBeTaken()
while (!fill.IsCompleted)
{
int newcount = buffer.Count;
- newcount.Should().BeGreaterThanOrEqualTo(count);
+ newcount.ShouldBeGreaterThanOrEqualTo(count);
count = newcount;
}
});
diff --git a/BitFaster.Caching.UnitTests/Buffers/MpscBoundedBufferTests.cs b/BitFaster.Caching.UnitTests/Buffers/MpscBoundedBufferTests.cs
index a4a65242..3059ac64 100644
--- a/BitFaster.Caching.UnitTests/Buffers/MpscBoundedBufferTests.cs
+++ b/BitFaster.Caching.UnitTests/Buffers/MpscBoundedBufferTests.cs
@@ -1,6 +1,6 @@
using System;
using BitFaster.Caching.Buffers;
-using FluentAssertions;
+using Shouldly;
using Xunit;
namespace BitFaster.Caching.UnitTests.Buffers
@@ -14,19 +14,19 @@ public void WhenSizeIsLessThan1CtorThrows()
{
Action constructor = () => { var x = new MpscBoundedBuffer(-1); };
- constructor.Should().Throw();
+ constructor.ShouldThrow();
}
[Fact]
public void SizeIsPowerOfTwo()
{
- buffer.Capacity.Should().Be(16);
+ buffer.Capacity.ShouldBe(16);
}
[Fact]
public void WhenBufferIsEmptyCountIsZero()
{
- buffer.Count.Should().Be(0);
+ buffer.Count.ShouldBe(0);
}
[Fact]
@@ -34,22 +34,22 @@ public void WhenBufferHasOneItemCountIsOne()
{
// head < tail
buffer.TryAdd("1");
- buffer.Count.Should().Be(1);
+ buffer.Count.ShouldBe(1);
}
[Fact]
public void WhenBufferHas15ItemCountIs15()
{
- buffer.TryAdd("1").Should().Be(BufferStatus.Success);
- buffer.TryTake(out var _).Should().Be(BufferStatus.Success);
+ buffer.TryAdd("1").ShouldBe(BufferStatus.Success);
+ buffer.TryTake(out var _).ShouldBe(BufferStatus.Success);
for (var i = 0; i < 15; i++)
{
- buffer.TryAdd("0").Should().Be(BufferStatus.Success);
+ buffer.TryAdd("0").ShouldBe(BufferStatus.Success);
}
// head = 1, tail = 0 : head > tail
- buffer.Count.Should().Be(15);
+ buffer.Count.ShouldBe(15);
}
[Fact]
@@ -57,24 +57,24 @@ public void WhenBufferIsFullTryAddIsFalse()
{
for (var i = 0; i < 16; i++)
{
- buffer.TryAdd(i.ToString()).Should().Be(BufferStatus.Success);
+ buffer.TryAdd(i.ToString()).ShouldBe(BufferStatus.Success);
}
- buffer.TryAdd("666").Should().Be(BufferStatus.Full);
+ buffer.TryAdd("666").ShouldBe(BufferStatus.Full);
}
[Fact]
public void WhenBufferIsEmptyTryTakeIsFalse()
{
- buffer.TryTake(out var _).Should().Be(BufferStatus.Empty);
+ buffer.TryTake(out var _).ShouldBe(BufferStatus.Empty);
}
[Fact]
public void WhenItemAddedItCanBeTaken()
{
- buffer.TryAdd("123").Should().Be(BufferStatus.Success);
- buffer.TryTake(out var item).Should().Be(BufferStatus.Success);
- item.Should().Be("123");
+ buffer.TryAdd("123").ShouldBe(BufferStatus.Success);
+ buffer.TryTake(out var item).ShouldBe(BufferStatus.Success);
+ item.ShouldBe("123");
}
[Fact]
@@ -83,12 +83,12 @@ public void WhenItemsAreAddedClearRemovesItems()
buffer.TryAdd("1");
buffer.TryAdd("2");
- buffer.Count.Should().Be(2);
+ buffer.Count.ShouldBe(2);
buffer.Clear();
- buffer.Count.Should().Be(0);
- buffer.TryTake(out var _).Should().Be(BufferStatus.Empty);
+ buffer.Count.ShouldBe(0);
+ buffer.TryTake(out var _).ShouldBe(BufferStatus.Empty);
}
[Fact]
@@ -97,7 +97,7 @@ public void WhenBufferEmptyDrainReturnsZero()
var outputBuffer = new string[16];
var output = new ArraySegment(outputBuffer);
- buffer.DrainTo(output).Should().Be(0);
+ buffer.DrainTo(output).ShouldBe(0);
}
#if NETCOREAPP3_0_OR_GREATER
@@ -110,11 +110,11 @@ public void WhenBufferContainsItemsDrainArrayTakesItems()
var outputBuffer = new string[16];
- buffer.DrainTo(outputBuffer.AsSpan()).Should().Be(3);
+ buffer.DrainTo(outputBuffer.AsSpan()).ShouldBe(3);
- outputBuffer[0].Should().Be("1");
- outputBuffer[1].Should().Be("2");
- outputBuffer[2].Should().Be("3");
+ outputBuffer[0].ShouldBe("1");
+ outputBuffer[1].ShouldBe("2");
+ outputBuffer[2].ShouldBe("3");
}
#endif
@@ -128,11 +128,11 @@ public void WhenBufferContainsItemsDrainSegmentTakesItems()
var outputBuffer = new string[16];
var output = new ArraySegment(outputBuffer);
- buffer.DrainTo(output).Should().Be(3);
+ buffer.DrainTo(output).ShouldBe(3);
- outputBuffer[0].Should().Be("1");
- outputBuffer[1].Should().Be("2");
- outputBuffer[2].Should().Be("3");
+ outputBuffer[0].ShouldBe("1");
+ outputBuffer[1].ShouldBe("2");
+ outputBuffer[2].ShouldBe("3");
}
[Fact]
@@ -145,11 +145,11 @@ public void WhenSegmentUsesOffsetItemsDrainedToOffset()
var outputBuffer = new string[16];
var output = new ArraySegment(outputBuffer, 6, 10);
- buffer.DrainTo(output).Should().Be(3);
+ buffer.DrainTo(output).ShouldBe(3);
- outputBuffer[6].Should().Be("1");
- outputBuffer[7].Should().Be("2");
- outputBuffer[8].Should().Be("3");
+ outputBuffer[6].ShouldBe("1");
+ outputBuffer[7].ShouldBe("2");
+ outputBuffer[8].ShouldBe("3");
}
}
}
diff --git a/BitFaster.Caching.UnitTests/Buffers/StripedMpscBufferTests.cs b/BitFaster.Caching.UnitTests/Buffers/StripedMpscBufferTests.cs
index 0c621f0d..9016d0db 100644
--- a/BitFaster.Caching.UnitTests/Buffers/StripedMpscBufferTests.cs
+++ b/BitFaster.Caching.UnitTests/Buffers/StripedMpscBufferTests.cs
@@ -1,10 +1,5 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
-using BitFaster.Caching.Buffers;
-using FluentAssertions;
+using BitFaster.Caching.Buffers;
+using Shouldly;
using Xunit;
namespace BitFaster.Caching.UnitTests.Buffers
@@ -18,23 +13,23 @@ public class StripedMpscBufferTests
[Fact]
public void CapacityReturnsCapacity()
{
- buffer.Capacity.Should().Be(32);
+ buffer.Capacity.ShouldBe(32);
}
[Fact]
public void CountReturnsCount()
{
- buffer.Count.Should().Be(0);
+ buffer.Count.ShouldBe(0);
for (var i = 0; i < stripeCount; i++)
{
for (var j = 0; j < bufferSize; j++)
{
- buffer.TryAdd(1.ToString()).Should().Be(BufferStatus.Success);
+ buffer.TryAdd(1.ToString()).ShouldBe(BufferStatus.Success);
}
}
- buffer.Count.Should().Be(buffer.Capacity);
+ buffer.Count.ShouldBe(buffer.Capacity);
}
[Fact]
@@ -44,18 +39,18 @@ public void WhenBufferIsFullTryAddReturnsFull()
{
for (var j = 0; j < bufferSize; j++)
{
- buffer.TryAdd(1.ToString()).Should().Be(BufferStatus.Success);
+ buffer.TryAdd(1.ToString()).ShouldBe(BufferStatus.Success);
}
}
- buffer.TryAdd("1").Should().Be(BufferStatus.Full);
+ buffer.TryAdd("1").ShouldBe(BufferStatus.Full);
}
[Fact]
public void WhenBufferIsEmptyDrainReturnsZero()
{
var array = new string[bufferSize];
- buffer.DrainTo(array).Should().Be(0);
+ buffer.DrainTo(array).ShouldBe(0);
}
[Fact]
@@ -70,7 +65,7 @@ public void WhenBufferIsFullDrainReturnsItemCount()
}
var array = new string[bufferSize * stripeCount];
- buffer.DrainTo(array).Should().Be(stripeCount * bufferSize);
+ buffer.DrainTo(array).ShouldBe(stripeCount * bufferSize);
}
[Fact]
@@ -85,7 +80,7 @@ public void WhenDrainBufferIsSmallerThanStripedBufferDrainReturnsBufferItemCount
}
var array = new string[bufferSize];
- buffer.DrainTo(array).Should().Be(bufferSize);
+ buffer.DrainTo(array).ShouldBe(bufferSize);
}
[Fact]
@@ -100,7 +95,7 @@ public void WhenDrainBufferIsSmallerThanStripedBufferDrainReturnsBufferItemCount
}
var array = new string[bufferSize+4];
- buffer.DrainTo(array).Should().Be(bufferSize+4);
+ buffer.DrainTo(array).ShouldBe(bufferSize+4);
}
[Fact]
@@ -112,7 +107,7 @@ public void WhenBufferIsPartFullDrainReturnsItems()
}
var array = new string[bufferSize * stripeCount];
- buffer.DrainTo(array).Should().Be(bufferSize);
+ buffer.DrainTo(array).ShouldBe(bufferSize);
}
[Fact]
@@ -129,7 +124,7 @@ public void WhenBufferIsClearedDrainReturns0()
buffer.Clear();
var array = new string[bufferSize * stripeCount];
- buffer.DrainTo(array).Should().Be(0);
+ buffer.DrainTo(array).ShouldBe(0);
}
}
}
diff --git a/BitFaster.Caching.UnitTests/CacheEventProxyBaseTests.cs b/BitFaster.Caching.UnitTests/CacheEventProxyBaseTests.cs
index 6cbd4908..0da88486 100644
--- a/BitFaster.Caching.UnitTests/CacheEventProxyBaseTests.cs
+++ b/BitFaster.Caching.UnitTests/CacheEventProxyBaseTests.cs
@@ -2,7 +2,7 @@
using System.Collections.Generic;
using System.Linq;
using BitFaster.Caching.Atomic;
-using FluentAssertions;
+using Shouldly;
using Xunit;
namespace BitFaster.Caching.UnitTests
@@ -28,7 +28,7 @@ public void WheRemovedEventHandlerIsRegisteredItIsFired()
this.testCacheEvents.FireRemoved(1, new AtomicFactory(1), ItemRemovedReason.Removed);
- this.removedItems.First().Key.Should().Be(1);
+ this.removedItems.First().Key.ShouldBe(1);
}
[Fact]
@@ -39,7 +39,7 @@ public void WhenRemovedEventHandlerIsAddedThenRemovedItIsNotFired()
this.testCacheEvents.FireRemoved(1, new AtomicFactory(1), ItemRemovedReason.Removed);
- this.removedItems.Count.Should().Be(0);
+ this.removedItems.Count.ShouldBe(0);
}
[Fact]
@@ -51,7 +51,7 @@ public void WhenTwoRemovedEventHandlersAddedThenOneRemovedEventIsFired()
this.testCacheEvents.FireRemoved(1, new AtomicFactory(1), ItemRemovedReason.Removed);
- this.removedItems.First().Key.Should().Be(1);
+ this.removedItems.First().Key.ShouldBe(1);
}
// backcompat: remove conditional compile
@@ -63,9 +63,9 @@ public void WheUpdatedEventHandlerIsRegisteredItIsFired()
this.testCacheEvents.FireUpdated(1, new AtomicFactory(2), new AtomicFactory(3));
- this.updatedItems.First().Key.Should().Be(1);
- this.updatedItems.First().OldValue.Should().Be(2);
- this.updatedItems.First().NewValue.Should().Be(3);
+ this.updatedItems.First().Key.ShouldBe(1);
+ this.updatedItems.First().OldValue.ShouldBe(2);
+ this.updatedItems.First().NewValue.ShouldBe(3);
}
[Fact]
@@ -76,7 +76,7 @@ public void WhenUpdatedEventHandlerIsAddedThenRemovedItIsNotFired()
this.testCacheEvents.FireUpdated(1, new AtomicFactory(2), new AtomicFactory(3));
- this.updatedItems.Count.Should().Be(0);
+ this.updatedItems.Count.ShouldBe(0);
}
[Fact]
@@ -88,7 +88,7 @@ public void WhenTwoUpdatedEventHandlersAddedThenOneRemovedEventIsFired()
this.testCacheEvents.FireUpdated(1, new AtomicFactory(2), new AtomicFactory(3));
- this.updatedItems.First().Key.Should().Be(1);
+ this.updatedItems.First().Key.ShouldBe(1);
}
#endif
private void OnItemRemoved(object sender, ItemRemovedEventArgs e)
@@ -156,9 +156,9 @@ public void WhenUpdatedEventHandlerIsRegisteredAndProxyUsesDefaultUpdateTranslat
this.testCacheEvents.FireUpdated(1, new AtomicFactory(2), new AtomicFactory(3));
#if NETCOREAPP3_0_OR_GREATER
- this.updatedItems.First().Key.Should().Be(1);
+ this.updatedItems.First().Key.ShouldBe(1);
#else
- this.updatedItems.Should().BeEmpty();
+ this.updatedItems.ShouldBeEmpty();
#endif
}
diff --git a/BitFaster.Caching.UnitTests/CacheEventsTests.cs b/BitFaster.Caching.UnitTests/CacheEventsTests.cs
index e51002d2..9f54199b 100644
--- a/BitFaster.Caching.UnitTests/CacheEventsTests.cs
+++ b/BitFaster.Caching.UnitTests/CacheEventsTests.cs
@@ -1,5 +1,4 @@
-
-using Moq;
+using Moq;
using Xunit;
namespace BitFaster.Caching.UnitTests
diff --git a/BitFaster.Caching.UnitTests/CacheMetricsTests.cs b/BitFaster.Caching.UnitTests/CacheMetricsTests.cs
index 62bf3368..82f61566 100644
--- a/BitFaster.Caching.UnitTests/CacheMetricsTests.cs
+++ b/BitFaster.Caching.UnitTests/CacheMetricsTests.cs
@@ -1,5 +1,4 @@
-
-using FluentAssertions;
+using Shouldly;
using Moq;
using Xunit;
@@ -15,7 +14,7 @@ public void WhenInterfaceDefaultUpdatedInvokedReturnZero()
var metrics = new Mock();
metrics.CallBase = true;
- metrics.Object.Updated.Should().Be(0);
+ metrics.Object.Updated.ShouldBe(0);
}
}
#endif
diff --git a/BitFaster.Caching.UnitTests/CachePolicyTests.cs b/BitFaster.Caching.UnitTests/CachePolicyTests.cs
index 8674ad37..f74c40e2 100644
--- a/BitFaster.Caching.UnitTests/CachePolicyTests.cs
+++ b/BitFaster.Caching.UnitTests/CachePolicyTests.cs
@@ -1,4 +1,4 @@
-using FluentAssertions;
+using Shouldly;
using Moq;
using Xunit;
@@ -14,10 +14,10 @@ public void WhenCtorFieldsAreAssigned()
var cp = new CachePolicy(new Optional(eviction.Object), new Optional(expire.Object));
- cp.Eviction.Value.Should().Be(eviction.Object);
- cp.ExpireAfterWrite.Value.Should().Be(expire.Object);
- cp.ExpireAfterAccess.HasValue.Should().BeFalse();
- cp.ExpireAfter.HasValue.Should().BeFalse();
+ cp.Eviction.Value.ShouldBe(eviction.Object);
+ cp.ExpireAfterWrite.Value.ShouldBe(expire.Object);
+ cp.ExpireAfterAccess.HasValue.ShouldBeFalse();
+ cp.ExpireAfter.HasValue.ShouldBeFalse();
}
}
}
diff --git a/BitFaster.Caching.UnitTests/CacheTests.cs b/BitFaster.Caching.UnitTests/CacheTests.cs
index 5cdeafa0..7d109add 100644
--- a/BitFaster.Caching.UnitTests/CacheTests.cs
+++ b/BitFaster.Caching.UnitTests/CacheTests.cs
@@ -1,8 +1,7 @@
-
-using System;
-using System.Collections.Generic;
+using System;
using System.Threading.Tasks;
-using FluentAssertions;
+using System.Collections.Generic;
+using Shouldly;
using Moq;
using Xunit;
@@ -25,7 +24,7 @@ public void WhenCacheInterfaceDefaultGetOrAddFallback()
cache.Object.GetOrAdd(
1,
(k, a) => k + a,
- 2).Should().Be(3);
+ 2).ShouldBe(3);
}
[Fact]
@@ -36,7 +35,7 @@ public void WhenCacheInterfaceDefaultTryRemoveKeyThrows()
Action tryRemove = () => { cache.Object.TryRemove(1, out var value); };
- tryRemove.Should().Throw();
+ tryRemove.ShouldThrow();
}
[Fact]
@@ -47,7 +46,7 @@ public void WhenCacheInterfaceDefaultTryRemoveKeyValueThrows()
Action tryRemove = () => { cache.Object.TryRemove(new KeyValuePair(1, 1)); };
- tryRemove.Should().Throw();
+ tryRemove.ShouldThrow();
}
[Fact]
@@ -64,7 +63,7 @@ public async Task WhenAsyncCacheInterfaceDefaultGetOrAddFallback()
(k, a) => Task.FromResult(k + a),
2);
- r.Should().Be(3);
+ r.ShouldBe(3);
}
[Fact]
@@ -75,7 +74,7 @@ public void WhenAsyncCacheInterfaceDefaultTryRemoveKeyThrows()
Action tryRemove = () => { cache.Object.TryRemove(1, out var value); };
- tryRemove.Should().Throw();
+ tryRemove.ShouldThrow();
}
[Fact]
@@ -86,7 +85,7 @@ public void WhenAsyncCacheInterfaceDefaultTryRemoveKeyValueThrows()
Action tryRemove = () => { cache.Object.TryRemove(new KeyValuePair(1, 1)); };
- tryRemove.Should().Throw();
+ tryRemove.ShouldThrow();
}
[Fact]
@@ -98,7 +97,7 @@ public void WhenScopedCacheInterfaceDefaultGetOrAddFallback()
Func>, Lifetime> evaluate = (k, f) =>
{
var scope = f(k);
- scope.TryCreateLifetime(out var lifetime).Should().BeTrue();
+ scope.TryCreateLifetime(out var lifetime).ShouldBeTrue();
return lifetime;
};
@@ -109,7 +108,7 @@ public void WhenScopedCacheInterfaceDefaultGetOrAddFallback()
(k, a) => new Scoped(new Disposable(k + a)),
2);
- l.Value.State.Should().Be(3);
+ l.Value.State.ShouldBe(3);
}
[Fact]
@@ -121,7 +120,7 @@ public async Task WhenScopedAsyncCacheInterfaceDefaultGetOrAddFallback()
Func>>, ValueTask>> evaluate = async (k, f) =>
{
var scope = await f(k);
- scope.TryCreateLifetime(out var lifetime).Should().BeTrue();
+ scope.TryCreateLifetime(out var lifetime).ShouldBeTrue();
return lifetime;
};
@@ -134,7 +133,7 @@ public async Task WhenScopedAsyncCacheInterfaceDefaultGetOrAddFallback()
(k, a) => Task.FromResult(new Scoped(new Disposable(k + a))),
2);
- lifetime.Value.State.Should().Be(3);
+ lifetime.Value.State.ShouldBe(3);
}
#endif
}
diff --git a/BitFaster.Caching.UnitTests/ConcurrentDictionarySizeTests.cs b/BitFaster.Caching.UnitTests/ConcurrentDictionarySizeTests.cs
index 8665f5d3..1ae5f724 100644
--- a/BitFaster.Caching.UnitTests/ConcurrentDictionarySizeTests.cs
+++ b/BitFaster.Caching.UnitTests/ConcurrentDictionarySizeTests.cs
@@ -1,4 +1,4 @@
-using FluentAssertions;
+using Shouldly;
using Xunit;
using Xunit.Abstractions;
@@ -21,7 +21,7 @@ public ConcurrentDictionarySizeTests(ITestOutputHelper testOutputHelper)
[InlineData(7199370, 7199370)]
public void NextPrimeGreaterThan(int input, int nextPrime)
{
- ConcurrentDictionarySize.NextPrimeGreaterThan(input).Should().Be(nextPrime);
+ ConcurrentDictionarySize.NextPrimeGreaterThan(input).ShouldBe(nextPrime);
}
[Theory]
@@ -35,7 +35,7 @@ public void NextPrimeGreaterThan(int input, int nextPrime)
[InlineData(2003828731, 250478587)] // test overflow
public void Estimate(int input, int optimal)
{
- ConcurrentDictionarySize.Estimate(input).Should().Be(optimal);
+ ConcurrentDictionarySize.Estimate(input).ShouldBe(optimal);
}
}
}
diff --git a/BitFaster.Caching.UnitTests/Counters/CounterSoakTests.cs b/BitFaster.Caching.UnitTests/Counters/CounterSoakTests.cs
index e9fb1e4f..91f91e61 100644
--- a/BitFaster.Caching.UnitTests/Counters/CounterSoakTests.cs
+++ b/BitFaster.Caching.UnitTests/Counters/CounterSoakTests.cs
@@ -1,6 +1,6 @@
using System.Threading.Tasks;
using BitFaster.Caching.Counters;
-using FluentAssertions;
+using Shouldly;
using Xunit;
namespace BitFaster.Caching.UnitTests.Counters
@@ -21,7 +21,7 @@ await Threaded.Run(4, () =>
}
});
- adder.Count().Should().Be(400_000);
+ adder.Count().ShouldBe(400_000);
}
}
}
diff --git a/BitFaster.Caching.UnitTests/Counters/StripedLongAdderTests.cs b/BitFaster.Caching.UnitTests/Counters/StripedLongAdderTests.cs
index 4062e2af..0e32eb78 100644
--- a/BitFaster.Caching.UnitTests/Counters/StripedLongAdderTests.cs
+++ b/BitFaster.Caching.UnitTests/Counters/StripedLongAdderTests.cs
@@ -1,5 +1,5 @@
using BitFaster.Caching.Counters;
-using FluentAssertions;
+using Shouldly;
using Xunit;
namespace BitFaster.Caching.UnitTests.Counters
@@ -9,7 +9,7 @@ public class StripedLongAdderTests
[Fact]
public void InitialValueIsZero()
{
- new Counter().Count().Should().Be(0);
+ new Counter().Count().ShouldBe(0);
}
[Fact]
@@ -19,7 +19,7 @@ public void WhenIncrementedOneIsAdded()
adder.Increment();
- adder.Count().Should().Be(1);
+ adder.Count().ShouldBe(1);
}
}
}
diff --git a/BitFaster.Caching.UnitTests/Disposable.cs b/BitFaster.Caching.UnitTests/Disposable.cs
index 2ca08414..8b671a8e 100644
--- a/BitFaster.Caching.UnitTests/Disposable.cs
+++ b/BitFaster.Caching.UnitTests/Disposable.cs
@@ -1,5 +1,5 @@
using System;
-using FluentAssertions;
+using Shouldly;
namespace BitFaster.Caching.UnitTests
{
@@ -15,7 +15,7 @@ public Disposable() { }
public void Dispose()
{
- this.IsDisposed.Should().BeFalse();
+ this.IsDisposed.ShouldBeFalse();
IsDisposed = true;
}
}
diff --git a/BitFaster.Caching.UnitTests/DisposableValueFactory.cs b/BitFaster.Caching.UnitTests/DisposableValueFactory.cs
index 0d1fb472..45275365 100644
--- a/BitFaster.Caching.UnitTests/DisposableValueFactory.cs
+++ b/BitFaster.Caching.UnitTests/DisposableValueFactory.cs
@@ -1,10 +1,4 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
-
-namespace BitFaster.Caching.UnitTests
+namespace BitFaster.Caching.UnitTests
{
public class DisposableValueFactory
{
diff --git a/BitFaster.Caching.UnitTests/DurationTests.cs b/BitFaster.Caching.UnitTests/DurationTests.cs
index 38fbce72..22c8e816 100644
--- a/BitFaster.Caching.UnitTests/DurationTests.cs
+++ b/BitFaster.Caching.UnitTests/DurationTests.cs
@@ -2,7 +2,7 @@
using System.Diagnostics;
using System.Runtime.InteropServices;
using BitFaster.Caching.Lru;
-using FluentAssertions;
+using Shouldly;
using Xunit;
using Xunit.Abstractions;
@@ -25,24 +25,22 @@ public void SinceEpoch()
#if NETCOREAPP3_0_OR_GREATER
if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
{
- // eps is 1/200 of a second
- ulong eps = (ulong)(Stopwatch.Frequency / 200);
- Duration.SinceEpoch().raw.Should().BeCloseTo(Stopwatch.GetTimestamp(), eps);
+ Duration.SinceEpoch().raw.ShouldBe(Stopwatch.GetTimestamp());
}
else
{
- Duration.SinceEpoch().raw.Should().BeCloseTo(Environment.TickCount64, 15);
+ Duration.SinceEpoch().raw.ShouldBe(Environment.TickCount64);
}
#else
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
{
- Duration.SinceEpoch().raw.Should().BeCloseTo(Duration.GetTickCount64(), 15);
+ Duration.SinceEpoch().raw.ShouldBe(Duration.GetTickCount64());
}
else
{
// eps is 1/200 of a second
ulong eps = (ulong)(Stopwatch.Frequency / 200);
- Duration.SinceEpoch().raw.Should().BeCloseTo(Stopwatch.GetTimestamp(), eps);
+ Duration.SinceEpoch().raw.ShouldBe(Stopwatch.GetTimestamp());
}
#endif
}
@@ -53,21 +51,21 @@ public void ToTimeSpan()
#if NETCOREAPP3_0_OR_GREATER
if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
{
- new Duration(100).ToTimeSpan().Should().BeCloseTo(new TimeSpan(100), TimeSpan.FromMilliseconds(50));
+ new Duration(100).ToTimeSpan().ShouldBe(new TimeSpan(100), TimeSpan.FromMilliseconds(50));
}
else
{
- new Duration(1000).ToTimeSpan().Should().BeCloseTo(TimeSpan.FromMilliseconds(1000), TimeSpan.FromMilliseconds(10));
+ new Duration(1000).ToTimeSpan().ShouldBe(TimeSpan.FromMilliseconds(1000), TimeSpan.FromMilliseconds(10));
}
#else
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
{
- new Duration(1000).ToTimeSpan().Should().BeCloseTo(TimeSpan.FromMilliseconds(1000), TimeSpan.FromMilliseconds(10));
+ new Duration(1000).ToTimeSpan().ShouldBe(TimeSpan.FromMilliseconds(1000), TimeSpan.FromMilliseconds(10));
}
else
{
// for Stopwatch.GetTimestamp() this is number of ticks
- new Duration(1 * Stopwatch.Frequency).ToTimeSpan().Should().BeCloseTo(TimeSpan.FromSeconds(1), TimeSpan.FromMilliseconds(10));
+ new Duration(1 * Stopwatch.Frequency).ToTimeSpan().ShouldBe(TimeSpan.FromSeconds(1), TimeSpan.FromMilliseconds(10));
}
#endif
}
@@ -79,23 +77,23 @@ public void FromTimeSpan()
if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
{
Duration.FromTimeSpan(TimeSpan.FromSeconds(1)).raw
- .Should().Be(Stopwatch.Frequency);
+ .ShouldBe(Stopwatch.Frequency);
}
else
{
Duration.FromTimeSpan(TimeSpan.FromSeconds(1)).raw
- .Should().Be((long)TimeSpan.FromSeconds(1).TotalMilliseconds);
+ .ShouldBe((long)TimeSpan.FromSeconds(1).TotalMilliseconds);
}
#else
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
{
Duration.FromTimeSpan(TimeSpan.FromSeconds(1)).raw
- .Should().Be((long)TimeSpan.FromSeconds(1).TotalMilliseconds);
+ .ShouldBe((long)TimeSpan.FromSeconds(1).TotalMilliseconds);
}
else
{
Duration.FromTimeSpan(TimeSpan.FromSeconds(1)).raw
- .Should().Be(Stopwatch.Frequency);
+ .ShouldBe(Stopwatch.Frequency);
}
#endif
}
@@ -105,7 +103,7 @@ public void RoundTripMilliseconds()
{
Duration.FromMilliseconds(2000)
.ToTimeSpan()
- .Should().BeCloseTo(TimeSpan.FromMilliseconds(2000), TimeSpan.FromMilliseconds(50));
+ .ShouldBe(TimeSpan.FromMilliseconds(2000), TimeSpan.FromMilliseconds(50));
}
[Fact]
@@ -113,7 +111,7 @@ public void RoundTripSeconds()
{
Duration.FromSeconds(2)
.ToTimeSpan()
- .Should().BeCloseTo(TimeSpan.FromSeconds(2), TimeSpan.FromMilliseconds(50));
+ .ShouldBe(TimeSpan.FromSeconds(2), TimeSpan.FromMilliseconds(50));
}
[Fact]
@@ -121,7 +119,7 @@ public void RoundTripMinutes()
{
Duration.FromMinutes(2)
.ToTimeSpan()
- .Should().BeCloseTo(TimeSpan.FromMinutes(2), TimeSpan.FromMilliseconds(100));
+ .ShouldBe(TimeSpan.FromMinutes(2), TimeSpan.FromMilliseconds(100));
}
[Fact]
@@ -129,7 +127,7 @@ public void RoundTripHours()
{
Duration.FromHours(2)
.ToTimeSpan()
- .Should().BeCloseTo(TimeSpan.FromHours(2), TimeSpan.FromMilliseconds(100));
+ .ShouldBe(TimeSpan.FromHours(2), TimeSpan.FromMilliseconds(100));
}
[Fact]
@@ -137,7 +135,7 @@ public void RoundTripDays()
{
Duration.FromDays(2)
.ToTimeSpan()
- .Should().BeCloseTo(TimeSpan.FromDays(2), TimeSpan.FromMilliseconds(100));
+ .ShouldBe(TimeSpan.FromDays(2), TimeSpan.FromMilliseconds(100));
}
[Fact]
@@ -145,7 +143,7 @@ public void OperatorPlus()
{
(Duration.FromDays(2) + Duration.FromDays(2))
.ToTimeSpan()
- .Should().BeCloseTo(TimeSpan.FromDays(4), TimeSpan.FromMilliseconds(100));
+ .ShouldBe(TimeSpan.FromDays(4), TimeSpan.FromMilliseconds(100));
}
[Fact]
@@ -153,21 +151,21 @@ public void OperatorMinus()
{
(Duration.FromDays(4) - Duration.FromDays(2))
.ToTimeSpan()
- .Should().BeCloseTo(TimeSpan.FromDays(2), TimeSpan.FromMilliseconds(100));
+ .ShouldBe(TimeSpan.FromDays(2), TimeSpan.FromMilliseconds(100));
}
[Fact]
public void OperatorGreater()
{
(Duration.FromDays(4) > Duration.FromDays(2))
- .Should().BeTrue();
+ .ShouldBeTrue();
}
[Fact]
public void OperatorLess()
{
(Duration.FromDays(4) < Duration.FromDays(2))
- .Should().BeFalse();
+ .ShouldBeFalse();
}
// This is for diagnostic purposes when tests run on different operating systems.
diff --git a/BitFaster.Caching.UnitTests/ExpireAfterAccessTests.cs b/BitFaster.Caching.UnitTests/ExpireAfterAccessTests.cs
index 4c64737e..f91e21e7 100644
--- a/BitFaster.Caching.UnitTests/ExpireAfterAccessTests.cs
+++ b/BitFaster.Caching.UnitTests/ExpireAfterAccessTests.cs
@@ -1,5 +1,4 @@
-using System;
-using FluentAssertions;
+using Shouldly;
using Xunit;
namespace BitFaster.Caching.UnitTests
@@ -17,25 +16,25 @@ public ExpireAfterAccessTests()
[Fact]
public void TimeToExpireReturnsCtorArg()
{
- expiryCalculator.TimeToExpire.Should().Be(expiry.ToTimeSpan());
+ expiryCalculator.TimeToExpire.ShouldBe(expiry.ToTimeSpan());
}
[Fact]
public void AfterCreateReturnsTimeToExpire()
{
- expiryCalculator.GetExpireAfterCreate(1, 2).Should().Be(expiry);
+ expiryCalculator.GetExpireAfterCreate(1, 2).ShouldBe(expiry);
}
[Fact]
public void AfteReadReturnsTimeToExpire()
{
- expiryCalculator.GetExpireAfterRead(1, 2, Duration.SinceEpoch()).Should().Be(expiry);
+ expiryCalculator.GetExpireAfterRead(1, 2, Duration.SinceEpoch()).ShouldBe(expiry);
}
[Fact]
public void AfteUpdateReturnsTimeToExpire()
{
- expiryCalculator.GetExpireAfterUpdate(1, 2, Duration.SinceEpoch()).Should().Be(expiry);
+ expiryCalculator.GetExpireAfterUpdate(1, 2, Duration.SinceEpoch()).ShouldBe(expiry);
}
}
}
diff --git a/BitFaster.Caching.UnitTests/ExpireAfterWriteTests.cs b/BitFaster.Caching.UnitTests/ExpireAfterWriteTests.cs
index 57774eed..84d98b0c 100644
--- a/BitFaster.Caching.UnitTests/ExpireAfterWriteTests.cs
+++ b/BitFaster.Caching.UnitTests/ExpireAfterWriteTests.cs
@@ -1,5 +1,4 @@
-using System;
-using FluentAssertions;
+using Shouldly;
using Xunit;
namespace BitFaster.Caching.UnitTests
@@ -17,26 +16,26 @@ public ExpireAfterWriteTests()
[Fact]
public void TimeToExpireReturnsCtorArg()
{
- expiryCalculator.TimeToExpire.Should().Be(expiry.ToTimeSpan());
+ expiryCalculator.TimeToExpire.ShouldBe(expiry.ToTimeSpan());
}
[Fact]
public void AfterCreateReturnsTimeToExpire()
{
- expiryCalculator.GetExpireAfterCreate(1, 2).Should().Be(expiry);
+ expiryCalculator.GetExpireAfterCreate(1, 2).ShouldBe(expiry);
}
[Fact]
public void AfteReadReturnsCurrentTimeToExpire()
{
var current = new Duration(123);
- expiryCalculator.GetExpireAfterRead(1, 2, current).Should().Be(current);
+ expiryCalculator.GetExpireAfterRead(1, 2, current).ShouldBe(current);
}
[Fact]
public void AfteUpdateReturnsTimeToExpire()
{
- expiryCalculator.GetExpireAfterUpdate(1, 2, Duration.SinceEpoch()).Should().Be(expiry);
+ expiryCalculator.GetExpireAfterUpdate(1, 2, Duration.SinceEpoch()).ShouldBe(expiry);
}
}
}
diff --git a/BitFaster.Caching.UnitTests/Lfu/CmSketchTests.cs b/BitFaster.Caching.UnitTests/Lfu/CmSketchTests.cs
index ba32b42e..879ae7c9 100644
--- a/BitFaster.Caching.UnitTests/Lfu/CmSketchTests.cs
+++ b/BitFaster.Caching.UnitTests/Lfu/CmSketchTests.cs
@@ -1,7 +1,6 @@
-
-using System.Collections.Generic;
+using System.Collections.Generic;
using BitFaster.Caching.Lfu;
-using FluentAssertions;
+using Shouldly;
using Xunit;
namespace BitFaster.Caching.UnitTests.Lfu
@@ -40,11 +39,11 @@ public void Repro()
}
}
- baseline.Size.Should().Be(sketch.Size);
+ baseline.Size.ShouldBe(sketch.Size);
for (int i = 0; i < 1_048_576; i++)
{
- sketch.EstimateFrequency(i).Should().Be(baseline.EstimateFrequency(i));
+ sketch.EstimateFrequency(i).ShouldBe(baseline.EstimateFrequency(i));
}
}
@@ -54,14 +53,14 @@ public void WhenCapacityIsZeroDefaultsSelected()
{
sketch = new CmSketchCore(0, EqualityComparer.Default);
- sketch.ResetSampleSize.Should().Be(10);
+ sketch.ResetSampleSize.ShouldBe(10);
}
[SkippableFact]
public void WhenIncrementedOnceCountIsOne()
{
sketch.Increment(1);
- sketch.EstimateFrequency(1).Should().Be(1);
+ sketch.EstimateFrequency(1).ShouldBe(1);
}
[SkippableFact]
@@ -72,7 +71,7 @@ public void WhenIncrementedMoreThanMaxCountIsMaximum()
sketch.Increment(1);
}
- sketch.EstimateFrequency(1).Should().Be(15);
+ sketch.EstimateFrequency(1).ShouldBe(15);
}
[SkippableFact]
@@ -82,8 +81,8 @@ public void WhenTwoItemsIncrementedCountIsIndependent()
sketch.Increment(1);
sketch.Increment(2);
- sketch.EstimateFrequency(1).Should().Be(2);
- sketch.EstimateFrequency(2).Should().Be(1);
+ sketch.EstimateFrequency(1).ShouldBe(2);
+ sketch.EstimateFrequency(2).ShouldBe(1);
}
[SkippableFact]
@@ -99,15 +98,15 @@ public void WhenSampleSizeExceededCountIsReset()
if (sketch.Size != i)
{
- i.Should().NotBe(1, "sketch should not be reset on the first iteration. Resize logic is broken");
+ i.ShouldNotBe(1, "sketch should not be reset on the first iteration. Resize logic is broken");
reset = true;
break;
}
}
- reset.Should().BeTrue();
- sketch.Size.Should().BeLessThan(10 * 64);
+ reset.ShouldBeTrue();
+ sketch.Size.ShouldBeLessThan(10 * 64);
}
[SkippableFact]
@@ -119,8 +118,8 @@ public void WhenClearedCountIsReset()
sketch.Clear();
- sketch.EstimateFrequency(1).Should().Be(0);
- sketch.EstimateFrequency(2).Should().Be(0);
+ sketch.EstimateFrequency(1).ShouldBe(0);
+ sketch.EstimateFrequency(2).ShouldBe(0);
}
[SkippableFact]
@@ -150,19 +149,19 @@ public void HeavyHitters()
{
if ((i == 0) || (i == 1) || (i == 3) || (i == 5) || (i == 7) || (i == 9))
{
- popularity[i].Should().BeLessThanOrEqualTo(popularity[2]);
+ popularity[i].ShouldBeLessThanOrEqualTo(popularity[2]);
}
else if (i == 2)
{
- popularity[2].Should().BeLessThanOrEqualTo(popularity[4]);
+ popularity[2].ShouldBeLessThanOrEqualTo(popularity[4]);
}
else if (i == 4)
{
- popularity[4].Should().BeLessThanOrEqualTo(popularity[6]);
+ popularity[4].ShouldBeLessThanOrEqualTo(popularity[6]);
}
else if (i == 6)
{
- popularity[6].Should().BeLessThanOrEqualTo(popularity[8]);
+ popularity[6].ShouldBeLessThanOrEqualTo(popularity[8]);
}
}
}
diff --git a/BitFaster.Caching.UnitTests/Lfu/ConcurrentLfuBuilderTests.cs b/BitFaster.Caching.UnitTests/Lfu/ConcurrentLfuBuilderTests.cs
index 343a7958..46c7098f 100644
--- a/BitFaster.Caching.UnitTests/Lfu/ConcurrentLfuBuilderTests.cs
+++ b/BitFaster.Caching.UnitTests/Lfu/ConcurrentLfuBuilderTests.cs
@@ -2,7 +2,7 @@
using BitFaster.Caching.Atomic;
using BitFaster.Caching.Lfu;
using BitFaster.Caching.Scheduler;
-using FluentAssertions;
+using Shouldly;
using Xunit;
namespace BitFaster.Caching.UnitTests.Lfu
@@ -17,7 +17,7 @@ public void TestConcurrencyLevel()
Action constructor = () => { var x = b.Build(); };
- constructor.Should().Throw();
+ constructor.ShouldThrow();
}
[Fact]
@@ -27,7 +27,7 @@ public void TestIntCapacity()
.WithCapacity(3)
.Build();
- lfu.Policy.Eviction.Value.Capacity.Should().Be(3);
+ lfu.Policy.Eviction.Value.Capacity.ShouldBe(3);
}
[Fact]
@@ -38,7 +38,7 @@ public void TestScheduler()
.Build();
var clfu = lfu as ConcurrentLfu;
- clfu.Scheduler.Should().BeOfType();
+ clfu.Scheduler.ShouldBeOfType();
}
[Fact]
@@ -49,7 +49,7 @@ public void TestComparer()
.Build();
lfu.GetOrAdd("a", k => 1);
- lfu.TryGet("A", out var value).Should().BeTrue();
+ lfu.TryGet("A", out var value).ShouldBeTrue();
}
[Fact]
@@ -59,9 +59,9 @@ public void TestExpireAfterAccess()
.WithExpireAfterAccess(TimeSpan.FromSeconds(1))
.Build();
- expireAfterAccess.Policy.ExpireAfterAccess.HasValue.Should().BeTrue();
- expireAfterAccess.Policy.ExpireAfterAccess.Value.TimeToLive.Should().Be(TimeSpan.FromSeconds(1));
- expireAfterAccess.Policy.ExpireAfterWrite.HasValue.Should().BeFalse();
+ expireAfterAccess.Policy.ExpireAfterAccess.HasValue.ShouldBeTrue();
+ expireAfterAccess.Policy.ExpireAfterAccess.Value.TimeToLive.ShouldBe(TimeSpan.FromSeconds(1));
+ expireAfterAccess.Policy.ExpireAfterWrite.HasValue.ShouldBeFalse();
}
[Fact]
@@ -72,7 +72,7 @@ public void TestExpireAfterReadAndExpireAfterWriteThrows()
.WithExpireAfterWrite(TimeSpan.FromSeconds(2));
Action act = () => builder.Build();
- act.Should().Throw();
+ act.ShouldThrow();
}
[Fact]
@@ -82,10 +82,10 @@ public void TestExpireAfter()
.WithExpireAfter(new TestExpiryCalculator((k, v) => Duration.FromMinutes(5)))
.Build();
- expireAfter.Policy.ExpireAfter.HasValue.Should().BeTrue();
+ expireAfter.Policy.ExpireAfter.HasValue.ShouldBeTrue();
- expireAfter.Policy.ExpireAfterAccess.HasValue.Should().BeFalse();
- expireAfter.Policy.ExpireAfterWrite.HasValue.Should().BeFalse();
+ expireAfter.Policy.ExpireAfterAccess.HasValue.ShouldBeFalse();
+ expireAfter.Policy.ExpireAfterWrite.HasValue.ShouldBeFalse();
}
[Fact]
@@ -96,10 +96,10 @@ public void TestAsyncExpireAfter()
.WithExpireAfter(new TestExpiryCalculator((k, v) => Duration.FromMinutes(5)))
.Build();
- expireAfter.Policy.ExpireAfter.HasValue.Should().BeTrue();
+ expireAfter.Policy.ExpireAfter.HasValue.ShouldBeTrue();
- expireAfter.Policy.ExpireAfterAccess.HasValue.Should().BeFalse();
- expireAfter.Policy.ExpireAfterWrite.HasValue.Should().BeFalse();
+ expireAfter.Policy.ExpireAfterAccess.HasValue.ShouldBeFalse();
+ expireAfter.Policy.ExpireAfterWrite.HasValue.ShouldBeFalse();
}
@@ -111,7 +111,7 @@ public void TestExpireAfterWriteAndExpireAfterThrows()
.WithExpireAfter(new TestExpiryCalculator((k, v) => Duration.FromMinutes(5)));
Action act = () => builder.Build();
- act.Should().Throw();
+ act.ShouldThrow();
}
[Fact]
@@ -122,7 +122,7 @@ public void TestExpireAfterAccessAndExpireAfterThrows()
.WithExpireAfter(new TestExpiryCalculator((k, v) => Duration.FromMinutes(5)));
Action act = () => builder.Build();
- act.Should().Throw();
+ act.ShouldThrow();
}
[Fact]
@@ -134,7 +134,7 @@ public void TestExpireAfterAccessAndWriteAndExpireAfterThrows()
.WithExpireAfter(new TestExpiryCalculator((k, v) => Duration.FromMinutes(5)));
Action act = () => builder.Build();
- act.Should().Throw();
+ act.ShouldThrow();
}
[Fact]
@@ -145,7 +145,7 @@ public void TestScopedWithExpireAfterThrows()
.AsScopedCache();
Action act = () => builder.Build();
- act.Should().Throw();
+ act.ShouldThrow();
}
[Fact]
@@ -157,7 +157,7 @@ public void TestScopedAtomicWithExpireAfterThrows()
.WithAtomicGetOrAdd();
Action act = () => builder.Build();
- act.Should().Throw();
+ act.ShouldThrow();
}
[Fact]
@@ -169,7 +169,7 @@ public void TestAsyncScopedWithExpireAfterThrows()
.AsScopedCache();
Action act = () => builder.Build();
- act.Should().Throw();
+ act.ShouldThrow();
}
[Fact]
@@ -182,7 +182,7 @@ public void TestAsyncScopedAtomicWithExpireAfterThrows()
.WithAtomicGetOrAdd();
Action act = () => builder.Build();
- act.Should().Throw();
+ act.ShouldThrow();
}
[Fact]
@@ -193,9 +193,9 @@ public void TestScopedWithExpireAfterWrite()
.AsScopedCache()
.Build();
- expireAfterWrite.Policy.ExpireAfterWrite.HasValue.Should().BeTrue();
- expireAfterWrite.Policy.ExpireAfterWrite.Value.TimeToLive.Should().Be(TimeSpan.FromSeconds(1));
- expireAfterWrite.Policy.ExpireAfterAccess.HasValue.Should().BeFalse();
+ expireAfterWrite.Policy.ExpireAfterWrite.HasValue.ShouldBeTrue();
+ expireAfterWrite.Policy.ExpireAfterWrite.Value.TimeToLive.ShouldBe(TimeSpan.FromSeconds(1));
+ expireAfterWrite.Policy.ExpireAfterAccess.HasValue.ShouldBeFalse();
}
[Fact]
@@ -206,9 +206,9 @@ public void TestScopedWithExpireAfterAccess()
.AsScopedCache()
.Build();
- expireAfterAccess.Policy.ExpireAfterAccess.HasValue.Should().BeTrue();
- expireAfterAccess.Policy.ExpireAfterAccess.Value.TimeToLive.Should().Be(TimeSpan.FromSeconds(1));
- expireAfterAccess.Policy.ExpireAfterWrite.HasValue.Should().BeFalse();
+ expireAfterAccess.Policy.ExpireAfterAccess.HasValue.ShouldBeTrue();
+ expireAfterAccess.Policy.ExpireAfterAccess.Value.TimeToLive.ShouldBe(TimeSpan.FromSeconds(1));
+ expireAfterAccess.Policy.ExpireAfterWrite.HasValue.ShouldBeFalse();
}
[Fact]
@@ -219,9 +219,9 @@ public void TestAtomicWithExpireAfterWrite()
.WithAtomicGetOrAdd()
.Build();
- expireAfterWrite.Policy.ExpireAfterWrite.HasValue.Should().BeTrue();
- expireAfterWrite.Policy.ExpireAfterWrite.Value.TimeToLive.Should().Be(TimeSpan.FromSeconds(1));
- expireAfterWrite.Policy.ExpireAfterAccess.HasValue.Should().BeFalse();
+ expireAfterWrite.Policy.ExpireAfterWrite.HasValue.ShouldBeTrue();
+ expireAfterWrite.Policy.ExpireAfterWrite.Value.TimeToLive.ShouldBe(TimeSpan.FromSeconds(1));
+ expireAfterWrite.Policy.ExpireAfterAccess.HasValue.ShouldBeFalse();
}
[Fact]
@@ -232,9 +232,9 @@ public void TestAtomicWithExpireAfterAccess()
.WithAtomicGetOrAdd()
.Build();
- expireAfterAccess.Policy.ExpireAfterAccess.HasValue.Should().BeTrue();
- expireAfterAccess.Policy.ExpireAfterAccess.Value.TimeToLive.Should().Be(TimeSpan.FromSeconds(1));
- expireAfterAccess.Policy.ExpireAfterWrite.HasValue.Should().BeFalse();
+ expireAfterAccess.Policy.ExpireAfterAccess.HasValue.ShouldBeTrue();
+ expireAfterAccess.Policy.ExpireAfterAccess.Value.TimeToLive.ShouldBe(TimeSpan.FromSeconds(1));
+ expireAfterAccess.Policy.ExpireAfterWrite.HasValue.ShouldBeFalse();
}
[Fact]
@@ -246,9 +246,9 @@ public void TestScopedAtomicWithExpireAfterWrite()
.WithAtomicGetOrAdd()
.Build();
- expireAfterWrite.Policy.ExpireAfterWrite.HasValue.Should().BeTrue();
- expireAfterWrite.Policy.ExpireAfterWrite.Value.TimeToLive.Should().Be(TimeSpan.FromSeconds(1));
- expireAfterWrite.Policy.ExpireAfterAccess.HasValue.Should().BeFalse();
+ expireAfterWrite.Policy.ExpireAfterWrite.HasValue.ShouldBeTrue();
+ expireAfterWrite.Policy.ExpireAfterWrite.Value.TimeToLive.ShouldBe(TimeSpan.FromSeconds(1));
+ expireAfterWrite.Policy.ExpireAfterAccess.HasValue.ShouldBeFalse();
}
[Fact]
@@ -260,9 +260,9 @@ public void TestScopedAtomicWithExpireAfterAccess()
.WithAtomicGetOrAdd()
.Build();
- expireAfterAccess.Policy.ExpireAfterAccess.HasValue.Should().BeTrue();
- expireAfterAccess.Policy.ExpireAfterAccess.Value.TimeToLive.Should().Be(TimeSpan.FromSeconds(1));
- expireAfterAccess.Policy.ExpireAfterWrite.HasValue.Should().BeFalse();
+ expireAfterAccess.Policy.ExpireAfterAccess.HasValue.ShouldBeTrue();
+ expireAfterAccess.Policy.ExpireAfterAccess.Value.TimeToLive.ShouldBe(TimeSpan.FromSeconds(1));
+ expireAfterAccess.Policy.ExpireAfterWrite.HasValue.ShouldBeFalse();
}
// 1
@@ -274,8 +274,8 @@ public void WithScopedValues()
.WithCapacity(3)
.Build();
- lru.Should().BeOfType>();
- lru.Policy.Eviction.Value.Capacity.Should().Be(3);
+ lru.ShouldBeOfType>();
+ lru.Policy.Eviction.Value.Capacity.ShouldBe(3);
}
// 2
@@ -287,7 +287,7 @@ public void WithAtomicFactory()
.WithCapacity(3)
.Build();
- lru.Should().BeOfType>();
+ lru.ShouldBeOfType>();
}
// 3
@@ -299,7 +299,7 @@ public void AsAsync()
.WithCapacity(3)
.Build();
- lru.Should().BeAssignableTo>();
+ lru.ShouldBeAssignableTo>();
}
// 4
@@ -312,8 +312,8 @@ public void WithAtomicWithScope()
.WithCapacity(3)
.Build();
- lru.Should().BeOfType>();
- lru.Policy.Eviction.Value.Capacity.Should().Be(3);
+ lru.ShouldBeOfType>();
+ lru.Policy.Eviction.Value.Capacity.ShouldBe(3);
}
// 5
@@ -326,8 +326,8 @@ public void WithScopedWithAtomic()
.WithCapacity(3)
.Build();
- lru.Should().BeOfType>();
- lru.Policy.Eviction.Value.Capacity.Should().Be(3);
+ lru.ShouldBeOfType>();
+ lru.Policy.Eviction.Value.Capacity.ShouldBe(3);
}
// 6
@@ -340,9 +340,9 @@ public void AsAsyncWithScoped()
.WithCapacity(3)
.Build();
- lru.Should().BeAssignableTo>();
+ lru.ShouldBeAssignableTo>();
- lru.Policy.Eviction.Value.Capacity.Should().Be(3);
+ lru.Policy.Eviction.Value.Capacity.ShouldBe(3);
}
// 7
@@ -355,8 +355,8 @@ public void WithScopedAsAsync()
.WithCapacity(3)
.Build();
- lru.Should().BeAssignableTo>();
- lru.Policy.Eviction.Value.Capacity.Should().Be(3);
+ lru.ShouldBeAssignableTo>();
+ lru.Policy.Eviction.Value.Capacity.ShouldBe(3);
}
// 8
@@ -369,7 +369,7 @@ public void WithAtomicAsAsync()
.WithCapacity(3)
.Build();
- lru.Should().BeAssignableTo>();
+ lru.ShouldBeAssignableTo>();
}
// 9
@@ -382,7 +382,7 @@ public void AsAsyncWithAtomic()
.WithCapacity(3)
.Build();
- lru.Should().BeAssignableTo>();
+ lru.ShouldBeAssignableTo>();
}
// 10
@@ -396,7 +396,7 @@ public void WithAtomicWithScopedAsAsync()
.WithCapacity(3)
.Build();
- lru.Should().BeAssignableTo>();
+ lru.ShouldBeAssignableTo>();
}
// 11
@@ -410,7 +410,7 @@ public void WithAtomicAsAsyncWithScoped()
.WithCapacity(3)
.Build();
- lru.Should().BeAssignableTo>();
+ lru.ShouldBeAssignableTo>();
}
// 12
@@ -424,7 +424,7 @@ public void WithScopedWithAtomicAsAsync()
.WithCapacity(3)
.Build();
- lru.Should().BeAssignableTo>();
+ lru.ShouldBeAssignableTo>();
}
// 13
@@ -438,7 +438,7 @@ public void WithScopedAsAsyncWithAtomic()
.WithCapacity(3)
.Build();
- lru.Should().BeAssignableTo>();
+ lru.ShouldBeAssignableTo>();
}
// 14
@@ -452,7 +452,7 @@ public void AsAsyncWithScopedWithAtomic()
.WithCapacity(3)
.Build();
- lru.Should().BeAssignableTo>();
+ lru.ShouldBeAssignableTo>();
}
// 15
@@ -466,7 +466,7 @@ public void AsAsyncWithAtomicWithScoped()
.WithCapacity(3)
.Build();
- lru.Should().BeAssignableTo>();
+ lru.ShouldBeAssignableTo>();
}
}
}
diff --git a/BitFaster.Caching.UnitTests/Lfu/ConcurrentLfuCoreTests.cs b/BitFaster.Caching.UnitTests/Lfu/ConcurrentLfuCoreTests.cs
index f3318658..e9506e03 100644
--- a/BitFaster.Caching.UnitTests/Lfu/ConcurrentLfuCoreTests.cs
+++ b/BitFaster.Caching.UnitTests/Lfu/ConcurrentLfuCoreTests.cs
@@ -4,7 +4,7 @@
using System.Threading.Tasks;
using BitFaster.Caching.Lfu;
using BitFaster.Caching.UnitTests.Retry;
-using FluentAssertions;
+using Shouldly;
using Xunit;
namespace BitFaster.Caching.UnitTests.Lfu
@@ -29,7 +29,7 @@ public ConcurrentLfuCoreTests()
[Fact]
public void EvictionPolicyCapacityReturnsCapacity()
{
- lfu.Policy.Eviction.Value.Capacity.Should().Be(capacity);
+ lfu.Policy.Eviction.Value.Capacity.ShouldBe(capacity);
}
[Fact]
@@ -38,8 +38,8 @@ public void WhenKeyIsRequestedItIsCreatedAndCached()
var result1 = lfu.GetOrAdd(1, valueFactory.Create);
var result2 = lfu.GetOrAdd(1, valueFactory.Create);
- valueFactory.timesCalled.Should().Be(1);
- result1.Should().Be(result2);
+ valueFactory.timesCalled.ShouldBe(1);
+ result1.ShouldBe(result2);
}
#if NETCOREAPP3_0_OR_GREATER
[Fact]
@@ -48,8 +48,8 @@ public void WhenKeyIsRequestedWithArgItIsCreatedAndCached()
var result1 = lfu.GetOrAdd(1, valueFactory.Create, 9);
var result2 = lfu.GetOrAdd(1, valueFactory.Create, 17);
- valueFactory.timesCalled.Should().Be(1);
- result1.Should().Be(result2);
+ valueFactory.timesCalled.ShouldBe(1);
+ result1.ShouldBe(result2);
}
#endif
[Fact]
@@ -59,8 +59,8 @@ public async Task WhenKeyIsRequesteItIsCreatedAndCachedAsync()
var result1 = await asyncLfu.GetOrAddAsync(1, valueFactory.CreateAsync);
var result2 = await asyncLfu.GetOrAddAsync(1, valueFactory.CreateAsync);
- valueFactory.timesCalled.Should().Be(1);
- result1.Should().Be(result2);
+ valueFactory.timesCalled.ShouldBe(1);
+ result1.ShouldBe(result2);
}
#if NETCOREAPP3_0_OR_GREATER
@@ -71,8 +71,8 @@ public async Task WhenKeyIsRequestedWithArgItIsCreatedAndCachedAsync()
var result1 = await asyncLfu.GetOrAddAsync(1, valueFactory.CreateAsync, 9);
var result2 = await asyncLfu.GetOrAddAsync(1, valueFactory.CreateAsync, 17);
- valueFactory.timesCalled.Should().Be(1);
- result1.Should().Be(result2);
+ valueFactory.timesCalled.ShouldBe(1);
+ result1.ShouldBe(result2);
}
#endif
@@ -82,8 +82,8 @@ public void WhenItemIsUpdatedItIsUpdated()
lfu.GetOrAdd(1, k => k);
lfu.AddOrUpdate(1, 2);
- lfu.TryGet(1, out var value).Should().BeTrue();
- value.Should().Be(2);
+ lfu.TryGet(1, out var value).ShouldBeTrue();
+ value.ShouldBe(2);
}
[RetryFact]
@@ -91,8 +91,8 @@ public void WhenItemDoesNotExistUpdatedAddsItem()
{
lfu.AddOrUpdate(1, 2);
- lfu.TryGet(1, out var value).Should().BeTrue();
- value.Should().Be(2);
+ lfu.TryGet(1, out var value).ShouldBeTrue();
+ value.ShouldBe(2);
}
@@ -101,8 +101,8 @@ public void WhenKeyExistsTryRemoveRemovesItem()
{
lfu.GetOrAdd(1, k => k);
- lfu.TryRemove(1).Should().BeTrue();
- lfu.TryGet(1, out _).Should().BeFalse();
+ lfu.TryRemove(1).ShouldBeTrue();
+ lfu.TryGet(1, out _).ShouldBeFalse();
}
#if NETCOREAPP3_0_OR_GREATER
@@ -111,8 +111,8 @@ public void WhenKeyExistsTryRemoveReturnsValue()
{
lfu.GetOrAdd(1, valueFactory.Create);
- lfu.TryRemove(1, out var value).Should().BeTrue();
- value.Should().Be(1);
+ lfu.TryRemove(1, out var value).ShouldBeTrue();
+ value.ShouldBe(1);
}
[Fact]
@@ -120,8 +120,8 @@ public void WhenItemExistsTryRemoveRemovesItem()
{
lfu.GetOrAdd(1, k => k);
- lfu.TryRemove(new KeyValuePair(1, 1)).Should().BeTrue();
- lfu.TryGet(1, out _).Should().BeFalse();
+ lfu.TryRemove(new KeyValuePair(1, 1)).ShouldBeTrue();
+ lfu.TryGet(1, out _).ShouldBeFalse();
}
[Fact]
@@ -129,8 +129,8 @@ public void WhenItemDoesntMatchTryRemoveDoesNotRemove()
{
lfu.GetOrAdd(1, k => k);
- lfu.TryRemove(new KeyValuePair(1, 2)).Should().BeFalse();
- lfu.TryGet(1, out var value).Should().BeTrue();
+ lfu.TryRemove(new KeyValuePair(1, 2)).ShouldBeFalse();
+ lfu.TryGet(1, out var value).ShouldBeTrue();
}
#endif
@@ -142,8 +142,8 @@ public void WhenClearedCacheIsEmpty()
lfu.Clear();
- lfu.Count.Should().Be(0);
- lfu.TryGet(1, out var _).Should().BeFalse();
+ lfu.Count.ShouldBe(0);
+ lfu.TryGet(1, out var _).ShouldBeFalse();
}
[Fact]
@@ -155,12 +155,12 @@ public void TrimRemovesNItems()
}
DoMaintenance(lfu);
- lfu.Count.Should().Be(20);
+ lfu.Count.ShouldBe(20);
lfu.Policy.Eviction.Value.Trim(5);
DoMaintenance(lfu);
- lfu.Count.Should().Be(15);
+ lfu.Count.ShouldBe(15);
}
[Fact]
@@ -170,10 +170,10 @@ public void WhenItemsAddedGenericEnumerateContainsKvps()
lfu.GetOrAdd(2, k => k);
var enumerator = lfu.GetEnumerator();
- enumerator.MoveNext().Should().BeTrue();
- enumerator.Current.Should().Be(new KeyValuePair(1, 1));
- enumerator.MoveNext().Should().BeTrue();
- enumerator.Current.Should().Be(new KeyValuePair(2, 2));
+ enumerator.MoveNext().ShouldBeTrue();
+ enumerator.Current.ShouldBe(new KeyValuePair(1, 1));
+ enumerator.MoveNext().ShouldBeTrue();
+ enumerator.Current.ShouldBe(new KeyValuePair(2, 2));
}
[Fact]
@@ -183,7 +183,7 @@ public void WhenItemsAddedEnumerateContainsKvps()
lfu.GetOrAdd(2, k => k);
var enumerable = (IEnumerable)lfu;
- enumerable.Should().BeEquivalentTo(new[] { new KeyValuePair(1, 1), new KeyValuePair(2, 2) });
+ enumerable.ShouldBe(new[] { new KeyValuePair(1, 1), new KeyValuePair(2, 2) });
}
}
diff --git a/BitFaster.Caching.UnitTests/Lfu/ConcurrentLfuSoakTests.cs b/BitFaster.Caching.UnitTests/Lfu/ConcurrentLfuSoakTests.cs
index 9c9f29f9..c30418f7 100644
--- a/BitFaster.Caching.UnitTests/Lfu/ConcurrentLfuSoakTests.cs
+++ b/BitFaster.Caching.UnitTests/Lfu/ConcurrentLfuSoakTests.cs
@@ -7,7 +7,7 @@
using BitFaster.Caching.Buffers;
using BitFaster.Caching.Lfu;
using BitFaster.Caching.Scheduler;
-using FluentAssertions;
+using Shouldly;
using Xunit;
using Xunit.Abstractions;
@@ -107,7 +107,7 @@ public void VerifyMisses()
this.output.WriteLine($"Cache misses {cache.Metrics.Value.Misses} (sampled {samplePercent}%)");
this.output.WriteLine($"Maintenance ops {cache.Scheduler.RunCount}");
- cache.Metrics.Value.Misses.Should().Be(iterations);
+ cache.Metrics.Value.Misses.ShouldBe(iterations);
}
private void VerifyHits(ConcurrentLfu cache, int iterations, int minSamples)
@@ -140,7 +140,7 @@ private void VerifyHits(ConcurrentLfu cache, int iterations, int minSa
this.output.WriteLine($"Error: {cache.Scheduler.LastException.Value}");
}
- cache.Metrics.Value.Hits.Should().BeGreaterThanOrEqualTo(minSamples);
+ cache.Metrics.Value.Hits.ShouldBeGreaterThanOrEqualTo(minSamples);
// verify this doesn't block or throw
var b = cache.Scheduler as BackgroundThreadScheduler;
@@ -287,7 +287,7 @@ await Threaded.Run(threads, i =>
this.output.WriteLine($"Cache misses {cache.Metrics.Value.Misses} (sampled {samplePercent}%)");
this.output.WriteLine($"Maintenance ops {cache.Scheduler.RunCount}");
- cache.Metrics.Value.Misses.Should().Be(loopIterations * threads);
+ cache.Metrics.Value.Misses.ShouldBe(loopIterations * threads);
RunIntegrityCheck(cache, this.output);
}
@@ -308,7 +308,7 @@ public async Task WhenConcurrentUpdateAndRemoveKvp()
for (var i = 0; i < 100_000; i++)
{
cache.AddOrUpdate(5, "a");
- cache.TryGet(5, out _).Should().BeTrue("key 'a' should not be deleted");
+ cache.TryGet(5, out _).ShouldBeTrue("key 'a' should not be deleted");
cache.AddOrUpdate(5, "x");
}
@@ -422,8 +422,8 @@ public void Validate(ITestOutputHelper output)
cache.DoMaintenance();
// buffers should be empty after maintenance
- this.readBuffer.Count.Should().Be(0);
- this.writeBuffer.Count.Should().Be(0);
+ this.readBuffer.Count.ShouldBe(0);
+ this.writeBuffer.Count.ShouldBe(0);
// all the items in the LRUs must exist in the dictionary.
// no items should be marked as removed after maintenance has run
@@ -435,7 +435,7 @@ public void Validate(ITestOutputHelper output)
VerifyDictionaryInLrus();
// cache must be within capacity
- cache.Count.Should().BeLessThanOrEqualTo(cache.Capacity, "capacity out of valid range");
+ cache.Count.ShouldBeLessThanOrEqualTo(cache.Capacity, "capacity out of valid range");
}
private void VerifyLruInDictionary(LfuNodeList lfuNodes, ITestOutputHelper output)
@@ -444,10 +444,10 @@ private void VerifyLruInDictionary(LfuNodeList lfuNodes, ITestOutputHelper
while (node != null)
{
- node.WasRemoved.Should().BeFalse();
- node.WasDeleted.Should().BeFalse();
+ node.WasRemoved.ShouldBeFalse();
+ node.WasDeleted.ShouldBeFalse();
- cache.TryGet(node.Key, out _).Should().BeTrue($"Orphaned node with key {node.Key} detected.");
+ cache.TryGet(node.Key, out _).ShouldBeTrue($"Orphaned node with key {node.Key} detected.");
node = node.Next;
}
@@ -458,7 +458,7 @@ private void VerifyDictionaryInLrus()
foreach (var kvp in this.cache)
{
var exists = Exists(kvp, this.windowLru) || Exists(kvp, this.probationLru) || Exists(kvp, this.protectedLru);
- exists.Should().BeTrue($"key {kvp.Key} must exist in LRU lists");
+ exists.ShouldBeTrue($"key {kvp.Key} must exist in LRU lists");
}
}
diff --git a/BitFaster.Caching.UnitTests/Lfu/ConcurrentLfuTests.cs b/BitFaster.Caching.UnitTests/Lfu/ConcurrentLfuTests.cs
index 0f3756bc..f14d4a29 100644
--- a/BitFaster.Caching.UnitTests/Lfu/ConcurrentLfuTests.cs
+++ b/BitFaster.Caching.UnitTests/Lfu/ConcurrentLfuTests.cs
@@ -1,14 +1,12 @@
using System;
using System.Collections;
using System.Collections.Generic;
-using System.Diagnostics;
using System.Linq;
using System.Threading.Tasks;
-using BitFaster.Caching.Buffers;
using BitFaster.Caching.Lfu;
using BitFaster.Caching.Scheduler;
using BitFaster.Caching.UnitTests.Lru;
-using FluentAssertions;
+using Shouldly;
using Xunit;
using Xunit.Abstractions;
@@ -31,7 +29,7 @@ public void WhenCapacityIsLessThan3CtorThrows()
{
Action constructor = () => { var x = new ConcurrentLfu(2); };
- constructor.Should().Throw();
+ constructor.ShouldThrow();
}
[Fact]
@@ -39,7 +37,7 @@ public void WhenCapacityIsValidCacheIsCreated()
{
var x = new ConcurrentLfu(3);
- x.Capacity.Should().Be(3);
+ x.Capacity.ShouldBe(3);
}
[Fact]
@@ -47,14 +45,14 @@ public void WhenConcurrencyIsLessThan1CtorThrows()
{
Action constructor = () => { var x = new ConcurrentLfu(0, 20, new ForegroundScheduler(), EqualityComparer.Default); };
- constructor.Should().Throw();
+ constructor.ShouldThrow();
}
[Fact]
public void DefaultSchedulerIsThreadPool()
{
var cache = new ConcurrentLfu(20);
- cache.Scheduler.Should().BeOfType();
+ cache.Scheduler.ShouldBeOfType();
}
[Fact]
@@ -63,8 +61,8 @@ public void WhenKeyIsRequestedItIsCreatedAndCached()
var result1 = cache.GetOrAdd(1, valueFactory.Create);
var result2 = cache.GetOrAdd(1, valueFactory.Create);
- valueFactory.timesCalled.Should().Be(1);
- result1.Should().Be(result2);
+ valueFactory.timesCalled.ShouldBe(1);
+ result1.ShouldBe(result2);
}
[Fact]
@@ -73,8 +71,8 @@ public void WhenKeyIsRequestedWithArgItIsCreatedAndCached()
var result1 = cache.GetOrAdd(1, valueFactory.Create, 9);
var result2 = cache.GetOrAdd(1, valueFactory.Create, 17);
- valueFactory.timesCalled.Should().Be(1);
- result1.Should().Be(result2);
+ valueFactory.timesCalled.ShouldBe(1);
+ result1.ShouldBe(result2);
}
[Fact]
@@ -83,8 +81,8 @@ public async Task WhenKeyIsRequesteItIsCreatedAndCachedAsync()
var result1 = await cache.GetOrAddAsync(1, valueFactory.CreateAsync);
var result2 = await cache.GetOrAddAsync(1, valueFactory.CreateAsync);
- valueFactory.timesCalled.Should().Be(1);
- result1.Should().Be(result2);
+ valueFactory.timesCalled.ShouldBe(1);
+ result1.ShouldBe(result2);
}
[Fact]
@@ -93,8 +91,8 @@ public async Task WhenKeyIsRequestedWithArgItIsCreatedAndCachedAsync()
var result1 = await cache.GetOrAddAsync(1, valueFactory.CreateAsync, 9);
var result2 = await cache.GetOrAddAsync(1, valueFactory.CreateAsync, 17);
- valueFactory.timesCalled.Should().Be(1);
- result1.Should().Be(result2);
+ valueFactory.timesCalled.ShouldBe(1);
+ result1.ShouldBe(result2);
}
[Fact]
@@ -113,7 +111,7 @@ public void WhenItemsAddedExceedsCapacityItemsAreDiscarded()
cache.DoMaintenance();
LogLru();
- cache.Count.Should().Be(20);
+ cache.Count.ShouldBe(20);
}
[Fact]
@@ -131,8 +129,8 @@ public void WhenItemIsEvictedItIsDisposed()
dcache.DoMaintenance();
LogLru();
- dcache.Count.Should().Be(20);
- disposables.Count(d => d.IsDisposed).Should().Be(5);
+ dcache.Count.ShouldBe(20);
+ disposables.Count(d => d.IsDisposed).ShouldBe(5);
}
// protected 15
@@ -185,16 +183,16 @@ public void WhenNewItemsAreAddedTheyArePromotedBasedOnFrequency()
// W[24] Protected[4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 20, 21, 22, 23] Probation[1, 2, 3, 25]
// W[24] Protected[5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 20, 21, 22, 23, 25] Probation[1, 2, 3, 4]
- cache.Count.Should().Be(20);
+ cache.Count.ShouldBe(20);
// W [24] Protected [5,6,7,8,9,10,11,12,13,14,20,21,22,23,25] Probation []
cache.Trim(4);
cache.DoMaintenance();
LogLru();
- cache.TryGet(1, out var value1).Should().BeFalse();
- cache.TryGet(2, out var value2).Should().BeFalse();
- cache.Count.Should().Be(16);
+ cache.TryGet(1, out var value1).ShouldBeFalse();
+ cache.TryGet(2, out var value2).ShouldBeFalse();
+ cache.Count.ShouldBe(16);
}
[Fact]
@@ -230,7 +228,7 @@ public void ReadPromotesProbation()
cache.DoMaintenance();
LogLru();
- cache.TryGet(16, out var value1).Should().BeTrue();
+ cache.TryGet(16, out var value1).ShouldBeTrue();
}
// when probation item is written it is moved to protected
@@ -247,7 +245,7 @@ public void WritePromotesProbation()
LogLru();
// W [24] Protected [16] Probation [2,6,7,8,9,10,11,12,13,14,15,17,18,19,20,21,22,23]
- cache.TryUpdate(16, -16).Should().BeTrue();
+ cache.TryUpdate(16, -16).ShouldBeTrue();
cache.DoMaintenance();
LogLru();
@@ -267,7 +265,7 @@ public void WritePromotesProbation()
cache.DoMaintenance();
LogLru();
- cache.TryGet(16, out var value1).Should().BeTrue();
+ cache.TryGet(16, out var value1).ShouldBeTrue();
}
[Fact]
@@ -302,7 +300,7 @@ public void ReadUpdatesProtectedLruOrder()
cache.DoMaintenance();
LogLru();
- cache.TryGet(7, out var _).Should().BeTrue();
+ cache.TryGet(7, out var _).ShouldBeTrue();
}
[Fact]
@@ -327,7 +325,7 @@ public void WriteUpdatesProtectedLruOrder()
// W [19] Protected [8,9,7] Probation [0,1,2,3,4,5,6,10,11,12,13,14,15,16,17,18]
// element 7 now moved to back of LRU
- cache.TryUpdate(7, -7).Should().BeTrue();
+ cache.TryUpdate(7, -7).ShouldBeTrue();
cache.DoMaintenance();
LogLru();
@@ -337,7 +335,7 @@ public void WriteUpdatesProtectedLruOrder()
cache.DoMaintenance();
LogLru();
- cache.TryGet(7, out var _).Should().BeTrue();
+ cache.TryGet(7, out var _).ShouldBeTrue();
}
[Fact]
@@ -402,8 +400,8 @@ public void WhenHitRateChangesWindowSizeIsAdapted()
cache.DoMaintenance();
LogLru();
- cache.TryGet(666, out var _).Should().BeTrue();
- cache.TryGet(667, out var _).Should().BeTrue();
+ cache.TryGet(666, out var _).ShouldBeTrue();
+ cache.TryGet(667, out var _).ShouldBeTrue();
this.output.WriteLine($"Scheduler ran {cache.Scheduler.RunCount} times.");
}
@@ -415,18 +413,18 @@ public void ReadSchedulesMaintenanceWhenBufferIsFull()
cache = new ConcurrentLfu(1, 20, scheduler, EqualityComparer.Default);
cache.GetOrAdd(1, k => k);
- scheduler.RunCount.Should().Be(1);
+ scheduler.RunCount.ShouldBe(1);
cache.DoMaintenance();
for (int i = 0; i < ConcurrentLfu.DefaultBufferSize; i++)
{
- scheduler.RunCount.Should().Be(1);
+ scheduler.RunCount.ShouldBe(1);
cache.GetOrAdd(1, k => k);
}
// read buffer is now full, next read triggers maintenance
cache.GetOrAdd(1, k => k);
- scheduler.RunCount.Should().Be(2);
+ scheduler.RunCount.ShouldBe(2);
}
[Fact]
@@ -436,7 +434,7 @@ public void WhenReadBufferIsFullReadsAreDropped()
cache = new ConcurrentLfu(1, 20, scheduler, EqualityComparer.Default);
cache.GetOrAdd(1, k => k);
- scheduler.RunCount.Should().Be(1);
+ scheduler.RunCount.ShouldBe(1);
cache.DoMaintenance();
for (int i = 0; i < ConcurrentLfu.DefaultBufferSize * 2; i++)
@@ -446,7 +444,7 @@ public void WhenReadBufferIsFullReadsAreDropped()
cache.DoMaintenance();
- cache.Metrics.Value.Hits.Should().Be(ConcurrentLfu.DefaultBufferSize);
+ cache.Metrics.Value.Hits.ShouldBe(ConcurrentLfu.DefaultBufferSize);
}
[Fact]
@@ -462,7 +460,7 @@ public void WhenWriteBufferIsFullAddDoesMaintenance()
cache.DoMaintenance();
// remove the item but don't flush, it is now in the write buffer and maintenance is scheduled
- cache.TryRemove(-1).Should().BeTrue();
+ cache.TryRemove(-1).ShouldBeTrue();
// add buffer size items, last iteration will invoke maintenance on the foreground since write
// buffer is full and test scheduler did not do any work
@@ -473,7 +471,7 @@ public void WhenWriteBufferIsFullAddDoesMaintenance()
// pending write (to remove -1) should be flushed by the 128th write calling maintenance
// directly within AfterWrite
- cache.TryGet(-1, out var _).Should().BeFalse();
+ cache.TryGet(-1, out var _).ShouldBeFalse();
}
// backcompat: remove conditional compile
@@ -487,7 +485,7 @@ public void WhenWriteBufferIsFullUpdatesAreDropped()
cache = new ConcurrentLfu(1, capacity, scheduler, EqualityComparer.Default);
cache.GetOrAdd(1, k => k);
- scheduler.RunCount.Should().Be(1);
+ scheduler.RunCount.ShouldBe(1);
cache.DoMaintenance();
for (int i = 0; i < bufferSize * 2; i++)
@@ -497,32 +495,32 @@ public void WhenWriteBufferIsFullUpdatesAreDropped()
cache.DoMaintenance();
- cache.Metrics.Value.Updated.Should().Be(bufferSize);
+ cache.Metrics.Value.Updated.ShouldBe(bufferSize);
}
#endif
[Fact]
public void EvictionPolicyReturnsCapacity()
{
- cache.Policy.Eviction.Value.Capacity.Should().Be(20);
+ cache.Policy.Eviction.Value.Capacity.ShouldBe(20);
}
[Fact]
public void ExpireAfterWriteIsDisabled()
{
- cache.Policy.ExpireAfterWrite.HasValue.Should().BeFalse();
+ cache.Policy.ExpireAfterWrite.HasValue.ShouldBeFalse();
}
[Fact]
public void EventsAreDisabled()
{
- cache.Events.HasValue.Should().BeFalse();
+ cache.Events.HasValue.ShouldBeFalse();
}
[Fact]
public void MetricsAreEnabled()
{
- cache.Metrics.HasValue.Should().BeTrue();
+ cache.Metrics.HasValue.ShouldBeTrue();
}
[Fact]
@@ -533,9 +531,9 @@ public void WhenItemIsAddedThenRetrievedMetricHitRatioIsHalf()
cache.DoMaintenance();
- cache.Metrics.Value.HitRatio.Should().Be(0.5);
- cache.Metrics.Value.Hits.Should().Be(1);
- cache.Metrics.Value.Misses.Should().Be(1);
+ cache.Metrics.Value.HitRatio.ShouldBe(0.5);
+ cache.Metrics.Value.Hits.ShouldBe(1);
+ cache.Metrics.Value.Misses.ShouldBe(1);
}
[Fact]
@@ -553,41 +551,41 @@ public void WhenItemIsEvictedMetricRecordsCount()
cache.DoMaintenance();
- cache.Metrics.Value.Evicted.Should().Be(5);
+ cache.Metrics.Value.Evicted.ShouldBe(5);
}
[Fact]
public void WhenItemsAddedKeysContainsTheKeys()
{
- cache.Count.Should().Be(0);
+ cache.Count.ShouldBe(0);
cache.GetOrAdd(1, k => k);
cache.GetOrAdd(2, k => k);
- cache.Keys.Should().BeEquivalentTo(new[] { 1, 2 });
+ cache.Keys.ShouldBe(new[] { 1, 2 });
}
[Fact]
public void WhenItemsAddedGenericEnumerateContainsKvps()
{
- cache.Count.Should().Be(0);
+ cache.Count.ShouldBe(0);
cache.GetOrAdd(1, k => k + 1);
cache.GetOrAdd(2, k => k + 1);
var enumerator = cache.GetEnumerator();
- enumerator.MoveNext().Should().BeTrue();
- enumerator.Current.Should().Be(new KeyValuePair(1, 2));
- enumerator.MoveNext().Should().BeTrue();
- enumerator.Current.Should().Be(new KeyValuePair(2, 3));
+ enumerator.MoveNext().ShouldBeTrue();
+ enumerator.Current.ShouldBe(new KeyValuePair(1, 2));
+ enumerator.MoveNext().ShouldBeTrue();
+ enumerator.Current.ShouldBe(new KeyValuePair(2, 3));
}
[Fact]
public void WhenItemsAddedEnumerateContainsKvps()
{
- cache.Count.Should().Be(0);
+ cache.Count.ShouldBe(0);
cache.GetOrAdd(1, k => k + 1);
cache.GetOrAdd(2, k => k + 1);
var enumerable = (IEnumerable)cache;
- enumerable.Should().BeEquivalentTo(new[] { new KeyValuePair(1, 2), new KeyValuePair(2, 3) });
+ enumerable.ShouldBe(new[] { new KeyValuePair(1, 2), new KeyValuePair(2, 3) });
}
[Fact]
@@ -596,8 +594,8 @@ public void WhenItemIsUpdatedItIsUpdated()
cache.GetOrAdd(1, k => k);
cache.AddOrUpdate(1, 2);
- cache.TryGet(1, out var value).Should().BeTrue();
- value.Should().Be(2);
+ cache.TryGet(1, out var value).ShouldBeTrue();
+ value.ShouldBe(2);
}
[Fact]
@@ -609,8 +607,8 @@ public void WhenKeyExistsAddOrUpdateGuidUpdatesExistingItem()
lfu2.AddOrUpdate(1, new Guid(1, 0, 0, b));
lfu2.AddOrUpdate(1, new Guid(2, 0, 0, b));
- lfu2.TryGet(1, out var value).Should().BeTrue();
- value.Should().Be(new Guid(2, 0, 0, b));
+ lfu2.TryGet(1, out var value).ShouldBeTrue();
+ value.ShouldBe(new Guid(2, 0, 0, b));
}
[Fact]
@@ -618,8 +616,8 @@ public void WhenItemDoesNotExistUpdatedAddsItem()
{
cache.AddOrUpdate(1, 2);
- cache.TryGet(1, out var value).Should().BeTrue();
- value.Should().Be(2);
+ cache.TryGet(1, out var value).ShouldBeTrue();
+ value.ShouldBe(2);
}
[Fact]
@@ -627,8 +625,8 @@ public void WhenKeyExistsTryRemoveRemovesItem()
{
cache.GetOrAdd(1, k => k);
- cache.TryRemove(1).Should().BeTrue();
- cache.TryGet(1, out _).Should().BeFalse();
+ cache.TryRemove(1).ShouldBeTrue();
+ cache.TryGet(1, out _).ShouldBeFalse();
}
[Fact]
@@ -636,8 +634,8 @@ public void WhenKeyExistsTryRemoveReturnsValue()
{
cache.GetOrAdd(1, valueFactory.Create);
- cache.TryRemove(1, out var value).Should().BeTrue();
- value.Should().Be(1);
+ cache.TryRemove(1, out var value).ShouldBeTrue();
+ value.ShouldBe(1);
}
[Fact]
@@ -645,8 +643,8 @@ public void WhenItemExistsTryRemoveRemovesItem()
{
cache.GetOrAdd(1, k => k);
- cache.TryRemove(new KeyValuePair(1, 1)).Should().BeTrue();
- cache.TryGet(1, out _).Should().BeFalse();
+ cache.TryRemove(new KeyValuePair(1, 1)).ShouldBeTrue();
+ cache.TryGet(1, out _).ShouldBeFalse();
}
[Fact]
@@ -654,8 +652,8 @@ public void WhenItemDoesntMatchTryRemoveDoesNotRemove()
{
cache.GetOrAdd(1, k => k);
- cache.TryRemove(new KeyValuePair(1, 2)).Should().BeFalse();
- cache.TryGet(1, out var value).Should().BeTrue();
+ cache.TryRemove(new KeyValuePair(1, 2)).ShouldBeFalse();
+ cache.TryGet(1, out var value).ShouldBeTrue();
}
[Fact]
@@ -666,10 +664,10 @@ public void WhenItemIsRemovedItIsDisposed()
dcache.GetOrAdd(1, k => disposable);
- dcache.TryRemove(1).Should().BeTrue();
+ dcache.TryRemove(1).ShouldBeTrue();
dcache.DoMaintenance();
- disposable.IsDisposed.Should().BeTrue();
+ disposable.IsDisposed.ShouldBeTrue();
}
[Fact]
@@ -677,16 +675,16 @@ public void WhenItemIsRemovedEvictionCountIsIncremented()
{
cache.GetOrAdd(1, k => k);
- cache.TryRemove(1).Should().BeTrue();
+ cache.TryRemove(1).ShouldBeTrue();
cache.DoMaintenance();
- cache.Metrics.Value.Evicted.Should().Be(1);
+ cache.Metrics.Value.Evicted.ShouldBe(1);
}
[Fact]
public void WhenItemDoesNotExistTryRemoveIsFalse()
{
- cache.TryRemove(1).Should().BeFalse();
+ cache.TryRemove(1).ShouldBeFalse();
}
// OnWrite handles the case where a node is removed while the write buffer contains the node
@@ -702,17 +700,17 @@ public void WhenRemovedInWriteBuffer()
cache.TryUpdate(1, 2);
// immediately remove
- cache.TryRemove(1).Should().BeTrue();
+ cache.TryRemove(1).ShouldBeTrue();
cache.DoMaintenance();
- cache.TryGet(1, out var _).Should().BeFalse();
+ cache.TryGet(1, out var _).ShouldBeFalse();
}
[Fact]
public void WhenItemDoesNotExistTryUpdateIsFalse()
{
- cache.TryUpdate(1, 2).Should().BeFalse();
+ cache.TryUpdate(1, 2).ShouldBeFalse();
}
[Fact]
@@ -720,9 +718,9 @@ public void WhenAddingNullValueCanBeAddedAndRemoved()
{
// use foreground so that any null ref exceptions will surface
var lfu = new ConcurrentLfu(1, 20, new ForegroundScheduler(), EqualityComparer.Default);
- lfu.GetOrAdd(1, _ => null).Should().BeNull();
+ lfu.GetOrAdd(1, _ => null).ShouldBeNull();
lfu.AddOrUpdate(1, null);
- lfu.TryRemove(1).Should().BeTrue();
+ lfu.TryRemove(1).ShouldBeTrue();
}
[Fact]
@@ -733,8 +731,8 @@ public void WhenClearedCacheIsEmpty()
cache.Clear();
- cache.Count.Should().Be(0);
- cache.TryGet(1, out var _).Should().BeFalse();
+ cache.Count.ShouldBe(0);
+ cache.TryGet(1, out var _).ShouldBeFalse();
}
[Fact]
@@ -755,7 +753,7 @@ public void WhenBackgroundMaintenanceRepeatedReadThenClearResultsInEmpty()
}
// there should be no iteration of the loop where count != 0
- overflow.Should().Be(0);
+ overflow.ShouldBe(0);
}
[Fact]
@@ -767,12 +765,12 @@ public void TrimRemovesNItems()
}
cache.DoMaintenance();
- cache.Count.Should().Be(20);
+ cache.Count.ShouldBe(20);
cache.Trim(5);
cache.DoMaintenance();
- cache.Count.Should().Be(15);
+ cache.Count.ShouldBe(15);
}
[Fact]
@@ -792,8 +790,8 @@ public void TrimWhileItemsInWriteBufferRemovesNItems()
cache.DoMaintenance();
// The trim takes effect before all the writes are replayed by the maintenance thread.
- cache.Metrics.Value.Evicted.Should().Be(10);
- cache.Count.Should().Be(15);
+ cache.Metrics.Value.Evicted.ShouldBe(10);
+ cache.Count.ShouldBe(15);
this.output.WriteLine($"Count {cache.Count}");
this.output.WriteLine($"Keys {string.Join(",", cache.Keys.Select(k => k.ToString()))}");
diff --git a/BitFaster.Caching.UnitTests/Lfu/ConcurrentTLfuSoakTests.cs b/BitFaster.Caching.UnitTests/Lfu/ConcurrentTLfuSoakTests.cs
index 1fa61d3b..f8194523 100644
--- a/BitFaster.Caching.UnitTests/Lfu/ConcurrentTLfuSoakTests.cs
+++ b/BitFaster.Caching.UnitTests/Lfu/ConcurrentTLfuSoakTests.cs
@@ -1,7 +1,4 @@
using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
using System.Threading.Tasks;
using BitFaster.Caching.Lfu;
using Xunit;
diff --git a/BitFaster.Caching.UnitTests/Lfu/ConcurrentTLfuTests.cs b/BitFaster.Caching.UnitTests/Lfu/ConcurrentTLfuTests.cs
index 59b0ad3f..4f1ddace 100644
--- a/BitFaster.Caching.UnitTests/Lfu/ConcurrentTLfuTests.cs
+++ b/BitFaster.Caching.UnitTests/Lfu/ConcurrentTLfuTests.cs
@@ -1,10 +1,9 @@
using System;
using System.Runtime.InteropServices;
-using System.Threading;
using BitFaster.Caching.Lfu;
using BitFaster.Caching.Scheduler;
using BitFaster.Caching.UnitTests.Retry;
-using FluentAssertions;
+using Shouldly;
using Xunit;
namespace BitFaster.Caching.UnitTests.Lfu
@@ -50,8 +49,8 @@ public void WhenItemIsAccessedTimeToExpireIsUpdated()
TimeSpan.FromSeconds(2),
cache =>
{
- cache.TryGet(1, out var value).Should().BeTrue();
- cache.TryGet(1, out value).Should().BeTrue();
+ cache.TryGet(1, out var value).ShouldBeTrue();
+ cache.TryGet(1, out value).ShouldBeTrue();
}
);
}
@@ -63,35 +62,35 @@ public void ConstructAddAndRetrieveWithCustomComparerReturnsValue()
lfu.GetOrAdd("foo", k => 1);
- lfu.TryGet("FOO", out var value).Should().BeTrue();
- value.Should().Be(1);
+ lfu.TryGet("FOO", out var value).ShouldBeTrue();
+ value.ShouldBe(1);
}
[Fact]
public void MetricsHasValueIsTrue()
{
var x = new ConcurrentTLfu(3, new TestExpiryCalculator());
- x.Metrics.HasValue.Should().BeTrue();
+ x.Metrics.HasValue.ShouldBeTrue();
}
[Fact]
public void EventsHasValueIsFalse()
{
var x = new ConcurrentTLfu(3, new TestExpiryCalculator());
- x.Events.HasValue.Should().BeFalse();
+ x.Events.HasValue.ShouldBeFalse();
}
[Fact]
public void DefaultSchedulerIsThreadPool()
{
- lfu.Scheduler.Should().BeOfType();
+ lfu.Scheduler.ShouldBeOfType();
}
[Fact]
public void WhenCalculatorIsAfterWritePolicyIsAfterWrite()
{
- lfu.Policy.ExpireAfterWrite.HasValue.Should().BeTrue();
- lfu.Policy.ExpireAfterWrite.Value.TimeToLive.Should().Be(timeToLive);
+ lfu.Policy.ExpireAfterWrite.HasValue.ShouldBeTrue();
+ lfu.Policy.ExpireAfterWrite.Value.TimeToLive.ShouldBe(timeToLive);
}
[Fact]
@@ -99,8 +98,8 @@ public void WhenCalculatorIsAfterAccessPolicyIsAfterAccess()
{
lfu = new ConcurrentTLfu(capacity, new ExpireAfterAccess(timeToLive));
- lfu.Policy.ExpireAfterAccess.HasValue.Should().BeTrue();
- lfu.Policy.ExpireAfterAccess.Value.TimeToLive.Should().Be(timeToLive);
+ lfu.Policy.ExpireAfterAccess.HasValue.ShouldBeTrue();
+ lfu.Policy.ExpireAfterAccess.Value.TimeToLive.ShouldBe(timeToLive);
}
[Fact]
@@ -108,8 +107,8 @@ public void WhenCalculatorIsCustomPolicyIsAfter()
{
lfu = new ConcurrentTLfu(capacity, new TestExpiryCalculator());
- lfu.Policy.ExpireAfter.HasValue.Should().BeTrue();
- (lfu as ITimePolicy).TimeToLive.Should().Be(TimeSpan.Zero);
+ lfu.Policy.ExpireAfter.HasValue.ShouldBeTrue();
+ (lfu as ITimePolicy).TimeToLive.ShouldBe(TimeSpan.Zero);
}
[Fact]
@@ -121,8 +120,8 @@ public void WhenKeyExistsTryGetTimeToExpireReturnsExpiry()
lfu.GetOrAdd(1, k => "1");
- lfu.Policy.ExpireAfter.Value.TryGetTimeToExpire(1, out var timeToExpire).Should().BeTrue();
- timeToExpire.Should().BeCloseTo(TimeSpan.FromMinutes(1), TimeSpan.FromMilliseconds(50));
+ lfu.Policy.ExpireAfter.Value.TryGetTimeToExpire(1, out var timeToExpire).ShouldBeTrue();
+ timeToExpire.ShouldBe(TimeSpan.FromMinutes(1), TimeSpan.FromMilliseconds(50));
}
[Fact]
@@ -130,7 +129,7 @@ public void WhenKeyDoesNotExistTryGetTimeToExpireReturnsFalse()
{
lfu = new ConcurrentTLfu(capacity, new TestExpiryCalculator());
- lfu.Policy.ExpireAfter.Value.TryGetTimeToExpire(1, out _).Should().BeFalse();
+ lfu.Policy.ExpireAfter.Value.TryGetTimeToExpire(1, out _).ShouldBeFalse();
}
[Fact]
@@ -138,7 +137,7 @@ public void WhenKeyTypeMismatchTryGetTimeToExpireReturnsFalse()
{
lfu = new ConcurrentTLfu(capacity, new TestExpiryCalculator());
- lfu.Policy.ExpireAfter.Value.TryGetTimeToExpire("string", out _).Should().BeFalse();
+ lfu.Policy.ExpireAfter.Value.TryGetTimeToExpire("string", out _).ShouldBeFalse();
}
// policy can expire after write
@@ -148,7 +147,7 @@ public void WhenItemIsNotExpiredItIsNotRemoved()
{
lfu.GetOrAdd(1, valueFactory.Create);
- lfu.TryGet(1, out var value).Should().BeTrue();
+ lfu.TryGet(1, out var value).ShouldBeTrue();
}
[RetryFact]
@@ -164,7 +163,7 @@ public void WhenItemIsExpiredItIsRemoved()
timeToLive.MultiplyBy(ttlWaitMlutiplier),
lfu =>
{
- lfu.TryGet(1, out var value).Should().BeFalse();
+ lfu.TryGet(1, out var value).ShouldBeFalse();
}
);
}
@@ -185,7 +184,7 @@ public void WhenItemIsExpiredItIsRemoved2()
// This is a bit flaky below 2 secs pause - seems like it doesnt always
// remove the item
lfu.Policy.ExpireAfterWrite.Value.TrimExpired();
- lfu.Count.Should().Be(0);
+ lfu.Count.ShouldBe(0);
}
);
}
@@ -208,7 +207,7 @@ public void WhenItemIsUpdatedTtlIsExtended()
// If we defer computing time to the maintenance loop, we
// need to call maintenance here for the timestamp to be updated
lfu.DoMaintenance();
- lfu.TryGet(1, out var value).Should().BeTrue();
+ lfu.TryGet(1, out var value).ShouldBeTrue();
}
);
}
diff --git a/BitFaster.Caching.UnitTests/Lfu/LfuCapacityPartitionTests.cs b/BitFaster.Caching.UnitTests/Lfu/LfuCapacityPartitionTests.cs
index 08e1ba62..6a3f8e19 100644
--- a/BitFaster.Caching.UnitTests/Lfu/LfuCapacityPartitionTests.cs
+++ b/BitFaster.Caching.UnitTests/Lfu/LfuCapacityPartitionTests.cs
@@ -1,10 +1,8 @@
using System;
using System.Collections.Generic;
using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
using BitFaster.Caching.Lfu;
-using FluentAssertions;
+using Shouldly;
using Xunit;
using Xunit.Abstractions;
@@ -24,14 +22,14 @@ public void WhenCapacityIsLessThan3CtorThrows()
{
Action constructor = () => { var partition = new LfuCapacityPartition(2); };
- constructor.Should().Throw();
+ constructor.ShouldThrow();
}
[Fact]
public void CapacityReturnsCapacity()
{
var partition = new LfuCapacityPartition(123);
- partition.Capacity.Should().Be(123);
+ partition.Capacity.ShouldBe(123);
}
[Theory]
@@ -41,9 +39,9 @@ public void CtorSetsExpectedCapacity(int capacity, int expectedWindow, int expec
{
var partition = new LfuCapacityPartition(capacity);
- partition.Window.Should().Be(expectedWindow);
- partition.Protected.Should().Be(expectedProtected);
- partition.Probation.Should().Be(expectedProbation);
+ partition.Window.ShouldBe(expectedWindow);
+ partition.Protected.ShouldBe(expectedProtected);
+ partition.Probation.ShouldBe(expectedProbation);
}
[Fact]
@@ -60,8 +58,8 @@ public void WhenHitRateKeepsDecreasingWindowIsCappedAt80Percent()
SetHitRate(partition, metrics, max, 0.1);
}
- partition.Window.Should().Be(80);
- partition.Protected.Should().Be(16);
+ partition.Window.ShouldBe(80);
+ partition.Protected.ShouldBe(16);
}
[Fact]
@@ -102,7 +100,7 @@ public void WhenHitRateIsStableWindowConverges()
var minWindow = last50.Min();
var maxWindow = last50.Max();
- (maxWindow - minWindow).Should().BeLessThanOrEqualTo(1);
+ (maxWindow - minWindow).ShouldBeLessThanOrEqualTo(1);
}
[Fact]
@@ -166,13 +164,13 @@ public void Capture(LfuCapacityPartition p)
public void AssertWindowIncreased(LfuCapacityPartition p)
{
- p.Window.Should().BeGreaterThan(prev);
+ p.Window.ShouldBeGreaterThan(prev);
prev = p.Window;
}
public void AssertWindowDecreased(LfuCapacityPartition p)
{
- p.Window.Should().BeLessThan(prev);
+ p.Window.ShouldBeLessThan(prev);
prev = p.Window;
}
}
diff --git a/BitFaster.Caching.UnitTests/Lfu/LfuInfoTests.cs b/BitFaster.Caching.UnitTests/Lfu/LfuInfoTests.cs
index e25a48b9..3b36cd1e 100644
--- a/BitFaster.Caching.UnitTests/Lfu/LfuInfoTests.cs
+++ b/BitFaster.Caching.UnitTests/Lfu/LfuInfoTests.cs
@@ -1,6 +1,6 @@
using System;
using BitFaster.Caching.Lfu.Builder;
-using FluentAssertions;
+using Shouldly;
using Xunit;
namespace BitFaster.Caching.UnitTests.Lfu
@@ -12,7 +12,7 @@ public void WhenExpiryNullGetExpiryReturnsNull()
{
var info = new LfuInfo();
- info.GetExpiry().Should().BeNull();
+ info.GetExpiry().ShouldBeNull();
}
[Fact]
@@ -23,7 +23,7 @@ public void WhenExpiryCalcValueTypeDoesNotMatchThrows()
info.SetExpiry(new TestExpiryCalculator());
Action act = () => info.GetExpiry();
- act.Should().Throw();
+ act.ShouldThrow();
}
}
}
diff --git a/BitFaster.Caching.UnitTests/Lfu/LfuNodeListTests.cs b/BitFaster.Caching.UnitTests/Lfu/LfuNodeListTests.cs
index e045a9ad..79a8af2b 100644
--- a/BitFaster.Caching.UnitTests/Lfu/LfuNodeListTests.cs
+++ b/BitFaster.Caching.UnitTests/Lfu/LfuNodeListTests.cs
@@ -1,6 +1,6 @@
using System;
using BitFaster.Caching.Lfu;
-using FluentAssertions;
+using Shouldly;
using Xunit;
namespace BitFaster.Caching.UnitTests.Lfu
@@ -13,7 +13,7 @@ public void WhenEmptyRemoveFirstThrows()
{
var list = new LfuNodeList();
Action remove = () => { list.RemoveFirst(); };
- remove.Should().Throw();
+ remove.ShouldThrow();
}
#endif
@@ -22,7 +22,7 @@ public void WhenPreviousNullLastReturnsNull()
{
var list = new LfuNodeList();
- list.Last.Should().BeNull();
+ list.Last.ShouldBeNull();
}
[Fact]
@@ -35,7 +35,7 @@ public void WhenPreviousExistsLastReturnsPrevious()
list.AddLast(node1);
list.AddLast(node2);
- list.Last.Should().BeSameAs(node2);
+ list.Last.ShouldBeSameAs(node2);
}
[Fact]
@@ -48,7 +48,7 @@ public void WhenPreviousExistsNodePreviousReturnsPrevious()
list.AddLast(node1);
list.AddLast(node2);
- node2.Previous.Should().BeSameAs(node1);
+ node2.Previous.ShouldBeSameAs(node1);
}
[Fact]
@@ -61,7 +61,7 @@ public void WhenHeadNodePreviousReturnsNull()
list.AddLast(node1);
list.AddLast(node2);
- node1.Previous.Should().BeNull();
+ node1.Previous.ShouldBeNull();
}
}
}
diff --git a/BitFaster.Caching.UnitTests/Lfu/TestScheduler.cs b/BitFaster.Caching.UnitTests/Lfu/TestScheduler.cs
index 9beefabd..037586b7 100644
--- a/BitFaster.Caching.UnitTests/Lfu/TestScheduler.cs
+++ b/BitFaster.Caching.UnitTests/Lfu/TestScheduler.cs
@@ -1,9 +1,5 @@
using System;
using System.Collections.Concurrent;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
using BitFaster.Caching.Scheduler;
namespace BitFaster.Caching.UnitTests.Lfu
diff --git a/BitFaster.Caching.UnitTests/Lfu/TimerWheelTests.cs b/BitFaster.Caching.UnitTests/Lfu/TimerWheelTests.cs
index 25bac835..0cf467c0 100644
--- a/BitFaster.Caching.UnitTests/Lfu/TimerWheelTests.cs
+++ b/BitFaster.Caching.UnitTests/Lfu/TimerWheelTests.cs
@@ -2,12 +2,10 @@
using System.Collections;
using System.Collections.Generic;
using System.Linq;
-using System.Xml.Linq;
using BitFaster.Caching.Lfu;
using BitFaster.Caching.Lru;
using BitFaster.Caching.Scheduler;
-using FluentAssertions;
-using FluentAssertions.Common;
+using Shouldly;
using Xunit;
using Xunit.Abstractions;
@@ -51,11 +49,11 @@ public void WhenAdvanceExpiredNodesExpire(long clock, Duration duration, int exp
timerWheel.Advance(ref cache, new Duration(clock) + duration);
var expired = items.Where(n => ((DisposeTracker)n.Value).Expired);
- expired.Count().Should().Be(expiredCount);
+ expired.Count().ShouldBe(expiredCount);
foreach (var node in expired)
{
- node.GetTimestamp().Should().BeLessThanOrEqualTo(clock + duration.raw);
+ node.GetTimestamp().ShouldBeLessThanOrEqualTo(clock + duration.raw);
}
}
@@ -70,7 +68,7 @@ public void WhenAdvancedPastItemExpiryItemIsEvicted(long clock2)
timerWheel.Advance(ref cache, new Duration(clock2 + 13 * TimerWheel.Spans[0]));
- item.Expired.Should().BeTrue();
+ item.Expired.ShouldBeTrue();
}
[Theory]
@@ -86,28 +84,28 @@ public void WhenAdvanceDifferentWheelsNodeIsRescheduled(long clock)
timerWheel.Schedule(AddNode(15, new DisposeTracker(), t15)); // wheel 0
timerWheel.Schedule(AddNode(120, new DisposeTracker(), t120)); // wheel 1
- wheelEnumerator.Count().Should().Be(2);
+ wheelEnumerator.Count().ShouldBe(2);
var initialPosition = wheelEnumerator.PositionOf(120);
Duration t45 = clockD + Duration.FromSeconds(45); // discard T15, T120 in wheel[1]
timerWheel.Advance(ref cache, t45);
- lfuNodeList.Count.Should().Be(1); // verify discarded T15
- wheelEnumerator.PositionOf(15).Should().Be(WheelPosition.None);
+ lfuNodeList.Count.ShouldBe(1); // verify discarded T15
+ wheelEnumerator.PositionOf(15).ShouldBe(WheelPosition.None);
Duration t110 = clockD + Duration.FromSeconds(110);
timerWheel.Advance(ref cache, t110);
- lfuNodeList.Count.Should().Be(1); // verify not discarded, T120 in wheel[0]
+ lfuNodeList.Count.ShouldBe(1); // verify not discarded, T120 in wheel[0]
var rescheduledPosition = wheelEnumerator.PositionOf(120);
- rescheduledPosition.Should().BeLessThan(initialPosition);
+ rescheduledPosition.ShouldBeLessThan(initialPosition);
Duration t130 = clockD + Duration.FromSeconds(130);
timerWheel.Advance(ref cache, t130);
- lfuNodeList.Count.Should().Be(0); // verify discarded T120
- wheelEnumerator.PositionOf(120).Should().Be(WheelPosition.None);
+ lfuNodeList.Count.ShouldBe(0); // verify discarded T120
+ wheelEnumerator.PositionOf(120).ShouldBe(WheelPosition.None);
}
[Fact]
@@ -119,7 +117,7 @@ public void WhenAdvanceOverflowsAndItemIsExpiredItemIsEvicted()
timerWheel.Advance(ref cache, new Duration(timerWheel.time + (TimerWheel.Spans[3] * 365)));
- this.lfuNodeList.Count.Should().Be(0);
+ this.lfuNodeList.Count.ShouldBe(0);
}
#if NET6_0_OR_GREATER
@@ -142,7 +140,7 @@ public void WhenAdvanceBackwardsNothingIsEvicted(long clock)
timerWheel.Advance(ref cache, new Duration(clock - 3 * TimerWheel.Spans[i]));
}
- this.lfuNodeList.Count.Should().Be(1_000);
+ this.lfuNodeList.Count.ShouldBe(1_000);
}
#endif
@@ -156,9 +154,9 @@ public void WhenAdvanceThrowsCurrentTimeIsNotAdvanced()
// This should expire the node, call evict, then throw via DisposeThrows.Dispose()
Action advance = () => timerWheel.Advance(ref cache, new Duration(clock.raw + (2 * TimerWheel.Spans[1])));
- advance.Should().Throw();
+ advance.ShouldThrow();
- timerWheel.time.Should().Be(clock.raw);
+ timerWheel.time.ShouldBe(clock.raw);
}
[Theory]
@@ -166,7 +164,7 @@ public void WhenAdvanceThrowsCurrentTimeIsNotAdvanced()
public void WhenEmptyGetExpirationDelayIsMax(long clock)
{
timerWheel.time = clock;
- timerWheel.GetExpirationDelay().raw.Should().Be(long.MaxValue);
+ timerWheel.GetExpirationDelay().raw.ShouldBe(long.MaxValue);
}
[Theory]
@@ -181,7 +179,7 @@ public void WhenScheduledMaxNodeIsInOuterWheel(long clock)
timerWheel.Schedule(AddNode(1, new DisposeTracker(), tMax));
var initialPosition = wheelEnumerator.PositionOf(1);
- initialPosition.wheel.Should().Be(4);
+ initialPosition.wheel.ShouldBe(4);
}
[Theory]
@@ -194,7 +192,7 @@ public void WhenScheduledInFirstWheelDelayIsUpdated(long clock)
timerWheel.Schedule(new TimeOrderNode(1, new DisposeTracker()) { TimeToExpire = new Duration(clock) + delay });
- timerWheel.GetExpirationDelay().raw.Should().BeLessThanOrEqualTo(TimerWheel.Spans[0]);
+ timerWheel.GetExpirationDelay().raw.ShouldBeLessThanOrEqualTo(TimerWheel.Spans[0]);
}
[Theory]
@@ -207,7 +205,7 @@ public void WhenScheduledInLastWheelDelayIsUpdated(long clock)
timerWheel.Schedule(new TimeOrderNode(1, new DisposeTracker()) { TimeToExpire = new Duration(clock) + delay });
- timerWheel.GetExpirationDelay().raw.Should().BeLessThanOrEqualTo(delay.raw);
+ timerWheel.GetExpirationDelay().raw.ShouldBeLessThanOrEqualTo(delay.raw);
}
[Theory]
@@ -226,14 +224,14 @@ public void WhenScheduledInDifferentWheelsDelayIsCorrect(long clock)
Duration t45 = clockD + Duration.FromSeconds(45); // discard T15, T80 in wheel[1]
timerWheel.Advance(ref cache, t45);
- lfuNodeList.Count.Should().Be(1); // verify discarded
+ lfuNodeList.Count.ShouldBe(1); // verify discarded
Duration t95 = clockD + Duration.FromSeconds(95);
timerWheel.Schedule(AddNode(3, new DisposeTracker(), t95)); // wheel 0
Duration expectedDelay = (t80 - t45);
var delay = timerWheel.GetExpirationDelay();
- delay.raw.Should().BeLessThan(expectedDelay.raw + TimerWheel.Spans[0]);
+ delay.raw.ShouldBeLessThan(expectedDelay.raw + TimerWheel.Spans[0]);
}
[Fact]
@@ -242,12 +240,12 @@ public void WhenScheduledThenDescheduledNodeIsRemoved()
var node = AddNode(1, new DisposeTracker(), Duration.SinceEpoch());
timerWheel.Schedule(node);
- wheelEnumerator.PositionOf(1).Should().NotBe(WheelPosition.None);
+ wheelEnumerator.PositionOf(1).ShouldNotBe(WheelPosition.None);
TimerWheel.Deschedule(node);
- wheelEnumerator.PositionOf(1).Should().Be(WheelPosition.None);
- node.GetNextInTimeOrder().Should().BeNull();
- node.GetPreviousInTimeOrder().Should().BeNull();
+ wheelEnumerator.PositionOf(1).ShouldBe(WheelPosition.None);
+ node.GetNextInTimeOrder().ShouldBeNull();
+ node.GetPreviousInTimeOrder().ShouldBeNull();
}
[Fact]
@@ -261,7 +259,7 @@ public void WhenRescheduledLaterNodeIsMoved()
node.TimeToExpire = time + Duration.FromMinutes(60 * 30);
timerWheel.Reschedule(node);
- wheelEnumerator.PositionOf(1).Should().BeGreaterThan(initial);
+ wheelEnumerator.PositionOf(1).ShouldBeGreaterThan(initial);
}
[Fact]
@@ -271,7 +269,7 @@ public void WhenDetachedRescheduleIsNoOp()
var node = AddNode(1, new DisposeTracker(), time);
timerWheel.Reschedule(node);
- wheelEnumerator.PositionOf(1).Should().Be(WheelPosition.None);
+ wheelEnumerator.PositionOf(1).ShouldBe(WheelPosition.None);
}
private TimeOrderNode AddNode(int key, IDisposable value, Duration timeToExpire)
diff --git a/BitFaster.Caching.UnitTests/Lru/AfterAccessPolicyTests.cs b/BitFaster.Caching.UnitTests/Lru/AfterAccessPolicyTests.cs
index e311f6d7..26d9afff 100644
--- a/BitFaster.Caching.UnitTests/Lru/AfterAccessPolicyTests.cs
+++ b/BitFaster.Caching.UnitTests/Lru/AfterAccessPolicyTests.cs
@@ -1,4 +1,4 @@
-using FluentAssertions;
+using Shouldly;
using BitFaster.Caching.Lru;
using System;
using System.Threading.Tasks;
@@ -15,7 +15,7 @@ public void WhenTtlIsTimeSpanMaxThrow()
{
Action constructor = () => { new AfterAccessPolicy(TimeSpan.MaxValue); };
- constructor.Should().Throw();
+ constructor.ShouldThrow();
}
[Fact]
@@ -23,20 +23,20 @@ public void WhenTtlIsZeroThrow()
{
Action constructor = () => { new AfterAccessPolicy(TimeSpan.Zero); };
- constructor.Should().Throw();
+ constructor.ShouldThrow();
}
[Fact]
public void WhenTtlIsMaxSetAsMax()
{
var policy = new AfterAccessPolicy(Duration.MaxRepresentable);
- policy.TimeToLive.Should().BeCloseTo(Duration.MaxRepresentable, TimeSpan.FromMilliseconds(20));
+ policy.TimeToLive.ShouldBe(Duration.MaxRepresentable, TimeSpan.FromMilliseconds(20));
}
[Fact]
public void TimeToLiveShouldBeTenSecs()
{
- this.policy.TimeToLive.Should().Be(TimeSpan.FromSeconds(10));
+ this.policy.TimeToLive.ShouldBe(TimeSpan.FromSeconds(10));
}
[Fact]
@@ -44,8 +44,8 @@ public void CreateItemInitializesKeyAndValue()
{
var item = this.policy.CreateItem(1, 2);
- item.Key.Should().Be(1);
- item.Value.Should().Be(2);
+ item.Key.ShouldBe(1);
+ item.Value.ShouldBe(2);
}
[Fact]
@@ -53,7 +53,7 @@ public void CreateItemInitializesTimestampToNow()
{
var item = this.policy.CreateItem(1, 2);
- item.TickCount.Should().BeCloseTo(Duration.SinceEpoch().raw, DurationTests.epsilon);
+ item.TickCount.ShouldBe(Duration.SinceEpoch().raw);
}
[Fact]
@@ -64,7 +64,7 @@ public void TouchUpdatesItemWasAccessed()
this.policy.Touch(item);
- item.WasAccessed.Should().BeTrue();
+ item.WasAccessed.ShouldBeTrue();
}
[Fact]
@@ -77,7 +77,7 @@ public async Task TouchUpdatesTicksCount()
this.policy.ShouldDiscard(item); // set the time in the policy
this.policy.Touch(item);
- item.TickCount.Should().BeGreaterThan(tc);
+ item.TickCount.ShouldBeGreaterThan(tc);
}
[Fact]
@@ -90,7 +90,7 @@ public async Task UpdateUpdatesTickCount()
this.policy.Update(item);
- item.TickCount.Should().BeGreaterThan(tc);
+ item.TickCount.ShouldBeGreaterThan(tc);
}
[Fact]
@@ -100,7 +100,7 @@ public void WhenItemIsExpiredShouldDiscardIsTrue()
item.TickCount = Duration.SinceEpoch().raw - Duration.FromSeconds(11).raw;
- this.policy.ShouldDiscard(item).Should().BeTrue();
+ this.policy.ShouldDiscard(item).ShouldBeTrue();
}
[Fact]
@@ -110,13 +110,13 @@ public void WhenItemIsNotExpiredShouldDiscardIsFalse()
item.TickCount = Duration.SinceEpoch().raw - Duration.FromSeconds(9).raw;
- this.policy.ShouldDiscard(item).Should().BeFalse();
+ this.policy.ShouldDiscard(item).ShouldBeFalse();
}
[Fact]
public void CanDiscardIsTrue()
{
- this.policy.CanDiscard().Should().BeTrue();
+ this.policy.CanDiscard().ShouldBeTrue();
}
[Theory]
@@ -128,7 +128,7 @@ public void RouteHot(bool wasAccessed, bool isExpired, ItemDestination expectedD
{
var item = CreateItem(wasAccessed, isExpired);
- this.policy.RouteHot(item).Should().Be(expectedDestination);
+ this.policy.RouteHot(item).ShouldBe(expectedDestination);
}
[Theory]
@@ -140,7 +140,7 @@ public void RouteWarm(bool wasAccessed, bool isExpired, ItemDestination expected
{
var item = CreateItem(wasAccessed, isExpired);
- this.policy.RouteWarm(item).Should().Be(expectedDestination);
+ this.policy.RouteWarm(item).ShouldBe(expectedDestination);
}
[Theory]
@@ -152,7 +152,7 @@ public void RouteCold(bool wasAccessed, bool isExpired, ItemDestination expected
{
var item = CreateItem(wasAccessed, isExpired);
- this.policy.RouteCold(item).Should().Be(expectedDestination);
+ this.policy.RouteCold(item).ShouldBe(expectedDestination);
}
private LongTickCountLruItem CreateItem(bool wasAccessed, bool isExpired)
diff --git a/BitFaster.Caching.UnitTests/Lru/CacheExtTests.cs b/BitFaster.Caching.UnitTests/Lru/CacheExtTests.cs
index 4c5ede93..f4e7aa4b 100644
--- a/BitFaster.Caching.UnitTests/Lru/CacheExtTests.cs
+++ b/BitFaster.Caching.UnitTests/Lru/CacheExtTests.cs
@@ -2,7 +2,7 @@
using System.Linq;
using BitFaster.Caching.Lfu;
using BitFaster.Caching.Lru;
-using FluentAssertions;
+using Shouldly;
using Xunit;
namespace BitFaster.Caching.UnitTests.Lru
@@ -14,10 +14,10 @@ public void CanUseICache2FromClassicLru()
{
var cache = new ClassicLru(5);
var cache2 = (ICacheExt)cache;
- cache2.GetOrAdd(42, static (k, i) => (k + i).ToString(), 1).Should().Be("43");
- cache2.TryRemove(43, out _).Should().BeFalse();
+ cache2.GetOrAdd(42, static (k, i) => (k + i).ToString(), 1).ShouldBe("43");
+ cache2.TryRemove(43, out _).ShouldBeFalse();
var first = cache2.First();
- cache2.TryRemove(first).Should().BeTrue();
+ cache2.TryRemove(first).ShouldBeTrue();
}
[Fact]
@@ -28,10 +28,10 @@ public void CanUseICache2FromConcurrentLfuBuilder()
.Build();
var cache2 = (ICacheExt)cache;
- cache2.GetOrAdd(42, static (k, i) => (k + i).ToString(), 1).Should().Be("43");
- cache2.TryRemove(43, out _).Should().BeFalse();
+ cache2.GetOrAdd(42, static (k, i) => (k + i).ToString(), 1).ShouldBe("43");
+ cache2.TryRemove(43, out _).ShouldBeFalse();
var first = cache2.First();
- cache2.TryRemove(first).Should().BeTrue();
+ cache2.TryRemove(first).ShouldBeTrue();
}
[Fact]
@@ -43,10 +43,10 @@ public void CanUseICache2FromConcurrentLruBuilder()
.Build();
var cache2 = (ICacheExt)cache;
- cache2.GetOrAdd(42, static (k, i) => (k + i).ToString(), 1).Should().Be("43");
- cache2.TryRemove(43, out _).Should().BeFalse();
+ cache2.GetOrAdd(42, static (k, i) => (k + i).ToString(), 1).ShouldBe("43");
+ cache2.TryRemove(43, out _).ShouldBeFalse();
var first = cache2.First();
- cache2.TryRemove(first).Should().BeTrue();
+ cache2.TryRemove(first).ShouldBeTrue();
}
}
}
diff --git a/BitFaster.Caching.UnitTests/Lru/CapacityPartitionExtensionsTests.cs b/BitFaster.Caching.UnitTests/Lru/CapacityPartitionExtensionsTests.cs
index 9b2e755d..35f0b322 100644
--- a/BitFaster.Caching.UnitTests/Lru/CapacityPartitionExtensionsTests.cs
+++ b/BitFaster.Caching.UnitTests/Lru/CapacityPartitionExtensionsTests.cs
@@ -1,10 +1,6 @@
using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
using BitFaster.Caching.Lru;
-using FluentAssertions;
+using Shouldly;
using Xunit;
namespace BitFaster.Caching.UnitTests.Lru
@@ -18,7 +14,7 @@ public void WhenCapacityIsValidDoesNotThrow()
Action validate = () => { p.Validate(); };
- validate.Should().NotThrow();
+ validate.ShouldNotThrow();
}
[Fact]
@@ -28,7 +24,7 @@ public void WhenColdIsZeroThrows()
Action validate = () => { p.Validate(); };
- validate.Should().Throw();
+ validate.ShouldThrow();
}
[Fact]
@@ -38,7 +34,7 @@ public void WhenWarmIsZeroThrows()
Action validate = () => { p.Validate(); };
- validate.Should().Throw();
+ validate.ShouldThrow();
}
[Fact]
@@ -48,7 +44,7 @@ public void WhenHotIsZeroThrows()
Action validate = () => { p.Validate(); };
- validate.Should().Throw();
+ validate.ShouldThrow();
}
}
}
diff --git a/BitFaster.Caching.UnitTests/Lru/ClassicLruTests.cs b/BitFaster.Caching.UnitTests/Lru/ClassicLruTests.cs
index 4b0b790f..dbae0c2f 100644
--- a/BitFaster.Caching.UnitTests/Lru/ClassicLruTests.cs
+++ b/BitFaster.Caching.UnitTests/Lru/ClassicLruTests.cs
@@ -1,9 +1,8 @@
-using FluentAssertions;
+using Shouldly;
using BitFaster.Caching.Lru;
using System;
using System.Collections.Generic;
using System.Linq;
-using System.Text;
using System.Threading.Tasks;
using Xunit;
using System.Collections;
@@ -22,7 +21,7 @@ public void WhenConcurrencyIsLessThan1CtorThrows()
{
Action constructor = () => { var x = new ClassicLru(0, 3, EqualityComparer.Default); };
- constructor.Should().Throw();
+ constructor.ShouldThrow();
}
[Fact]
@@ -30,7 +29,7 @@ public void WhenCapacityIsLessThan3CtorThrows()
{
Action constructor = () => { var x = new ClassicLru(1, 2, EqualityComparer.Default); };
- constructor.Should().Throw();
+ constructor.ShouldThrow();
}
[Fact]
@@ -38,7 +37,7 @@ public void WhenComparerIsNullCtorThrows()
{
Action constructor = () => { var x = new ClassicLru(1, 3, null); };
- constructor.Should().Throw();
+ constructor.ShouldThrow();
}
[Fact]
@@ -46,50 +45,50 @@ public void ConstructAddAndRetrieveWithDefaultCtorReturnsValue()
{
var x = new ClassicLru(3);
- x.GetOrAdd(1, k => k).Should().Be(1);
+ x.GetOrAdd(1, k => k).ShouldBe(1);
}
[Fact]
public void WhenCtorCapacityArgIs3CapacityIs3()
{
- new ClassicLru(3).Capacity.Should().Be(3);
+ new ClassicLru(3).Capacity.ShouldBe(3);
}
[Fact]
public void WhenItemIsAddedCountIsCorrect()
{
- lru.Count.Should().Be(0);
+ lru.Count.ShouldBe(0);
lru.GetOrAdd(1, valueFactory.Create);
- lru.Count.Should().Be(1);
+ lru.Count.ShouldBe(1);
}
[Fact]
public void WhenItemsAddedKeysContainsTheKeys()
{
- lru.Count.Should().Be(0);
+ lru.Count.ShouldBe(0);
lru.GetOrAdd(1, valueFactory.Create);
lru.GetOrAdd(2, valueFactory.Create);
- lru.Keys.Should().BeEquivalentTo(new[] { 1, 2 });
+ lru.Keys.ShouldBe(new[] { 1, 2 });
}
[Fact]
public void WhenItemsAddedGenericEnumerateContainsKvps()
{
- lru.Count.Should().Be(0);
+ lru.Count.ShouldBe(0);
lru.GetOrAdd(1, valueFactory.Create);
lru.GetOrAdd(2, valueFactory.Create);
- lru.Should().BeEquivalentTo(new[] { new KeyValuePair(1, "1"), new KeyValuePair(2, "2") });
+ lru.ShouldBe(new[] { new KeyValuePair(1, "1"), new KeyValuePair(2, "2") });
}
[Fact]
public void WhenItemsAddedEnumerateContainsKvps()
{
- lru.Count.Should().Be(0);
+ lru.Count.ShouldBe(0);
lru.GetOrAdd(1, valueFactory.Create);
lru.GetOrAdd(2, valueFactory.Create);
var enumerable = (IEnumerable)lru;
- enumerable.Should().BeEquivalentTo(new[] { new KeyValuePair(1, "1"), new KeyValuePair(2, "2") });
+ enumerable.ShouldBe(new[] { new KeyValuePair(1, "1"), new KeyValuePair(2, "2") });
}
[Fact]
@@ -98,8 +97,8 @@ public void WhenItemExistsTryGetReturnsValueAndTrue()
lru.GetOrAdd(1, valueFactory.Create);
bool result = lru.TryGet(1, out var value);
- result.Should().Be(true);
- value.Should().Be("1");
+ result.ShouldBe(true);
+ value.ShouldBe("1");
}
[Fact]
@@ -108,14 +107,14 @@ public void WhenItemDoesNotExistTryGetReturnsNullAndFalse()
lru.GetOrAdd(1, valueFactory.Create);
bool result = lru.TryGet(2, out var value);
- result.Should().Be(false);
- value.Should().BeNull();
+ result.ShouldBe(false);
+ value.ShouldBeNull();
}
[Fact]
public void MetricsAreEnabled()
{
- lru.Metrics.HasValue.Should().BeTrue();
+ lru.Metrics.HasValue.ShouldBeTrue();
}
[Fact]
@@ -124,7 +123,7 @@ public void WhenItemIsAddedThenRetrievedMetricHitRatioIsHalf()
lru.GetOrAdd(1, valueFactory.Create);
bool result = lru.TryGet(1, out var value);
- lru.Metrics.Value.HitRatio.Should().Be(0.5);
+ lru.Metrics.Value.HitRatio.ShouldBe(0.5);
}
[Fact]
@@ -133,7 +132,7 @@ public void WhenItemIsAddedThenRetrievedMetricHitsIs1()
lru.GetOrAdd(1, valueFactory.Create);
bool result = lru.TryGet(1, out var value);
- lru.Metrics.Value.Hits.Should().Be(1);
+ lru.Metrics.Value.Hits.ShouldBe(1);
}
[Fact]
@@ -142,7 +141,7 @@ public void WhenItemIsAddedThenRetrievedMetricTotalIs2()
lru.GetOrAdd(1, valueFactory.Create);
bool result = lru.TryGet(1, out var value);
- lru.Metrics.Value.Total.Should().Be(2);
+ lru.Metrics.Value.Total.ShouldBe(2);
}
[Fact]
@@ -151,13 +150,13 @@ public void WhenItemDoesNotExistTryGetIncrementsMiss()
lru.GetOrAdd(1, valueFactory.Create);
bool result = lru.TryGet(1, out var value);
- lru.Metrics.Value.Misses.Should().Be(1);
+ lru.Metrics.Value.Misses.ShouldBe(1);
}
[Fact]
public void EventsAreEnabled()
{
- lru.Events.HasValue.Should().BeFalse();
+ lru.Events.HasValue.ShouldBeFalse();
}
private void OnItemRemoved(object sender, ItemRemovedEventArgs e)
@@ -168,7 +167,7 @@ private void OnItemRemoved(object sender, ItemRemovedEventArgs e)
[Fact]
public void ExpireAfterWriteIsDisabled()
{
- lru.Policy.ExpireAfterWrite.HasValue.Should().BeFalse();
+ lru.Policy.ExpireAfterWrite.HasValue.ShouldBeFalse();
}
[Fact]
@@ -177,8 +176,8 @@ public void WhenKeyIsRequestedItIsCreatedAndCached()
var result1 = lru.GetOrAdd(1, valueFactory.Create);
var result2 = lru.GetOrAdd(1, valueFactory.Create);
- valueFactory.timesCalled.Should().Be(1);
- result1.Should().Be(result2);
+ valueFactory.timesCalled.ShouldBe(1);
+ result1.ShouldBe(result2);
}
@@ -188,8 +187,8 @@ public void WhenKeyIsRequestedWithArgItIsCreatedAndCached()
var result1 = lru.GetOrAdd(1, valueFactory.Create, "x");
var result2 = lru.GetOrAdd(1, valueFactory.Create, "y");
- valueFactory.timesCalled.Should().Be(1);
- result1.Should().Be(result2);
+ valueFactory.timesCalled.ShouldBe(1);
+ result1.ShouldBe(result2);
}
[Fact]
@@ -198,8 +197,8 @@ public async Task WhenKeyIsRequesteItIsCreatedAndCachedAsync()
var result1 = await lru.GetOrAddAsync(1, valueFactory.CreateAsync);
var result2 = await lru.GetOrAddAsync(1, valueFactory.CreateAsync);
- valueFactory.timesCalled.Should().Be(1);
- result1.Should().Be(result2);
+ valueFactory.timesCalled.ShouldBe(1);
+ result1.ShouldBe(result2);
}
[Fact]
@@ -208,8 +207,8 @@ public async Task WhenKeyIsRequestedWithArgItIsCreatedAndCachedAsync()
var result1 = await lru.GetOrAddAsync(1, valueFactory.CreateAsync, "x");
var result2 = await lru.GetOrAddAsync(1, valueFactory.CreateAsync, "y");
- valueFactory.timesCalled.Should().Be(1);
- result1.Should().Be(result2);
+ valueFactory.timesCalled.ShouldBe(1);
+ result1.ShouldBe(result2);
}
[Fact]
@@ -218,10 +217,10 @@ public void WhenDifferentKeysAreRequestedValueIsCreatedForEach()
var result1 = lru.GetOrAdd(1, valueFactory.Create);
var result2 = lru.GetOrAdd(2, valueFactory.Create);
- valueFactory.timesCalled.Should().Be(2);
+ valueFactory.timesCalled.ShouldBe(2);
- result1.Should().Be("1");
- result2.Should().Be("2");
+ result1.ShouldBe("1");
+ result2.ShouldBe("2");
}
[Fact]
@@ -230,10 +229,10 @@ public async Task WhenDifferentKeysAreRequesteValueIsCreatedForEachAsync()
var result1 = await lru.GetOrAddAsync(1, valueFactory.CreateAsync);
var result2 = await lru.GetOrAddAsync(2, valueFactory.CreateAsync);
- valueFactory.timesCalled.Should().Be(2);
+ valueFactory.timesCalled.ShouldBe(2);
- result1.Should().Be("1");
- result2.Should().Be("2");
+ result1.ShouldBe("1");
+ result2.ShouldBe("2");
}
[Fact]
@@ -244,8 +243,8 @@ public void WhenMoreKeysRequestedThanCapacityCountDoesNotIncrease()
lru.GetOrAdd(i, valueFactory.Create);
}
- lru.Count.Should().Be(capacity);
- valueFactory.timesCalled.Should().Be(capacity + 1);
+ lru.Count.ShouldBe(capacity);
+ valueFactory.timesCalled.ShouldBe(capacity + 1);
}
[Fact]
@@ -256,8 +255,8 @@ public async Task WhenMoreKeysRequestedThanCapacityCountDoesNotIncreaseAsync()
await lru.GetOrAddAsync(i, valueFactory.CreateAsync);
}
- lru.Count.Should().Be(capacity);
- valueFactory.timesCalled.Should().Be(capacity + 1);
+ lru.Count.ShouldBe(capacity);
+ valueFactory.timesCalled.ShouldBe(capacity + 1);
}
[Fact]
@@ -269,23 +268,23 @@ public void WhenMoreKeysRequestedThanCapacityOldestItemIsEvicted()
lru.GetOrAdd(i, valueFactory.Create);
}
- valueFactory.timesCalled.Should().Be(capacity);
+ valueFactory.timesCalled.ShouldBe(capacity);
// request 0, now item 1 is to be evicted
lru.GetOrAdd(0, valueFactory.Create);
- valueFactory.timesCalled.Should().Be(capacity);
+ valueFactory.timesCalled.ShouldBe(capacity);
// request next item after last, verify value factory was called
lru.GetOrAdd(capacity, valueFactory.Create);
- valueFactory.timesCalled.Should().Be(capacity + 1);
+ valueFactory.timesCalled.ShouldBe(capacity + 1);
// request 0, verify value factory not called
lru.GetOrAdd(0, valueFactory.Create);
- valueFactory.timesCalled.Should().Be(capacity + 1);
+ valueFactory.timesCalled.ShouldBe(capacity + 1);
// request 1, verify value factory is called (and it was therefore not cached)
lru.GetOrAdd(1, valueFactory.Create);
- valueFactory.timesCalled.Should().Be(capacity + 2);
+ valueFactory.timesCalled.ShouldBe(capacity + 2);
}
[Fact]
@@ -297,12 +296,12 @@ public void WhenMoreKeysRequestedThanCapacityEvictedMetricRecordsNumberEvicted()
lru.GetOrAdd(i, valueFactory.Create);
}
- lru.Metrics.Value.Evicted.Should().Be(0);
+ lru.Metrics.Value.Evicted.ShouldBe(0);
// request 0, now item 1 is to be evicted
lru.GetOrAdd(4, valueFactory.Create);
- lru.Metrics.Value.Evicted.Should().Be(1);
+ lru.Metrics.Value.Evicted.ShouldBe(1);
}
[Fact]
@@ -316,8 +315,8 @@ public void WhenValueExpiresItIsDisposed()
lruOfDisposable.GetOrAdd(i, disposableValueFactory.Create);
}
- disposableValueFactory.Items[0].IsDisposed.Should().BeTrue();
- disposableValueFactory.Items[1].IsDisposed.Should().BeFalse();
+ disposableValueFactory.Items[0].IsDisposed.ShouldBeTrue();
+ disposableValueFactory.Items[1].IsDisposed.ShouldBeFalse();
}
[Fact]
@@ -331,8 +330,8 @@ public async Task WhenValueExpiresAsyncItIsDisposed()
await lruOfDisposable.GetOrAddAsync(i, disposableValueFactory.CreateAsync);
}
- disposableValueFactory.Items[0].IsDisposed.Should().BeTrue();
- disposableValueFactory.Items[1].IsDisposed.Should().BeFalse();
+ disposableValueFactory.Items[0].IsDisposed.ShouldBeTrue();
+ disposableValueFactory.Items[1].IsDisposed.ShouldBeFalse();
}
[Fact]
@@ -340,7 +339,7 @@ public void WhenKeyDoesNotExistTryGetReturnsFalse()
{
lru.GetOrAdd(1, valueFactory.Create);
- lru.TryGet(2, out var result).Should().Be(false);
+ lru.TryGet(2, out var result).ShouldBe(false);
}
[Fact]
@@ -349,8 +348,8 @@ public void WhenKeyExistsTryGetReturnsTrueAndOutValueIsCorrect()
lru.GetOrAdd(1, valueFactory.Create);
bool result = lru.TryGet(1, out var value);
- result.Should().Be(true);
- value.Should().Be("1");
+ result.ShouldBe(true);
+ value.ShouldBe("1");
}
[Fact]
@@ -358,8 +357,8 @@ public void WhenKeyExistsTryRemoveRemovesItemAndReturnsTrue()
{
lru.GetOrAdd(1, valueFactory.Create);
- lru.TryRemove(1).Should().BeTrue();
- lru.TryGet(1, out var value).Should().BeFalse();
+ lru.TryRemove(1).ShouldBeTrue();
+ lru.TryGet(1, out var value).ShouldBeFalse();
}
[Fact]
@@ -367,8 +366,8 @@ public void WhenKeyExistsTryRemoveReturnsValue()
{
lru.GetOrAdd(1, valueFactory.Create);
- lru.TryRemove(1, out var value).Should().BeTrue();
- value.Should().Be("1");
+ lru.TryRemove(1, out var value).ShouldBeTrue();
+ value.ShouldBe("1");
}
[Fact]
@@ -376,8 +375,8 @@ public void WhenItemExistsTryRemovesItemAndReturnsTrue()
{
lru.GetOrAdd(1, valueFactory.Create);
- lru.TryRemove(new KeyValuePair(1, "1")).Should().BeTrue();
- lru.TryGet(1, out var value).Should().BeFalse();
+ lru.TryRemove(new KeyValuePair(1, "1")).ShouldBeTrue();
+ lru.TryGet(1, out var value).ShouldBeFalse();
}
[Fact]
@@ -385,8 +384,8 @@ public void WhenTryRemoveKvpDoesntMatchItemNotRemovedAndReturnsFalse()
{
lru.GetOrAdd(1, valueFactory.Create);
- lru.TryRemove(new KeyValuePair(1, "2")).Should().BeFalse();
- lru.TryGet(1, out var value).Should().BeTrue();
+ lru.TryRemove(new KeyValuePair(1, "2")).ShouldBeFalse();
+ lru.TryGet(1, out var value).ShouldBeTrue();
}
[Fact]
@@ -398,7 +397,7 @@ public void WhenItemIsRemovedItIsDisposed()
lruOfDisposable.GetOrAdd(1, disposableValueFactory.Create);
lruOfDisposable.TryRemove(1);
- disposableValueFactory.Items[1].IsDisposed.Should().BeTrue();
+ disposableValueFactory.Items[1].IsDisposed.ShouldBeTrue();
}
[Fact]
@@ -406,7 +405,7 @@ public void WhenKeyDoesNotExistTryRemoveReturnsFalse()
{
lru.GetOrAdd(1, valueFactory.Create);
- lru.TryRemove(2).Should().BeFalse();
+ lru.TryRemove(2).ShouldBeFalse();
}
[Fact]
@@ -414,10 +413,10 @@ public void WhenKeyExistsTryUpdateUpdatesValueAndReturnsTrue()
{
lru.GetOrAdd(1, valueFactory.Create);
- lru.TryUpdate(1, "2").Should().BeTrue();
+ lru.TryUpdate(1, "2").ShouldBeTrue();
lru.TryGet(1, out var value);
- value.Should().Be("2");
+ value.ShouldBe("2");
}
[Fact]
@@ -425,7 +424,7 @@ public void WhenKeyDoesNotExistTryUpdateReturnsFalse()
{
lru.GetOrAdd(1, valueFactory.Create);
- lru.TryUpdate(2, "3").Should().BeFalse();
+ lru.TryUpdate(2, "3").ShouldBeFalse();
}
// backcompat: remove conditional compile
@@ -435,9 +434,9 @@ public void WhenKeyExistsTryUpdateIncrementsUpdateCount()
{
lru.GetOrAdd(1, valueFactory.Create);
- lru.TryUpdate(1, "2").Should().BeTrue();
+ lru.TryUpdate(1, "2").ShouldBeTrue();
- lru.Metrics.Value.Updated.Should().Be(1);
+ lru.Metrics.Value.Updated.ShouldBe(1);
}
[Fact]
@@ -445,9 +444,9 @@ public void WhenKeyDoesNotExistTryUpdateDoesNotIncrementCounter()
{
lru.GetOrAdd(1, valueFactory.Create);
- lru.TryUpdate(2, "3").Should().BeFalse();
+ lru.TryUpdate(2, "3").ShouldBeFalse();
- lru.Metrics.Value.Updated.Should().Be(0);
+ lru.Metrics.Value.Updated.ShouldBe(0);
}
#endif
@@ -456,8 +455,8 @@ public void WhenKeyDoesNotExistAddOrUpdateAddsNewItem()
{
lru.AddOrUpdate(1, "1");
- lru.TryGet(1, out var value).Should().BeTrue();
- value.Should().Be("1");
+ lru.TryGet(1, out var value).ShouldBeTrue();
+ value.ShouldBe("1");
}
[Fact]
@@ -466,8 +465,8 @@ public void WhenKeyExistsAddOrUpdatUpdatesExistingItem()
lru.AddOrUpdate(1, "1");
lru.AddOrUpdate(1, "2");
- lru.TryGet(1, out var value).Should().BeTrue();
- value.Should().Be("2");
+ lru.TryGet(1, out var value).ShouldBeTrue();
+ value.ShouldBe("2");
}
[Fact]
@@ -479,8 +478,8 @@ public void WhenKeyDoesNotExistAddOrUpdateMaintainsLruOrder()
lru.AddOrUpdate(4, "4");
// verify first item added is removed
- lru.Count.Should().Be(3);
- lru.TryGet(1, out var value).Should().BeFalse();
+ lru.Count.ShouldBe(3);
+ lru.TryGet(1, out _).ShouldBeFalse();
}
[Fact]
@@ -496,17 +495,17 @@ public void WhenAddOrUpdateExpiresItemsTheyAreDisposed()
}
// first item is evicted and disposed
- items[0].IsDisposed.Should().BeTrue();
+ items[0].IsDisposed.ShouldBeTrue();
// all other items are not disposed
- items.Skip(1).All(i => i.IsDisposed == false).Should().BeTrue();
+ items.Skip(1).All(i => i.IsDisposed == false).ShouldBeTrue();
}
[Fact]
public void WhenCacheIsEmptyClearIsNoOp()
{
lru.Clear();
- lru.Count.Should().Be(0);
+ lru.Count.ShouldBe(0);
}
[Fact]
@@ -515,7 +514,7 @@ public void WhenItemsExistClearRemovesAllItems()
lru.AddOrUpdate(1, "1");
lru.AddOrUpdate(2, "2");
lru.Clear();
- lru.Count.Should().Be(0);
+ lru.Count.ShouldBe(0);
}
[Fact]
@@ -532,19 +531,19 @@ public void WhenItemsAreDisposableClearDisposesItemsOnRemove()
lruOfDisposable.Clear();
- items.All(i => i.IsDisposed == true).Should().BeTrue();
+ items.All(i => i.IsDisposed == true).ShouldBeTrue();
}
[Fact]
public void WhenTrimCountIsZeroThrows()
- {
- lru.Invoking(l => lru.Trim(0)).Should().Throw();
+ {
+ Should.Throw(() => lru.Trim(0));
}
[Fact]
public void WhenTrimCountIsMoreThanCapacityThrows()
{
- lru.Invoking(l => lru.Trim(capacity + 1)).Should().Throw();
+ Should.Throw(() => lru.Trim(capacity + 1));
}
[Theory]
@@ -563,7 +562,7 @@ public void WhenItemsExistTrimRemovesExpectedItemCount(int trimCount, int[] expe
lru.Trim(trimCount);
- lru.Keys.Should().BeEquivalentTo(expected);
+ lru.Keys.ShouldBe(expected);
}
[Fact]
@@ -586,10 +585,10 @@ public void WhenItemsAreDisposableTrimDisposesItems()
lruOfDisposable.Trim(2);
- items[0].IsDisposed.Should().BeTrue();
- items[1].IsDisposed.Should().BeTrue();
- items[2].IsDisposed.Should().BeFalse();
- items[3].IsDisposed.Should().BeFalse();
+ items[0].IsDisposed.ShouldBeTrue();
+ items[1].IsDisposed.ShouldBeTrue();
+ items[2].IsDisposed.ShouldBeFalse();
+ items[3].IsDisposed.ShouldBeFalse();
}
}
}
diff --git a/BitFaster.Caching.UnitTests/Lru/ConcurrentLruAfterAccessTests.cs b/BitFaster.Caching.UnitTests/Lru/ConcurrentLruAfterAccessTests.cs
index fbdb8a05..bb6ef60d 100644
--- a/BitFaster.Caching.UnitTests/Lru/ConcurrentLruAfterAccessTests.cs
+++ b/BitFaster.Caching.UnitTests/Lru/ConcurrentLruAfterAccessTests.cs
@@ -3,7 +3,7 @@
using System.Runtime.InteropServices;
using BitFaster.Caching.Lru;
using BitFaster.Caching.UnitTests.Retry;
-using FluentAssertions;
+using Shouldly;
using Xunit;
namespace BitFaster.Caching.UnitTests.Lru
@@ -37,13 +37,13 @@ public ConcurrentLruAfterAccessTests()
[Fact]
public void CanExpireIsTrue()
{
- this.lru.Policy.ExpireAfterAccess.HasValue.Should().BeTrue();
+ this.lru.Policy.ExpireAfterAccess.HasValue.ShouldBeTrue();
}
[Fact]
public void TimeToLiveIsCtorArg()
{
- this.lru.Policy.ExpireAfterAccess.Value.TimeToLive.Should().Be(timeToLive);
+ this.lru.Policy.ExpireAfterAccess.Value.TimeToLive.ShouldBe(timeToLive);
}
[RetryFact]
@@ -51,7 +51,7 @@ public void WhenItemIsNotExpiredItIsNotRemoved()
{
lru.GetOrAdd(1, valueFactory.Create);
- lru.TryGet(1, out var value).Should().BeTrue();
+ lru.TryGet(1, out var value).ShouldBeTrue();
}
[RetryFact]
@@ -67,7 +67,7 @@ public void WhenItemIsExpiredItIsRemoved()
timeToLive.MultiplyBy(ttlWaitMlutiplier),
lru =>
{
- lru.TryGet(1, out var value).Should().BeFalse();
+ lru.TryGet(1, out var value).ShouldBeFalse();
}
);
}
@@ -86,7 +86,7 @@ public void WhenItemIsUpdatedTtlIsExtended()
lru =>
{
lru.TryUpdate(1, "3");
- lru.TryGet(1, out var value).Should().BeTrue();
+ lru.TryGet(1, out var value).ShouldBeTrue();
}
);
}
@@ -120,12 +120,12 @@ public void WhenItemIsReadTtlIsExtended()
TimeSpan.FromMilliseconds(50),
lru =>
{
- lru.TryGet(1, out _).Should().BeTrue($"First");
+ lru.TryGet(1, out _).ShouldBeTrue($"First");
},
TimeSpan.FromMilliseconds(75),
lru =>
{
- lru.TryGet(1, out var value).Should().BeTrue($"Second");
+ lru.TryGet(1, out var value).ShouldBeTrue($"Second");
}
);
}
@@ -150,15 +150,15 @@ public void WhenValueEvictedItemRemovedEventIsFired()
lruEvents.GetOrAdd(i + 1, i => i + 1);
}
- removedItems.Count.Should().Be(2);
+ removedItems.Count.ShouldBe(2);
- removedItems[0].Key.Should().Be(1);
- removedItems[0].Value.Should().Be(2);
- removedItems[0].Reason.Should().Be(ItemRemovedReason.Evicted);
+ removedItems[0].Key.ShouldBe(1);
+ removedItems[0].Value.ShouldBe(2);
+ removedItems[0].Reason.ShouldBe(ItemRemovedReason.Evicted);
- removedItems[1].Key.Should().Be(4);
- removedItems[1].Value.Should().Be(5);
- removedItems[1].Reason.Should().Be(ItemRemovedReason.Evicted);
+ removedItems[1].Key.ShouldBe(4);
+ removedItems[1].Value.ShouldBe(5);
+ removedItems[1].Reason.ShouldBe(ItemRemovedReason.Evicted);
}
[RetryFact]
@@ -190,7 +190,7 @@ public void WhenItemsAreExpiredExpireRemovesExpiredItems()
{
lru.Policy.ExpireAfterAccess.Value.TrimExpired();
- lru.Count.Should().Be(0);
+ lru.Count.ShouldBe(0);
}
);
}
@@ -221,7 +221,7 @@ public void WhenCacheHasExpiredAndFreshItemsExpireRemovesOnlyExpiredItems()
lru.Policy.ExpireAfterAccess.Value.TrimExpired();
- lru.Count.Should().Be(3);
+ lru.Count.ShouldBe(3);
}
);
}
@@ -244,7 +244,7 @@ public void WhenItemsAreExpiredTrimRemovesExpiredItems()
{
lru.Policy.Eviction.Value.Trim(1);
- lru.Count.Should().Be(0);
+ lru.Count.ShouldBe(0);
}
);
}
diff --git a/BitFaster.Caching.UnitTests/Lru/ConcurrentLruAfterDiscreteTests.cs b/BitFaster.Caching.UnitTests/Lru/ConcurrentLruAfterDiscreteTests.cs
index c0ddf336..e9897613 100644
--- a/BitFaster.Caching.UnitTests/Lru/ConcurrentLruAfterDiscreteTests.cs
+++ b/BitFaster.Caching.UnitTests/Lru/ConcurrentLruAfterDiscreteTests.cs
@@ -3,7 +3,7 @@
using System.Runtime.InteropServices;
using BitFaster.Caching.Lru;
using BitFaster.Caching.UnitTests.Retry;
-using FluentAssertions;
+using Shouldly;
using Xunit;
namespace BitFaster.Caching.UnitTests.Lru
@@ -39,21 +39,21 @@ public ConcurrentLruAfterDiscreteTests()
[Fact]
public void WhenKeyIsWrongTypeTryGetTimeToExpireIsFalse()
{
- lru.Policy.ExpireAfter.Value.TryGetTimeToExpire("foo", out _).Should().BeFalse();
+ lru.Policy.ExpireAfter.Value.TryGetTimeToExpire("foo", out _).ShouldBeFalse();
}
[Fact]
public void WhenKeyDoesNotExistTryGetTimeToExpireIsFalse()
{
- lru.Policy.ExpireAfter.Value.TryGetTimeToExpire(1, out _).Should().BeFalse();
+ lru.Policy.ExpireAfter.Value.TryGetTimeToExpire(1, out _).ShouldBeFalse();
}
[RetryFact]
public void WhenKeyExistsTryGetTimeToExpireReturnsExpiryTime()
{
lru.GetOrAdd(1, k => "1");
- lru.Policy.ExpireAfter.Value.TryGetTimeToExpire(1, out var expiry).Should().BeTrue();
- expiry.Should().BeCloseTo(TestExpiryCalculator.DefaultTimeToExpire.ToTimeSpan(), delta);
+ lru.Policy.ExpireAfter.Value.TryGetTimeToExpire(1, out var expiry).ShouldBeTrue();
+ expiry.ShouldBe(TestExpiryCalculator.DefaultTimeToExpire.ToTimeSpan(), delta);
}
[RetryFact]
@@ -69,7 +69,7 @@ public void WhenItemIsExpiredItIsRemoved()
TestExpiryCalculator.DefaultTimeToExpire.MultiplyBy(ttlWaitMlutiplier),
lru =>
{
- lru.TryGet(1, out var value).Should().BeFalse();
+ lru.TryGet(1, out var value).ShouldBeFalse();
}
);
}
@@ -88,7 +88,7 @@ public void WhenItemIsUpdatedTtlIsExtended()
lru =>
{
lru.TryUpdate(1, "3");
- lru.TryGet(1, out var value).Should().BeTrue();
+ lru.TryGet(1, out var value).ShouldBeTrue();
}
);
}
@@ -118,12 +118,12 @@ public void WhenItemIsReadTtlIsExtended()
TimeSpan.FromMilliseconds(50),
lru =>
{
- lru.TryGet(1, out _).Should().BeTrue($"First");
+ lru.TryGet(1, out _).ShouldBeTrue($"First");
},
TimeSpan.FromMilliseconds(75),
lru =>
{
- lru.TryGet(1, out var value).Should().BeTrue($"Second");
+ lru.TryGet(1, out var value).ShouldBeTrue($"Second");
}
);
}
@@ -150,15 +150,15 @@ public void WhenValueEvictedItemRemovedEventIsFired()
lruEvents.GetOrAdd(i + 1, i => $"{i + 1}");
}
- removedItems.Count.Should().Be(2);
+ removedItems.Count.ShouldBe(2);
- removedItems[0].Key.Should().Be(1);
- removedItems[0].Value.Should().Be("2");
- removedItems[0].Reason.Should().Be(ItemRemovedReason.Evicted);
+ removedItems[0].Key.ShouldBe(1);
+ removedItems[0].Value.ShouldBe("2");
+ removedItems[0].Reason.ShouldBe(ItemRemovedReason.Evicted);
- removedItems[1].Key.Should().Be(4);
- removedItems[1].Value.Should().Be("5");
- removedItems[1].Reason.Should().Be(ItemRemovedReason.Evicted);
+ removedItems[1].Key.ShouldBe(4);
+ removedItems[1].Value.ShouldBe("5");
+ removedItems[1].Reason.ShouldBe(ItemRemovedReason.Evicted);
}
[RetryFact]
@@ -190,7 +190,7 @@ public void WhenItemsAreExpiredExpireRemovesExpiredItems()
{
lru.Policy.ExpireAfter.Value.TrimExpired();
- lru.Count.Should().Be(0);
+ lru.Count.ShouldBe(0);
}
);
}
@@ -221,7 +221,7 @@ public void WhenCacheHasExpiredAndFreshItemsExpireRemovesOnlyExpiredItems()
lru.Policy.ExpireAfter.Value.TrimExpired();
- lru.Count.Should().Be(3);
+ lru.Count.ShouldBe(3);
}
);
}
@@ -244,7 +244,7 @@ public void WhenItemsAreExpiredTrimRemovesExpiredItems()
{
lru.Policy.Eviction.Value.Trim(1);
- lru.Count.Should().Be(0);
+ lru.Count.ShouldBe(0);
}
);
}
diff --git a/BitFaster.Caching.UnitTests/Lru/ConcurrentLruBuilderTests.cs b/BitFaster.Caching.UnitTests/Lru/ConcurrentLruBuilderTests.cs
index 851640c3..68ecafa1 100644
--- a/BitFaster.Caching.UnitTests/Lru/ConcurrentLruBuilderTests.cs
+++ b/BitFaster.Caching.UnitTests/Lru/ConcurrentLruBuilderTests.cs
@@ -1,557 +1,557 @@
-using System;
-using BitFaster.Caching.Lru;
-using BitFaster.Caching.Atomic;
-using FluentAssertions;
-using Xunit;
-
-namespace BitFaster.Caching.UnitTests.Lru
-{
- public class ConcurrentLruBuilderTests
- {
- [Fact]
- public void TestFastLru()
- {
- ICache lru = new ConcurrentLruBuilder()
- .Build();
-
- lru.Should().BeOfType>();
- }
-
- [Fact]
- public void TestMetricsLru()
- {
- ICache lru = new ConcurrentLruBuilder()
- .WithMetrics()
- .Build();
-
- lru.Should().BeOfType>();
- }
-
- [Fact]
- public void TestFastTLru()
- {
- ICache lru = new ConcurrentLruBuilder()
- .WithExpireAfterWrite(TimeSpan.FromSeconds(1))
- .Build();
-
- lru.Should().BeOfType>();
- }
-
- [Fact]
- public void TestMetricsTLru()
- {
- ICache lru = new ConcurrentLruBuilder()
- .WithExpireAfterWrite(TimeSpan.FromSeconds(1))
- .WithMetrics()
- .Build();
-
- lru.Should().BeOfType>();
- lru.Policy.Eviction.Value.Capacity.Should().Be(128);
- }
-
- [Fact]
- public void AsAsyncTestFastLru()
- {
- IAsyncCache lru = new ConcurrentLruBuilder()
- .AsAsyncCache()
- .Build();
-
- lru.Should().BeOfType