Skip to content
This repository was archived by the owner on Apr 8, 2023. It is now read-only.

Commit 7904cd7

Browse files
authored
Merge pull request #3 from Umplify/resolve-commit-issue-142
Merging the head repository's changes
2 parents 11c15a4 + a46078d commit 7904cd7

File tree

3 files changed

+16
-5
lines changed

3 files changed

+16
-5
lines changed

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@
44
[![Xunit.Microsoft.DependencyInjection on fuget.org](https://www.fuget.org/packages/Xunit.Microsoft.DependencyInjection/badge.svg)](https://www.fuget.org/packages/Xunit.Microsoft.DependencyInjection)
55

66
# Xunit Dependency Injection framework
7+
8+
*(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.)*
9+
10+
---
11+
712
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.
813

914
This library brings in Microsoft's dependency injection container to Xunit by leveraging Xunit's fixture.
Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,20 @@
1-
using Microsoft.Extensions.Options;
1+
using Microsoft.Extensions.Logging;
2+
using Microsoft.Extensions.Options;
23

34
namespace Xunit.Microsoft.DependencyInjection.ExampleTests.Services;
45

56
public class Calculator : ICalculator
67
{
78
private readonly Options _option;
9+
private readonly ILogger<Calculator> _logger;
810

9-
public Calculator(IOptions<Options> option)
10-
=> _option = option.Value;
11+
public Calculator(ILogger<Calculator> logger, IOptions<Options> option)
12+
=> (_logger, _option) = (logger, option.Value);
1113

1214
public int Add(int x, int y)
13-
=> (x + y) * _option.Rate;
15+
{
16+
var result = (x + y) * _option.Rate;
17+
_logger.LogInformation("The result is {@Result}", result);
18+
return result;
19+
}
1420
}

src/Logging/OutputLogger.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public void Log<TState>(LogLevel logLevel, EventId eventId, TState state, Except
3030
}
3131
else
3232
{
33-
_testOutputHelper.WriteLine($"{logLevel} - Category: {_categoryName} : {DateTime.Now}");
33+
_testOutputHelper.WriteLine($"{logLevel} - Category: {_categoryName} : {state} :: {DateTime.Now}");
3434
}
3535
}
3636
}

0 commit comments

Comments
 (0)