InMemoryTestStore<T> Class
Definition
- Namespace
- Codebelt.Extensions.Xunit
- Assemblies
- Codebelt.Extensions.Xunit.dll
Provides a default base implementation of the ITestStore<T> interface.
public class InMemoryTestStore<T> : ITestStore<T>
Type Parameters
TThe type of the object to reference in the memory store.
- Inheritance
-
InMemoryTestStore<T>
- Implements
-
ITestStore<T>
Examples
Use the store to retain test data and query the matching items without a database.
using System.Linq;
using Codebelt.Extensions.Xunit;
namespace Example.Tests;
public class StoreExample
{
public bool HasMatchingItem()
{
var store = new InMemoryTestStore<string>();
store.Add("cached");
store.Add("other");
return store.Count == 2 && store.Query(value => value == "cached").Single() == "cached";
}
}
Availability: .NET 11, .NET 10 and .NET Standard 2.0
Constructors
| Name | Description |
|---|---|
| InMemoryTestStore() | Initializes a new instance of the InMemoryTestStore<T> class. |
Properties
| Name | Description |
|---|---|
| Count | Gets the number of elements contained in the InMemoryTestStore<T>. |
| InnerStore | Gets the reference to the encapsulated store. |
Methods
| Name | Description |
|---|---|
| Add(T) | Adds an item to the InMemoryTestStore<T>. |
| Query(Func<T, bool>) | Filters the elements contained in the InMemoryTestStore<T> based on an optional |
| QueryFor<TResult>() | Filters the elements contained in the InMemoryTestStore<T> based on the type |
See Also
ITestStore<T>