Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: adding the minimal testing infrastructure #4

Merged
merged 1 commit into from
Jul 20, 2024
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
8 changes: 7 additions & 1 deletion Backend.sln
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Common.Validators", "Common
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Common.Commands", "Common.Commands\Common.Commands.csproj", "{57A082E9-0442-4566-ADC5-D6EF3B10D396}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DocumentDomain.Spec", "DocumentDomain.Spec\DocumentDomain.Spec.csproj", "{5052A579-CCC9-447B-9541-E38FB5CD6D32}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand All @@ -36,5 +38,9 @@ Global
{57A082E9-0442-4566-ADC5-D6EF3B10D396}.Debug|Any CPU.Build.0 = Debug|Any CPU
{57A082E9-0442-4566-ADC5-D6EF3B10D396}.Release|Any CPU.ActiveCfg = Release|Any CPU
{57A082E9-0442-4566-ADC5-D6EF3B10D396}.Release|Any CPU.Build.0 = Release|Any CPU
{5052A579-CCC9-447B-9541-E38FB5CD6D32}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{5052A579-CCC9-447B-9541-E38FB5CD6D32}.Debug|Any CPU.Build.0 = Debug|Any CPU
{5052A579-CCC9-447B-9541-E38FB5CD6D32}.Release|Any CPU.ActiveCfg = Release|Any CPU
{5052A579-CCC9-447B-9541-E38FB5CD6D32}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
EndGlobal
EndGlobal
14 changes: 7 additions & 7 deletions Backend.sln.DotSettings
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,21 @@
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=SuggestVarOrType_005FBuiltInTypes/@EntryIndexedValue">WARNING</s:String>
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=SuggestVarOrType_005FElsewhere/@EntryIndexedValue">WARNING</s:String>
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=SuggestVarOrType_005FSimpleTypes/@EntryIndexedValue">WARNING</s:String>
<s:String x:Key="/Default/CodeStyle/CodeCleanup/Profiles/=Acsanyi/@EntryIndexedValue">&lt;?xml version="1.0" encoding="utf-16"?&gt;&lt;Profile name="Acsanyi"&gt;&lt;GherkinReformatCode&gt;True&lt;/GherkinReformatCode&gt;&lt;XAMLCollapseEmptyTags&gt;False&lt;/XAMLCollapseEmptyTags&gt;&lt;HtmlReformatCode&gt;True&lt;/HtmlReformatCode&gt;&lt;CSReformatCode&gt;True&lt;/CSReformatCode&gt;&lt;CSharpFormatDocComments&gt;True&lt;/CSharpFormatDocComments&gt;&lt;CSOptimizeUsings&gt;&lt;OptimizeUsings&gt;True&lt;/OptimizeUsings&gt;&lt;EmbraceInRegion&gt;True&lt;/EmbraceInRegion&gt;&lt;/CSOptimizeUsings&gt;&lt;CSShortenReferences&gt;True&lt;/CSShortenReferences&gt;&lt;AspOptimizeRegisterDirectives&gt;True&lt;/AspOptimizeRegisterDirectives&gt;&lt;CSReorderTypeMembers&gt;True&lt;/CSReorderTypeMembers&gt;&lt;IDEA_SETTINGS&gt;&amp;lt;profile version="1.0"&amp;gt;
<s:String x:Key="/Default/CodeStyle/CodeCleanup/Profiles/=Acsanyi/@EntryIndexedValue">&lt;?xml version="1.0" encoding="utf-16"?&gt;&lt;Profile name="Acsanyi"&gt;&lt;GherkinReformatCode&gt;True&lt;/GherkinReformatCode&gt;&lt;XAMLCollapseEmptyTags&gt;False&lt;/XAMLCollapseEmptyTags&gt;&lt;HtmlReformatCode&gt;True&lt;/HtmlReformatCode&gt;&lt;CSReformatCode&gt;True&lt;/CSReformatCode&gt;&lt;CSharpFormatDocComments&gt;True&lt;/CSharpFormatDocComments&gt;&lt;CSOptimizeUsings&gt;&lt;OptimizeUsings&gt;True&lt;/OptimizeUsings&gt;&lt;/CSOptimizeUsings&gt;&lt;CSShortenReferences&gt;True&lt;/CSShortenReferences&gt;&lt;AspOptimizeRegisterDirectives&gt;True&lt;/AspOptimizeRegisterDirectives&gt;&lt;CSReorderTypeMembers&gt;True&lt;/CSReorderTypeMembers&gt;&lt;IDEA_SETTINGS&gt;&amp;lt;profile version="1.0"&amp;gt;
&amp;lt;option name="myName" value="Acsanyi" /&amp;gt;
&amp;lt;inspection_tool class="WrongPropertyKeyValueDelimiter" enabled="false" level="WEAK WARNING" enabled_by_default="false" /&amp;gt;
&amp;lt;/profile&amp;gt;&lt;/IDEA_SETTINGS&gt;&lt;RIDER_SETTINGS&gt;&amp;lt;profile&amp;gt;
&amp;lt;Language id="CSS"&amp;gt;
&amp;lt;Rearrange&amp;gt;true&amp;lt;/Rearrange&amp;gt;
&amp;lt;Reformat&amp;gt;true&amp;lt;/Reformat&amp;gt;
&amp;lt;Rearrange&amp;gt;true&amp;lt;/Rearrange&amp;gt;
&amp;lt;/Language&amp;gt;
&amp;lt;Language id="EditorConfig"&amp;gt;
&amp;lt;Reformat&amp;gt;true&amp;lt;/Reformat&amp;gt;
&amp;lt;/Language&amp;gt;
&amp;lt;Language id="GraphQL"&amp;gt;
&amp;lt;Reformat&amp;gt;true&amp;lt;/Reformat&amp;gt;
&amp;lt;/Language&amp;gt;
&amp;lt;Language id="HTML"&amp;gt;
&amp;lt;Rearrange&amp;gt;true&amp;lt;/Rearrange&amp;gt;
&amp;lt;OptimizeImports&amp;gt;true&amp;lt;/OptimizeImports&amp;gt;
&amp;lt;Reformat&amp;gt;true&amp;lt;/Reformat&amp;gt;
&amp;lt;Rearrange&amp;gt;true&amp;lt;/Rearrange&amp;gt;
&amp;lt;/Language&amp;gt;
&amp;lt;Language id="Handlebars"&amp;gt;
&amp;lt;Reformat&amp;gt;true&amp;lt;/Reformat&amp;gt;
Expand All @@ -46,9 +43,9 @@
&amp;lt;Reformat&amp;gt;true&amp;lt;/Reformat&amp;gt;
&amp;lt;/Language&amp;gt;
&amp;lt;Language id="XML"&amp;gt;
&amp;lt;Rearrange&amp;gt;true&amp;lt;/Rearrange&amp;gt;
&amp;lt;OptimizeImports&amp;gt;true&amp;lt;/OptimizeImports&amp;gt;
&amp;lt;Reformat&amp;gt;true&amp;lt;/Reformat&amp;gt;
&amp;lt;Rearrange&amp;gt;true&amp;lt;/Rearrange&amp;gt;
&amp;lt;/Language&amp;gt;
&amp;lt;Language id="liquid"&amp;gt;
&amp;lt;Reformat&amp;gt;true&amp;lt;/Reformat&amp;gt;
Expand All @@ -58,6 +55,9 @@
&amp;lt;/Language&amp;gt;
&amp;lt;/profile&amp;gt;&lt;/RIDER_SETTINGS&gt;&lt;/Profile&gt;</s:String>
<s:Int64 x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/MAX_ATTRIBUTE_LENGTH_FOR_SAME_LINE/@EntryValue">1</s:Int64>
<s:Boolean x:Key="/Default/CodeStyle/CSharpUsing/AddImportsToDeepestScope/@EntryValue">True</s:Boolean>
<s:Boolean x:Key="/Default/CodeStyle/CSharpUsing/AllowAlias/@EntryValue">False</s:Boolean>
<s:Boolean x:Key="/Default/CodeStyle/CSharpUsing/CanUseGlobalAlias/@EntryValue">False</s:Boolean>
<s:String x:Key="/Default/CodeStyle/CSharpVarKeywordUsage/ForBuiltInTypes/@EntryValue">UseExplicitType</s:String>
<s:String x:Key="/Default/CodeStyle/CSharpVarKeywordUsage/ForOtherTypes/@EntryValue">UseExplicitType</s:String>
<s:String x:Key="/Default/CodeStyle/CSharpVarKeywordUsage/ForSimpleTypes/@EntryValue">UseExplicitType</s:String>
Expand Down
4 changes: 2 additions & 2 deletions Common.Commands/Exceptions/InvalidArgumentCommandException.cs
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
using System.Runtime.Serialization;

namespace Common.Commands.Exceptions;

using System.Runtime.Serialization;

public class InvalidArgumentCommandException : Exception
{
public InvalidArgumentCommandException()
{
}

protected InvalidArgumentCommandException(SerializationInfo info, StreamingContext context) : base(info, context)

Check warning on line 11 in Common.Commands/Exceptions/InvalidArgumentCommandException.cs

View workflow job for this annotation

GitHub Actions / EG.Backend

'Exception.Exception(SerializationInfo, StreamingContext)' is obsolete: 'This API supports obsolete formatter-based serialization. It should not be called or extended by application code.' (https://aka.ms/dotnet-warnings/SYSLIB0051)
{
}

Expand Down
4 changes: 2 additions & 2 deletions Common.Commands/Exceptions/NoSuchItemCommandException.cs
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
#region

using System.Runtime.Serialization;

#endregion

namespace Common.Commands.Exceptions;

using System.Runtime.Serialization;

public class NoSuchItemCommandException : Exception
{
public NoSuchItemCommandException()
{
}

protected NoSuchItemCommandException(SerializationInfo info, StreamingContext context) : base(info, context)

Check warning on line 15 in Common.Commands/Exceptions/NoSuchItemCommandException.cs

View workflow job for this annotation

GitHub Actions / EG.Backend

'Exception.Exception(SerializationInfo, StreamingContext)' is obsolete: 'This API supports obsolete formatter-based serialization. It should not be called or extended by application code.' (https://aka.ms/dotnet-warnings/SYSLIB0051)
{
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
using System.Runtime.Serialization;

namespace Common.Commands.Exceptions;

using System.Runtime.Serialization;

public class OperationCancelledCommandException : Exception
{
public OperationCancelledCommandException()
{
}

protected OperationCancelledCommandException(SerializationInfo info, StreamingContext context) : base(info, context)

Check warning on line 11 in Common.Commands/Exceptions/OperationCancelledCommandException.cs

View workflow job for this annotation

GitHub Actions / EG.Backend

'Exception.Exception(SerializationInfo, StreamingContext)' is obsolete: 'This API supports obsolete formatter-based serialization. It should not be called or extended by application code.' (https://aka.ms/dotnet-warnings/SYSLIB0051)
{
}

Expand Down
4 changes: 2 additions & 2 deletions Common.Commands/Exceptions/UnknownErrorCommandException.cs
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
using System.Runtime.Serialization;

namespace Common.Commands.Exceptions;

using System.Runtime.Serialization;

public class UnknownErrorCommandException : Exception
{
public UnknownErrorCommandException()
{
}

protected UnknownErrorCommandException(SerializationInfo info, StreamingContext context) : base(info, context)

Check warning on line 11 in Common.Commands/Exceptions/UnknownErrorCommandException.cs

View workflow job for this annotation

GitHub Actions / EG.Backend

'Exception.Exception(SerializationInfo, StreamingContext)' is obsolete: 'This API supports obsolete formatter-based serialization. It should not be called or extended by application code.' (https://aka.ms/dotnet-warnings/SYSLIB0051)
{
}

Expand Down
4 changes: 2 additions & 2 deletions Common.Sagas/SagaException.cs
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
using System.Runtime.Serialization;

namespace Common.Sagas;

using System.Runtime.Serialization;

public class SagaException : Exception
{
public SagaException()
{
}

protected SagaException(SerializationInfo info, StreamingContext context) : base(info, context)

Check warning on line 11 in Common.Sagas/SagaException.cs

View workflow job for this annotation

GitHub Actions / EG.Backend

'Exception.Exception(SerializationInfo, StreamingContext)' is obsolete: 'This API supports obsolete formatter-based serialization. It should not be called or extended by application code.' (https://aka.ms/dotnet-warnings/SYSLIB0051)
{
}

Expand Down
38 changes: 38 additions & 0 deletions DocumentDomain.Spec/DocumentDomain.Spec.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>

<IsPackable>false</IsPackable>
<IsTestProject>true</IsTestProject>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="FluentAssertions" Version="6.12.0"/>
<PackageReference Include="FluentAssertions.Analyzers" Version="0.32.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="8.0.7"/>
<PackageReference Include="Microsoft.EntityFrameworkCore.Analyzers" Version="8.0.7"/>
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="8.0.7"/>
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite.Core" Version="8.0.7"/>
<PackageReference Include="Microsoft.Extensions.Logging" Version="8.0.0"/>
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="8.0.1"/>
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="8.0.0"/>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.8.0"/>
<PackageReference Include="xunit" Version="2.5.3"/>
<PackageReference Include="xunit.runner.visualstudio" Version="2.5.3"/>
</ItemGroup>

<ItemGroup>
<Using Include="Xunit"/>
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\DocumentDomain\DocumentDomain.csproj"/>
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
namespace DocumentDomain.Spec.Operations.Sagas;

using System.Collections;
using Contracts;

public class AddDocumentSagaInputInvalidData : IEnumerable<object[]>
{
public IEnumerator<object[]> GetEnumerator()
{
yield return new object[]
{
new DocumentInput { Id = 1, Name = "asd", Description = "asd" }
};
yield return new object[]
{
new DocumentInput { Id = 0, Name = null, Description = "asd" }
};
yield return new object[]
{
new DocumentInput { Id = 0, Name = string.Empty, Description = "asd" }
};
yield return new object[]
{
new DocumentInput { Id = 0, Name = " ", Description = "asd" }
};
yield return new object[]
{
new DocumentInput { Id = 0, Name = "as ", Description = "asd" }
};
yield return new object[]
{
new DocumentInput { Id = 0, Name = "asd", Description = null }
};
yield return new object[]
{
new DocumentInput { Id = 0, Name = "asd", Description = string.Empty }
};
yield return new object[]
{
new DocumentInput { Id = 0, Name = "asd", Description = " " }
};
yield return new object[]
{
new DocumentInput { Id = 0, Name = "asd", Description = "as " }
};
}

IEnumerator IEnumerable.GetEnumerator()
{
return GetEnumerator();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
namespace DocumentDomain.Spec.Operations.Sagas;

using System.Collections;
using Contracts;

public class AddDocumentSagaInputValidData : IEnumerable<object[]>
{
public IEnumerator<object[]> GetEnumerator()
{
yield return new object[]
{
new DocumentInput { Id = 0, Name = "asd", Description = "asd" }
};
}

IEnumerator IEnumerable.GetEnumerator()
{
return GetEnumerator();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
namespace DocumentDomain.Spec.Operations.Sagas;

using Contracts;
using FluentAssertions;
using FluentValidation.Results;
using Infrastructure.Validators;

public class AddDocumentSagaInputValidatorShould
{
private readonly AddDocumentSagaInputValidator AddDocumentSagaInputValidator;

public AddDocumentSagaInputValidatorShould()
{
AddDocumentSagaInputValidator = new AddDocumentSagaInputValidator();
}

[Theory]
[ClassData(typeof(AddDocumentSagaInputInvalidData))]
public void IndicateTheInputIsInvalid(DocumentInput documentInput)
{
ValidationResult? res = AddDocumentSagaInputValidator.Validate(documentInput);
res.IsValid.Should().BeFalse();
}

[Theory]
[ClassData(typeof(AddDocumentSagaInputValidData))]
public void IndicateTheInputIsValid(DocumentInput documentInput)
{
ValidationResult? res = AddDocumentSagaInputValidator.Validate(documentInput);
res.IsValid.Should().BeTrue();
}
}
41 changes: 41 additions & 0 deletions DocumentDomain.Spec/Operations/Sagas/AddDocumentSagaShould.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
namespace DocumentDomain.Spec.Operations.Sagas;

using Common.Sagas;
using Contracts;
using DocumentDomain.Operations.Sagas;
using FluentAssertions;

public class AddDocumentSagaShould : SagaBaseTest
{
[Fact]
public async Task AddDocument()
{
DocumentInput input = new DocumentInput
{
Name = "name",
Description = "description"
};
AddDocumentSagaContext ctx = new AddDocumentSagaContext
{
Payload = input
};
DocumentResult result = await AddDocumentSaga.ExecuteAsync(ctx);

result.Should().NotBeNull();
result.Id.Should().BeGreaterThanOrEqualTo(1);
result.Name.Should().Be(input.Name);
result.Description.Should().Be(input.Description);
}

[Theory]
[ClassData(typeof(AddDocumentSagaInputInvalidData))]
public async Task ThrowWhenInputIsInvalid(DocumentInput documentInput)
{
AddDocumentSagaContext ctx = new AddDocumentSagaContext
{
Payload = documentInput
};
Func<Task> task = async () => { await AddDocumentSaga.ExecuteAsync(ctx); };
await task.Should().ThrowExactlyAsync<SagaException>();
}
}
Loading
Loading