Skip to content

Commit

Permalink
feat(testing): add unit test to project
Browse files Browse the repository at this point in the history
  • Loading branch information
JoeGLauria committed Dec 5, 2024
1 parent 312610e commit c3f0622
Show file tree
Hide file tree
Showing 4 changed files with 75 additions and 0 deletions.
6 changes: 6 additions & 0 deletions DVSRegister.sln
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DVSRegister.UnitTests", "DV
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DVSRegister.CommonUtility", "DVSRegister.CommonUtility\DVSRegister.CommonUtility.csproj", "{ABDD8283-1B81-4D5C-898E-59E338976411}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Unit-testing", "Unit-testing\Unit-testing.csproj", "{08523FED-40BC-4BA7-88B2-B62AB9CEDEDF}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand All @@ -39,6 +41,10 @@ Global
{ABDD8283-1B81-4D5C-898E-59E338976411}.Debug|Any CPU.Build.0 = Debug|Any CPU
{ABDD8283-1B81-4D5C-898E-59E338976411}.Release|Any CPU.ActiveCfg = Release|Any CPU
{ABDD8283-1B81-4D5C-898E-59E338976411}.Release|Any CPU.Build.0 = Release|Any CPU
{08523FED-40BC-4BA7-88B2-B62AB9CEDEDF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{08523FED-40BC-4BA7-88B2-B62AB9CEDEDF}.Debug|Any CPU.Build.0 = Debug|Any CPU
{08523FED-40BC-4BA7-88B2-B62AB9CEDEDF}.Release|Any CPU.ActiveCfg = Release|Any CPU
{08523FED-40BC-4BA7-88B2-B62AB9CEDEDF}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
2 changes: 2 additions & 0 deletions DVSRegister/DVSRegister.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="8.0.7" />
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="8.0.4" />
<PackageReference Include="libphonenumber-csharp" Version="8.13.40" />
<PackageReference Include="NUnit" Version="4.2.2" />
<PackageReference Include="NUnit3TestAdapter" Version="4.6.0" />
<PackageReference Include="Sentry.AspNetCore" Version="4.12.0" />
<PackageReference Include="System.Formats.Asn1" Version="8.0.1" />
</ItemGroup>
Expand Down
42 changes: 42 additions & 0 deletions Unit-testing/CompanyNameValidationTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
using System.Text.RegularExpressions;

namespace Unit_testing
{
public class Tests
{
private string _pattern;

[SetUp]
public void Setup()
{
_pattern = @"^[A-Za-zÀ-ž&@£$€¥(){}\[\]<>!«»“”'‘’?""/*=#%+0-9.,:;\\/-]+$";
}

[Test]
[TestCase("ValidName123", true)]
[TestCase("NameWithAccentsÀÁÂ", true)]
[TestCase("NameWithSymbols&@£$€¥", true)]
[TestCase("NameWithPunctuation.,:;-", true)]
[TestCase("NameWithBrackets()", true)]
[TestCase("NameWithBrackets[]", true)]
[TestCase("NameWithBrackets{}", true)]
[TestCase("NameWithBrackets<>", true)]
[TestCase("NameWithExclamation!", true)]
[TestCase("NameWithGuillemet«»", true)]
[TestCase("NameWithInvertedComma“”", true)]
[TestCase("NameWithApostrophe‘’", true)]
[TestCase("NameWithQuestionMark?", true)]
[TestCase("NameWithSolidus\\/\\", true)]
[TestCase("NameWithSigns*=", true)]
[TestCase("NameWithSymbols#%+", true)]
public void TestAcceptedCharacters(string input, bool expectedIsValid)
{
var isValid = Regex.IsMatch(input, _pattern);
Assert.AreEqual(expectedIsValid, isValid);
}
}
}




25 changes: 25 additions & 0 deletions Unit-testing/Unit-testing.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<Project Sdk="Microsoft.NET.Sdk">

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

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

<ItemGroup>
<PackageReference Include="coverlet.collector" Version="6.0.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.8.0" />
<PackageReference Include="NUnit" Version="3.14.0" />
<PackageReference Include="NUnit.Analyzers" Version="3.9.0" />
<PackageReference Include="NUnit3TestAdapter" Version="4.5.0" />
</ItemGroup>

<ItemGroup>
<Using Include="NUnit.Framework" />
</ItemGroup>

</Project>

0 comments on commit c3f0622

Please sign in to comment.