ClickHouse.Facades.Testing 2.1.2

There is a newer version of this package available.
See the version list below for details.
dotnet add package ClickHouse.Facades.Testing --version 2.1.2                
NuGet\Install-Package ClickHouse.Facades.Testing -Version 2.1.2                
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="ClickHouse.Facades.Testing" Version="2.1.2" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add ClickHouse.Facades.Testing --version 2.1.2                
#r "nuget: ClickHouse.Facades.Testing, 2.1.2"                
#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 ClickHouse.Facades.Testing as a Cake Addin
#addin nuget:?package=ClickHouse.Facades.Testing&version=2.1.2

// Install ClickHouse.Facades.Testing as a Cake Tool
#tool nuget:?package=ClickHouse.Facades.Testing&version=2.1.2                

ClickHouse.Facades.Testing

Dedicated testing toolkit tailored for unit testing components within the ClickHouse.Facades library.

Key Features

  • Base Testing Class: Utilize the ClickHouseFacadesTestsCore class, a base class designed specifically for testing ClickHouse facades within MSTest v2 framework.
  • Facilitated Mocking: Seamlessly mock ClickHouse facades or specific requests to the ClickHouse database, including operations like ExecuteNonQuery, ExecuteScalar, and ExecuteReader.
  • Request Tracking: Monitor requests made to the ClickHouse database, utilizing IClickHouseConnectionTracker interface.

Note: This package does not reference any testing frameworks, but it was designed with a focus on MSTest v2. Therefore, correct behavior is currently guaranteed only for this framework.

Getting Started

Installation

To get started, install the ClickHouse.Facades.Testing package via NuGet Package Manager:

nuget install ClickHouse.Facades.Testing

Usage

Create your test classes by inheriting from ClickHouseFacadesTestsCore.

[TestClass]
public class YourTestClass : ClickHouseFacadesTestsCore
{
    protected override void SetupServiceCollection(IServiceCollection services)
    {
        services.AddClickHouseTestContext<MyContext, MyContextFactory>(builder =>
            builder.AddFacade<IMyFacade, MyFacade>());
    }
}

If you use exposed factory type, pass optional parameter exposedFactoryType to AddClickHouseTestContext method.

Now you have two ways to test your application: mock facade abstraction or mock database requests.

Mock facade abstraction

To use this approach you should register your facade with abstraction - .AddFacade<IMyFacade, MyFacade>().

[TestMethod]
public async Task My_Test()
{
    Mock<IMyFacade> facadeMock = new();
    facadeMock
        .Setup(m => m.SomeRequest())
        .Callback(SomeMethod);
		
    MockFacadeAbstraction(facadeMock.Object);
}
Mock database requests

You can only mock ExecuteNonQuery, ExecuteScalar and ExecuteReader (ExecuteDataTable can be mocked through mocking ExecuteReader). All calls of these methods are mocked to return default values by default. You can override return values of selected calls by sql string predicate. Database requests are tracked with IClickHouseConnectionTracker (GetClickHouseConnectionTracker<TContext>). CreateCommand and BulkInsert are throwing exceptions - use facade mock approach.

[TestMethod]
public async Task My_Test()
{
    MockExecuteScalar<MyContext>(
        sql => sql == "select count() from my_table",
        () => 100_000);

    MockExecuteReader<MyContext, MyDataTransferObject>(
        sql => sql == "select * from my_second_table",
        new List<MyDataTransferObject>
        {
            new(1, "One"),
            new(2, "Two"),
        },
        ("id", typeof(ulong), item => item.Id),
        ("name", typeof(string), item => item.Name));

    // Act

    var connectionTracker = GetClickHouseConnectionTracker<MyContext>();

    Assert.AreEqual(2, connectionTracker.RecordsCount);
}

Note: To test your code that uses facades, it is not necessary to inherit from the ClickHouseFacadesTestsCore class. It is sufficient to use facades through abstractions, register the context via services.AddClickHouseTestContext, and replace the facade abstraction in the service collection with a prepared mock, as done in ClickHouseFacadesTestsCore.MockFacadeAbstraction.

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  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. 
.NET Core netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.1 is compatible. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos 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
2.5.3 75 10/14/2024
2.5.2 91 9/24/2024
2.5.1 94 8/29/2024
2.4.2 92 8/27/2024
2.4.1 73 8/5/2024
2.3.1 91 7/19/2024
2.2.2 87 7/15/2024
2.2.1 97 6/18/2024
2.1.3 103 6/17/2024
2.1.2 103 6/14/2024
2.1.1 89 6/6/2024
2.0.1 100 6/4/2024
1.2.1 108 6/2/2024
1.1.2 110 5/19/2024
1.1.1 77 5/14/2024
1.0.8 109 4/18/2024
1.0.7 107 4/17/2024
1.0.6 114 3/26/2024
1.0.5 108 3/21/2024
1.0.4 116 2/22/2024
1.0.3 117 2/5/2024
1.0.2 244 11/2/2023
1.0.1 128 11/2/2023