Skip to content
This repository was archived by the owner on Apr 8, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@
[![Xunit.Microsoft.DependencyInjection on fuget.org](https://www.fuget.org/packages/Xunit.Microsoft.DependencyInjection/badge.svg)](https://www.fuget.org/packages/Xunit.Microsoft.DependencyInjection)

# Xunit Dependency Injection framework

*(The source code of the .NET 7.0 version of this library is retained in [the fork of this repo](https://github.com/Umplify/xunit-dependency-injection-NET7) while the .NET 6.0 version of this library is maintained and supported in this repo.)*

---

Xunit does not support any built-in dependency injection features, therefore developers have to come up with a solution to recruit their favourite dependency injection framework in their tests.

This library brings in Microsoft's dependency injection container to Xunit by leveraging Xunit's fixture.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,20 @@
using Microsoft.Extensions.Options;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;

namespace Xunit.Microsoft.DependencyInjection.ExampleTests.Services;

public class Calculator : ICalculator
{
private readonly Options _option;
private readonly ILogger<Calculator> _logger;

public Calculator(IOptions<Options> option)
=> _option = option.Value;
public Calculator(ILogger<Calculator> logger, IOptions<Options> option)
=> (_logger, _option) = (logger, option.Value);

public int Add(int x, int y)
=> (x + y) * _option.Rate;
{
var result = (x + y) * _option.Rate;
_logger.LogInformation("The result is {@Result}", result);
return result;
}
}
2 changes: 1 addition & 1 deletion src/Logging/OutputLogger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public void Log<TState>(LogLevel logLevel, EventId eventId, TState state, Except
}
else
{
_testOutputHelper.WriteLine($"{logLevel} - Category: {_categoryName} : {DateTime.Now}");
_testOutputHelper.WriteLine($"{logLevel} - Category: {_categoryName} : {state} :: {DateTime.Now}");
}
}
}