Enabling FxCop on tests (#6481)

This commit is contained in:
Clint Rutkas
2020-09-09 15:33:18 -07:00
committed by GitHub
parent fb1888f01f
commit 1027b7de72
13 changed files with 215 additions and 118 deletions

View File

@@ -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;
}
}

View File

@@ -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);
}
}
}