Style cop up and running (#5340)

Co-authored-by: Clint Rutkas <crutkas@microsoft.com>
This commit is contained in:
Clint Rutkas 2020-07-31 09:49:42 -07:00 committed by GitHub
parent ab86fc9a5e
commit d9fd967c48
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 74 additions and 56 deletions

View file

@ -26,8 +26,8 @@ namespace UnitTests_PreviewHandlerCommon
}
[DataTestMethod]
[DataRow((uint)0)]
[DataRow((uint)1)]
[DataRow(0U)]
[DataRow(1U)]
public void FileBasedPreviewHandler_ShouldSetFilePath_WhenInitializeCalled(uint grfMode)
{
// Arrange

View file

@ -2,12 +2,12 @@
// The Microsoft Corporation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using Common;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
using System.Drawing;
using System.Runtime.InteropServices;
using System.Windows.Forms;
using Common;
using Microsoft.VisualStudio.TestTools.UnitTesting;
namespace UnitTests_PreviewHandlerCommon
{
@ -15,7 +15,8 @@ namespace UnitTests_PreviewHandlerCommon
public class FormHandlerControlTests
{
private class TestFormControl : FormHandlerControl
{ }
{
}
[TestMethod]
public void FormHandlerControl_ShouldCreateHandle_OnInitialization()

View file

@ -5,7 +5,6 @@
using System;
using System.ComponentModel;
using System.Drawing;
using System.Drawing.Drawing2D;
using Common;
using Common.ComInterlop;
using Microsoft.VisualStudio.TestTools.UnitTesting;
@ -111,7 +110,7 @@ namespace UnitTests_PreviewHandlerCommon
previewHandlerControl = mockPreviewControl.Object;
var testPreviewHandler = new TestPreviewHandler();
var color = new COLORREF();
var color = default(COLORREF);
// Act
testPreviewHandler.SetBackgroundColor(color);
@ -128,7 +127,7 @@ namespace UnitTests_PreviewHandlerCommon
previewHandlerControl = mockPreviewControl.Object;
var testPreviewHandler = new TestPreviewHandler();
var color = new COLORREF();
var color = default(COLORREF);
// Act
testPreviewHandler.SetTextColor(color);
@ -231,7 +230,7 @@ namespace UnitTests_PreviewHandlerCommon
// Arrange
var mockPreviewControl = new Mock<IPreviewHandlerControl>();
var mockPreviewHandlerFrame = new Mock<IPreviewHandlerFrame>();
var msg = new MSG();
var msg = default(MSG);
previewHandlerControl = mockPreviewControl.Object;
var testPreviewHandler = new TestPreviewHandler();
@ -245,14 +244,14 @@ namespace UnitTests_PreviewHandlerCommon
}
[DataTestMethod]
[DataRow((uint)0)]
[DataRow((uint)1)]
[DataRow(0U)]
[DataRow(1U)]
public void PreviewHandlerBase_ShouldReturnIPreviewHandlerFrameResponse_IfIPreviewHandlerFrameIsSet(uint resultCode)
{
// Arrange
var mockPreviewControl = new Mock<IPreviewHandlerControl>();
var mockPreviewHandlerFrame = new Mock<IPreviewHandlerFrame>();
var msg = new MSG();
var msg = default(MSG);
mockPreviewHandlerFrame
.Setup(x => x.TranslateAccelerator(ref msg))
.Returns(resultCode);
@ -273,8 +272,8 @@ namespace UnitTests_PreviewHandlerCommon
{
// Arrange
var mockPreviewControl = new Mock<IPreviewHandlerControl>();
var msg = new MSG();
uint S_FALSE = 1;
var msg = default(MSG);
uint sFalse = 1;
previewHandlerControl = mockPreviewControl.Object;
var testPreviewHandler = new TestPreviewHandler();
@ -283,7 +282,7 @@ namespace UnitTests_PreviewHandlerCommon
var result = testPreviewHandler.TranslateAccelerator(ref msg);
// Assert
Assert.AreEqual(result, S_FALSE);
Assert.AreEqual(result, sFalse);
}
[TestMethod]
@ -354,31 +353,35 @@ namespace UnitTests_PreviewHandlerCommon
private LOGFONT GetLogFont()
{
var logFont = new LOGFONT();
logFont.LfHeight = 12;
logFont.LfWidth = 0;
logFont.LfEscapement = 0;
logFont.LfWeight = 400; // FW_NORMAL
logFont.LfItalic = Convert.ToByte(false);
logFont.LfUnderline = Convert.ToByte(false);
logFont.LfStrikeOut = Convert.ToByte(0);
logFont.LfCharSet = Convert.ToByte(0); // ANSI_CHARSET
logFont.LfOutPrecision = Convert.ToByte(0); // OUT_DEFAULT_PRECIS
logFont.LfClipPrecision = Convert.ToByte(0);
logFont.LfQuality = Convert.ToByte(0);
logFont.LfPitchAndFamily = Convert.ToByte(0);
logFont.LfFaceName = "valid-font";
var logFont = new LOGFONT
{
LfHeight = 12,
LfWidth = 0,
LfEscapement = 0,
LfWeight = 400, // FW_NORMAL
LfItalic = Convert.ToByte(false),
LfUnderline = Convert.ToByte(false),
LfStrikeOut = Convert.ToByte(0),
LfCharSet = Convert.ToByte(0), // ANSI_CHARSET
LfOutPrecision = Convert.ToByte(0), // OUT_DEFAULT_PRECIS
LfClipPrecision = Convert.ToByte(0),
LfQuality = Convert.ToByte(0),
LfPitchAndFamily = Convert.ToByte(0),
LfFaceName = "valid-font",
};
return logFont;
}
private RECT GetRectangle(int left, int top, int right, int bottom)
{
var rect = new RECT();
rect.Left = left;
rect.Top = top;
rect.Right = right;
rect.Bottom = bottom;
var rect = new RECT
{
Left = left,
Top = top,
Right = right,
Bottom = bottom,
};
return rect;
}

View file

@ -27,8 +27,8 @@ namespace UnitTests_PreviewHandlerCommon
}
[DataTestMethod]
[DataRow((uint)0)]
[DataRow((uint)1)]
[DataRow(0U)]
[DataRow(1U)]
public void StreamBasedPreviewHandler_ShouldSetStream_WhenInitializeCalled(uint grfMode)
{
// Arrange

View file

@ -2,16 +2,14 @@
// The Microsoft Corporation licenses this file to you under the MIT license.
// 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.IO;
using System.Linq;
using System.Net.Sockets;
using System.Runtime.InteropServices;
using System.Runtime.InteropServices.ComTypes;
using Common.Utilities;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Moq;
namespace UnitTests_PreviewHandlerCommon
{
@ -84,8 +82,10 @@ namespace UnitTests_PreviewHandlerCommon
// Arrange
long streamLength = 5;
var stremMock = new Mock<IStream>();
var stat = new System.Runtime.InteropServices.ComTypes.STATSTG();
stat.cbSize = streamLength;
var stat = new System.Runtime.InteropServices.ComTypes.STATSTG
{
cbSize = streamLength,
};
stremMock
.Setup(x => x.Stat(out stat, It.IsAny<int>()));
@ -131,22 +131,23 @@ namespace UnitTests_PreviewHandlerCommon
int expectedDwOrigin = 0; // STREAM_SEEK_SET
var stremMock = new Mock<IStream>();
var streamWrapper = new StreamWrapper(stremMock.Object);
// Act
streamWrapper.Position = positionToSet;
var streamWrapper = new StreamWrapper(stremMock.Object)
{
// Act
Position = positionToSet,
};
// Assert
stremMock.Verify(_ => _.Seek(It.Is<long>(offset => offset == positionToSet), It.Is<int>(dworigin => dworigin == expectedDwOrigin), It.IsAny<IntPtr>()), Times.Once);
}
[DataTestMethod]
[DataRow((long)0, SeekOrigin.Begin)]
[DataRow((long)5, SeekOrigin.Begin)]
[DataRow((long)0, SeekOrigin.Current)]
[DataRow((long)5, SeekOrigin.Current)]
[DataRow((long)0, SeekOrigin.End)]
[DataRow((long)5, SeekOrigin.End)]
[DataRow(0L, SeekOrigin.Begin)]
[DataRow(5L, SeekOrigin.Begin)]
[DataRow(0L, SeekOrigin.Current)]
[DataRow(5L, SeekOrigin.Current)]
[DataRow(0L, SeekOrigin.End)]
[DataRow(5L, SeekOrigin.End)]
public void StreamWrapper_ShouldCallIStreamSeekWithValidArguments_WhenSeekCalled(long offset, SeekOrigin origin)
{
// Arrange
@ -326,7 +327,5 @@ namespace UnitTests_PreviewHandlerCommon
// Assert
Assert.IsNotNull(exception);
}
}
}

View file

@ -98,6 +98,21 @@
<SubType>Component</SubType>
</Compile>
</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>
<PackageReference Include="Moq">
<Version>4.14.5</Version>

View file

@ -2,9 +2,9 @@
// The Microsoft Corporation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using System.Reflection;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using PreviewHandlerCommon;
using System.Reflection;
namespace UnitTests_PreviewHandlerCommon
{