Skip to content
This repository has been archived by the owner on Oct 2, 2024. It is now read-only.

Commit

Permalink
Finished unit test coding for #100
Browse files Browse the repository at this point in the history
  • Loading branch information
Aha43 committed Jun 12, 2021
1 parent 63a3870 commit 825b155
Show file tree
Hide file tree
Showing 32 changed files with 243 additions and 77 deletions.
4 changes: 3 additions & 1 deletion src/HitUnitTests/Configurations/ConfSetting.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
namespace HitUnitTests.Configurations
{
public class ConfSetting
public abstract class ConfSetting
{
public string Name { get; set; }

public override string ToString() => $"{GetType().Name}_{Name}";
}
}
6 changes: 6 additions & 0 deletions src/HitUnitTests/Configurations/ConfSetting1.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
namespace HitUnitTests.Configurations
{
public class ConfSetting1 : ConfSetting
{
}
}
6 changes: 6 additions & 0 deletions src/HitUnitTests/Configurations/ConfSetting2.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
namespace HitUnitTests.Configurations
{
public class ConfSetting2 : ConfSetting
{
}
}
6 changes: 6 additions & 0 deletions src/HitUnitTests/Configurations/ConfSetting3.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
namespace HitUnitTests.Configurations
{
public class ConfSetting3 : ConfSetting
{
}
}
1 change: 0 additions & 1 deletion src/HitUnitTests/Configurations/SystemConfiguration1.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using Hit.Infrastructure.Attributes;
using Hit.Infrastructure.User;
using HitUnitTests.Worlds;

namespace HitUnitTests.Configurations
{
Expand Down
1 change: 0 additions & 1 deletion src/HitUnitTests/Configurations/SystemConfiguration2.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using Hit.Infrastructure.Attributes;
using Hit.Infrastructure.User;
using HitUnitTests.Worlds;

namespace HitUnitTests.Configurations
{
Expand Down
1 change: 0 additions & 1 deletion src/HitUnitTests/Configurations/SystemConfiguration3.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using Hit.Infrastructure.Attributes;
using Hit.Infrastructure.User;
using HitUnitTests.Worlds;

namespace HitUnitTests.Configurations
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,21 +1,20 @@
using Hit.Infrastructure.Attributes;
using Hit.Infrastructure.User;
using HitUnitTests.Worlds;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;

namespace HitUnitTests.Configurations
{
[SysCon("system-with-configuration-no-sections-1", JsonPath = "configuration-no-sections-1.json")]
[SysCon("system-with-configuration-no-sections-2", JsonPath = "configuration-no-sections-2.json")]
[SysCon("system-with-configuration-sections-part1", JsonPath = "configuration-sections.json", ConfigurationSections = "Part1")]
[SysCon("system-with-configuration-sections-part2", JsonPath = "configuration-sections.json", ConfigurationSections = "Part2")]
public class SystemConfigurationForTestingReadingOfConfiguration : DefaultSystemConfigurationAdapter<World4>
[SysCon("system-with-configuration-sections-part1", JsonPath = "configuration-sections-1.json", ConfigurationSections = "Part1")]
[SysCon("system-with-configuration-sections-part2", JsonPath = "configuration-sections-1.json", ConfigurationSections = "Part2")]
public class SystemConfigurationForTestingReadingOfConfiguration1 : DefaultSystemConfigurationAdapter<World4>
{
public override IServiceCollection ConfigureServices(IServiceCollection services, IConfiguration configuration, SysCon meta, string currentLayer)
{
var section = configuration.GetSection("ConfSetting");
var confSetting = section.Get<ConfSetting>();
var section = configuration.GetSection("ConfSetting1");
var confSetting = section.Get<ConfSetting1>();
if (confSetting != null)
{
services.AddSingleton(confSetting);
Expand All @@ -26,4 +25,22 @@ public override IServiceCollection ConfigureServices(IServiceCollection services

}

[SysCon("system-with-configuration-sections-multi", JsonPath = "configuration-sections-2.json", ConfigurationSections = "Part1, Part2")]
public class SystemConfigurationForTestingReadingOfConfiguration2 : DefaultSystemConfigurationAdapter<World6>
{
public override IServiceCollection ConfigureServices(IServiceCollection services, IConfiguration configuration, SysCon meta, string currentLayer)
{
var section1 = configuration.GetSection("ConfSetting1");
var confSetting1 = section1.Get<ConfSetting1>();
services.AddSingleton(confSetting1);

var section2 = configuration.GetSection("ConfSetting2");
var confSetting2 = section2.Get<ConfSetting2>();
services.AddSingleton(confSetting2);

return services;
}

}

}
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using Hit.Infrastructure.Attributes;
using Hit.Infrastructure.User;
using HitUnitTests.Worlds;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;

Expand All @@ -9,12 +8,12 @@ namespace HitUnitTests.Configurations
[SysCon("system-with-configuration-user-secret", UserSecrets = true)]
[SysCon("system-with-configuration-user-secret-part1", UserSecrets = true, ConfigurationSections = "Part1")]
[SysCon("system-with-configuration-user-secret-part2", UserSecrets = true, ConfigurationSections = "Part2")]
public class SystemConfigurationForTestingReadingOfConfigurationUserSecrets : DefaultSystemConfigurationAdapter<World5>
public class SystemConfigurationForTestingReadingOfConfigurationUserSecrets1 : DefaultSystemConfigurationAdapter<World5>
{
public override IServiceCollection ConfigureServices(IServiceCollection services, IConfiguration configuration, SysCon meta, string currentLayer)
{
var section = configuration.GetSection("ConfSetting");
var confSetting = section.Get<ConfSetting>();
var section = configuration.GetSection("ConfSetting1");
var confSetting = section.Get<ConfSetting1>();
if (confSetting != null)
{
services.AddSingleton(confSetting);
Expand All @@ -25,4 +24,22 @@ public override IServiceCollection ConfigureServices(IServiceCollection services

}

[SysCon("system-with-configuration-sections-file-and-user", UserSecrets = true, JsonPath = "configuration-sections-2.json", ConfigurationSections = "Part2, Part3")]
public class SystemConfigurationForTestingReadingOfConfigurationUserSecrets2 : DefaultSystemConfigurationAdapter<World7>
{
public override IServiceCollection ConfigureServices(IServiceCollection services, IConfiguration configuration, SysCon meta, string currentLayer)
{
var section2 = configuration.GetSection("ConfSetting2");
var confSetting2 = section2.Get<ConfSetting2>();
services.AddSingleton(confSetting2);

var section3 = configuration.GetSection("ConfSetting3");
var confSetting3 = section3.Get<ConfSetting3>();
services.AddSingleton(confSetting3);

return services;
}

}

}
5 changes: 4 additions & 1 deletion src/HitUnitTests/HitUnitTests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,10 @@
</ItemGroup>

<ItemGroup>
<None Update="configuration-sections.json">
<None Update="configuration-sections-2.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="configuration-sections-1.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="configuration-no-sections-2.json">
Expand Down
61 changes: 56 additions & 5 deletions src/HitUnitTests/TestLogic/TestHierarchies.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
using Hit.Infrastructure.User;
using Hit.Specification.Infrastructure;
using HitUnitTests.Configurations;
using HitUnitTests.Worlds;
using Xunit;

namespace HitUnitTests.TestLogic
Expand Down Expand Up @@ -85,9 +84,9 @@ public class TestLogicImpl3 : UnitAsyncTestLogic<World3>
[UseAs("AppSettingTest4", Options = "name = configuration-sections-part-2", UnitTest = "!")]
public class TestLogicImpl4 : TestLogicBase<World4>
{
private readonly ConfSetting _setting;
private readonly ConfSetting1 _setting;

public TestLogicImpl4(ConfSetting setting) => _setting = setting;
public TestLogicImpl4(ConfSetting1 setting) => _setting = setting;

public override void Test(ITestContext<World4> context)
{
Expand All @@ -103,9 +102,9 @@ public override void Test(ITestContext<World4> context)
[UseAs("AppSettingUserSecretTest3", Options = "name = configuration-user-secret-sections-part-2", UnitTest = "!")]
public class TestLogicImpl5 : TestLogicBase<World5>
{
private readonly ConfSetting _setting;
private readonly ConfSetting1 _setting;

public TestLogicImpl5(ConfSetting setting) => _setting = setting;
public TestLogicImpl5(ConfSetting1 setting) => _setting = setting;

public override void Test(ITestContext<World5> context)
{
Expand All @@ -116,4 +115,56 @@ public override void Test(ITestContext<World5> context)

}

[UseAs("AppSettingTest1", Options = "name1 = config1, name2 = config2", UnitTest = "!")]
public class TestLogicImpl6 : TestLogicBase<World6>
{
private readonly ConfSetting1 _setting1;
private readonly ConfSetting2 _setting2;

public TestLogicImpl6(ConfSetting1 setting1,
ConfSetting2 setting2)
{
_setting1 = setting1;
_setting2 = setting2;
}

public override void Test(ITestContext<World6> context)
{
Assert.NotNull(_setting1);
Assert.NotNull(_setting2);

var expected1 = context.Options.Get("name1");
Assert.Equal(expected1, _setting1.Name);
var expected2 = context.Options.Get("name2");
Assert.Equal(expected2, _setting2.Name);
}

}

[UseAs("AppSettingTest1", Options = "name2 = config2, name3 = config3", UnitTest = "!")]
public class TestLogicImpl7 : TestLogicBase<World7>
{
private readonly ConfSetting2 _setting2;
private readonly ConfSetting3 _setting3;

public TestLogicImpl7(ConfSetting2 setting2,
ConfSetting3 setting3)
{
_setting2 = setting2;
_setting3 = setting3;
}

public override void Test(ITestContext<World7> context)
{
Assert.NotNull(_setting2);
Assert.NotNull(_setting3);

var expected2 = context.Options.Get("name2");
Assert.Equal(expected2, _setting2.Name);
var expected3 = context.Options.Get("name3");
Assert.Equal(expected3, _setting3.Name);
}

}

}
1 change: 0 additions & 1 deletion src/HitUnitTests/UnitTest1_runningUnitTests.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using Hit.Infrastructure;
using Hit.Specification.Infrastructure;
using HitUnitTests.Assertions;
using HitUnitTests.Worlds;
using System.Threading.Tasks;
using Xunit;

Expand Down
1 change: 0 additions & 1 deletion src/HitUnitTests/UnitTest2_runningSyncUnitTests.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using Hit.Infrastructure;
using Hit.Specification.Infrastructure;
using HitUnitTests.Assertions;
using HitUnitTests.Worlds;
using System.Threading.Tasks;
using Xunit;

Expand Down
1 change: 0 additions & 1 deletion src/HitUnitTests/UnitTest3_runningUnitTests.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using Hit.Infrastructure;
using Hit.Specification.Infrastructure;
using HitUnitTests.Assertions;
using HitUnitTests.Worlds;
using System.Threading.Tasks;
using Xunit;

Expand Down
1 change: 0 additions & 1 deletion src/HitUnitTests/UnitTests1_space.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using Hit.Infrastructure;
using Hit.Specification.Infrastructure;
using HitUnitTests.Worlds;
using System.Linq;
using Xunit;

Expand Down
1 change: 0 additions & 1 deletion src/HitUnitTests/UnitTests2_space.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using Hit.Infrastructure;
using Hit.Specification.Infrastructure;
using HitUnitTests.Worlds;
using System.Linq;
using Xunit;

Expand Down
1 change: 0 additions & 1 deletion src/HitUnitTests/UnitTests3_space.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using Hit.Infrastructure;
using Hit.Specification.Infrastructure;
using HitUnitTests.Worlds;
using System.Linq;
using Xunit;

Expand Down
2 changes: 1 addition & 1 deletion src/HitUnitTests/UnitTests4.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using Hit.Infrastructure;
using Hit.Specification.Infrastructure;
using HitUnitTests.Worlds;
using System.Threading.Tasks;
using Xunit;

Expand All @@ -19,6 +18,7 @@ public async Task UnitTestShouldNotFailAsync(string system, string unitTest)
{
var result = await _unitTestsSpace.RunUnitTestAsync(system, unitTest);
UnitTestsUtil.AssertResult(result, system, string.Empty, unitTest);
UnitTestsUtil.AssertResult(result, system, string.Empty, unitTest);
}
}
}
1 change: 0 additions & 1 deletion src/HitUnitTests/UnitTests5.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using Hit.Infrastructure;
using Hit.Specification.Infrastructure;
using HitUnitTests.Worlds;
using System.Threading.Tasks;
using Xunit;

Expand Down
20 changes: 20 additions & 0 deletions src/HitUnitTests/UnitTests6.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
using Hit.Infrastructure;
using Hit.Specification.Infrastructure;
using System.Threading.Tasks;
using Xunit;

namespace HitUnitTests
{
public class UnitTests6
{
private static readonly IUnitTestsSpace<World6> _unitTestsSpace = new UnitTestsSpace<World6>();

[Theory]
[InlineData("system-with-configuration-sections-multi", "AppSettingTest1")]
public async Task UnitTestShouldNotFailAsync(string system, string unitTest)
{
var result = await _unitTestsSpace.RunUnitTestAsync(system, unitTest);
UnitTestsUtil.AssertResult(result, system, string.Empty, unitTest);
}
}
}
23 changes: 23 additions & 0 deletions src/HitUnitTests/UnitTests7.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
using Hit.Infrastructure;
using Hit.Specification.Infrastructure;
using System.Threading.Tasks;
using Xunit;

namespace HitUnitTests
{
public class UnitTests7
{
private static readonly IUnitTestsSpace<World7> _unitTestsSpace = new UnitTestsSpace<World7>();

[Theory]
[InlineData("system-with-configuration-sections-file-and-user", "AppSettingTest1")]
public async Task UnitTestShouldNotFailAsync(string system, string unitTest)
{
if (UnitTestsUtil.InDevelopment)
{
var result = await _unitTestsSpace.RunUnitTestAsync(system, unitTest);
UnitTestsUtil.AssertResult(result, system, string.Empty, unitTest);
}
}
}
}
Loading

0 comments on commit 825b155

Please sign in to comment.