Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(maint) Implementing unit tests for language server #6

Draft
wants to merge 22 commits into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
e807a0a
(maint) Add new unit testing library
AdmiringWorm Jan 24, 2020
3e11ee6
(maint) Set language version to 8.0
AdmiringWorm Jan 24, 2020
cec7f7c
(maint) Corrected coverage filter in recipe.cake
AdmiringWorm Jan 24, 2020
d7920d0
(maint) Add implicit operators for MetaValue class
AdmiringWorm Jan 24, 2020
70b8404
(maint) Add unit tests for Author does not match maintainer
AdmiringWorm Jan 24, 2020
9a14111
(maint) Add unit tests for no email used
AdmiringWorm Jan 24, 2020
ff9fa8c
(maint) Add unit tests for minimum copyright length
AdmiringWorm Jan 24, 2020
8538584
(maint) Add unit tests for deprecated pkg with dependency
AdmiringWorm Jan 24, 2020
360d232
(maint) Add unit tests for maximum description length
AdmiringWorm Jan 24, 2020
4cabf2e
(maint) Add unit tests for minumum description length
AdmiringWorm Jan 24, 2020
96b1219
(maint) Add unit tests for required description
AdmiringWorm Jan 24, 2020
4587946
(maint) Added unit tests for templated values
AdmiringWorm Jan 25, 2020
ce0e791
(maint) Add unit tests for supported icon url extension
AdmiringWorm Jan 25, 2020
cd5f258
(maint) Add unit tests for license requirement
AdmiringWorm Jan 25, 2020
d5d6607
(maint) Disable dupfinder and inspect code
AdmiringWorm Jan 25, 2020
6d5a27f
(maint) Add unit tests for nuspec enhancement urls
AdmiringWorm Jan 25, 2020
47b6b51
(maint) Add unit tests for package id ending with config
AdmiringWorm Jan 25, 2020
9a04c4d
(maint) Add unit tests for underscore in package id
AdmiringWorm Jan 25, 2020
ddaace1
(maint) Add unit tests for package id with pre-release version
AdmiringWorm Jan 25, 2020
b040b00
(maint) Add unit tests for comma separated tags
AdmiringWorm Jan 25, 2020
80f3d8c
(maint) Add unit tests for no empty tags
AdmiringWorm Jan 25, 2020
80a6bcb
(maint) Add unit tests for ssl capable validation
AdmiringWorm Jan 25, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
using Chocolatey.Language.Server.Models;
using Chocolatey.Language.Server.Validations;
using NUnit.Framework;
using System.Collections;
using System.Linq;

namespace Chocolatey.Language.Server.Tests.Validations
{
public class AuthorDoesNotMatchMaintainerTests : ValidationBaseTests<AuthorDoesNotMatchMaintainer>
{
public override string ExpectedId { get; } = "choco3002";

public static IEnumerable SameDadaValues
{
get
{
yield return new TestCaseData("AdmiringWorm", "AdmiringWorm");
yield return new TestCaseData("admiringworm", "AdmiringWorm");
yield return new TestCaseData("AdmiringWorm", "admiringworm");
yield return new TestCaseData("ADMIRINGWORM", "AdmiringWorm");
yield return new TestCaseData("AdmiringWorm", "ADMIRINGWORM");
}
}

[TestCaseSource(nameof(SameDadaValues))]
public void Should_FailValidationWhenAuthorAndOwnerIsSame(string author, string owner)
{
var package = new Package
{
Authors = new MetaValue<string>[] { author },
Maintainers = new MetaValue<string>[] { owner }
};

ValidateDiagnosticResult(package, 2);
}

[TestCase("AdmiringWorm", "gep13")]
[TestCase("mkevenaar", "steviecoaster")]
public void Should_NotFailValidationWhenAuthonAndOwnerIsNotSame(string author, string owner)
{
var package = new Package
{
Authors = new MetaValue<string>[] { author },
Maintainers = new MetaValue<string>[] { owner }
};

var result = Rule.Validate(package).ToList();

Assert.That(result, Is.Empty);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
using Chocolatey.Language.Server.Models;
using Chocolatey.Language.Server.Validations;
using NUnit.Framework;
using System.Collections;
using System.Collections.Generic;
using System.Linq;

namespace Chocolatey.Language.Server.Tests.Validations
{
public class CopyrightAndAuthorFieldShouldntContainEmailRequirementTests : ValidationBaseTests<CopyrightAndAuthorFieldShouldntContainEmailRequirement>
{
public static IEnumerable FailingAuthors
{
get
{
yield return new TestCaseData("[email protected]", null);
yield return new TestCaseData("Chocolatey", "[email protected]");
yield return new TestCaseData("[email protected]", "[email protected]");
}
}

public static IEnumerable FailingCopyrights
{
get
{
yield return new TestCaseData("[email protected]");
}
}

public override string ExpectedId { get; } = "choco0005";

[TestCaseSource(nameof(FailingAuthors))]
public void Should_FailValidationWhenEmailIsUsedInAuthorField(string author1, string author2)
{
var authors = new List<MetaValue<string>> { author1 };
if (author2 != null) { authors.Add(author2); }

var package = new Package
{
Authors = authors,
Copyright = string.Empty
};

ValidateDiagnosticResult(package, authors.Count(a => a.Value.Contains('@')));
}

[TestCaseSource(nameof(FailingCopyrights))]
public void Should_FailValidationWhenEmailIsUsedInCopyrightField(string copyright)
{
var package = new Package
{
Copyright = copyright,
};

ValidateDiagnosticResult(package, 1);
}

[Test]
public void Should_NotFailValidationWhenEmailIsNotUsedInAuthors()
{
var package = new Package
{
Authors = new MetaValue<string>[] { "Chocolatey", "NuGet" }
};

var result = Rule.Validate(package);

Assert.That(result, Is.Empty);
}

[Test]
public void Should_NotFailValidationWhenEmailIsNotUsedInCopyright()
{
var package = new Package
{
Copyright = "Copyright 2016"
};

var result = Rule.Validate(package);

Assert.That(result, Is.Empty);
}

[Test]
public void Should_SetDiagnosticsForAllFoundEmailsInAuthors()
{
var package = new Package
{
Authors = new MetaValue<string>[] { "[email protected] [email protected]" }
};

ValidateDiagnosticResult(package, 2);
}

[Test]
public void Should_SetDiagnosticsForAllFoundEmailsInCopyright()
{
var package = new Package
{
Copyright = "[email protected] something [email protected]"
};

ValidateDiagnosticResult(package, 2);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
using Chocolatey.Language.Server.Models;
using Chocolatey.Language.Server.Validations;
using NUnit.Framework;

namespace Chocolatey.Language.Server.Tests.Validations
{
public class CopyrightWordCountTests : ValidationBaseTests<CopyrightWordCount>
{
public override string ExpectedId { get; } = "choco0006";

[Test]
public void Should_FailValidationWhenCharacterCountIsEqualTo4()
{
var package = new Package
{
Copyright = "2020"
};

ValidateDiagnosticResult(package, 1);
}

[Test]
public void Should_FailValidationWhenCharacterCountIsLessThan4()
{
var package = new Package
{
Copyright = "© m"
};

ValidateDiagnosticResult(package, 1);
}

[Test]
public void Should_NotFailValidationWhenCharacterCountIsMoreThan4()
{
var package = new Package
{
Copyright = "© 2020"
};

var result = Rule.Validate(package);

Assert.That(result, Is.Empty);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
using Chocolatey.Language.Server.Models;
using Chocolatey.Language.Server.Validations;
using NUnit.Framework;

namespace Chocolatey.Language.Server.Tests.Validations
{
public class DeprecatedPackagesShouldHaveDependencyTests : ValidationBaseTests<DeprecatedPackagesShouldHaveDependency>
{
public override string ExpectedId { get; } = "choco0007";

[Test]
public void Should_FailValidationWhenNoDependencyIsSpecified()
{
var package = new Package
{
Title = "[deprecated] Some kind of title"
};

ValidateDiagnosticResult(package, 1);
}

[Test]
public void Should_NotFailValidationWhenADependencyIsSpecified()
{
var package = new Package
{
Title = "[deprecated] Some kind of title"
};
package.AddDependency(new Dependency { Id = "some-package-id" });

var result = Rule.Validate(package);

Assert.That(result, Is.Empty);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
using Chocolatey.Language.Server.Models;
using Chocolatey.Language.Server.Validations;
using NUnit.Framework;

namespace Chocolatey.Language.Server.Tests.Validations
{
public class DescriptionMaximumWordCountTests : ValidationBaseTests<DescriptionMaximumWordCount>
{
public override string ExpectedId { get; } = "choco0003";

[Test]
public void Should_FailValidationWhenDescriptionIsLongerThan4000Characters()
{
var package = new Package
{
Description = "Hello".PadLeft(4001, 'x'),
};

ValidateDiagnosticResult(package, 1);
}

[TestCase(100)]
[TestCase(3990)]
[TestCase(4000, TestName = "Should_NotFailValidationWhenDescriptionIsEqualTo4000Characters")]
public void Should_NotFailValidationWhenDescriptionIsLessThan4000Characters(int length)
{
var package = new Package
{
Description = "Hello".PadLeft(length, 'x')
};

var result = Rule.Validate(package);

Assert.That(result, Is.Empty);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
using Chocolatey.Language.Server.Models;
using Chocolatey.Language.Server.Validations;
using NUnit.Framework;

namespace Chocolatey.Language.Server.Tests.Validations
{
public class DescriptionMinimumWordCountTests : ValidationBaseTests<DescriptionMinimumWordCount>
{
public override string ExpectedId { get; } = "choco1001";

[TestCase(6)]
[TestCase(10)]
[TestCase(30, TestName = "Should_FailValidationWhenDescriptionIsEqualTo30Characters")]
public void Should_FailValidationWhenDescriptionIsLessThan30Characters(int length)
{
var package = new Package
{
Description = "Hello".PadLeft(length, 'x')
};

ValidateDiagnosticResult(package, 1);
}

[Test]
public void Should_NotFailValidationWhenDescriptionIsMoreThan30Characters()
{
var package = new Package
{
Description = "Yo".PadLeft(31, 'x')
};

var result = Rule.Validate(package);

Assert.That(result, Is.Empty);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
using Chocolatey.Language.Server.Models;
using Chocolatey.Language.Server.Validations;
using NUnit.Framework;

namespace Chocolatey.Language.Server.Tests.Validations
{
public class DescriptionRequiredValidationTests : ValidationBaseTests<DescriptionRequiredValidation>
{
public override string ExpectedId { get; } = "choco0002";

[TestCase(null)]
[TestCase("")]
[TestCase(" ")]
public void Should_FailValidationWhenDescriptionIsNullOrWhitespace(string value)
{
var package = new Package
{
Description = value
};

ValidateDiagnosticResult(package, 1);
}

[Test]
public void Should_NotFailValidationWhenDescriptionHaveText()
{
var package = new Package
{
Description = "My new awesome package description"
};

var result = Rule.Validate(package);

Assert.That(result, Is.Empty);
}
}
}
Loading