Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
10 changes: 5 additions & 5 deletions FastMoq-Release.sln
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "FastMoq", "FastMoq\FastMoq.
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "FastMoq.Abstractions", "FastMoq.Abstractions\FastMoq.Abstractions.csproj", "{970828D1-0EF2-4D0D-BF1B-BB85DEB38514}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "FastMoq.Generators", "FastMoq.Generators\FastMoq.Generators.csproj", "{3A865DC1-4C90-42F7-B0E9-25A31D7C432E}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "FastMoq.Generators", "FastMoq.Generators\FastMoq.Generators.csproj", "{5FE82C4B-17E0-4C41-9A79-4F13FCB6D2D1}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "FastMoq.Azure", "FastMoq.Azure\FastMoq.Azure.csproj", "{CADD0874-D3E6-40B3-A8D5-EB04047597EC}"
EndProject
Expand Down Expand Up @@ -39,10 +39,10 @@ Global
{970828D1-0EF2-4D0D-BF1B-BB85DEB38514}.Debug|Any CPU.Build.0 = Release|Any CPU
{970828D1-0EF2-4D0D-BF1B-BB85DEB38514}.Release|Any CPU.ActiveCfg = Release|Any CPU
{970828D1-0EF2-4D0D-BF1B-BB85DEB38514}.Release|Any CPU.Build.0 = Release|Any CPU
{3A865DC1-4C90-42F7-B0E9-25A31D7C432E}.Debug|Any CPU.ActiveCfg = Release|Any CPU
{3A865DC1-4C90-42F7-B0E9-25A31D7C432E}.Debug|Any CPU.Build.0 = Release|Any CPU
{3A865DC1-4C90-42F7-B0E9-25A31D7C432E}.Release|Any CPU.ActiveCfg = Release|Any CPU
{3A865DC1-4C90-42F7-B0E9-25A31D7C432E}.Release|Any CPU.Build.0 = Release|Any CPU
{5FE82C4B-17E0-4C41-9A79-4F13FCB6D2D1}.Debug|Any CPU.ActiveCfg = Release|Any CPU
{5FE82C4B-17E0-4C41-9A79-4F13FCB6D2D1}.Debug|Any CPU.Build.0 = Release|Any CPU
{5FE82C4B-17E0-4C41-9A79-4F13FCB6D2D1}.Release|Any CPU.ActiveCfg = Release|Any CPU
{5FE82C4B-17E0-4C41-9A79-4F13FCB6D2D1}.Release|Any CPU.Build.0 = Release|Any CPU
{CADD0874-D3E6-40B3-A8D5-EB04047597EC}.Debug|Any CPU.ActiveCfg = Release|Any CPU
{CADD0874-D3E6-40B3-A8D5-EB04047597EC}.Debug|Any CPU.Build.0 = Release|Any CPU
{CADD0874-D3E6-40B3-A8D5-EB04047597EC}.Release|Any CPU.ActiveCfg = Release|Any CPU
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,20 @@ public sealed class FastMoqGeneratedTestTargetAttribute : Attribute
/// Initializes a new instance of the <see cref="FastMoqGeneratedTestTargetAttribute" /> class.
/// </summary>
/// <param name="componentType">The component under test that the generated harness path should target.</param>
/// <param name="constructorParameterTypes">An optional explicit constructor signature to use for the generated harness bootstrap.</param>
public FastMoqGeneratedTestTargetAttribute(Type componentType, params Type[] constructorParameterTypes)
public FastMoqGeneratedTestTargetAttribute(Type componentType)
{
ComponentType = componentType ?? throw new ArgumentNullException(nameof(componentType));
ConstructorParameterTypes = Array.Empty<Type>();
}

/// <summary>
/// Initializes a new instance of the <see cref="FastMoqGeneratedTestTargetAttribute" /> class with an explicit constructor signature.
/// </summary>
/// <param name="componentType">The component under test that the generated harness path should target.</param>
/// <param name="constructorParameterTypes">The explicit constructor signature to use for the generated harness bootstrap. Pass an explicit empty array to target the parameterless constructor.</param>
public FastMoqGeneratedTestTargetAttribute(Type componentType, params Type[] constructorParameterTypes)
: this(componentType)
{
ConstructorParameterTypes = constructorParameterTypes ?? throw new ArgumentNullException(nameof(constructorParameterTypes));
}

Expand Down
35 changes: 28 additions & 7 deletions FastMoq.Analyzers.Tests/AnalyzerTestHelpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@ internal static class AnalyzerTestHelpers
"FastMoq.Tests.Web",
};

private static bool IsXunitAssemblyName(string assemblyName)
{
return assemblyName.StartsWith("xunit", StringComparison.OrdinalIgnoreCase);
}

public static async Task<ImmutableArray<Diagnostic>> GetDiagnosticsAsync(string source, params DiagnosticAnalyzer[] analyzers)
{
return await GetDiagnosticsAsync(source, includeAzureFunctionsHelpers: false, includeMoqProviderPackage: true, includeNSubstituteProviderPackage: true, includeWebHelpers: true, analyzers).ConfigureAwait(false);
Expand Down Expand Up @@ -148,7 +153,8 @@ public static Document CreateDocumentForTest(
bool includeWebHelpers = true,
bool includeDatabaseHelpers = false,
bool includeAzureHelpers = false,
bool includeAggregatePackage = false)
bool includeAggregatePackage = false,
bool includeXunit = true)
{
return CreateDocument(
source,
Expand All @@ -158,7 +164,8 @@ public static Document CreateDocumentForTest(
includeWebHelpers,
includeDatabaseHelpers,
includeAzureHelpers,
includeAggregatePackage);
includeAggregatePackage,
includeXunit);
}

private static Document CreateDocument(
Expand All @@ -169,7 +176,8 @@ private static Document CreateDocument(
bool includeWebHelpers = true,
bool includeDatabaseHelpers = false,
bool includeAzureHelpers = false,
bool includeAggregatePackage = false)
bool includeAggregatePackage = false,
bool includeXunit = true)
{
var project = CreateProject(
[("Test.cs", source)],
Expand All @@ -179,7 +187,8 @@ private static Document CreateDocument(
includeWebHelpers,
includeDatabaseHelpers,
includeAzureHelpers,
includeAggregatePackage);
includeAggregatePackage,
includeXunit);
return project.Documents.Single();
}

Expand All @@ -191,7 +200,8 @@ private static Project CreateProject(
bool includeWebHelpers = true,
bool includeDatabaseHelpers = false,
bool includeAzureHelpers = false,
bool includeAggregatePackage = false)
bool includeAggregatePackage = false,
bool includeXunit = true)
{
var workspace = new AdhocWorkspace();
var projectId = ProjectId.CreateNewId();
Expand All @@ -208,7 +218,8 @@ private static Project CreateProject(
includeWebHelpers,
includeDatabaseHelpers,
includeAzureHelpers,
includeAggregatePackage))
includeAggregatePackage,
includeXunit))
{
solution = solution.AddMetadataReference(projectId, metadataReference);
}
Expand All @@ -229,7 +240,8 @@ private static IEnumerable<MetadataReference> GetMetadataReferences(
bool includeWebHelpers,
bool includeDatabaseHelpers,
bool includeAzureHelpers,
bool includeAggregatePackage)
bool includeAggregatePackage,
bool includeXunit)
{
if (includeAggregatePackage)
{
Expand All @@ -250,6 +262,11 @@ private static IEnumerable<MetadataReference> GetMetadataReferences(
continue;
}

if (!includeXunit && IsXunitAssemblyName(assemblyName))
{
continue;
}

if (!includeAggregatePackage &&
string.Equals(assemblyName, "FastMoq", StringComparison.OrdinalIgnoreCase))
{
Expand Down Expand Up @@ -335,6 +352,10 @@ private static IEnumerable<MetadataReference> GetMetadataReferences(

references.Add(typeof(Moq.Mock).Assembly.Location);
references.Add(typeof(NSubstitute.Substitute).Assembly.Location);
if (includeXunit)
{
references.Add(typeof(global::Xunit.FactAttribute).Assembly.Location);
}
references.Add(typeof(Microsoft.Extensions.Logging.ILogger).Assembly.Location);
references.Add(typeof(Microsoft.AspNetCore.Http.DefaultHttpContext).Assembly.Location);
references.Add(typeof(Microsoft.AspNetCore.Mvc.ControllerContext).Assembly.Location);
Expand Down
Loading