Skip to content

Commit 9c63d2e

Browse files
committed
Added **RestJson** service automation.
Added **Integration** testing using MSTest.
1 parent 7203f9f commit 9c63d2e

File tree

10 files changed

+2405
-3
lines changed

10 files changed

+2405
-3
lines changed

src/Architecture/CodeFactory.Architecture.Blazor.Server/CodeFactory.Architecture.Blazor.Server.csproj

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,20 @@
4848
<Reference Include="WindowsBase" />
4949
</ItemGroup>
5050
<ItemGroup>
51+
<Compile Include="LoadExternalConfiguration.cs" />
5152
<Compile Include="Properties\AssemblyInfo.cs" />
53+
<Compile Include="RegisterTransientServices.cs" />
54+
<Compile Include="ReloadAutomationConfiguration.cs" />
55+
</ItemGroup>
56+
<ItemGroup>
57+
<ProjectReference Include="..\..\Automation\CodeFactory.Automation.NDF.Logic\CodeFactory.Automation.NDF.Logic.csproj">
58+
<Project>{01f5417b-d33e-43ba-9d13-e9114eb989ac}</Project>
59+
<Name>CodeFactory.Automation.NDF.Logic</Name>
60+
</ProjectReference>
61+
<ProjectReference Include="..\..\Automation\CodeFactory.Automation.Standard.Logic\CodeFactory.Automation.Standard.Logic.csproj">
62+
<Project>{b1973f62-7951-41d3-a227-f3584b7f3cde}</Project>
63+
<Name>CodeFactory.Automation.Standard.Logic</Name>
64+
</ProjectReference>
5265
</ItemGroup>
5366
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
5467
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
using CodeFactory.WinVs;
2+
using CodeFactory.WinVs.Commands;
3+
using CodeFactory.WinVs.Commands.IDE;
4+
using CodeFactory.WinVs.Logging;
5+
using CodeFactory.WinVs.Models.CSharp;
6+
using CodeFactory.WinVs.Models.CSharp.Builder;
7+
using CodeFactory.WinVs.Models.ProjectSystem;
8+
using System;
9+
using System.Collections.Generic;
10+
using System.Linq;
11+
using System.Text;
12+
using System.Threading.Tasks;
13+
14+
namespace CodeFactory.Architecture.Blazor.Server
15+
{
16+
/// <summary>
17+
/// Code factory command that is executed when the solution is loaded. This command only gets called one time on load of the solution.
18+
/// </summary>
19+
public class LoadExternalConfiguration : SolutionLoadCommandBase
20+
{
21+
private static readonly string commandTitle = "Load External Configuration";
22+
private static readonly string commandDescription = "Loads the external configuration for automation.";
23+
24+
#pragma warning disable CS1998
25+
/// <inheritdoc />
26+
public LoadExternalConfiguration(ILogger logger, IVsActions vsActions) : base(logger, vsActions, commandTitle, commandDescription)
27+
{
28+
//Intentionally blank
29+
}
30+
31+
/// <summary>
32+
/// Code factory framework calls this method when the command has been executed.
33+
/// </summary>
34+
/// <param name="result">The code factory model that has generated and provided to the command to process.</param>
35+
public override async Task ExecuteCommandAsync(VsSolution result)
36+
{
37+
38+
try
39+
{
40+
//var addMissingMember = new AddMissingMembersNDF(null, null);
41+
//addMissingMember.LoadExternalConfigDefinition().RegisterCommandWithDefaultConfiguration();
42+
43+
//var refreshEFRepository = new RefreshEFRepository(null, null);
44+
//refreshEFRepository.LoadExternalConfigDefinition().RegisterCommandWithDefaultConfiguration();
45+
46+
//var refreshRestService = new RefreshRestService(null, null);
47+
//refreshRestService.LoadExternalConfigDefinition().RegisterCommandWithDefaultConfiguration();
48+
49+
//var refreshTest = new RefreshTest(null, null);
50+
//refreshTest.LoadExternalConfigDefinition().RegisterCommandWithDefaultConfiguration();
51+
52+
//var refreshFluentValidation = new RefreshFluentValidation(null, null);
53+
//refreshFluentValidation.LoadExternalConfigDefinition().RegisterCommandWithDefaultConfiguration();
54+
55+
//var addMissingRepositoryMembers = new AddMissingRepositoryMembers(null, null);
56+
//addMissingRepositoryMembers.LoadExternalConfigDefinition().RegisterCommandWithDefaultConfiguration();
57+
58+
//var updateLogicImplementation = new UpdateLogicImplementation(null, null);
59+
//updateLogicImplementation.LoadExternalConfigDefinition().RegisterCommandWithDefaultConfiguration();
60+
61+
//var addMissingLogicMembers = new AddMissingLogicMembers(null, null);
62+
//addMissingLogicMembers.LoadExternalConfigDefinition().RegisterCommandWithDefaultConfiguration();
63+
64+
//var addMissingControllerMembers = new AddMissingControllerMembers(null, null);
65+
//addMissingControllerMembers.LoadExternalConfigDefinition().RegisterCommandWithDefaultConfiguration();
66+
67+
ConfigManager.LoadConfiguration(result, "Automation", VisualStudioActions);
68+
}
69+
catch (Exception unhandledError)
70+
{
71+
_logger.Error($"The following unhandled error occurred while executing the solution explorer solution command {commandTitle}. ",
72+
unhandledError);
73+
74+
}
75+
76+
}
77+
}
78+
}
Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
using CodeFactory.Automation.NDF.Logic;
2+
using CodeFactory.WinVs;
3+
using CodeFactory.WinVs.Commands;
4+
using CodeFactory.WinVs.Commands.SolutionExplorer;
5+
using CodeFactory.WinVs.Logging;
6+
using CodeFactory.WinVs.Models.CSharp;
7+
using CodeFactory.WinVs.Models.CSharp.Builder;
8+
using CodeFactory.WinVs.Models.ProjectSystem;
9+
using System;
10+
using System.Collections.Generic;
11+
using System.Linq;
12+
using System.Text;
13+
using System.Threading.Tasks;
14+
15+
16+
namespace CodeFactory.Architecture.Blazor.Server
17+
{
18+
/// <summary>
19+
/// Code factory command for automation of a project when selected from solution explorer.
20+
/// </summary>
21+
public class RegisterTransientServices : ProjectCommandBase
22+
{
23+
private static readonly string commandTitle = "Register Transient Services";
24+
private static readonly string commandDescription = "Registers Transient classes with a NDF dependency injection loader for a target project.";
25+
26+
#pragma warning disable CS1998
27+
28+
/// <inheritdoc />
29+
public RegisterTransientServices(ILogger logger, IVsActions vsActions) : base(logger, vsActions, commandTitle, commandDescription)
30+
{
31+
//Intentionally blank
32+
}
33+
#pragma warning disable CS1998
34+
35+
#region External Configuration
36+
37+
/// <summary>
38+
/// The fully qualified name of the command to be used with configuration.
39+
/// </summary>
40+
public static string Type = typeof(RegisterTransientServices).FullName;
41+
42+
/// <summary>
43+
/// Loads the external configuration definition for this command.
44+
/// </summary>
45+
/// <returns>Will return the command configuration or null if this command does not support external configurations.</returns>
46+
public override ConfigCommand LoadExternalConfigDefinition()
47+
{
48+
return null;
49+
}
50+
#endregion
51+
52+
#region Overrides of VsCommandBase<VsProject>
53+
54+
/// <summary>
55+
/// Validation logic that will determine if this command should be enabled for execution.
56+
/// </summary>
57+
/// <param name="result">The target model data that will be used to determine if this command should be enabled.</param>
58+
/// <returns>Boolean flag that will tell code factory to enable this command or disable it.</returns>
59+
public override async Task<bool> EnableCommandAsync(VsProject result)
60+
{
61+
//Result that determines if the command is enabled and visible in the context menu for execution.
62+
bool isEnabled = false;
63+
64+
try
65+
{
66+
isEnabled = await result.CanRegisterTransientClassesAsync();
67+
}
68+
catch (Exception unhandledError)
69+
{
70+
_logger.Error($"The following unhandled error occurred while checking if the solution explorer project command {commandTitle} is enabled. ",
71+
unhandledError);
72+
isEnabled = false;
73+
}
74+
75+
return isEnabled;
76+
}
77+
78+
/// <summary>
79+
/// Code factory framework calls this method when the command has been executed.
80+
/// </summary>
81+
/// <param name="result">The code factory model that has generated and provided to the command to process.</param>
82+
public override async Task ExecuteCommandAsync(VsProject result)
83+
{
84+
try
85+
{
86+
await VisualStudioActions.RegisterTransientClassesAsync(result);
87+
}
88+
catch (Exception unhandledError)
89+
{
90+
_logger.Error($"The following unhandled error occurred while executing the solution explorer project command {commandTitle}. ",
91+
unhandledError);
92+
93+
}
94+
}
95+
96+
#endregion
97+
}
98+
}
Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
using CodeFactory.WinVs;
2+
using CodeFactory.WinVs.Commands;
3+
using CodeFactory.WinVs.Commands.SolutionExplorer;
4+
using CodeFactory.WinVs.Logging;
5+
using CodeFactory.WinVs.Models.CSharp;
6+
using CodeFactory.WinVs.Models.CSharp.Builder;
7+
using CodeFactory.WinVs.Models.ProjectSystem;
8+
using System;
9+
using System.Collections.Generic;
10+
using System.Linq;
11+
using System.Text;
12+
using System.Threading.Tasks;
13+
14+
namespace CodeFactory.Architecture.Blazor.Server
15+
{
16+
/// <summary>
17+
/// Code factory command for automation of the solution when selected from solution explorer.
18+
/// </summary>
19+
public class ReloadAutomationConfiguration : SolutionCommandBase
20+
{
21+
private static readonly string commandTitle = "Reload Automation Configuration";
22+
private static readonly string commandDescription = "Reloads the automation configuration.";
23+
24+
#pragma warning disable CS1998
25+
/// <inheritdoc />
26+
public ReloadAutomationConfiguration(ILogger logger, IVsActions vsActions) : base(logger, vsActions, commandTitle, commandDescription)
27+
{
28+
//Intentionally blank
29+
}
30+
31+
#region External Configuration
32+
33+
/// <summary>
34+
/// The fully qualified name of the command to be used with configuration.
35+
/// </summary>
36+
public static string Type = typeof(ReloadAutomationConfiguration).FullName;
37+
38+
/// <summary>
39+
/// Loads the external configuration definition for this command.
40+
/// </summary>
41+
/// <returns>Will return the command configuration or null if this command does not support external configurations.</returns>
42+
public override ConfigCommand LoadExternalConfigDefinition()
43+
{
44+
return null;
45+
}
46+
#endregion
47+
48+
#region Overrides of VsCommandBase<VsSolution>
49+
50+
/// <summary>
51+
/// Validation logic that will determine if this command should be enabled for execution.
52+
/// </summary>
53+
/// <param name="result">The target model data that will be used to determine if this command should be enabled.</param>
54+
/// <returns>Boolean flag that will tell code factory to enable this command or disable it.</returns>
55+
public override async Task<bool> EnableCommandAsync(VsSolution result)
56+
{
57+
//Result that determines if the command is enabled and visible in the context menu for execution.
58+
bool isEnabled = false;
59+
60+
try
61+
{
62+
isEnabled = await ConfigManager.HasAutomationConfigAsync(result, "Automation");
63+
}
64+
catch (Exception unhandledError)
65+
{
66+
_logger.Error($"The following unhandled error occurred while checking if the solution explorer solution command {commandTitle} is enabled. ",
67+
unhandledError);
68+
isEnabled = false;
69+
}
70+
71+
return isEnabled;
72+
}
73+
74+
/// <summary>
75+
/// Code factory framework calls this method when the command has been executed.
76+
/// </summary>
77+
/// <param name="result">The code factory model that has generated and provided to the command to process.</param>
78+
public override async Task ExecuteCommandAsync(VsSolution result)
79+
{
80+
81+
try
82+
{
83+
ConfigManager.LoadConfiguration(result, "Automation", VisualStudioActions);
84+
}
85+
catch (Exception unhandledError)
86+
{
87+
_logger.Error($"The following unhandled error occurred while executing the solution explorer solution command {commandTitle}. ",
88+
unhandledError);
89+
90+
}
91+
92+
}
93+
94+
#endregion
95+
}
96+
}
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
using CodeFactory.WinVs.Models.CSharp;
2+
using System;
3+
using System.Collections.Generic;
4+
using System.Linq;
5+
using System.Text;
6+
using System.Threading.Tasks;
7+
8+
namespace CodeFactory.Automation.NDF.Logic.AspNetCore.Service.Rest.Json
9+
{
10+
/// <summary>
11+
/// Method extensions that support name generation for rest services.
12+
/// </summary>
13+
public static class MethodExtensions
14+
{
15+
/// <summary>
16+
/// Generates the rest action name based on the method name and the supporting parameters of the method.
17+
/// </summary>
18+
/// <param name="source">The source method to extract the name from.</param>
19+
/// <param name="fullSignatureName">Flag that determines if the parameters of the method should also be used in the name rest call.</param>
20+
/// <returns>The formatted name of the rest call.</returns>
21+
/// <exception cref="CodeFactoryException">Raised if required data is missing.</exception>
22+
public static string GetRestName(this CsMethod source, bool fullSignatureName = false)
23+
{
24+
if (source == null)
25+
throw new CodeFactoryException(
26+
"Cannot update the rest service, a method was not provided so cannot determine the name of the rest call.");
27+
28+
if (string.IsNullOrEmpty(source.Name))
29+
throw new CodeFactoryException(
30+
"Cannot update the rest service, the method name was empty or null, cannot determine the name of the rest call.");
31+
32+
33+
StringBuilder restNameBuilder = new StringBuilder();
34+
35+
var methodName = source.Name.Trim();
36+
37+
restNameBuilder.Append(methodName.EndsWith("Async", StringComparison.InvariantCultureIgnoreCase)
38+
? methodName.Substring(0, methodName.Length - 5)
39+
: methodName);
40+
41+
if (!(fullSignatureName & source.HasParameters)) return restNameBuilder.ToString();
42+
43+
restNameBuilder.Append("By");
44+
45+
bool firstParameter = true;
46+
foreach (var sourceParameter in source.Parameters)
47+
{
48+
if (string.IsNullOrEmpty(sourceParameter.Name)) continue;
49+
50+
if (firstParameter)
51+
{
52+
restNameBuilder.Append(sourceParameter.Name.ToUpper().First());
53+
firstParameter = false;
54+
}
55+
else
56+
{
57+
restNameBuilder.Append(sourceParameter.Name.ToLower().First());
58+
}
59+
}
60+
61+
return restNameBuilder.ToString();
62+
}
63+
64+
/// <summary>
65+
/// Determines of the source method will be called as a post call or not.
66+
/// </summary>
67+
/// <param name="source">Target method to check for a post call.</param>
68+
/// <returns>True if the call will be post based or false if not.</returns>
69+
/// <exception cref="CodeFactoryException">Raised if required data is missing.</exception>
70+
public static bool IsPostCall(this CsMethod source)
71+
{
72+
if (source == null)
73+
throw new CodeFactoryException("No method was provided cannot determine if a Post call.");
74+
75+
return source.HasParameters;
76+
}
77+
}
78+
}

0 commit comments

Comments
 (0)