This repository was archived by the owner on Dec 13, 2018. It is now read-only.
File tree Expand file tree Collapse file tree 3 files changed +69
-1
lines changed
src/Microsoft.Framework.Logging
test/Microsoft.Framework.Logging.Test Expand file tree Collapse file tree 3 files changed +69
-1
lines changed Original file line number Diff line number Diff line change 1+ // Copyright (c) Microsoft Open Technologies, Inc. All rights reserved.
2+ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
3+
4+ using System ;
5+
6+ namespace Microsoft . Framework . Logging
7+ {
8+ /// <summary>
9+ /// ILoggerFactory extension methods for common scenarios.
10+ /// </summary>
11+ public static class LoggerFactoryExtensions
12+ {
13+ /// <summary>
14+ /// Creates a new ILogger instance using the full name of the given type.
15+ /// </summary>
16+ /// <typeparam name="T">The type.</typeparam>
17+ /// <param name="factory">The factory.</param>
18+ public static ILogger Create < T > ( this ILoggerFactory factory )
19+ {
20+ if ( factory == null )
21+ {
22+ throw new ArgumentNullException ( "factory" ) ;
23+ }
24+
25+ return factory . Create ( typeof ( T ) . FullName ) ;
26+ }
27+ }
28+ }
Original file line number Diff line number Diff line change 1- using System ;
1+ // Copyright (c) Microsoft Open Technologies, Inc. All rights reserved.
2+ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
3+
24using System . Diagnostics ;
35using Xunit ;
46#if NET45
Original file line number Diff line number Diff line change 1+ // Copyright (c) Microsoft Open Technologies, Inc. All rights reserved.
2+ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
3+
4+ #if NET45
5+ using Moq ;
6+ #endif
7+ using Xunit ;
8+
9+ namespace Microsoft . Framework . Logging . Test
10+ {
11+ public class LoggerFactoryExtensionsTest
12+ {
13+ #if NET45
14+ [ Fact ]
15+ public void LoggerFactoryCreateOfT_CallsCreateWithCorrectName ( )
16+ {
17+ // Arrange
18+ var expected = typeof ( TestType ) . FullName ;
19+
20+ var factory = new Mock < ILoggerFactory > ( ) ;
21+ factory . Setup ( f => f . Create (
22+ It . IsAny < string > ( ) ) )
23+ . Returns ( new Mock < ILogger > ( ) . Object ) ;
24+
25+ // Act
26+ factory . Object . Create < TestType > ( ) ;
27+
28+ // Assert
29+ factory . Verify ( f => f . Create ( expected ) ) ;
30+ }
31+ #endif
32+
33+ private class TestType
34+ {
35+ // intentionally holds nothing
36+ }
37+ }
38+ }
You can’t perform that action at this time.
0 commit comments