mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-02-23 19:49:43 +01:00
tests
This commit is contained in:
@@ -811,6 +811,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Microsoft.CmdPal.Ext.WebSea
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Microsoft.CmdPal.Ext.Shell.UnitTests", "src\modules\cmdpal\Tests\Microsoft.CmdPal.Ext.Shell.UnitTests\Microsoft.CmdPal.Ext.Shell.UnitTests.csproj", "{E816D7B4-4688-4ECB-97CC-3D8E798F3833}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Microsoft.CmdPal.Ext.ClipboardHistory.UnitTests", "src\modules\cmdpal\Tests\Microsoft.CmdPal.Ext.ClipboardHistory.UnitTests\Microsoft.CmdPal.Ext.ClipboardHistory.UnitTests.csproj", "{4E0FCF69-B06B-D272-76BF-ED3A559B4EDA}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|ARM64 = Debug|ARM64
|
||||
@@ -2945,6 +2947,14 @@ Global
|
||||
{E816D7B4-4688-4ECB-97CC-3D8E798F3833}.Release|ARM64.Build.0 = Release|ARM64
|
||||
{E816D7B4-4688-4ECB-97CC-3D8E798F3833}.Release|x64.ActiveCfg = Release|x64
|
||||
{E816D7B4-4688-4ECB-97CC-3D8E798F3833}.Release|x64.Build.0 = Release|x64
|
||||
{4E0FCF69-B06B-D272-76BF-ED3A559B4EDA}.Debug|ARM64.ActiveCfg = Debug|ARM64
|
||||
{4E0FCF69-B06B-D272-76BF-ED3A559B4EDA}.Debug|ARM64.Build.0 = Debug|ARM64
|
||||
{4E0FCF69-B06B-D272-76BF-ED3A559B4EDA}.Debug|x64.ActiveCfg = Debug|x64
|
||||
{4E0FCF69-B06B-D272-76BF-ED3A559B4EDA}.Debug|x64.Build.0 = Debug|x64
|
||||
{4E0FCF69-B06B-D272-76BF-ED3A559B4EDA}.Release|ARM64.ActiveCfg = Release|ARM64
|
||||
{4E0FCF69-B06B-D272-76BF-ED3A559B4EDA}.Release|ARM64.Build.0 = Release|ARM64
|
||||
{4E0FCF69-B06B-D272-76BF-ED3A559B4EDA}.Release|x64.ActiveCfg = Release|x64
|
||||
{4E0FCF69-B06B-D272-76BF-ED3A559B4EDA}.Release|x64.Build.0 = Release|x64
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
@@ -3267,6 +3277,7 @@ Global
|
||||
{E816D7B3-4688-4ECB-97CC-3D8E798F3832} = {8EF25507-2575-4ADE-BF7E-D23376903AB8}
|
||||
{E816D7B2-4688-4ECB-97CC-3D8E798F3831} = {8EF25507-2575-4ADE-BF7E-D23376903AB8}
|
||||
{E816D7B4-4688-4ECB-97CC-3D8E798F3833} = {8EF25507-2575-4ADE-BF7E-D23376903AB8}
|
||||
{4E0FCF69-B06B-D272-76BF-ED3A559B4EDA} = {8EF25507-2575-4ADE-BF7E-D23376903AB8}
|
||||
EndGlobalSection
|
||||
GlobalSection(ExtensibilityGlobals) = postSolution
|
||||
SolutionGuid = {C3A2F9D1-7930-4EF4-A6FC-7EE0A99821D0}
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
<!-- Look at Directory.Build.props in root for common stuff as well -->
|
||||
<Import Project="..\..\..\..\Common.Dotnet.CsWinRT.props" />
|
||||
|
||||
<PropertyGroup>
|
||||
<IsPackable>false</IsPackable>
|
||||
<RootNamespace>Microsoft.CmdPal.Ext.ClipboardHistory.UnitTests</RootNamespace>
|
||||
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Moq" />
|
||||
<PackageReference Include="MSTest" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\ext\Microsoft.CmdPal.Ext.ClipboardHistory\Microsoft.CmdPal.Ext.ClipboardHistory.csproj" />
|
||||
<ProjectReference Include="..\Microsoft.CmdPal.Ext.UnitTestsBase\Microsoft.CmdPal.Ext.UnitTestBase.csproj" />
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
@@ -0,0 +1,185 @@
|
||||
// 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 Microsoft.CmdPal.Ext.ClipboardHistory.Helpers;
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
|
||||
namespace Microsoft.CmdPal.Ext.ClipboardHistory.UnitTests;
|
||||
|
||||
[TestClass]
|
||||
public class UrlHelperTests
|
||||
{
|
||||
[TestMethod]
|
||||
[DataRow(null)]
|
||||
[DataRow("")]
|
||||
[DataRow(" ")]
|
||||
[DataRow("\t")]
|
||||
[DataRow("\r\n")]
|
||||
public void IsValidUrl_ReturnssFalse_WhenUrlIsNullOrWhitespace(string url)
|
||||
{
|
||||
// Act
|
||||
var result = UrlHelper.IsValidUrl(url);
|
||||
|
||||
// Assert
|
||||
Assert.IsFalse(result);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[DataRow("test\nurl")]
|
||||
[DataRow("test\rurl")]
|
||||
[DataRow("http://example.com\nmalicious")]
|
||||
[DataRow("https://test.com\r\nheader")]
|
||||
public void IsValidUrl_ReturnsFalse_WhenUrlContainsNewlines(string url)
|
||||
{
|
||||
// Act
|
||||
var result = UrlHelper.IsValidUrl(url);
|
||||
|
||||
// Assert
|
||||
Assert.IsFalse(result);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[DataRow("com")]
|
||||
[DataRow("org")]
|
||||
[DataRow("localhost")]
|
||||
[DataRow("test")]
|
||||
[DataRow("http")]
|
||||
[DataRow("https")]
|
||||
public void IsValidUrl_ReturnsFalse_WhenUrlDoesNotContainDot(string url)
|
||||
{
|
||||
// Act
|
||||
var result = UrlHelper.IsValidUrl(url);
|
||||
|
||||
// Assert
|
||||
Assert.IsFalse(result);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[DataRow("https://www.example.com")]
|
||||
[DataRow("http://test.org")]
|
||||
[DataRow("ftp://files.example.net")]
|
||||
[DataRow("file://localhost/path/to/file.txt")]
|
||||
[DataRow("https://subdomain.example.co.uk")]
|
||||
[DataRow("http://192.168.1.1")]
|
||||
[DataRow("https://example.com:8080/path")]
|
||||
public void IsValidUrl_ReturnsTrue_WhenUrlIsWellFormedAbsolute(string url)
|
||||
{
|
||||
// Act
|
||||
var result = UrlHelper.IsValidUrl(url);
|
||||
|
||||
// Assert
|
||||
Assert.IsTrue(result);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[DataRow("www.example.com")]
|
||||
[DataRow("example.org")]
|
||||
[DataRow("subdomain.test.net")]
|
||||
[DataRow("github.com/user/repo")]
|
||||
[DataRow("stackoverflow.com/questions/123")]
|
||||
[DataRow("192.168.1.1")]
|
||||
public void IsValidUrl_ReturnsTrue_WhenUrlIsValidWithoutProtocol(string url)
|
||||
{
|
||||
// Act
|
||||
var result = UrlHelper.IsValidUrl(url);
|
||||
|
||||
// Assert
|
||||
Assert.IsTrue(result);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[DataRow("not a url")]
|
||||
[DataRow("invalid..url")]
|
||||
[DataRow("http://")]
|
||||
[DataRow("https://")]
|
||||
[DataRow("://example.com")]
|
||||
[DataRow("ht tp://example.com")]
|
||||
public void IsValidUrl_ReturnsFalse_WhenUrlIsInvalid(string url)
|
||||
{
|
||||
// Act
|
||||
var result = UrlHelper.IsValidUrl(url);
|
||||
|
||||
// Assert
|
||||
Assert.IsFalse(result);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[DataRow(" https://www.example.com ")]
|
||||
[DataRow("\t\tgithub.com\t\t")]
|
||||
[DataRow(" \r\n stackoverflow.com \r\n ")]
|
||||
public void IsValidUrl_TrimsWhitespace_BeforeValidation(string url)
|
||||
{
|
||||
// Act
|
||||
var result = UrlHelper.IsValidUrl(url);
|
||||
|
||||
// Assert
|
||||
Assert.IsTrue(result);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[DataRow("tel:+1234567890")]
|
||||
[DataRow("javascript:alert('test')")]
|
||||
public void IsValidUrl_ReturnsFalse_ForNonWebProtocols(string url)
|
||||
{
|
||||
// Act
|
||||
var result = UrlHelper.IsValidUrl(url);
|
||||
|
||||
// Assert
|
||||
Assert.IsFalse(result);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[DataRow(null)]
|
||||
[DataRow("")]
|
||||
[DataRow(" ")]
|
||||
public void NormalizeUrl_ReturnsInput_WhenUrlIsNullOrWhitespace(string url)
|
||||
{
|
||||
// Act
|
||||
var result = UrlHelper.NormalizeUrl(url);
|
||||
|
||||
// Assert
|
||||
Assert.AreEqual(url, result);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[DataRow("https://www.example.com")]
|
||||
[DataRow("http://test.org")]
|
||||
[DataRow("ftp://files.example.net")]
|
||||
[DataRow("file://localhost/path/to/file.txt")]
|
||||
public void NormalizeUrl_ReturnsUnchanged_WhenUrlIsAlreadyWellFormed(string url)
|
||||
{
|
||||
// Act
|
||||
var result = UrlHelper.NormalizeUrl(url);
|
||||
|
||||
// Assert
|
||||
Assert.AreEqual(url, result);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[DataRow("www.example.com", "https://www.example.com")]
|
||||
[DataRow("example.org", "https://example.org")]
|
||||
[DataRow("github.com/user/repo", "https://github.com/user/repo")]
|
||||
[DataRow("stackoverflow.com/questions/123", "https://stackoverflow.com/questions/123")]
|
||||
public void NormalizeUrl_AddsHttpsPrefix_WhenNoProtocolPresent(string input, string expected)
|
||||
{
|
||||
// Act
|
||||
var result = UrlHelper.NormalizeUrl(input);
|
||||
|
||||
// Assert
|
||||
Assert.AreEqual(expected, result);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[DataRow(" www.example.com ", "https://www.example.com")]
|
||||
[DataRow("\t\tgithub.com\t\t", "https://github.com")]
|
||||
[DataRow(" \r\n stackoverflow.com \r\n ", "https://stackoverflow.com")]
|
||||
public void NormalizeUrl_TrimsWhitespace_BeforeNormalizing(string input, string expected)
|
||||
{
|
||||
// Act
|
||||
var result = UrlHelper.NormalizeUrl(input);
|
||||
|
||||
// Assert
|
||||
Assert.AreEqual(expected, result);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
// 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.Runtime.CompilerServices;
|
||||
|
||||
[assembly: InternalsVisibleTo("Microsoft.CmdPal.Ext.ClipboardHistory.UnitTests")]
|
||||
Reference in New Issue
Block a user