mirror of
https://github.com/microsoft/PowerToys
synced 2025-09-04 00:15:11 +00:00
Style cop up and running (#5340)
Co-authored-by: Clint Rutkas <crutkas@microsoft.com>
This commit is contained in:
@@ -26,8 +26,8 @@ namespace UnitTests_PreviewHandlerCommon
|
|||||||
}
|
}
|
||||||
|
|
||||||
[DataTestMethod]
|
[DataTestMethod]
|
||||||
[DataRow((uint)0)]
|
[DataRow(0U)]
|
||||||
[DataRow((uint)1)]
|
[DataRow(1U)]
|
||||||
public void FileBasedPreviewHandler_ShouldSetFilePath_WhenInitializeCalled(uint grfMode)
|
public void FileBasedPreviewHandler_ShouldSetFilePath_WhenInitializeCalled(uint grfMode)
|
||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
|
@@ -2,12 +2,12 @@
|
|||||||
// The Microsoft Corporation licenses this file to you under the MIT license.
|
// The Microsoft Corporation licenses this file to you under the MIT license.
|
||||||
// See the LICENSE file in the project root for more information.
|
// See the LICENSE file in the project root for more information.
|
||||||
|
|
||||||
using Common;
|
|
||||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
|
||||||
using System;
|
using System;
|
||||||
using System.Drawing;
|
using System.Drawing;
|
||||||
using System.Runtime.InteropServices;
|
using System.Runtime.InteropServices;
|
||||||
using System.Windows.Forms;
|
using System.Windows.Forms;
|
||||||
|
using Common;
|
||||||
|
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||||
|
|
||||||
namespace UnitTests_PreviewHandlerCommon
|
namespace UnitTests_PreviewHandlerCommon
|
||||||
{
|
{
|
||||||
@@ -15,7 +15,8 @@ namespace UnitTests_PreviewHandlerCommon
|
|||||||
public class FormHandlerControlTests
|
public class FormHandlerControlTests
|
||||||
{
|
{
|
||||||
private class TestFormControl : FormHandlerControl
|
private class TestFormControl : FormHandlerControl
|
||||||
{ }
|
{
|
||||||
|
}
|
||||||
|
|
||||||
[TestMethod]
|
[TestMethod]
|
||||||
public void FormHandlerControl_ShouldCreateHandle_OnInitialization()
|
public void FormHandlerControl_ShouldCreateHandle_OnInitialization()
|
||||||
|
@@ -5,7 +5,6 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.ComponentModel;
|
using System.ComponentModel;
|
||||||
using System.Drawing;
|
using System.Drawing;
|
||||||
using System.Drawing.Drawing2D;
|
|
||||||
using Common;
|
using Common;
|
||||||
using Common.ComInterlop;
|
using Common.ComInterlop;
|
||||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||||
@@ -111,7 +110,7 @@ namespace UnitTests_PreviewHandlerCommon
|
|||||||
|
|
||||||
previewHandlerControl = mockPreviewControl.Object;
|
previewHandlerControl = mockPreviewControl.Object;
|
||||||
var testPreviewHandler = new TestPreviewHandler();
|
var testPreviewHandler = new TestPreviewHandler();
|
||||||
var color = new COLORREF();
|
var color = default(COLORREF);
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
testPreviewHandler.SetBackgroundColor(color);
|
testPreviewHandler.SetBackgroundColor(color);
|
||||||
@@ -128,7 +127,7 @@ namespace UnitTests_PreviewHandlerCommon
|
|||||||
|
|
||||||
previewHandlerControl = mockPreviewControl.Object;
|
previewHandlerControl = mockPreviewControl.Object;
|
||||||
var testPreviewHandler = new TestPreviewHandler();
|
var testPreviewHandler = new TestPreviewHandler();
|
||||||
var color = new COLORREF();
|
var color = default(COLORREF);
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
testPreviewHandler.SetTextColor(color);
|
testPreviewHandler.SetTextColor(color);
|
||||||
@@ -231,7 +230,7 @@ namespace UnitTests_PreviewHandlerCommon
|
|||||||
// Arrange
|
// Arrange
|
||||||
var mockPreviewControl = new Mock<IPreviewHandlerControl>();
|
var mockPreviewControl = new Mock<IPreviewHandlerControl>();
|
||||||
var mockPreviewHandlerFrame = new Mock<IPreviewHandlerFrame>();
|
var mockPreviewHandlerFrame = new Mock<IPreviewHandlerFrame>();
|
||||||
var msg = new MSG();
|
var msg = default(MSG);
|
||||||
|
|
||||||
previewHandlerControl = mockPreviewControl.Object;
|
previewHandlerControl = mockPreviewControl.Object;
|
||||||
var testPreviewHandler = new TestPreviewHandler();
|
var testPreviewHandler = new TestPreviewHandler();
|
||||||
@@ -245,14 +244,14 @@ namespace UnitTests_PreviewHandlerCommon
|
|||||||
}
|
}
|
||||||
|
|
||||||
[DataTestMethod]
|
[DataTestMethod]
|
||||||
[DataRow((uint)0)]
|
[DataRow(0U)]
|
||||||
[DataRow((uint)1)]
|
[DataRow(1U)]
|
||||||
public void PreviewHandlerBase_ShouldReturnIPreviewHandlerFrameResponse_IfIPreviewHandlerFrameIsSet(uint resultCode)
|
public void PreviewHandlerBase_ShouldReturnIPreviewHandlerFrameResponse_IfIPreviewHandlerFrameIsSet(uint resultCode)
|
||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
var mockPreviewControl = new Mock<IPreviewHandlerControl>();
|
var mockPreviewControl = new Mock<IPreviewHandlerControl>();
|
||||||
var mockPreviewHandlerFrame = new Mock<IPreviewHandlerFrame>();
|
var mockPreviewHandlerFrame = new Mock<IPreviewHandlerFrame>();
|
||||||
var msg = new MSG();
|
var msg = default(MSG);
|
||||||
mockPreviewHandlerFrame
|
mockPreviewHandlerFrame
|
||||||
.Setup(x => x.TranslateAccelerator(ref msg))
|
.Setup(x => x.TranslateAccelerator(ref msg))
|
||||||
.Returns(resultCode);
|
.Returns(resultCode);
|
||||||
@@ -273,8 +272,8 @@ namespace UnitTests_PreviewHandlerCommon
|
|||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
var mockPreviewControl = new Mock<IPreviewHandlerControl>();
|
var mockPreviewControl = new Mock<IPreviewHandlerControl>();
|
||||||
var msg = new MSG();
|
var msg = default(MSG);
|
||||||
uint S_FALSE = 1;
|
uint sFalse = 1;
|
||||||
|
|
||||||
previewHandlerControl = mockPreviewControl.Object;
|
previewHandlerControl = mockPreviewControl.Object;
|
||||||
var testPreviewHandler = new TestPreviewHandler();
|
var testPreviewHandler = new TestPreviewHandler();
|
||||||
@@ -283,7 +282,7 @@ namespace UnitTests_PreviewHandlerCommon
|
|||||||
var result = testPreviewHandler.TranslateAccelerator(ref msg);
|
var result = testPreviewHandler.TranslateAccelerator(ref msg);
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
Assert.AreEqual(result, S_FALSE);
|
Assert.AreEqual(result, sFalse);
|
||||||
}
|
}
|
||||||
|
|
||||||
[TestMethod]
|
[TestMethod]
|
||||||
@@ -354,31 +353,35 @@ namespace UnitTests_PreviewHandlerCommon
|
|||||||
|
|
||||||
private LOGFONT GetLogFont()
|
private LOGFONT GetLogFont()
|
||||||
{
|
{
|
||||||
var logFont = new LOGFONT();
|
var logFont = new LOGFONT
|
||||||
logFont.LfHeight = 12;
|
{
|
||||||
logFont.LfWidth = 0;
|
LfHeight = 12,
|
||||||
logFont.LfEscapement = 0;
|
LfWidth = 0,
|
||||||
logFont.LfWeight = 400; // FW_NORMAL
|
LfEscapement = 0,
|
||||||
logFont.LfItalic = Convert.ToByte(false);
|
LfWeight = 400, // FW_NORMAL
|
||||||
logFont.LfUnderline = Convert.ToByte(false);
|
LfItalic = Convert.ToByte(false),
|
||||||
logFont.LfStrikeOut = Convert.ToByte(0);
|
LfUnderline = Convert.ToByte(false),
|
||||||
logFont.LfCharSet = Convert.ToByte(0); // ANSI_CHARSET
|
LfStrikeOut = Convert.ToByte(0),
|
||||||
logFont.LfOutPrecision = Convert.ToByte(0); // OUT_DEFAULT_PRECIS
|
LfCharSet = Convert.ToByte(0), // ANSI_CHARSET
|
||||||
logFont.LfClipPrecision = Convert.ToByte(0);
|
LfOutPrecision = Convert.ToByte(0), // OUT_DEFAULT_PRECIS
|
||||||
logFont.LfQuality = Convert.ToByte(0);
|
LfClipPrecision = Convert.ToByte(0),
|
||||||
logFont.LfPitchAndFamily = Convert.ToByte(0);
|
LfQuality = Convert.ToByte(0),
|
||||||
logFont.LfFaceName = "valid-font";
|
LfPitchAndFamily = Convert.ToByte(0),
|
||||||
|
LfFaceName = "valid-font",
|
||||||
|
};
|
||||||
|
|
||||||
return logFont;
|
return logFont;
|
||||||
}
|
}
|
||||||
|
|
||||||
private RECT GetRectangle(int left, int top, int right, int bottom)
|
private RECT GetRectangle(int left, int top, int right, int bottom)
|
||||||
{
|
{
|
||||||
var rect = new RECT();
|
var rect = new RECT
|
||||||
rect.Left = left;
|
{
|
||||||
rect.Top = top;
|
Left = left,
|
||||||
rect.Right = right;
|
Top = top,
|
||||||
rect.Bottom = bottom;
|
Right = right,
|
||||||
|
Bottom = bottom,
|
||||||
|
};
|
||||||
|
|
||||||
return rect;
|
return rect;
|
||||||
}
|
}
|
||||||
|
@@ -27,8 +27,8 @@ namespace UnitTests_PreviewHandlerCommon
|
|||||||
}
|
}
|
||||||
|
|
||||||
[DataTestMethod]
|
[DataTestMethod]
|
||||||
[DataRow((uint)0)]
|
[DataRow(0U)]
|
||||||
[DataRow((uint)1)]
|
[DataRow(1U)]
|
||||||
public void StreamBasedPreviewHandler_ShouldSetStream_WhenInitializeCalled(uint grfMode)
|
public void StreamBasedPreviewHandler_ShouldSetStream_WhenInitializeCalled(uint grfMode)
|
||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
|
@@ -2,16 +2,14 @@
|
|||||||
// The Microsoft Corporation licenses this file to you under the MIT license.
|
// The Microsoft Corporation licenses this file to you under the MIT license.
|
||||||
// See the LICENSE file in the project root for more information.
|
// See the LICENSE file in the project root for more information.
|
||||||
|
|
||||||
using Castle.Core.Logging;
|
|
||||||
using Common.Utilities;
|
|
||||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
|
||||||
using Moq;
|
|
||||||
using System;
|
using System;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Net.Sockets;
|
|
||||||
using System.Runtime.InteropServices;
|
using System.Runtime.InteropServices;
|
||||||
using System.Runtime.InteropServices.ComTypes;
|
using System.Runtime.InteropServices.ComTypes;
|
||||||
|
using Common.Utilities;
|
||||||
|
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||||
|
using Moq;
|
||||||
|
|
||||||
namespace UnitTests_PreviewHandlerCommon
|
namespace UnitTests_PreviewHandlerCommon
|
||||||
{
|
{
|
||||||
@@ -84,8 +82,10 @@ namespace UnitTests_PreviewHandlerCommon
|
|||||||
// Arrange
|
// Arrange
|
||||||
long streamLength = 5;
|
long streamLength = 5;
|
||||||
var stremMock = new Mock<IStream>();
|
var stremMock = new Mock<IStream>();
|
||||||
var stat = new System.Runtime.InteropServices.ComTypes.STATSTG();
|
var stat = new System.Runtime.InteropServices.ComTypes.STATSTG
|
||||||
stat.cbSize = streamLength;
|
{
|
||||||
|
cbSize = streamLength,
|
||||||
|
};
|
||||||
|
|
||||||
stremMock
|
stremMock
|
||||||
.Setup(x => x.Stat(out stat, It.IsAny<int>()));
|
.Setup(x => x.Stat(out stat, It.IsAny<int>()));
|
||||||
@@ -131,22 +131,23 @@ namespace UnitTests_PreviewHandlerCommon
|
|||||||
int expectedDwOrigin = 0; // STREAM_SEEK_SET
|
int expectedDwOrigin = 0; // STREAM_SEEK_SET
|
||||||
var stremMock = new Mock<IStream>();
|
var stremMock = new Mock<IStream>();
|
||||||
|
|
||||||
var streamWrapper = new StreamWrapper(stremMock.Object);
|
var streamWrapper = new StreamWrapper(stremMock.Object)
|
||||||
|
{
|
||||||
// Act
|
// Act
|
||||||
streamWrapper.Position = positionToSet;
|
Position = positionToSet,
|
||||||
|
};
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
stremMock.Verify(_ => _.Seek(It.Is<long>(offset => offset == positionToSet), It.Is<int>(dworigin => dworigin == expectedDwOrigin), It.IsAny<IntPtr>()), Times.Once);
|
stremMock.Verify(_ => _.Seek(It.Is<long>(offset => offset == positionToSet), It.Is<int>(dworigin => dworigin == expectedDwOrigin), It.IsAny<IntPtr>()), Times.Once);
|
||||||
}
|
}
|
||||||
|
|
||||||
[DataTestMethod]
|
[DataTestMethod]
|
||||||
[DataRow((long)0, SeekOrigin.Begin)]
|
[DataRow(0L, SeekOrigin.Begin)]
|
||||||
[DataRow((long)5, SeekOrigin.Begin)]
|
[DataRow(5L, SeekOrigin.Begin)]
|
||||||
[DataRow((long)0, SeekOrigin.Current)]
|
[DataRow(0L, SeekOrigin.Current)]
|
||||||
[DataRow((long)5, SeekOrigin.Current)]
|
[DataRow(5L, SeekOrigin.Current)]
|
||||||
[DataRow((long)0, SeekOrigin.End)]
|
[DataRow(0L, SeekOrigin.End)]
|
||||||
[DataRow((long)5, SeekOrigin.End)]
|
[DataRow(5L, SeekOrigin.End)]
|
||||||
public void StreamWrapper_ShouldCallIStreamSeekWithValidArguments_WhenSeekCalled(long offset, SeekOrigin origin)
|
public void StreamWrapper_ShouldCallIStreamSeekWithValidArguments_WhenSeekCalled(long offset, SeekOrigin origin)
|
||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
@@ -326,7 +327,5 @@ namespace UnitTests_PreviewHandlerCommon
|
|||||||
// Assert
|
// Assert
|
||||||
Assert.IsNotNull(exception);
|
Assert.IsNotNull(exception);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -98,6 +98,21 @@
|
|||||||
<SubType>Component</SubType>
|
<SubType>Component</SubType>
|
||||||
</Compile>
|
</Compile>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<Compile Include="..\..\..\codeAnalysis\GlobalSuppressions.cs">
|
||||||
|
<Link>GlobalSuppressions.cs</Link>
|
||||||
|
</Compile>
|
||||||
|
<AdditionalFiles Include="..\..\..\codeAnalysis\StyleCop.json">
|
||||||
|
<Link>StyleCop.json</Link>
|
||||||
|
</AdditionalFiles>
|
||||||
|
</ItemGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<PackageReference Include="StyleCop.Analyzers">
|
||||||
|
<Version>1.1.118</Version>
|
||||||
|
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||||
|
<PrivateAssets>all</PrivateAssets>
|
||||||
|
</PackageReference>
|
||||||
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="Moq">
|
<PackageReference Include="Moq">
|
||||||
<Version>4.14.5</Version>
|
<Version>4.14.5</Version>
|
||||||
|
@@ -2,9 +2,9 @@
|
|||||||
// The Microsoft Corporation licenses this file to you under the MIT license.
|
// The Microsoft Corporation licenses this file to you under the MIT license.
|
||||||
// See the LICENSE file in the project root for more information.
|
// See the LICENSE file in the project root for more information.
|
||||||
|
|
||||||
|
using System.Reflection;
|
||||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||||
using PreviewHandlerCommon;
|
using PreviewHandlerCommon;
|
||||||
using System.Reflection;
|
|
||||||
|
|
||||||
namespace UnitTests_PreviewHandlerCommon
|
namespace UnitTests_PreviewHandlerCommon
|
||||||
{
|
{
|
||||||
|
Reference in New Issue
Block a user