Skip to content

Commit

Permalink
housekeeping: fix unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
glennawatson committed Oct 13, 2020
1 parent 83f065f commit ea7dec3
Show file tree
Hide file tree
Showing 8 changed files with 37 additions and 17 deletions.
5 changes: 4 additions & 1 deletion src/Splat.TestRunner.Uwp/Splat.TestRunner.Uwp.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,10 @@
<Content Include="Assets\Wide310x150Logo.scale-200.png" />
</ItemGroup>
<ItemGroup>
<Compile Include="..\Splat.Tests\**\*.cs" LinkBase="..\Splat.Tests" Exclude="**\*AssemblyInfo.cs;**/obj/**/*" />
<Compile Include="..\Splat.Tests\**\*.cs" LinkBase="..\Splat.Tests" Exclude="**\Log4NetLoggerTests.cs;**\*AssemblyInfo.cs;**/obj/**/*" />
<EmbeddedResource Include="..\Splat.Tests\*.jpg" />
<EmbeddedResource Include="..\Splat.Tests\*.png" />
<EmbeddedResource Include="..\Splat.Tests\*.bmp" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.NETCore.UniversalWindowsPlatform">
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
[assembly: System.Runtime.CompilerServices.InternalsVisibleTo("Splat.TestRunner.Android")]
[assembly: System.Runtime.CompilerServices.InternalsVisibleTo("Splat.TestRunner.Uwp")]
[assembly: System.Runtime.CompilerServices.InternalsVisibleTo("Splat.Tests")]
[assembly: System.Runtime.Versioning.TargetFramework(".NETFramework,Version=v4.6.1", FrameworkDisplayName=".NET Framework 4.6.1")]
namespace Splat
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
[assembly: System.Runtime.CompilerServices.InternalsVisibleTo("Splat.TestRunner.Android")]
[assembly: System.Runtime.CompilerServices.InternalsVisibleTo("Splat.TestRunner.Uwp")]
[assembly: System.Runtime.CompilerServices.InternalsVisibleTo("Splat.Tests")]
[assembly: System.Runtime.Versioning.TargetFramework(".NETStandard,Version=v2.0", FrameworkDisplayName="")]
namespace Splat
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
[assembly: System.Resources.NeutralResourcesLanguage("en-US")]
[assembly: System.Runtime.CompilerServices.InternalsVisibleTo("Splat.TestRunner.Android")]
[assembly: System.Runtime.CompilerServices.InternalsVisibleTo("Splat.TestRunner.Uwp")]
[assembly: System.Runtime.CompilerServices.InternalsVisibleTo("Splat.Tests")]
[assembly: System.Runtime.Versioning.TargetFramework(".NETFramework,Version=v4.6.1", FrameworkDisplayName=".NET Framework 4.6.1")]
namespace Splat
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
[assembly: System.Resources.NeutralResourcesLanguage("en-US")]
[assembly: System.Runtime.CompilerServices.InternalsVisibleTo("Splat.TestRunner.Android")]
[assembly: System.Runtime.CompilerServices.InternalsVisibleTo("Splat.TestRunner.Uwp")]
[assembly: System.Runtime.CompilerServices.InternalsVisibleTo("Splat.Tests")]
[assembly: System.Runtime.Versioning.TargetFramework(".NETCoreApp,Version=v3.1", FrameworkDisplayName="")]
namespace Splat
Expand Down
6 changes: 3 additions & 3 deletions src/Splat.Tests/BitmapLoaderTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Reflection;
using System.Text;
using Xunit;

Expand Down Expand Up @@ -98,9 +99,8 @@ private static Stream GetStream(string imageName)
#if ANDROID
return Android.App.Application.Context.Assets.Open(imageName);
#else
var cwd = Path.GetDirectoryName(typeof(BitmapLoaderTests).Assembly.Location);
var path = Path.Combine(cwd, imageName);
return File.OpenRead(path);
var assembly = Assembly.GetExecutingAssembly();
return assembly.GetManifestResourceStream(imageName);
#endif
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -530,7 +530,7 @@ public void WarnExceptionThreeArgumentsMethod_Should_Not_Write_If_Higher_Level()
public void WarnExceptionFourArgumentsMethod_Should_Write_Message()
{
var (logger, target) = GetLogger(LogLevel.Debug);
logger.Info(FormatHelper.Exception, "{0}, {1}, {2}, {3}", 1, 2, 3, 4);
logger.Warn(FormatHelper.Exception, "{0}, {1}, {2}, {3}", 1, 2, 3, 4);
Assert.Equal("1, 2, 3, 4 System.Exception: Exception of type 'System.Exception' was thrown.", target.Logs.Last().message.Trim(FormatHelper.NewLine).Trim());
}

Expand All @@ -541,7 +541,7 @@ public void WarnExceptionFourArgumentsMethod_Should_Write_Message()
public void WarnExceptionFourArgumentsMethod_Should_Not_Write_If_Higher_Level()
{
var (logger, target) = GetLogger(LogLevel.Fatal);
logger.Info(FormatHelper.Exception, "{0}, {1}, {2}, {3}", 1, 2, 3, 4);
logger.Warn(FormatHelper.Exception, "{0}, {1}, {2}, {3}", 1, 2, 3, 4);
Assert.Empty(target.Logs);
}

Expand Down Expand Up @@ -574,7 +574,7 @@ public void WarnExceptionFiveArgumentsMethod_Should_Not_Write_If_Higher_Level()
public void WarnExceptionSixArgumentsMethod_Should_Write_Message()
{
var (logger, target) = GetLogger(LogLevel.Debug);
logger.Info(FormatHelper.Exception, "{0}, {1}, {2}, {3}, {4}, {5}", 1, 2, 3, 4, 5, 6);
logger.Warn(FormatHelper.Exception, "{0}, {1}, {2}, {3}, {4}, {5}", 1, 2, 3, 4, 5, 6);
Assert.Equal("1, 2, 3, 4, 5, 6 System.Exception: Exception of type 'System.Exception' was thrown.", target.Logs.Last().message.Trim(FormatHelper.NewLine).Trim());
}

Expand All @@ -585,7 +585,7 @@ public void WarnExceptionSixArgumentsMethod_Should_Write_Message()
public void WarnExceptionSixArgumentsMethod_Should_Not_Write_If_Higher_Level()
{
var (logger, target) = GetLogger(LogLevel.Fatal);
logger.Info(FormatHelper.Exception, "{0}, {1}, {2}, {3}, {4}, {5}", 1, 2, 3, 4, 5, 6);
logger.Warn(FormatHelper.Exception, "{0}, {1}, {2}, {3}, {4}, {5}", 1, 2, 3, 4, 5, 6);
Assert.Empty(target.Logs);
}

Expand Down
27 changes: 18 additions & 9 deletions src/Splat.Tests/Logging/WrappingFullLoggers/Log4NetLoggerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,12 @@
using System.Collections.Generic;
using System.Linq;
using System.Reflection;

using log4net;
using log4net.Core;
using log4net.Layout;
using log4net.Repository.Hierarchy;

using Splat.Log4Net;
using Splat.Tests.Mocks;

Expand Down Expand Up @@ -43,7 +45,7 @@ public class Log4NetLoggerTests : FullLoggerTestBase
/// <inheritdoc/>
protected override (IFullLogger logger, IMockLogTarget mockTarget) GetLogger(LogLevel minimumLogLevel)
{
var logger = LogManager.GetLogger(typeof(Log4NetLoggerTests));
var logger = LogManager.GetLogger(Guid.NewGuid().ToString());

var hierarchyLogger = (log4net.Repository.Hierarchy.Logger)logger.Logger;
hierarchyLogger.Level = _splat2log4net[minimumLogLevel];
Expand Down Expand Up @@ -90,17 +92,24 @@ public MemoryTargetWrapper(global::log4net.Appender.MemoryAppender memoryTarget)

public global::log4net.Appender.MemoryAppender MemoryTarget { get; }

public ICollection<(LogLevel logLevel, string message)> Logs => MemoryTarget.GetEvents().Select(x =>
public ICollection<(LogLevel logLevel, string message)> Logs
{
var currentLevel = _log4Net2Splat[x.Level];

if (x.ExceptionObject != null)
get
{
return (currentLevel, $"{x.MessageObject} {x.ExceptionObject}");
MemoryTarget.Flush(0);
return MemoryTarget.GetEvents().Select(x =>
{
var currentLevel = _log4Net2Splat[x.Level];

if (x.ExceptionObject != null)
{
return (currentLevel, $"{x.MessageObject} {x.ExceptionObject}");
}

return (currentLevel, x.MessageObject.ToString());
}).ToList();
}

return (currentLevel, x.MessageObject.ToString());
}).ToList();
}
}
}
}

0 comments on commit ea7dec3

Please sign in to comment.