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

Release to production #10

Merged
merged 65 commits into from
Feb 29, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
65 commits
Select commit Hold shift + click to select a range
bde8cc3
Upgraded nuget packages to highest possible version compatible with .…
jonasanker Oct 12, 2019
817e2ea
Revert NSWag to v11.20.1
jonasanker Oct 12, 2019
ac9ebc1
Upgraded project and dependencies to .net core 2.2
jonasanker Oct 13, 2019
4afb9a2
Performed code clean up
jonasanker Oct 13, 2019
9db15f2
Updated .gitignore to avoid logfiles
jonasanker Oct 13, 2019
a142737
Upgraded NSwag package and impl to v13.1.3
jonasanker Oct 13, 2019
435b43d
Added AppConfigController, DTO and Service
KasperLarssen Oct 12, 2019
73b6634
added exceptions when retreiving configuration
KasperLarssen Oct 15, 2019
ab37c03
Resolved pull-request comments
KasperLarssen Oct 16, 2019
f0694ae
Added MobilePay methods for GetPaymentStatus, Capture and Delete rese…
jonasanker Oct 17, 2019
5729556
Added OnModelCreating to context
Oct 12, 2019
4834061
OnModelCreating is now using the configuration from appsettings
Oct 12, 2019
fb3c6d4
Merge branch 'feature/schemas-from-config' into feature/jonas/mobile-…
Oct 17, 2019
2f5054c
Changed the mobilePay service to use the right cert and expaanded the…
Oct 19, 2019
b6fa900
Added RetrieveTemplate and SendReceipt functions to EmailService. Cha…
Oct 29, 2019
6f310b7
Added logic to CompletePurchase in purchase service to handle sending…
Oct 29, 2019
db506ab
Changes to invoice template
Oct 30, 2019
ff78c17
Added correct handling of timezones to SendInvoice
Oct 31, 2019
253e806
New draft of the invoice. Based on the feedback from UX, it now resem…
Jan 8, 2020
ee67a03
Rename Solution and Project to CamelCase
jonasanker Jan 20, 2020
48cef50
Code Cleanup
jonasanker Jan 20, 2020
8cd00a9
Added MobilePay methods for GetPaymentStatus, Capture and Delete rese…
jonasanker Oct 17, 2019
159c6f8
Added OnModelCreating to context
Oct 12, 2019
fa6077f
OnModelCreating is now using the configuration from appsettings
Oct 12, 2019
42471e9
Changed the mobilePay service to use the right cert and expaanded the…
Oct 19, 2019
76ae74e
Rewrite MobilePay Service, introduce MobilePayApiClient
jonasanker Jan 20, 2020
aa39150
Rewritten PurchaseService to support new MobilePay flow
Jan 20, 2020
430c78c
Extract IMobilePayApiHttpClient interface
jonasanker Jan 20, 2020
1290510
Fix namespaces
jonasanker Jan 20, 2020
5b53c6d
Setup CoffeeCardTests project and move CoffeeCard project to its own …
jonasanker Jan 20, 2020
40223cd
MobilePayService tests
jonasanker Jan 20, 2020
bd427ac
Certificate Expiry Test
Jan 21, 2020
d3b4c4d
Temp MPApiClientTests
Jan 21, 2020
4d4ddb4
Merge feature/jonas/mobile-api-extension with feature/thomas/purchase…
jonasanker Jan 23, 2020
448e40b
Moved invoice.html and logo into the cofeecardAPI instead of root fol…
Jan 24, 2020
d0a8a30
Add appsettings.json to .gitignore
jonasanker Feb 16, 2020
04f425b
Move certificate to publish directory when building project
jonasanker Feb 16, 2020
6c1cce5
Return IActionResult instead of ActionResult in Controllers
jonasanker Feb 16, 2020
ddded8f
Log unhandled exceptions
jonasanker Feb 16, 2020
dba7780
Merge branch 'feature/thomas/purchase-receipt' into develop
jonasanker Feb 16, 2020
7fa8991
Retrive analogo.png from online url
jonasanker Feb 16, 2020
b7c6ac9
Do not log tokens
jonasanker Feb 16, 2020
3f429b5
Make ProgrammeId nullable
jonasanker Feb 16, 2020
fcef165
Cleanup Purchaseservice
jonasanker Feb 16, 2020
39cce48
Sort Tickets and Purchase by usage date or purchase date
jonasanker Feb 16, 2020
88bb219
Setup Github Actions build and test pipeline
jonasanker Feb 16, 2020
99920bd
Disable HttpClient tests
jonasanker Feb 16, 2020
067b068
Add Github Actions badge to readme
jonasanker Feb 16, 2020
776c75a
Log failed logins and password recovery
jonasanker Feb 17, 2020
8bb8d53
Simple PingController for heartbeat
jonasanker Feb 20, 2020
c2b185a
Basic PingController tets
jonasanker Feb 20, 2020
c3d2093
Ignore compilerwarning for specific AspNetCore.App version
jonasanker Feb 20, 2020
9335850
Upgrade AspNetCore.App to 2.2.8 and upgraded nuget packages
jonasanker Feb 20, 2020
02b9bd8
Code Cleanup and Reformatting
jonasanker Feb 20, 2020
f2deb97
Renamed test project to CoffeeCard.Tests.Unit
jonasanker Feb 22, 2020
456b088
Setup new project CoffeeCard.Tests.Integration
jonasanker Feb 22, 2020
113d33d
Change Github Actions pipeline to updated project structure
jonasanker Feb 22, 2020
761cd9a
Integration test spike
jonasanker Feb 22, 2020
2bae834
Simplify Github Actions pipeline
jonasanker Feb 22, 2020
d4c2677
Bump Github Actions dotnet core to 2.2.207
jonasanker Feb 22, 2020
c06beed
Use appsettings-for-test.json for Integration tests
jonasanker Feb 22, 2020
3eb20fa
Align E-mail footer content
jonasanker Feb 23, 2020
3dbf5d5
Strongly typed app settings
jonasanker Feb 25, 2020
0f66839
Update Migration for Production database
jonasanker Feb 28, 2020
3c42a24
Add deployment url to appsettings
jonasanker Feb 29, 2020
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
24 changes: 24 additions & 0 deletions .github/workflows/dotnetcore.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
name: Build and test solution

on: [push]

jobs:
build:

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
# Create an empty certificate file since it it a build dependency
- uses: "finnp/create-file-action@master"
env:
FILE_NAME: "coffeecard/CoffeeCard/www.analogio.dk.pfx"
FILE_DATA: "empty file"
- name: Setup .NET Core
uses: actions/setup-dotnet@v1
with:
dotnet-version: 2.2.207
- name: Build CoffeeCard solution
run: dotnet build coffeecard/
- name: Run tests
run: dotnet test coffeecard/
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
# analog-core

![Build and test solution](https://github.com/AnalogIO/analog-core/workflows/Build%20and%20test%20solution/badge.svg)

This repository will contain the ASP.NET Core 2 version of the backend for the coffeecard apps.

Lets try to follow this guide: https://docs.microsoft.com/en-us/aspnet/core/tutorials/web-api-vsc?view=aspnetcore-2.1
Expand All @@ -11,4 +14,4 @@ Add `appsettings.json` to directory `/coffeecard/` with the following format:
},
"TokenKey": "<symmetrickey>"
}
```
```
5 changes: 4 additions & 1 deletion coffeecard/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -278,5 +278,8 @@ __pycache__/
!.vscode/launch.json
!.vscode/extensions.json

# Logs
**/logs/

# End of https://www.gitignore.io/api/aspnetcore,visualstudiocode
# Appsettings
appsettings.json
46 changes: 0 additions & 46 deletions coffeecard/.vscode/launch.json

This file was deleted.

15 changes: 0 additions & 15 deletions coffeecard/.vscode/tasks.json

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netcoreapp2.2</TargetFramework>

<IsPackable>false</IsPackable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.App" Version="2.2.8">
<!-- Deploying on UnoEuro demands a specific AspNetCore.App version even though it not recommended by MS
AllowExplicitVersion = true disables compiler warning -->
<AllowExplicitVersion>true</AllowExplicitVersion>
</PackageReference>
<PackageReference Include="Microsoft.AspNetCore.Mvc.Testing" Version="2.2.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.5.0" />
<PackageReference Include="NetEscapades.Configuration.Validation" Version="2.0.0" />
<PackageReference Include="xunit" Version="2.4.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.1" />
<PackageReference Include="coverlet.collector" Version="1.2.0" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\CoffeeCard\CoffeeCard.csproj" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
using System.Net;
using System.Threading.Tasks;
using CoffeeCard.Tests.Integration.WebApplication;
using Xunit;

namespace CoffeeCard.Tests.Integration.Controllers
{
public class PingControllerTests : IClassFixture<CustomWebApplicationFactory<CoffeeCard.Startup>>
{
private readonly CustomWebApplicationFactory<Startup> _webApplicationFactory;

public PingControllerTests(CustomWebApplicationFactory<Startup> webApplicationFactory)
{
_webApplicationFactory = webApplicationFactory;
}

[Fact(DisplayName = "Ping returns HTTP 200 OK")]
public async Task PingReturnsHTTP200Ok()
{
// Arrange
var client = _webApplicationFactory.CreateClient();

// Act
var response = await client.GetAsync("api/v1/Ping");

// Assert
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
}

[Fact(DisplayName = "Ping returns pong")]
public async Task PingReturnsPong()
{
// Arrange
var client = _webApplicationFactory.CreateClient();

// Act
var response = await client.GetAsync("api/v1/Ping");

var content = await response.Content.ReadAsStringAsync();

// Assert
Assert.Equal("pong", content);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
using CoffeeCard.Configuration;
using CoffeeCard.Models;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Mvc.Testing;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;

namespace CoffeeCard.Tests.Integration.WebApplication
{
// Based on https://docs.microsoft.com/en-us/aspnet/core/test/integration-tests?view=aspnetcore-2.2

public class CustomWebApplicationFactory<TStartup> : WebApplicationFactory<TStartup> where TStartup: class
{
private IConfiguration Configuration { get; set; }

protected override void ConfigureWebHost(IWebHostBuilder builder)
{
// Use TestAppSettings
builder.ConfigureAppConfiguration(configuration =>
{
configuration.AddJsonFile("appsettings-for-tests.json");
Configuration = configuration.Build();
});

builder.ConfigureServices(services =>
{
services.UseConfigurationValidation();

// Parse and setup settings from configuration
services.ConfigureValidatableSetting<DatabaseSettings>(Configuration.GetSection("DatabaseSettings"));
services.ConfigureValidatableSetting<EnvironmentSettings>(Configuration.GetSection("EnvironmentSettings"));
services.ConfigureValidatableSetting<IdentitySettings>(Configuration.GetSection("IdentitySettings"));
services.ConfigureValidatableSetting<MailgunSettings>(Configuration.GetSection("MailgunSettings"));
services.ConfigureValidatableSetting<MobilePaySettings>(Configuration.GetSection("MobilePaySettings"));

// Create a new service provider.
var serviceProvider = new ServiceCollection()
.AddEntityFrameworkInMemoryDatabase()
.BuildServiceProvider();

// Add a database context (ApplicationDbContext) using an in-memory database for testing.
services.AddDbContext<CoffeeCardContext>(options =>
{
options.UseInMemoryDatabase("InMemoryDbForTesting");
options.UseInternalServiceProvider(serviceProvider);
});

// Build the service provider
var sp = services.BuildServiceProvider();

// Create a scope to obtain a reference to the database context (ApplicationDbContext).
using (var scope = sp.CreateScope())
{
var scopedServices = scope.ServiceProvider;
var db = scopedServices.GetRequiredService<CoffeeCardContext>();

// Ensure the database is created.
db.Database.EnsureCreated();
}
});
}
}
}
27 changes: 27 additions & 0 deletions coffeecard/CoffeeCard.Tests.Unit/CoffeeCard.Tests.Unit.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netcoreapp2.2</TargetFramework>

<IsPackable>false</IsPackable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.5.0" />
<PackageReference Include="Moq" Version="4.13.1" />
<PackageReference Include="xunit" Version="2.4.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.1">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>
<PackageReference Include="coverlet.collector" Version="1.2.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\CoffeeCard\CoffeeCard.csproj" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
using CoffeeCard.Controllers;
using Microsoft.AspNetCore.Mvc;
using Xunit;

namespace CoffeeCard.Tests.Unit.Controllers
{
public class PingControllerTests
{
[Fact(DisplayName = "Ping returns OkObjectResult")]
public void PingReturnsOkObjectResult()
{
var controller = new PingController();

var result = controller.Ping();

Assert.IsType<OkObjectResult>(result);
}

[Fact(DisplayName = "Ping returns pong")]
public void PingReturnsPong()
{
var controller = new PingController();

var result = (OkObjectResult) controller.Ping();

Assert.Equal("pong", result.Value);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
using System.Linq;
using System.Net.Http;
using CoffeeCard.Configuration;
using CoffeeCard.Helpers.MobilePay;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.FileProviders;
using Moq;

namespace CoffeeCard.Tests.Unit.Helpers
{
public class MobilePayApiHttpClientTests
{
//[Fact(DisplayName = "")]
public void test()
{
var testCertificateName = "testCertificate.pfx";

var mobilePaySettings = new Mock<MobilePaySettings>();
mobilePaySettings.Setup(c => c.CertificatePassword).Returns("password");
mobilePaySettings.Setup(c => c.SubscriptionKey).Returns("subscrpKey");
mobilePaySettings.Setup(c => c.CertificateName).Returns(testCertificateName);

var directoryContents = new Mock<IDirectoryContents>();
directoryContents.Setup(dc => dc.FirstOrDefault(f => f.Name.Equals(testCertificateName)).PhysicalPath)
.Returns("");

var fileProvider = new Mock<IFileProvider>();
fileProvider.Setup(fp => fp.GetDirectoryContents(string.Empty)).Returns(directoryContents.Object);

var environment = new Mock<IHostingEnvironment>();
environment.Setup(e => e.ContentRootFileProvider).Returns(fileProvider.Object);

var httpClient = new Mock<HttpClient>();

var mobileApiHttpClient =
new MobilePayApiHttpClient(httpClient.Object, environment.Object, mobilePaySettings.Object);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
README
by Jonas Anker Rasmussen, anjr@itu.dk

For testing purposes, a test certificate has been created. The certificate cannot and must not be used in production.
There is no password on the certificate.

Test Certificate files
- testCertificate.pfx
- testCertificate.pvk
- testCertificate.crt
24 changes: 24 additions & 0 deletions coffeecard/CoffeeCard.Tests.Unit/Resources/testCertificate.crt
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
-----BEGIN CERTIFICATE-----
MIIEEzCCAvugAwIBAgIUGpDzWkmn10o+OVrRzX2wzBIemXgwDQYJKoZIhvcNAQEN
BQAwgZgxCzAJBgNVBAYTAkRLMRMwEQYDVQQIDApTb21lLVN0YXRlMRMwEQYDVQQH
DApDb3BlbmhhZ2VuMRIwEAYDVQQKDAlBbmFsb2cgSU8xCzAJBgNVBAsMAklPMRww
GgYDVQQDDBNBbmFsb2cgSU8gVGVzdCBDZXJ0MSAwHgYJKoZIhvcNAQkBFhFhZG1p
bkBhbmFsb2dpby5kazAeFw0yMDAxMjExNDIxNTZaFw0zMzA5MjkxNDIxNTZaMIGY
MQswCQYDVQQGEwJESzETMBEGA1UECAwKU29tZS1TdGF0ZTETMBEGA1UEBwwKQ29w
ZW5oYWdlbjESMBAGA1UECgwJQW5hbG9nIElPMQswCQYDVQQLDAJJTzEcMBoGA1UE
AwwTQW5hbG9nIElPIFRlc3QgQ2VydDEgMB4GCSqGSIb3DQEJARYRYWRtaW5AYW5h
bG9naW8uZGswggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAwggEKAoIBAQDGizdVCJ7B
RBzHtK1gXUkVOdVz2S8ioST13Ocfp4dQpIK6Fues5OUhv2Y8TB+UBePxsJd3GWVu
M0gzgED2a4h/8r0gEnN8nbrjSPVS3I0WRFvkPKTmEqMKrv1WiWc4Rs4aQJGF+AIz
nOWKxABF9WGivR0mZOD0iF0S2Gcb84TG049Qjg1QbJKHn2+piUsjfZ/Ob487D+sU
0KKcXlfVWjBaMf5/7KNaKjwxoR+VsGt/T0XYEuOHhcfe7n/Qhip+NJCgm9aIvcSC
UlMbJ0HKKHtyeQNJ67Z4Ti/fl7E4qdoF9/Cjv4uK7VcdrHREQmRE6NTW1YkdSj0b
DMJzuxoPCO3NAgMBAAGjUzBRMB0GA1UdDgQWBBSyr+yue13nTnRdjgH3W7/1L3Bk
wTAfBgNVHSMEGDAWgBSyr+yue13nTnRdjgH3W7/1L3BkwTAPBgNVHRMBAf8EBTAD
AQH/MA0GCSqGSIb3DQEBDQUAA4IBAQBO+M9hPB7htS/609UkcxTTU6oYqvq6I14s
QBDSLqq2Ct+o/TK5NnOtlXoOUKv5uluGRW0u9BjhcY9DEnS5lV5TmUZcvICsPyqi
3XRtJvh8UCKihlHVpkBdkSRSmmWIiURyIodhsOv0sGCh7wXwgAI9sLPF1sUkQ0k3
sOv5MPWIX+nt+kk2rJOuo54eYQT6bz2XvtcaTi5S5sqC0Jd+uMTGGbC0p3bqo6aV
HHN6rZx0GMcDYeKVDnZfi9wuvLeqLyVBQpFFIXVThDXoMWiApuUJdXeKQTH8Ech+
lCeF91MDm1gXBpu6OSSTRovSOzJvuI0QvaUtoNV5juEQsOACTZD1
-----END CERTIFICATE-----
Binary file not shown.
Loading