From 80a6bcb30f590d7d870d894f22a929ddaebd4f75 Mon Sep 17 00:00:00 2001 From: AdmiringWorm Date: Sat, 25 Jan 2020 03:01:17 +0100 Subject: [PATCH] (maint) Add unit tests for ssl capable validation --- .../Validations/UrlSslCapableTests.cs | 59 +++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 Source/chocolatey-language-server.Tests/Validations/UrlSslCapableTests.cs diff --git a/Source/chocolatey-language-server.Tests/Validations/UrlSslCapableTests.cs b/Source/chocolatey-language-server.Tests/Validations/UrlSslCapableTests.cs new file mode 100644 index 0000000..083313d --- /dev/null +++ b/Source/chocolatey-language-server.Tests/Validations/UrlSslCapableTests.cs @@ -0,0 +1,59 @@ +using Chocolatey.Language.Server.Models; +using Chocolatey.Language.Server.Validations; +using NUnit.Framework; +using System.Collections; +using System.Collections.Generic; + +namespace Chocolatey.Language.Server.Tests.Validations +{ + public class UrlSslCapableTests : ValidationBaseTests + { + public static IEnumerable SupportedElements + { + get => new[] + { + "bugTrackerUrl", + "docsUrl", + "iconUrl", + "licenseUrl", + "mailingListUrl", + "packageSourceUrl", + "projectSourceUrl", + "projectUrl", + "wikiUrl" + }; + } + + public override string ExpectedId { get; } = "choco1002"; + + [Test] + public void Should_FailValidationWhenSslCanBeUsedOnUrl([ValueSource(nameof(SupportedElements))] string xmlElement) + { + var package = new Package + { + AllElements = new Dictionary> + { + { xmlElement, "http://chocolatey.org" } + } + }; + + ValidateDiagnosticResult(package, 1); + } + + [Test] + public void Should_NotFailValidationWhenSslIsUsedOnUrl([ValueSource(nameof(SupportedElements))] string xmlElement) + { + var package = new Package + { + AllElements = new Dictionary> + { + { xmlElement, "https://chocolatey.org" } + } + }; + + ValidateDiagnosticResult(package, 0); + } + + // TODO: Validation for when a url is not ssl capable should also be tested. + } +} \ No newline at end of file