Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix ReSharper/Rider inspection warnings #312

Merged
merged 1 commit into from
May 11, 2022
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
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Text.RegularExpressions;

using Microsoft.Extensions.Configuration;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,12 +88,12 @@ bool TryCreateContainer(out object result)

var configurationElements = _section.GetChildren().ToArray();
result = Activator.CreateInstance(toType);

for (int i = 0; i < configurationElements.Length; ++i)
{
var argumentValue = ConfigurationReader.GetArgumentValue(configurationElements[i], _configurationAssemblies);
var value = argumentValue.ConvertTo(elementType, resolutionContext);
addMethod.Invoke(result, new object[] { value });
addMethod.Invoke(result, new[] { value });
}

return true;
Expand Down Expand Up @@ -164,7 +164,7 @@ where gr.All(z => z.argumentBindResult.success)
{
return false;
}

var ctorArguments = new List<Expression>();
foreach (var argumentValue in ctor.ArgumentValues)
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,39 +1,20 @@
using System;
#if PRIVATE_BIN
using System;
using System.IO;
#endif

using Xunit;

using Serilog.Settings.Configuration.Assemblies;

namespace Serilog.Settings.Configuration.Tests
{
public class DllScanningAssemblyFinderTests : IDisposable
public class DllScanningAssemblyFinderTests
{
const string BinDir1 = "bin1";
const string BinDir2 = "bin2";
const string BinDir3 = "bin3";

readonly string _privateBinPath;

public DllScanningAssemblyFinderTests()
{
var d1 = GetOrCreateDirectory(BinDir1);
var d2 = GetOrCreateDirectory(BinDir2);
var d3 = GetOrCreateDirectory(BinDir3);

_privateBinPath = $"{d1.Name};{d2.FullName};{d3.Name}";

DirectoryInfo GetOrCreateDirectory(string name)
=> Directory.Exists(name) ? new DirectoryInfo(name) : Directory.CreateDirectory(name);
}

public void Dispose()
{
Directory.Delete(BinDir1, true);
Directory.Delete(BinDir2, true);
Directory.Delete(BinDir3, true);
}

[Fact]
public void ShouldProbeCurrentDirectory()
{
Expand All @@ -45,6 +26,13 @@ public void ShouldProbeCurrentDirectory()
[Fact]
public void ShouldProbePrivateBinPath()
{
var d1 = GetOrCreateDirectory(BinDir1);
var d2 = GetOrCreateDirectory(BinDir2);
var d3 = GetOrCreateDirectory(BinDir3);

DirectoryInfo GetOrCreateDirectory(string name)
=> Directory.Exists(name) ? new DirectoryInfo(name) : Directory.CreateDirectory(name);

File.Copy("testdummies.dll", $"{BinDir1}/customSink1.dll", true);
File.Copy("testdummies.dll", $"{BinDir2}/customSink2.dll", true);
File.Copy("testdummies.dll", $"{BinDir3}/thirdpartydependency.dll", true);
Expand All @@ -53,7 +41,7 @@ public void ShouldProbePrivateBinPath()
new AppDomainSetup
{
ApplicationBase = AppDomain.CurrentDomain.BaseDirectory,
PrivateBinPath = _privateBinPath
PrivateBinPath = $"{d1.Name};{d2.FullName};{d3.Name}"
});

try
Expand All @@ -63,6 +51,9 @@ public void ShouldProbePrivateBinPath()
finally
{
AppDomain.Unload(ad);
Directory.Delete(BinDir1, true);
Directory.Delete(BinDir2, true);
Directory.Delete(BinDir3, true);
}

static void DoTestInner()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public void ReadFromConfigurationSectionReadsFromAnArbitrarySection()
LogEvent evt = null;

var json = @"{
""NotSerilog"": {
""NotSerilog"": {
""Properties"": {
""App"": ""Test""
}
Expand Down Expand Up @@ -53,12 +53,12 @@ public void ReadFromConfigurationSectionReadsFromAnArbitrarySection()
public void ReadFromConfigurationSectionThrowsWhenTryingToCallConfigurationMethodWithIConfigurationParam()
{
var json = @"{
""NotSerilog"": {
""NotSerilog"": {
""Using"": [""TestDummies""],
""WriteTo"": [{
""Name"": ""DummyWithConfiguration"",
""Args"": {}
}]
}]
}
}";

Expand All @@ -84,20 +84,20 @@ public void ReadFromConfigurationSectionThrowsWhenTryingToCallConfigurationMetho
public void ReadFromConfigurationDoesNotThrowWhenTryingToCallConfigurationMethodWithIConfigurationParam()
{
var json = @"{
""NotSerilog"": {
""NotSerilog"": {
""Using"": [""TestDummies""],
""WriteTo"": [{
""Name"": ""DummyWithConfiguration"",
""Args"": {}
}]
}]
}
}";

var config = new ConfigurationBuilder()
.AddJsonString(json)
.Build();

var exception = new LoggerConfiguration()
_ = new LoggerConfiguration()
.ReadFrom.Configuration(config, "NotSerilog")
.CreateLogger();

Expand All @@ -108,12 +108,12 @@ public void ReadFromConfigurationDoesNotThrowWhenTryingToCallConfigurationMethod
public void ReadFromConfigurationSectionDoesNotThrowWhenTryingToCallConfigurationMethodWithOptionalIConfigurationParam()
{
var json = @"{
""NotSerilog"": {
""NotSerilog"": {
""Using"": [""TestDummies""],
""WriteTo"": [{
""Name"": ""DummyWithOptionalConfiguration"",
""Args"": {}
}]
}]
}
}";

Expand Down
4 changes: 0 additions & 4 deletions test/TestDummies/DummyThreadIdEnricher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,6 @@ namespace TestDummies
{
public class DummyThreadIdEnricher : ILogEventEnricher
{
static DummyThreadIdEnricher()
{
}

public void Enrich(LogEvent logEvent, ILogEventPropertyFactory propertyFactory)
{
logEvent.AddPropertyIfAbsent(propertyFactory
Expand Down