Skip to content

Commit

Permalink
adding integration test shell
Browse files Browse the repository at this point in the history
  • Loading branch information
SteveWinward committed Jun 8, 2024
1 parent abab4c8 commit d768f65
Show file tree
Hide file tree
Showing 8 changed files with 153 additions and 2 deletions.
8 changes: 6 additions & 2 deletions .github/workflows/main_build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,5 +36,9 @@ jobs:
run: dotnet build --no-restore

# Run the unit tests
- name: Test
run: dotnet test --no-build --verbosity normal
- name: Unit Tests
run: dotnet test ~/GoogleSheetsWrapper.Tests/GoogleSheetsWrapper.Tests.csproj --no-build --verbosity normal

# Run the integration tests
- name: Integration Tests
run: dotnet test ~/GoogleSheetsWrapper.IntegrationTests/GoogleSheetsWrapper.IntegrationTests.csproj --no-build --verbosity normal
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
using Microsoft.Extensions.Configuration;

namespace GoogleSheetsWrapper.IntegrationTests
{
public class EnvironmentVariableConfig
{
public string GoogleServiceAccount { get; private set; } = "";

public string GoogleSpreadsheetId { get; private set; } = "";

public string JsonCredentials { get; private set; } = "";

private readonly IConfigurationRoot Config;

public EnvironmentVariableConfig()
{
Config = BuildConfig();

GoogleServiceAccount = Config["GOOGLE_SERVICE_ACCOUNT"];

Check warning on line 19 in src/GoogleSheetsWrapper.IntegrationTests/EnvironmentVariableConfig.cs

View workflow job for this annotation

GitHub Actions / build

Possible null reference assignment.

Check warning on line 19 in src/GoogleSheetsWrapper.IntegrationTests/EnvironmentVariableConfig.cs

View workflow job for this annotation

GitHub Actions / build

Possible null reference assignment.
GoogleSpreadsheetId = Config["GOOGLE_SPREADSHEET_ID"];

Check warning on line 20 in src/GoogleSheetsWrapper.IntegrationTests/EnvironmentVariableConfig.cs

View workflow job for this annotation

GitHub Actions / build

Possible null reference assignment.

Check warning on line 20 in src/GoogleSheetsWrapper.IntegrationTests/EnvironmentVariableConfig.cs

View workflow job for this annotation

GitHub Actions / build

Possible null reference assignment.
JsonCredentials = Config["GOOGLE_JSON_CREDS"];

Check warning on line 21 in src/GoogleSheetsWrapper.IntegrationTests/EnvironmentVariableConfig.cs

View workflow job for this annotation

GitHub Actions / build

Possible null reference assignment.

Check warning on line 21 in src/GoogleSheetsWrapper.IntegrationTests/EnvironmentVariableConfig.cs

View workflow job for this annotation

GitHub Actions / build

Possible null reference assignment.
}

/// <summary>
/// Really simple method to build the config locally. This requires you to setup User Secrets locally with Visual Studio
/// </summary>
/// <returns></returns>
private static IConfigurationRoot BuildConfig()
{
var devEnvironmentVariable = Environment.GetEnvironmentVariable("NETCORE_ENVIRONMENT");

var isDevelopment = string.IsNullOrEmpty(devEnvironmentVariable) ||
devEnvironmentVariable.Equals("development", StringComparison.OrdinalIgnoreCase);

var builder = new ConfigurationBuilder();

_ = builder.AddEnvironmentVariables();

//only add secrets in development
if (isDevelopment)
{
_ = builder.AddUserSecrets<EnvironmentVariableConfig>();
}

return builder.Build();
}
}
}
1 change: 1 addition & 0 deletions src/GoogleSheetsWrapper.IntegrationTests/GlobalUsings.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
global using NUnit.Framework;
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<IsPackable>false</IsPackable>
<IsTestProject>true</IsTestProject>
<UserSecretsId>606ff594-acc4-4258-98e5-3926eab33faf</UserSecretsId>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Configuration.EnvironmentVariables" Version="8.0.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.6.0" />
<PackageReference Include="NUnit" Version="3.13.3" />
<PackageReference Include="NUnit3TestAdapter" Version="4.2.1" />
<PackageReference Include="NUnit.Analyzers" Version="3.6.1" />
<PackageReference Include="coverlet.collector" Version="6.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.UserSecrets" Version="8.0.0" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\GoogleSheetsWrapper\GoogleSheetsWrapper.csproj" />
</ItemGroup>

</Project>
31 changes: 31 additions & 0 deletions src/GoogleSheetsWrapper.IntegrationTests/ReadAllRowsTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
namespace GoogleSheetsWrapper.IntegrationTests
{
public class ReadAllRowsTests
{
public EnvironmentVariableConfig Config { get; set; }

[SetUp]
public void Setup()
{
Config = new EnvironmentVariableConfig();
}

[Test]
public void ReadAllRowsHasFiveRows()
{
// Create a new SheetHelper class
var sheetHelper = new SheetHelper<ReadAllRowsTestRecord>(
Config.GoogleSpreadsheetId,
Config.GoogleServiceAccount,
"ReadAllRows");

sheetHelper.Init(Config.JsonCredentials);

var respository = new ReadAllRowsTestRepository(sheetHelper);

var rows = respository.GetAllRecords();

Assert.That(rows, Has.Count.EqualTo(5));
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
namespace GoogleSheetsWrapper.IntegrationTests
{
public class ReadAllRowsTestRecord : BaseRecord
{
[SheetField(
DisplayName = "Task",
ColumnID = 1,
FieldType = SheetFieldType.String)]
public string Task { get; set; }

[SheetField(
DisplayName = "Value",
ColumnID = 2,
FieldType = SheetFieldType.String)]
public string Value { get; set; }


public ReadAllRowsTestRecord() { }

Check warning on line 18 in src/GoogleSheetsWrapper.IntegrationTests/TestObjects/ReadAllRowsTestRecord.cs

View workflow job for this annotation

GitHub Actions / build

Non-nullable property 'Task' must contain a non-null value when exiting constructor. Consider declaring the property as nullable.

Check warning on line 18 in src/GoogleSheetsWrapper.IntegrationTests/TestObjects/ReadAllRowsTestRecord.cs

View workflow job for this annotation

GitHub Actions / build

Non-nullable property 'Value' must contain a non-null value when exiting constructor. Consider declaring the property as nullable.

public ReadAllRowsTestRecord(IList<object> row, int rowId, int minColumnId = 1)

Check warning on line 20 in src/GoogleSheetsWrapper.IntegrationTests/TestObjects/ReadAllRowsTestRecord.cs

View workflow job for this annotation

GitHub Actions / build

Non-nullable property 'Task' must contain a non-null value when exiting constructor. Consider declaring the property as nullable.

Check warning on line 20 in src/GoogleSheetsWrapper.IntegrationTests/TestObjects/ReadAllRowsTestRecord.cs

View workflow job for this annotation

GitHub Actions / build

Non-nullable property 'Value' must contain a non-null value when exiting constructor. Consider declaring the property as nullable.
: base(row, rowId, minColumnId)
{
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
namespace GoogleSheetsWrapper.IntegrationTests
{
public class ReadAllRowsTestRepository : BaseRepository<ReadAllRowsTestRecord>
{
public ReadAllRowsTestRepository() { }

public ReadAllRowsTestRepository(SheetHelper<ReadAllRowsTestRecord> sheetsHelper)
: base(sheetsHelper) { }
}
}
6 changes: 6 additions & 0 deletions src/GoogleSheetsWrapper.sln
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "GoogleSheetsWrapper.Tests",
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "GoogleSheetsWrapper.SampleClient", "GoogleSheetsWrapper.SampleClient\GoogleSheetsWrapper.SampleClient.csproj", "{821B9814-7752-4E00-B92C-EA28AAA21CF6}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "GoogleSheetsWrapper.IntegrationTests", "GoogleSheetsWrapper.IntegrationTests\GoogleSheetsWrapper.IntegrationTests.csproj", "{2A765A6D-B5C2-4894-8720-892ACE9A2291}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand All @@ -27,6 +29,10 @@ Global
{821B9814-7752-4E00-B92C-EA28AAA21CF6}.Debug|Any CPU.Build.0 = Debug|Any CPU
{821B9814-7752-4E00-B92C-EA28AAA21CF6}.Release|Any CPU.ActiveCfg = Release|Any CPU
{821B9814-7752-4E00-B92C-EA28AAA21CF6}.Release|Any CPU.Build.0 = Release|Any CPU
{2A765A6D-B5C2-4894-8720-892ACE9A2291}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{2A765A6D-B5C2-4894-8720-892ACE9A2291}.Debug|Any CPU.Build.0 = Debug|Any CPU
{2A765A6D-B5C2-4894-8720-892ACE9A2291}.Release|Any CPU.ActiveCfg = Release|Any CPU
{2A765A6D-B5C2-4894-8720-892ACE9A2291}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down

0 comments on commit d768f65

Please sign in to comment.