Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master' into github-api-refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
timbussmann committed Dec 1, 2024
2 parents de12b65 + 71ad323 commit e662169
Show file tree
Hide file tree
Showing 4 changed files with 78 additions and 24 deletions.
45 changes: 45 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# This workflow will build a .NET project
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-net

name: .NET

on:
push:
branches: [ "master" ]
pull_request:
branches: [ "master" ]

concurrency:
group: ci-tests
cancel-in-progress: false

jobs:
build:

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
- name: Setup .NET
uses: actions/setup-dotnet@v4
with:
dotnet-version: 8.0.x
- name: Restore dependencies
run: dotnet restore
- name: Build
run: dotnet build --no-restore
# - name: Azure login
# uses: azure/[email protected]
# with:
# creds: ${{ secrets.AZURE_CREDENTIALS }}
# - name: Setup Cosmos DB
# uses: Particular/[email protected]
# with:
# connection-string-name: Annoy_O_Bot_ComsmosConnectionString
# azure-credentials: ${{ secrets.AZURE_CREDENTIALS }}
# tag: Annoy_O_Bot_Tests
- name: Test
env:
CosmosDBConnectionString: ${{ secrets.CosmosDBConnectionString }}
# current using MaxCpuCount 1 as both CosmosDB.Tests and AcceptanceTests use the same cosmos DB instance and tests fail otherwise
run: dotnet test --no-build --verbosity normal -maxcpucount:1
28 changes: 14 additions & 14 deletions Annoy-o-Bot.AcceptanceTests/AcceptanceTest.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System.Net;
using System.Security.Cryptography;
using System.Security.Cryptography;
using System.Text;
using Annoy_o_Bot.CosmosDB;
using Annoy_o_Bot.GitHub;
Expand All @@ -14,15 +13,15 @@
namespace Annoy_o_Bot.AcceptanceTests;

[Collection("CosmosDB")]
public class AcceptanceTest
public class AcceptanceTest(CosmosFixture cosmosFixture) : IAsyncLifetime

Check warning on line 16 in Annoy-o-Bot.AcceptanceTests/AcceptanceTest.cs

View workflow job for this annotation

GitHub Actions / build

Non-nullable field 'configurationBuilder' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the field as nullable.

Check warning on line 16 in Annoy-o-Bot.AcceptanceTests/AcceptanceTest.cs

View workflow job for this annotation

GitHub Actions / build

Non-nullable field 'container' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the field as nullable.
{
protected const string SignatureKey = "mysecretkey";

protected ConfigurationBuilder configurationBuilder;

protected Container container;

public AcceptanceTest(CosmosFixture cosmosFixture)
public async Task InitializeAsync()
{
configurationBuilder = new ConfigurationBuilder();
configurationBuilder.AddInMemoryCollection(new Dictionary<string, string>
Expand All @@ -31,25 +30,26 @@ public AcceptanceTest(CosmosFixture cosmosFixture)
});

container = cosmosFixture.CreateDocumentClient();
SetupCollection().GetAwaiter().GetResult();
await SetupCollection();
}

async Task SetupCollection()
public async Task DisposeAsync()
{
var database = container.Database;
try
{
await database.GetContainer(CosmosClientWrapper.collectionId).DeleteContainerAsync();
await container.DeleteContainerAsync();
}
catch (CosmosException e)
catch (Exception)
{
if (e.StatusCode != HttpStatusCode.NotFound)
{
throw;
}
// ignored
}
}

await database.CreateContainerAsync(CosmosClientWrapper.collectionId, "/id");
async Task SetupCollection()
{
var database = container.Database;
await database.Client.CreateDatabaseIfNotExistsAsync(CosmosClientWrapper.dbName);
await database.CreateContainerIfNotExistsAsync(CosmosClientWrapper.collectionId, "/id");
}

protected async Task CreateDueReminders(IGitHubApi gitHubApi)
Expand Down
5 changes: 4 additions & 1 deletion Annoy-o-Bot.CosmosDB.Tests/CosmosFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ namespace Annoy_o_Bot.AcceptanceTests;

public class CosmosFixture
{
const string EmulatorConnectionString = "AccountEndpoint=https://localhost:8081/;AccountKey=C2y6yDjf5/R+ob0N8A7Cgv30VRDJIWEHLM+4QDU5DE2nQ9nDuVTqobD4b8mGGyPMbIZnqyMsEcaGQy67XIw/Jw==";

public Container CreateDocumentClient()
{
/*
Expand All @@ -20,7 +22,8 @@ public Container CreateDocumentClient()
Serializer = new WorkerCosmosSerializer()
};
// CosmosDB emulator connection settings
var cosmosClient = new CosmosClient("AccountEndpoint=https://localhost:8081/;AccountKey=C2y6yDjf5/R+ob0N8A7Cgv30VRDJIWEHLM+4QDU5DE2nQ9nDuVTqobD4b8mGGyPMbIZnqyMsEcaGQy67XIw/Jw==", options);
var cosmosConnectinString = Environment.GetEnvironmentVariable("CosmosDBConnectionString") ?? EmulatorConnectionString;
var cosmosClient = new CosmosClient(cosmosConnectinString, options);
return cosmosClient.GetContainer(CosmosClientWrapper.dbName, CosmosClientWrapper.collectionId);
}
}
Expand Down
24 changes: 15 additions & 9 deletions Annoy-o-Bot.CosmosDB.Tests/CosmosWrapperTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@

namespace Annoy_o_Bot.CosmosDB.Tests;

public class CosmosWrapperTests : IClassFixture<CosmosFixture>
public class CosmosWrapperTests(CosmosFixture cosmosFixture) : IClassFixture<CosmosFixture>, IAsyncLifetime

Check warning on line 8 in Annoy-o-Bot.CosmosDB.Tests/CosmosWrapperTests.cs

View workflow job for this annotation

GitHub Actions / build

Non-nullable field 'DocumentClient' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the field as nullable.

Check warning on line 8 in Annoy-o-Bot.CosmosDB.Tests/CosmosWrapperTests.cs

View workflow job for this annotation

GitHub Actions / build

Non-nullable field 'CosmosWrapper' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the field as nullable.
{
Container DocumentClient;

CosmosClientWrapper CosmosWrapper;

ReminderDefinition reminderDefinition = new()
Expand All @@ -20,23 +21,28 @@ public class CosmosWrapperTests : IClassFixture<CosmosFixture>
Title = "demo title"
};

public CosmosWrapperTests(CosmosFixture cosmosFixture)
public async Task InitializeAsync()
{
DocumentClient = cosmosFixture.CreateDocumentClient();

CosmosWrapper = new CosmosClientWrapper(DocumentClient);

await DocumentClient.Database.Client.CreateDatabaseIfNotExistsAsync(CosmosClientWrapper.dbName);
try
{
DocumentClient.DeleteContainerAsync().GetAwaiter().GetResult();
await DocumentClient.DeleteContainerAsync();
}
catch (CosmosException e)
catch (CosmosException e) when (e.StatusCode == HttpStatusCode.NotFound)
{
if (e.StatusCode != HttpStatusCode.NotFound)
{
throw;
}
}

DocumentClient.Database.CreateContainerAsync(new ContainerProperties(CosmosClientWrapper.collectionId, "/id")).GetAwaiter().GetResult();
await DocumentClient.Database.CreateContainerIfNotExistsAsync(
new ContainerProperties(CosmosClientWrapper.collectionId, "/id"));
}

public Task DisposeAsync()
{
return Task.CompletedTask;
}

[Fact]
Expand Down

0 comments on commit e662169

Please sign in to comment.