-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
- Loading branch information
There are no files selected for viewing
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 GitHub Actions / build
|
||
GoogleSpreadsheetId = Config["GOOGLE_SPREADSHEET_ID"]; | ||
Check warning on line 20 in src/GoogleSheetsWrapper.IntegrationTests/EnvironmentVariableConfig.cs GitHub Actions / build
|
||
JsonCredentials = Config["GOOGLE_JSON_CREDS"]; | ||
Check warning on line 21 in src/GoogleSheetsWrapper.IntegrationTests/EnvironmentVariableConfig.cs GitHub Actions / build
|
||
} | ||
|
||
/// <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(); | ||
} | ||
} | ||
} |
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> |
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 GitHub Actions / build
|
||
|
||
public ReadAllRowsTestRecord(IList<object> row, int rowId, int minColumnId = 1) | ||
Check warning on line 20 in src/GoogleSheetsWrapper.IntegrationTests/TestObjects/ReadAllRowsTestRecord.cs GitHub Actions / build
|
||
: 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) { } | ||
} | ||
} |