Skip to content

Commit

Permalink
Add unit tests for StringVisitor.
Browse files Browse the repository at this point in the history
  • Loading branch information
eminencegrs committed Jan 31, 2024
1 parent 538e777 commit d5f88cd
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<RootNamespace>DesignPatterns.Visitor.UnitTests</RootNamespace>
<IsPackable>false</IsPackable>
<IsTestProject>true</IsTestProject>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="AutoFixture" Version="4.18.1" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.8.0" />
<PackageReference Include="Moq" Version="4.20.70" />
<PackageReference Include="Shouldly" Version="4.2.1" />
<PackageReference Include="xunit" Version="2.6.5" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.5.6">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="coverlet.collector" Version="6.0.0">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="coverlet.msbuild" Version="6.0.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\DesignPatterns.Visitor\DesignPatterns.Visitor.csproj" />
</ItemGroup>

</Project>
27 changes: 27 additions & 0 deletions Behavioral/DesignPatterns.Visitor.UnitTests/StringVisitor.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
using DesignPatterns.Visitor.Models;
using Shouldly;
using Xunit;

namespace DesignPatterns.Visitor.UnitTests;

public class StringVisitorTests
{
[Theory]
[InlineData("256KB", 256, typeof(SizeInKiloBytes))]
[InlineData("512 KB", 512, typeof(SizeInKiloBytes))]
[InlineData("256MB", 256, typeof(SizeInMegaBytes))]
[InlineData("512 MB", 512, typeof(SizeInMegaBytes))]
[InlineData("256GB", 256, typeof(SizeInGigaBytes))]
[InlineData("512 GB", 512, typeof(SizeInGigaBytes))]
[InlineData("256TB", 256, typeof(SizeInTeraBytes))]
[InlineData("512 TB", 512, typeof(SizeInTeraBytes))]
[InlineData("256PB", 256, typeof(SizeInPetaBytes))]
[InlineData("512 PB", 512, typeof(SizeInPetaBytes))]
public void GivenStringValue_WhenCallVisit_ThenResultAsExpected(string inputValue, long expectedValue, Type expectedType)
{
var stringVisitor = new StringVisitor();
var result = stringVisitor.Visit(inputValue);
result.ShouldBeOfType(expectedType);
result.Value.ShouldBe(expectedValue);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,4 @@
<RootNamespace>DesignPatterns.Visitor</RootNamespace>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="AutoFixture" Version="4.18.1" />
</ItemGroup>

</Project>
</Project>
7 changes: 7 additions & 0 deletions DesignPatterns.sln
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DesignPatterns.Visitor", "B
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Behavioral", "Behavioral", "{7FF0E83F-EBEB-4103-BCD1-2F100E82FCD1}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DesignPatterns.Visitor.UnitTests", "Behavioral\DesignPatterns.Visitor.UnitTests\DesignPatterns.Visitor.UnitTests.csproj", "{02AA0F74-2EFE-4804-8938-A92542860F74}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand All @@ -14,8 +16,13 @@ Global
{DCE06EB6-BAB5-4573-AF67-128DBCCDB90C}.Debug|Any CPU.Build.0 = Debug|Any CPU
{DCE06EB6-BAB5-4573-AF67-128DBCCDB90C}.Release|Any CPU.ActiveCfg = Release|Any CPU
{DCE06EB6-BAB5-4573-AF67-128DBCCDB90C}.Release|Any CPU.Build.0 = Release|Any CPU
{02AA0F74-2EFE-4804-8938-A92542860F74}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{02AA0F74-2EFE-4804-8938-A92542860F74}.Debug|Any CPU.Build.0 = Debug|Any CPU
{02AA0F74-2EFE-4804-8938-A92542860F74}.Release|Any CPU.ActiveCfg = Release|Any CPU
{02AA0F74-2EFE-4804-8938-A92542860F74}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{DCE06EB6-BAB5-4573-AF67-128DBCCDB90C} = {7FF0E83F-EBEB-4103-BCD1-2F100E82FCD1}
{02AA0F74-2EFE-4804-8938-A92542860F74} = {7FF0E83F-EBEB-4103-BCD1-2F100E82FCD1}
EndGlobalSection
EndGlobal

0 comments on commit d5f88cd

Please sign in to comment.