Skip to content

Commit

Permalink
Created test library to start adding common test helpers to. Refactor…
Browse files Browse the repository at this point in the history
…ed how user secrets work.
  • Loading branch information
khanjal committed Nov 24, 2024
1 parent 02b4332 commit 2674429
Show file tree
Hide file tree
Showing 27 changed files with 66 additions and 73 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/dotnet.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ jobs:
run: dotnet build --no-restore
- name: Test
env:
gig_spreadsheet_id: ${{ secrets.GIG_SPREADSHEET_ID }}
stock_spreadsheet_id: ${{ secrets.STOCK_SPREADSHEET_ID }}
spreadsheets:gig: ${{ secrets.GIG_SPREADSHEET_ID }}
spreadsheets:stock: ${{ secrets.STOCK_SPREADSHEET_ID }}
google_credentials:type: ${{ secrets.GOOGLE_CREDENTIALS_TYPE }}
google_credentials:private_key_id: ${{ secrets.GOOGLE_CREDENTIALS_PRIVATE_KEY_ID }}
google_credentials:private_key: ${{ secrets.GOOGLE_CREDENTIALS_PRIVATE_KEY }}
Expand Down
4 changes: 2 additions & 2 deletions RLE.Gig.Tests/Data/GoogleDataFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@
using RLE.Core.Extensions;
using RLE.Core.Services;
using RLE.Gig.Enums;
using RLE.Gig.Tests.Data.Helpers;
using RLE.Test.Helpers;

namespace RLE.Gig.Tests.Data;

public class GoogleDataFixture : IAsyncLifetime // https://xunit.net/docs/shared-context
{
public async Task InitializeAsync()
{
var spreadsheetId = TestConfigurationHelper.GetSpreadsheetId();
var spreadsheetId = TestConfigurationHelper.GetGigSpreadsheet();
var credential = TestConfigurationHelper.GetJsonCredential();

var googleSheetService = new GoogleSheetService(credential, spreadsheetId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@
using Google.Apis.Sheets.v4.Data;
using RLE.Gig.Enums;
using RLE.Gig.Mappers;
using RLE.Gig.Tests.Data.Helpers;
using RLE.Gig.Tests.Data;
using RLE.Core.Enums;
using RLE.Core.Extensions;
using RLE.Core.Models.Google;
using RLE.Core.Helpers;
using RLE.Test.Helpers;

namespace RLE.Gig.Tests.Helpers.HeaderHelperTests;

Expand Down
4 changes: 2 additions & 2 deletions RLE.Gig.Tests/Managers/GoogleSheetManagerTests.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
using FluentAssertions;
using Moq;
using RLE.Gig.Enums;
using RLE.Gig.Tests.Data.Helpers;
using RLE.Gig.Entities;
using RLE.Core.Enums;
using RLE.Core.Extensions;
using RLE.Gig.Managers;
using RLE.Test.Helpers;

namespace RLE.Gig.Tests.Managers;

Expand All @@ -24,7 +24,7 @@ public GoogleSheetManagerTests()
_sheetEnum = random.NextEnum<SheetEnum>();
_currentTime = (long)DateTime.UtcNow.Subtract(DateTime.UnixEpoch).TotalSeconds;

_spreadsheetId = TestConfigurationHelper.GetSpreadsheetId();
_spreadsheetId = TestConfigurationHelper.GetGigSpreadsheet();
_credential = TestConfigurationHelper.GetJsonCredential();

_googleSheetManager = new GoogleSheetManager(_credential, _spreadsheetId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
using RLE.Gig.Enums;
using RLE.Gig.Mappers;
using RLE.Gig.Tests.Data;
using RLE.Gig.Tests.Data.Helpers;
using RLE.Test.Helpers;

namespace RLE.Gig.Tests.Mappers.MapFromRangeData;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
using RLE.Gig.Enums;
using RLE.Gig.Mappers;
using RLE.Gig.Tests.Data;
using RLE.Gig.Tests.Data.Helpers;
using RLE.Test.Helpers;

namespace RLE.Gig.Tests.Mappers.MapFromRangeData;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
using RLE.Gig.Enums;
using RLE.Gig.Mappers;
using RLE.Gig.Tests.Data;
using RLE.Gig.Tests.Data.Helpers;
using RLE.Test.Helpers;

namespace RLE.Gig.Tests.Mappers.MapFromRangeData;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
using RLE.Gig.Enums;
using RLE.Gig.Mappers;
using RLE.Gig.Tests.Data;
using RLE.Gig.Tests.Data.Helpers;
using RLE.Test.Helpers;

namespace RLE.Gig.Tests.Mappers.MapFromRangeData;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
using RLE.Gig.Enums;
using RLE.Gig.Mappers;
using RLE.Gig.Tests.Data;
using RLE.Gig.Tests.Data.Helpers;
using RLE.Test.Helpers;

namespace RLE.Gig.Tests.Mappers.MapFromRangeData;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
using RLE.Gig.Enums;
using RLE.Gig.Mappers;
using RLE.Gig.Tests.Data;
using RLE.Gig.Tests.Data.Helpers;
using RLE.Test.Helpers;

namespace RLE.Gig.Tests.Mappers.MapFromRangeData;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
using RLE.Gig.Enums;
using RLE.Gig.Mappers;
using RLE.Gig.Tests.Data;
using RLE.Gig.Tests.Data.Helpers;
using RLE.Test.Helpers;

namespace RLE.Gig.Tests.Mappers.MapFromRangeData;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
using RLE.Gig.Enums;
using RLE.Gig.Mappers;
using RLE.Gig.Tests.Data;
using RLE.Gig.Tests.Data.Helpers;
using RLE.Test.Helpers;

namespace RLE.Gig.Tests.Mappers.MapFromRangeData;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
using RLE.Gig.Enums;
using RLE.Gig.Mappers;
using RLE.Gig.Tests.Data;
using RLE.Gig.Tests.Data.Helpers;
using RLE.Test.Helpers;

namespace RLE.Gig.Tests.Mappers.MapFromRangeData;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
using RLE.Gig.Enums;
using RLE.Gig.Mappers;
using RLE.Gig.Tests.Data;
using RLE.Gig.Tests.Data.Helpers;
using RLE.Test.Helpers;

namespace RLE.Gig.Tests.Mappers.MapFromRangeData;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
using RLE.Gig.Enums;
using RLE.Gig.Mappers;
using RLE.Gig.Tests.Data;
using RLE.Gig.Tests.Data.Helpers;
using RLE.Test.Helpers;

namespace RLE.Gig.Tests.Mappers.MapFromRangeData;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
using RLE.Gig.Enums;
using RLE.Gig.Mappers;
using RLE.Gig.Tests.Data;
using RLE.Gig.Tests.Data.Helpers;
using RLE.Test.Helpers;

namespace RLE.Gig.Tests.Mappers.MapFromRangeData;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
using RLE.Gig.Enums;
using RLE.Gig.Mappers;
using RLE.Gig.Tests.Data;
using RLE.Gig.Tests.Data.Helpers;
using RLE.Test.Helpers;

namespace RLE.Gig.Tests.Mappers.MapFromRangeData;

Expand Down
2 changes: 1 addition & 1 deletion RLE.Gig.Tests/RLE.Gig.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

<IsPackable>false</IsPackable>
<IsTestProject>true</IsTestProject>
<UserSecretsId>b6c9cdfa-48ad-4a65-b400-27b15b457c38</UserSecretsId>
</PropertyGroup>

<ItemGroup>
Expand Down Expand Up @@ -80,6 +79,7 @@
<ProjectReference Include="..\RLE.Core.Tests\RLE.Core.Tests.csproj" />
<ProjectReference Include="..\RLE.Core\RLE.Core.csproj" />
<ProjectReference Include="..\RLE.Gig\RLE.Gig.csproj" />
<ProjectReference Include="..\RLE.Test\RLE.Test.csproj" />
</ItemGroup>

<ItemGroup>
Expand Down
2 changes: 1 addition & 1 deletion RLE.Gig.Tests/Services/GoogleDriveServiceTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
using RLE.Core.Services;
using RLE.Gig.Enums;
using RLE.Gig.Helpers;
using RLE.Gig.Tests.Data.Helpers;
using RLE.Test.Helpers;

namespace RLE.Gig.Tests.Services;

Expand Down
4 changes: 2 additions & 2 deletions RLE.Gig.Tests/Services/GoogleSheetServiceTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
using Google.Apis.Sheets.v4.Data;
using Moq;
using RLE.Gig.Enums;
using RLE.Gig.Tests.Data.Helpers;
using RLE.Core.Services;
using RLE.Core.Extensions;
using RLE.Gig.Helpers;
using RLE.Test.Helpers;

namespace RLE.Gig.Tests.Services;

Expand All @@ -18,7 +18,7 @@ public class GoogleSheetServiceTests

public GoogleSheetServiceTests()
{
_spreadsheetId = TestConfigurationHelper.GetSpreadsheetId();
_spreadsheetId = TestConfigurationHelper.GetGigSpreadsheet();
_credential = TestConfigurationHelper.GetJsonCredential();

_googleSheetService = new GoogleSheetService(_credential, _spreadsheetId);
Expand Down
39 changes: 0 additions & 39 deletions RLE.Stock.Tests/Data/Helpers/TestConfigurationHelper.cs

This file was deleted.

4 changes: 2 additions & 2 deletions RLE.Stock.Tests/Managers/GoogleSheetManagerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
using Xunit;
using RLE.Stock.Entities;
using RLE.Stock.Enums;
using RLE.Stock.Tests.Data.Helpers;
using RLE.Stock.Managers;
using RLE.Test.Helpers;

namespace RLE.Stock.Tests.Managers;

Expand All @@ -25,7 +25,7 @@ public GoogleSheetManagerTests()
_sheetEnum = random.NextEnum<SheetEnum>();
_currentTime = (long)DateTime.UtcNow.Subtract(DateTime.UnixEpoch).TotalSeconds;

_spreadsheetId = TestConfigurationHelper.GetSpreadsheetId();
_spreadsheetId = TestConfigurationHelper.GetStockSpreadsheet();
_credential = TestConfigurationHelper.GetJsonCredential();

_googleSheetManager = new GoogleSheetManager(_credential, _spreadsheetId);
Expand Down
6 changes: 5 additions & 1 deletion RLE.Stock.Tests/RLE.Stock.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

<IsPackable>false</IsPackable>
<IsTestProject>true</IsTestProject>
<UserSecretsId>1c1f5003-92f8-4bd6-b60b-20711296b84e</UserSecretsId>
</PropertyGroup>

<ItemGroup>
Expand All @@ -30,6 +29,11 @@
<ItemGroup>
<ProjectReference Include="..\RLE.Core\RLE.Core.csproj" />
<ProjectReference Include="..\RLE.Stock\RLE.Stock.csproj" />
<ProjectReference Include="..\RLE.Test\RLE.Test.csproj" />
</ItemGroup>

<ItemGroup>
<Folder Include="Data\Helpers\" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace RLE.Gig.Tests.Data.Helpers;
namespace RLE.Test.Helpers;

public static class RandomHelpers
{
Expand All @@ -11,7 +11,7 @@ public static int[] GetRandomOrder(int start, int length)
return [.. array.OrderBy((item) => rng.NextDouble())];
}

internal static IList<IList<object>> RandomizeValues(IList<IList<object>> values, int[] valueOrder)
public static IList<IList<object>> RandomizeValues(IList<IList<object>> values, int[] valueOrder)
{
var objectList = new List<IList<object>>();

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using Microsoft.Extensions.Configuration;
using System.Reflection;

namespace RLE.Gig.Tests.Data.Helpers;
namespace RLE.Test.Helpers;

public static class TestConfigurationHelper
{
Expand Down Expand Up @@ -30,10 +30,17 @@ public static Dictionary<string, string> GetJsonCredential()
return parameters;
}

public static string GetSpreadsheetId()
public static string GetGigSpreadsheet()
{
GetConfiguration();

return _configuration["gig_spreadsheet_id"] ?? string.Empty;
return _configuration["spreadsheets:gig"] ?? string.Empty;
}

public static string GetStockSpreadsheet()
{
GetConfiguration();

return _configuration["spreadsheets:stock"] ?? string.Empty;
}
}
15 changes: 15 additions & 0 deletions RLE.Test/RLE.Test.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<UserSecretsId>d3dcd413-34b9-40ef-9a99-a2615263e431</UserSecretsId>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Configuration.EnvironmentVariables" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.UserSecrets" Version="8.0.1" />
</ItemGroup>

</Project>
10 changes: 8 additions & 2 deletions RaptorLoggerEngine.sln
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,11 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "RLE.Core.Tests", "RLE.Core.
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Stock", "Stock", "{930D1E94-EE6E-41CB-82A7-474BA7E54C73}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "RLE.Stock", "RLE.Stock\RLE.Stock.csproj", "{A209D9EF-AFB7-450C-A7D4-A7003337B0A6}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "RLE.Stock", "RLE.Stock\RLE.Stock.csproj", "{A209D9EF-AFB7-450C-A7D4-A7003337B0A6}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "RLE.Stock.Tests", "RLE.Stock.Tests\RLE.Stock.Tests.csproj", "{44184538-9BF7-40CE-A585-0DF442722324}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "RLE.Stock.Tests", "RLE.Stock.Tests\RLE.Stock.Tests.csproj", "{44184538-9BF7-40CE-A585-0DF442722324}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "RLE.Test", "RLE.Test\RLE.Test.csproj", "{1EC60D38-096B-475D-86C3-E751EF8B7786}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand Down Expand Up @@ -49,6 +51,10 @@ Global
{44184538-9BF7-40CE-A585-0DF442722324}.Debug|Any CPU.Build.0 = Debug|Any CPU
{44184538-9BF7-40CE-A585-0DF442722324}.Release|Any CPU.ActiveCfg = Release|Any CPU
{44184538-9BF7-40CE-A585-0DF442722324}.Release|Any CPU.Build.0 = Release|Any CPU
{1EC60D38-096B-475D-86C3-E751EF8B7786}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{1EC60D38-096B-475D-86C3-E751EF8B7786}.Debug|Any CPU.Build.0 = Debug|Any CPU
{1EC60D38-096B-475D-86C3-E751EF8B7786}.Release|Any CPU.ActiveCfg = Release|Any CPU
{1EC60D38-096B-475D-86C3-E751EF8B7786}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down

0 comments on commit 2674429

Please sign in to comment.