Skip to content
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
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<TargetFramework>net7.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<DebugType>Full</DebugType>
<DebugType>None</DebugType>
<IsPackable>false</IsPackable>
<IsTestProject>true</IsTestProject>
</PropertyGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<TargetFramework>net7.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<DebugType>Full</DebugType>
<DebugType>None</DebugType>

<IsPackable>false</IsPackable>
</PropertyGroup>
Expand Down
1 change: 1 addition & 0 deletions Shared.IntegrationTesting.UnitTests/GlobalUsings.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
global using Xunit;
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<DebugType>None</DebugType>
<IsPackable>false</IsPackable>
<IsTestProject>true</IsTestProject>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.6.0" />
<PackageReference Include="xunit" Version="2.4.2" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.5">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="coverlet.collector" Version="3.2.0">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\Shared.IntegrationTesting\Shared.IntegrationTesting.csproj" />
</ItemGroup>

</Project>
118 changes: 118 additions & 0 deletions Shared.IntegrationTesting.UnitTests/UnitTest1.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
namespace Shared.IntegrationTesting.UnitTests
{
using Shouldly;
using TechTalk.SpecFlow;

public class SpecflowTableHelperTests
{
[Theory]
[InlineData("Field1", "true", true)]
[InlineData("Field1", "false", false)]
public void SpecflowTableHelper_GetBooleanValue_ExpectedValueIsReturned(String header, String value, Boolean expectedValue)
{
List<String> headers = new List<String>();
headers.Add(header);
Table table = new Table(headers.ToArray());
table.AddRow(value);
Boolean actual = SpecflowTableHelper.GetBooleanValue(table.Rows.First(), header);
actual.ShouldBe(expectedValue);
}

[Theory]
[MemberData(nameof(GetUserChoiceTestData))]
public void SpecflowTableHelper_GetDateForDateString_ExpectedValueIsReturned(String value, DateTime expectedDate)
{

DateTime today = new DateTime(2023, 11, 27);
DateTime actual = SpecflowTableHelper.GetDateForDateString(value, today);
actual.ShouldBe(expectedDate);
}

public static IEnumerable<object[]> GetUserChoiceTestData()
{
yield return new object[] { "TODAY", new DateTime(2023, 11, 27) };
yield return new object[] { "YESTERDAY", new DateTime(2023, 11, 26) };
yield return new object[] { "LASTWEEK", new DateTime(2023, 11, 20) };
yield return new object[] { "LASTMONTH", new DateTime(2023, 10, 27) };
yield return new object[] { "LASTYEAR", new DateTime(2022, 11, 27) };
yield return new object[] { "TOMORROW", new DateTime(2023, 11, 28) };
yield return new object[] { "2023-11-01", new DateTime(2023, 11, 1) };
}

[Theory]
[InlineData("Field1", "-1.00", -1.00)]
[InlineData("Field1", "0.00", 0.00)]
[InlineData("Field1", "1.00", 1.00)]
[InlineData("Field1", "-1.23", -1.23)]
[InlineData("Field1", "1.23", 1.23)]
public void SpecflowTableHelper_GetDecimalValue_ExpectedValueIsReturned(String header, String value, Decimal expectedValue)
{
List<String> headers = new List<String>();
headers.Add(header);
Table table = new Table(headers.ToArray());
table.AddRow(value);
Decimal actual = SpecflowTableHelper.GetDecimalValue(table.Rows.First(), header);
actual.ShouldBe(expectedValue);
}

[Theory]
[InlineData("Field1", "-1", -1.00)]
[InlineData("Field1", "0", 0.00)]
[InlineData("Field1", "1", 1.00)]
public void SpecflowTableHelper_GetIntValue_ExpectedValueIsReturned(String header, String value, Int32 expectedValue)
{
List<String> headers = new List<String>();
headers.Add(header);
Table table = new Table(headers.ToArray());
table.AddRow(value);
Int32 actual = SpecflowTableHelper.GetIntValue(table.Rows.First(), header);
actual.ShouldBe(expectedValue);
}

[Theory]
[InlineData("Field1", "-1", -1.00)]
[InlineData("Field1", "0", 0.00)]
[InlineData("Field1", "1", 1.00)]
public void SpecflowTableHelper_GetShortValue_ExpectedValueIsReturned(String header, String value, Int16 expectedValue)
{
List<String> headers = new List<String>();
headers.Add(header);
Table table = new Table(headers.ToArray());
table.AddRow(value);
Int16 actual = SpecflowTableHelper.GetShortValue(table.Rows.First(), header);
actual.ShouldBe(expectedValue);
}

[Fact]
public void SpecflowTableHelper_GetStringRowValue_ExpectedValueIsReturned()
{
String header = "Field1";
String expectedValue = "TestStringValue";

List<String> headers = new List<String>();
headers.Add(header);
Table table = new Table(headers.ToArray());
table.AddRow(expectedValue);

String? actual = SpecflowTableHelper.GetStringRowValue(table.Rows.First(), header);
actual.ShouldBe(expectedValue);
}

[Theory]
[InlineData("Field1", "Ordinal", StringComparison.Ordinal)]
[InlineData("Field1", "OrdinalIgnoreCase", StringComparison.OrdinalIgnoreCase)]
[InlineData("Field1", "InvariantCulture", StringComparison.InvariantCulture)]
[InlineData("Field1", "InvariantCultureIgnoreCase", StringComparison.InvariantCultureIgnoreCase)]
[InlineData("Field1", "CurrentCulture", StringComparison.CurrentCulture)]
[InlineData("Field1", "CurrentCultureIgnoreCase", StringComparison.CurrentCultureIgnoreCase)]
public void SpecflowTableHelper_GetEnumValue_ExpectedResultIsReturned(String header, String value, StringComparison expectedValue)
{
List<String> headers = new List<String>();
headers.Add(header);
Table table = new Table(headers.ToArray());
table.AddRow(value);
StringComparison actual = SpecflowTableHelper.GetEnumValue<StringComparison>(table.Rows.First(), header);
actual.ShouldBe(expectedValue);
}
}
}
44 changes: 9 additions & 35 deletions Shared.IntegrationTesting/SpecflowTableHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,6 @@ public static class SpecflowTableHelper
{
#region Methods

/// <summary>
/// Gets the boolean value.
/// </summary>
/// <param name="row">The row.</param>
/// <param name="key">The key.</param>
/// <returns></returns>
public static Boolean GetBooleanValue(TableRow row,
String key)
{
Expand All @@ -24,12 +18,6 @@ public static Boolean GetBooleanValue(TableRow row,
return bool.TryParse(field, out Boolean value) && value;
}

/// <summary>
/// Gets the date for date string.
/// </summary>
/// <param name="dateString">The date string.</param>
/// <param name="today">The today.</param>
/// <returns></returns>
public static DateTime GetDateForDateString(String dateString,
DateTime today)
{
Expand All @@ -52,12 +40,6 @@ public static DateTime GetDateForDateString(String dateString,
}
}

/// <summary>
/// Gets the decimal value.
/// </summary>
/// <param name="row">The row.</param>
/// <param name="key">The key.</param>
/// <returns></returns>
public static Decimal GetDecimalValue(TableRow row,
String key)
{
Expand All @@ -66,12 +48,6 @@ public static Decimal GetDecimalValue(TableRow row,
return decimal.TryParse(field, out Decimal value) ? value : -1;
}

/// <summary>
/// Gets the int value.
/// </summary>
/// <param name="row">The row.</param>
/// <param name="key">The key.</param>
/// <returns></returns>
public static Int32 GetIntValue(TableRow row,
String key)
{
Expand All @@ -80,12 +56,6 @@ public static Int32 GetIntValue(TableRow row,
return int.TryParse(field, out Int32 value) ? value : -1;
}

/// <summary>
/// Gets the short value.
/// </summary>
/// <param name="row">The row.</param>
/// <param name="key">The key.</param>
/// <returns></returns>
public static Int16 GetShortValue(TableRow row,
String key)
{
Expand All @@ -99,17 +69,21 @@ public static Int16 GetShortValue(TableRow row,
return -1;
}

/// <summary>
/// Gets the string row value.
/// </summary>
/// <param name="row">The row.</param>
/// <param name="key">The key.</param>
/// <returns></returns>
public static String GetStringRowValue(TableRow row,
String key)
{
return row.TryGetValue(key, out String value) ? value : "";
}

public static T GetEnumValue<T>(TableRow row,
String key) where T : struct
{
String field = SpecflowTableHelper.GetStringRowValue(row, key);

return Enum.Parse<T>(field, true);
}


#endregion
}
Expand Down
9 changes: 8 additions & 1 deletion Shared.sln
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution
.github\workflows\sonarcloud.yml = .github\workflows\sonarcloud.yml
EndProjectSection
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Shared.EventStoreContext.Tests", "Shared.EventStoreContext.Tests\Shared.EventStoreContext.Tests.csproj", "{A7909DC1-12F9-42F8-B665-E8A2C63B1481}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Shared.EventStoreContext.Tests", "Shared.EventStoreContext.Tests\Shared.EventStoreContext.Tests.csproj", "{A7909DC1-12F9-42F8-B665-E8A2C63B1481}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Shared.IntegrationTesting.UnitTests", "Shared.IntegrationTesting.UnitTests\Shared.IntegrationTesting.UnitTests.csproj", "{5E23CBBB-8484-4F7F-81D9-308957783695}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand Down Expand Up @@ -81,6 +83,10 @@ Global
{A7909DC1-12F9-42F8-B665-E8A2C63B1481}.Debug|Any CPU.Build.0 = Debug|Any CPU
{A7909DC1-12F9-42F8-B665-E8A2C63B1481}.Release|Any CPU.ActiveCfg = Release|Any CPU
{A7909DC1-12F9-42F8-B665-E8A2C63B1481}.Release|Any CPU.Build.0 = Release|Any CPU
{5E23CBBB-8484-4F7F-81D9-308957783695}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{5E23CBBB-8484-4F7F-81D9-308957783695}.Debug|Any CPU.Build.0 = Debug|Any CPU
{5E23CBBB-8484-4F7F-81D9-308957783695}.Release|Any CPU.ActiveCfg = Release|Any CPU
{5E23CBBB-8484-4F7F-81D9-308957783695}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand All @@ -96,6 +102,7 @@ Global
{81AF1FCA-837F-4CEA-9E8E-AD38F510930A} = {C641A0E0-A26E-4B16-89E2-DD6E33509C6E}
{77D4A6AC-1DEF-4F6D-88C8-35763A1FD9B5} = {C641A0E0-A26E-4B16-89E2-DD6E33509C6E}
{A7909DC1-12F9-42F8-B665-E8A2C63B1481} = {C641A0E0-A26E-4B16-89E2-DD6E33509C6E}
{5E23CBBB-8484-4F7F-81D9-308957783695} = {C641A0E0-A26E-4B16-89E2-DD6E33509C6E}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {34032CEC-68CD-41EA-8707-D450689AEA46}
Expand Down