mirror of
https://github.com/microsoft/PowerToys.git
synced 2024-11-24 20:46:20 +08:00
Enabling FxCop on tests (#6481)
This commit is contained in:
parent
fb1888f01f
commit
1027b7de72
@ -39,8 +39,11 @@ namespace Microsoft.PowerToys.Settings.UI.Lib.Utilities
|
||||
ModuleAction = customAction,
|
||||
};
|
||||
|
||||
var sendCustomAction = new SendCustomAction(moduleName);
|
||||
sendCustomAction.Action = moduleCustomAction;
|
||||
var sendCustomAction = new SendCustomAction(moduleName)
|
||||
{
|
||||
Action = moduleCustomAction,
|
||||
};
|
||||
|
||||
return sendCustomAction.ToJsonString();
|
||||
}
|
||||
|
||||
@ -53,12 +56,15 @@ namespace Microsoft.PowerToys.Settings.UI.Lib.Utilities
|
||||
Directory.CreateDirectory(path);
|
||||
}
|
||||
|
||||
var watcher = new FileSystemWatcher();
|
||||
watcher.Path = path;
|
||||
watcher.Filter = fileName;
|
||||
watcher.NotifyFilter = NotifyFilters.LastWrite;
|
||||
var watcher = new FileSystemWatcher
|
||||
{
|
||||
Path = path,
|
||||
Filter = fileName,
|
||||
NotifyFilter = NotifyFilters.LastWrite,
|
||||
EnableRaisingEvents = true,
|
||||
};
|
||||
|
||||
watcher.Changed += (o, e) => onChangedCallback();
|
||||
watcher.EnableRaisingEvents = true;
|
||||
|
||||
return watcher;
|
||||
}
|
||||
@ -71,11 +77,11 @@ namespace Microsoft.PowerToys.Settings.UI.Lib.Utilities
|
||||
[DllImport("user32.dll")]
|
||||
private static extern bool AllowSetForegroundWindow(int dwProcessId);
|
||||
|
||||
private static interop.LayoutMapManaged layoutMap = new interop.LayoutMapManaged();
|
||||
private static readonly interop.LayoutMapManaged LayoutMap = new interop.LayoutMapManaged();
|
||||
|
||||
public static string GetKeyName(uint key)
|
||||
{
|
||||
return layoutMap.GetKeyName(key);
|
||||
return LayoutMap.GetKeyName(key);
|
||||
}
|
||||
|
||||
public static string GetProductVersion()
|
||||
|
@ -41,8 +41,7 @@ namespace ColorPickerUI
|
||||
protected override void OnStartup(StartupEventArgs e)
|
||||
{
|
||||
// allow only one instance of color picker
|
||||
bool createdNew;
|
||||
_instanceMutex = new Mutex(true, @"Global\ColorPicker", out createdNew);
|
||||
_instanceMutex = new Mutex(true, @"Global\ColorPicker", out bool createdNew);
|
||||
if (!createdNew)
|
||||
{
|
||||
_instanceMutex = null;
|
||||
|
@ -18,9 +18,11 @@ namespace ColorPicker.Settings
|
||||
private const string ColorPickerModuleName = "ColorPicker";
|
||||
private const string DefaultActivationShortcut = "Ctrl + Break";
|
||||
private const int MaxNumberOfRetry = 5;
|
||||
private FileSystemWatcher _watcher;
|
||||
|
||||
private object _loadingSettingsLock = new object();
|
||||
[System.Diagnostics.CodeAnalysis.SuppressMessage("CodeQuality", "IDE0052:Remove unread private members", Justification = "Actually, call back is LoadSettingsFromJson")]
|
||||
private readonly FileSystemWatcher _watcher;
|
||||
|
||||
private readonly object _loadingSettingsLock = new object();
|
||||
|
||||
[ImportingConstructor]
|
||||
public UserSettings()
|
||||
|
@ -128,6 +128,11 @@
|
||||
</Content>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.CodeAnalysis.FxCopAnalyzers">
|
||||
<Version>3.3.0</Version>
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
</PackageReference>
|
||||
<PackageReference Include="Moq">
|
||||
<Version>4.14.5</Version>
|
||||
</PackageReference>
|
||||
|
@ -10,11 +10,12 @@ namespace ImageResizer.Models
|
||||
public class CustomSizeTests
|
||||
{
|
||||
[Fact]
|
||||
public void Name_works()
|
||||
public void NameWorks()
|
||||
{
|
||||
var size = new CustomSize();
|
||||
|
||||
size.Name = "Ignored";
|
||||
var size = new CustomSize
|
||||
{
|
||||
Name = "Ignored",
|
||||
};
|
||||
|
||||
Assert.Equal(Resources.Input_Custom, size.Name);
|
||||
}
|
||||
|
@ -20,7 +20,7 @@ namespace ImageResizer.Models
|
||||
private static readonly string EOL = Environment.NewLine;
|
||||
|
||||
[Fact]
|
||||
public void FromCommandLine_works()
|
||||
public void FromCommandLineWorks()
|
||||
{
|
||||
var standardInput =
|
||||
"Image1.jpg" + EOL +
|
||||
@ -56,7 +56,7 @@ namespace ImageResizer.Models
|
||||
}*/
|
||||
|
||||
[Fact]
|
||||
public void Process_aggregates_errors()
|
||||
public void ProcessAggregatesErrors()
|
||||
{
|
||||
var batch = CreateBatch(file => throw new Exception("Error: " + file));
|
||||
batch.Files.Add("Image1.jpg");
|
||||
@ -81,7 +81,7 @@ namespace ImageResizer.Models
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Process_reports_progress()
|
||||
public void ProcessReportsProgress()
|
||||
{
|
||||
var batch = CreateBatch(_ => { });
|
||||
batch.Files.Add("Image1.jpg");
|
||||
|
@ -16,9 +16,10 @@ namespace ImageResizer.Models
|
||||
public class ResizeOperationTests : IDisposable
|
||||
{
|
||||
private readonly TestDirectory _directory = new TestDirectory();
|
||||
private bool disposedValue;
|
||||
|
||||
[Fact]
|
||||
public void Execute_copies_frame_metadata()
|
||||
public void ExecuteCopiesFrameMetadata()
|
||||
{
|
||||
var operation = new ResizeOperation("Test.jpg", _directory, Settings());
|
||||
|
||||
@ -30,7 +31,7 @@ namespace ImageResizer.Models
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Execute_keeps_date_modified()
|
||||
public void ExecuteKeepsDateModified()
|
||||
{
|
||||
var operation = new ResizeOperation("Test.png", _directory, Settings(s => s.KeepDateModified = true));
|
||||
|
||||
@ -40,7 +41,7 @@ namespace ImageResizer.Models
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Execute_keeps_date_modified_when_replacing_originals()
|
||||
public void ExecuteKeepsDateModifiedWhenReplacingOriginals()
|
||||
{
|
||||
var path = Path.Combine(_directory, "Test.png");
|
||||
File.Copy("Test.png", path);
|
||||
@ -63,7 +64,7 @@ namespace ImageResizer.Models
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Execute_replaces_originals()
|
||||
public void ExecuteReplacesOriginals()
|
||||
{
|
||||
var path = Path.Combine(_directory, "Test.png");
|
||||
File.Copy("Test.png", path);
|
||||
@ -76,7 +77,7 @@ namespace ImageResizer.Models
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Execute_transforms_each_frame()
|
||||
public void ExecuteTransformsEachFrame()
|
||||
{
|
||||
var operation = new ResizeOperation("Test.gif", _directory, Settings());
|
||||
|
||||
@ -92,7 +93,7 @@ namespace ImageResizer.Models
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Execute_uses_fallback_encoder()
|
||||
public void ExecuteUsesFallbackEncoder()
|
||||
{
|
||||
var operation = new ResizeOperation(
|
||||
"Test.ico",
|
||||
@ -105,7 +106,7 @@ namespace ImageResizer.Models
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Transform_ignores_orientation_when_landscape_to_portrait()
|
||||
public void TransformIgnoresOrientationWhenLandscapeToPortrait()
|
||||
{
|
||||
var operation = new ResizeOperation(
|
||||
"Test.png",
|
||||
@ -130,7 +131,7 @@ namespace ImageResizer.Models
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Transform_ignores_orientation_when_portrait_to_landscape()
|
||||
public void TransformIgnoresOrientationWhenPortraitToLandscape()
|
||||
{
|
||||
var operation = new ResizeOperation(
|
||||
"TestPortrait.png",
|
||||
@ -155,7 +156,7 @@ namespace ImageResizer.Models
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Transform_ignores_ignore_orientation_when_auto()
|
||||
public void TransformIgnoresIgnoreOrientationWhenAuto()
|
||||
{
|
||||
var operation = new ResizeOperation(
|
||||
"Test.png",
|
||||
@ -180,7 +181,7 @@ namespace ImageResizer.Models
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Transform_ignores_ignore_orientation_when_percent()
|
||||
public void TransformIgnoresIgnoreOrientationWhenPercent()
|
||||
{
|
||||
var operation = new ResizeOperation(
|
||||
"Test.png",
|
||||
@ -207,7 +208,7 @@ namespace ImageResizer.Models
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Transform_honors_shrink_only()
|
||||
public void TransformHonorsShrinkOnly()
|
||||
{
|
||||
var operation = new ResizeOperation(
|
||||
"Test.png",
|
||||
@ -232,7 +233,7 @@ namespace ImageResizer.Models
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Transform_ignores_shrink_only_when_percent()
|
||||
public void TransformIgnoresShrinkOnlyWhenPercent()
|
||||
{
|
||||
var operation = new ResizeOperation(
|
||||
"Test.png",
|
||||
@ -257,7 +258,7 @@ namespace ImageResizer.Models
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Transform_honors_shrink_only_when_auto_height()
|
||||
public void TransformHonorsShrinkOnlyWhenAutoHeight()
|
||||
{
|
||||
var operation = new ResizeOperation(
|
||||
"Test.png",
|
||||
@ -278,7 +279,7 @@ namespace ImageResizer.Models
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Transform_honors_shrink_only_when_auto_width()
|
||||
public void TransformHonorsShrinkOnlyWhenAutoWidth()
|
||||
{
|
||||
var operation = new ResizeOperation(
|
||||
"Test.png",
|
||||
@ -299,7 +300,7 @@ namespace ImageResizer.Models
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Transform_honors_unit()
|
||||
public void TransformHonorsUnit()
|
||||
{
|
||||
var operation = new ResizeOperation(
|
||||
"Test.png",
|
||||
@ -318,7 +319,7 @@ namespace ImageResizer.Models
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Transform_honors_fit_when_Fit()
|
||||
public void TransformHonorsFitWhenFit()
|
||||
{
|
||||
var operation = new ResizeOperation(
|
||||
"Test.png",
|
||||
@ -337,7 +338,7 @@ namespace ImageResizer.Models
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Transform_honors_fit_when_Fill()
|
||||
public void TransformHonorsFitWhenFill()
|
||||
{
|
||||
var operation = new ResizeOperation(
|
||||
"Test.png",
|
||||
@ -357,7 +358,7 @@ namespace ImageResizer.Models
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Transform_honors_fit_when_Stretch()
|
||||
public void TransformHonorsFitWhenStretch()
|
||||
{
|
||||
var operation = new ResizeOperation(
|
||||
"Test.png",
|
||||
@ -377,9 +378,9 @@ namespace ImageResizer.Models
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void GetDestinationPath_uniquifies_output_filename()
|
||||
public void GetDestinationPathUniquifiesOutputFilename()
|
||||
{
|
||||
File.WriteAllBytes(Path.Combine(_directory, "Test (Test).png"), new byte[0]);
|
||||
File.WriteAllBytes(Path.Combine(_directory, "Test (Test).png"), Array.Empty<byte>());
|
||||
|
||||
var operation = new ResizeOperation("Test.png", _directory, Settings());
|
||||
|
||||
@ -389,10 +390,10 @@ namespace ImageResizer.Models
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void GetDestinationPath_uniquifies_output_filename_again()
|
||||
public void GetDestinationPathUniquifiesOutputFilenameAgain()
|
||||
{
|
||||
File.WriteAllBytes(Path.Combine(_directory, "Test (Test).png"), new byte[0]);
|
||||
File.WriteAllBytes(Path.Combine(_directory, "Test (Test) (1).png"), new byte[0]);
|
||||
File.WriteAllBytes(Path.Combine(_directory, "Test (Test).png"), Array.Empty<byte>());
|
||||
File.WriteAllBytes(Path.Combine(_directory, "Test (Test) (1).png"), Array.Empty<byte>());
|
||||
|
||||
var operation = new ResizeOperation("Test.png", _directory, Settings());
|
||||
|
||||
@ -402,7 +403,7 @@ namespace ImageResizer.Models
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void GetDestinationPath_uses_fileName_format()
|
||||
public void GetDestinationPathUsesFileNameFormat()
|
||||
{
|
||||
var operation = new ResizeOperation(
|
||||
"Test.png",
|
||||
@ -415,7 +416,7 @@ namespace ImageResizer.Models
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Execute_handles_directories_in_fileName_format()
|
||||
public void ExecuteHandlesDirectoriesInFileNameFormat()
|
||||
{
|
||||
var operation = new ResizeOperation(
|
||||
"Test.png",
|
||||
@ -427,10 +428,7 @@ namespace ImageResizer.Models
|
||||
Assert.True(File.Exists(_directory + @"\Directory\Test (Test).png"));
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
=> _directory.Dispose();
|
||||
|
||||
private Settings Settings(Action<Settings> action = null)
|
||||
private static Settings Settings(Action<Settings> action = null)
|
||||
{
|
||||
var settings = new Settings
|
||||
{
|
||||
@ -449,5 +447,27 @@ namespace ImageResizer.Models
|
||||
|
||||
return settings;
|
||||
}
|
||||
|
||||
protected virtual void Dispose(bool disposing)
|
||||
{
|
||||
if (!disposedValue)
|
||||
{
|
||||
if (disposing)
|
||||
{
|
||||
_directory.Dispose();
|
||||
}
|
||||
|
||||
// TODO: free unmanaged resources (unmanaged objects) and override finalizer
|
||||
// TODO: set large fields to null
|
||||
disposedValue = true;
|
||||
}
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
// Do not change this code. Put cleanup code in 'Dispose(bool disposing)' method
|
||||
Dispose(disposing: true);
|
||||
GC.SuppressFinalize(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -14,7 +14,7 @@ namespace ImageResizer.Models
|
||||
public class ResizeSizeTests
|
||||
{
|
||||
[Fact]
|
||||
public void Name_works()
|
||||
public void NameWorks()
|
||||
{
|
||||
var size = new ResizeSize();
|
||||
|
||||
@ -28,7 +28,7 @@ namespace ImageResizer.Models
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Name_replaces_tokens()
|
||||
public void NameReplacesTokens()
|
||||
{
|
||||
var args = new List<(string, string)>
|
||||
{
|
||||
@ -39,16 +39,17 @@ namespace ImageResizer.Models
|
||||
};
|
||||
foreach (var (name, expected) in args)
|
||||
{
|
||||
var size = new ResizeSize();
|
||||
|
||||
size.Name = name;
|
||||
var size = new ResizeSize
|
||||
{
|
||||
Name = name,
|
||||
};
|
||||
|
||||
Assert.Equal(expected, size.Name);
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Fit_works()
|
||||
public void FitWorks()
|
||||
{
|
||||
var size = new ResizeSize();
|
||||
|
||||
@ -62,7 +63,7 @@ namespace ImageResizer.Models
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Width_works()
|
||||
public void WidthWorks()
|
||||
{
|
||||
var size = new ResizeSize();
|
||||
|
||||
@ -76,7 +77,7 @@ namespace ImageResizer.Models
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Height_works()
|
||||
public void HeightWorks()
|
||||
{
|
||||
var size = new ResizeSize();
|
||||
|
||||
@ -90,7 +91,7 @@ namespace ImageResizer.Models
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void HasAuto_returns_true_when_Width_unset()
|
||||
public void HasAutoReturnsTrueWhenWidthUnset()
|
||||
{
|
||||
var size = new ResizeSize
|
||||
{
|
||||
@ -102,7 +103,7 @@ namespace ImageResizer.Models
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void HasAuto_returns_true_when_Height_unset()
|
||||
public void HasAutoReturnsTrueWhenHeightUnset()
|
||||
{
|
||||
var size = new ResizeSize
|
||||
{
|
||||
@ -114,7 +115,7 @@ namespace ImageResizer.Models
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void HasAuto_returns_false_when_Width_and_Height_set()
|
||||
public void HasAutoReturnsFalseWhenWidthAndHeightSet()
|
||||
{
|
||||
var size = new ResizeSize
|
||||
{
|
||||
@ -126,7 +127,7 @@ namespace ImageResizer.Models
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Unit_works()
|
||||
public void UnitWorks()
|
||||
{
|
||||
var size = new ResizeSize();
|
||||
|
||||
@ -140,7 +141,7 @@ namespace ImageResizer.Models
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void GetPixelWidth_works()
|
||||
public void GetPixelWidthWorks()
|
||||
{
|
||||
var size = new ResizeSize
|
||||
{
|
||||
@ -154,7 +155,7 @@ namespace ImageResizer.Models
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void GetPixelHeight_works()
|
||||
public void GetPixelHeightWorks()
|
||||
{
|
||||
var size = new ResizeSize
|
||||
{
|
||||
@ -170,7 +171,7 @@ namespace ImageResizer.Models
|
||||
[Theory]
|
||||
[InlineData(ResizeFit.Fit)]
|
||||
[InlineData(ResizeFit.Fill)]
|
||||
public void GetPixelHeight_uses_Width_when_scale_by_percent(ResizeFit fit)
|
||||
public void GetPixelHeightUsesWidthWhenScaleByPercent(ResizeFit fit)
|
||||
{
|
||||
var size = new ResizeSize
|
||||
{
|
||||
@ -186,7 +187,7 @@ namespace ImageResizer.Models
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ConvertToPixels_works_when_auto_and_fit()
|
||||
public void ConvertToPixelsWorksWhenAutoAndFit()
|
||||
{
|
||||
var size = new ResizeSize
|
||||
{
|
||||
@ -200,7 +201,7 @@ namespace ImageResizer.Models
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ConvertToPixels_works_when_auto_and_not_fit()
|
||||
public void ConvertToPixelsWorksWhenAutoAndNotFit()
|
||||
{
|
||||
var size = new ResizeSize
|
||||
{
|
||||
@ -214,7 +215,7 @@ namespace ImageResizer.Models
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ConvertToPixels_works_when_inches()
|
||||
public void ConvertToPixelsWorksWhenInches()
|
||||
{
|
||||
var size = new ResizeSize
|
||||
{
|
||||
@ -228,7 +229,7 @@ namespace ImageResizer.Models
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ConvertToPixels_works_when_centimeters()
|
||||
public void ConvertToPixelsWorksWhenCentimeters()
|
||||
{
|
||||
var size = new ResizeSize
|
||||
{
|
||||
@ -242,7 +243,7 @@ namespace ImageResizer.Models
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ConvertToPixels_works_when_percent()
|
||||
public void ConvertToPixelsWorksWhenPercent()
|
||||
{
|
||||
var size = new ResizeSize
|
||||
{
|
||||
@ -256,7 +257,7 @@ namespace ImageResizer.Models
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ConvertToPixels_works_when_pixels()
|
||||
public void ConvertToPixelsWorksWhenPixels()
|
||||
{
|
||||
var size = new ResizeSize
|
||||
{
|
||||
|
@ -13,14 +13,33 @@ namespace ImageResizer.Properties
|
||||
public AppFixture()
|
||||
{
|
||||
// new App() needs to be created since Settings.Reload() uses App.Current to update properties on the UI thread. App() can be created only once otherwise it results in System.InvalidOperationException : Cannot create more than one System.Windows.Application instance in the same AppDomain.
|
||||
imageResizerApp = new App();
|
||||
_imageResizerApp = new App();
|
||||
}
|
||||
|
||||
[System.Diagnostics.CodeAnalysis.SuppressMessage("CodeQuality", "IDE0052:Remove unread private members", Justification = "new App() needs to be created since Settings.Reload() uses App.Current to update properties on the UI thread. App() can be created only once otherwise it results in System.InvalidOperationException : Cannot create more than one System.Windows.Application instance in the same AppDomain")]
|
||||
private App _imageResizerApp;
|
||||
private bool _disposedValue;
|
||||
|
||||
protected virtual void Dispose(bool disposing)
|
||||
{
|
||||
if (!_disposedValue)
|
||||
{
|
||||
if (disposing)
|
||||
{
|
||||
_imageResizerApp = null;
|
||||
}
|
||||
|
||||
// TODO: free unmanaged resources (unmanaged objects) and override finalizer
|
||||
// TODO: set large fields to null
|
||||
_disposedValue = true;
|
||||
}
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
imageResizerApp = null;
|
||||
// Do not change this code. Put cleanup code in 'Dispose(bool disposing)' method
|
||||
Dispose(disposing: true);
|
||||
GC.SuppressFinalize(this);
|
||||
}
|
||||
|
||||
private App imageResizerApp;
|
||||
}
|
||||
}
|
||||
|
@ -6,6 +6,7 @@ using System;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Collections.Specialized;
|
||||
using System.ComponentModel;
|
||||
using System.Globalization;
|
||||
using ImageResizer.Models;
|
||||
using ImageResizer.Test;
|
||||
using Xunit;
|
||||
@ -16,22 +17,16 @@ namespace ImageResizer.Properties
|
||||
{
|
||||
public class SettingsTests : IClassFixture<AppFixture>, IDisposable
|
||||
{
|
||||
private bool disposedValue;
|
||||
|
||||
public SettingsTests()
|
||||
{
|
||||
// Change settings.json path to a temp file
|
||||
Settings.SettingsPath = ".\\test_settings.json";
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
if (System.IO.File.Exists(Settings.SettingsPath))
|
||||
{
|
||||
System.IO.File.Delete(Settings.SettingsPath);
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void AllSizes_propagates_Sizes_collection_events()
|
||||
public void AllSizesPropagatesSizesCollectionEvents()
|
||||
{
|
||||
var settings = new Settings
|
||||
{
|
||||
@ -49,7 +44,7 @@ namespace ImageResizer.Properties
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void AllSizes_propagates_Sizes_property_events()
|
||||
public void AllSizesPropagatesSizesPropertyEvents()
|
||||
{
|
||||
var settings = new Settings
|
||||
{
|
||||
@ -64,7 +59,7 @@ namespace ImageResizer.Properties
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void AllSizes_contains_Sizes()
|
||||
public void AllSizesContainsSizes()
|
||||
{
|
||||
var settings = new Settings
|
||||
{
|
||||
@ -76,7 +71,7 @@ namespace ImageResizer.Properties
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void AllSizes_contains_CustomSize()
|
||||
public void AllSizesContainsCustomSize()
|
||||
{
|
||||
var settings = new Settings
|
||||
{
|
||||
@ -88,7 +83,7 @@ namespace ImageResizer.Properties
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void AllSizes_handles_property_events_for_CustomSize()
|
||||
public void AllSizesHandlesPropertyEventsForCustomSize()
|
||||
{
|
||||
var originalCustomSize = new CustomSize();
|
||||
var settings = new Settings
|
||||
@ -113,7 +108,7 @@ namespace ImageResizer.Properties
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void FileNameFormat_works()
|
||||
public void FileNameFormatWorks()
|
||||
{
|
||||
var settings = new Settings { FileName = "{T}%1e%2s%3t%4%5%6%7" };
|
||||
|
||||
@ -126,7 +121,7 @@ namespace ImageResizer.Properties
|
||||
[InlineData(0)]
|
||||
[InlineData(1)]
|
||||
[InlineData(2)]
|
||||
public void SelectedSize_returns_CustomSize_when_out_of_range(int index)
|
||||
public void SelectedSizeReturnsCustomSizeWhenOutOfRange(int index)
|
||||
{
|
||||
var settings = new Settings
|
||||
{
|
||||
@ -141,7 +136,7 @@ namespace ImageResizer.Properties
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void SelectedSize_returns_Size_when_in_range()
|
||||
public void SelectedSizeReturnsSizeWhenInRange()
|
||||
{
|
||||
var settings = new Settings
|
||||
{
|
||||
@ -158,7 +153,7 @@ namespace ImageResizer.Properties
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void IDataErrorInfo_Error_returns_empty()
|
||||
public void IDataErrorInfoErrorReturnsEmpty()
|
||||
{
|
||||
var settings = new Settings();
|
||||
|
||||
@ -170,21 +165,21 @@ namespace ImageResizer.Properties
|
||||
[Theory]
|
||||
[InlineData(0)]
|
||||
[InlineData(101)]
|
||||
public void IDataErrorInfo_Item_JpegQualityLevel_returns_error_when_out_of_range(int value)
|
||||
public void IDataErrorInfoItemJpegQualityLevelReturnsErrorWhenOutOfRange(int value)
|
||||
{
|
||||
var settings = new Settings { JpegQualityLevel = value };
|
||||
|
||||
var result = ((IDataErrorInfo)settings)["JpegQualityLevel"];
|
||||
|
||||
Assert.Equal(
|
||||
string.Format(Resources.ValueMustBeBetween, 1, 100),
|
||||
string.Format(CultureInfo.InvariantCulture, Resources.ValueMustBeBetween, 1, 100),
|
||||
result);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData(1)]
|
||||
[InlineData(100)]
|
||||
public void IDataErrorInfo_Item_JpegQualityLevel_returns_empty_when_in_range(int value)
|
||||
public void IDataErrorInfoItemJpegQualityLevelReturnsEmptyWhenInRange(int value)
|
||||
{
|
||||
var settings = new Settings { JpegQualityLevel = value };
|
||||
|
||||
@ -194,7 +189,7 @@ namespace ImageResizer.Properties
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void IDataErrorInfo_Item_returns_empty_when_not_JpegQualityLevel()
|
||||
public void IDataErrorInfoItemReturnsEmptyWhenNotJpegQualityLevel()
|
||||
{
|
||||
var settings = new Settings();
|
||||
|
||||
@ -204,7 +199,7 @@ namespace ImageResizer.Properties
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Reload_createsFile_when_FileNotFound()
|
||||
public void ReloadCreatesFileWhenFileNotFound()
|
||||
{
|
||||
// Arrange
|
||||
var settings = new Settings();
|
||||
@ -220,7 +215,7 @@ namespace ImageResizer.Properties
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Save_creates_file()
|
||||
public void SaveCreatesFile()
|
||||
{
|
||||
// Arrange
|
||||
var settings = new Settings();
|
||||
@ -236,7 +231,7 @@ namespace ImageResizer.Properties
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Save_json_is_readable_by_Reload()
|
||||
public void SaveJsonIsReadableByReload()
|
||||
{
|
||||
// Arrange
|
||||
var settings = new Settings();
|
||||
@ -253,7 +248,7 @@ namespace ImageResizer.Properties
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Reload_raises_PropertyChanged_()
|
||||
public void ReloadRaisesPropertyChanged()
|
||||
{
|
||||
// Arrange
|
||||
var settings = new Settings();
|
||||
@ -276,5 +271,30 @@ namespace ImageResizer.Properties
|
||||
Assert.PropertyChanged(settings, "CustomSize", action);
|
||||
Assert.PropertyChanged(settings, "SelectedSizeIndex", action);
|
||||
}
|
||||
|
||||
protected virtual void Dispose(bool disposing)
|
||||
{
|
||||
if (!disposedValue)
|
||||
{
|
||||
if (disposing)
|
||||
{
|
||||
if (System.IO.File.Exists(Settings.SettingsPath))
|
||||
{
|
||||
System.IO.File.Delete(Settings.SettingsPath);
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: free unmanaged resources (unmanaged objects) and override finalizer
|
||||
// TODO: set large fields to null
|
||||
disposedValue = true;
|
||||
}
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
// Do not change this code. Put cleanup code in 'Dispose(bool disposing)' method
|
||||
Dispose(disposing: true);
|
||||
GC.SuppressFinalize(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -16,6 +16,7 @@ namespace ImageResizer
|
||||
public class TestDirectory : IDisposable
|
||||
{
|
||||
private readonly string _path;
|
||||
private bool disposedValue;
|
||||
|
||||
public TestDirectory()
|
||||
{
|
||||
@ -34,24 +35,50 @@ namespace ImageResizer
|
||||
public string File()
|
||||
=> Assert.Single(Files);
|
||||
|
||||
public void Dispose()
|
||||
public static implicit operator string(TestDirectory directory)
|
||||
{
|
||||
var stopwatch = Stopwatch.StartNew();
|
||||
while (stopwatch.ElapsedMilliseconds < 30000)
|
||||
return directory?._path;
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return _path;
|
||||
}
|
||||
|
||||
protected virtual void Dispose(bool disposing)
|
||||
{
|
||||
if (!disposedValue)
|
||||
{
|
||||
try
|
||||
if (disposing)
|
||||
{
|
||||
Directory.Delete(_path, recursive: true);
|
||||
break;
|
||||
}
|
||||
catch
|
||||
{
|
||||
Thread.Sleep(150);
|
||||
var stopwatch = Stopwatch.StartNew();
|
||||
while (stopwatch.ElapsedMilliseconds < 30000)
|
||||
{
|
||||
try
|
||||
{
|
||||
Directory.Delete(_path, recursive: true);
|
||||
break;
|
||||
}
|
||||
#pragma warning disable CA1031 // Do not catch general exception types
|
||||
catch
|
||||
#pragma warning restore CA1031 // Do not catch general exception types
|
||||
{
|
||||
Thread.Sleep(150);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: free unmanaged resources (unmanaged objects) and override finalizer
|
||||
// TODO: set large fields to null
|
||||
disposedValue = true;
|
||||
}
|
||||
}
|
||||
|
||||
public static implicit operator string(TestDirectory directory)
|
||||
=> directory._path;
|
||||
public void Dispose()
|
||||
{
|
||||
// Do not change this code. Put cleanup code in 'Dispose(bool disposing)' method
|
||||
Dispose(disposing: true);
|
||||
GC.SuppressFinalize(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -23,7 +23,7 @@ namespace ImageResizer.Views
|
||||
[InlineData("MinutesSeconds", 0, 2, 2)]
|
||||
[InlineData("Second", 0, 0, 1)]
|
||||
[InlineData("Seconds", 0, 0, 2)]
|
||||
public void Convert_works(string resource, int hours, int minutes, int seconds)
|
||||
public void ConvertWorks(string resource, int hours, int minutes, int seconds)
|
||||
{
|
||||
var timeRemaining = new TimeSpan(hours, minutes, seconds);
|
||||
var converter = new TimeRemainingConverter();
|
||||
@ -36,7 +36,8 @@ namespace ImageResizer.Views
|
||||
|
||||
Assert.Equal(
|
||||
string.Format(
|
||||
Resources.ResourceManager.GetString("Progress_TimeRemaining_" + resource),
|
||||
CultureInfo.InvariantCulture,
|
||||
Resources.ResourceManager.GetString("Progress_TimeRemaining_" + resource, CultureInfo.InvariantCulture),
|
||||
hours,
|
||||
minutes,
|
||||
seconds),
|
||||
|
@ -137,12 +137,8 @@ namespace Microsoft.Plugin.Calculator
|
||||
|
||||
public void Init(PluginInitContext context)
|
||||
{
|
||||
if (context == null)
|
||||
{
|
||||
throw new ArgumentNullException(paramName: nameof(context));
|
||||
}
|
||||
Context = context ?? throw new ArgumentNullException(paramName: nameof(context));
|
||||
|
||||
Context = context;
|
||||
Context.API.ThemeChanged += OnThemeChanged;
|
||||
UpdateIconPath(Context.API.GetCurrentTheme());
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user