Skip to content

Commit 53a7f0d

Browse files
authored
Resolve logging challenges. (#2)
Support logging scopes. Correct invalid namespaces.
1 parent 286f2ad commit 53a7f0d

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+368
-165
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,12 @@
22

33
Represents the **NuGet** versions.
44

5+
## v1.0.3
6+
- *Fixed:* `MockHttpClientFactory.CreateClient` overloads were ambiquous, this has been corrected.
7+
- *Fixed:* Resolved logging output challenges between the various test frameworks and `ApiTester` (specifically) to achieve consistent output.
8+
- *Enhancement:* The logging output now includes scope details.
9+
- *Added:* New `MockServiceBus.CreateReceivedMessage` which will mock the `ServiceBusReceivedMessage` and add the passed value as serialized JSON into the `Body` (`BinaryData`).
10+
511
## v1.0.2
612
- *Added:* A new `GenericTestertrigger` has been enabled for non HTTP-triggered functions.
713
- *Added:* Assert capabilities, where applicable, support runtime `Exception` capturing, and have `AssertSuccess` and `AssertException` accordingly. There is a new `VoidAsserter` to ensure success or exception where a function is `void`.

src/UnitTestEx.MSTest/ApiTester.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
// Copyright (c) Avanade. Licensed under the MIT License. See https://github.com/Avanade/UnitTestEx
22

33
using System;
4-
using UnitTestEx.MSUnit.Internal;
4+
using UnitTestEx.MSTest.Internal;
55

6-
namespace UnitTestEx.MSUnit
6+
namespace UnitTestEx.MSTest
77
{
88
/// <summary>
9-
/// Provides the <b>MSUnit</b> API testing capability.
9+
/// Provides the <b>MSTest</b> API testing capability.
1010
/// </summary>
1111
public static class ApiTester
1212
{

src/UnitTestEx.MSTest/FunctionTester.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33
using Microsoft.Azure.Functions.Extensions.DependencyInjection;
44
using System;
55
using System.Collections.Generic;
6-
using UnitTestEx.MSUnit.Internal;
6+
using UnitTestEx.MSTest.Internal;
77

8-
namespace UnitTestEx.MSUnit
8+
namespace UnitTestEx.MSTest
99
{
1010
/// <summary>
1111
/// Provides the <b>MSTest</b> Function testing capability.

src/UnitTestEx.MSTest/Internal/ApiTesterT.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22

33
using UnitTestEx.AspNetCore;
44

5-
namespace UnitTestEx.MSUnit.Internal
5+
namespace UnitTestEx.MSTest.Internal
66
{
77
/// <summary>
8-
/// Provides the <b>MSUnit</b> <see cref="ApiTesterBase{TEntryPoint, TSelf}"/> implementation.
8+
/// Provides the <b>MSTest</b> <see cref="ApiTesterBase{TEntryPoint, TSelf}"/> implementation.
99
/// </summary>
1010
/// <typeparam name="TEntryPoint"></typeparam>
1111
public class ApiTester<TEntryPoint> : ApiTesterBase<TEntryPoint, ApiTester<TEntryPoint>> where TEntryPoint : class

src/UnitTestEx.MSTest/Internal/FunctionTesterT.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
using System.Collections.Generic;
55
using UnitTestEx.Functions;
66

7-
namespace UnitTestEx.MSUnit.Internal
7+
namespace UnitTestEx.MSTest.Internal
88
{
99
/// <summary>
1010
/// Provides the <b>MSTest</b> <see cref="FunctionTesterBase{TEntryPoint, TSelf}"/> implementation.

src/UnitTestEx.MSTest/Internal/MSTestImplementor.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@
44
using Microsoft.VisualStudio.TestTools.UnitTesting;
55
using Microsoft.VisualStudio.TestTools.UnitTesting.Logging;
66

7-
namespace UnitTestEx.MSUnit.Internal
7+
namespace UnitTestEx.MSTest.Internal
88
{
99
/// <summary>
10-
/// Provides the <b>MSUnit</b> <see cref="Abstractions.TestFrameworkImplementor"/> implementation.
10+
/// Provides the <b>MSTest</b> <see cref="Abstractions.TestFrameworkImplementor"/> implementation.
1111
/// </summary>
1212
internal sealed class MSTestImplementor : Abstractions.TestFrameworkImplementor
1313
{

src/UnitTestEx.MSTest/MSTestLogger.cs

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,42 +2,45 @@
22

33
using Microsoft.Extensions.Logging;
44
using Microsoft.VisualStudio.TestTools.UnitTesting.Logging;
5-
using System.Diagnostics;
65
using UnitTestEx.Logging;
76

8-
namespace UnitTestEx.MSUnit
7+
namespace UnitTestEx.MSTest
98
{
109
/// <summary>
1110
/// Represents the <see cref="MSTestLogger"/> provider.
1211
/// </summary>
1312
[ProviderAlias("")]
14-
[DebuggerStepThrough]
15-
public sealed class MSTestLoggerProvider : ILoggerProvider
13+
public sealed class MSTestLoggerProvider : ILoggerProvider, ISupportExternalScope
1614
{
15+
private IExternalScopeProvider? _scopeProvider;
16+
1717
/// <summary>
1818
/// Creates a new instance of the <see cref="MSTestLogger"/>.
1919
/// </summary>
2020
/// <param name="name">The name of the logger.</param>
2121
/// <returns>The <see cref="MSTestLogger"/>.</returns>
22-
public ILogger CreateLogger(string name) => new MSTestLogger(name);
22+
public ILogger CreateLogger(string name) => new MSTestLogger(name, _scopeProvider);
2323

2424
/// <summary>
2525
/// Closes and disposes the <see cref="MSTestLoggerProvider"/>.
2626
/// </summary>
2727
public void Dispose() { }
28+
29+
/// <inheritdoc/>
30+
public void SetScopeProvider(IExternalScopeProvider scopeProvider) => _scopeProvider = scopeProvider;
2831
}
2932

3033
/// <summary>
3134
/// Represents an <b>MSTest</b> <see cref="ILogger"/> that writes to <see cref="Microsoft.Extensions.Logging.Logger"/>.
3235
/// </summary>
33-
[DebuggerStepThrough]
3436
public sealed class MSTestLogger : LoggerBase
3537
{
3638
/// <summary>
3739
/// Initializes a new instance of the <see cref="MSTestLogger"/> class.
3840
/// </summary>
3941
/// <param name="name">The name of the logger.</param>
40-
public MSTestLogger(string name) : base(name) { }
42+
/// <param name="scopeProvider">The <see cref="IExternalScopeProvider"/>.</param>
43+
public MSTestLogger(string name, IExternalScopeProvider? scopeProvider = null) : base(name, scopeProvider) { }
4144

4245
/// <inheritdoc />
4346
protected override void WriteMessage(string message) => Logger.LogMessage("{0}", message);

src/UnitTestEx.MSTest/MockHttpClientFactory.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
// Copyright (c) Avanade. Licensed under the MIT License. See https://github.com/Avanade/UnitTestEx
22

3-
using UnitTestEx.MSUnit.Internal;
3+
using UnitTestEx.MSTest.Internal;
44

5-
namespace UnitTestEx.MSUnit
5+
namespace UnitTestEx.MSTest
66
{
77
/// <summary>
8-
/// Provides the <b>MSUnit</b> <see cref="Mocking.MockHttpClientFactory"/> implementation.
8+
/// Provides the <b>MSTest</b> <see cref="Mocking.MockHttpClientFactory"/> implementation.
99
/// </summary>
1010
public static class MockHttpClientFactory
1111
{

src/UnitTestEx.MSTest/UnitTestEx.MSTest.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<PropertyGroup>
44
<TargetFramework>netcoreapp3.1</TargetFramework>
55
<RootNamespace>UnitTestEx.MSTest</RootNamespace>
6-
<Version>1.0.2</Version>
6+
<Version>1.0.3</Version>
77
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
88
<Authors>UnitTestEx Developers</Authors>
99
<Company>Avanade</Company>

src/UnitTestEx.NUnit/Internal/ApiTesterT.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// Copyright (c) Avanade. Licensed under the MIT License. See https://github.com/Avanade/UnitTestEx
22

33
using UnitTestEx.AspNetCore;
4+
using NFI = NUnit.Framework.Internal;
45

56
namespace UnitTestEx.NUnit.Internal
67
{
@@ -13,6 +14,6 @@ public class ApiTester<TEntryPoint> : ApiTesterBase<TEntryPoint, ApiTester<TEntr
1314
/// <summary>
1415
/// Initializes a new instance of the <see cref="ApiTester{TEntryPoint}"/> class.
1516
/// </summary>
16-
internal ApiTester() : base(new Internal.NUnitTestImplementor()) { }
17+
internal ApiTester() : base(new Internal.NUnitTestImplementor(NFI.TestExecutionContext.CurrentContext)) { }
1718
}
1819
}

0 commit comments

Comments
 (0)