Rystem.RepositoryFramework.Infrastructure.InMemory 0.9.3

There is a newer version of this package available.
See the version list below for details.
dotnet add package Rystem.RepositoryFramework.Infrastructure.InMemory --version 0.9.3                
NuGet\Install-Package Rystem.RepositoryFramework.Infrastructure.InMemory -Version 0.9.3                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Rystem.RepositoryFramework.Infrastructure.InMemory" Version="0.9.3" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Rystem.RepositoryFramework.Infrastructure.InMemory --version 0.9.3                
#r "nuget: Rystem.RepositoryFramework.Infrastructure.InMemory, 0.9.3"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install Rystem.RepositoryFramework.Infrastructure.InMemory as a Cake Addin
#addin nuget:?package=Rystem.RepositoryFramework.Infrastructure.InMemory&version=0.9.3

// Install Rystem.RepositoryFramework.Infrastructure.InMemory as a Cake Tool
#tool nuget:?package=Rystem.RepositoryFramework.Infrastructure.InMemory&version=0.9.3                

In memory integration by default

With this library you can add in memory integration with the chance to create random data with random values, random based on regular expressions and delegated methods

public static RepositoryInMemoryBuilder<T, TKey> AddRepositoryInMemoryStorage<T, TKey>(
    this IServiceCollection services,
    Action<RepositoryBehaviorSettings<T, TKey>>? settings = default)
    where TKey : notnull 

Populate with specific key (example with Guid)

public RepositoryInMemoryBuilder<TNext, Guid> AddRepositoryInMemoryStorageWithGuidKey<TNext>(Action<RepositoryBehaviorSettings<TNext, Guid>>? settings = default)
    

How to populate with random data?

Simple random (example)

Populate your in memory storage with 120 users

var builder = WebApplication.CreateBuilder(args);
builder.Services.AddRepositoryInMemoryStorageWithStringKey<User>()
.PopulateWithRandomData(x => x.Email!, 120);

and in app after build during startup of your application

var app = builder.Build();
app.Services.Populate();
Simple random with regex (example)

Populate your in memory storage with 100 users and property Email with a random regex @"[a-z]{4,10}@gmail.com"

.AddRepositoryInMemoryStorage<User, string>()
.PopulateWithRandomData(x => x.Id!, 100)
.WithPattern(x => x.Email, @"[a-z]{4,10}@gmail\.com")

and in app after build during startup of your application

var app = builder.Build();
app.Services.Populate();
Where can I use the regex pattern?

You can use regex pattern on all primitives type and most used structs.

Complete list:
int, uint, byte, sbyte, short, ushort, long, ulong, nint, nuint, float, double, decimal, bool, char, Guid, DateTime, TimeSpan, Range, string, int?, uint?, byte?, sbyte?, short?, ushort?, long?, ulong?, nint?, nuint?, float?, double?, decimal?, bool?, char?, Guid?, DateTime?, TimeSpan?, Range?, string?

You can use the pattern in Class, IEnumerable, IDictionary, or Array, and in everything that extends IEnumerable or IDictionary

Important!! You can override regex service in your DI

public static IServiceCollection AddRegexService<T>(
        this IServiceCollection services)
        where T : class, IRegexService
IEnumerable or Array one-dimension (example)

You have your model x (User) that has a property Groups as IEnumerable or something that extends IEnumerable, Groups is a class with a property Id as string. In the code below you are creating a list of class Groups with 8 elements in each 100 User instances, in each element of Groups you randomize based on this regex "[a-z]{4,5}". You may take care of use First() linq method to set correctly the Id property.

.AddRepositoryInMemoryStorage<User, string>()
.PopulateWithRandomData(x => x.Id!, 100, 8)
.WithPattern(x => x.Groups!.First().Id, "[a-z]{4,5}")

and in app after build during startup of your application

app.Services.Populate()
IDictionary (example)

Similar to IEnumerable population you may populate your Claims property (a dictionary) with random key but with values based on regular expression "[a-z]{4,5}". As well as IEnumerable implementation you will have 6 elements (because I choose to create 6 elements in Populate method)

.AddRepositoryInMemoryStorage<User, string>()
.PopulateWithRandomData(x => x.Id!, 100, 6)
.WithPattern(x => x.Claims!.First().Value, "[a-z]{4,5}")

and in app after build during startup of your application

app.Services.Populate()

or if you have in Value an object

AddRepositoryInMemoryStorage<User, string>()
.PopulateWithRandomData(x => x.Id!, 100, 6)
.WithPattern(x => x.Claims!.First().Value.SomeProperty, "[a-z]{4,5}")

and in app after build during startup of your application

app.Services.Populate()

Populate with delegation

Similar to regex pattern, you can use a delegation to populate something.

Dictionary (example)

Here you can see that all 6 elements in each 100 users are populated in Value with string "A"

.AddRepositoryPatternInMemoryStorage<User, string>()
.PopulateWithRandomData(x => x.Id!, 100, 6)
.WithPattern(x => x.Claims!.First().Value, () => "A"))

and in app after build during startup of your application

app.Services.Populate()

Populate with Implementation

If you have an interface or abstraction in your model, you can specify an implementation type for population. You have two different methods, with typeof

.AddRepositoryInMemoryStorageWithStringKey<PopulationTest>()
.PopulateWithRandomData(x => x.Id!, 100, )
.WithImplementation(x => x.I, typeof(MyInnerInterfaceImplementation))

or generics

.AddRepositoryInMemoryStorageWithStringKey<PopulationTest>()
.PopulateWithRandomData(x => x.Id!, 100, )
.WithImplementation<IInnerInterface, MyInnerInterfaceImplementation>(x => x.I!)

In Memory, simulate real implementation

If you want to test with possible exceptions (for your reliability tests) and waiting time (for your load tests) you may do it with this library and in memory behavior settings.

Add random exceptions

You can set different custom exceptions and different percentage for each operation: Delete, Get, Insert, Update, Query. In the code below I'm adding three exceptions with a percentage of throwing them, they are the same for each operation. I have a 0.45% for normal Exception, 0.1% for "Big Exception" and 0.548% for "Great Exception"

.AddRepositoryInMemoryStorage<User, string>(options =>
{
    var customExceptions = new List<ExceptionOdds>
    {
        new ExceptionOdds()
        {
            Exception = new Exception(),
            Percentage = 0.45
        },
        new ExceptionOdds()
        {
            Exception = new Exception("Big Exception"),
            Percentage = 0.1
        },
        new ExceptionOdds()
        {
            Exception = new Exception("Great Exception"),
            Percentage = 0.548
        }
    };
    options.ExceptionOddsForDelete.AddRange(customExceptions);
    options.ExceptionOddsForGet.AddRange(customExceptions);
    options.ExceptionOddsForInsert.AddRange(customExceptions);
    options.ExceptionOddsForUpdate.AddRange(customExceptions);
    options.ExceptionOddsForQuery.AddRange(customExceptions);
})

Add random waiting time

You can set different range in milliseconds for each operation. In the code below I'm adding a same custom range for Delete, Insert, Update, Get between 1000ms and 2000ms, and a unique custom range for Query between 3000ms and 7000ms.

 .AddRepositoryInMemoryStorage<User, string>(options =>
  {
      var customRange = new Range(1000, 2000);
      options.MillisecondsOfWaitForDelete = customRange;
      options.MillisecondsOfWaitForInsert = customRange;
      options.MillisecondsOfWaitForUpdate = customRange;
      options.MillisecondsOfWaitForGet = customRange;
      options.MillisecondsOfWaitForQuery = new Range(3000, 7000);
  })   

Add random waiting time before an exception

You can set different range in milliseconds for each operation before to throw an exception. In the code below I'm adding a same custom range for Delete, Insert, Update, Get between 1000ms and 2000ms, and a unique custom range for Query between 3000ms and 7000ms in case of exception.

.AddRepositoryInMemoryStorage<User, string>(options =>
{
    var customRange = new Range(1000, 2000);
    options.MillisecondsOfWaitBeforeExceptionForDelete = customRange;
    options.MillisecondsOfWaitBeforeExceptionForInsert = customRange;
    options.MillisecondsOfWaitBeforeExceptionForUpdate = customRange;
    options.MillisecondsOfWaitBeforeExceptionForGet = customRange;
    options.MillisecondsOfWaitBeforeExceptionForQuery = new Range(3000, 7000);
    var customExceptions = new List<ExceptionOdds>
    {
        new ExceptionOdds()
        {
            Exception = new Exception(),
            Percentage = 0.45
        },
        new ExceptionOdds()
        {
            Exception = new Exception("Big Exception"),
            Percentage = 0.1
        },
        new ExceptionOdds()
        {
            Exception = new Exception("Great Exception"),
            Percentage = 0.548
        }
    };
    options.ExceptionOddsForDelete.AddRange(customExceptions);
    options.ExceptionOddsForGet.AddRange(customExceptions);
Product Compatible and additional computed target framework versions.
.NET net6.0 is compatible.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
9.0.0 56,972 11/16/2024
9.0.0-rc.1 73 10/18/2024
6.2.0 219,007 10/9/2024
6.1.1 102 10/9/2024
6.1.0 47,884 9/29/2024
6.0.24 117 9/11/2024
6.0.23 105 7/18/2024
6.0.21 107 6/18/2024
6.0.20 103 6/16/2024
6.0.19 380 6/14/2024
6.0.18 103 6/14/2024
6.0.17 99 6/14/2024
6.0.16 99 6/10/2024
6.0.15 110 6/9/2024
6.0.14 124 5/24/2024
6.0.13 113 5/23/2024
6.0.12 118 5/23/2024
6.0.11 117 5/20/2024
6.0.9 120 5/20/2024
6.0.7 108 5/18/2024
6.0.6 93 5/10/2024
6.0.5 97 5/10/2024
6.0.4 127 4/3/2024
6.0.3 120 3/25/2024
6.0.2 112 3/11/2024
6.0.0 281 11/21/2023
6.0.0-rc.6 104 10/25/2023
6.0.0-rc.5 85 10/25/2023
6.0.0-rc.4 71 10/23/2023
6.0.0-rc.3 70 10/19/2023
6.0.0-rc.2 76 10/18/2023
6.0.0-rc.1 70 10/16/2023
5.0.20 190 9/25/2023
5.0.19 225 9/10/2023
5.0.18 182 9/6/2023
5.0.17 146 9/6/2023
5.0.16 145 9/5/2023
5.0.15 151 9/5/2023
5.0.14 163 9/5/2023
5.0.13 153 9/1/2023
5.0.12 147 8/31/2023
5.0.11 134 8/30/2023
5.0.10 150 8/29/2023
5.0.9 169 8/24/2023
5.0.8 154 8/24/2023
5.0.7 161 8/23/2023
5.0.6 162 8/21/2023
5.0.5 151 8/21/2023
5.0.4 179 8/16/2023
5.0.3 176 8/2/2023
5.0.2 170 8/2/2023
5.0.1 162 8/1/2023
5.0.0 183 7/31/2023
4.1.26 184 7/20/2023
4.1.25 201 7/16/2023
4.1.24 220 6/13/2023
4.1.23 183 6/13/2023
4.1.22 173 5/30/2023
4.1.21 205 5/20/2023
4.1.20 315,190 4/19/2023
4.1.19 95,069 3/20/2023
4.1.18 269 3/20/2023
4.1.17 254 3/16/2023
4.1.16 273 3/16/2023
4.1.15 268 3/15/2023
4.1.14 850 3/9/2023
4.1.13 276 3/7/2023
4.1.12 311 2/10/2023
4.1.11 366 1/26/2023
4.1.10 372 1/22/2023
4.1.9 348 1/20/2023
4.1.8 348 1/18/2023
4.1.7 519 1/18/2023
4.1.6 328 1/17/2023
4.1.1 373 1/4/2023
4.1.0 412 1/1/2023
3.1.5 359 12/21/2022
3.1.3 370 12/12/2022
3.1.2 345 12/7/2022
3.1.1 350 12/7/2022
3.1.0 401 12/2/2022
3.0.29 399 12/1/2022
3.0.28 357 12/1/2022
3.0.27 407 11/23/2022
3.0.25 363 11/23/2022
3.0.24 395 11/18/2022
3.0.23 361 11/18/2022
3.0.22 387 11/15/2022
3.0.21 391 11/14/2022
3.0.20 422 11/13/2022
3.0.19 422 11/2/2022
3.0.18 414 11/2/2022
3.0.17 460 10/29/2022
3.0.16 423 10/29/2022
3.0.15 435 10/29/2022
3.0.14 453 10/24/2022
3.0.13 436 10/24/2022
3.0.12 450 10/17/2022
3.0.11 478 10/10/2022
3.0.10 452 10/6/2022
3.0.9 450 10/6/2022
3.0.8 451 10/6/2022
3.0.7 473 10/6/2022
3.0.6 451 10/5/2022
3.0.5 462 10/5/2022
3.0.4 483 10/5/2022
3.0.3 460 10/3/2022
3.0.2 446 9/30/2022
3.0.1 454 9/29/2022
2.0.17 463 9/29/2022
2.0.16 490 9/27/2022
2.0.15 506 9/27/2022
2.0.14 505 9/26/2022
2.0.13 511 9/26/2022
2.0.12 505 9/26/2022
2.0.11 491 9/25/2022
2.0.10 522 9/25/2022
2.0.9 500 9/22/2022
2.0.8 483 9/22/2022
2.0.6 488 9/20/2022
2.0.5 479 9/20/2022
2.0.4 496 9/20/2022
2.0.2 519 9/20/2022
2.0.1 566 9/13/2022
2.0.0 499 8/19/2022
1.1.24 513 7/30/2022
1.1.23 495 7/29/2022
1.1.22 495 7/29/2022
1.1.21 802 7/29/2022
1.1.20 516 7/29/2022
1.1.19 571 7/27/2022
1.1.17 503 7/27/2022
1.1.16 520 7/26/2022
1.1.15 503 7/25/2022
1.1.14 517 7/25/2022
1.1.13 516 7/22/2022
1.1.12 522 7/19/2022
1.1.11 558 7/19/2022
1.1.10 506 7/19/2022
1.1.9 540 7/19/2022
1.1.8 513 7/18/2022
1.1.7 520 7/18/2022
1.1.6 516 7/18/2022
1.1.5 518 7/17/2022
1.1.4 521 7/17/2022
1.1.3 534 7/17/2022
1.1.2 534 7/17/2022
1.1.0 535 7/17/2022
1.0.2 523 7/15/2022
1.0.1 503 7/15/2022
1.0.0 535 7/8/2022
0.10.7 520 7/7/2022
0.10.2 583 7/2/2022
0.10.1 506 7/1/2022
0.10.0 508 7/1/2022
0.9.12 521 6/29/2022
0.9.11 567 6/20/2022
0.9.10 520 6/20/2022
0.9.9 512 6/11/2022
0.9.7 560 6/9/2022
0.9.6 533 6/5/2022
0.9.5 522 6/3/2022
0.9.4 512 6/3/2022
0.9.3 486 6/3/2022
0.9.2 490 5/31/2022
0.9.1 497 5/31/2022
0.9.0 511 5/31/2022