Skip to content
This repository has been archived by the owner on Jul 5, 2024. It is now read-only.

Commit

Permalink
Clean up some compiler warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
caesay committed Nov 4, 2023
1 parent d0dc16f commit f3d80d3
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 32 deletions.
38 changes: 19 additions & 19 deletions src/Update.Windows/Logging.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
using System;
using System.IO;
using NLog;
using NLog.Config;
using NLog.Targets;
using Squirrel.SimpleSplat;
using LogLevel = Squirrel.SimpleSplat.LogLevel;
using ILogger = Squirrel.SimpleSplat.ILogger;

namespace Squirrel.Update
{
Expand All @@ -11,7 +14,7 @@ class SetupLogLogger : ILogger
public LogLevel Level { get; set; } = LogLevel.Info;

public string LogFilePath { get; }

private readonly NLog.Logger _log;

public SetupLogLogger(UpdateAction action)
Expand All @@ -24,30 +27,27 @@ public SetupLogLogger(UpdateAction action)
action == UpdateAction.Setup ||
action == UpdateAction.Install;

var logDirectory = logToTemp
? Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData)
var logDirectory = logToTemp
? Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData)
: SquirrelRuntimeInfo.BaseDirectory;
var logName = logToTemp ? "Squirrel.log" : $"Squirrel-{action}.log";
var logArchiveName = logToTemp ? "Squirrel.{###}.log" : $"Squirrel-{action}.{{###}}.log";

LogFilePath = Path.Combine(logDirectory, logName);

// https://gist.github.com/chrisortman/1092889
SimpleConfigurator.ConfigureForTargetLogging(
new FileTarget() {
FileName = LogFilePath,
Layout = new NLog.Layouts.SimpleLayout("${longdate} [${level:uppercase=true}] - ${message}"),
ArchiveFileName = Path.Combine(logDirectory, logArchiveName),
ArchiveAboveSize = 1_000_000,
ArchiveNumbering = ArchiveNumberingMode.Sequence,
ConcurrentWrites = true, // should allow multiple processes to use the same file
KeepFileOpen = true,
MaxArchiveFiles = 1 ,
},
NLog.LogLevel.Debug
);

_log = NLog.LogManager.GetLogger("SetupLogLogger");
var fileTarget = new FileTarget() {
FileName = LogFilePath,
Layout = new NLog.Layouts.SimpleLayout("${longdate} [${level:uppercase=true}] - ${message}"),
ArchiveFileName = Path.Combine(logDirectory, logArchiveName),
ArchiveAboveSize = 1_000_000,
ArchiveNumbering = ArchiveNumberingMode.Sequence,
ConcurrentWrites = true, // should allow multiple processes to use the same file
KeepFileOpen = true,
MaxArchiveFiles = 1,
};

LogManager.Setup().LoadConfiguration(c => c.ForLogger(NLog.LogLevel.Debug).WriteTo(fileTarget));
_log = LogManager.GetLogger("SetupLogLogger");
}

public void Write(string message, LogLevel logLevel)
Expand Down
6 changes: 3 additions & 3 deletions test/Squirrel.Tests/CheckForUpdateTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public class CheckForUpdateTests
[Fact(Skip = "Rewrite this to be an integration test")]
public void NewReleasesShouldBeDetected()
{
Assert.False(true, "Rewrite this to be an integration test");
Assert.Fail("Rewrite this to be an integration test");
/*
string localReleasesFile = Path.Combine(".", "theApp", "packages", "RELEASES");
Expand Down Expand Up @@ -46,7 +46,7 @@ public void NewReleasesShouldBeDetected()
[Fact(Skip = "Rewrite this to be an integration test")]
public void CorruptedReleaseFileMeansWeStartFromScratch()
{
Assert.False(true, "Rewrite this to be an integration test");
Assert.Fail("Rewrite this to be an integration test");

/*
string localPackagesDir = Path.Combine(".", "theApp", "packages");
Expand Down Expand Up @@ -84,7 +84,7 @@ public void CorruptedReleaseFileMeansWeStartFromScratch()
[Fact(Skip = "Rewrite this to be an integration test")]
public void CorruptRemoteFileShouldThrowOnCheck()
{
Assert.False(true, "Rewrite this to be an integration test");
Assert.Fail("Rewrite this to be an integration test");

/*
string localPackagesDir = Path.Combine(".", "theApp", "packages");
Expand Down
2 changes: 1 addition & 1 deletion test/Squirrel.Tests/DeltaPackageTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ public void ApplyMultipleDeltasFast()
[Fact(Skip = "Rewrite this test, the original uses too many heavyweight fixtures")]
public void ApplyMultipleDeltaPackagesGeneratesCorrectHash()
{
Assert.True(false, "Rewrite this test, the original uses too many heavyweight fixtures");
Assert.Fail("Rewrite this test, the original uses too many heavyweight fixtures");
}
}

Expand Down
8 changes: 4 additions & 4 deletions test/Squirrel.Tests/DownloadReleasesTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public class DownloadReleasesTests
[Fact(Skip = "Rewrite this to be an integration test")]
public void ChecksumShouldFailIfFilesAreMissing()
{
Assert.False(true, "Rewrite this to be an integration test");
Assert.Fail("Rewrite this to be an integration test");

/*
var filename = "Squirrel.Core.1.0.0.0.nupkg";
Expand Down Expand Up @@ -54,7 +54,7 @@ public void ChecksumShouldFailIfFilesAreMissing()
[Fact(Skip = "Rewrite this to be an integration test")]
public void ChecksumShouldFailIfFilesAreBogus()
{
Assert.False(true, "Rewrite this to be an integration test");
Assert.Fail("Rewrite this to be an integration test");

/*
var filename = "Squirrel.Core.1.0.0.0.nupkg";
Expand Down Expand Up @@ -94,7 +94,7 @@ public void ChecksumShouldFailIfFilesAreBogus()
[Fact(Skip = "Rewrite this to be an integration test")]
public async Task DownloadReleasesFromHttpServerIntegrationTest()
{
Assert.False(true, "Rewrite this to not use the SampleUpdatingApp");
Assert.Fail("Rewrite this to not use the SampleUpdatingApp");

/*
string tempDir = null;
Expand Down Expand Up @@ -148,7 +148,7 @@ public async Task DownloadReleasesFromHttpServerIntegrationTest()
[Fact(Skip = "Rewrite this to be an integration test")]
public async Task DownloadReleasesFromFileDirectoryIntegrationTest()
{
Assert.False(true, "Rewrite this to not use the SampleUpdatingApp");
Assert.Fail("Rewrite this to not use the SampleUpdatingApp");

/*
string tempDir = null;
Expand Down
7 changes: 4 additions & 3 deletions test/Squirrel.Tests/RuntimeTests.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Net.Http;
using System.Threading.Tasks;
using Xunit;

namespace Squirrel.Tests
Expand Down Expand Up @@ -87,10 +88,10 @@ public void GetRuntimeTests(string input, bool expected)
[InlineData("7.0", RuntimeCpu.x64, Runtimes.DotnetRuntimeType.WindowsDesktop)]
[InlineData("7.0", RuntimeCpu.x64, Runtimes.DotnetRuntimeType.Runtime)]
[InlineData("7.0", RuntimeCpu.x64, Runtimes.DotnetRuntimeType.AspNetCore)]
public void MicrosoftReturnsValidDotnetDownload(string minversion, RuntimeCpu architecture, Runtimes.DotnetRuntimeType runtimeType)
public async Task MicrosoftReturnsValidDotnetDownload(string minversion, RuntimeCpu architecture, Runtimes.DotnetRuntimeType runtimeType)
{
var dni = new Runtimes.DotnetInfo(minversion, architecture, runtimeType);
var url = dni.GetDownloadUrl().Result;
var url = await dni.GetDownloadUrl();

Assert.Contains(minversion, url, StringComparison.OrdinalIgnoreCase);
Assert.Contains(architecture.ToString(), url, StringComparison.OrdinalIgnoreCase);
Expand All @@ -103,7 +104,7 @@ public void MicrosoftReturnsValidDotnetDownload(string minversion, RuntimeCpu ar
Assert.Matches(@"/windowsdesktop-runtime-\d", url);

using var hc = new HttpClient();
var result = hc.GetAsync(url, HttpCompletionOption.ResponseHeadersRead).Result;
var result = await hc.GetAsync(url, HttpCompletionOption.ResponseHeadersRead);
result.EnsureSuccessStatusCode();
}
}
Expand Down
5 changes: 3 additions & 2 deletions test/Squirrel.Tests/UtilityTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
using Squirrel.Shell;
using System.Collections.Generic;
using Xunit.Abstractions;
using System.Threading.Tasks;

namespace Squirrel.Tests
{
Expand Down Expand Up @@ -184,7 +185,7 @@ public void WeCanFetchAllProcesses()
}

[Fact(Skip = "Only really need to run this test after changes to FileDownloader")]
public void DownloaderReportsProgress()
public async Task DownloaderReportsProgress()
{
// this probably should use a local http server instead.
const string testUrl = "http://speedtest.tele2.net/1MB.zip";
Expand All @@ -193,7 +194,7 @@ public void DownloaderReportsProgress()

List<int> prog = new List<int>();
using (Utility.GetTempFileName(out var tempPath))
dl.DownloadFile(testUrl, tempPath, prog.Add).Wait();
await dl.DownloadFile(testUrl, tempPath, prog.Add);

Assert.True(prog.Count > 10);
Assert.Equal(100, prog.Last());
Expand Down

0 comments on commit f3d80d3

Please sign in to comment.