Squadron

Squadron

  • Docs
  • Blog
  • GitHub

›Container Providers

Introduction

  • Introduction
  • Quickstart
  • Basic Concept
  • Container Options
  • Configuration
  • Multiple resources

Container Providers

  • MongoDB
  • MongoDB Replica Set
  • SQL Server
  • Elasticsearch
  • PostgreSQL
  • Redis
  • RabbitMQ
  • Azure Storage
  • Generic
  • Compose

Azure Cloud Providers

  • Setup
  • ServiceBus
Edit

SQL Server

Install

Install the Squadron nuget package for SqlServer within your test project:

dotnet add package Squadron.SqlServer

Access

Inject SqlServerResource into your test class constructor:

public class AccountRepositoryTests
    : IClassFixture<SqlServerResource>
{
    private readonly SqlServerResource _sqlServerResource;

    public AccountRepositoryTests(
        SqlServerResource sqlServerResource)
    {
        _sqlServerResource = sqlServerResource;
    }
}

Use

Use SqlServerResource to create a database and initialize your repository:

[Fact]
public async Task CreateAccount_AccountExists()
{
    // arrange
    string sqlFile = Path.Combine("Resources", "CreateEmpty.sql");
    string databaseName = "Accounts";
    var connectionString = await _sqlServerResource.CreateDatabaseAsync(File.ReadAllText(sqlFile), databaseName);
    var accountRepository = new AccountRepository(connectionString);
    var account = new Account();

    // act
    var addedAccount = accountRepository.Add(account);

    // assert
    Snapshot.Match(addedAccount);
}
Last updated on 10/29/2019 by Lucien Zimmermann
← MongoDB Replica SetElasticsearch →
  • Install
  • Access
  • Use

Community

Contributor License AgreementsCode of Conduct
Swiss Life OSSSwiss Life | OSS
Copyright © 2021 Swiss Life Developers