Skip to content

Commit

Permalink
Address CodeQL warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
m-ringler committed Nov 9, 2023
1 parent 98531d4 commit 34cdbdf
Show file tree
Hide file tree
Showing 12 changed files with 19 additions and 27 deletions.
7 changes: 2 additions & 5 deletions czishrink/netczicompressTests/Models/CompressionLevelTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,7 @@ public void DefaultConstructor_HasDefaultValue()
[InlineData(230)]
public void OutOfRange_ShouldThrowOutOfRangeException(int value)
{
var act = () =>
{
var sut = new CompressionLevel() { Value = value };
};
var act = () => _ = new CompressionLevel { Value = value };

act.Should().Throw<ArgumentOutOfRangeException>();
}
Expand All @@ -37,7 +34,7 @@ public void OutOfRange_ShouldThrowOutOfRangeException(int value)
[InlineData(0)]
public void InRangeValue_ShouldBeEqual(int value)
{
var sut = new CompressionLevel() { Value = value };
var sut = new CompressionLevel { Value = value };
sut.Value.Should().Be(value);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,6 @@ public void CompressWithLevel_FilesHaveCorrectSize(

var compressedSize = GetLength(compressed);
var decompressedSize = GetLength(uncompressed);
var originalSize = GetLength(testFile);

// ASSERT
compressedSize.Should().Be(expectedCompressedSize);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public void ObserveRun_WhenRunCompletes_CorrectFirstAndFinalResult(int scanTimeM
new(fileMock, 10, 1000, null, "Failed"),
};

var observable = new Subject<FileFinished>();
using var observable = new Subject<FileFinished>();
var watch = Stopwatch.StartNew();

var sut = new StatisticsRunObserver(
Expand Down
5 changes: 1 addition & 4 deletions czishrink/netczicompressTests/Models/ThreadCountTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,7 @@ public void DefaultConstructor_HasDefaultValue()
[InlineData(230)]
public void OutOfRange_ShouldThrowOutOfRangeException(int value)
{
var act = () =>
{
var sut = new ThreadCount() { Value = value };
};
var act = () => _ = new ThreadCount { Value = value };

act.Should().Throw<ArgumentOutOfRangeException>();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public void PublicProperties_WhenGot_HaveExpectedValues()
{
// ARRANGE
var fileName = CreateFixture().Create<string>();
var progress = new BehaviorSubject<int>(0);
using var progress = new BehaviorSubject<int>(0);
var sut = new CompressionTaskViewModel(
fileName,
progress);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ public void OnNext_WhenTaskFinished_DoesNotAddTaskToList()
// ARRANGE
var sut = new CurrentTasksViewModel(ImmediateScheduler.Instance);

var message = new FileStarting(Mock.Of<IFileInfo>(), new BehaviorSubject<int>(100));
using var progress = new BehaviorSubject<int>(100);
var message = new FileStarting(Mock.Of<IFileInfo>(), progress);

// ACT
sut.OnNext(message);
Expand Down Expand Up @@ -93,7 +94,7 @@ public void WhenTaskCompletes_TaskIsRemovedFromListOnGuiScheduler()
var sut = new CurrentTasksViewModel(guiScheduler);

sut.OnNextAll(CreateFixture().CreateMany<FileStarting>(5));
var progress = new BehaviorSubject<int>(0);
using var progress = new BehaviorSubject<int>(0);
var completingTask = new FileStarting(
Mock.Of<IFileInfo>(f => f.FullName == "Foo_Bar_Baz"),
progress);
Expand All @@ -116,7 +117,7 @@ public void WhenTaskCompletes_TaskIsRemovedFromListOnGuiScheduler()
beforeSchedulerRun.SequenceEqual(initialTasks).Should().BeTrue();

afterSchedulerRun.Should().HaveCount(10);
afterSchedulerRun.SequenceEqual(initialTasks.Where(t => t != taskViewModel)).Should().BeTrue();
afterSchedulerRun.SequenceEqual(initialTasks.Where(t => !object.ReferenceEquals(t, taskViewModel))).Should().BeTrue();
}

private static IFixture CreateFixture()
Expand Down
7 changes: 4 additions & 3 deletions czishrink/netczicompressTests/ViewModels/ErrorItemTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,11 @@ public class ErrorItemTests
[Fact]
public void WritableProperties_AreInitOnly()
{
foreach (var property in WritableProperties())
{
var setMethod = property.SetMethod;
var writablePropertySetters = from p in WritableProperties()
select p.SetMethod;

foreach (var setMethod in writablePropertySetters)
{
// Get the modifiers applied to the return parameter.
var setMethodReturnParameterModifiers = setMethod!.ReturnParameter.GetRequiredCustomModifiers();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -414,7 +414,8 @@ private static IEnumerable<ErrorItem> GetExpectedErrorItems(IEnumerable<FileFini
private static IObservable<(ErrorItem[] Snapshot, ErrorItem? SelectedItem)> ObserveSelectedItemChanges(ErrorListViewModel sut)
{
var changes = sut.ObservableForProperty(vm => vm.SelectedErrorItem);
return from change in changes select (sut.Errors.ToArray(), sut.SelectedErrorItem);

return from change in changes select (sut.Errors.ToArray(), change.Value);
}

private static string ToString(NotifyCollectionChangedEventArgs e)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ void StoreDataPoint(string name)
}

// ACT
var subject = new Subject<CompressorMessage.FileFinished>();
using var subject = new Subject<CompressorMessage.FileFinished>();
sut.ObserveRun(p, subject.AsObservable());
var messages = fixture.CreateMany<CompressorMessage.FileFinished>();
subject.OnNextAll(messages);
Expand Down Expand Up @@ -317,7 +317,7 @@ public void ShowLogFile_WhenOpeningTheLogFileFails_UpdatesCanExecute()
var fixture = CreateFixture();
fixture.Inject<IScheduler>(ImmediateScheduler.Instance);
var loggingStrategyMock = fixture.Freeze<Mock<ILoggingStrategy>>();
var logFile = Mock.Of<IFileInfo>(x => x.Exists == true);
var logFile = Mock.Of<IFileInfo>(x => x.Exists);
var sut = fixture.Create<LogFileViewModel>();

var p = fixture.Create<FolderCompressorParameters>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ namespace netczicompressTests.ViewModels;
using System.IO.Abstractions.TestingHelpers;
using System.Reactive;
using System.Reactive.Threading.Tasks;
using System.Windows.Input;

using AutoFixture;

Expand Down Expand Up @@ -190,8 +189,6 @@ public async Task OverallStatus_WhenProcessing_HasExpectedValues()
_ = fixture.Freeze<Mock<IFolderCompressor>>().WithWaitForCancellation();

var sut = fixture.Create<MainViewModel>();
ICommand start = sut.StartCommand;
ICommand stop = sut.StopCommand;
SetFolders(sut, fs);

Dictionary<string, string> overallStatusWhen = new();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -188,8 +188,8 @@ public async Task StartCommands_WhenProcessingStarts_UsesCorrectParameters(Opera
It.Is<FolderCompressorParameters>(
x => x.InputDir.FullName == sut.InputDirectory &&
x.OutputDir.FullName == sut.OutputDirectory &&
x.InputDir.FileSystem == fs &&
x.OutputDir.FileSystem == fs &&
object.ReferenceEquals(x.InputDir.FileSystem, fs) &&
object.ReferenceEquals(x.OutputDir.FileSystem, fs) &&
x.Recursive == recursive &&
x.Mode == selectedMode.Value),
It.Is<CancellationToken>(t => !t.IsCancellationRequested)),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ public async Task StopCommand_WhenProcessing_CanExecuteHasExpectedValues()
_ = fixture.Freeze<Mock<IFolderCompressor>>().WithWaitForCancellation();

var sut = fixture.Create<MainViewModel>();
ICommand start = sut.StartCommand;
ICommand stop = sut.StopCommand;
SetFolders(sut, fs);

Expand Down

0 comments on commit 34cdbdf

Please sign in to comment.