-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #32 from bb-io/develop
Added unit tests
- Loading branch information
Showing
10 changed files
with
169 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -356,3 +356,4 @@ healthchecksdb | |
*.env | ||
|
||
/Apps.GoogleSheets/ApplicationConstants.cs | ||
/Tests.GoogleSheets/appsettings.json |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
using Blackbird.Applications.Sdk.Common.Files; | ||
using Blackbird.Applications.SDK.Extensions.FileManagement.Interfaces; | ||
|
||
namespace Tests.GoogleSheets.Base; | ||
|
||
public class FileManager(string folderLocation) : IFileManagementClient | ||
{ | ||
public Task<Stream> DownloadAsync(FileReference reference) | ||
{ | ||
var path = Path.Combine(folderLocation, @$"Input\{reference.Name}"); | ||
var bytes = File.ReadAllBytes(path); | ||
|
||
var stream = new MemoryStream(bytes); | ||
return Task.FromResult((Stream)stream); | ||
} | ||
|
||
public Task<FileReference> UploadAsync(Stream stream, string contentType, string fileName) | ||
{ | ||
var path = Path.Combine(folderLocation, @$"Output\{fileName}"); | ||
new FileInfo(path).Directory!.Create(); | ||
using (var fileStream = File.Create(path)) | ||
{ | ||
stream.CopyTo(fileStream); | ||
} | ||
|
||
return Task.FromResult(new FileReference { Name = fileName }); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
using Blackbird.Applications.Sdk.Common.Authentication; | ||
using Blackbird.Applications.Sdk.Common.Invocation; | ||
using Microsoft.Extensions.Configuration; | ||
|
||
namespace Tests.GoogleSheets.Base; | ||
|
||
public class TestBase | ||
{ | ||
protected TestBase() | ||
{ | ||
var config = new ConfigurationBuilder().AddJsonFile("appsettings.json").Build(); | ||
Creds = config.GetSection("ConnectionDefinition").GetChildren() | ||
.Select(x => new AuthenticationCredentialsProvider(x.Key, x.Value!)).ToList(); | ||
var folderLocation = config.GetSection("TestFolder").Value!; | ||
|
||
InvocationContext = new InvocationContext | ||
{ | ||
AuthenticationCredentialsProviders = Creds, | ||
}; | ||
|
||
FileManager = new FileManager(folderLocation); | ||
} | ||
|
||
protected IEnumerable<AuthenticationCredentialsProvider> Creds { get; set; } | ||
|
||
public InvocationContext InvocationContext { get; set; } | ||
|
||
public FileManager FileManager { get; set; } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
using Tests.GoogleSheets.Base; | ||
|
||
namespace Tests.CrowGoogleSheetsdin | ||
{ | ||
[TestClass] | ||
public class SpreadsheetTests : TestBase | ||
{ | ||
[TestMethod] | ||
public async Task Getrange_ReturnsSuccess() | ||
{ | ||
|
||
} | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>net8.0</TargetFramework> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
<Nullable>enable</Nullable> | ||
|
||
<IsPackable>false</IsPackable> | ||
<IsTestProject>true</IsTestProject> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="coverlet.collector" Version="6.0.0" /> | ||
<PackageReference Include="FluentAssertions" Version="8.0.0-rc.2" /> | ||
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="9.0.0" /> | ||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.8.0" /> | ||
<PackageReference Include="MSTest.TestAdapter" Version="3.1.1" /> | ||
<PackageReference Include="MSTest.TestFramework" Version="3.1.1" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<Using Include="Microsoft.VisualStudio.TestTools.UnitTesting" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\Apps.GoogleSheets\Apps.GoogleSheets.csproj" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<Folder Include="Output\" /> | ||
<Folder Include="Output\" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<None Update="appsettings.json"> | ||
<CopyToOutputDirectory>Always</CopyToOutputDirectory> | ||
</None> | ||
</ItemGroup> | ||
|
||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
using Apps.GoogleSheets.Connections; | ||
using Blackbird.Applications.Sdk.Common.Authentication; | ||
using FluentAssertions; | ||
using Tests.GoogleSheets.Base; | ||
|
||
namespace Tests.GoogleSheets; | ||
|
||
[TestClass] | ||
public class ValidatorTests : TestBase | ||
{ | ||
[TestMethod] | ||
public async Task ValidateConnection_ValidEnterpriseConnection_ShouldBeSuccessful() | ||
{ | ||
var validator = new ConnectionValidator(); | ||
|
||
var result = await validator.ValidateConnection(Creds, CancellationToken.None); | ||
Console.WriteLine(result.Message); | ||
result.IsValid.Should().Be(true); | ||
} | ||
|
||
[TestMethod] | ||
public async Task ValidateConnection_InvalidConnection_ShouldFail() | ||
{ | ||
var validator = new ConnectionValidator(); | ||
|
||
var newCredentials = Creds.Select(x => new AuthenticationCredentialsProvider(x.KeyName, x.Value + "_incorrect")); | ||
var result = await validator.ValidateConnection(newCredentials, CancellationToken.None); | ||
result.IsValid.Should().Be(false); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{ | ||
"ConnectionDefinition": { | ||
"access_token": "", | ||
"crowdin_plan": "", | ||
"domain": "" | ||
}, | ||
"TestFolder": "C:\\Users\\..." | ||
} |