Skip to content

Commit

Permalink
add tests
Browse files Browse the repository at this point in the history
update the structure of tests and started with the init method
  • Loading branch information
csc530 committed Dec 15, 2023
1 parent db702eb commit b1c83e5
Show file tree
Hide file tree
Showing 6 changed files with 88 additions and 73 deletions.
37 changes: 2 additions & 35 deletions .idea/.idea.resume builder/.idea/dataSources.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

33 changes: 18 additions & 15 deletions TestResumeBuilder/AppTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,26 @@

namespace TestResumeBuilder
{
//todo: find way to pass text to test command app for prompts
public abstract class AppTest
{
internal CommandAppTester TestApp;
//todo: find way to pass text to test command app for prompts
public abstract class AppTest
{
internal CommandAppTester TestApp;

[SetUp]
public virtual void InitializeApp()
{
TestApp = new CommandAppTester();
TestApp.Configure(Program.AppConfiguration);
}
[SetUp]
public virtual void InitializeApp()
{
TestApp = new CommandAppTester();
TestApp.Configure(Program.AppConfiguration);
}


protected CommandAppResult Run(IEnumerable<string> cmdArgs, params string[] args) =>
TestApp.Run(cmdArgs.Concat(args).ToArray());
protected CommandAppResult Run(IEnumerable<string> cmdArgs, params string[] args) =>
TestApp.Run(cmdArgs.Concat(args).ToArray());

protected CommandAppFailure RunAndCatch<T>(IEnumerable<string> cmdArgs, params string[] args)
where T : Exception => TestApp.RunAndCatch<T>(cmdArgs.Concat(args).ToArray());
}
protected CommandAppResult Run(string cmd, params string[] args) =>
Run(args.Prepend(cmd));

protected CommandAppFailure RunAndCatch<T>(IEnumerable<string> cmdArgs, params string[] args)
where T : Exception => TestApp.RunAndCatch<T>(cmdArgs.Concat(args).ToArray());
}
}
17 changes: 17 additions & 0 deletions TestResumeBuilder/TestData.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Bogus;

namespace TestResumeBuilder;
internal class TestData
{
public static IEnumerable<string[]> RandomArgs() {
yield return new Faker().Random.WordsArray(1, 20).ToArray();
yield return new Faker().Random.WordsArray(1, 20).ToArray();
yield return new Faker().Random.WordsArray(1, 20).ToArray();
}
public static string r => "";
}
48 changes: 29 additions & 19 deletions TestResumeBuilder/TestResumeBuilder.csproj
Original file line number Diff line number Diff line change
@@ -1,25 +1,35 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">

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

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

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.7.1" />
<PackageReference Include="NUnit" Version="3.13.3" />
<PackageReference Include="NUnit3TestAdapter" Version="4.4.2" />
<PackageReference Include="NUnit.Analyzers" Version="3.6.1" />
<PackageReference Include="coverlet.collector" Version="3.2.0" />
<PackageReference Include="Spectre.Console.Testing" Version="0.47.0" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="AutoBogus" Version="2.13.1" />
<PackageReference Include="Bogus" Version="35.0.1" />
<PackageReference Include="CountryData" Version="4.3.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.8.0" />
<PackageReference Include="NaughtyStrings.Bogus" Version="2.4.1" />
<PackageReference Include="NUnit" Version="4.0.1" />
<PackageReference Include="NUnit3TestAdapter" Version="4.5.0" />
<PackageReference Include="NUnit.Analyzers" Version="3.10.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="coverlet.collector" Version="6.0.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Spectre.Console.Testing" Version="0.48.0" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\resume builder\resume builder.csproj" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\resume builder\resume builder.csproj" />
</ItemGroup>

</Project>
20 changes: 20 additions & 0 deletions TestResumeBuilder/commands/InitTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
namespace TestResumeBuilder.commands;

[TestFixture]
public class InitTest : AppTest
{
[Test]
public void Init_WithNoArgs_ShouldReturnSuccess()
{
var result = TestApp.Run("init");
Assert.That(result.ExitCode, Is.EqualTo(0));
}

[Test]
[TestCaseSource(typeof(TestData), nameof(TestData.RandomArgs))]
public void Init_WithArgs_ShouldReturnSuccess(string[] args)
{
var result = Run("init", args);
Assert.That(result.ExitCode, Is.EqualTo(0));
}
}
6 changes: 2 additions & 4 deletions resume builder/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,9 @@ private static int Main(string[] args)
//todo: don't like that parent options and arguments are positional; spectre problem
public static void AppConfiguration(IConfigurator config)
{
if(config == null)
throw new ArgumentNullException(nameof(config));

#if DEBUG
config.PropagateExceptions();
#if DEBUG
config.PropagateExceptions();
config.ValidateExamples();
#endif

Expand Down

0 comments on commit b1c83e5

Please sign in to comment.