Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for Integration tests #61

Merged
merged 31 commits into from
Oct 16, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
a2ba1fd
Setup xUnit
drqCode Jul 31, 2021
45019ae
Update README
drqCode Jul 31, 2021
fe0dd49
Rename
drqCode Jul 31, 2021
b4df331
Drop boss test
pirvudoru Sep 25, 2021
1e34868
Add new env for tests
pirvudoru Sep 25, 2021
68f74bb
Restrict scanned types to solution
pirvudoru Sep 25, 2021
ce83965
Make EF dependency explicit for API
pirvudoru Sep 25, 2021
b5d06e0
Add working test
pirvudoru Sep 25, 2021
49825c9
Add support to create a theme
pirvudoru Sep 25, 2021
76c8ea2
Add spec flow tests for create
pirvudoru Sep 25, 2021
48957d1
[WIP] Add test for anonymous
pirvudoru Sep 25, 2021
fd8d3a0
Remove debug statement
pirvudoru Oct 14, 2021
ed4a56a
Update autogenerated file
pirvudoru Oct 14, 2021
a8a6c7d
Add CI
pirvudoru Oct 14, 2021
a80087c
Add CI config
pirvudoru Oct 14, 2021
19422d8
Wrap and rollback transaction for each spec
pirvudoru Oct 15, 2021
751e82b
Enable CI to read correct configuration
pirvudoru Oct 15, 2021
30222a1
Reduce overrides from tests
pirvudoru Oct 15, 2021
5461150
Change db name for CI
pirvudoru Oct 15, 2021
842ea91
Extract queries in separate folder
pirvudoru Oct 15, 2021
fe580a2
Remove awkward file
pirvudoru Oct 15, 2021
e92c6ca
Drop Api tests in favor of Specs
pirvudoru Oct 15, 2021
8380950
Reuse same Test env on CI
pirvudoru Oct 15, 2021
f51a2a0
Add ability to do matching on responses
pirvudoru Oct 16, 2021
870e54a
Remove debug statements
pirvudoru Oct 16, 2021
f617723
Disable recording new snapshots on CI
pirvudoru Oct 16, 2021
9d77719
Add CI env back in
pirvudoru Oct 16, 2021
774d67b
Drop mock implementation of repository
pirvudoru Oct 16, 2021
699f697
Fix build
pirvudoru Oct 16, 2021
028e246
Drop dummy data migration
pirvudoru Oct 16, 2021
8792df9
Revert "Drop mock implementation of repository"
pirvudoru Oct 16, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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