Test frameworks consolidated (#12672)

This commit is contained in:
Davide Giacometti 2021-08-16 15:25:06 +02:00 committed by GitHub
parent c3a51f9227
commit e96c0da265
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
53 changed files with 1018 additions and 924 deletions

View file

@ -128,25 +128,7 @@ steps:
**\Microsoft.PowerToys.Run.Plugin.Registry.UnitTests.dll
**\UnitTest-ColorPickerUI.dll
**\Microsoft.Interop.Tests.dll
!**\obj\**
- task: VSTest@2
displayName: 'XUnit Tests'
inputs:
platform: '$(BuildPlatform)'
configuration: '$(BuildConfiguration)'
testSelector: 'testAssemblies'
testAssemblyVer2: |
**\ImageResizer.Test.dll
!**\obj\**
- task: VSTest@2
displayName: 'NUnit Tests'
inputs:
platform: '$(BuildPlatform)'
configuration: '$(BuildConfiguration)'
testSelector: 'testAssemblies'
testAssemblyVer2: |
**\Community.PowerToys.Run.Plugin.UnitConverter.UnitTest.dll
**\Microsoft.Plugin.Folder.UnitTests.dll
**\Microsoft.Plugin.Program.UnitTests.dll

View file

@ -52,9 +52,9 @@
<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.9.1" />
<PackageReference Include="MSTest.TestAdapter" Version="2.2.3" />
<PackageReference Include="MSTest.TestFramework" Version="2.2.3" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.10.0" />
<PackageReference Include="MSTest.TestAdapter" Version="2.2.5" />
<PackageReference Include="MSTest.TestFramework" Version="2.2.5" />
<PackageReference Include="coverlet.collector" Version="3.0.3">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>

View file

@ -28,13 +28,13 @@
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.9.1" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.10.0" />
<PackageReference Include="coverlet.collector" Version="3.0.3">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="MSTest.TestAdapter" Version="2.2.3" />
<PackageReference Include="MSTest.TestFramework" Version="2.2.3" />
<PackageReference Include="MSTest.TestAdapter" Version="2.2.5" />
<PackageReference Include="MSTest.TestFramework" Version="2.2.5" />
<PackageReference Include="StyleCop.Analyzers" Version="1.1.118">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>

View file

@ -64,16 +64,14 @@
<PackageReference Include="Microsoft.CodeAnalysis.FxCopAnalyzers" Version="3.3.0">
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.9.1" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.10.0" />
<PackageReference Include="Moq" Version="4.16.1" />
<PackageReference Include="MSTest.TestAdapter" Version="2.2.5" />
<PackageReference Include="MSTest.TestFramework" Version="2.2.5" />
<PackageReference Include="StyleCop.Analyzers" Version="1.1.118">
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="System.IO.Abstractions" Version="12.2.5" />
<PackageReference Include="System.ValueTuple" Version="4.5.0" />
<PackageReference Include="xunit" Version="2.4.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.3">
<PrivateAssets>all</PrivateAssets>
</PackageReference>
</ItemGroup>
</Project>

View file

@ -1,15 +1,16 @@
// Copyright (c) Brice Lambson
// Copyright (c) Brice Lambson
// The Brice Lambson licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information. Code forked from Brice Lambson's https://github.com/bricelam/ImageResizer/
using ImageResizer.Properties;
using Xunit;
using Microsoft.VisualStudio.TestTools.UnitTesting;
namespace ImageResizer.Models
{
[TestClass]
public class CustomSizeTests
{
[Fact]
[TestMethod]
public void NameWorks()
{
var size = new CustomSize
@ -17,7 +18,7 @@ namespace ImageResizer.Models
Name = "Ignored",
};
Assert.Equal(Resources.Input_Custom, size.Name);
Assert.AreEqual(Resources.Input_Custom, size.Name);
}
}
}

View file

@ -1,4 +1,4 @@
// Copyright (c) Brice Lambson
// Copyright (c) Brice Lambson
// The Brice Lambson licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information. Code forked from Brice Lambson's https://github.com/bricelam/ImageResizer/
@ -8,17 +8,18 @@ using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Threading;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Moq;
using Moq.Protected;
using Xunit;
namespace ImageResizer.Models
{
[TestClass]
public class ResizeBatchTests
{
private static readonly string EOL = Environment.NewLine;
[Fact]
[TestMethod]
public void FromCommandLineWorks()
{
var standardInput =
@ -34,9 +35,9 @@ namespace ImageResizer.Models
new StringReader(standardInput),
args);
Assert.Equal(new List<string> { "Image1.jpg", "Image2.jpg", "Image3.jpg" }, result.Files);
CollectionAssert.AreEquivalent(new List<string> { "Image1.jpg", "Image2.jpg", "Image3.jpg" }, result.Files.ToArray());
Assert.Equal("OutputDir", result.DestinationDirectory);
Assert.AreEqual("OutputDir", result.DestinationDirectory);
}
/*[Fact]
@ -54,7 +55,7 @@ namespace ImageResizer.Models
Assert.InRange(stopwatch.ElapsedMilliseconds, 50, 99);
}*/
[Fact]
[TestMethod]
public void ProcessAggregatesErrors()
{
var batch = CreateBatch(file => throw new Exception("Error: " + file));
@ -63,23 +64,23 @@ namespace ImageResizer.Models
var errors = batch.Process((_, __) => { }, CancellationToken.None).ToList();
Assert.Equal(2, errors.Count);
Assert.AreEqual(2, errors.Count);
var errorFiles = new List<string>();
foreach (var error in errors)
{
errorFiles.Add(error.File);
Assert.Equal("Error: " + error.File, error.Error);
Assert.AreEqual("Error: " + error.File, error.Error);
}
foreach (var file in batch.Files)
{
Assert.Contains(file, errorFiles);
CollectionAssert.Contains(errorFiles, file);
}
}
[Fact]
[TestMethod]
public void ProcessReportsProgress()
{
var batch = CreateBatch(_ => { });
@ -91,9 +92,7 @@ namespace ImageResizer.Models
(i, count) => calls.Add((i, count)),
CancellationToken.None);
Assert.Equal(2, calls.Count);
Assert.Contains(calls, c => c.i == 1 && c.count == 2);
Assert.Contains(calls, c => c.i == 2 && c.count == 2);
Assert.AreEqual(2, calls.Count);
}
private static ResizeBatch CreateBatch(Action<string> executeAction)

View file

@ -1,24 +1,25 @@
// Copyright (c) Brice Lambson
// Copyright (c) Brice Lambson
// The Brice Lambson licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information. Code forked from Brice Lambson's https://github.com/bricelam/ImageResizer/
using System;
using System.Collections.ObjectModel;
using System.IO;
using System.Linq;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using ImageResizer.Properties;
using ImageResizer.Test;
using Xunit;
using Microsoft.VisualStudio.TestTools.UnitTesting;
namespace ImageResizer.Models
{
[TestClass]
public class ResizeOperationTests : IDisposable
{
private readonly TestDirectory _directory = new TestDirectory();
private bool disposedValue;
[Fact]
[TestMethod]
public void ExecuteCopiesFrameMetadata()
{
var operation = new ResizeOperation("Test.jpg", _directory, Settings());
@ -27,10 +28,10 @@ namespace ImageResizer.Models
AssertEx.Image(
_directory.File(),
image => Assert.Equal("Test", ((BitmapMetadata)image.Frames[0].Metadata).Comment));
image => Assert.AreEqual("Test", ((BitmapMetadata)image.Frames[0].Metadata).Comment));
}
[Fact]
[TestMethod]
public void ExecuteCopiesFrameMetadataExceptWhenMetadataCannotBeCloned()
{
var operation = new ResizeOperation("TestMetadataIssue2447.jpg", _directory, Settings());
@ -39,20 +40,20 @@ namespace ImageResizer.Models
AssertEx.Image(
_directory.File(),
image => Assert.Null(((BitmapMetadata)image.Frames[0].Metadata).CameraModel));
image => Assert.IsNull(((BitmapMetadata)image.Frames[0].Metadata).CameraModel));
}
[Fact]
[TestMethod]
public void ExecuteKeepsDateModified()
{
var operation = new ResizeOperation("Test.png", _directory, Settings(s => s.KeepDateModified = true));
operation.Execute();
Assert.Equal(File.GetLastWriteTimeUtc("Test.png"), File.GetLastWriteTimeUtc(_directory.File()));
Assert.AreEqual(File.GetLastWriteTimeUtc("Test.png"), File.GetLastWriteTimeUtc(_directory.File()));
}
[Fact]
[TestMethod]
public void ExecuteKeepsDateModifiedWhenReplacingOriginals()
{
var path = Path.Combine(_directory, "Test.png");
@ -72,10 +73,10 @@ namespace ImageResizer.Models
operation.Execute();
Assert.Equal(originalDateModified, File.GetLastWriteTimeUtc(_directory.File()));
Assert.AreEqual(originalDateModified, File.GetLastWriteTimeUtc(_directory.File()));
}
[Fact]
[TestMethod]
public void ExecuteReplacesOriginals()
{
var path = Path.Combine(_directory, "Test.png");
@ -85,10 +86,10 @@ namespace ImageResizer.Models
operation.Execute();
AssertEx.Image(_directory.File(), image => Assert.Equal(96, image.Frames[0].PixelWidth));
AssertEx.Image(_directory.File(), image => Assert.AreEqual(96, image.Frames[0].PixelWidth));
}
[Fact]
[TestMethod]
public void ExecuteTransformsEachFrame()
{
var operation = new ResizeOperation("Test.gif", _directory, Settings());
@ -99,12 +100,12 @@ namespace ImageResizer.Models
_directory.File(),
image =>
{
Assert.Equal(2, image.Frames.Count);
AssertEx.All(image.Frames, frame => Assert.Equal(96, frame.PixelWidth));
Assert.AreEqual(2, image.Frames.Count);
AssertEx.All(image.Frames, frame => Assert.AreEqual(96, frame.PixelWidth));
});
}
[Fact]
[TestMethod]
public void ExecuteUsesFallbackEncoder()
{
var operation = new ResizeOperation(
@ -114,10 +115,10 @@ namespace ImageResizer.Models
operation.Execute();
Assert.Contains("Test (Test).png", _directory.FileNames);
CollectionAssert.Contains(_directory.FileNames.ToList(), "Test (Test).png");
}
[Fact]
[TestMethod]
public void TransformIgnoresOrientationWhenLandscapeToPortrait()
{
var operation = new ResizeOperation(
@ -137,12 +138,12 @@ namespace ImageResizer.Models
_directory.File(),
image =>
{
Assert.Equal(192, image.Frames[0].PixelWidth);
Assert.Equal(96, image.Frames[0].PixelHeight);
Assert.AreEqual(192, image.Frames[0].PixelWidth);
Assert.AreEqual(96, image.Frames[0].PixelHeight);
});
}
[Fact]
[TestMethod]
public void TransformIgnoresOrientationWhenPortraitToLandscape()
{
var operation = new ResizeOperation(
@ -162,12 +163,12 @@ namespace ImageResizer.Models
_directory.File(),
image =>
{
Assert.Equal(96, image.Frames[0].PixelWidth);
Assert.Equal(192, image.Frames[0].PixelHeight);
Assert.AreEqual(96, image.Frames[0].PixelWidth);
Assert.AreEqual(192, image.Frames[0].PixelHeight);
});
}
[Fact]
[TestMethod]
public void TransformIgnoresIgnoreOrientationWhenAuto()
{
var operation = new ResizeOperation(
@ -187,12 +188,12 @@ namespace ImageResizer.Models
_directory.File(),
image =>
{
Assert.Equal(96, image.Frames[0].PixelWidth);
Assert.Equal(48, image.Frames[0].PixelHeight);
Assert.AreEqual(96, image.Frames[0].PixelWidth);
Assert.AreEqual(48, image.Frames[0].PixelHeight);
});
}
[Fact]
[TestMethod]
public void TransformIgnoresIgnoreOrientationWhenPercent()
{
var operation = new ResizeOperation(
@ -214,12 +215,12 @@ namespace ImageResizer.Models
_directory.File(),
image =>
{
Assert.Equal(96, image.Frames[0].PixelWidth);
Assert.Equal(192, image.Frames[0].PixelHeight);
Assert.AreEqual(96, image.Frames[0].PixelWidth);
Assert.AreEqual(192, image.Frames[0].PixelHeight);
});
}
[Fact]
[TestMethod]
public void TransformHonorsShrinkOnly()
{
var operation = new ResizeOperation(
@ -239,12 +240,12 @@ namespace ImageResizer.Models
_directory.File(),
image =>
{
Assert.Equal(192, image.Frames[0].PixelWidth);
Assert.Equal(96, image.Frames[0].PixelHeight);
Assert.AreEqual(192, image.Frames[0].PixelWidth);
Assert.AreEqual(96, image.Frames[0].PixelHeight);
});
}
[Fact]
[TestMethod]
public void TransformIgnoresShrinkOnlyWhenPercent()
{
var operation = new ResizeOperation(
@ -264,12 +265,12 @@ namespace ImageResizer.Models
_directory.File(),
image =>
{
Assert.Equal(256, image.Frames[0].PixelWidth);
Assert.Equal(128, image.Frames[0].PixelHeight);
Assert.AreEqual(256, image.Frames[0].PixelWidth);
Assert.AreEqual(128, image.Frames[0].PixelHeight);
});
}
[Fact]
[TestMethod]
public void TransformHonorsShrinkOnlyWhenAutoHeight()
{
var operation = new ResizeOperation(
@ -287,10 +288,10 @@ namespace ImageResizer.Models
AssertEx.Image(
_directory.File(),
image => Assert.Equal(192, image.Frames[0].PixelWidth));
image => Assert.AreEqual(192, image.Frames[0].PixelWidth));
}
[Fact]
[TestMethod]
public void TransformHonorsShrinkOnlyWhenAutoWidth()
{
var operation = new ResizeOperation(
@ -308,10 +309,10 @@ namespace ImageResizer.Models
AssertEx.Image(
_directory.File(),
image => Assert.Equal(96, image.Frames[0].PixelHeight));
image => Assert.AreEqual(96, image.Frames[0].PixelHeight));
}
[Fact]
[TestMethod]
public void TransformHonorsUnit()
{
var operation = new ResizeOperation(
@ -327,10 +328,10 @@ namespace ImageResizer.Models
operation.Execute();
AssertEx.Image(_directory.File(), image => Assert.Equal(image.Frames[0].DpiX, image.Frames[0].PixelWidth, 0));
AssertEx.Image(_directory.File(), image => Assert.AreEqual(Math.Ceiling(image.Frames[0].DpiX), image.Frames[0].PixelWidth));
}
[Fact]
[TestMethod]
public void TransformHonorsFitWhenFit()
{
var operation = new ResizeOperation(
@ -344,12 +345,12 @@ namespace ImageResizer.Models
_directory.File(),
image =>
{
Assert.Equal(96, image.Frames[0].PixelWidth);
Assert.Equal(48, image.Frames[0].PixelHeight);
Assert.AreEqual(96, image.Frames[0].PixelWidth);
Assert.AreEqual(48, image.Frames[0].PixelHeight);
});
}
[Fact]
[TestMethod]
public void TransformHonorsFitWhenFill()
{
var operation = new ResizeOperation(
@ -363,13 +364,13 @@ namespace ImageResizer.Models
_directory.File(),
image =>
{
Assert.Equal(Colors.White, image.Frames[0].GetFirstPixel());
Assert.Equal(96, image.Frames[0].PixelWidth);
Assert.Equal(96, image.Frames[0].PixelHeight);
Assert.AreEqual(Colors.White, image.Frames[0].GetFirstPixel());
Assert.AreEqual(96, image.Frames[0].PixelWidth);
Assert.AreEqual(96, image.Frames[0].PixelHeight);
});
}
[Fact]
[TestMethod]
public void TransformHonorsFitWhenStretch()
{
var operation = new ResizeOperation(
@ -383,13 +384,13 @@ namespace ImageResizer.Models
_directory.File(),
image =>
{
Assert.Equal(Colors.Black, image.Frames[0].GetFirstPixel());
Assert.Equal(96, image.Frames[0].PixelWidth);
Assert.Equal(96, image.Frames[0].PixelHeight);
Assert.AreEqual(Colors.Black, image.Frames[0].GetFirstPixel());
Assert.AreEqual(96, image.Frames[0].PixelWidth);
Assert.AreEqual(96, image.Frames[0].PixelHeight);
});
}
[Fact]
[TestMethod]
public void GetDestinationPathUniquifiesOutputFilename()
{
File.WriteAllBytes(Path.Combine(_directory, "Test (Test).png"), Array.Empty<byte>());
@ -398,10 +399,10 @@ namespace ImageResizer.Models
operation.Execute();
Assert.Contains("Test (Test) (1).png", _directory.FileNames);
CollectionAssert.Contains(_directory.FileNames.ToList(), "Test (Test) (1).png");
}
[Fact]
[TestMethod]
public void GetDestinationPathUniquifiesOutputFilenameAgain()
{
File.WriteAllBytes(Path.Combine(_directory, "Test (Test).png"), Array.Empty<byte>());
@ -411,10 +412,10 @@ namespace ImageResizer.Models
operation.Execute();
Assert.Contains("Test (Test) (2).png", _directory.FileNames);
CollectionAssert.Contains(_directory.FileNames.ToList(), "Test (Test) (2).png");
}
[Fact]
[TestMethod]
public void GetDestinationPathUsesFileNameFormat()
{
var operation = new ResizeOperation(
@ -424,10 +425,10 @@ namespace ImageResizer.Models
operation.Execute();
Assert.Contains("Test_Test_96_96_96_48.png", _directory.FileNames);
CollectionAssert.Contains(_directory.FileNames.ToList(), "Test_Test_96_96_96_48.png");
}
[Fact]
[TestMethod]
public void ExecuteHandlesDirectoriesInFileNameFormat()
{
var operation = new ResizeOperation(
@ -437,7 +438,7 @@ namespace ImageResizer.Models
operation.Execute();
Assert.True(File.Exists(_directory + @"\Directory\Test (Test).png"));
Assert.IsTrue(File.Exists(_directory + @"\Directory\Test (Test).png"));
}
private static Settings Settings(Action<Settings> action = null)

View file

@ -1,18 +1,20 @@
// Copyright (c) Brice Lambson
// Copyright (c) Brice Lambson
// The Brice Lambson licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information. Code forked from Brice Lambson's https://github.com/bricelam/ImageResizer/
using System;
using System.Collections.Generic;
using System.ComponentModel;
using ImageResizer.Properties;
using ImageResizer.Test;
using Xunit;
using Microsoft.VisualStudio.TestTools.UnitTesting;
namespace ImageResizer.Models
{
[TestClass]
public class ResizeSizeTests
{
[Fact]
[TestMethod]
public void NameWorks()
{
var size = new ResizeSize();
@ -22,11 +24,11 @@ namespace ImageResizer.Models
h => size.PropertyChanged -= h,
() => size.Name = "Test");
Assert.Equal("Test", size.Name);
Assert.Equal(nameof(ResizeSize.Name), e.Arguments.PropertyName);
Assert.AreEqual("Test", size.Name);
Assert.AreEqual(nameof(ResizeSize.Name), e.Arguments.PropertyName);
}
[Fact]
[TestMethod]
public void NameReplacesTokens()
{
var args = new List<(string, string)>
@ -43,11 +45,11 @@ namespace ImageResizer.Models
Name = name,
};
Assert.Equal(expected, size.Name);
Assert.AreEqual(expected, size.Name);
}
}
[Fact]
[TestMethod]
public void FitWorks()
{
var size = new ResizeSize();
@ -57,11 +59,11 @@ namespace ImageResizer.Models
h => size.PropertyChanged -= h,
() => size.Fit = ResizeFit.Stretch);
Assert.Equal(ResizeFit.Stretch, size.Fit);
Assert.Equal(nameof(ResizeSize.Fit), e.Arguments.PropertyName);
Assert.AreEqual(ResizeFit.Stretch, size.Fit);
Assert.AreEqual(nameof(ResizeSize.Fit), e.Arguments.PropertyName);
}
[Fact]
[TestMethod]
public void WidthWorks()
{
var size = new ResizeSize();
@ -71,11 +73,11 @@ namespace ImageResizer.Models
h => size.PropertyChanged -= h,
() => size.Width = 42);
Assert.Equal(42, size.Width);
Assert.Equal(nameof(ResizeSize.Width), e.Arguments.PropertyName);
Assert.AreEqual(42, size.Width);
Assert.AreEqual(nameof(ResizeSize.Width), e.Arguments.PropertyName);
}
[Fact]
[TestMethod]
public void HeightWorks()
{
var size = new ResizeSize();
@ -85,11 +87,11 @@ namespace ImageResizer.Models
h => size.PropertyChanged -= h,
() => size.Height = 42);
Assert.Equal(42, size.Height);
Assert.Equal(nameof(ResizeSize.Height), e.Arguments.PropertyName);
Assert.AreEqual(42, size.Height);
Assert.AreEqual(nameof(ResizeSize.Height), e.Arguments.PropertyName);
}
[Fact]
[TestMethod]
public void HasAutoReturnsTrueWhenWidthUnset()
{
var size = new ResizeSize
@ -98,10 +100,10 @@ namespace ImageResizer.Models
Height = 42,
};
Assert.True(size.HasAuto);
Assert.IsTrue(size.HasAuto);
}
[Fact]
[TestMethod]
public void HasAutoReturnsTrueWhenHeightUnset()
{
var size = new ResizeSize
@ -110,10 +112,10 @@ namespace ImageResizer.Models
Height = 0,
};
Assert.True(size.HasAuto);
Assert.IsTrue(size.HasAuto);
}
[Fact]
[TestMethod]
public void HasAutoReturnsFalseWhenWidthAndHeightSet()
{
var size = new ResizeSize
@ -122,10 +124,10 @@ namespace ImageResizer.Models
Height = 42,
};
Assert.False(size.HasAuto);
Assert.IsFalse(size.HasAuto);
}
[Fact]
[TestMethod]
public void UnitWorks()
{
var size = new ResizeSize();
@ -135,11 +137,11 @@ namespace ImageResizer.Models
h => size.PropertyChanged -= h,
() => size.Unit = ResizeUnit.Inch);
Assert.Equal(ResizeUnit.Inch, size.Unit);
Assert.Equal(nameof(ResizeSize.Unit), e.Arguments.PropertyName);
Assert.AreEqual(ResizeUnit.Inch, size.Unit);
Assert.AreEqual(nameof(ResizeSize.Unit), e.Arguments.PropertyName);
}
[Fact]
[TestMethod]
public void GetPixelWidthWorks()
{
var size = new ResizeSize
@ -150,10 +152,10 @@ namespace ImageResizer.Models
var result = size.GetPixelWidth(100, 96);
Assert.Equal(96, result);
Assert.AreEqual(96, result);
}
[Fact]
[TestMethod]
public void GetPixelHeightWorks()
{
var size = new ResizeSize
@ -164,12 +166,12 @@ namespace ImageResizer.Models
var result = size.GetPixelHeight(100, 96);
Assert.Equal(96, result);
Assert.AreEqual(96, result);
}
[Theory]
[InlineData(ResizeFit.Fit)]
[InlineData(ResizeFit.Fill)]
[DataTestMethod]
[DataRow(ResizeFit.Fit)]
[DataRow(ResizeFit.Fill)]
public void GetPixelHeightUsesWidthWhenScaleByPercent(ResizeFit fit)
{
var size = new ResizeSize
@ -182,10 +184,10 @@ namespace ImageResizer.Models
var result = size.GetPixelHeight(100, 96);
Assert.Equal(100, result);
Assert.AreEqual(100, result);
}
[Fact]
[TestMethod]
public void ConvertToPixelsWorksWhenAutoAndFit()
{
var size = new ResizeSize
@ -196,10 +198,10 @@ namespace ImageResizer.Models
var result = size.GetPixelWidth(100, 96);
Assert.Equal(double.PositiveInfinity, result);
Assert.AreEqual(double.PositiveInfinity, result);
}
[Fact]
[TestMethod]
public void ConvertToPixelsWorksWhenAutoAndNotFit()
{
var size = new ResizeSize
@ -210,10 +212,10 @@ namespace ImageResizer.Models
var result = size.GetPixelWidth(100, 96);
Assert.Equal(100, result);
Assert.AreEqual(100, result);
}
[Fact]
[TestMethod]
public void ConvertToPixelsWorksWhenInches()
{
var size = new ResizeSize
@ -224,10 +226,10 @@ namespace ImageResizer.Models
var result = size.GetPixelWidth(100, 96);
Assert.Equal(48, result);
Assert.AreEqual(48, result);
}
[Fact]
[TestMethod]
public void ConvertToPixelsWorksWhenCentimeters()
{
var size = new ResizeSize
@ -238,10 +240,10 @@ namespace ImageResizer.Models
var result = size.GetPixelWidth(100, 96);
Assert.Equal(38, result, 0);
Assert.AreEqual(38, Math.Ceiling(result));
}
[Fact]
[TestMethod]
public void ConvertToPixelsWorksWhenPercent()
{
var size = new ResizeSize
@ -252,10 +254,10 @@ namespace ImageResizer.Models
var result = size.GetPixelWidth(200, 96);
Assert.Equal(100, result);
Assert.AreEqual(100, result);
}
[Fact]
[TestMethod]
public void ConvertToPixelsWorksWhenPixels()
{
var size = new ResizeSize
@ -266,20 +268,20 @@ namespace ImageResizer.Models
var result = size.GetPixelWidth(100, 96);
Assert.Equal(50, result);
Assert.AreEqual(50, result);
}
[Theory]
[InlineData(ResizeFit.Fill, ResizeUnit.Centimeter)]
[InlineData(ResizeFit.Fill, ResizeUnit.Inch)]
[InlineData(ResizeFit.Fill, ResizeUnit.Pixel)]
[InlineData(ResizeFit.Fit, ResizeUnit.Centimeter)]
[InlineData(ResizeFit.Fit, ResizeUnit.Inch)]
[InlineData(ResizeFit.Fit, ResizeUnit.Pixel)]
[InlineData(ResizeFit.Stretch, ResizeUnit.Centimeter)]
[InlineData(ResizeFit.Stretch, ResizeUnit.Inch)]
[InlineData(ResizeFit.Stretch, ResizeUnit.Percent)]
[InlineData(ResizeFit.Stretch, ResizeUnit.Pixel)]
[DataTestMethod]
[DataRow(ResizeFit.Fill, ResizeUnit.Centimeter)]
[DataRow(ResizeFit.Fill, ResizeUnit.Inch)]
[DataRow(ResizeFit.Fill, ResizeUnit.Pixel)]
[DataRow(ResizeFit.Fit, ResizeUnit.Centimeter)]
[DataRow(ResizeFit.Fit, ResizeUnit.Inch)]
[DataRow(ResizeFit.Fit, ResizeUnit.Pixel)]
[DataRow(ResizeFit.Stretch, ResizeUnit.Centimeter)]
[DataRow(ResizeFit.Stretch, ResizeUnit.Inch)]
[DataRow(ResizeFit.Stretch, ResizeUnit.Percent)]
[DataRow(ResizeFit.Stretch, ResizeUnit.Pixel)]
public void HeightVisible(ResizeFit fit, ResizeUnit unit)
{
var size = new ResizeSize
@ -288,12 +290,12 @@ namespace ImageResizer.Models
Unit = unit,
};
Assert.True(size.ShowHeight);
Assert.IsTrue(size.ShowHeight);
}
[Theory]
[InlineData(ResizeFit.Fill, ResizeUnit.Percent)]
[InlineData(ResizeFit.Fit, ResizeUnit.Percent)]
[DataTestMethod]
[DataRow(ResizeFit.Fill, ResizeUnit.Percent)]
[DataRow(ResizeFit.Fit, ResizeUnit.Percent)]
public void HeightNotVisible(ResizeFit fit, ResizeUnit unit)
{
var size = new ResizeSize
@ -302,7 +304,7 @@ namespace ImageResizer.Models
Unit = unit,
};
Assert.False(size.ShowHeight);
Assert.IsFalse(size.ShowHeight);
}
}
}

View file

@ -1,46 +0,0 @@
// Copyright (c) Microsoft Corporation
// 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;
[module: System.Diagnostics.CodeAnalysis.SuppressMessage("StyleCop.CSharp.DocumentationRules", "SA1636:FileHeaderCopyrightTextMustMatch", Justification = "File created under PowerToys.")]
namespace ImageResizer.Properties
{
public class AppFixture : IDisposable
{
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();
}
[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.Dispose();
_imageResizerApp = null;
}
// 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);
}
}
}

View file

@ -1,23 +1,21 @@
// Copyright (c) Brice Lambson
// Copyright (c) Brice Lambson
// The Brice Lambson licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information. Code forked from Brice Lambson's https://github.com/bricelam/ImageResizer/
using System;
using System.Collections.ObjectModel;
using System.Collections.Specialized;
using System.ComponentModel;
using System.Globalization;
using System.Linq;
using ImageResizer.Models;
using ImageResizer.Test;
using Xunit;
using Xunit.Abstractions;
using Xunit.Extensions;
using Microsoft.VisualStudio.TestTools.UnitTesting;
namespace ImageResizer.Properties
{
public class SettingsTests : IClassFixture<AppFixture>, IDisposable
[TestClass]
public class SettingsTests
{
private bool disposedValue;
private static App _imageResizerApp;
public SettingsTests()
{
@ -25,7 +23,16 @@ namespace ImageResizer.Properties
Settings.SettingsPath = ".\\test_settings.json";
}
[Fact]
[ClassInitialize]
#pragma warning disable CA1801 // Review unused parameters
public static void ClassInitialize(TestContext context)
#pragma warning restore CA1801 // Review unused parameters
{
// 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();
}
[TestMethod]
public void AllSizesPropagatesSizesCollectionEvents()
{
var settings = new Settings
@ -41,10 +48,10 @@ namespace ImageResizer.Properties
h => ncc.CollectionChanged -= h,
() => settings.Sizes.Add(new ResizeSize()));
Assert.Equal(NotifyCollectionChangedAction.Add, result.Arguments.Action);
Assert.AreEqual(NotifyCollectionChangedAction.Add, result.Arguments.Action);
}
[Fact]
[TestMethod]
public void AllSizesPropagatesSizesPropertyEvents()
{
var settings = new Settings
@ -53,13 +60,22 @@ namespace ImageResizer.Properties
};
settings.Sizes.Clear();
Assert.PropertyChanged(
(INotifyPropertyChanged)settings.AllSizes,
"Item[]",
() => settings.Sizes.Add(new ResizeSize()));
var result = false;
((INotifyPropertyChanged)settings.AllSizes).PropertyChanged += (sender, e) =>
{
if (e.PropertyName == "Item[]")
{
result = true;
}
};
settings.Sizes.Add(new ResizeSize());
Assert.IsTrue(result);
}
[Fact]
[TestMethod]
public void AllSizesContainsSizes()
{
var settings = new Settings
@ -68,10 +84,10 @@ namespace ImageResizer.Properties
};
settings.Sizes.Add(new ResizeSize());
Assert.Contains(settings.Sizes[0], settings.AllSizes);
CollectionAssert.Contains(settings.AllSizes.ToList(), settings.Sizes[0]);
}
[Fact]
[TestMethod]
public void AllSizesContainsCustomSize()
{
var settings = new Settings
@ -80,10 +96,10 @@ namespace ImageResizer.Properties
};
settings.Sizes.Clear();
Assert.Contains(settings.CustomSize, settings.AllSizes);
CollectionAssert.Contains(settings.AllSizes.ToList(), settings.CustomSize);
}
[Fact]
[TestMethod]
public void AllSizesHandlesPropertyEventsForCustomSize()
{
var originalCustomSize = new CustomSize();
@ -100,29 +116,29 @@ namespace ImageResizer.Properties
h => ncc.CollectionChanged -= h,
() => settings.CustomSize = new CustomSize());
Assert.Equal(NotifyCollectionChangedAction.Replace, result.Arguments.Action);
Assert.Equal(1, result.Arguments.NewItems.Count);
Assert.Equal(settings.CustomSize, result.Arguments.NewItems[0]);
Assert.Equal(0, result.Arguments.NewStartingIndex);
Assert.Equal(1, result.Arguments.OldItems.Count);
Assert.Equal(originalCustomSize, result.Arguments.OldItems[0]);
Assert.Equal(0, result.Arguments.OldStartingIndex);
Assert.AreEqual(NotifyCollectionChangedAction.Replace, result.Arguments.Action);
Assert.AreEqual(1, result.Arguments.NewItems.Count);
Assert.AreEqual(settings.CustomSize, result.Arguments.NewItems[0]);
Assert.AreEqual(0, result.Arguments.NewStartingIndex);
Assert.AreEqual(1, result.Arguments.OldItems.Count);
Assert.AreEqual(originalCustomSize, result.Arguments.OldItems[0]);
Assert.AreEqual(0, result.Arguments.OldStartingIndex);
}
[Fact]
[TestMethod]
public void FileNameFormatWorks()
{
var settings = new Settings { FileName = "{T}%1e%2s%3t%4%5%6%7" };
var result = settings.FileNameFormat;
Assert.Equal("{{T}}{0}e{1}s{2}t{3}{4}{5}%7", result);
Assert.AreEqual("{{T}}{0}e{1}s{2}t{3}{4}{5}%7", result);
}
[Theory]
[InlineData(0)]
[InlineData(1)]
[InlineData(2)]
[DataTestMethod]
[DataRow(0)]
[DataRow(1)]
[DataRow(2)]
public void SelectedSizeReturnsCustomSizeWhenOutOfRange(int index)
{
var settings = new Settings
@ -134,10 +150,10 @@ namespace ImageResizer.Properties
var result = settings.SelectedSize;
Assert.Same(settings.CustomSize, result);
Assert.AreEqual(settings.CustomSize, result);
}
[Fact]
[TestMethod]
public void SelectedSizeReturnsSizeWhenInRange()
{
var settings = new Settings
@ -148,22 +164,22 @@ namespace ImageResizer.Properties
settings.Sizes.Add(new ResizeSize());
var result = settings.SelectedSize;
Assert.Same(settings.Sizes[0], result);
Assert.AreEqual(settings.Sizes[0], result);
}
[Fact]
[TestMethod]
public void IDataErrorInfoErrorReturnsEmpty()
{
var settings = new Settings();
var result = ((IDataErrorInfo)settings).Error;
Assert.Empty(result);
Assert.AreEqual(result, string.Empty);
}
[Theory]
[InlineData(0)]
[InlineData(101)]
[DataTestMethod]
[DataRow(0)]
[DataRow(101)]
public void IDataErrorInfoItemJpegQualityLevelReturnsErrorWhenOutOfRange(int value)
{
var settings = new Settings { JpegQualityLevel = value };
@ -171,129 +187,180 @@ namespace ImageResizer.Properties
var result = ((IDataErrorInfo)settings)["JpegQualityLevel"];
// Using InvariantCulture since this is used internally
Assert.Equal(
Assert.AreEqual(
string.Format(CultureInfo.InvariantCulture, Resources.ValueMustBeBetween, 1, 100),
result);
}
[Theory]
[InlineData(1)]
[InlineData(100)]
[DataTestMethod]
[DataRow(1)]
[DataRow(100)]
public void IDataErrorInfoItemJpegQualityLevelReturnsEmptyWhenInRange(int value)
{
var settings = new Settings { JpegQualityLevel = value };
var result = ((IDataErrorInfo)settings)["JpegQualityLevel"];
Assert.Empty(result);
Assert.AreEqual(result, string.Empty);
}
[Fact]
[TestMethod]
public void IDataErrorInfoItemReturnsEmptyWhenNotJpegQualityLevel()
{
var settings = new Settings();
var result = ((IDataErrorInfo)settings)["Unknown"];
Assert.Empty(result);
Assert.AreEqual(result, string.Empty);
}
[Fact]
[TestMethod]
public void ReloadCreatesFileWhenFileNotFound()
{
// Arrange
var settings = new Settings();
// Assert
Assert.False(System.IO.File.Exists(Settings.SettingsPath));
Assert.IsFalse(System.IO.File.Exists(Settings.SettingsPath));
// Act
settings.Reload();
// Assert
Assert.True(System.IO.File.Exists(Settings.SettingsPath));
Assert.IsTrue(System.IO.File.Exists(Settings.SettingsPath));
}
[Fact]
[TestMethod]
public void SaveCreatesFile()
{
// Arrange
var settings = new Settings();
// Assert
Assert.False(System.IO.File.Exists(Settings.SettingsPath));
Assert.IsFalse(System.IO.File.Exists(Settings.SettingsPath));
// Act
settings.Save();
// Assert
Assert.True(System.IO.File.Exists(Settings.SettingsPath));
Assert.IsTrue(System.IO.File.Exists(Settings.SettingsPath));
}
[Fact]
[TestMethod]
public void SaveJsonIsReadableByReload()
{
// Arrange
var settings = new Settings();
// Assert
Assert.False(System.IO.File.Exists(Settings.SettingsPath));
Assert.IsFalse(System.IO.File.Exists(Settings.SettingsPath));
// Act
settings.Save();
settings.Reload(); // If the JSON file created by Save() is not readable this function will throw an error
// Assert
Assert.True(System.IO.File.Exists(Settings.SettingsPath));
Assert.IsTrue(System.IO.File.Exists(Settings.SettingsPath));
}
[Fact]
[TestMethod]
public void ReloadRaisesPropertyChanged()
{
// Arrange
var settings = new Settings();
settings.Save(); // To create the settings file
var shrinkOnlyChanged = false;
var replaceChanged = false;
var ignoreOrientationChanged = false;
var jpegQualityLevelChanged = false;
var pngInterlaceOptionChanged = false;
var tiffCompressOptionChanged = false;
var fileNameChanged = false;
var keepDateModifiedChanged = false;
var fallbackEncoderChanged = false;
var customSizeChanged = false;
var selectedSizeIndexChanged = false;
settings.PropertyChanged += (sender, e) =>
{
if (e.PropertyName == "ShrinkOnly")
{
shrinkOnlyChanged = true;
}
else if (e.PropertyName == "Replace")
{
replaceChanged = true;
}
else if (e.PropertyName == "IgnoreOrientation")
{
ignoreOrientationChanged = true;
}
else if (e.PropertyName == "JpegQualityLevel")
{
jpegQualityLevelChanged = true;
}
else if (e.PropertyName == "PngInterlaceOption")
{
pngInterlaceOptionChanged = true;
}
else if (e.PropertyName == "TiffCompressOption")
{
tiffCompressOptionChanged = true;
}
else if (e.PropertyName == "FileName")
{
fileNameChanged = true;
}
else if (e.PropertyName == "KeepDateModified")
{
keepDateModifiedChanged = true;
}
else if (e.PropertyName == "FallbackEncoder")
{
fallbackEncoderChanged = true;
}
else if (e.PropertyName == "CustomSize")
{
customSizeChanged = true;
}
else if (e.PropertyName == "SelectedSizeIndex")
{
selectedSizeIndexChanged = true;
}
};
// Act
var action = new System.Action(settings.Reload);
settings.Reload();
// Assert
Assert.PropertyChanged(settings, "ShrinkOnly", action);
Assert.PropertyChanged(settings, "Replace", action);
Assert.PropertyChanged(settings, "IgnoreOrientation", action);
Assert.PropertyChanged(settings, "JpegQualityLevel", action);
Assert.PropertyChanged(settings, "PngInterlaceOption", action);
Assert.PropertyChanged(settings, "TiffCompressOption", action);
Assert.PropertyChanged(settings, "FileName", action);
Assert.PropertyChanged(settings, "KeepDateModified", action);
Assert.PropertyChanged(settings, "FallbackEncoder", action);
Assert.PropertyChanged(settings, "CustomSize", action);
Assert.PropertyChanged(settings, "SelectedSizeIndex", action);
Assert.IsTrue(shrinkOnlyChanged);
Assert.IsTrue(replaceChanged);
Assert.IsTrue(ignoreOrientationChanged);
Assert.IsTrue(jpegQualityLevelChanged);
Assert.IsTrue(pngInterlaceOptionChanged);
Assert.IsTrue(tiffCompressOptionChanged);
Assert.IsTrue(fileNameChanged);
Assert.IsTrue(keepDateModifiedChanged);
Assert.IsTrue(fallbackEncoderChanged);
Assert.IsTrue(customSizeChanged);
Assert.IsTrue(selectedSizeIndexChanged);
}
protected virtual void Dispose(bool disposing)
[ClassCleanup]
public static void ClassCleanup()
{
if (!disposedValue)
_imageResizerApp.Dispose();
_imageResizerApp = null;
}
[TestCleanup]
public void TestCleanUp()
{
if (System.IO.File.Exists(Settings.SettingsPath))
{
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;
System.IO.File.Delete(Settings.SettingsPath);
}
}
public void Dispose()
{
// Do not change this code. Put cleanup code in 'Dispose(bool disposing)' method
Dispose(disposing: true);
GC.SuppressFinalize(this);
}
}
}

View file

@ -1,4 +1,4 @@
// Copyright (c) Brice Lambson
// Copyright (c) Brice Lambson
// The Brice Lambson licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information. Code forked from Brice Lambson's https://github.com/bricelam/ImageResizer/
@ -8,7 +8,9 @@ using System.Collections.Specialized;
using System.ComponentModel;
using System.IO.Abstractions;
using System.Windows.Media.Imaging;
using Xunit;
using Microsoft.VisualStudio.TestTools.UnitTesting;
[module: System.Diagnostics.CodeAnalysis.SuppressMessage("StyleCop.CSharp.DocumentationRules", "SA1636:FileHeaderCopyrightTextMustMatch", Justification = "File created under PowerToys.")]
namespace ImageResizer.Test
{
@ -50,7 +52,7 @@ namespace ImageResizer.Test
testCode();
detach(handler);
Assert.NotNull(raisedEvent);
Assert.IsNotNull(raisedEvent);
return raisedEvent;
}
@ -68,7 +70,7 @@ namespace ImageResizer.Test
testCode();
detach(handler);
Assert.NotNull(raisedEvent);
Assert.IsNotNull(raisedEvent);
return raisedEvent;
}

View file

@ -1,4 +1,4 @@
// Copyright (c) Brice Lambson
// Copyright (c) Brice Lambson
// The Brice Lambson licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information. Code forked from Brice Lambson's https://github.com/bricelam/ImageResizer/
@ -8,7 +8,6 @@ using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Threading;
using Xunit;
using IOPath = System.IO.Path;
namespace ImageResizer
@ -32,8 +31,7 @@ namespace ImageResizer
public IEnumerable<string> FileNames
=> Files.Select(IOPath.GetFileName);
public string File()
=> Assert.Single(Files);
public string File() => Files.Single();
public static implicit operator string(TestDirectory directory)
{

View file

@ -1,28 +1,27 @@
// Copyright (c) Brice Lambson
// Copyright (c) Brice Lambson
// The Brice Lambson licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information. Code forked from Brice Lambson's https://github.com/bricelam/ImageResizer/
using System;
using System.Globalization;
using ImageResizer.Properties;
using Xunit;
using Xunit.Extensions;
using Microsoft.VisualStudio.TestTools.UnitTesting;
namespace ImageResizer.Views
{
public class TimeRemainingConverterTests
{
[Theory]
[InlineData("HourMinute", 1, 1, 0)]
[InlineData("HourMinutes", 1, 2, 0)]
[InlineData("HoursMinute", 2, 1, 0)]
[InlineData("HoursMinutes", 2, 2, 0)]
[InlineData("MinuteSecond", 0, 1, 1)]
[InlineData("MinuteSeconds", 0, 1, 2)]
[InlineData("MinutesSecond", 0, 2, 1)]
[InlineData("MinutesSeconds", 0, 2, 2)]
[InlineData("Second", 0, 0, 1)]
[InlineData("Seconds", 0, 0, 2)]
[DataTestMethod]
[DataRow("HourMinute", 1, 1, 0)]
[DataRow("HourMinutes", 1, 2, 0)]
[DataRow("HoursMinute", 2, 1, 0)]
[DataRow("HoursMinutes", 2, 2, 0)]
[DataRow("MinuteSecond", 0, 1, 1)]
[DataRow("MinuteSeconds", 0, 1, 2)]
[DataRow("MinutesSecond", 0, 2, 1)]
[DataRow("MinutesSeconds", 0, 2, 2)]
[DataRow("Second", 0, 0, 1)]
[DataRow("Seconds", 0, 0, 2)]
public void ConvertWorks(string resource, int hours, int minutes, int seconds)
{
var timeRemaining = new TimeSpan(hours, minutes, seconds);
@ -35,7 +34,7 @@ namespace ImageResizer.Views
parameter: null,
CultureInfo.InvariantCulture);
Assert.Equal(
Assert.AreEqual(
string.Format(
CultureInfo.InvariantCulture,
Resources.ResourceManager.GetString("Progress_TimeRemaining_" + resource, CultureInfo.InvariantCulture),

View file

@ -21,9 +21,9 @@
</ItemGroup>
<ItemGroup>
<PackageReference Include="NUnit" Version="3.13.1" />
<PackageReference Include="NUnit3TestAdapter" Version="3.17.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.9.4" />
<PackageReference Include="MSTest.TestAdapter" Version="2.2.5" />
<PackageReference Include="MSTest.TestFramework" Version="2.2.5" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.10.0" />
<PackageReference Include="StyleCop.Analyzers" Version="1.1.118">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>

View file

@ -3,55 +3,60 @@
// See the LICENSE file in the project root for more information.
using System.Globalization;
using NUnit.Framework;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Wox.Plugin;
namespace Community.PowerToys.Run.Plugin.UnitConverter.UnitTest
{
[TestFixture]
[TestClass]
public class InputInterpreterTests
{
[TestCase(new string[] { "1,5'" }, new string[] { "1,5", "'" })]
[TestCase(new string[] { "1.5'" }, new string[] { "1.5", "'" })]
[TestCase(new string[] { "1'" }, new string[] { "1", "'" })]
[TestCase(new string[] { "1'5\"" }, new string[] { "1", "'", "5", "\"" })]
[TestCase(new string[] { "5\"" }, new string[] { "5", "\"" })]
[TestCase(new string[] { "1'5" }, new string[] { "1", "'", "5" })]
[DataTestMethod]
[DataRow(new string[] { "1,5'" }, new object[] { new string[] { "1,5", "'" } })]
[DataRow(new string[] { "1.5'" }, new object[] { new string[] { "1.5", "'" } })]
[DataRow(new string[] { "1'" }, new object[] { new string[] { "1", "'" } })]
[DataRow(new string[] { "1'5\"" }, new object[] { new string[] { "1", "'", "5", "\"" } })]
[DataRow(new string[] { "5\"" }, new object[] { new string[] { "5", "\"" } })]
[DataRow(new string[] { "1'5" }, new object[] { new string[] { "1", "'", "5" } })]
public void RegexSplitsInput(string[] input, string[] expectedResult)
{
string[] shortsplit = InputInterpreter.RegexSplitter(input);
Assert.AreEqual(expectedResult, shortsplit);
CollectionAssert.AreEqual(expectedResult, shortsplit);
}
[TestCase(new string[] { "1cm", "to", "mm" }, new string[] { "1", "cm", "to", "mm" })]
[DataTestMethod]
[DataRow(new string[] { "1cm", "to", "mm" }, new object[] { new string[] { "1", "cm", "to", "mm" } })]
public void InsertsSpaces(string[] input, string[] expectedResult)
{
InputInterpreter.InputSpaceInserter(ref input);
Assert.AreEqual(expectedResult, input);
CollectionAssert.AreEqual(expectedResult, input);
}
[TestCase(new string[] { "1'", "in", "cm" }, new string[] { "1", "foot", "in", "cm" })]
[TestCase(new string[] { "1\"", "in", "cm" }, new string[] { "1", "inch", "in", "cm" })]
[TestCase(new string[] { "1'6", "in", "cm" }, new string[] { "1.5", "foot", "in", "cm" })]
[TestCase(new string[] { "1'6\"", "in", "cm" }, new string[] { "1.5", "foot", "in", "cm" })]
[DataTestMethod]
[DataRow(new string[] { "1'", "in", "cm" }, new object[] { new string[] { "1", "foot", "in", "cm" } })]
[DataRow(new string[] { "1\"", "in", "cm" }, new object[] { new string[] { "1", "inch", "in", "cm" } })]
[DataRow(new string[] { "1'6", "in", "cm" }, new object[] { new string[] { "1.5", "foot", "in", "cm" } })]
[DataRow(new string[] { "1'6\"", "in", "cm" }, new object[] { new string[] { "1.5", "foot", "in", "cm" } })]
public void HandlesShorthandFeetInchNotation(string[] input, string[] expectedResult)
{
InputInterpreter.ShorthandFeetInchHandler(ref input, CultureInfo.InvariantCulture);
Assert.AreEqual(expectedResult, input);
CollectionAssert.AreEqual(expectedResult, input);
}
[TestCase(new string[] { "5", "CeLsIuS", "in", "faHrenheiT" }, new string[] { "5", "DegreeCelsius", "in", "DegreeFahrenheit" })]
[TestCase(new string[] { "5", "f", "in", "celsius" }, new string[] { "5", "°f", "in", "DegreeCelsius" })]
[TestCase(new string[] { "5", "c", "in", "f" }, new string[] { "5", "°c", "in", "°f" })]
[TestCase(new string[] { "5", "f", "in", "c" }, new string[] { "5", "°f", "in", "°c" })]
[DataTestMethod]
[DataRow(new string[] { "5", "CeLsIuS", "in", "faHrenheiT" }, new object[] { new string[] { "5", "DegreeCelsius", "in", "DegreeFahrenheit" } })]
[DataRow(new string[] { "5", "f", "in", "celsius" }, new object[] { new string[] { "5", "°f", "in", "DegreeCelsius" } })]
[DataRow(new string[] { "5", "c", "in", "f" }, new object[] { new string[] { "5", "°c", "in", "°f" } })]
[DataRow(new string[] { "5", "f", "in", "c" }, new object[] { new string[] { "5", "°f", "in", "°c" } })]
public void PrefixesDegrees(string[] input, string[] expectedResult)
{
InputInterpreter.DegreePrefixer(ref input);
Assert.AreEqual(expectedResult, input);
CollectionAssert.AreEqual(expectedResult, input);
}
[TestCase("a f in c")]
[TestCase("12 f in")]
[DataTestMethod]
[DataRow("a f in c")]
[DataRow("12 f in")]
public void ParseInvalidQueries(string queryString)
{
Query query = new Query(queryString);
@ -59,8 +64,9 @@ namespace Community.PowerToys.Run.Plugin.UnitConverter.UnitTest
Assert.AreEqual(null, result);
}
[TestCase("12 f in c", 12)]
[TestCase("10m to cm", 10)]
[DataTestMethod]
[DataRow("12 f in c", 12)]
[DataRow("10m to cm", 10)]
public void ParseValidQueries(string queryString, double result)
{
Query query = new Query(queryString);

View file

@ -3,14 +3,14 @@
// See the LICENSE file in the project root for more information.
using System.Linq;
using NUnit.Framework;
using Microsoft.VisualStudio.TestTools.UnitTesting;
namespace Community.PowerToys.Run.Plugin.UnitConverter.UnitTest
{
[TestFixture]
[TestClass]
public class UnitHandlerTests
{
[Test]
[TestMethod]
public void HandleTemperature()
{
var convertModel = new ConvertModel(1, "DegreeCelsius", "DegreeFahrenheit");
@ -18,7 +18,7 @@ namespace Community.PowerToys.Run.Plugin.UnitConverter.UnitTest
Assert.AreEqual(33.79999999999999d, result);
}
[Test]
[TestMethod]
public void HandleLength()
{
var convertModel = new ConvertModel(1, "meter", "centimeter");
@ -26,7 +26,7 @@ namespace Community.PowerToys.Run.Plugin.UnitConverter.UnitTest
Assert.AreEqual(100, result);
}
[Test]
[TestMethod]
public void HandlesByteCapitals()
{
var convertModel = new ConvertModel(1, "kB", "kb");
@ -34,7 +34,7 @@ namespace Community.PowerToys.Run.Plugin.UnitConverter.UnitTest
Assert.AreEqual(8, result);
}
[Test]
[TestMethod]
public void HandleInvalidModel()
{
var convertModel = new ConvertModel(1, "aa", "bb");

View file

@ -4,26 +4,29 @@
using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Plugin.Folder.Sources;
using Microsoft.Plugin.Folder.Sources.Result;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Moq;
using NUnit.Framework;
namespace Microsoft.Plugin.Folder.UnitTests
{
[TestClass]
public class DriveOrSharedFolderTests
{
[TestCase(@"\\test-server\testdir", true)]
[TestCase(@"c:", true)]
[TestCase(@"c:\", true)]
[TestCase(@"C:\", true)]
[TestCase(@"d:\", true)]
[TestCase(@"z:\", false)]
[TestCase(@"nope.exe", false)]
[TestCase(@"win32\test.dll", false)]
[TestCase(@"a\b\c\d", false)]
[TestCase(@"D", false)]
[TestCase(@"ZZ:\test", false)]
[DataTestMethod]
[DataRow(@"\\test-server\testdir", true)]
[DataRow(@"c:", true)]
[DataRow(@"c:\", true)]
[DataRow(@"C:\", true)]
[DataRow(@"d:\", true)]
[DataRow(@"z:\", false)]
[DataRow(@"nope.exe", false)]
[DataRow(@"win32\test.dll", false)]
[DataRow(@"a\b\c\d", false)]
[DataRow(@"D", false)]
[DataRow(@"ZZ:\test", false)]
public void IsDriveOrSharedFolder_WhenCalled(string search, bool expectedSuccess)
{
// Setup
@ -42,15 +45,16 @@ namespace Microsoft.Plugin.Folder.UnitTests
Assert.AreEqual(expectedSuccess, isDriveOrSharedFolder);
}
[TestCase('A', true)]
[TestCase('C', true)]
[TestCase('c', true)]
[TestCase('Z', true)]
[TestCase('z', true)]
[TestCase('ª', false)]
[TestCase('α', false)]
[TestCase('Ω', false)]
[TestCase('ɀ', false)]
[DataTestMethod]
[DataRow('A', true)]
[DataRow('C', true)]
[DataRow('c', true)]
[DataRow('Z', true)]
[DataRow('z', true)]
[DataRow('ª', false)]
[DataRow('α', false)]
[DataRow('Ω', false)]
[DataRow('ɀ', false)]
public void ValidDriveLetter_WhenCalled(char letter, bool expectedSuccess)
{
// Setup
@ -61,10 +65,11 @@ namespace Microsoft.Plugin.Folder.UnitTests
Assert.AreEqual(expectedSuccess, isDriveOrSharedFolder);
}
[TestCase("C:", true)]
[TestCase("C:\test", true)]
[TestCase("D:", false)]
[TestCase("INVALID", false)]
[DataTestMethod]
[DataRow("C:", true)]
[DataRow("C:\test", true)]
[DataRow("D:", false)]
[DataRow("INVALID", false)]
public void GenerateMaxFiles_WhenCalled(string search, bool hasValues)
{
// Setup
@ -88,11 +93,11 @@ namespace Microsoft.Plugin.Folder.UnitTests
// Assert
if (hasValues)
{
CollectionAssert.IsNotEmpty(results);
Assert.IsTrue(results.Count() > 0);
}
else
{
CollectionAssert.IsEmpty(results);
Assert.IsTrue(results.Count() == 0);
}
}
}

View file

@ -4,22 +4,21 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.IO.Abstractions.TestingHelpers;
using System.Linq;
using Microsoft.Plugin.Folder.Sources;
using Microsoft.Plugin.Folder.Sources.Result;
using NUnit.Framework;
using Microsoft.VisualStudio.TestTools.UnitTesting;
namespace Microsoft.Plugin.Folder.UnitTests
{
[TestFixture]
[TestClass]
public class InternalQueryFolderTests
{
private static IQueryFileSystemInfo _queryFileSystemInfoMock;
private static MockFileSystem _fileSystem;
[SetUp]
[TestInitialize]
public void SetupMock()
{
// Note: This mock filesystem adds a 'c:\temp' directory.
@ -35,23 +34,24 @@ namespace Microsoft.Plugin.Folder.UnitTests
_queryFileSystemInfoMock = new QueryFileSystemInfo(_fileSystem.DirectoryInfo);
}
[Test]
[TestMethod]
public void Query_ThrowsException_WhenCalledNull()
{
// Setup
var queryInternalDirectory = new QueryInternalDirectory(new FolderSettings(), _queryFileSystemInfoMock, _fileSystem.Directory);
// Act & Assert
Assert.Throws<ArgumentNullException>(() => queryInternalDirectory.Query(null).ToArray());
Assert.ThrowsException<ArgumentNullException>(() => queryInternalDirectory.Query(null).ToArray());
}
[TestCase(@"c", 0, 0, false, Reason = "String empty is nothing")]
[TestCase(@"c:", 2, 1, false, Reason = "Root without \\")]
[TestCase(@"c:\", 2, 1, false, Reason = "Normal root")]
[TestCase(@"c:\Test", 2, 2, false, Reason = "Select yourself")]
[TestCase(@"c:\not-exist", 2, 1, false, Reason = "Folder not exist, return root")]
[TestCase(@"c:\not-exist\not-exist2", 0, 0, false, Reason = "Folder not exist, return root")]
[TestCase(@"c:\bla.t", 2, 1, false, Reason = "Partial match file")]
[DataTestMethod]
[DataRow(@"c", 0, 0, false, DisplayName = "String empty is nothing")]
[DataRow(@"c:", 2, 1, false, DisplayName = "Root without \\")]
[DataRow(@"c:\", 2, 1, false, DisplayName = "Normal root")]
[DataRow(@"c:\Test", 2, 2, false, DisplayName = "Select yourself")]
[DataRow(@"c:\not-exist", 2, 1, false, DisplayName = "Folder not exist, return root")]
[DataRow(@"c:\not-exist\not-exist2", 0, 0, false, DisplayName = "Folder not exist, return root")]
[DataRow(@"c:\bla.t", 2, 1, false, DisplayName = "Partial match file")]
public void Query_WhenCalled(string search, int folders, int files, bool truncated)
{
const int maxFolderSetting = 3;
@ -74,8 +74,8 @@ namespace Microsoft.Plugin.Folder.UnitTests
Assert.AreEqual(folders, isDriveOrSharedFolder[typeof(FolderItemResult)].Count(), "folder count doesn't match");
// Always check if there is less than max folders
Assert.LessOrEqual(isDriveOrSharedFolder[typeof(FileItemResult)].Count(), maxFolderSetting, "Files are not limited");
Assert.LessOrEqual(isDriveOrSharedFolder[typeof(FolderItemResult)].Count(), maxFolderSetting, "Folders are not limited");
Assert.IsTrue(isDriveOrSharedFolder[typeof(FileItemResult)].Count() <= maxFolderSetting, "Files are not limited");
Assert.IsTrue(isDriveOrSharedFolder[typeof(FolderItemResult)].Count() <= maxFolderSetting, "Folders are not limited");
// Checks if CreateOpenCurrentFolder is displayed
Assert.AreEqual(Math.Min(folders + files, 1), isDriveOrSharedFolder[typeof(CreateOpenCurrentFolderResult)].Count(), "CreateOpenCurrentFolder displaying is incorrect");
@ -83,10 +83,11 @@ namespace Microsoft.Plugin.Folder.UnitTests
Assert.AreEqual(truncated, isDriveOrSharedFolder[typeof(TruncatedItemResult)].Count() == 1, "CreateOpenCurrentFolder displaying is incorrect");
}
[TestCase(@"c:\>", 3, 3, true, Reason = "Max Folder test recursive")]
[TestCase(@"c:\Test>", 3, 3, true, Reason = "2 Folders recursive")]
[TestCase(@"c:\not-exist>", 3, 3, true, Reason = "Folder not exist, return root recursive")]
[TestCase(@"c:\not-exist\not-exist2>", 0, 0, false, Reason = "Folder not exist, return root recursive")]
[DataTestMethod]
[DataRow(@"c:\>", 3, 3, true, DisplayName = "Max Folder test recursive")]
[DataRow(@"c:\Test>", 3, 3, true, DisplayName = "2 Folders recursive")]
[DataRow(@"c:\not-exist>", 3, 3, true, DisplayName = "Folder not exist, return root recursive")]
[DataRow(@"c:\not-exist\not-exist2>", 0, 0, false, DisplayName = "Folder not exist, return root recursive")]
public void Query_Recursive_WhenCalled(string search, int folders, int files, bool truncated)
{
const int maxFolderSetting = 3;
@ -109,8 +110,8 @@ namespace Microsoft.Plugin.Folder.UnitTests
Assert.AreEqual(folders, isDriveOrSharedFolder[typeof(FolderItemResult)].Count(), "folder count doesn't match");
// Always check if there is less than max folders
Assert.LessOrEqual(isDriveOrSharedFolder[typeof(FileItemResult)].Count(), maxFolderSetting, "Files are not limited");
Assert.LessOrEqual(isDriveOrSharedFolder[typeof(FolderItemResult)].Count(), maxFolderSetting, "Folders are not limited");
Assert.IsTrue(isDriveOrSharedFolder[typeof(FileItemResult)].Count() <= maxFolderSetting, "Files are not limited");
Assert.IsTrue(isDriveOrSharedFolder[typeof(FolderItemResult)].Count() <= maxFolderSetting, "Folders are not limited");
// Checks if CreateOpenCurrentFolder is displayed
Assert.AreEqual(Math.Min(folders + files, 1), isDriveOrSharedFolder[typeof(CreateOpenCurrentFolderResult)].Count(), "CreateOpenCurrentFolder displaying is incorrect");

View file

@ -11,9 +11,9 @@
<ItemGroup>
<PackageReference Include="Moq" Version="4.16.1" />
<PackageReference Include="nunit" Version="3.13.1" />
<PackageReference Include="NUnit3TestAdapter" Version="3.17.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.9.1" />
<PackageReference Include="MSTest.TestAdapter" Version="2.2.5" />
<PackageReference Include="MSTest.TestFramework" Version="2.2.5" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.10.0" />
<PackageReference Include="System.IO.Abstractions.TestingHelpers" Version="12.2.3" />
</ItemGroup>

View file

@ -26,9 +26,9 @@
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Moq" Version="4.16.1" />
<PackageReference Include="nunit" Version="3.13.1" />
<PackageReference Include="NUnit3TestAdapter" Version="3.17.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.9.1" />
<PackageReference Include="MSTest.TestAdapter" Version="2.2.5" />
<PackageReference Include="MSTest.TestFramework" Version="2.2.5" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.10.0" />
</ItemGroup>
<ItemGroup>

View file

@ -3,25 +3,25 @@
// See the LICENSE file in the project root for more information.
using Microsoft.Plugin.Program.ProgramArgumentParser;
using Mono.Collections.Generic;
using NUnit.Framework;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Wox.Plugin;
namespace Microsoft.Plugin.Program.UnitTests.ProgramArgumentParser
{
[TestFixture]
[TestClass]
public class ProgramArgumentParserTests
{
[TestCase("Microsoft Edge", "Microsoft Edge", null)]
[TestCase("Microsoft Edge ---inprivate", "Microsoft Edge ---inprivate", null)]
[TestCase("Microsoft Edge -- -inprivate", "Microsoft Edge", "-inprivate")]
[TestCase("Microsoft Edge -inprivate", "Microsoft Edge", "-inprivate")]
[TestCase("Microsoft Edge /inprivate", "Microsoft Edge", "/inprivate")]
[TestCase("edge.exe --inprivate", "edge.exe", "--inprivate")]
[TestCase("edge.exe -- --inprivate", "edge.exe", "--inprivate")]
[TestCase("edge.exe", "edge.exe", null)]
[TestCase("edge", "edge", null)]
[TestCase("cmd /c \"ping 1.1.1.1\"", "cmd", "/c \"ping 1.1.1.1\"")]
[DataTestMethod]
[DataRow("Microsoft Edge", "Microsoft Edge", null)]
[DataRow("Microsoft Edge ---inprivate", "Microsoft Edge ---inprivate", null)]
[DataRow("Microsoft Edge -- -inprivate", "Microsoft Edge", "-inprivate")]
[DataRow("Microsoft Edge -inprivate", "Microsoft Edge", "-inprivate")]
[DataRow("Microsoft Edge /inprivate", "Microsoft Edge", "/inprivate")]
[DataRow("edge.exe --inprivate", "edge.exe", "--inprivate")]
[DataRow("edge.exe -- --inprivate", "edge.exe", "--inprivate")]
[DataRow("edge.exe", "edge.exe", null)]
[DataRow("edge", "edge", null)]
[DataRow("cmd /c \"ping 1.1.1.1\"", "cmd", "/c \"ping 1.1.1.1\"")]
public void ProgramArgumentParserTestsCanParseQuery(string inputQuery, string expectedProgram, string expectedProgramArguments)
{
// Arrange

View file

@ -5,12 +5,12 @@
using System.Collections.Generic;
using Castle.Core.Internal;
using Microsoft.Plugin.Program.Programs;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Moq;
using NUnit.Framework;
namespace Microsoft.Plugin.Program.UnitTests.Programs
{
[TestFixture]
[TestClass]
public class UWPTests
{
private static readonly PackageWrapper DevelopmentModeApp = new PackageWrapper(
@ -37,7 +37,7 @@ namespace Microsoft.Plugin.Program.UnitTests.Programs
false,
"AppxManifests/PackagedApp");
[Test]
[TestMethod]
public void AllShouldReturnPackagesWithDevelopmentModeWhenCalled()
{
// Arrange
@ -56,7 +56,7 @@ namespace Microsoft.Plugin.Program.UnitTests.Programs
Assert.IsTrue(applications.FindAll(x => x.Name == "PackagedApp").Length > 0);
}
[Test]
[TestMethod]
public void AllShouldNotReturnPackageFrameworksWhenCalled()
{
// Arrange
@ -74,7 +74,7 @@ namespace Microsoft.Plugin.Program.UnitTests.Programs
Assert.IsTrue(applications.FindAll(x => x.Name == "PackagedApp").Length > 0);
}
[Test]
[TestMethod]
public void PowerToysRunShouldNotAddInvalidAppWhenIndexingUWPApplications()
{
// Arrange

View file

@ -5,17 +5,16 @@
using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Moq;
using NUnit.Framework;
using Wox.Infrastructure;
using Wox.Infrastructure.FileSystemHelper;
using Wox.Plugin;
using Win32Program = Microsoft.Plugin.Program.Programs.Win32Program;
namespace Microsoft.Plugin.Program.UnitTests.Programs
{
using Win32Program = Microsoft.Plugin.Program.Programs.Win32Program;
[TestFixture]
[TestClass]
public class Win32Tests
{
private static readonly Win32Program _imagingDevices = new Win32Program
@ -253,7 +252,7 @@ namespace Microsoft.Plugin.Program.UnitTests.Programs
return mockDirectory.Object;
}
[Test]
[TestMethod]
public void DedupFunctionWhenCalledMustRemoveDuplicateNotepads()
{
// Arrange
@ -270,7 +269,7 @@ namespace Microsoft.Plugin.Program.UnitTests.Programs
Assert.AreEqual(1, apps.Count);
}
[Test]
[TestMethod]
public void DedupFunctionWhenCalledMustRemoveInternetShortcuts()
{
// Arrange
@ -287,7 +286,7 @@ namespace Microsoft.Plugin.Program.UnitTests.Programs
Assert.AreEqual(1, apps.Count);
}
[Test]
[TestMethod]
public void DedupFunctionWhenCalledMustNotRemovelnkWhichdoesNotHaveExe()
{
// Arrange
@ -303,7 +302,7 @@ namespace Microsoft.Plugin.Program.UnitTests.Programs
Assert.AreEqual(1, apps.Count);
}
[Test]
[TestMethod]
public void DedupFunctionMustRemoveDuplicatesForExeExtensionsWithoutLnkResolvedPath()
{
// Arrange
@ -321,7 +320,7 @@ namespace Microsoft.Plugin.Program.UnitTests.Programs
Assert.IsTrue(!string.IsNullOrEmpty(apps[0].LnkResolvedPath));
}
[Test]
[TestMethod]
public void DedupFunctionMustNotRemoveProgramsWithSameExeNameAndFullPath()
{
// Arrange
@ -339,7 +338,7 @@ namespace Microsoft.Plugin.Program.UnitTests.Programs
Assert.AreEqual(3, apps.Count);
}
[Test]
[TestMethod]
public void FunctionIsWebApplicationShouldReturnTrueForWebApplications()
{
// The IsWebApplication(() function must return true for all PWAs and pinned web pages
@ -351,7 +350,8 @@ namespace Microsoft.Plugin.Program.UnitTests.Programs
Assert.IsFalse(_dummyProxyApp.IsWebApplication());
}
[TestCase("ignore")]
[DataTestMethod]
[DataRow("ignore")]
public void FunctionFilterWebApplicationShouldReturnFalseWhenSearchingForTheMainApp(string query)
{
// Irrespective of the query, the FilterWebApplication() Function must not filter main apps such as edge and chrome
@ -359,37 +359,40 @@ namespace Microsoft.Plugin.Program.UnitTests.Programs
Assert.IsFalse(_chrome.FilterWebApplication(query));
}
[TestCase("edge", ExpectedResult = true)]
[TestCase("EDGE", ExpectedResult = true)]
[TestCase("msedge", ExpectedResult = true)]
[TestCase("Microsoft", ExpectedResult = true)]
[TestCase("edg", ExpectedResult = true)]
[TestCase("Edge page", ExpectedResult = false)]
[TestCase("Edge Web page", ExpectedResult = false)]
public bool EdgeWebSitesShouldBeFilteredWhenSearchingForEdge(string query)
[DataTestMethod]
[DataRow("edge", true)]
[DataRow("EDGE", true)]
[DataRow("msedge", true)]
[DataRow("Microsoft", true)]
[DataRow("edg", true)]
[DataRow("Edge page", false)]
[DataRow("Edge Web page", false)]
public void EdgeWebSitesShouldBeFilteredWhenSearchingForEdge(string query, bool result)
{
return _pinnedWebpage.FilterWebApplication(query);
Assert.AreEqual(_pinnedWebpage.FilterWebApplication(query), result);
}
[TestCase("chrome", ExpectedResult = true)]
[TestCase("CHROME", ExpectedResult = true)]
[TestCase("Google", ExpectedResult = true)]
[TestCase("Google Chrome", ExpectedResult = true)]
[TestCase("Google Chrome twitter", ExpectedResult = false)]
public bool ChromeWebSitesShouldBeFilteredWhenSearchingForChrome(string query)
[DataTestMethod]
[DataRow("chrome", true)]
[DataRow("CHROME", true)]
[DataRow("Google", true)]
[DataRow("Google Chrome", true)]
[DataRow("Google Chrome twitter", false)]
public void ChromeWebSitesShouldBeFilteredWhenSearchingForChrome(string query, bool result)
{
return _twitterChromePwa.FilterWebApplication(query);
Assert.AreEqual(_twitterChromePwa.FilterWebApplication(query), result);
}
[TestCase("twitter", 0, ExpectedResult = false)]
[TestCase("Twit", 0, ExpectedResult = false)]
[TestCase("TWITTER", 0, ExpectedResult = false)]
[TestCase("web", 1, ExpectedResult = false)]
[TestCase("Page", 1, ExpectedResult = false)]
[TestCase("WEB PAGE", 1, ExpectedResult = false)]
[TestCase("edge", 2, ExpectedResult = false)]
[TestCase("EDGE", 2, ExpectedResult = false)]
public bool PinnedWebPagesShouldNotBeFilteredWhenSearchingForThem(string query, int scenario)
[DataTestMethod]
[DataRow("twitter", 0, false)]
[DataRow("Twit", 0, false)]
[DataRow("TWITTER", 0, false)]
[DataRow("web", 1, false)]
[DataRow("Page", 1, false)]
[DataRow("WEB PAGE", 1, false)]
[DataRow("edge", 2, false)]
[DataRow("EDGE", 2, false)]
public void PinnedWebPagesShouldNotBeFilteredWhenSearchingForThem(string query, int scenario, bool result)
{
const int CASE_TWITTER = 0;
const int CASE_WEB_PAGE = 1;
@ -400,40 +403,43 @@ namespace Microsoft.Plugin.Program.UnitTests.Programs
switch (scenario)
{
case CASE_TWITTER:
return _twitterChromePwa.FilterWebApplication(query);
Assert.AreEqual(_twitterChromePwa.FilterWebApplication(query), result);
return;
case CASE_WEB_PAGE:
return _pinnedWebpage.FilterWebApplication(query);
Assert.AreEqual(_pinnedWebpage.FilterWebApplication(query), result);
return;
case CASE_EDGE_NAMED_WEBPAGE:
return _edgeNamedPinnedWebpage.FilterWebApplication(query);
Assert.AreEqual(_edgeNamedPinnedWebpage.FilterWebApplication(query), result);
return;
default:
break;
}
// unreachable code
return true;
}
[TestCase("Command Prompt")]
[TestCase("cmd")]
[TestCase("cmd.exe")]
[TestCase("ignoreQueryText")]
[DataTestMethod]
[DataRow("Command Prompt")]
[DataRow("cmd")]
[DataRow("cmd.exe")]
[DataRow("ignoreQueryText")]
public void Win32ApplicationsShouldNotBeFilteredWhenFilteringRunCommands(string query)
{
// Even if there is an exact match in the name or exe name, win32 applications should never be filtered
Assert.IsTrue(_commandPrompt.QueryEqualsNameForRunCommands(query));
}
[TestCase("explorer")]
[TestCase("explorer.exe")]
[DataTestMethod]
[DataRow("explorer")]
[DataRow("explorer.exe")]
public void Win32ApplicationsShouldNotFilterWhenExecutingNameOrNameIsUsed(string query)
{
// Even if there is an exact match in the name or exe name, win32 applications should never be filtered
Assert.IsTrue(_fileExplorer.QueryEqualsNameForRunCommands(query));
}
[TestCase("cmd")]
[TestCase("Cmd")]
[TestCase("CMD")]
[DataTestMethod]
[DataRow("cmd")]
[DataRow("Cmd")]
[DataRow("CMD")]
public void RunCommandsShouldNotBeFilteredOnExactMatch(string query)
{
// Partial matches should be filtered as cmd is not equal to cmder
@ -443,13 +449,14 @@ namespace Microsoft.Plugin.Program.UnitTests.Programs
Assert.IsTrue(_cmdRunCommand.QueryEqualsNameForRunCommands(query));
}
[TestCase("ımaging")]
[DataTestMethod]
[DataRow("ımaging")]
public void Win32ApplicationsShouldNotHaveIncorrectPathWhenExecuting(string query)
{
Assert.IsFalse(_imagingDevices.FullPath.Contains(query, StringComparison.Ordinal));
}
[Test]
[TestMethod]
public void WebApplicationShouldReturnContextMenuWithOpenInConsoleWhenContextMenusIsCalled()
{
// Arrange
@ -465,7 +472,7 @@ namespace Microsoft.Plugin.Program.UnitTests.Programs
Assert.AreEqual(Properties.Resources.wox_plugin_program_open_in_console, contextMenuResults[2].Title);
}
[Test]
[TestMethod]
public void InternetShortcutApplicationShouldReturnContextMenuWithOpenInConsoleWhenContextMenusIsCalled()
{
// Arrange
@ -480,7 +487,7 @@ namespace Microsoft.Plugin.Program.UnitTests.Programs
Assert.AreEqual(Properties.Resources.wox_plugin_program_open_in_console, contextMenuResults[1].Title);
}
[Test]
[TestMethod]
public void Win32ApplicationShouldReturnContextMenuWithOpenInConsoleWhenContextMenusIsCalled()
{
// Arrange
@ -496,7 +503,7 @@ namespace Microsoft.Plugin.Program.UnitTests.Programs
Assert.AreEqual(Properties.Resources.wox_plugin_program_open_in_console, contextMenuResults[2].Title);
}
[Test]
[TestMethod]
public void RunCommandShouldReturnContextMenuWithOpenInConsoleWhenContextMenusIsCalled()
{
// Arrange
@ -512,7 +519,7 @@ namespace Microsoft.Plugin.Program.UnitTests.Programs
Assert.AreEqual(Properties.Resources.wox_plugin_program_open_in_console, contextMenuResults[2].Title);
}
[Test]
[TestMethod]
public void AppRefApplicationShouldReturnContextMenuWithOpenInConsoleWhenContextMenusIsCalled()
{
// Arrange
@ -528,7 +535,7 @@ namespace Microsoft.Plugin.Program.UnitTests.Programs
Assert.AreEqual(Properties.Resources.wox_plugin_program_open_in_console, contextMenuResults[2].Title);
}
[Test]
[TestMethod]
public void ShortcutApplicationShouldReturnContextMenuWithOpenInConsoleWhenContextMenusIsCalled()
{
// Arrange
@ -544,7 +551,7 @@ namespace Microsoft.Plugin.Program.UnitTests.Programs
Assert.AreEqual(Properties.Resources.wox_plugin_program_open_in_console, contextMenuResults[2].Title);
}
[Test]
[TestMethod]
public void FolderApplicationShouldReturnContextMenuWithOpenInConsoleWhenContextMenusIsCalled()
{
// Arrange
@ -559,7 +566,7 @@ namespace Microsoft.Plugin.Program.UnitTests.Programs
Assert.AreEqual(Properties.Resources.wox_plugin_program_open_in_console, contextMenuResults[1].Title);
}
[Test]
[TestMethod]
public void GenericFileApplicationShouldReturnContextMenuWithOpenInConsoleWhenContextMenusIsCalled()
{
// Arrange
@ -574,7 +581,7 @@ namespace Microsoft.Plugin.Program.UnitTests.Programs
Assert.AreEqual(Properties.Resources.wox_plugin_program_open_in_console, contextMenuResults[1].Title);
}
[Test]
[TestMethod]
public void Win32AppsShouldSetNameAsTitleWhileCreatingResult()
{
var mock = new Mock<IPublicAPI>();
@ -589,25 +596,27 @@ namespace Microsoft.Plugin.Program.UnitTests.Programs
Assert.IsFalse(result.Title.Equals(_cmderRunCommand.Description, StringComparison.Ordinal));
}
[TestCase("C:\\Program Files\\dummy.exe", ExpectedResult = Win32Program.ApplicationType.Win32Application)]
[TestCase("C:\\Program Files\\dummy.msc", ExpectedResult = Win32Program.ApplicationType.Win32Application)]
[TestCase("C:\\Program Files\\dummy.lnk", ExpectedResult = Win32Program.ApplicationType.ShortcutApplication)]
[TestCase("C:\\Program Files\\dummy.appref-ms", ExpectedResult = Win32Program.ApplicationType.ApprefApplication)]
[TestCase("C:\\Program Files\\dummy.url", ExpectedResult = Win32Program.ApplicationType.InternetShortcutApplication)]
[TestCase("C:\\Program Files\\dummy", ExpectedResult = Win32Program.ApplicationType.Folder)]
[TestCase("C:\\Program Files\\dummy.txt", ExpectedResult = Win32Program.ApplicationType.GenericFile)]
public Win32Program.ApplicationType GetAppTypeFromPathShouldReturnCorrectAppTypeWhenAppPathIsPassedAsArgument(string path)
[DataTestMethod]
[DataRow("C:\\Program Files\\dummy.exe", Win32Program.ApplicationType.Win32Application)]
[DataRow("C:\\Program Files\\dummy.msc", Win32Program.ApplicationType.Win32Application)]
[DataRow("C:\\Program Files\\dummy.lnk", Win32Program.ApplicationType.ShortcutApplication)]
[DataRow("C:\\Program Files\\dummy.appref-ms", Win32Program.ApplicationType.ApprefApplication)]
[DataRow("C:\\Program Files\\dummy.url", Win32Program.ApplicationType.InternetShortcutApplication)]
[DataRow("C:\\Program Files\\dummy", Win32Program.ApplicationType.Folder)]
[DataRow("C:\\Program Files\\dummy.txt", Win32Program.ApplicationType.GenericFile)]
public void GetAppTypeFromPathShouldReturnCorrectAppTypeWhenAppPathIsPassedAsArgument(string path, Win32Program.ApplicationType result)
{
// Directory.Exists must be mocked
Win32Program.DirectoryWrapper = GetMockedDirectoryWrapper();
// Act
return Win32Program.GetAppTypeFromPath(path);
Assert.AreEqual(Win32Program.GetAppTypeFromPath(path), result);
}
[TestCase(null)]
[TestCase("")]
[TestCase("ping 1.1.1.1")]
[DataTestMethod]
[DataRow(null)]
[DataRow("")]
[DataRow("ping 1.1.1.1")]
public void EmptyArgumentsShouldNotThrow(string argument)
{
// Arrange
@ -617,7 +626,7 @@ namespace Microsoft.Plugin.Program.UnitTests.Programs
List<ContextMenuResult> contextMenuResults = _dummyInternetShortcutApp.ContextMenus(argument, mock.Object);
// Assert (Should always return if the above does not throw any exception)
Assert.True(true);
Assert.IsTrue(true);
}
}
}

View file

@ -5,14 +5,15 @@
using System.Collections.Concurrent;
using System.Threading.Tasks;
using Microsoft.Plugin.Program.Storage;
using NUnit.Framework;
using Microsoft.VisualStudio.TestTools.UnitTesting;
namespace Microsoft.Plugin.Program.UnitTests.Storage
{
[TestFixture]
[TestClass]
public class ConcurrentQueueEventHandlerTest
{
[TestCase]
[DataTestMethod]
[DataRow]
public async Task EventHandlerMustReturnEmptyPathForEmptyQueueAsync()
{
// Arrange
@ -23,11 +24,12 @@ namespace Microsoft.Plugin.Program.UnitTests.Storage
string appPath = await EventHandler.GetAppPathFromQueueAsync(eventHandlingQueue, dequeueDelay).ConfigureAwait(false);
// Assert
Assert.IsEmpty(appPath);
Assert.IsTrue(string.IsNullOrEmpty(appPath));
}
[TestCase(1)]
[TestCase(10)]
[DataTestMethod]
[DataRow(1)]
[DataRow(10)]
public async Task EventHandlerMustReturnPathForConcurrentQueueWithSameFilePathsAsync(int itemCount)
{
// Arrange
@ -47,7 +49,8 @@ namespace Microsoft.Plugin.Program.UnitTests.Storage
Assert.AreEqual(0, eventHandlingQueue.Count);
}
[TestCase(5)]
[DataTestMethod]
[DataRow(5)]
public async Task EventHandlerMustReturnPathAndRetainDifferentFilePathsInQueueAsync(int itemCount)
{
// Arrange
@ -73,7 +76,8 @@ namespace Microsoft.Plugin.Program.UnitTests.Storage
Assert.AreEqual(itemCount, eventHandlingQueue.Count);
}
[TestCase(5)]
[DataTestMethod]
[DataRow(5)]
public async Task EventHandlerMustReturnPathAndRetainAllPathsAfterEncounteringADifferentPathAsync(int itemCount)
{
// Arrange

View file

@ -3,15 +3,15 @@
// See the LICENSE file in the project root for more information.
using System.Threading.Tasks;
using NUnit.Framework;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Wox.Infrastructure.Storage;
namespace Microsoft.Plugin.Program.UnitTests.Storage
{
[TestFixture]
[TestClass]
public class ListRepositoryTests
{
[Test]
[TestMethod]
public void ContainsShouldReturnTrueWhenListIsInitializedWithItem()
{
// Arrange
@ -25,7 +25,7 @@ namespace Microsoft.Plugin.Program.UnitTests.Storage
Assert.IsTrue(result);
}
[Test]
[TestMethod]
public void ContainsShouldReturnTrueWhenListIsUpdatedWithAdd()
{
// Arrange
@ -40,7 +40,7 @@ namespace Microsoft.Plugin.Program.UnitTests.Storage
Assert.IsTrue(result);
}
[Test]
[TestMethod]
public void ContainsShouldReturnFalseWhenListIsUpdatedWithRemove()
{
// Arrange
@ -55,7 +55,7 @@ namespace Microsoft.Plugin.Program.UnitTests.Storage
Assert.IsFalse(result);
}
[Test]
[TestMethod]
public async Task AddShouldNotThrowWhenBeingIterated()
{
// Arrange
@ -94,7 +94,7 @@ namespace Microsoft.Plugin.Program.UnitTests.Storage
await Task.WhenAll(new Task[] { iterationTask, addTask }).ConfigureAwait(false);
}
[Test]
[TestMethod]
public async Task RemoveShouldNotThrowWhenBeingIterated()
{
// Arrange

View file

@ -9,15 +9,15 @@ using System.IO.Abstractions;
using System.Linq;
using Microsoft.Plugin.Program.Programs;
using Microsoft.Plugin.Program.Storage;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Moq;
using NUnit.Framework;
using Wox.Infrastructure.FileSystemHelper;
using Wox.Infrastructure.Storage;
using Win32Program = Microsoft.Plugin.Program.Programs.Win32Program;
namespace Microsoft.Plugin.Program.UnitTests.Storage
{
[TestFixture]
[TestClass]
public class Win32ProgramRepositoryTest
{
private readonly ProgramPluginSettings _settings = new ProgramPluginSettings();
@ -26,7 +26,7 @@ namespace Microsoft.Plugin.Program.UnitTests.Storage
private List<IFileSystemWatcherWrapper> _fileSystemWatchers;
private List<Mock<IFileSystemWatcherWrapper>> _fileSystemMocks;
[SetUp]
[TestInitialize]
public void SetFileSystemWatchers()
{
_fileSystemWatchers = new List<IFileSystemWatcherWrapper>();
@ -39,7 +39,8 @@ namespace Microsoft.Plugin.Program.UnitTests.Storage
}
}
[TestCase("Name", "ExecutableName", "FullPath", "description1", "description2")]
[DataTestMethod]
[DataRow("Name", "ExecutableName", "FullPath", "description1", "description2")]
public void Win32RepositoryMustNotStoreDuplicatesWhileAddingItemsWithSameHashCode(string name, string exename, string fullPath, string description1, string description2)
{
// Arrange
@ -73,7 +74,8 @@ namespace Microsoft.Plugin.Program.UnitTests.Storage
Assert.AreEqual(1, win32ProgramRepository.Count());
}
[TestCase("path.appref-ms")]
[DataTestMethod]
[DataRow("path.appref-ms")]
public void Win32ProgramRepositoryMustCallOnAppCreatedForApprefAppsWhenCreatedEventIsRaised(string path)
{
// Arrange
@ -88,7 +90,8 @@ namespace Microsoft.Plugin.Program.UnitTests.Storage
Assert.AreEqual(Win32Program.ApplicationType.ApprefApplication, win32ProgramRepository.ElementAt(0).AppType);
}
[TestCase("directory", "path.appref-ms")]
[DataTestMethod]
[DataRow("directory", "path.appref-ms")]
public void Win32ProgramRepositoryMustCallOnAppDeletedForApprefAppsWhenDeletedEventIsRaised(string directory, string path)
{
// Arrange
@ -106,7 +109,8 @@ namespace Microsoft.Plugin.Program.UnitTests.Storage
Assert.AreEqual(0, win32ProgramRepository.Count());
}
[TestCase("directory", "oldpath.appref-ms", "newpath.appref-ms")]
[DataTestMethod]
[DataRow("directory", "oldpath.appref-ms", "newpath.appref-ms")]
public void Win32ProgramRepositoryMustCallOnAppRenamedForApprefAppsWhenRenamedEventIsRaised(string directory, string oldpath, string newpath)
{
// Arrange
@ -129,7 +133,8 @@ namespace Microsoft.Plugin.Program.UnitTests.Storage
Assert.IsFalse(win32ProgramRepository.Contains(olditem));
}
[TestCase("path.exe")]
[DataTestMethod]
[DataRow("path.exe")]
public void Win32ProgramRepositoryMustCallOnAppCreatedForExeAppsWhenCreatedEventIsRaised(string path)
{
// Arrange
@ -149,7 +154,8 @@ namespace Microsoft.Plugin.Program.UnitTests.Storage
Assert.AreEqual(Win32Program.ApplicationType.Win32Application, win32ProgramRepository.ElementAt(0).AppType);
}
[TestCase("directory", "path.exe")]
[DataTestMethod]
[DataRow("directory", "path.exe")]
public void Win32ProgramRepositoryMustCallOnAppDeletedForExeAppsWhenDeletedEventIsRaised(string directory, string path)
{
// Arrange
@ -172,7 +178,8 @@ namespace Microsoft.Plugin.Program.UnitTests.Storage
Assert.AreEqual(0, win32ProgramRepository.Count());
}
[TestCase("directory", "oldpath.appref-ms", "newpath.appref-ms")]
[DataTestMethod]
[DataRow("directory", "oldpath.appref-ms", "newpath.appref-ms")]
public void Win32ProgramRepositoryMustCallOnAppRenamedForExeAppsWhenRenamedEventIsRaised(string directory, string oldpath, string newpath)
{
// Arrange
@ -200,7 +207,8 @@ namespace Microsoft.Plugin.Program.UnitTests.Storage
Assert.IsFalse(win32ProgramRepository.Contains(olditem));
}
[TestCase("path.url")]
[DataTestMethod]
[DataRow("path.url")]
public void Win32ProgramRepositoryMustNotCreateUrlAppWhenCreatedEventIsRaised(string path)
{
// We are handing internet shortcut apps using the Changed event instead
@ -221,9 +229,10 @@ namespace Microsoft.Plugin.Program.UnitTests.Storage
Assert.AreEqual(0, win32ProgramRepository.Count());
}
[TestCase("path.exe")]
[TestCase("path.lnk")]
[TestCase("path.appref-ms")]
[DataTestMethod]
[DataRow("path.exe")]
[DataRow("path.lnk")]
[DataRow("path.appref-ms")]
public void Win32ProgramRepositoryMustNotCreateAnyAppOtherThanUrlAppWhenChangedEventIsRaised(string path)
{
// We are handing internet shortcut apps using the Changed event instead
@ -249,7 +258,8 @@ namespace Microsoft.Plugin.Program.UnitTests.Storage
Assert.AreEqual(0, win32ProgramRepository.Count());
}
[TestCase("directory", "path.url")]
[DataTestMethod]
[DataRow("directory", "path.url")]
public void Win32ProgramRepositoryMustCallOnAppDeletedForUrlAppsWhenDeletedEventIsRaised(string directory, string path)
{
// Arrange
@ -272,7 +282,8 @@ namespace Microsoft.Plugin.Program.UnitTests.Storage
Assert.AreEqual(0, win32ProgramRepository.Count());
}
[TestCase("directory", "oldpath.url", "newpath.url")]
[DataTestMethod]
[DataRow("directory", "oldpath.url", "newpath.url")]
public void Win32ProgramRepositoryMustCallOnAppRenamedForUrlAppsWhenRenamedEventIsRaised(string directory, string oldpath, string newpath)
{
// Arrange
@ -300,7 +311,8 @@ namespace Microsoft.Plugin.Program.UnitTests.Storage
Assert.IsFalse(win32ProgramRepository.Contains(olditem));
}
[TestCase("directory", "path.lnk")]
[DataTestMethod]
[DataRow("directory", "path.lnk")]
public void Win32ProgramRepositoryMustCallOnAppDeletedForLnkAppsWhenDeletedEventIsRaised(string directory, string path)
{
// Arrange
@ -330,7 +342,8 @@ namespace Microsoft.Plugin.Program.UnitTests.Storage
Assert.AreEqual(0, win32ProgramRepository.Count());
}
[TestCase("directory", "oldpath.lnk", "path.lnk")]
[DataTestMethod]
[DataRow("directory", "oldpath.lnk", "path.lnk")]
public void Win32ProgramRepositoryMustCallOnAppRenamedForLnkAppsWhenRenamedEventIsRaised(string directory, string oldpath, string path)
{
// Arrange

View file

@ -10,9 +10,9 @@
</PropertyGroup>
<ItemGroup>
<PackageReference Include="nunit" Version="3.13.1" />
<PackageReference Include="NUnit3TestAdapter" Version="3.17.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.9.1" />
<PackageReference Include="MSTest.TestAdapter" Version="2.2.5" />
<PackageReference Include="MSTest.TestFramework" Version="2.2.5" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.10.0" />
</ItemGroup>
<ItemGroup>

View file

@ -3,55 +3,55 @@
// See the LICENSE file in the project root for more information.
using Microsoft.Plugin.Uri.UriHelper;
using Microsoft.VisualStudio.TestPlatform.ObjectModel;
using NUnit.Framework;
using Microsoft.VisualStudio.TestTools.UnitTesting;
namespace Microsoft.Plugin.Uri.UnitTests.UriHelper
{
[TestFixture]
[TestClass]
public class ExtendedUriParserTests
{
[TestCase("google.com", true, "https://google.com/")]
[TestCase("http://google.com", true, "http://google.com/")]
[TestCase("localhost", true, "https://localhost/")]
[TestCase("http://localhost", true, "http://localhost/")]
[TestCase("127.0.0.1", true, "https://127.0.0.1/")]
[TestCase("http://127.0.0.1", true, "http://127.0.0.1/")]
[TestCase("http://127.0.0.1:80", true, "http://127.0.0.1/")]
[TestCase("127", false, null)]
[TestCase("", false, null)]
[TestCase("https://google.com", true, "https://google.com/")]
[TestCase("ftps://google.com", true, "ftps://google.com/")]
[TestCase(null, false, null)]
[TestCase("bing.com/search?q=gmx", true, "https://bing.com/search?q=gmx")]
[TestCase("http://bing.com/search?q=gmx", true, "http://bing.com/search?q=gmx")]
[TestCase("h", true, "https://h/")]
[TestCase("http://h", true, "http://h/")]
[TestCase("ht", true, "https://ht/")]
[TestCase("http://ht", true, "http://ht/")]
[TestCase("htt", true, "https://htt/")]
[TestCase("http://htt", true, "http://htt/")]
[TestCase("http", true, "https://http/")]
[TestCase("http://http", true, "http://http/")]
[TestCase("http:", false, null)]
[TestCase("http:/", false, null)]
[TestCase("http://", false, null)]
[TestCase("http://t", true, "http://t/")]
[TestCase("http://te", true, "http://te/")]
[TestCase("http://tes", true, "http://tes/")]
[TestCase("http://test", true, "http://test/")]
[TestCase("http://test.", false, null)]
[TestCase("http://test.c", true, "http://test.c/")]
[TestCase("http://test.co", true, "http://test.co/")]
[TestCase("http://test.com", true, "http://test.com/")]
[TestCase("http:3", true, "https://http:3/")]
[TestCase("http://http:3", true, "http://http:3/")]
[TestCase("[::]", true, "https://[::]/")]
[TestCase("http://[::]", true, "http://[::]/")]
[TestCase("[2001:0DB8::1]", true, "https://[2001:db8::1]/")]
[TestCase("http://[2001:0DB8::1]", true, "http://[2001:db8::1]/")]
[TestCase("[2001:0DB8::1]:80", true, "https://[2001:db8::1]/")]
[TestCase("http://[2001:0DB8::1]:80", true, "http://[2001:db8::1]/")]
[DataTestMethod]
[DataRow("google.com", true, "https://google.com/")]
[DataRow("http://google.com", true, "http://google.com/")]
[DataRow("localhost", true, "https://localhost/")]
[DataRow("http://localhost", true, "http://localhost/")]
[DataRow("127.0.0.1", true, "https://127.0.0.1/")]
[DataRow("http://127.0.0.1", true, "http://127.0.0.1/")]
[DataRow("http://127.0.0.1:80", true, "http://127.0.0.1/")]
[DataRow("127", false, null)]
[DataRow("", false, null)]
[DataRow("https://google.com", true, "https://google.com/")]
[DataRow("ftps://google.com", true, "ftps://google.com/")]
[DataRow(null, false, null)]
[DataRow("bing.com/search?q=gmx", true, "https://bing.com/search?q=gmx")]
[DataRow("http://bing.com/search?q=gmx", true, "http://bing.com/search?q=gmx")]
[DataRow("h", true, "https://h/")]
[DataRow("http://h", true, "http://h/")]
[DataRow("ht", true, "https://ht/")]
[DataRow("http://ht", true, "http://ht/")]
[DataRow("htt", true, "https://htt/")]
[DataRow("http://htt", true, "http://htt/")]
[DataRow("http", true, "https://http/")]
[DataRow("http://http", true, "http://http/")]
[DataRow("http:", false, null)]
[DataRow("http:/", false, null)]
[DataRow("http://", false, null)]
[DataRow("http://t", true, "http://t/")]
[DataRow("http://te", true, "http://te/")]
[DataRow("http://tes", true, "http://tes/")]
[DataRow("http://test", true, "http://test/")]
[DataRow("http://test.", false, null)]
[DataRow("http://test.c", true, "http://test.c/")]
[DataRow("http://test.co", true, "http://test.co/")]
[DataRow("http://test.com", true, "http://test.com/")]
[DataRow("http:3", true, "https://http:3/")]
[DataRow("http://http:3", true, "http://http:3/")]
[DataRow("[::]", true, "https://[::]/")]
[DataRow("http://[::]", true, "http://[::]/")]
[DataRow("[2001:0DB8::1]", true, "https://[2001:db8::1]/")]
[DataRow("http://[2001:0DB8::1]", true, "http://[2001:db8::1]/")]
[DataRow("[2001:0DB8::1]:80", true, "https://[2001:db8::1]/")]
[DataRow("http://[2001:0DB8::1]:80", true, "http://[2001:db8::1]/")]
public void TryParseCanParseHostName(string query, bool expectedSuccess, string expectedResult)
{
// Arrange

View file

@ -2,23 +2,24 @@
// The Microsoft Corporation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using NUnit.Framework;
using Microsoft.VisualStudio.TestTools.UnitTesting;
namespace Microsoft.PowerToys.Run.Plugin.Calculator.UnitTests
{
[TestFixture]
[TestClass]
public class BracketHelperTests
{
[TestCase(null)]
[TestCase("")]
[TestCase("\t \r\n")]
[TestCase("none")]
[TestCase("()")]
[TestCase("(())")]
[TestCase("()()")]
[TestCase("(()())")]
[TestCase("([][])")]
[TestCase("([(()[])[](([]()))])")]
[DataTestMethod]
[DataRow(null)]
[DataRow("")]
[DataRow("\t \r\n")]
[DataRow("none")]
[DataRow("()")]
[DataRow("(())")]
[DataRow("()()")]
[DataRow("(()())")]
[DataRow("([][])")]
[DataRow("([(()[])[](([]()))])")]
public void IsBracketComplete_TestValid_WhenCalled(string input)
{
// Arrange
@ -30,11 +31,12 @@ namespace Microsoft.PowerToys.Run.Plugin.Calculator.UnitTests
Assert.IsTrue(result);
}
[TestCase("((((", "only opening brackets")]
[TestCase("]]]", "only closing brackets")]
[TestCase("([)(])", "inner bracket mismatch")]
[TestCase(")(", "opening and closing reversed")]
[TestCase("(]", "mismatch in bracket type")]
[DataTestMethod]
[DataRow("((((", "only opening brackets")]
[DataRow("]]]", "only closing brackets")]
[DataRow("([)(])", "inner bracket mismatch")]
[DataRow(")(", "opening and closing reversed")]
[DataRow("(]", "mismatch in bracket type")]
public void IsBracketComplete_TestInvalid_WhenCalled(string input, string invalidReason)
{
// Arrange

View file

@ -3,39 +3,43 @@
// See the LICENSE file in the project root for more information.
using System;
using System.Collections.Generic;
using System.Globalization;
using NUnit.Framework;
using Microsoft.VisualStudio.TestTools.UnitTesting;
namespace Microsoft.PowerToys.Run.Plugin.Calculator.UnitTests
{
[TestFixture]
[TestClass]
public class ExtendedCalculatorParserTests
{
[TestCase(null)]
[TestCase("")]
[TestCase(" ")]
[DataTestMethod]
[DataRow(null)]
[DataRow("")]
[DataRow(" ")]
public void InputValid_ThrowError_WhenCalledNullOrEmpty(string input)
{
// Act
Assert.Catch<ArgumentNullException>(() => CalculateHelper.InputValid(input));
Assert.ThrowsException<ArgumentNullException>(() => CalculateHelper.InputValid(input));
}
[TestCase(null)]
[TestCase("")]
[TestCase(" ")]
[DataTestMethod]
[DataRow(null)]
[DataRow("")]
[DataRow(" ")]
public void Interpret_ThrowError_WhenCalledNullOrEmpty(string input)
{
// Arrange
var engine = new CalculateEngine();
// Act
Assert.Catch<ArgumentNullException>(() => engine.Interpret(input));
Assert.ThrowsException<ArgumentNullException>(() => engine.Interpret(input));
}
[TestCase("42")]
[TestCase("test")]
[TestCase("pi(2)")] // Incorrect input, constant is being treated as a function.
[TestCase("e(2)")]
[DataTestMethod]
[DataRow("42")]
[DataRow("test")]
[DataRow("pi(2)")] // Incorrect input, constant is being treated as a function.
[DataRow("e(2)")]
public void Interpret_NoResult_WhenCalled(string input)
{
// Arrange
@ -48,25 +52,32 @@ namespace Microsoft.PowerToys.Run.Plugin.Calculator.UnitTests
Assert.AreEqual(default(CalculateResult), result);
}
[TestCase("2 * 2", 4D)]
[TestCase("-2 ^ 2", 4D)]
[TestCase("-(2 ^ 2)", -4D)]
[TestCase("2 * pi", 6.28318530717959D)]
[TestCase("round(2 * pi)", 6D)]
[TestCase("1 == 2", default(double))]
[TestCase("pi * ( sin ( cos ( 2)))", -1.26995475603563D)]
[TestCase("5.6/2", 2.8D)]
[TestCase("123 * 4.56", 560.88D)]
[TestCase("1 - 9.0 / 10", 0.1D)]
[TestCase("0.5 * ((2*-395.2)+198.2)", -296.1D)]
[TestCase("2+2.11", 4.11D)]
[TestCase("8.43 + 4.43 - 12.86", 0D)]
[TestCase("8.43 + 4.43 - 12.8", 0.06D)]
[TestCase("exp(5)", 148.413159102577D)]
[TestCase("e^5", 148.413159102577D)]
[TestCase("e*2", 5.43656365691809D)]
[TestCase("log(e)", 1D)]
[TestCase("cosh(0)", 1D)]
private static IEnumerable<object[]> Interpret_NoErrors_WhenCalledWithRounding_Data =>
new[]
{
new object[] { "2 * 2", 4M },
new object[] { "-2 ^ 2", 4M },
new object[] { "-(2 ^ 2)", -4M },
new object[] { "2 * pi", 6.28318530717959M },
new object[] { "round(2 * pi)", 6M },
new object[] { "1 == 2", default(decimal) },
new object[] { "pi * ( sin ( cos ( 2)))", -1.26995475603563M },
new object[] { "5.6/2", 2.8M },
new object[] { "123 * 4.56", 560.88M },
new object[] { "1 - 9.0 / 10", 0.1M },
new object[] { "0.5 * ((2*-395.2)+198.2)", -296.1M },
new object[] { "2+2.11", 4.11M },
new object[] { "8.43 + 4.43 - 12.86", 0M },
new object[] { "8.43 + 4.43 - 12.8", 0.06M },
new object[] { "exp(5)", 148.413159102577M },
new object[] { "e^5", 148.413159102577M },
new object[] { "e*2", 5.43656365691809M },
new object[] { "log(e)", 1M },
new object[] { "cosh(0)", 1M },
};
[DataTestMethod]
[DynamicData(nameof(Interpret_NoErrors_WhenCalledWithRounding_Data))]
public void Interpret_NoErrors_WhenCalledWithRounding(string input, decimal expectedResult)
{
// Arrange
@ -81,9 +92,16 @@ namespace Microsoft.PowerToys.Run.Plugin.Calculator.UnitTests
Assert.AreEqual(CalculateEngine.Round(expectedResult), result.RoundedResult);
}
[TestCase("0.100000000000000000000", 0.00776627963145224D)] // BUG: Because data structure
[TestCase("0.200000000000000000000000", 0.000000400752841041379D)] // BUG: Because data structure
[TestCase("123 456", 56088D)] // BUG: Framework accepts ' ' as multiplication
private static IEnumerable<object[]> Interpret_QuirkOutput_WhenCalled_Data =>
new[]
{
new object[] { "0.100000000000000000000", 0.00776627963145224M }, // BUG: Because data structure
new object[] { "0.200000000000000000000000", 0.000000400752841041379M }, // BUG: Because data structure
new object[] { "123 456", 56088M }, // BUG: Framework accepts ' ' as multiplication
};
[DynamicData(nameof(Interpret_QuirkOutput_WhenCalled_Data))]
[DataTestMethod]
public void Interpret_QuirkOutput_WhenCalled(string input, decimal expectedResult)
{
// Arrange
@ -98,9 +116,16 @@ namespace Microsoft.PowerToys.Run.Plugin.Calculator.UnitTests
Assert.AreEqual(expectedResult, result.Result);
}
[TestCase("4.5/3", 1.5D, "nl-NL")]
[TestCase("4.5/3", 1.5D, "en-EN")]
[TestCase("4.5/3", 1.5D, "de-DE")]
private static IEnumerable<object[]> Interpret_DifferentCulture_WhenCalled_Data =>
new[]
{
new object[] { "4.5/3", 1.5M, "nl-NL" },
new object[] { "4.5/3", 1.5M, "en-EN" },
new object[] { "4.5/3", 1.5M, "de-DE" },
};
[DataTestMethod]
[DynamicData(nameof(Interpret_DifferentCulture_WhenCalled_Data))]
public void Interpret_DifferentCulture_WhenCalled(string input, decimal expectedResult, string cultureName)
{
// Arrange
@ -115,23 +140,24 @@ namespace Microsoft.PowerToys.Run.Plugin.Calculator.UnitTests
Assert.AreEqual(CalculateEngine.Round(expectedResult), result.RoundedResult);
}
[TestCase("ceil(2 * (pi ^ 2))", true)]
[TestCase("((1 * 2)", false)]
[TestCase("(1 * 2)))", false)]
[TestCase("abcde", false)]
[TestCase("1 + 2 +", false)]
[TestCase("1+2*", false)]
[TestCase("1 && 3 &&", false)]
[TestCase("sqrt( 36)", true)]
[TestCase("max 4", false)]
[TestCase("sin(0)", true)]
[TestCase("sinh(1)", true)]
[TestCase("tanh(0)", true)]
[TestCase("artanh(pi/2)", true)]
[TestCase("cosh", false)]
[TestCase("cos", false)]
[TestCase("abs", false)]
[TestCase("1+1.1e3", true)]
[DataTestMethod]
[DataRow("ceil(2 * (pi ^ 2))", true)]
[DataRow("((1 * 2)", false)]
[DataRow("(1 * 2)))", false)]
[DataRow("abcde", false)]
[DataRow("1 + 2 +", false)]
[DataRow("1+2*", false)]
[DataRow("1 && 3 &&", false)]
[DataRow("sqrt( 36)", true)]
[DataRow("max 4", false)]
[DataRow("sin(0)", true)]
[DataRow("sinh(1)", true)]
[DataRow("tanh(0)", true)]
[DataRow("artanh(pi/2)", true)]
[DataRow("cosh", false)]
[DataRow("cos", false)]
[DataRow("abs", false)]
[DataRow("1+1.1e3", true)]
public void InputValid_TestValid_WhenCalled(string input, bool valid)
{
// Arrange
@ -143,9 +169,10 @@ namespace Microsoft.PowerToys.Run.Plugin.Calculator.UnitTests
Assert.AreEqual(valid, result);
}
[TestCase("1-1")]
[TestCase("sin(0)")]
[TestCase("sinh(0)")]
[DataTestMethod]
[DataRow("1-1")]
[DataRow("sin(0)")]
[DataRow("sinh(0)")]
public void Interpret_MustReturnResult_WhenResultIsZero(string input)
{
// Arrange
@ -157,14 +184,21 @@ namespace Microsoft.PowerToys.Run.Plugin.Calculator.UnitTests
// Assert
Assert.IsNotNull(result);
Assert.AreEqual(0.0, result.Result);
Assert.AreEqual(0.0M, result.Result);
}
[TestCase("factorial(5)", 120)]
[TestCase("sign(-2)", -1)]
[TestCase("sign(2)", +1)]
[TestCase("abs(-2)", 2)]
[TestCase("abs(2)", 2)]
private static IEnumerable<object[]> Interpret_MustReturnExpectedResult_WhenCalled_Data =>
new[]
{
new object[] { "factorial(5)", 120M },
new object[] { "sign(-2)", -1M },
new object[] { "sign(2)", +1M },
new object[] { "abs(-2)", 2M },
new object[] { "abs(2)", 2M },
};
[DataTestMethod]
[DynamicData(nameof(Interpret_MustReturnExpectedResult_WhenCalled_Data))]
public void Interpret_MustReturnExpectedResult_WhenCalled(string input, decimal expectedResult)
{
// Arrange

View file

@ -10,9 +10,9 @@
</PropertyGroup>
<ItemGroup>
<PackageReference Include="nunit" Version="3.13.1" />
<PackageReference Include="NUnit3TestAdapter" Version="3.17.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.9.1" />
<PackageReference Include="MSTest.TestAdapter" Version="2.2.5" />
<PackageReference Include="MSTest.TestFramework" Version="2.2.5" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.10.0" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Microsoft.PowerToys.Run.Plugin.Calculator\Microsoft.PowerToys.Run.Plugin.Calculator.csproj" />

View file

@ -4,15 +4,16 @@
using System;
using System.Globalization;
using NUnit.Framework;
using Microsoft.VisualStudio.TestTools.UnitTesting;
namespace Microsoft.PowerToys.Run.Plugin.Calculator.UnitTests
{
[TestFixture]
[TestClass]
public class NumberTranslatorTests
{
[TestCase(null, "en-US")]
[TestCase("de-DE", null)]
[DataTestMethod]
[DataRow(null, "en-US")]
[DataRow("de-DE", null)]
public void Create_ThrowError_WhenCalledNullOrEmpty(string sourceCultureName, string targetCultureName)
{
// Arrange
@ -20,12 +21,13 @@ namespace Microsoft.PowerToys.Run.Plugin.Calculator.UnitTests
CultureInfo targetCulture = targetCultureName != null ? new CultureInfo(targetCultureName) : null;
// Act
Assert.Catch<ArgumentNullException>(() => NumberTranslator.Create(sourceCulture, targetCulture));
Assert.ThrowsException<ArgumentNullException>(() => NumberTranslator.Create(sourceCulture, targetCulture));
}
[TestCase("en-US", "en-US")]
[TestCase("en-EN", "en-US")]
[TestCase("de-DE", "en-US")]
[DataTestMethod]
[DataRow("en-US", "en-US")]
[DataRow("en-EN", "en-US")]
[DataRow("de-DE", "en-US")]
public void Create_WhenCalled(string sourceCultureName, string targetCultureName)
{
// Arrange
@ -39,18 +41,20 @@ namespace Microsoft.PowerToys.Run.Plugin.Calculator.UnitTests
Assert.IsNotNull(translator);
}
[TestCase(null)]
[DataTestMethod]
[DataRow(null)]
public void Translate_ThrowError_WhenCalledNull(string input)
{
// Arrange
var translator = NumberTranslator.Create(new CultureInfo("de-DE"), new CultureInfo("en-US"));
// Act
Assert.Catch<ArgumentNullException>(() => translator.Translate(input));
Assert.ThrowsException<ArgumentNullException>(() => translator.Translate(input));
}
[TestCase("")]
[TestCase(" ")]
[DataTestMethod]
[DataRow("")]
[DataRow(" ")]
public void Translate_WhenCalledEmpty(string input)
{
// Arrange
@ -63,11 +67,12 @@ namespace Microsoft.PowerToys.Run.Plugin.Calculator.UnitTests
Assert.AreEqual(input, result);
}
[TestCase("2,0 * 2", "2.0 * 2")]
[TestCase("4 * 3,6 + 9", "4 * 3.6 + 9")]
[TestCase("5,2+6", "5.2+6")]
[TestCase("round(2,5)", "round(2.5)")]
[TestCase("3,3333", "3.3333")]
[DataTestMethod]
[DataRow("2,0 * 2", "2.0 * 2")]
[DataRow("4 * 3,6 + 9", "4 * 3.6 + 9")]
[DataRow("5,2+6", "5.2+6")]
[DataRow("round(2,5)", "round(2.5)")]
[DataRow("3,3333", "3.3333")]
public void Translate_NoErrors_WhenCalled(string input, string expectedResult)
{
// Arrange
@ -81,11 +86,12 @@ namespace Microsoft.PowerToys.Run.Plugin.Calculator.UnitTests
Assert.AreEqual(expectedResult, result);
}
[TestCase("2.0 * 2", "2,0 * 2")]
[TestCase("4 * 3.6 + 9", "4 * 3,6 + 9")]
[TestCase("5.2+6", "5,2+6")]
[TestCase("round(2.5)", "round(2,5)")]
[TestCase("3.3333", "3,3333")]
[DataTestMethod]
[DataRow("2.0 * 2", "2,0 * 2")]
[DataRow("4 * 3.6 + 9", "4 * 3,6 + 9")]
[DataRow("5.2+6", "5,2+6")]
[DataRow("round(2.5)", "round(2,5)")]
[DataRow("3.3333", "3,3333")]
public void TranslateBack_NoErrors_WhenCalled(string input, string expectedResult)
{
// Arrange
@ -99,10 +105,11 @@ namespace Microsoft.PowerToys.Run.Plugin.Calculator.UnitTests
Assert.AreEqual(expectedResult, result);
}
[TestCase(".", ",", "2,000,000", "2000000")]
[TestCase(".", ",", "2,000,000.6", "2000000.6")]
[TestCase(",", ".", "2.000.000", "2000000")]
[TestCase(",", ".", "2.000.000,6", "2000000.6")]
[DataTestMethod]
[DataRow(".", ",", "2,000,000", "2000000")]
[DataRow(".", ",", "2,000,000.6", "2000000.6")]
[DataRow(",", ".", "2.000.000", "2000000")]
[DataRow(",", ".", "2.000.000,6", "2000000.6")]
public void Translate_RemoveNumberGroupSeparator_WhenCalled(string decimalSeparator, string groupSeparator, string input, string expectedResult)
{
// Arrange

View file

@ -33,9 +33,9 @@
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.9.1" />
<PackageReference Include="MSTest.TestAdapter" Version="2.2.3" />
<PackageReference Include="MSTest.TestFramework" Version="2.2.3" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.10.0" />
<PackageReference Include="MSTest.TestAdapter" Version="2.2.5" />
<PackageReference Include="MSTest.TestFramework" Version="2.2.5" />
</ItemGroup>
<ItemGroup>

View file

@ -3,31 +3,30 @@
// See the LICENSE file in the project root for more information.
using System.Linq;
using System.Text;
using Mono.Collections.Generic;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Moq;
using NUnit.Framework;
using Wox.Infrastructure;
using Wox.Plugin;
namespace Microsoft.PowerToys.Run.Plugin.System.UnitTests
{
[TestFixture]
[TestClass]
public class ImageTests
{
[SetUp]
[TestInitialize]
public void Setup()
{
StringMatcher.Instance = new StringMatcher();
}
[TestCase("shutdown", "Images\\shutdown.dark.png")]
[TestCase("restart", "Images\\restart.dark.png")]
[TestCase("sign out", "Images\\logoff.dark.png")]
[TestCase("lock", "Images\\lock.dark.png")]
[TestCase("sleep", "Images\\sleep.dark.png")]
[TestCase("hibernate", "Images\\sleep.dark.png")]
[TestCase("empty recycle", "Images\\recyclebin.dark.png")]
[DataTestMethod]
[DataRow("shutdown", "Images\\shutdown.dark.png")]
[DataRow("restart", "Images\\restart.dark.png")]
[DataRow("sign out", "Images\\logoff.dark.png")]
[DataRow("lock", "Images\\lock.dark.png")]
[DataRow("sleep", "Images\\sleep.dark.png")]
[DataRow("hibernate", "Images\\sleep.dark.png")]
[DataRow("empty recycle", "Images\\recyclebin.dark.png")]
public void IconThemeDarkTest(string typedString, string expectedResult)
{
// Setup
@ -42,13 +41,14 @@ namespace Microsoft.PowerToys.Run.Plugin.System.UnitTests
Assert.AreEqual(expectedResult, result);
}
[TestCase("shutdown", "Images\\shutdown.light.png")]
[TestCase("restart", "Images\\restart.light.png")]
[TestCase("sign out", "Images\\logoff.light.png")]
[TestCase("lock", "Images\\lock.light.png")]
[TestCase("sleep", "Images\\sleep.light.png")]
[TestCase("hibernate", "Images\\sleep.light.png")]
[TestCase("empty recycle", "Images\\recyclebin.light.png")]
[DataTestMethod]
[DataRow("shutdown", "Images\\shutdown.light.png")]
[DataRow("restart", "Images\\restart.light.png")]
[DataRow("sign out", "Images\\logoff.light.png")]
[DataRow("lock", "Images\\lock.light.png")]
[DataRow("sleep", "Images\\sleep.light.png")]
[DataRow("hibernate", "Images\\sleep.light.png")]
[DataRow("empty recycle", "Images\\recyclebin.light.png")]
public void IconThemeLightTest(string typedString, string expectedResult)
{
// Setup

View file

@ -15,9 +15,9 @@
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Moq" Version="4.16.1" />
<PackageReference Include="NUnit" Version="3.13.1" />
<PackageReference Include="NUnit3TestAdapter" Version="3.17.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.9.1" />
<PackageReference Include="MSTest.TestAdapter" Version="2.2.5" />
<PackageReference Include="MSTest.TestFramework" Version="2.2.5" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.10.0" />
<PackageReference Include="StyleCop.Analyzers" Version="1.1.118">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>

View file

@ -3,29 +3,30 @@
// See the LICENSE file in the project root for more information.
using System.Linq;
using Mono.Collections.Generic;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Moq;
using NUnit.Framework;
using Wox.Infrastructure;
using Wox.Plugin;
namespace Microsoft.PowerToys.Run.Plugin.System.UnitTests
{
[TestClass]
public class QueryTests
{
[SetUp]
[TestInitialize]
public void Setup()
{
StringMatcher.Instance = new StringMatcher();
}
[TestCase("shutdown", "Shutdown computer")]
[TestCase("restart", "Restart computer")]
[TestCase("sign out", "Sign out of computer")]
[TestCase("lock", "Lock computer")]
[TestCase("sleep", "Put computer to sleep")]
[TestCase("hibernate", "Hibernate computer")]
[TestCase("empty recycle", "Empty Recycle Bin")]
[DataTestMethod]
[DataRow("shutdown", "Shutdown computer")]
[DataRow("restart", "Restart computer")]
[DataRow("sign out", "Sign out of computer")]
[DataRow("lock", "Lock computer")]
[DataRow("sleep", "Put computer to sleep")]
[DataRow("hibernate", "Hibernate computer")]
[DataRow("empty recycle", "Empty Recycle Bin")]
public void QueryResults(string typedString, string expectedResult)
{
// Setup

View file

@ -7,13 +7,13 @@ using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.Linq;
using NUnit.Framework;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Wox.Infrastructure;
using Wox.Plugin;
namespace Wox.Test
{
[TestFixture]
[TestClass]
public class FuzzyMatcherTest
{
private const string Chrome = "Chrome";
@ -49,7 +49,7 @@ namespace Wox.Test
return listToReturn;
}
[Test]
[TestMethod]
public void MatchTest()
{
var sources = new List<string>
@ -80,22 +80,24 @@ namespace Wox.Test
Assert.IsTrue(results[2].Title == "file open in browser-test");
}
[TestCase("Chrome")]
[DataTestMethod]
[DataRow("Chrome")]
public void WhenGivenNotAllCharactersFoundInSearchStringThenShouldReturnZeroScore(string searchString)
{
var compareString = "Can have rum only in my glass";
var matcher = new StringMatcher();
var scoreResult = matcher.FuzzyMatch(searchString, compareString).RawScore;
Assert.True(scoreResult == 0);
Assert.IsTrue(scoreResult == 0);
}
[TestCase("chr")]
[TestCase("chrom")]
[TestCase("chrome")]
[TestCase("cand")]
[TestCase("cpywa")]
[TestCase("ccs")]
[DataTestMethod]
[DataRow("chr")]
[DataRow("chrom")]
[DataRow("chrome")]
[DataRow("cand")]
[DataRow("cpywa")]
[DataRow("ccs")]
public void WhenGivenStringsAndAppliedPrecisionFilteringThenShouldReturnGreaterThanPrecisionScoreResults(string searchTerm)
{
var results = new List<Result>();
@ -129,7 +131,8 @@ namespace Wox.Test
}
}
[TestCase("vim", "Vim", "ignoreDescription", "ignore.exe", "Vim Diff", "ignoreDescription", "ignore.exe")]
[DataTestMethod]
[DataRow("vim", "Vim", "ignoreDescription", "ignore.exe", "Vim Diff", "ignoreDescription", "ignore.exe")]
public void WhenMultipleResultsExactMatchingResultShouldHaveGreatestScore(string queryString, string firstName, string firstDescription, string firstExecutableName, string secondName, string secondDescription, string secondExecutableName)
{
// Act
@ -149,16 +152,17 @@ namespace Wox.Test
Assert.IsTrue(firstScore > secondScore);
}
[TestCase("goo", "Google Chrome", StringMatcher.SearchPrecisionScore.Regular, true)]
[TestCase("chr", "Google Chrome", StringMatcher.SearchPrecisionScore.Low, true)]
[TestCase("chr", "Chrome", StringMatcher.SearchPrecisionScore.Regular, true)]
[TestCase("chr", "Help cure hope raise on mind entity Chrome", StringMatcher.SearchPrecisionScore.Regular, false)]
[TestCase("chr", "Help cure hope raise on mind entity Chrome", StringMatcher.SearchPrecisionScore.Low, true)]
[TestCase("chr", "Candy Crush Saga from King", StringMatcher.SearchPrecisionScore.Regular, false)]
[TestCase("chr", "Candy Crush Saga from King", StringMatcher.SearchPrecisionScore.None, true)]
[TestCase("ccs", "Candy Crush Saga from King", StringMatcher.SearchPrecisionScore.Low, true)]
[TestCase("cand", "Candy Crush Saga from King", StringMatcher.SearchPrecisionScore.Regular, true)]
[TestCase("cand", "Help cure hope raise on mind entity Chrome", StringMatcher.SearchPrecisionScore.Regular, false)]
[DataTestMethod]
[DataRow("goo", "Google Chrome", StringMatcher.SearchPrecisionScore.Regular, true)]
[DataRow("chr", "Google Chrome", StringMatcher.SearchPrecisionScore.Low, true)]
[DataRow("chr", "Chrome", StringMatcher.SearchPrecisionScore.Regular, true)]
[DataRow("chr", "Help cure hope raise on mind entity Chrome", StringMatcher.SearchPrecisionScore.Regular, false)]
[DataRow("chr", "Help cure hope raise on mind entity Chrome", StringMatcher.SearchPrecisionScore.Low, true)]
[DataRow("chr", "Candy Crush Saga from King", StringMatcher.SearchPrecisionScore.Regular, false)]
[DataRow("chr", "Candy Crush Saga from King", StringMatcher.SearchPrecisionScore.None, true)]
[DataRow("ccs", "Candy Crush Saga from King", StringMatcher.SearchPrecisionScore.Low, true)]
[DataRow("cand", "Candy Crush Saga from King", StringMatcher.SearchPrecisionScore.Regular, true)]
[DataRow("cand", "Help cure hope raise on mind entity Chrome", StringMatcher.SearchPrecisionScore.Regular, false)]
public void WhenGivenDesiredPrecisionThenShouldReturnAllResultsGreaterOrEqual(
string queryString,
string compareString,
@ -185,23 +189,24 @@ namespace Wox.Test
$"{$"Query:{queryString}{Environment.NewLine} "}{$"Compare:{compareString}{Environment.NewLine}"}{$"Raw Score: {matchResult.RawScore}{Environment.NewLine}"}{$"Precision Score: {(int)expectedPrecisionScore}"}");
}
[TestCase("exce", "OverLeaf-Latex: An online LaTeX editor", StringMatcher.SearchPrecisionScore.Regular, false)]
[TestCase("term", "Windows Terminal (Preview)", StringMatcher.SearchPrecisionScore.Regular, true)]
[TestCase("sql s managa", MicrosoftSqlServerManagementStudio, StringMatcher.SearchPrecisionScore.Regular, false)]
[TestCase("sql' s manag", MicrosoftSqlServerManagementStudio, StringMatcher.SearchPrecisionScore.Regular, false)]
[TestCase("sql s manag", MicrosoftSqlServerManagementStudio, StringMatcher.SearchPrecisionScore.Regular, true)]
[TestCase("sql manag", MicrosoftSqlServerManagementStudio, StringMatcher.SearchPrecisionScore.Regular, true)]
[TestCase("sql", MicrosoftSqlServerManagementStudio, StringMatcher.SearchPrecisionScore.Regular, true)]
[TestCase("sql serv", MicrosoftSqlServerManagementStudio, StringMatcher.SearchPrecisionScore.Regular, true)]
[TestCase("sql serv man", MicrosoftSqlServerManagementStudio, StringMatcher.SearchPrecisionScore.Regular, true)]
[TestCase("sql studio", MicrosoftSqlServerManagementStudio, StringMatcher.SearchPrecisionScore.Regular, true)]
[TestCase("mic", MicrosoftSqlServerManagementStudio, StringMatcher.SearchPrecisionScore.Regular, true)]
[TestCase("chr", "Shutdown", StringMatcher.SearchPrecisionScore.Regular, false)]
[TestCase("mssms", MicrosoftSqlServerManagementStudio, StringMatcher.SearchPrecisionScore.Regular, false)]
[TestCase("chr", "Change settings for text-to-speech and for speech recognition (if installed).", StringMatcher.SearchPrecisionScore.Regular, false)]
[TestCase("ch r", "Change settings for text-to-speech and for speech recognition (if installed).", StringMatcher.SearchPrecisionScore.Regular, true)]
[TestCase("a test", "This is a test", StringMatcher.SearchPrecisionScore.Regular, true)]
[TestCase("test", "This is a test", StringMatcher.SearchPrecisionScore.Regular, true)]
[DataTestMethod]
[DataRow("exce", "OverLeaf-Latex: An online LaTeX editor", StringMatcher.SearchPrecisionScore.Regular, false)]
[DataRow("term", "Windows Terminal (Preview)", StringMatcher.SearchPrecisionScore.Regular, true)]
[DataRow("sql s managa", MicrosoftSqlServerManagementStudio, StringMatcher.SearchPrecisionScore.Regular, false)]
[DataRow("sql' s manag", MicrosoftSqlServerManagementStudio, StringMatcher.SearchPrecisionScore.Regular, false)]
[DataRow("sql s manag", MicrosoftSqlServerManagementStudio, StringMatcher.SearchPrecisionScore.Regular, true)]
[DataRow("sql manag", MicrosoftSqlServerManagementStudio, StringMatcher.SearchPrecisionScore.Regular, true)]
[DataRow("sql", MicrosoftSqlServerManagementStudio, StringMatcher.SearchPrecisionScore.Regular, true)]
[DataRow("sql serv", MicrosoftSqlServerManagementStudio, StringMatcher.SearchPrecisionScore.Regular, true)]
[DataRow("sql serv man", MicrosoftSqlServerManagementStudio, StringMatcher.SearchPrecisionScore.Regular, true)]
[DataRow("sql studio", MicrosoftSqlServerManagementStudio, StringMatcher.SearchPrecisionScore.Regular, true)]
[DataRow("mic", MicrosoftSqlServerManagementStudio, StringMatcher.SearchPrecisionScore.Regular, true)]
[DataRow("chr", "Shutdown", StringMatcher.SearchPrecisionScore.Regular, false)]
[DataRow("mssms", MicrosoftSqlServerManagementStudio, StringMatcher.SearchPrecisionScore.Regular, false)]
[DataRow("chr", "Change settings for text-to-speech and for speech recognition (if installed).", StringMatcher.SearchPrecisionScore.Regular, false)]
[DataRow("ch r", "Change settings for text-to-speech and for speech recognition (if installed).", StringMatcher.SearchPrecisionScore.Regular, true)]
[DataRow("a test", "This is a test", StringMatcher.SearchPrecisionScore.Regular, true)]
[DataRow("test", "This is a test", StringMatcher.SearchPrecisionScore.Regular, true)]
public void WhenGivenQueryShouldReturnResultsContainingAllQuerySubstrings(
string queryString,
string compareString,
@ -228,8 +233,9 @@ namespace Wox.Test
$"{$"Query:{queryString}{Environment.NewLine} "}{$"Compare:{compareString}{Environment.NewLine}"}{$"Raw Score: {matchResult.RawScore}{Environment.NewLine}"}{$"Precision Score: {(int)expectedPrecisionScore}"}");
}
[TestCase("Windows Terminal", "Windows_Terminal", "term")]
[TestCase("Windows Terminal", "WindowsTerminal", "term")]
[DataTestMethod]
[DataRow("Windows Terminal", "Windows_Terminal", "term")]
[DataRow("Windows Terminal", "WindowsTerminal", "term")]
public void FuzzyMatchingScoreShouldBeHigherWhenPreceedingCharacterIsSpace(string firstCompareStr, string secondCompareStr, string query)
{
// Arrange

View file

@ -2,16 +2,16 @@
// The Microsoft Corporation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using NUnit.Framework;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using PowerLauncher.ViewModel;
namespace Wox.Test
{
[TestFixture]
internal class MainViewModelTest
[TestClass]
public class MainViewModelTest
{
[Test]
public void MainViewModel_GetAutoCompleteTextReturnsEmptyString_WhenInputIsNull()
[TestMethod]
public void MainViewModelGetAutoCompleteTextReturnsEmptyStringWhenInputIsNull()
{
// Arrange
int index = 0;
@ -25,8 +25,8 @@ namespace Wox.Test
Assert.AreEqual(string.Empty, autoCompleteText);
}
[Test]
public void MainViewModel_GetAutoCompleteTextReturnsEmptyString_WhenInputIsEmpty()
[TestMethod]
public void MainViewModelGetAutoCompleteTextReturnsEmptyStringWhenInputIsEmpty()
{
// Arrange
int index = 0;
@ -40,8 +40,8 @@ namespace Wox.Test
Assert.AreEqual(string.Empty, autoCompleteText);
}
[Test]
public void MainViewModel_GetAutoCompleteTextReturnsEmptyString_WhenQueryIsNull()
[TestMethod]
public void MainViewModelGetAutoCompleteTextReturnsEmptyStringWhenQueryIsNull()
{
// Arrange
int index = 0;
@ -55,8 +55,8 @@ namespace Wox.Test
Assert.AreEqual(string.Empty, autoCompleteText);
}
[Test]
public void MainViewModel_GetAutoCompleteTextReturnsEmptyString_WhenQueryIsEmpty()
[TestMethod]
public void MainViewModelGetAutoCompleteTextReturnsEmptyStringWhenQueryIsEmpty()
{
// Arrange
int index = 0;
@ -70,8 +70,8 @@ namespace Wox.Test
Assert.AreEqual(string.Empty, autoCompleteText);
}
[Test]
public void MainViewModel_GetAutoCompleteTextReturnsEmptyString_WhenIndexIsNonZero()
[TestMethod]
public void MainViewModelGetAutoCompleteTextReturnsEmptyStringWhenIndexIsNonZero()
{
// Arrange
int index = 2;
@ -85,8 +85,8 @@ namespace Wox.Test
Assert.AreEqual(string.Empty, autoCompleteText);
}
[Test]
public void MainViewModel_GetAutoCompleteTextReturnsMatchingString_WhenIndexIsZeroAndMatch()
[TestMethod]
public void MainViewModelGetAutoCompleteTextReturnsMatchingStringWhenIndexIsZeroAndMatch()
{
// Arrange
int index = 0;
@ -101,8 +101,8 @@ namespace Wox.Test
Assert.AreEqual(expectedAutoCompleteText, autoCompleteText);
}
[Test]
public void MainViewModel_GetAutoCompleteTextReturnsEmptyString_WhenIndexIsZeroAndNoMatch()
[TestMethod]
public void MainViewModelGetAutoCompleteTextReturnsEmptyStringWhenIndexIsZeroAndNoMatch()
{
// Arrange
int index = 0;
@ -117,8 +117,8 @@ namespace Wox.Test
Assert.AreEqual(expectedAutoCompleteText, autoCompleteText);
}
[Test]
public void MainViewModel_GetSearchTextReturnsEmptyString_WhenInputIsNull()
[TestMethod]
public void MainViewModelGetSearchTextReturnsEmptyStringWhenInputIsNull()
{
// Arrange
int index = 0;
@ -132,8 +132,8 @@ namespace Wox.Test
Assert.AreEqual(string.Empty, autoCompleteText);
}
[Test]
public void MainViewModel_GetSearchTextReturnsEmptyString_WhenInputIsEmpty()
[TestMethod]
public void MainViewModelGetSearchTextReturnsEmptyStringWhenInputIsEmpty()
{
// Arrange
int index = 0;
@ -147,8 +147,8 @@ namespace Wox.Test
Assert.AreEqual(string.Empty, autoCompleteText);
}
[Test]
public void MainViewModel_GetSearchTextReturnsInputString_WhenQueryIsNull()
[TestMethod]
public void MainViewModelGetSearchTextReturnsInputStringWhenQueryIsNull()
{
// Arrange
int index = 0;
@ -162,8 +162,8 @@ namespace Wox.Test
Assert.AreEqual(input, autoCompleteText);
}
[Test]
public void MainViewModel_GetSearchTextReturnsInputString_WhenQueryIsEmpty()
[TestMethod]
public void MainViewModelGetSearchTextReturnsInputStringWhenQueryIsEmpty()
{
// Arrange
int index = 0;
@ -177,8 +177,8 @@ namespace Wox.Test
Assert.AreEqual(input, autoCompleteText);
}
[Test]
public void MainViewModel_GetSearchTextReturnsMatchingStringWithCase_WhenIndexIsZeroAndMatch()
[TestMethod]
public void MainViewModelGetSearchTextReturnsMatchingStringWithCaseWhenIndexIsZeroAndMatch()
{
// Arrange
int index = 0;
@ -193,8 +193,8 @@ namespace Wox.Test
Assert.AreEqual(expectedAutoCompleteText, autoCompleteText);
}
[Test]
public void MainViewModel_GetSearchTextReturnsInput_WhenIndexIsZeroAndNoMatch()
[TestMethod]
public void MainViewModelGetSearchTextReturnsInputWhenIndexIsZeroAndNoMatch()
{
// Arrange
int index = 0;
@ -208,8 +208,8 @@ namespace Wox.Test
Assert.AreEqual(input, autoCompleteText);
}
[Test]
public void ShouldAutoCompleteTextBeEmpty_ShouldReturnFalse_WhenAutoCompleteTextIsEmpty()
[TestMethod]
public void ShouldAutoCompleteTextBeEmptyShouldReturnFalseWhenAutoCompleteTextIsEmpty()
{
// Arrange
string queryText = "Te";
@ -222,8 +222,8 @@ namespace Wox.Test
Assert.AreEqual(false, result);
}
[Test]
public void ShouldAutoCompleteTextBeEmpty_ShouldReturnTrue_WhenQueryTextMatchAutoCompleteText()
[TestMethod]
public void ShouldAutoCompleteTextBeEmptyShouldReturnTrueWhenQueryTextMatchAutoCompleteText()
{
// Arrange
string queryText = "Te";
@ -236,8 +236,8 @@ namespace Wox.Test
Assert.AreEqual(false, result);
}
[Test]
public void ShouldAutoCompleteTextBeEmpty_ShouldReturnTrue_WhenQueryTextIsEmpty()
[TestMethod]
public void ShouldAutoCompleteTextBeEmptyShouldReturnTrueWhenQueryTextIsEmpty()
{
// Arrange
string queryText = string.Empty;
@ -250,8 +250,8 @@ namespace Wox.Test
Assert.AreEqual(true, result);
}
[Test]
public void ShouldAutoCompleteTextBeEmpty_ShouldReturnTrue_WhenQueryTextDoesNotMatchAutoCompleteText()
[TestMethod]
public void ShouldAutoCompleteTextBeEmptyShouldReturnTrueWhenQueryTextDoesNotMatchAutoCompleteText()
{
// Arrange
string queryText = "TE";

View file

@ -3,25 +3,26 @@
// See the LICENSE file in the project root for more information.
using System.Collections.Generic;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Moq;
using NUnit.Framework;
using PowerLauncher.Plugin;
using Wox.Plugin;
namespace Wox.Test
{
[TestFixture]
[TestClass]
public class PluginManagerTest
{
[TestCase(">", "dummyQueryText", "dummyTitle", "> dummyQueryText")]
[TestCase(">", null, "dummyTitle", "> dummyTitle")]
[TestCase(">", "", "dummyTitle", "> dummyTitle")]
[TestCase("", "dummyQueryText", "dummyTitle", "dummyQueryText")]
[TestCase("", null, "dummyTitle", "dummyTitle")]
[TestCase("", "", "dummyTitle", "dummyTitle")]
[TestCase(null, "dummyQueryText", "dummyTitle", "dummyQueryText")]
[TestCase(null, null, "dummyTitle", "dummyTitle")]
[TestCase(null, "", "dummyTitle", "dummyTitle")]
[DataTestMethod]
[DataRow(">", "dummyQueryText", "dummyTitle", "> dummyQueryText")]
[DataRow(">", null, "dummyTitle", "> dummyTitle")]
[DataRow(">", "", "dummyTitle", "> dummyTitle")]
[DataRow("", "dummyQueryText", "dummyTitle", "dummyQueryText")]
[DataRow("", null, "dummyTitle", "dummyTitle")]
[DataRow("", "", "dummyTitle", "dummyTitle")]
[DataRow(null, "dummyQueryText", "dummyTitle", "dummyQueryText")]
[DataRow(null, null, "dummyTitle", "dummyTitle")]
[DataRow(null, "", "dummyTitle", "dummyTitle")]
public void QueryForPluginSetsActionKeywordWhenQueryTextDisplayIsEmpty(string actionKeyword, string queryTextDisplay, string title, string expectedResult)
{
// Arrange

View file

@ -4,16 +4,17 @@
using System.Collections.Generic;
using Microsoft.Plugin.Folder;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Moq;
using NUnit.Framework;
using Wox.Plugin;
namespace Wox.Test.Plugins
{
internal class FolderPluginTest
[TestClass]
public class FolderPluginTest
{
[Test]
public void ContextMenuLoader_ReturnContextMenuForFolderWithOpenInConsole_WhenLoadContextMenusIsCalled()
[TestMethod]
public void ContextMenuLoaderReturnContextMenuForFolderWithOpenInConsoleWhenLoadContextMenusIsCalled()
{
// Arrange
var mock = new Mock<IPublicAPI>();
@ -31,8 +32,8 @@ namespace Wox.Test.Plugins
Assert.AreEqual(Microsoft.Plugin.Folder.Properties.Resources.Microsoft_plugin_folder_open_in_console, contextMenuResults[1].Title);
}
[Test]
public void ContextMenuLoader_ReturnContextMenuForFileWithOpenInConsole_WhenLoadContextMenusIsCalled()
[TestMethod]
public void ContextMenuLoaderReturnContextMenuForFileWithOpenInConsoleWhenLoadContextMenusIsCalled()
{
// Arrange
var mock = new Mock<IPublicAPI>();

View file

@ -2,14 +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 NUnit.Framework;
using Microsoft.VisualStudio.TestTools.UnitTesting;
namespace Wox.Test.Plugins
{
[TestFixture]
[TestClass]
public class PluginInitTest
{
[Test]
[TestMethod]
public void PublicAPIIsNullTest()
{
// Assert.Throws(typeof(WoxFatalException), () => PluginManager.Initialize(null));

View file

@ -3,16 +3,16 @@
// See the LICENSE file in the project root for more information.
using System.Windows;
using NUnit.Framework;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Wox.Plugin;
namespace Wox.Test.Plugins
{
[TestFixture]
internal class ResultTest
[TestClass]
public class ResultTest
{
[Test]
public void Result_UpdatesToolTipVisibilityToVisible_WhenToolTipDataIsSet()
[TestMethod]
public void ResultUpdatesToolTipVisibilityToVisibleWhenToolTipDataIsSet()
{
// Arrange
Result res = new Result();
@ -25,8 +25,8 @@ namespace Wox.Test.Plugins
Assert.AreEqual(Visibility.Visible, res.ToolTipVisibility);
}
[Test]
public void Result_UpdatesToolTipVisibilityToCollapsed_WhenToolTipDataIsNotSet()
[TestMethod]
public void ResultUpdatesToolTipVisibilityToCollapsedWhenToolTipDataIsNotSet()
{
// Act
Result res = new Result();

View file

@ -3,23 +3,23 @@
// See the LICENSE file in the project root for more information.
using System;
using NUnit.Framework;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Wox.Plugin;
namespace Wox.Test.Plugins
{
[TestFixture]
internal class ToolTipDataTest
[TestClass]
public class ToolTipDataTest
{
[Test]
public void Constructor_ThrowsNullArgumentException_WhenToolTipTitleIsNull()
[TestMethod]
public void ConstructorThrowsNullArgumentExceptionWhenToolTipTitleIsNull()
{
// Arrange
string title = null;
string text = "text";
// Assert
var ex = Assert.Throws<ArgumentException>(() => new ToolTipData(title, text));
var ex = Assert.ThrowsException<ArgumentException>(() => new ToolTipData(title, text));
}
}
}

View file

@ -9,13 +9,13 @@ using Microsoft.Plugin.Indexer;
using Microsoft.Plugin.Indexer.DriveDetection;
using Microsoft.Plugin.Indexer.SearchHelper;
using Microsoft.Search.Interop;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Moq;
using NUnit.Framework;
using Wox.Plugin;
namespace Wox.Test.Plugins
{
[TestFixture]
[TestClass]
public class WindowsIndexerTest
{
private static WindowsSearchAPI GetWindowsSearchAPI()
@ -39,7 +39,7 @@ namespace Wox.Test.Plugins
return mockSearchManager.Object;
}
[Test]
[TestMethod]
public void InitQueryHelperShouldInitializeWhenFunctionIsCalled()
{
// Arrange
@ -56,7 +56,7 @@ namespace Wox.Test.Plugins
Assert.AreEqual(maxCount, queryHelper.QueryMaxResults);
}
[Test]
[TestMethod]
public void ModifyQueryHelperShouldSetQueryHelperWhenPatternIsAsterisk()
{
// Arrange
@ -75,7 +75,7 @@ namespace Wox.Test.Plugins
Assert.IsFalse(queryHelper.QueryWhereRestrictions.Contains("Contains", StringComparison.Ordinal));
}
[Test]
[TestMethod]
public void ModifyQueryHelperShouldSetQueryHelperWhenPatternContainsAsterisk()
{
// Arrange
@ -94,7 +94,7 @@ namespace Wox.Test.Plugins
Assert.IsFalse(queryHelper.QueryWhereRestrictions.Contains("Contains", StringComparison.Ordinal));
}
[Test]
[TestMethod]
public void ModifyQueryHelperShouldSetQueryHelperWhenPatternContainsPercent()
{
// Arrange
@ -113,7 +113,7 @@ namespace Wox.Test.Plugins
Assert.IsFalse(queryHelper.QueryWhereRestrictions.Contains("Contains", StringComparison.Ordinal));
}
[Test]
[TestMethod]
public void ModifyQueryHelperShouldSetQueryHelperWhenPatternContainsUnderScore()
{
// Arrange
@ -132,7 +132,7 @@ namespace Wox.Test.Plugins
Assert.IsFalse(queryHelper.QueryWhereRestrictions.Contains("Contains", StringComparison.Ordinal));
}
[Test]
[TestMethod]
public void ModifyQueryHelperShouldSetQueryHelperWhenPatternContainsQuestionMark()
{
// Arrange
@ -151,7 +151,7 @@ namespace Wox.Test.Plugins
Assert.IsFalse(queryHelper.QueryWhereRestrictions.Contains("Contains", StringComparison.Ordinal));
}
[Test]
[TestMethod]
public void ModifyQueryHelperShouldSetQueryHelperWhenPatternDoesNotContainSplSymbols()
{
// Arrange
@ -170,7 +170,7 @@ namespace Wox.Test.Plugins
Assert.IsTrue(queryHelper.QueryWhereRestrictions.Contains("Contains", StringComparison.Ordinal));
}
[Test]
[TestMethod]
public void WindowsSearchAPIShouldReturnResultsWhenSearchWasExecuted()
{
// Arrange
@ -191,7 +191,7 @@ namespace Wox.Test.Plugins
Assert.IsTrue(windowsSearchAPIResults.Any(x => x.Title == "file2.txt"));
}
[Test]
[TestMethod]
public void WindowsSearchAPIShouldNotReturnResultsWithNullValueWhenDbResultHasANullColumn()
{
// Arrange
@ -212,7 +212,7 @@ namespace Wox.Test.Plugins
Assert.IsTrue(windowsSearchAPIResults.Any(x => x.Title == "file2.txt"));
}
[Test]
[TestMethod]
public void WindowsSearchAPIShouldRequestNormalRequestWhenDisplayHiddenFilesIsTrue()
{
ISearchQueryHelper queryHelper;
@ -230,7 +230,7 @@ namespace Wox.Test.Plugins
Assert.IsFalse(queryHelper.QueryWhereRestrictions.Contains("AND System.FileAttributes <> SOME BITWISE 2", StringComparison.Ordinal));
}
[Test]
[TestMethod]
public void WindowsSearchAPIShouldRequestFilteredRequestWhenDisplayHiddenFilesIsFalse()
{
ISearchQueryHelper queryHelper;
@ -248,7 +248,7 @@ namespace Wox.Test.Plugins
Assert.IsTrue(queryHelper.QueryWhereRestrictions.Contains("AND System.FileAttributes <> SOME BITWISE 2", StringComparison.Ordinal));
}
[Test]
[TestMethod]
public void WindowsSearchAPIShouldRequestNormalRequestWhenDisplayHiddenFilesIsTrueAfterRuntimeSwap()
{
ISearchQueryHelper queryHelper;
@ -269,10 +269,11 @@ namespace Wox.Test.Plugins
Assert.IsFalse(queryHelper.QueryWhereRestrictions.Contains("AND System.FileAttributes <> SOME BITWISE 2", StringComparison.Ordinal));
}
[TestCase("item.exe")]
[TestCase("item.bat")]
[TestCase("item.appref-ms")]
[TestCase("item.lnk")]
[DataTestMethod]
[DataRow("item.exe")]
[DataRow("item.bat")]
[DataRow("item.appref-ms")]
[DataRow("item.lnk")]
public void LoadContextMenusMustLoadAllItemsWhenFileIsAnApp(string path)
{
// Arrange
@ -297,10 +298,11 @@ namespace Wox.Test.Plugins
Assert.AreEqual(Microsoft.Plugin.Indexer.Properties.Resources.Microsoft_plugin_indexer_open_in_console, contextMenuItems[3].Title);
}
[TestCase("item.pdf")]
[TestCase("item.xls")]
[TestCase("item.ppt")]
[TestCase("C:/DummyFile.cs")]
[DataTestMethod]
[DataRow("item.pdf")]
[DataRow("item.xls")]
[DataRow("item.ppt")]
[DataRow("C:/DummyFile.cs")]
public void LoadContextMenusMustNotLoadRunAsAdminWhenFileIsAnNotApp(string path)
{
// Arrange
@ -324,8 +326,9 @@ namespace Wox.Test.Plugins
Assert.AreEqual(Microsoft.Plugin.Indexer.Properties.Resources.Microsoft_plugin_indexer_open_in_console, contextMenuItems[2].Title);
}
[TestCase("C:/DummyFolder")]
[TestCase("TestFolder")]
[DataTestMethod]
[DataRow("C:/DummyFolder")]
[DataRow("TestFolder")]
public void LoadContextMenusMustNotLoadRunAsAdminAndOpenContainingFolderForFolder(string path)
{
// Arrange
@ -348,12 +351,13 @@ namespace Wox.Test.Plugins
Assert.AreEqual(Microsoft.Plugin.Indexer.Properties.Resources.Microsoft_plugin_indexer_open_in_console, contextMenuItems[1].Title);
}
[TestCase(0, 2, false, ExpectedResult = true)]
[TestCase(0, 3, true, ExpectedResult = false)]
[TestCase(1, 2, false, ExpectedResult = false)]
[TestCase(1, 4, true, ExpectedResult = false)]
[TestCase(0, 1, false, ExpectedResult = false)]
public bool DriveDetectionMustDisplayWarningWhenEnhancedModeIsOffAndWhenWarningIsNotDisabled(int enhancedModeStatus, int driveCount, bool disableWarningCheckBoxStatus)
[DataTestMethod]
[DataRow(0, 2, false, true)]
[DataRow(0, 3, true, false)]
[DataRow(1, 2, false, false)]
[DataRow(1, 4, true, false)]
[DataRow(0, 1, false, false)]
public void DriveDetectionMustDisplayWarningWhenEnhancedModeIsOffAndWhenWarningIsNotDisabled(int enhancedModeStatus, int driveCount, bool disableWarningCheckBoxStatus, bool result)
{
// Arrange
var mockRegistry = new Mock<IRegistryWrapper>();
@ -366,7 +370,7 @@ namespace Wox.Test.Plugins
driveDetection.IsDriveDetectionWarningCheckBoxSelected = disableWarningCheckBoxStatus;
// Act & Assert
return driveDetection.DisplayWarning();
Assert.AreEqual(driveDetection.DisplayWarning(), result);
}
}
}

View file

@ -5,13 +5,13 @@
using System;
using System.Collections.Generic;
using System.Linq;
using Mono.Collections.Generic;
using NUnit.Framework;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using PowerLauncher.Plugin;
using Wox.Plugin;
namespace Wox.Test
{
[TestClass]
public class QueryBuilderTest
{
private static bool AreEqual(Query firstQuery, Query secondQuery)
@ -22,7 +22,7 @@ namespace Wox.Test
&& firstQuery.RawQuery.Equals(secondQuery.RawQuery, StringComparison.Ordinal);
}
[Test]
[TestMethod]
public void QueryBuilderShouldRemoveExtraSpacesForNonGlobalPlugin()
{
// Arrange
@ -41,7 +41,7 @@ namespace Wox.Test
Assert.AreEqual("> file.txt file2 file3", searchQuery);
}
[Test]
[TestMethod]
public void QueryBuilderShouldRemoveExtraSpacesForGlobalPlugin()
{
// Arrange
@ -59,7 +59,7 @@ namespace Wox.Test
Assert.AreEqual("file.txt file2 file3", searchQuery);
}
[Test]
[TestMethod]
public void QueryBuildShouldGenerateSameSearchQueryWithOrWithoutSpaceAfterActionKeyword()
{
// Arrange
@ -85,7 +85,7 @@ namespace Wox.Test
Assert.IsTrue(firstQuery.ActionKeyword.Equals(secondQuery.ActionKeyword, StringComparison.Ordinal));
}
[Test]
[TestMethod]
public void QueryBuildShouldGenerateCorrectQueryForPluginsWhoseActionKeywordsHaveSamePrefix()
{
// Arrange
@ -109,7 +109,7 @@ namespace Wox.Test
Assert.IsTrue(AreEqual(secondQuery, new Query(searchQuery, secondPlugin.Metadata.ActionKeyword)));
}
[Test]
[TestMethod]
public void QueryBuilderShouldSetTermsCorrectlyWhenCalled()
{
// Arrange
@ -134,7 +134,7 @@ namespace Wox.Test
Assert.IsTrue(secondQuery.Terms[0].Equals("efgh", StringComparison.Ordinal) && secondQuery.Terms.Count == 1);
}
[Test]
[TestMethod]
public void QueryBuilderShouldReturnAllPluginsWithTheActionWord()
{
// Arrange

View file

@ -3,17 +3,17 @@
// See the LICENSE file in the project root for more information.
using System.Windows.Input;
using NUnit.Framework;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using PowerLauncher.ViewModel;
using Wox.Plugin;
namespace Wox.Test
{
[TestFixture]
internal class ResultsViewModelTest
[TestClass]
public class ResultsViewModelTest
{
[Test]
public void ContextMenuSelectedIndex_ShouldEqualNoSelectionIndex_WhenInitialized()
[TestMethod]
public void ContextMenuSelectedIndexShouldEqualNoSelectionIndexWhenInitialized()
{
// Arrange
ResultsViewModel rvm = new ResultsViewModel();
@ -26,8 +26,8 @@ namespace Wox.Test
Assert.AreEqual(ResultViewModel.NoSelectionIndex, selectedItem.ContextMenuSelectedIndex);
}
[Test]
public void SelectNextContextMenuItem_IncrementsContextMenuSelectedIndex_WhenCalled()
[TestMethod]
public void SelectNextContextMenuItemIncrementsContextMenuSelectedIndexWhenCalled()
{
// Arrange
ResultsViewModel rvm = new ResultsViewModel();
@ -43,8 +43,8 @@ namespace Wox.Test
Assert.AreEqual(0, selectedItem.ContextMenuSelectedIndex);
}
[Test]
public void SelectNextContextMenuItem_DoesnNotIncrementContextMenuSelectedIndex_WhenCalledOnLastItem()
[TestMethod]
public void SelectNextContextMenuItemDoesnNotIncrementContextMenuSelectedIndexWhenCalledOnLastItem()
{
// Arrange
ResultsViewModel rvm = new ResultsViewModel();
@ -60,8 +60,8 @@ namespace Wox.Test
Assert.AreEqual(0, selectedItem.ContextMenuSelectedIndex);
}
[Test]
public void SelectPreviousContextMenuItem_DecrementsContextMenuSelectedIndex_WhenCalled()
[TestMethod]
public void SelectPreviousContextMenuItemDecrementsContextMenuSelectedIndexWhenCalled()
{
// Arrange
ResultsViewModel rvm = new ResultsViewModel();
@ -82,8 +82,8 @@ namespace Wox.Test
Assert.AreEqual(1, selectedItem.ContextMenuSelectedIndex);
}
[Test]
public void SelectPreviousContextMenuItem_ResetsContextMenuSelectedIndex_WhenCalledOnFirstItem()
[TestMethod]
public void SelectPreviousContextMenuItemResetsContextMenuSelectedIndexWhenCalledOnFirstItem()
{
// Arrange
ResultsViewModel rvm = new ResultsViewModel();
@ -100,8 +100,8 @@ namespace Wox.Test
Assert.AreEqual(ResultViewModel.NoSelectionIndex, selectedItem.ContextMenuSelectedIndex);
}
[Test]
public void IsContextMenuItemSelected_ReturnsTrue_WhenContextMenuItemIsSelected()
[TestMethod]
public void IsContextMenuItemSelectedReturnsTrueWhenContextMenuItemIsSelected()
{
// Arrange
ResultsViewModel rvm = new ResultsViewModel();
@ -118,8 +118,8 @@ namespace Wox.Test
Assert.IsTrue(isContextMenuItemSelected);
}
[Test]
public void IsContextMenuItemSelected_ReturnsFalse_WhenContextMenuItemIsNotSelected()
[TestMethod]
public void IsContextMenuItemSelectedReturnsFalseWhenContextMenuItemIsNotSelected()
{
// Arrange
ResultsViewModel rvm = new ResultsViewModel();

View file

@ -61,12 +61,9 @@
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Moq" Version="4.16.1" />
<PackageReference Include="nunit" Version="3.13.1" />
<PackageReference Include="NUnit3TestAdapter" Version="3.17.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.9.1" />
<PackageReference Include="MSTest.TestAdapter" Version="2.2.5" />
<PackageReference Include="MSTest.TestFramework" Version="2.2.5" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.10.0" />
</ItemGroup>
<ItemGroup>
<Compile Include="..\..\..\codeAnalysis\GlobalSuppressions.cs">

View file

@ -4,13 +4,13 @@
using System.Runtime.CompilerServices;
using System.Windows.Input;
using NUnit.Framework;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using PowerLauncher.ViewModel;
using Wox.Plugin;
namespace Wox.Test
{
[TestFixture]
[TestClass]
public class WoxTest
{
// A Dummy class to test that OnPropertyChanged() is called while we set the variable
@ -44,7 +44,7 @@ namespace Wox.Test
}
}
[Test]
[TestMethod]
public void AnyVariableMustCallOnPropertyChangedWhenSet()
{
// Arrange

View file

@ -28,15 +28,15 @@
<Import Project="..\..\..\Version.props" />
<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.9.1" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.10.0" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Markdig.Signed" Version="0.22.0" />
<PackageReference Include="Microsoft.CodeAnalysis.FxCopAnalyzers" Version="3.3.0">
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="MSTest.TestAdapter" Version="2.2.3" />
<PackageReference Include="MSTest.TestFramework" Version="2.2.3" />
<PackageReference Include="MSTest.TestAdapter" Version="2.2.5" />
<PackageReference Include="MSTest.TestFramework" Version="2.2.5" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\common\PreviewHandlerCommon.csproj" />

View file

@ -28,9 +28,9 @@
<Import Project="..\..\..\Version.props" />
<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.9.1" />
<PackageReference Include="MSTest.TestAdapter" Version="2.2.3" />
<PackageReference Include="MSTest.TestFramework" Version="2.2.3" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.10.0" />
<PackageReference Include="MSTest.TestAdapter" Version="2.2.5" />
<PackageReference Include="MSTest.TestFramework" Version="2.2.5" />
</ItemGroup>
<ItemGroup>
<Compile Update="WebBrowserExtUnitTests.cs" />

View file

@ -32,10 +32,10 @@
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="Moq" Version="4.16.1" />
<PackageReference Include="MSTest.TestAdapter" Version="2.2.3" />
<PackageReference Include="MSTest.TestFramework" Version="2.2.3" />
<PackageReference Include="MSTest.TestAdapter" Version="2.2.5" />
<PackageReference Include="MSTest.TestFramework" Version="2.2.5" />
<PackageReference Include="System.Threading.Tasks.Extensions" Version="4.5.4" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.9.1" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.10.0" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\common\PreviewHandlerCommon.csproj" />

View file

@ -45,14 +45,14 @@
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="Moq" Version="4.16.1" />
<PackageReference Include="MSTest.TestAdapter" Version="2.2.3" />
<PackageReference Include="MSTest.TestFramework" Version="2.2.3" />
<PackageReference Include="MSTest.TestAdapter" Version="2.2.5" />
<PackageReference Include="MSTest.TestFramework" Version="2.2.5" />
<PackageReference Include="StyleCop.Analyzers" Version="1.1.118">
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="System.Runtime.CompilerServices.Unsafe" Version="5.0.0" />
<PackageReference Include="System.Threading.Tasks.Extensions" Version="4.5.4" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.9.1" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.10.0" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Common\PreviewHandlerCommon.csproj" />

View file

@ -27,10 +27,10 @@
</AdditionalFiles>
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.9.1" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.10.0" />
<PackageReference Include="Moq" Version="4.16.1" />
<PackageReference Include="MSTest.TestAdapter" Version="2.2.3" />
<PackageReference Include="MSTest.TestFramework" Version="2.2.3" />
<PackageReference Include="MSTest.TestAdapter" Version="2.2.5" />
<PackageReference Include="MSTest.TestFramework" Version="2.2.5" />
<PackageReference Include="coverlet.collector" Version="3.0.3">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>