Skip to content

Commit

Permalink
#23: Added architectural test with Public Api description for Synergy…
Browse files Browse the repository at this point in the history
….Behaviours.Testing library
  • Loading branch information
MarcinCelej committed May 14, 2023
1 parent b6dea6c commit ef67f18
Show file tree
Hide file tree
Showing 9 changed files with 104 additions and 25 deletions.
12 changes: 9 additions & 3 deletions Behaviours/Synergy.Behaviours.Testing/FeatureGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,18 @@ public static void Generate<TBehaviour>(
include,
exclude,
generateAfter,
// ReSharper disable once ExplicitCallerInfoArgument
callerFilePath
);
var destinationFilePath = Path.Combine(Path.GetDirectoryName(callerFilePath), to);
var destinationFilePath = Path.Combine(PathFor(callerFilePath), to);
File.WriteAllText(destinationFilePath, code);
}

private static String PathFor(string callerFilePath)
{
return Path.GetDirectoryName(callerFilePath) ?? throw new ArgumentException("Improper path: " + callerFilePath, nameof(callerFilePath));
}

public static string Generate<TBehaviour>(
this TBehaviour featureClass,
string from,
Expand All @@ -54,7 +60,7 @@ public static string Generate<TBehaviour>(
StringBuilder code = new StringBuilder();
string className = featureClass.GetType()
.Name;
var gherkinPath = Path.Combine(Path.GetDirectoryName(callerFilePath), from);
var gherkinPath = Path.Combine(PathFor(callerFilePath), from);

string[] gherkins = FeatureGenerator.ReadAllLinesFrom(gherkinPath);

Expand All @@ -65,7 +71,7 @@ public static string Generate<TBehaviour>(
code.AppendLine();
code.AppendLine(
$"[GeneratedCode(\"{typeof(FeatureGenerator).Assembly.FullName}\", " +
$"\"{typeof(FeatureGenerator).Assembly.GetName().Version.ToString()}\")]"
$"\"{typeof(FeatureGenerator).Assembly.GetName().Version?.ToString()}\")]"
);
code.AppendLine($"public partial class {className}");
code.AppendLine("{");
Expand Down
2 changes: 0 additions & 2 deletions Behaviours/Synergy.Behaviours.Testing/Sentence.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

namespace Synergy.Behaviours.Testing;

// TODO: Marcin Celej [from: Marcin Celej on: 12-05-2023]: Add Public API verification test to see what is exposed from this library

internal static class Sentence
{
public static string ToMethod(string sentence)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,17 @@
<AssemblyVersion>$(Version)</AssemblyVersion>
</PropertyGroup>

<PropertyGroup Condition=" '$(Configuration)' == 'Debug' ">
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
</PropertyGroup>

<PropertyGroup Condition=" '$(Configuration)' == 'Release' ">
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
</PropertyGroup>

<ItemGroup>
<None Update="synergy.png">
<Pack>true</Pack>
<PackagePath></PackagePath>
</None>
<None Update="license.txt">
<Pack>true</Pack>
<PackagePath></PackagePath>
</None>
<None Include="synergy.png" Pack="true" PackagePath="" />
<None Include="license.txt" Pack="true" PackagePath="" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Technical Debt for Synergy.Contracts

Total: 2

## [FeatureGenerator.cs](../../../Synergy.Behaviours.Testing/FeatureGenerator.cs)
- TODO: Marcin Celej [from: Marcin Celej on: 10-05-2023]: Add include / exclude as functions
- TODO: Marcin Celej [from: Marcin Celej on: 10-05-2023]: Support Scenario Outline along with Examples
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using Synergy.Documentation.Code;
using Synergy.Documentation.Todos;

namespace Synergy.Behaviours.Tests.Todos;
namespace Synergy.Behaviours.Tests.Architecture.Debt;

[UsesVerify]
public class Todos
Expand All @@ -10,7 +10,7 @@ public class Todos
public async Task Generate()
{
var rootFolder = CodeFolder.Current()
.Up(2);
.Up(3);
var technicalDebt = TodoExplorer.DebtFor("Synergy.Contracts", rootFolder);

await Verifier
Expand Down
23 changes: 23 additions & 0 deletions Behaviours/Synergy.Behaviours.Tests/Architecture/Public/Api.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
using Synergy.Behaviours.Testing;
using Synergy.Documentation.Api;

namespace Synergy.Behaviours.Tests.Architecture.Public;

[UsesVerify]
public class Api
{
[Fact]
public async Task Generate()
{
// ARRANGE
var assembly = typeof(Feature<>).Assembly;

// ACT
var publicApi = ApiDescription.GenerateFor(assembly);

// ASSERT
await Verifier.Verify(publicApi, "md")
.UseMethodName("of." + assembly.GetName()
.Name);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# Synergy.Behaviours.Testing

## Feature<TFeature> (abstract class) : IFeature
- And() : TFeature?
- Background() : TFeature?
- But() : TFeature?
- Given() : TFeature?
- Moreover() : TFeature?
- Then() : TFeature?
- When() : TFeature?

## FeatureGenerator (abstract class)
- FeatureGenerator.Generate<TBehaviour>(
feature: TBehaviour?,
from: string,
to: string,
include: String[]? [Nullable, Optional],
exclude: String[]? [Nullable, Optional],
generateAfter: Func<Scenario, bool>? [Nullable, Optional],
callerFilePath: string [CallerFilePath, Optional]
) : void [Extension]
- FeatureGenerator.Generate<TBehaviour>(
featureClass: TBehaviour?,
from: string,
include: String[]? [Nullable, Optional],
exclude: String[]? [Nullable, Optional],
generateAfter: Func<Scenario, bool>? [Nullable, Optional],
callerFilePath: string [CallerFilePath, Optional]
) : string [Extension]

## IFeature (interface)

## Scenario (record) : IEquatable<Scenario>
- Method: string { get; }
- Tags: ReadOnlyCollection<string> { get; set; }
- Title: string { get; set; }
- ctor(
Title: string,
Tags: ReadOnlyCollection<string>
)
- IsTagged(
tag: string,
tags: params String[] [ParamArray]
) : bool

Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,14 @@
<OutputType>Library</OutputType>
</PropertyGroup>

<PropertyGroup Condition=" '$(Configuration)' == 'Debug' ">
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
</PropertyGroup>

<PropertyGroup Condition=" '$(Configuration)' == 'Release' ">
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.5.0" />
<PackageReference Include="Verify.Xunit" Version="19.10.0" />
Expand Down

This file was deleted.

0 comments on commit ef67f18

Please sign in to comment.