Skip to content

Commit

Permalink
Add support for Integration tests (#61)
Browse files Browse the repository at this point in the history
* Setup xUnit

* Update README

* Rename

* Drop boss test

* Add new env for tests

* Restrict scanned types to solution

* Make EF dependency explicit for API

* Add working test

* Add support to create a theme

* Add spec flow tests for create

* [WIP] Add test for anonymous

* Remove debug statement

* Update autogenerated file

* Add CI

* Add CI config

* Wrap and rollback transaction for each spec

* Enable CI to read correct configuration

* Reduce overrides from tests

* Change db name for CI

* Extract queries in separate folder

* Remove awkward file

* Drop Api tests in favor of Specs

* Reuse same Test env on CI

* Add ability to do matching on responses

* Remove debug statements

* Disable recording new snapshots on CI

* Add CI env back in

* Drop mock implementation of repository

* Fix build

* Drop dummy data migration

* Revert "Drop mock implementation of repository"

This reverts commit 774d67b.

Co-authored-by: Constantin Capatina <[email protected]>
  • Loading branch information
pirvudoru and drqCode authored Oct 16, 2021
1 parent a464730 commit ca82a9a
Show file tree
Hide file tree
Showing 38 changed files with 819 additions and 256 deletions.
50 changes: 50 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
name: CI

on:
push:
branches: [ develop, main ]
pull_request:
branches: [ develop, main ]

jobs:
build:
runs-on: ubuntu-latest
env:
ASPNETCORE_ENVIRONMENT: CI
services:
postgres:
image: postgres
env:
POSTGRES_DB: teacher_workout_test
POSTGRES_PASSWORD: docker
POSTGRES_USER: docker
ports:
- 5432:5432
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
steps:
- uses: actions/checkout@v2

- name: Setup .NET
uses: actions/setup-dotnet@v1
with:
dotnet-version: 5.0.x

- name: Install dependencies
run: dotnet tool install --global dotnet-ef

- name: Restore dependencies
run: dotnet restore TeacherWorkout.sln

- name: Build
run: dotnet build --no-restore /p:ContinuousIntegrationBuild=true TeacherWorkout.sln

- name: Apply migrations
run: dotnet ef database update --no-build --project TeacherWorkout.Domain --startup-project TeacherWorkout.Api

- name: Run tests
run: dotnet test --no-build --verbosity normal /p:CollectCoverage=true /p:CoverletOutputFormat=opencover TeacherWorkout.sln
15 changes: 15 additions & 0 deletions .graphqlconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"name": "Untitled GraphQL Schema",
"schemaPath": "schema.graphql",
"extensions": {
"endpoints": {
"Default GraphQL Endpoint": {
"url": "http://localhost:8080/graphql",
"headers": {
"user-agent": "JS GraphQL"
},
"introspect": false
}
}
}
}
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,9 @@ Guide users through getting your code up and running on their own system. In thi

Describe and show how to build your code and run the tests.

## Automatic tests
1. Run `$ dotnet test`

## Feedback

* Request a new feature on GitHub.
Expand Down
19 changes: 16 additions & 3 deletions TeacherWorkout.Api/GraphQL/TeacherWorkoutMutation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@
using TeacherWorkout.Api.GraphQL.Types.Payloads;
using TeacherWorkout.Domain.Lessons;
using TeacherWorkout.Domain.Models.Inputs;
using TeacherWorkout.Domain.Themes;

namespace TeacherWorkout.Api.GraphQL
{
public class TeacherWorkoutMutation : ObjectGraphType<object>
{
public TeacherWorkoutMutation(CompleteStep completeStep)
public TeacherWorkoutMutation(CompleteStep completeStep,
CreateTheme createTheme)
{
Name = "Mutation";

Expand All @@ -32,8 +34,19 @@ public TeacherWorkoutMutation(CompleteStep completeStep)
),
resolve: context =>
{
var stepComplete = context.GetArgument<StepCompleteInput>("input");
return completeStep.Execute(stepComplete);
var input = context.GetArgument<StepCompleteInput>("input");
return completeStep.Execute(input);
});

Field<ThemeCreatePayloadType>(
"themeCreate",
arguments: new QueryArguments(
new QueryArgument<NonNullGraphType<ThemeCreateInputType>> { Name = "input" }
),
resolve: context =>
{
var input = context.GetArgument<ThemeCreateInput>("input");
return createTheme.Execute(input);
});
}
}
Expand Down
1 change: 1 addition & 0 deletions TeacherWorkout.Api/GraphQL/TeacherWorkoutSchema.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ private void AddTypeMappings()
var classTypes = AppDomain.CurrentDomain.GetAssemblies()
.SelectMany(t => t.GetTypes())
.Where(t => t.IsClass || t.IsEnum)
.Where(t => t.Namespace != null && t.Namespace.StartsWith("TeacherWorkout"))
.ToList();

classTypes.Where(t => t.Namespace == "TeacherWorkout.Domain.Models")
Expand Down
16 changes: 16 additions & 0 deletions TeacherWorkout.Api/GraphQL/Types/Inputs/ThemeCreateInputType.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
using GraphQL.Types;
using TeacherWorkout.Domain.Models.Inputs;

namespace TeacherWorkout.Api.GraphQL.Types.Inputs
{
public class ThemeCreateInputType : InputObjectGraphType<ThemeCreateInput>
{
public ThemeCreateInputType()
{
Name = "ThemeCreateInput";

Field(x => x.ThumbnailId, type: typeof(IdGraphType));
Field(x => x.Title);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
using GraphQL.Types;
using TeacherWorkout.Domain.Models.Payloads;

namespace TeacherWorkout.Api.GraphQL.Types.Payloads
{
public class ThemeCreatePayloadType : ObjectGraphType<ThemeCreatePayload>
{
public ThemeCreatePayloadType()
{
Name = "ThemeCreatePayload";

Field(x => x.Theme).Description("The Theme.");
}
}
}
4 changes: 2 additions & 2 deletions TeacherWorkout.Api/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public void ConfigureServices(IServiceCollection services)
services.AddHttpContextAccessor();
services.AddGraphQL(options =>
{
options.EnableMetrics = true;
options.EnableMetrics = false;
})
.AddErrorInfoProvider(opt => opt.ExposeExceptionStackTrace = true)
.AddSystemTextJson()
Expand Down Expand Up @@ -111,7 +111,7 @@ private static void EnsureReferencedAssembliesAreLoaded()
{
// We need to reference something in the assembly to make it load
// otherwise the Compiler will not include it in the output package
new List<Assembly> { typeof(MockData.Repositories.LessonRepository).Assembly };
new List<Assembly> { typeof(MockData.Repositories.StepRepository).Assembly };
}
}
}
1 change: 1 addition & 0 deletions TeacherWorkout.Api/TeacherWorkout.Api.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.EntityFrameworkCore.Relational" Version="5.0.10" />
</ItemGroup>

<ItemGroup>
Expand Down
15 changes: 0 additions & 15 deletions TeacherWorkout.Api/WeatherForecast.cs

This file was deleted.

12 changes: 12 additions & 0 deletions TeacherWorkout.Api/appsettings.CI.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft": "Warning",
"Microsoft.Hosting.Lifetime": "Information"
}
},
"ConnectionStrings": {
"TeacherWorkoutContext": "host=localhost;Port=5432;Database=teacher_workout_test;User Id=docker;Password=docker;"
}
}
12 changes: 12 additions & 0 deletions TeacherWorkout.Api/appsettings.Test.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft": "Warning",
"Microsoft.Hosting.Lifetime": "Information"
}
},
"ConnectionStrings": {
"TeacherWorkoutContext": "host=localhost;Port=5432;Database=teacher_workout_test;User Id=docker;Password=docker;"
}
}

This file was deleted.

Loading

0 comments on commit ca82a9a

Please sign in to comment.