ClickHouse.Facades.Testing 1.0.8

dotnet add package ClickHouse.Facades.Testing --version 1.0.8
NuGet\Install-Package ClickHouse.Facades.Testing -Version 1.0.8
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="1.0.8" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add ClickHouse.Facades.Testing --version 1.0.8
#r "nuget: ClickHouse.Facades.Testing, 1.0.8"
#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=1.0.8

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

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>());
    }
}

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);
}
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
1.0.8 75 4/18/2024
1.0.7 76 4/17/2024
1.0.6 88 3/26/2024
1.0.5 70 3/21/2024
1.0.4 90 2/22/2024
1.0.3 70 2/5/2024
1.0.2 217 11/2/2023
1.0.1 101 11/2/2023