Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Logger Message Action support (#200)
* initial generator for crud controller log message action * add sample generator for log message action * tidied up logger naming consistency * generate logger message action properties * clean up series of sonarcloud warnings * add unit tests for crud controller log message action generator
- Loading branch information
Showing
9 changed files
with
220 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 10 additions & 0 deletions
10
...s.Nucleotide.Generators/Features/Logging/CrudControllerLoggerMessageActionFeatureFlags.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Text; | ||
|
||
namespace Dhgms.Nucleotide.Generators.Features.Logging | ||
{ | ||
public class CrudControllerLoggerMessageActionFeatureFlags | ||
{ | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
...hgms.Nucleotide.Generators/Features/Logging/CrudControllerLoggerMessageActionGenerator.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
using Dhgms.Nucleotide.Generators.Generators; | ||
using Dhgms.Nucleotide.Generators.Models; | ||
|
||
namespace Dhgms.Nucleotide.Generators.Features.Logging | ||
{ | ||
public abstract class CrudControllerLoggerMessageActionGenerator : BaseClassLevelCodeGenerator<CrudControllerLoggerMessageActionFeatureFlags, CrudControllerLoggerMessageActionGeneratorProcessor, IEntityGenerationModel> | ||
{ | ||
/// <inheritdoc /> | ||
protected override string GetNamespace() | ||
{ | ||
return "LoggerMessageActions"; | ||
} | ||
} | ||
} |
138 changes: 138 additions & 0 deletions
138
...eotide.Generators/Features/Logging/CrudControllerLoggerMessageActionGeneratorProcessor.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,138 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using Dhgms.Nucleotide.Generators.GeneratorProcessors; | ||
using Dhgms.Nucleotide.Generators.Models; | ||
using Dhgms.Nucleotide.Generators.PropertyInfo; | ||
using Microsoft.CodeAnalysis; | ||
using Microsoft.CodeAnalysis.CSharp; | ||
using Microsoft.CodeAnalysis.CSharp.Syntax; | ||
|
||
namespace Dhgms.Nucleotide.Generators.Features.Logging | ||
{ | ||
public class CrudControllerLoggerMessageActionGeneratorProcessor : BaseClassLevelCodeGeneratorProcessor<IEntityGenerationModel> | ||
{ | ||
/// <inheritdoc /> | ||
protected override string[] GetClassPrefixes() | ||
{ | ||
return Array.Empty<string>(); | ||
} | ||
|
||
/// <inheritdoc /> | ||
protected override string GetClassSuffix() | ||
{ | ||
return "LoggerMessageActions"; | ||
} | ||
|
||
/// <inheritdoc /> | ||
protected override IList<string> GetUsings() | ||
{ | ||
return new List<string> | ||
{ | ||
"System", | ||
"Microsoft.Extensions.Logging", | ||
}; | ||
} | ||
|
||
/// <inheritdoc /> | ||
protected override bool GetWhetherClassShouldBePartialClass() | ||
{ | ||
return false; | ||
} | ||
|
||
/// <inheritdoc /> | ||
protected override bool GetWhetherClassShouldBeSealedClass() | ||
{ | ||
return true; | ||
} | ||
|
||
/// <inheritdoc /> | ||
protected override string[] GetClassLevelCommentSummary(string entityName) | ||
{ | ||
return new[] | ||
{ | ||
$"Log Message Actions for the {entityName} Controller." | ||
}; | ||
} | ||
|
||
/// <inheritdoc /> | ||
protected override string[] GetClassLevelCommentRemarks(string entityName) | ||
{ | ||
return Array.Empty<string>(); | ||
} | ||
|
||
/// <inheritdoc /> | ||
protected override IList<Tuple<string, IList<string>>> GetClassAttributes(IEntityGenerationModel entityDeclaration) | ||
{ | ||
return new List<Tuple<string, IList<string>>>(); | ||
} | ||
|
||
/// <inheritdoc /> | ||
protected override IList<string> GetBaseConstructorArguments() | ||
{ | ||
return new List<string>(); | ||
} | ||
|
||
/// <inheritdoc /> | ||
protected override MethodDeclarationSyntax[] GetMethodDeclarations(IEntityGenerationModel entityGenerationModel) | ||
{ | ||
return Array.Empty<MethodDeclarationSyntax>(); | ||
} | ||
|
||
/// <inheritdoc /> | ||
protected override IEnumerable<PropertyDeclarationSyntax> GetPropertyDeclarations(IEntityGenerationModel entityGenerationModel) | ||
{ | ||
var pocoSummary = GetSummary(new[] { $"Gets the Logger Message Action {entityGenerationModel.ClassName}." }); | ||
|
||
var pocoType = SyntaxFactory.ParseTypeName("global::System.Action<global::Microsoft.Extensions.Logging.ILogger, string, global::System.Exception?>"); | ||
var accessorList = new[] | ||
{ | ||
SyntaxFactory.AccessorDeclaration(SyntaxKind.GetAccessorDeclaration) | ||
.WithSemicolonToken(SyntaxFactory.Token(SyntaxKind.SemicolonToken)), | ||
SyntaxFactory.AccessorDeclaration(SyntaxKind.InitAccessorDeclaration) | ||
.WithSemicolonToken(SyntaxFactory.Token(SyntaxKind.SemicolonToken)), | ||
}; | ||
|
||
var addLongerMessageAction = RoslynGenerationHelpers.GetPropertyDeclarationSyntax(pocoType, "AddEventLogMessageAction", accessorList, pocoSummary); | ||
var deleteLongerMessageAction = RoslynGenerationHelpers.GetPropertyDeclarationSyntax(pocoType, "DeleteEventLogMessageAction", accessorList, pocoSummary); | ||
var listLongerMessageAction = RoslynGenerationHelpers.GetPropertyDeclarationSyntax(pocoType, "ListEventLogMessageAction", accessorList, pocoSummary); | ||
var updateLongerMessageAction = RoslynGenerationHelpers.GetPropertyDeclarationSyntax(pocoType, "UpdateEventLogMessageAction", accessorList, pocoSummary); | ||
var viewLongerMessageAction = RoslynGenerationHelpers.GetPropertyDeclarationSyntax(pocoType, "ViewEventLogMessageAction", accessorList, pocoSummary); | ||
|
||
return new [] | ||
{ | ||
addLongerMessageAction, | ||
deleteLongerMessageAction, | ||
listLongerMessageAction, | ||
updateLongerMessageAction, | ||
viewLongerMessageAction, | ||
}; | ||
} | ||
|
||
/// <inheritdoc /> | ||
protected override IList<Tuple<Func<string, string>, string, Accessibility>> GetConstructorArguments() | ||
{ | ||
return new List<Tuple<Func<string, string>, string, Accessibility>>(); | ||
} | ||
|
||
/// <inheritdoc /> | ||
protected override string GetBaseClass(string entityName) | ||
{ | ||
return null; | ||
} | ||
|
||
/// <inheritdoc /> | ||
protected override IEnumerable<string> GetImplementedInterfaces(IEntityGenerationModel generationModel) | ||
{ | ||
return new [] | ||
{ | ||
"Whipstaff.AspNetCore.Features.Logging.ICrudControllerLogMessageActions" | ||
}; | ||
} | ||
|
||
/// <inheritdoc /> | ||
protected override SeparatedSyntaxList<AttributeSyntax> GetAttributesForProperty(PropertyInfoBase propertyInfo) | ||
{ | ||
return default(SeparatedSyntaxList<AttributeSyntax>); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 13 additions & 0 deletions
13
src/Dhgms.Nucleotide.ModelTests/TestCrudControllerLoggerMessageActionGenerator.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
using Dhgms.Nucleotide.Generators.Features.Logging; | ||
using Dhgms.Nucleotide.Generators.Models; | ||
using Dhgms.Nucleotide.ModelTests; | ||
using Microsoft.CodeAnalysis; | ||
|
||
namespace Dhgms.Nucleotide.SampleGenerator | ||
{ | ||
[Generator] | ||
public sealed class TestCrudControllerLoggerMessageActionGenerator : CrudControllerLoggerMessageActionGenerator | ||
{ | ||
protected override INucleotideGenerationModel<IEntityGenerationModel> NucleotideGenerationModel => new ModelGenerationDetails(); | ||
} | ||
} |
38 changes: 38 additions & 0 deletions
38
....UnitTests/Generators/Features/Logging/CrudControllerLoggerMessageActionGeneratorTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
using System; | ||
using System.Diagnostics.CodeAnalysis; | ||
using Dhgms.Nucleotide.Generators.Features.Logging; | ||
using Dhgms.Nucleotide.Generators.Models; | ||
using Dhgms.Nucleotide.SampleGenerator; | ||
using Microsoft.CodeAnalysis; | ||
using Xunit.Abstractions; | ||
|
||
namespace Dhgms.Nucleotide.UnitTests.Generators.Features.Logging | ||
{ | ||
[ExcludeFromCodeCoverage] | ||
public static class CrudControllerLoggerMessageActionGeneratorTests | ||
{ | ||
public sealed class ConstructorMethod : BaseGeneratorTests.BaseConstructorMethod<CrudControllerLoggerMessageActionGenerator, CrudControllerLoggerMessageActionFeatureFlags, CrudControllerLoggerMessageActionGeneratorProcessor, IEntityGenerationModel> | ||
{ | ||
public ConstructorMethod(ITestOutputHelper output) : base(output) | ||
{ | ||
} | ||
|
||
protected override Func<AttributeData, CrudControllerLoggerMessageActionGenerator> GetFactory() | ||
{ | ||
return data => new TestCrudControllerLoggerMessageActionGenerator(); | ||
} | ||
} | ||
|
||
public sealed class GenerateAsyncMethod : BaseGeneratorTests.BaseGenerateAsyncMethod<CrudControllerLoggerMessageActionGenerator, CrudControllerLoggerMessageActionFeatureFlags, CrudControllerLoggerMessageActionGeneratorProcessor, IEntityGenerationModel> | ||
{ | ||
public GenerateAsyncMethod(ITestOutputHelper output) : base(output) | ||
{ | ||
} | ||
|
||
protected override Func<AttributeData, CrudControllerLoggerMessageActionGenerator> GetFactory() | ||
{ | ||
return data => new TestCrudControllerLoggerMessageActionGenerator(); | ||
} | ||
} | ||
} | ||
} |