Skip to content

devpro/withywoods

Repository files navigation

Devpro Withywoods - Shared .NET libraries

Build Status Quality Gate Status Coverage

Whithywoods is a set of small independant .NET libraries (Standard/Core). The goal is to do better with less code and capitalize on best practices (#KISS #DRY).

All libraries are available on nuget.org. Feel free to report any issue or ask for a change. You can also contribute with Pull Requests on GitHub!

NB: The name Whithywoods comes from Robin Hobb's incredible writing.

How to use

Common / Configuration library

Version Downloads

tl;dr New extension method to access configuration: configuration.TryGetSection()

More information

Common / Net HTTP library

Version Downloads

tl;dr New exception: ConnectivityException

More information

Common / Serialization library

Version Downloads

tl;dr New extension methods to serialize/deserialize from Json: myObject.ToJson() and myString.FromJson()

More information

Common / System library

Version Downloads

tl;dr New string extensions: myString.FirstCharToUpper()

More information

Common / Unit testing

Version Downloads

tl;dr Enable unit testing on HTTP calls: HttpRepositoryTestBase abstract class with BuildHttpClientFactory() method

More information

Data Access / MongoDB library

Version Downloads

tl;dr Get access to a MongoDB database in a few lines by using best practices.

More information

Message Broker / RabbitMQ library

Version Downloads

tl;dr Clean channel factory to ease the use of RabbitMQ as well as enabling decoupling through interfaces.

More information

Web / Selenium library

Version Downloads

tl;dr New extension method to find an element with a wait: driver.FindElement(By.ClassName("title"), 360);.

More information

Web / Web Application library

Version Downloads

tl;dr Easily add Swagger self-generated web page, only two lines in your Startup class!

services.AddSwaggerGen(_webAppConfiguration); // in ConfigureServices()

app.UseSwagger(_webAppConfiguration); // in Configure()

More information

Web / Web Testing library

Version Downloads

tl;dr Use Selenium web driver inside ASP.NET Integration tests? Yes, that's possible with LocalServerFactory class!

public class SwaggerResourceTest : IClassFixture<LocalServerFactory<Startup>>, IDisposable
{
    [Fact]
    public void AspNetCoreApiSampleSwaggerResourceGet_ReturnsHttpOk()
    {
        // Arrange & Act
        _webDriver.Navigate().GoToUrl($"{_server.RootUri}/{_ResourceEndpoint}");

        // Assert
        _webDriver.FindElement(By.ClassName("title"), 360);
        _webDriver.Title.Should().Be("Swagger UI");
        _webDriver.FindElementByClassName("title").Text.Should().Contain("My API");
    }
}

Want to write easy API Rest tests? Sure, just use the TestRunner class!

[Fact]
public async Task AspNetCoreApiSampleTaskResourceFullCycle_IsOk()
{
    var initialTasks = await _restRunner.GetResources<TaskDto>(_client);
    initialTasks.Count.Should().Be(0);

    var created = await _restRunner.CreateResource<TaskDto>(_client);

    await _restRunner.GetResourceById(created.Id, _client, created);

    await _restRunner.UpdateResource(created.Id, created, _client);

    var existingTasks = await _restRunner.GetResources<TaskDto>(_client);
    existingTasks.Count.Should().Be(1);

    await _restRunner.DeleteResource(created.Id, _client);

    var expectedNotFound = new ProblemDetails
    {
        Title = "Not Found",
        Status = 404,
        Type = "https://tools.ietf.org/html/rfc7231#section-6.5.4"
    };
    await _restRunner.GetResourceById(created.Id, _client, expectedNotFound, HttpStatusCode.NotFound, config => config.Excluding(x => x.Extensions));

    var finalTasks = await _restRunner.GetResources<TaskDto>(_client);
    finalTasks.Count.Should().Be(0);
}

More information

How to build

# check .NET Core SDK is installed (download from https://dotnet.microsoft.com/download)
dotnet --version

# restore NuGet packages
dotnet restore

# build the solution
dotnet build

How to test

/!\ MongoDB DAL integration tests require a local MongoDB server (through Docker for instance)

dotnet test

Samples

AspNetCoreApiSample

This is a fully working example, with Swagger generation, API controllers, completely tested by integration tests.

RabbitMQ

There are two console projects to publish and consumes messages through RabbitMQ, using Withywoods RabbitMQ library.