* Squashed commit of test rewrite changes fix missing priority speaker flag rewrite the TestChannelPermissionModify test add test for GuildPermission modify separate unit and integration tests, start writing channel and guild permission tests copy over the color tests copy over the emote tests copy the token utils tests make the mocked entities sealed classes copy the TypeReaderTests class properly dispose the CommandService in the TypeReaderTests start writing tests for EmbedBuilder and related classes test that properties throw ArgumentException when invalid add tests for the embed length property add withFooter tests finish adding tests to EmbedBuilder fix bug in value validation of EmbedFieldBuilder hey, these tests actually found a bug! add tests for the MentionUtils class add tests for the Format util class remove all of the old tests add analyzer tests (copied from old tests) add tests for the SnowflakeUtils class add integration tests these get around the issue of state persisting between tests by creating and deleting a guild for each set of tests. these shouldn't be run excessively because of the rate limits, but should be fine every now and then remove unnecessary launchSettings.json update outdated string don't create a new guild each time, as that can result in errors this can happen if a bot creates too many guilds without properly deleting them add some tests that show that guild can be modified await async assert add more measures that created channels are deleted when done remove "Test" prefix from test method names I think that this prefix when already displayed under a class with a suffix of "Tests" is redundant Remove mention of old test project fix an issue from forgetting to await Assert.ThrowsAsync explicitly disable parallelization on integration tests add test for GuildPermission modify separate unit and integration tests, start writing channel and guild permission tests copy over the color tests copy over the emote tests make the mocked entities sealed classes properly dispose the CommandService in the TypeReaderTests fix bug in value validation of EmbedFieldBuilder hey, these tests actually found a bug! add tests for the MentionUtils class add tests for the Format util class remove all of the old tests add analyzer tests (copied from old tests) add tests for the SnowflakeUtils class add integration tests these get around the issue of state persisting between tests by creating and deleting a guild for each set of tests. these shouldn't be run excessively because of the rate limits, but should be fine every now and then remove unnecessary launchSettings.json update outdated string don't create a new guild each time, as that can result in errors this can happen if a bot creates too many guilds without properly deleting them add more measures that created channels are deleted when done remove "Test" prefix from test method names I think that this prefix when already displayed under a class with a suffix of "Tests" is redundant Remove mention of old test project fix an issue from forgetting to await Assert.ThrowsAsync explicitly disable parallelization on integration tests update the azure CI build script separate execution of test projects so that if one fails the other will not pass one of the unit tests failed, but the analzyer tests passed fix test that would break in different timezones enable the integration tests (only on dev branch) * Squashed commit of test rewrite changes fix missing priority speaker flag rewrite the TestChannelPermissionModify test add test for GuildPermission modify separate unit and integration tests, start writing channel and guild permission tests copy over the color tests copy over the emote tests copy the token utils tests make the mocked entities sealed classes copy the TypeReaderTests class properly dispose the CommandService in the TypeReaderTests start writing tests for EmbedBuilder and related classes test that properties throw ArgumentException when invalid add tests for the embed length property add withFooter tests finish adding tests to EmbedBuilder fix bug in value validation of EmbedFieldBuilder hey, these tests actually found a bug! add tests for the MentionUtils class add tests for the Format util class remove all of the old tests add analyzer tests (copied from old tests) add tests for the SnowflakeUtils class add integration tests these get around the issue of state persisting between tests by creating and deleting a guild for each set of tests. these shouldn't be run excessively because of the rate limits, but should be fine every now and then remove unnecessary launchSettings.json update outdated string don't create a new guild each time, as that can result in errors this can happen if a bot creates too many guilds without properly deleting them add some tests that show that guild can be modified await async assert add more measures that created channels are deleted when done remove "Test" prefix from test method names I think that this prefix when already displayed under a class with a suffix of "Tests" is redundant Remove mention of old test project fix an issue from forgetting to await Assert.ThrowsAsync explicitly disable parallelization on integration tests add test for GuildPermission modify separate unit and integration tests, start writing channel and guild permission tests copy over the color tests copy over the emote tests make the mocked entities sealed classes properly dispose the CommandService in the TypeReaderTests fix bug in value validation of EmbedFieldBuilder hey, these tests actually found a bug! add tests for the MentionUtils class add tests for the Format util class remove all of the old tests add analyzer tests (copied from old tests) add tests for the SnowflakeUtils class add integration tests these get around the issue of state persisting between tests by creating and deleting a guild for each set of tests. these shouldn't be run excessively because of the rate limits, but should be fine every now and then remove unnecessary launchSettings.json update outdated string don't create a new guild each time, as that can result in errors this can happen if a bot creates too many guilds without properly deleting them add more measures that created channels are deleted when done remove "Test" prefix from test method names I think that this prefix when already displayed under a class with a suffix of "Tests" is redundant Remove mention of old test project fix an issue from forgetting to await Assert.ThrowsAsync explicitly disable parallelization on integration tests update the azure CI build script separate execution of test projects so that if one fails the other will not pass one of the unit tests failed, but the analzyer tests passed fix test that would break in different timezones enable the integration tests (only on dev branch) * Update mocked channels for changed SendFileAsync signature * comment out the integration tests from the build script no bot token is provided to this script, and use of integration tests in CI is questionable here * force rebuild because Azure linux build broke
86 lines
3.9 KiB
C#
86 lines
3.9 KiB
C#
using Microsoft.CodeAnalysis;
|
|
using Microsoft.CodeAnalysis.CodeActions;
|
|
using Microsoft.CodeAnalysis.Formatting;
|
|
using Microsoft.CodeAnalysis.Simplification;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Threading;
|
|
|
|
namespace TestHelper
|
|
{
|
|
/// <summary>
|
|
/// Diagnostic Producer class with extra methods dealing with applying codefixes
|
|
/// All methods are static
|
|
/// </summary>
|
|
public abstract partial class CodeFixVerifier : DiagnosticVerifier
|
|
{
|
|
/// <summary>
|
|
/// Apply the inputted CodeAction to the inputted document.
|
|
/// Meant to be used to apply codefixes.
|
|
/// </summary>
|
|
/// <param name="document">The Document to apply the fix on</param>
|
|
/// <param name="codeAction">A CodeAction that will be applied to the Document.</param>
|
|
/// <returns>A Document with the changes from the CodeAction</returns>
|
|
private static Document ApplyFix(Document document, CodeAction codeAction)
|
|
{
|
|
var operations = codeAction.GetOperationsAsync(CancellationToken.None).Result;
|
|
var solution = operations.OfType<ApplyChangesOperation>().Single().ChangedSolution;
|
|
return solution.GetDocument(document.Id);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Compare two collections of Diagnostics,and return a list of any new diagnostics that appear only in the second collection.
|
|
/// Note: Considers Diagnostics to be the same if they have the same Ids. In the case of multiple diagnostics with the same Id in a row,
|
|
/// this method may not necessarily return the new one.
|
|
/// </summary>
|
|
/// <param name="diagnostics">The Diagnostics that existed in the code before the CodeFix was applied</param>
|
|
/// <param name="newDiagnostics">The Diagnostics that exist in the code after the CodeFix was applied</param>
|
|
/// <returns>A list of Diagnostics that only surfaced in the code after the CodeFix was applied</returns>
|
|
private static IEnumerable<Diagnostic> GetNewDiagnostics(IEnumerable<Diagnostic> diagnostics, IEnumerable<Diagnostic> newDiagnostics)
|
|
{
|
|
var oldArray = diagnostics.OrderBy(d => d.Location.SourceSpan.Start).ToArray();
|
|
var newArray = newDiagnostics.OrderBy(d => d.Location.SourceSpan.Start).ToArray();
|
|
|
|
int oldIndex = 0;
|
|
int newIndex = 0;
|
|
|
|
while (newIndex < newArray.Length)
|
|
{
|
|
if (oldIndex < oldArray.Length && oldArray[oldIndex].Id == newArray[newIndex].Id)
|
|
{
|
|
++oldIndex;
|
|
++newIndex;
|
|
}
|
|
else
|
|
{
|
|
yield return newArray[newIndex++];
|
|
}
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Get the existing compiler diagnostics on the inputted document.
|
|
/// </summary>
|
|
/// <param name="document">The Document to run the compiler diagnostic analyzers on</param>
|
|
/// <returns>The compiler diagnostics that were found in the code</returns>
|
|
private static IEnumerable<Diagnostic> GetCompilerDiagnostics(Document document)
|
|
{
|
|
return document.GetSemanticModelAsync().Result.GetDiagnostics();
|
|
}
|
|
|
|
/// <summary>
|
|
/// Given a document, turn it into a string based on the syntax root
|
|
/// </summary>
|
|
/// <param name="document">The Document to be converted to a string</param>
|
|
/// <returns>A string containing the syntax of the Document after formatting</returns>
|
|
private static string GetStringFromDocument(Document document)
|
|
{
|
|
var simplifiedDoc = Simplifier.ReduceAsync(document, Simplifier.Annotation).Result;
|
|
var root = simplifiedDoc.GetSyntaxRootAsync().Result;
|
|
root = Formatter.Format(root, Formatter.Annotation, simplifiedDoc.Project.Solution.Workspace);
|
|
return root.GetText().ToString();
|
|
}
|
|
}
|
|
}
|
|
|