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.
tl;dr New extension method to access configuration: configuration.TryGetSection()
tl;dr New exception: ConnectivityException
tl;dr New extension methods to serialize/deserialize from Json: myObject.ToJson()
and myString.FromJson()
tl;dr New string extensions: myString.FirstCharToUpper()
tl;dr Enable unit testing on HTTP calls: HttpRepositoryTestBase
abstract class with BuildHttpClientFactory()
method
tl;dr Get access to a MongoDB database in a few lines by using best practices.
tl;dr Clean channel factory to ease the use of RabbitMQ as well as enabling decoupling through interfaces.
tl;dr New extension method to find an element with a wait: driver.FindElement(By.ClassName("title"), 360);
.
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()
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);
}
# 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
/!\ MongoDB DAL integration tests require a local MongoDB server (through Docker for instance)
dotnet test
This is a fully working example, with Swagger generation, API controllers, completely tested by integration tests.
There are two console projects to publish and consumes messages through RabbitMQ, using Withywoods RabbitMQ library.