Skip to content
Draft
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
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using System.ComponentModel.DataAnnotations;
using NetEscapades.Configuration.Validation;
using NetEscapades.Configuration.Validation;
using System.ComponentModel.DataAnnotations;

namespace CoffeeCard.Common.Configuration
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using System.ComponentModel.DataAnnotations;
using NetEscapades.Configuration.Validation;
using NetEscapades.Configuration.Validation;
using System.ComponentModel.DataAnnotations;

namespace CoffeeCard.Common.Configuration
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using System.ComponentModel.DataAnnotations;
using NetEscapades.Configuration.Validation;
using NetEscapades.Configuration.Validation;
using System.ComponentModel.DataAnnotations;

namespace CoffeeCard.Common.Configuration
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using System.ComponentModel.DataAnnotations;
using NetEscapades.Configuration.Validation;
using System.ComponentModel.DataAnnotations;

namespace CoffeeCard.Common.Configuration
{
Expand Down
4 changes: 2 additions & 2 deletions coffeecard/CoffeeCard.Common/Configuration/MailgunSettings.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using System.ComponentModel.DataAnnotations;
using NetEscapades.Configuration.Validation;
using NetEscapades.Configuration.Validation;
using System.ComponentModel.DataAnnotations;

namespace CoffeeCard.Common.Configuration
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using System;
using NetEscapades.Configuration.Validation;
using System;
using System.ComponentModel.DataAnnotations;
using NetEscapades.Configuration.Validation;

namespace CoffeeCard.Common.Configuration
{
Expand Down
2 changes: 1 addition & 1 deletion coffeecard/CoffeeCard.Common/Errors/ConflictException.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using Microsoft.AspNetCore.Http;
using System;
using System.Runtime.Serialization;
using Microsoft.AspNetCore.Http;

namespace CoffeeCard.Common.Errors
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using Microsoft.AspNetCore.Http;
using System;
using System.Runtime.Serialization;
using Microsoft.AspNetCore.Http;

namespace CoffeeCard.Common.Errors
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using Microsoft.AspNetCore.Http;
using System;
using System.Runtime.Serialization;
using Microsoft.AspNetCore.Http;

namespace CoffeeCard.Common.Errors
{
Expand Down
58 changes: 29 additions & 29 deletions coffeecard/CoffeeCard.Generators/Builder/BuilderGenerator.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using System.Text;
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.CSharp.Syntax;
using Microsoft.CodeAnalysis.Text;
using System.Text;

namespace CoffeeCard.Generators.Builder;

Expand Down Expand Up @@ -37,7 +37,7 @@ private static bool IsSyntaxTargetForGeneration(
SyntaxNode syntaxNode,
CancellationToken cancellationToken)
{
return syntaxNode is ClassDeclarationSyntax classDeclaration;
return syntaxNode is ClassDeclarationSyntax;
}

private static INamedTypeSymbol GetSemanticTargetForGeneration(GeneratorAttributeSyntaxContext context,
Expand All @@ -50,16 +50,16 @@ private string GenerateBuilderCode(INamedTypeSymbol typeSymbol, ITypeSymbol enti
{
var codeBuilder = new StringBuilder();

codeBuilder.AppendLine("// <auto-generated/>");
codeBuilder.AppendLine("using System;");
codeBuilder.AppendLine("using AutoBogus.Conventions;");
codeBuilder.AppendLine($"using {entity.ContainingNamespace};");
codeBuilder.AppendLine();
codeBuilder.AppendLine($"namespace {typeSymbol.ContainingNamespace};");
codeBuilder.AppendLine();
_ = codeBuilder.AppendLine("// <auto-generated/>");
_ = codeBuilder.AppendLine("using System;");
_ = codeBuilder.AppendLine("using AutoBogus.Conventions;");
_ = codeBuilder.AppendLine($"using {entity.ContainingNamespace};");
_ = codeBuilder.AppendLine();
_ = codeBuilder.AppendLine($"namespace {typeSymbol.ContainingNamespace};");
_ = codeBuilder.AppendLine();

codeBuilder.AppendLine($"public partial class {typeSymbol.Name} : BaseBuilder<{entity.Name}>, IBuilder<{typeSymbol.Name}>");
codeBuilder.AppendLine("{");
_ = codeBuilder.AppendLine($"public partial class {typeSymbol.Name} : BaseBuilder<{entity.Name}>, IBuilder<{typeSymbol.Name}>");
_ = codeBuilder.AppendLine("{");

// Retrieve all properties of the given entity
var properties = entity.GetMembers().OfType<IPropertySymbol>().Where(p => p.Kind == SymbolKind.Property);
Expand All @@ -71,7 +71,7 @@ private string GenerateBuilderCode(INamedTypeSymbol typeSymbol, ITypeSymbol enti
{
if (property.Name.Contains("Id"))
{
configBuilder.AppendLine($" .WithSkip<{entity.Name}>(\"{property.Name}\")");
_ = configBuilder.AppendLine($" .WithSkip<{entity.Name}>(\"{property.Name}\")");
}
AddWithPropertyValueToCodeBuilder(codeBuilder: codeBuilder,
typeSymbol: typeSymbol,
Expand All @@ -87,7 +87,7 @@ private string GenerateBuilderCode(INamedTypeSymbol typeSymbol, ITypeSymbol enti
AddPrivateConstructorToCodeBuilder(codeBuilder, typeSymbol, configBuilder);

// End class
codeBuilder.AppendLine("}");
_ = codeBuilder.AppendLine("}");

return codeBuilder.ToString();
}
Expand All @@ -100,35 +100,35 @@ private string GenerateBuilderCode(INamedTypeSymbol typeSymbol, ITypeSymbol enti
/// <param name="configBuilder"></param>
private void AddPrivateConstructorToCodeBuilder(StringBuilder codeBuilder, ITypeSymbol typeSymbol, StringBuilder configBuilder)
{
codeBuilder.AppendLine(
_ = codeBuilder.AppendLine(
$" private {typeSymbol.Name} ()");
codeBuilder.AppendLine(" {");
codeBuilder.AppendLine(" Faker.Configure(builder => builder");
codeBuilder.Append($"{configBuilder}");
codeBuilder.AppendLine(" .WithConventions());");
codeBuilder.AppendLine(" }");
_ = codeBuilder.AppendLine(" {");
_ = codeBuilder.AppendLine(" Faker.Configure(builder => builder");
_ = codeBuilder.Append($"{configBuilder}");
_ = codeBuilder.AppendLine(" .WithConventions());");
_ = codeBuilder.AppendLine(" }");
}

private void AddWithPropertyValueToCodeBuilder(StringBuilder codeBuilder, ITypeSymbol typeSymbol, IPropertySymbol property, char entityNameChar)
{
codeBuilder.AppendLine(
_ = codeBuilder.AppendLine(
$" public {typeSymbol.Name} With{property.Name}({property.Type} {property.Name}Value)");
codeBuilder.AppendLine(" {");
_ = codeBuilder.AppendLine(" {");

codeBuilder.AppendLine(
_ = codeBuilder.AppendLine(
$" Faker.RuleFor({entityNameChar} => {entityNameChar}.{property.Name}, {property.Name}Value);");
codeBuilder.AppendLine(" return this;");
codeBuilder.AppendLine(" }");
_ = codeBuilder.AppendLine(" return this;");
_ = codeBuilder.AppendLine(" }");
}
private void AddWithPropertySetterToCodeBuilder(StringBuilder codeBuilder, ITypeSymbol typeSymbol, IPropertySymbol property, char entityNameChar)
{
codeBuilder.AppendLine(
_ = codeBuilder.AppendLine(
$" public {typeSymbol.Name} With{property.Name}(Func<Bogus.Faker, {property.Type}> {property.Name}Setter)");
codeBuilder.AppendLine(" {");
_ = codeBuilder.AppendLine(" {");

codeBuilder.AppendLine(
_ = codeBuilder.AppendLine(
$" Faker.RuleFor({entityNameChar} => {entityNameChar}.{property.Name}, {property.Name}Setter);");
codeBuilder.AppendLine(" return this;");
codeBuilder.AppendLine(" }");
_ = codeBuilder.AppendLine(" return this;");
_ = codeBuilder.AppendLine(" }");
}
}
6 changes: 2 additions & 4 deletions coffeecard/CoffeeCard.Library/CoffeeCard.Library.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,12 @@
</PropertyGroup>
<ItemGroup>
<PackageReference Include="MailKit" Version="3.4.2" />
<PackageReference Include="Microsoft.Data.SqlClient" Version="5.1.1" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="8.0.0" />
<PackageReference Include="Microsoft.FeatureManagement.AspNetCore" Version="3.2.0" />
<PackageReference Include="MimeKit" Version="3.4.2" />
<PackageReference Include="NetEscapades.Configuration.Validation" Version="2.0.0" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.Core" Version="2.2.5" />
<PackageReference Include="RestSharp" Version="108.0.2" />
<PackageReference Include="Serilog.AspNetCore" Version="6.0.1" />
<PackageReference Include="Serilog.Enrichers.CorrelationId" Version="3.0.1" />
<PackageReference Include="Serilog.Settings.Configuration" Version="3.4.0" />
<PackageReference Include="Serilog.Sinks.Console" Version="4.1.0" />
<PackageReference Include="Serilog.Sinks.File" Version="5.0.0" />
Expand All @@ -20,7 +19,6 @@
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="8.0.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="8.0.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="8.0.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.Diagnostics.HealthChecks.EntityFrameworkCore" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.Hosting.Abstractions" Version="8.0.0" />
</ItemGroup>
Expand Down
Loading